Class: AsciiChem::Model::Molecule
- Defined in:
- lib/asciichem/model/molecule.rb
Overview
A molecule: an ordered sequence of atoms/groups with optional leading stoichiometric coefficient, optional stereochemistry marker (R/S/E/Z/α/β), and optional names/identifiers for CML metadata round-trip.
Constant Summary collapse
- STEREO_LETTERS =
{ "R" => :R, "S" => :S, "E" => :E, "Z" => :Z, "a" => :alpha, "alpha" => :alpha, "α" => :alpha, "b" => :beta, "beta" => :beta, "β" => :beta }.freeze
- STEREO_TO_LETTER =
{ R: "R", S: "S", E: "E", Z: "Z", alpha: "alpha", beta: "beta" }.freeze
Instance Attribute Summary collapse
-
#coefficient ⇒ Object
Returns the value of attribute coefficient.
-
#formulas ⇒ Object
Returns the value of attribute formulas.
-
#identifiers ⇒ Object
Returns the value of attribute identifiers.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#names ⇒ Object
Returns the value of attribute names.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#stereo ⇒ Object
Returns the value of attribute stereo.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #children ⇒ Object
-
#initialize(nodes:, coefficient: nil, stereo: nil, names: [], identifiers: [], title: nil, formulas: [], properties: [], labels: [], metadata: []) ⇒ Molecule
constructor
A new instance of Molecule.
- #stereo_letter ⇒ Object
- #to_s ⇒ Object
- #value_attributes ⇒ Object
Methods inherited from Node
#==, #accept, #diagnostic_label, #hash, short_name, #to_cml, #to_html, #to_latex, #to_mathml, #to_svg, #to_text
Constructor Details
#initialize(nodes:, coefficient: nil, stereo: nil, names: [], identifiers: [], title: nil, formulas: [], properties: [], labels: [], metadata: []) ⇒ Molecule
Returns a new instance of Molecule.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/asciichem/model/molecule.rb', line 31 def initialize(nodes:, coefficient: nil, stereo: nil, names: [], identifiers: [], title: nil, formulas: [], properties: [], labels: [], metadata: []) @nodes = nodes @coefficient = coefficient @stereo = stereo @names = names @identifiers = identifiers @title = title @formulas = formulas @properties = properties @labels = labels @metadata = end |
Instance Attribute Details
#coefficient ⇒ Object
Returns the value of attribute coefficient.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def coefficient @coefficient end |
#formulas ⇒ Object
Returns the value of attribute formulas.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def formulas @formulas end |
#identifiers ⇒ Object
Returns the value of attribute identifiers.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def identifiers @identifiers end |
#labels ⇒ Object
Returns the value of attribute labels.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def labels @labels end |
#metadata ⇒ Object
Returns the value of attribute metadata.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def @metadata end |
#names ⇒ Object
Returns the value of attribute names.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def names @names end |
#nodes ⇒ Object
Returns the value of attribute nodes.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def nodes @nodes end |
#properties ⇒ Object
Returns the value of attribute properties.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def properties @properties end |
#stereo ⇒ Object
Returns the value of attribute stereo.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def stereo @stereo end |
#title ⇒ Object
Returns the value of attribute title.
28 29 30 |
# File 'lib/asciichem/model/molecule.rb', line 28 def title @title end |
Instance Method Details
#children ⇒ Object
53 54 55 |
# File 'lib/asciichem/model/molecule.rb', line 53 def children nodes end |
#stereo_letter ⇒ Object
57 58 59 |
# File 'lib/asciichem/model/molecule.rb', line 57 def stereo_letter STEREO_TO_LETTER.fetch(stereo) if stereo end |
#to_s ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/asciichem/model/molecule.rb', line 61 def to_s prefix = coefficient ? "#{coefficient}" : "" stereo_str = stereo ? "(#{stereo_letter})-" : "" name_str = names.empty? ? "" : " #{names.map(&:to_s).join(', ')}" id_str = identifiers.empty? ? "" : " #{identifiers.map(&:to_s).join(', ')}" "#{stereo_str}#{prefix}Molecule[#{nodes.map(&:to_s).join(', ')}]#{name_str}#{id_str}" end |
#value_attributes ⇒ Object
46 47 48 49 50 51 |
# File 'lib/asciichem/model/molecule.rb', line 46 def value_attributes { nodes: nodes, coefficient: coefficient, stereo: stereo, names: names, identifiers: identifiers, title: title, formulas: formulas, properties: properties, labels: labels, metadata: } end |