Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SmilesMoleculeBuilder.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_MOLASSEMBLER_IO_SMILES_MOLECULE_BUILDER_H
9 #define INCLUDE_MOLASSEMBLER_IO_SMILES_MOLECULE_BUILDER_H
10 
14 #include "boost/variant.hpp"
15 #include <stack>
16 
17 namespace Scine {
18 
19 namespace Utils {
20 enum class ElementType : unsigned;
21 } // namespace Utils
22 
23 
24 namespace Molassembler {
25 
26 class Molecule;
27 
28 namespace IO {
29 
35 public:
38  /* @brief Parsing trigger on encountering an atom
39  *
40  * Adds an atom with the last set bond information.
41  */
42  void addAtom(const AtomData& atom);
43 
45  void addRingClosure(const BondData& bond);
46 
48  inline void branchOpen() {
49  vertexStack.push(vertexStack.top());
50  }
51 
53  inline void branchClose() {
54  assert(!vertexStack.empty());
55  vertexStack.pop();
56  }
57 
59  inline void setNextAtomUnbonded() {
60  lastBondData = SimpleLastBondData::Unbonded;
61  }
62 
64  inline void setNextAtomBondInformation(const BondData& bond) {
65  lastBondData = bond;
66  }
68 
70  std::vector<Molecule> interpret();
71 
72 private:
76  static bool isValenceFillElement(Utils::ElementType e);
77 
79  static unsigned valenceFillElementImplicitHydrogenCount(
80  int valence,
81  Utils::ElementType e
82  );
83 
88  static BondType mutualBondType(
89  const boost::optional<BondType>& a,
90  const boost::optional<BondType>& b
91  );
92 
94  static std::vector<Shapes::Vertex> shapeMap(const ChiralData& chiralData);
96 
100  void setShapes(
101  std::vector<Molecule>& molecules,
102  const std::vector<unsigned>& componentMap,
103  const std::vector<PrivateGraph::Vertex>& indexInComponentMap
104  );
105 
107  void setAtomStereo(
108  std::vector<Molecule>& molecules,
109  const std::vector<unsigned>& componentMap,
110  const std::vector<PrivateGraph::Vertex>& indexInComponentMap
111  );
112 
114  void setBondStereo(
115  std::vector<Molecule>& molecules,
116  const std::vector<unsigned>& componentMap,
117  const std::vector<PrivateGraph::Vertex>& indexInComponentMap
118  );
120 
123  enum class SimpleLastBondData {
124  Unbonded,
125  Unspecified
126  };
127 
129  boost::variant<SimpleLastBondData, BondData> lastBondData = SimpleLastBondData::Unbonded;
130 
133 
135  std::stack<PrivateGraph::Vertex> vertexStack;
136 
138  using StereoMarkedBondTuple = std::tuple<PrivateGraph::Vertex, PrivateGraph::Vertex, BondData::StereoMarker>;
139  std::vector<StereoMarkedBondTuple> stereoMarkedBonds;
140 
142  std::unordered_map<
143  unsigned,
144  std::pair<PrivateGraph::Vertex, boost::optional<BondType>>
146 
148  std::vector<AtomData> vertexData;
150 };
151 
152 } // namespace IO
153 } // namespace Molassembler
154 } // namespace Scine
155 
156 #endif
MoleculesResult molecules(const Utils::ElementTypeCollection &elements, const AngstromPositions &angstromWrapper, const Utils::BondOrderCollection &bondOrders, BondDiscretizationOption discretization=BondDiscretizationOption::Binary, const boost::optional< double > &stereopermutatorThreshold=1.4)
The function that actually does all the work with the library-internal wrapper.
Semantic interpreter of the smiles grammar, constructs molecules from the data accrued by the parser...
Definition: SmilesMoleculeBuilder.h:34
void branchClose()
Parsing trigger on branch close.
Definition: SmilesMoleculeBuilder.h:53
void setNextAtomBondInformation(const BondData &bond)
Parsing trigger on encountering non-default bond information.
Definition: SmilesMoleculeBuilder.h:64
Definition: SmilesParseData.h:37
Centralizes basic shape data in runtime types.
std::stack< PrivateGraph::Vertex > vertexStack
State to track the vertex a new vertex is bound to.
Definition: SmilesMoleculeBuilder.h:135
std::tuple< PrivateGraph::Vertex, PrivateGraph::Vertex, BondData::StereoMarker > StereoMarkedBondTuple
Storage for bonds marked with stereo indicators (&quot;/&quot; and &quot;\&quot;)
Definition: SmilesMoleculeBuilder.h:138
SimpleLastBondData
Storage for bonds marked with stereo indicators (&quot;/&quot; and &quot;\&quot;)
Definition: SmilesMoleculeBuilder.h:123
Library internal graph class wrapping BGL types.
Definition: PrivateGraph.h:24
PrivateGraph graph
Possibly disconnected tracking graph.
Definition: SmilesMoleculeBuilder.h:132
Definition: SmilesParseData.h:42
BondType
Discrete bond type numeration.
Definition: Types.h:26
void setNextAtomUnbonded()
Parsing trigger on finding a dot (molecule separator) in place of a bond.
Definition: SmilesMoleculeBuilder.h:59
Definition: SmilesParseData.h:63
std::unordered_map< unsigned, std::pair< PrivateGraph::Vertex, boost::optional< BondType > > > ringClosures
Storage for ring closure bond indicators.
Definition: SmilesMoleculeBuilder.h:145
Define data accrued in smiles parser for consumption in the accompanying molecule builder...
void branchOpen()
Parsing trigger on branch open.
Definition: SmilesMoleculeBuilder.h:48
std::vector< StereoMarkedBondTuple > stereoMarkedBonds
Storage for bonds marked with stereo indicators (&quot;/&quot; and &quot;\&quot;)
Definition: SmilesMoleculeBuilder.h:139
std::vector< AtomData > vertexData
AtomData for each created vertex.
Definition: SmilesMoleculeBuilder.h:148
Boost Graph Library wrapper to help in concealing underlying type.