indigoX
condensed.hpp
Go to the documentation of this file.
1 
2 #ifndef INDIGOX_GRAPH_CONDENSED_HPP
3 #define INDIGOX_GRAPH_CONDENSED_HPP
4 
5 #include "../utils/fwd_declares.hpp"
6 #include "base_graph.hpp"
7 
8 #include <EASTL/bitset.h>
9 #include <EASTL/vector_map.h>
10 #include <EASTL/vector_set.h>
11 #include <memory>
12 #include <vector>
13 
14 namespace indigox::graph {
16  using VertexIsoMask = eastl::bitset<37, uint64_t>;
18  using EdgeIsoMask = eastl::bitset<14, uint16_t>;
19 
21  class CMGVertex {
22  public:
24  enum class ContractedSymmetry {
25  Hydrogen,
26  Fluorine,
27  Chlorine,
28  Bromine,
29  Iodine
30  };
31 
32  private:
36  friend class cereal::access;
38  using CondensedVertex = std::pair<ContractedSymmetry, MGVertex>;
39 
40  struct CMGVertexData;
41 
42  public:
45 
46  private:
50  CMGVertex(const MGVertex &v, const CondensedMolecularGraph &g);
51 
52  template <typename Archive>
53  void serialise(Archive &archive, const uint32_t version);
54 
55  public:
58  const MGVertex &GetSource() const;
59 
62  const CondensedMolecularGraph &GetGraph() const;
63 
66  size_t NumContracted() const;
67 
71  size_t NumContracted(ContractedSymmetry sym) const;
72 
75  const VertexIsoMask &GetIsomorphismMask() const;
76 
80  bool IsContractedHere(const MGVertex &v) const;
81 
82  std::vector<MGVertex> GetContractedVertices() const;
83  const std::vector<CondensedVertex> &GetCondensedVertices() const;
84 
85  private:
87  std::shared_ptr<CMGVertexData> m_data;
88  };
90 
92  class CMGEdge {
96  friend class cereal::access;
97 
98  struct CMGEdgeData;
99 
100  public:
103 
104  private:
108  CMGEdge(const MGEdge &e, const CondensedMolecularGraph &g);
109 
110  template <typename Archive>
111  void serialise(Archive &archive, const uint32_t version);
112 
113  public:
116  const MGEdge &GetSource() const;
117 
120  const CondensedMolecularGraph &GetGraph() const;
121 
124  const EdgeIsoMask &GetIsomorphismMask() const;
125 
126  private:
128  std::shared_ptr<CMGEdgeData> m_data;
129  };
130 
132  : public BaseGraph<CMGVertex, CMGEdge, CondensedMolecularGraph> {
133  public:
135  friend class cereal::access;
138  friend class MolecularGraph;
139 
143  using VertContain = std::vector<CMGVertex>;
145  using EdgeContain = std::vector<CMGEdge>;
147  using NbrsContain = std::map<CMGVertex, VertContain>;
149  using VertMap = eastl::vector_map<MGVertex, CMGVertex>;
151  using EdgeMap = eastl::vector_map<MGEdge, CMGEdge>;
152 
153  public:
155  using EdgeIter = EdgeContain::const_iterator;
157  using VertIter = VertContain::const_iterator;
159  using NbrsIter = NbrsContain::mapped_type::const_iterator;
163  using EdgeType = CMGEdge;
164 
165  private:
166  template <typename Archive>
167  void serialise(Archive &archive, const uint32_t version);
168 
169  // Modification methods are private so that the CMG is a snapshot of the MG
170  // at time of creation
177  CMGEdge AddEdge(const MGEdge &e);
178 
184  CMGVertex AddVertex(const MGVertex &v);
185 
186  // void Clear();
187 
188  public:
191 
192  private:
196 
197  public:
206  CondensedMolecularGraph Subgraph(std::vector<CMGVertex> &verts);
207 
218  CondensedMolecularGraph Subgraph(std::vector<CMGVertex> &verts,
219  std::vector<CMGEdge> &edges);
220 
221  bool IsSubgraph() const;
222  // {
223  // return bool(_subg);
224  // }
225 
228  const MolecularGraph &GetMolecularGraph() const;
229 
230  const CondensedMolecularGraph &GetSuperGraph() const;
231 
232  using graph_type::GetEdge;
233  using graph_type::HasEdge;
234  using graph_type::HasVertex;
235 
241  const CMGEdge &GetEdge(const MGEdge &e) const;
242 
248  const CMGVertex &GetVertex(const MGVertex &v) const;
249  const CMGVertex &GetCondensedVertex(const MGVertex &v) const;
250 
257  bool HasVertex(const MGVertex &v) const;
258 
264  bool HasCondensedVertex(const MGVertex &v) const;
265 
269  bool HasEdge(const MGEdge &e) const;
270 
271  private:
272  struct Impl;
273  std::shared_ptr<Impl> m_data;
274  };
275 
277 
278 } // namespace indigox::graph
279 
280 #endif /* INDIGOX_GRAPH_CONDENSED_HPP */
const std::vector< CondensedVertex > & GetCondensedVertices() const
EdgeContain::const_iterator EdgeIter
Type of the iterator returned by GetEdges() method.
Definition: condensed.hpp:155
#define INDIGOX_GENERIC_PIMPL_CLASS_DEFAULTS(class_name)
Definition: fwd_declares.hpp:18
CondensedMolecularGraph Condense(const MolecularGraph &G)
friend class cereal::access
Friendship allows for serialisation.
Definition: condensed.hpp:36
const MolecularGraph & GetMolecularGraph() const
Get the source MolecularGraph.
bool HasVertex(const CMGVertex &v) const
Is the vertex in the graph.
Definition: base_graph_impl.hpp:187
VertContain::const_iterator VertIter
Type of the iterator returned by GetVertices() method.
Definition: condensed.hpp:157
NbrsContain::mapped_type::const_iterator NbrsIter
Type of the iterator returned by GetNeighbours() method.
Definition: condensed.hpp:159
Definition: assignment.hpp:16
std::map< CMGVertex, VertContain > NbrsContain
Container for neighbours of vertices.
Definition: condensed.hpp:147
Definition: condensed.hpp:131
friend class cereal::access
Friendship allows for serialisation.
Definition: condensed.hpp:96
const CondensedMolecularGraph & GetGraph() const
Get the graph this edge is part of.
Class for the vertices of an IXCondensedMolecularGraph.
Definition: condensed.hpp:21
const CMGVertex & GetVertex(const MGVertex &v) const
Get the vertex associated with an MGVertex.
Class for the edges of a IXMolecularGraph.
Definition: molecular.hpp:55
const CondensedMolecularGraph & GetSuperGraph() const
std::vector< CMGEdge > EdgeContain
Container for edges.
Definition: condensed.hpp:145
Class containing a graph representation of a molecule.
Definition: molecular.hpp:95
friend CondensedMolecularGraph Condense(const MolecularGraph &)
Friendship allows for generating from a source.
bool HasCondensedVertex(const MGVertex &v) const
Check of the graph has a vertex associated with an MGVertex.
Class for the vertices of a IXMolecularGraph.
Definition: molecular.hpp:20
const MGVertex & GetSource() const
Get the MGVertex associated with this vertex.
eastl::bitset< 37, uint64_t > VertexIsoMask
type used to store the isomorphism testing mask for IXCMGVertex.
Definition: condensed.hpp:16
const VertexIsoMask & GetIsomorphismMask() const
Get the isomorphism testing mask.
const MGEdge & GetSource() const
Get the MGEdge associated with this vertex.
bool HasEdge(const CMGEdge &e) const
Is the edge in the graph.
Definition: base_graph_impl.hpp:192
CondensedMolecularGraph Subgraph(std::vector< CMGVertex > &verts)
Induce a subgraph from the range of vertices.
eastl::bitset< 14, uint16_t > EdgeIsoMask
type used to store the isomorphism testing mask for IXCMGEdge.
Definition: condensed.hpp:18
std::vector< CMGVertex > VertContain
Container for vertices.
Definition: condensed.hpp:143
const EdgeIsoMask & GetIsomorphismMask() const
Get the isomorphism testing mask.
const CondensedMolecularGraph & GetGraph() const
Get the graph this vertex is part of.
#define INDIGOX_GENERIC_PIMPL_CLASS_OPERATORS(class_name, short_name)
Definition: fwd_declares.hpp:26
CMGEdge GetEdge(const CMGVertex &u, const CMGVertex &v) const
Get the edge between two vertices.
Definition: base_graph_impl.hpp:267
bool HasEdge(const MGEdge &e) const
Check if the graph has an edge associated with an MGEdge.
eastl::vector_map< MGVertex, CMGVertex > VertMap
Container for mapping MGVertex to vertices.
Definition: condensed.hpp:149
const CMGVertex & GetCondensedVertex(const MGVertex &v) const
std::vector< MGVertex > GetContractedVertices() const
Template base class for all graphs used in the indigoX library.
Definition: base_graph.hpp:56
const CMGEdge & GetEdge(const MGEdge &e) const
Get the edge associated with an MGEdge.
size_t NumContracted() const
Get the number of contracted vertices.
bool IsContractedHere(const MGVertex &v) const
Checks if a given MGVertex is contracted into this vertex.
eastl::vector_map< MGEdge, CMGEdge > EdgeMap
Container for mapping MGEdge to edges.
Definition: condensed.hpp:151
Class for the edges of an IXCondensedMolecularGraph.
Definition: condensed.hpp:92
bool HasVertex(const MGVertex &v) const
Check if the graph has a vertex directly associated with an MGVertex.
ContractedSymmetry
Enum for the contracted symmetry groups.
Definition: condensed.hpp:24
friend class cereal::access
Friendship allows serialisation.
Definition: condensed.hpp:135