8 #ifndef INCLUDE_MOLASSEMBLER_IO_SMILES_MOLECULE_BUILDER_H
9 #define INCLUDE_MOLASSEMBLER_IO_SMILES_MOLECULE_BUILDER_H
14 #include "boost/variant.hpp"
15 #include "boost/bimap.hpp"
16 #include "boost/graph/subgraph.hpp"
22 enum class ElementType : unsigned;
26 namespace Molassembler {
45 using BaseGraph = boost::adjacency_list<
50 boost::property<boost::edge_index_t, int>
52 using Graph = boost::subgraph<BaseGraph>;
53 using Vertex =
typename BaseGraph::vertex_descriptor;
54 using Edge =
typename BaseGraph::edge_descriptor;
55 using IndexMap = boost::bimap<Vertex, Vertex>;
56 using VertexSet = std::unordered_set<Vertex>;
60 static bool hasUnpairedElectrons(Vertex i,
int charge,
const PrivateGraph& g);
69 case Utils::ElementType::C:
70 case Utils::ElementType::N:
71 case Utils::ElementType::O:
72 case Utils::ElementType::S:
73 case Utils::ElementType::P:
74 case Utils::ElementType::As:
75 case Utils::ElementType::Sb:
76 case Utils::ElementType::Se:
77 case Utils::ElementType::Te: {
114 static boost::optional<EligibleOmissible> multipleOrderAdjacent(
118 const boost::optional<unsigned>& neighborCount
121 static boost::optional<EligibleOmissible> threeNeighborChargedCarbon(
125 const boost::optional<unsigned>& neighborCount
128 static boost::optional<EligibleOmissible> neutralTrivalents(
132 const boost::optional<unsigned>& neighborCount
135 static boost::optional<EligibleOmissible> neutralDivalents(
139 const boost::optional<unsigned>& neighborCount
147 const auto iter = index.left.find(i);
148 if(iter == index.left.end()) {
149 const Vertex a = boost::add_vertex(graph);
150 index.insert(IndexMap::relation(i, a));
162 boost::optional<VertexSet> match();
193 void addRingClosure(
const BondData& bond);
197 vertexStack.push(vertexStack.top());
202 assert(!vertexStack.empty());
208 lastBondData = boost::none;
218 std::vector<Molecule> interpret(
const std::string& smiles);
231 const boost::optional<BondType>& a,
232 const boost::optional<BondType>& b
240 static std::vector<Shapes::Vertex> shapeMap(
const ChiralData& chiralData);
246 std::unordered_set<PrivateGraph::Vertex> matchAromatics(
247 std::vector<PrivateGraph>& precursors,
248 const std::vector<unsigned>& componentMap,
249 const std::vector<PrivateGraph::Vertex>& indexInComponentMap
255 const std::vector<unsigned>& componentMap,
256 const std::vector<PrivateGraph::Vertex>& indexInComponentMap
262 const std::vector<unsigned>& componentMap,
263 const std::vector<PrivateGraph::Vertex>& indexInComponentMap,
264 const std::string& smiles
270 const std::vector<unsigned>& componentMap,
271 const std::vector<PrivateGraph::Vertex>& indexInComponentMap,
272 const std::string& smiles
276 void addAromaticBondStereo(
278 const std::vector<unsigned>& componentMap,
279 const std::vector<PrivateGraph::Vertex>& indexInComponentMap
304 std::pair<PrivateGraph::Vertex, boost::optional<BondType>>
bool omissible
Can be omitted from the pi subgraph to find a perfect matching.
Definition: SmilesMoleculeBuilder.h:90
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.
Definition: SmilesMoleculeBuilder.h:182
void branchClose()
Parsing trigger on branch close.
Definition: SmilesMoleculeBuilder.h:201
void setNextAtomBondInformation(const BondData &bond)
Parsing trigger on encountering non-default bond information.
Definition: SmilesMoleculeBuilder.h:212
boost::optional< BondData > lastBondData
State for last stored bond data.
Definition: SmilesMoleculeBuilder.h:286
Data struct for eligibleOmissible()
Definition: SmilesMoleculeBuilder.h:86
Definition: SmilesParseData.h:37
Class to help validate aromatic subgraphs in parsed smiles strings.
Definition: SmilesMoleculeBuilder.h:42
Centralizes basic shape data in runtime types.
static bool permittedElementType(Utils::ElementType e)
Decide whether an element type is allowed to be in the pi subgraph.
Definition: SmilesMoleculeBuilder.h:67
std::stack< PrivateGraph::Vertex > vertexStack
State to track the vertex a new vertex is bound to.
Definition: SmilesMoleculeBuilder.h:292
std::tuple< PrivateGraph::Vertex, PrivateGraph::Vertex, SmilesBondType > StereoMarkedBondTuple
Storage for bonds marked with stereo indicators ("/" and "\")
Definition: SmilesMoleculeBuilder.h:295
Graph graph
Subgraph data structure.
Definition: SmilesMoleculeBuilder.h:168
IndexMap index
Index mapping from precursor to subgraph vertex index.
Definition: SmilesMoleculeBuilder.h:170
VertexSet omissible
Set of omissible subgraph vertices.
Definition: SmilesMoleculeBuilder.h:172
Library internal graph class wrapping BGL types.
Definition: PrivateGraph.h:26
PrivateGraph graph
Possibly disconnected tracking graph.
Definition: SmilesMoleculeBuilder.h:289
bool eligible
Should be added to the pi subgraph.
Definition: SmilesMoleculeBuilder.h:88
Definition: SmilesParseData.h:42
BondType
Discrete bond type numeration.
Definition: Types.h:26
Vertex findOrAdd(Vertex i)
Find a precursor vertex's subgraph index, inserting it if not present.
Definition: SmilesMoleculeBuilder.h:146
void setNextAtomUnbonded()
Parsing trigger on finding a dot (molecule separator) in place of a bond.
Definition: SmilesMoleculeBuilder.h:207
std::vector< PrivateGraph::Edge > piSubgraphEdges
Storage for pi-subgraph edges.
Definition: SmilesMoleculeBuilder.h:299
Definition: SmilesParseData.h:73
std::unordered_map< unsigned, std::pair< PrivateGraph::Vertex, boost::optional< BondType > > > ringClosures
Storage for ring closure bond indicators.
Definition: SmilesMoleculeBuilder.h:305
Define data accrued in smiles parser for consumption in the accompanying molecule builder...
void branchOpen()
Parsing trigger on branch open.
Definition: SmilesMoleculeBuilder.h:196
std::vector< StereoMarkedBondTuple > stereoMarkedBonds
Storage for bonds marked with stereo indicators ("/" and "\")
Definition: SmilesMoleculeBuilder.h:296
std::vector< AtomData > vertexData
AtomData for each created vertex.
Definition: SmilesMoleculeBuilder.h:308
Boost Graph Library wrapper to help in concealing underlying type.