indigoX
molecular.hpp
Go to the documentation of this file.
1 
2 #ifndef INDIGOX_GRAPH_MOLECULAR_HPP
3 #define INDIGOX_GRAPH_MOLECULAR_HPP
4 
5 #include "../algorithm/graph/cycles.hpp"
6 #include "../utils/fwd_declares.hpp"
7 #include "base_graph.hpp"
8 
9 #include <EASTL/vector_map.h>
10 #include <iterator>
11 #include <map>
12 #include <memory>
13 #include <set>
14 #include <stdexcept>
15 #include <vector>
16 
17 // Local declarations
18 namespace indigox::graph {
20  class MGVertex {
22  friend class MolecularGraph;
24  friend class cereal::access;
25 
26  public:
29  const Atom &GetAtom() const;
30 
33  const MolecularGraph &GetGraph() const;
34 
35  public:
38 
39  private:
44  MGVertex(const Atom &a, const MolecularGraph &graph);
45 
46  template <typename Archive>
47  void serialise(Archive &archive, const uint32_t version);
48 
49  private:
50  struct MGVertexData;
51  std::shared_ptr<MGVertexData> m_data;
52  };
53 
55  class MGEdge {
57  friend class MolecularGraph;
59  friend class cereal::access;
60 
61  public:
64  const Bond &GetBond() const;
65 
68  const MolecularGraph &GetGraph() const;
69 
70  public:
73 
74  private:
79  MGEdge(const Bond &b, const MolecularGraph &graph);
80 
81  template <typename Archive>
82  void serialise(Archive &archive, const uint32_t version);
83 
84  private:
85  struct MGEdgeData;
86  std::shared_ptr<MGEdgeData> m_data;
87  };
88 
95  class MolecularGraph : public BaseGraph<MGVertex, MGEdge, MolecularGraph> {
96  public:
98  friend class indigox::Molecule;
100  friend class cereal::access;
101 
105  using VertContain = std::vector<MGVertex>;
107  using EdgeContain = std::vector<MGEdge>;
109  using NbrsContain = std::map<MGVertex, VertContain>;
111  using AtomMap = eastl::vector_map<Atom, MGVertex>;
113  using BondMap = eastl::vector_map<Bond, MGEdge>;
114 
115  public:
117  using EdgeIter = EdgeContain::const_iterator;
119  using VertIter = VertContain::const_iterator;
121  using NbrsIter = NbrsContain::mapped_type::const_iterator;
125  using EdgeType = MGEdge;
126 
127  public:
132 
133  public:
134  MolecularGraph(const Molecule &mol);
135 
136  private:
137  template <typename Archive>
138  void serialise(Archive &archive, const uint32_t version);
139 
140  // modifcation methods are private so that the structure of the graph can
141  // be controlled only by the molecule owning it.
148  MGEdge AddEdge(const Bond &bnd);
149 
155  MGVertex AddVertex(const Atom &atm);
156 
160  void RemoveEdge(const MGEdge &e);
161 
166  void RemoveEdge(const MGVertex &u, const MGVertex &v);
167 
172  void RemoveVertex(const MGVertex &v);
173 
174  public:
183  MolecularGraph Subgraph(std::vector<MGVertex> &vertices);
184 
185  MolecularGraph Subgraph(std::vector<MGVertex> &vertices,
186  std::vector<MGEdge> &edges);
187 
188  bool IsSubgraph() const;
189  // {
190  // return !_subg.expired();
191  // }
192 
193  using graph_type::GetEdge;
194  using graph_type::HasEdge;
195  using graph_type::HasVertex;
196 
202  const MGEdge &GetEdge(const Bond &bnd) const;
203 
209  const MGVertex &GetVertex(const Atom &atm) const;
210 
214  bool HasVertex(const Atom &v) const;
215 
219  bool HasEdge(const Bond &e) const;
220 
221  const Molecule &GetMolecule() const;
222 
223  const MolecularGraph &GetSuperGraph() const;
224 
225  // Can only generate/get the condensed graph when molecule is frozen
227 
228  private:
229  struct Impl;
230  std::shared_ptr<Impl> m_data;
231  };
232 } // namespace indigox::graph
233 
234 #endif /* INDIGOX_GRAPH_MOLECULAR_HPP */
MolecularGraph Subgraph(std::vector< MGVertex > &vertices)
Induce a subgraph from the range of vertices.
const Atom & GetAtom() const
Get the atom associated with this vertex.
const Molecule & GetMolecule() const
#define INDIGOX_GENERIC_PIMPL_CLASS_DEFAULTS(class_name)
Definition: fwd_declares.hpp:18
Definition: bond.hpp:11
bool HasVertex(const MGVertex &v) const
Is the vertex in the graph.
Definition: base_graph_impl.hpp:187
const MGVertex & GetVertex(const Atom &atm) const
Get the vertex associated with an atom.
Definition: atom.hpp:13
Definition: assignment.hpp:16
eastl::vector_map< Bond, MGEdge > BondMap
Container for mapping bonds to edges.
Definition: molecular.hpp:113
Definition: condensed.hpp:131
const MolecularGraph & GetSuperGraph() const
Class for the edges of a IXMolecularGraph.
Definition: molecular.hpp:55
std::map< MGVertex, VertContain > NbrsContain
Container for neighbours of vertices.
Definition: molecular.hpp:109
EdgeContain::const_iterator EdgeIter
Type of the iterator returned by GetEdges() method.
Definition: molecular.hpp:117
const MGEdge & GetEdge(const Bond &bnd) const
Get the edge associated with a bond.
MolecularGraph()=default
Construct with a molecule.
Class containing a graph representation of a molecule.
Definition: molecular.hpp:95
NbrsContain::mapped_type::const_iterator NbrsIter
Type of the iterator returned by GetNeighbours() method.
Definition: molecular.hpp:121
Class for the vertices of a IXMolecularGraph.
Definition: molecular.hpp:20
std::vector< MGEdge > EdgeContain
Container for edges.
Definition: molecular.hpp:107
eastl::vector_map< Atom, MGVertex > AtomMap
Container for mapping atoms to vertices.
Definition: molecular.hpp:111
bool HasEdge(const MGEdge &e) const
Is the edge in the graph.
Definition: base_graph_impl.hpp:192
friend class cereal::access
Friendship allows for serialisation.
Definition: molecular.hpp:24
const MolecularGraph & GetGraph() const
Get the graph this edge is part of.
friend class cereal::access
Friendship allows serialisation.
Definition: molecular.hpp:100
const CondensedMolecularGraph & GetCondensedGraph()
VertContain::const_iterator VertIter
Type of the iterator returned by GetVertices() method.
Definition: molecular.hpp:119
Definition: molecule.hpp:15
#define INDIGOX_GENERIC_PIMPL_CLASS_OPERATORS(class_name, short_name)
Definition: fwd_declares.hpp:26
MGEdge GetEdge(const MGVertex &u, const MGVertex &v) const
Get the edge between two vertices.
Definition: base_graph_impl.hpp:267
bool HasVertex(const Atom &v) const
Check if the graph has a vertex associated with an atom.
Template base class for all graphs used in the indigoX library.
Definition: base_graph.hpp:56
std::vector< MGVertex > VertContain
Container for vertices.
Definition: molecular.hpp:105
friend class cereal::access
Friendship allows for serialisation.
Definition: molecular.hpp:59
const Bond & GetBond() const
Get the bond associated with this edge.
const MolecularGraph & GetGraph() const
Get the graph this vertex is part of.
bool HasEdge(const Bond &e) const
Check if the graph has an edge associated with a bond.