Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PrivateGraph.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_MOLASSEMBLER_INNER_GRAPH_H
9 #define INCLUDE_MOLASSEMBLER_INNER_GRAPH_H
10 
11 #include "boost/graph/adjacency_list.hpp"
13 
14 #include "Molassembler/Cycles.h"
15 
16 #include <limits>
17 
18 namespace Scine {
19 namespace Molassembler {
20 
24 class PrivateGraph {
25 public:
29  struct VertexData {
30  Utils::ElementType elementType;
31  };
32 
34  struct EdgeData {
35  BondType bondType;
36  };
37 
42  using BglType = boost::adjacency_list<
43  /* OutEdgeListS = Type of Container for edges of a vertex
44  * Options: vector, list, slist, set, multiset, unordered_set
45  * Choice: vecS, we have to rigorously test that no parallel edges are
46  * created
47  */
48  boost::vecS,
49  /* VertexListS = Type of Container for vertices
50  * Options: vector, list, slist, set, multiset, unordered_set
51  * Choice: vecS, removing vertices is rare, keep memory use limited
52  * Consequence: operation remove_vertex() invalidates:
53  * - Vertex descriptors / iterators
54  * - Edge descriptors / iterators
55  * - Adjacency iterators
56  */
57  boost::vecS,
58  // Molecular graphs are undirected
59  boost::undirectedS,
60  // VertexProperty: What information is stored about vertices?
61  VertexData,
62  // EdgeProperty: What information is stored about edges?
63  EdgeData
64  // GraphProperty: Omitted, defaults
65  // EdgeListS: Omitted, defaults
66  >;
67 
68  using Vertex = BglType::vertex_descriptor;
69  using Edge = BglType::edge_descriptor;
70 
75 
85  std::unordered_set<PrivateGraph::Vertex> articulationVertices;
87  std::set<PrivateGraph::Edge> bridges;
88  };
90 
94  PrivateGraph();
98 
101  PrivateGraph(const PrivateGraph& other);
102  PrivateGraph(PrivateGraph&& other);
103  PrivateGraph& operator = (const PrivateGraph& other);
104  PrivateGraph& operator = (PrivateGraph&& other);
105  ~PrivateGraph();
107 
111  static constexpr Vertex removalPlaceholder = std::numeric_limits<Vertex>::max();
113 
116 
122 
127  Vertex addVertex(Utils::ElementType elementType);
128 
133  void applyPermutation(const std::vector<Vertex>& permutation);
134 
140  BondType& bondType(const Edge& edge);
141 
143  BglType& bgl();
144 
149  void clearVertex(Vertex a);
150 
156  Utils::ElementType& elementType(Vertex a);
157 
162  void removeEdge(const Edge& e);
163 
169  void removeVertex(Vertex a);
171 
174 
179  Utils::ElementType elementType(Vertex a) const;
185  BondType bondType(const Edge& edge) const;
187  const BglType& bgl() const;
188 
199  bool canRemove(Vertex a) const;
208  bool canRemove(const Edge& edge) const;
209 
214  unsigned connectedComponents() const;
215 
220  unsigned connectedComponents(std::vector<unsigned>& componentMap) const;
221 
227  Edge edge(Vertex a, Vertex b) const;
228 
233  boost::optional<Edge> edgeOption(Vertex a, Vertex b) const;
234 
236  Vertex source(const Edge& edge) const;
238  Vertex target(const Edge& edge) const;
239 
244  Vertex degree(Vertex a) const;
245 
247  Vertex N() const;
249  Vertex B() const;
250 
256  boost::optional<std::vector<AtomIndex>> modularIsomorphism(
257  const PrivateGraph& other,
258  AtomEnvironmentComponents components = AtomEnvironmentComponents::All
259  ) const;
260 
265  bool identicalGraph(const PrivateGraph& other) const;
266 
272  std::pair<
273  std::vector<AtomIndex>,
274  std::vector<AtomIndex>
275  > splitAlongBridge(Edge bridge) const;
277 
287  void populateProperties() const;
289  const Cycles& cycles() const;
291  const RemovalSafetyData& removalSafetyData() const;
293  const Cycles& etaPreservedCycles() const;
295 
298  VertexRange vertices() const;
299  EdgeRange edges() const;
300  AdjacentVertexRange adjacents(Vertex a) const;
301  IncidentEdgeRange edges(Vertex a) const;
303 
307  bool operator == (const PrivateGraph& other) const;
308  inline bool operator != (const PrivateGraph& other) const {
309  return !(*this == other);
310  }
312 
313 private:
316  struct Properties {
317  boost::optional<RemovalSafetyData> removalSafetyDataOption;
318  boost::optional<Cycles> cyclesOption;
319  boost::optional<Cycles> etaPreservedCyclesOption;
320 
321  inline void invalidate() {
322  removalSafetyDataOption = boost::none;
323  cyclesOption = boost::none;
324  etaPreservedCyclesOption = boost::none;
325  }
326  };
327 
328  RemovalSafetyData generateRemovalSafetyData_() const;
329  Cycles generateCycles_() const;
330  Cycles generateEtaPreservedCycles_() const;
332 
340 };
341 
342 } // namespace Molassembler
343 } // namespace Scine
344 #endif
Definition: PrivateGraph.h:316
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, VertexData, EdgeData > BglType
Definition: PrivateGraph.h:66
std::unordered_set< PrivateGraph::Vertex > articulationVertices
Articulation vertices cannot be removed without disconnecting the graph.
Definition: PrivateGraph.h:85
const Cycles & cycles() const
Access cycle information of the graph.
std::set< PrivateGraph::Edge > bridges
Bridges are edges that cannot be removed without disconnecting the graph.
Definition: PrivateGraph.h:87
Information stored at each graph vertex.
Definition: PrivateGraph.h:29
BglType & bgl()
Referential access to the underlying BGL graph.
const Cycles & etaPreservedCycles() const
Access cycle information of the graph with eta bonds preserved.
bool operator==(const PrivateGraph &other) const
Full isomorphism comparison including element types and bond orders.
Class to explore cyclic structure of molecules.
Edge edge(Vertex a, Vertex b) const
Make an edge descriptor from two vertex descriptors.
Vertex N() const
Number of vertices in the graph.
AtomEnvironmentComponents
For bitmasks grouping components of immediate atom environments.
Definition: Types.h:103
const RemovalSafetyData & removalSafetyData() const
Access removal safety information of the graph.
Data class to return removal safety information on the graph.
Definition: PrivateGraph.h:83
Wrapper class to make working with RDL in C++ more pleasant.
Definition: Cycles.h:44
void applyPermutation(const std::vector< Vertex > &permutation)
Apply a permutation to the graph.
unsigned connectedComponents() const
Number of connected components.
Information stored at each graph edge.
Definition: PrivateGraph.h:34
Homogeneous pair of iterators with begin and end member fns.
Definition: IteratorRange.h:26
void removeEdge(const Edge &e)
Removes an edge from the graph.
PrivateGraph()
Empty constructor.
std::pair< std::vector< AtomIndex >, std::vector< AtomIndex > > splitAlongBridge(Edge bridge) const
Determine which vertices belong to which side of a bridge edge.
BglType graph_
A directly owned Boost Library Graph.
Definition: PrivateGraph.h:336
void populateProperties() const
Access cycle information of the graph.
Vertex target(const Edge &edge) const
Target of an edge.
Vertex degree(Vertex a) const
Number of substituents of a vertex.
boost::optional< Edge > edgeOption(Vertex a, Vertex b) const
Get an edge descriptor from two vertex descriptors, get None if the edge doesn&#39;t exist.
Library internal graph class wrapping BGL types.
Definition: PrivateGraph.h:24
bool canRemove(Vertex a) const
Determine whether a vertex can be safely removed.
BondType & bondType(const Edge &edge)
Fetch the bond type of an edge.
BondType
Discrete bond type numeration.
Definition: Types.h:26
BglType::edge_descriptor Edge
Definition: PrivateGraph.h:69
Properties properties_
Property caching.
Definition: PrivateGraph.h:338
static constexpr Vertex removalPlaceholder
Placeholder vertex index used to indicate that a vertex has been removed.
Definition: PrivateGraph.h:111
Edge addEdge(Vertex a, Vertex b, BondType bondType)
Add an edge to the graph.
void removeVertex(Vertex a)
Removes a vertex from the graph.
Utils::ElementType & elementType(Vertex a)
Fetches the element type of a vertex.
bool identicalGraph(const PrivateGraph &other) const
Checks whether all edges present in *this are present in other.
boost::optional< std::vector< AtomIndex > > modularIsomorphism(const PrivateGraph &other, AtomEnvironmentComponents components=AtomEnvironmentComponents::All) const
Modular isomorphism comparison.
BglType::vertex_descriptor Vertex
Definition: PrivateGraph.h:68
Vertex source(const Edge &edge) const
Source of an edge.
Vertex B() const
Number of edges in the graph.
void clearVertex(Vertex a)
Removes all bonds involving a vertex.
bool operator!=(const PrivateGraph &other) const
Full isomorphism comparison including element types and bond orders.
Definition: PrivateGraph.h:308
Vertex addVertex(Utils::ElementType elementType)
Add a (disconnected) vertex to the graph.