Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Graph.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_MOLASSEMBLER_OUTER_GRAPH_H
9 #define INCLUDE_MOLASSEMBLER_OUTER_GRAPH_H
10 
11 #include "boost/optional/optional_fwd.hpp"
13 
14 #include "Molassembler/Types.h"
16 
17 #include <memory>
18 #include <vector>
19 
20 namespace Scine {
21 // Forward-declarations
22 namespace Utils {
23 using ElementTypeCollection = std::vector<ElementType>;
24 class BondOrderCollection;
25 } // namespace Utils
26 
27 namespace Molassembler {
28 
29 // Forward-declare PrivateGraph
30 class PrivateGraph;
31 class Cycles;
32 
57 class MASM_EXPORT Graph {
58 public:
61 
74  template<typename T, bool isVertexInitialized>
76  public:
77  static_assert(
78  std::is_same<T, AtomIndex>::value || std::is_same<T, BondIndex>::value,
79  "You may not instantiate this type for other Ts than AtomIndex or BondIndex"
80  );
81 
82  using iterator_category = std::forward_iterator_tag;
83  using difference_type = std::ptrdiff_t;
84  using value_type = T;
85  using pointer = T;
86  using reference = T;
87 
88  InnerBasedIterator(InnerBasedIterator&& other) noexcept;
89  InnerBasedIterator& operator = (InnerBasedIterator&& other) noexcept;
91  InnerBasedIterator& operator = (const InnerBasedIterator& other);
93 
94  // Default constructor
96 
97  /* We want to use this iterator facade in four ways:
98  *
99  * Iterate through all valid atom indices: (graph) -> AtomIndex
100  * Iterate through all valid bond indices: (graph) -> BondIndex
101  * Iterate through all atom indices adjacent to i: (graph, i) -> AtomIndex
102  * Iterate through all bonds incident on i: (graph, i) -> BondIndex
103  *
104  * So, we template and enable-if constructors for the cases that the
105  * template parameter isVertexInitialized (which denotes whether
106  * additionally to the graph, a vertex descriptor is required in the
107  * constructor):
108  */
109 
120  template<bool Dependent = isVertexInitialized, std::enable_if_t<!Dependent, int>...>
121  InnerBasedIterator(const PrivateGraph& inner, bool begin);
122 
135  template<bool Dependent = isVertexInitialized, std::enable_if_t<Dependent, int>...>
136  InnerBasedIterator(AtomIndex a, const PrivateGraph& inner, bool begin);
137 
139  InnerBasedIterator& operator ++ ();
141  InnerBasedIterator operator ++ (int);
143  value_type operator * () const;
144 
146  bool operator == (const InnerBasedIterator& other) const;
148  bool operator != (const InnerBasedIterator& other) const;
149 
150  private:
151  struct Impl;
152  std::unique_ptr<Impl> pImpl_;
153  };
154 
164 
167  Graph(Graph&& other) noexcept;
168  Graph& operator = (Graph&& other) noexcept;
169  Graph(const Graph& other);
170  Graph& operator = (const Graph& other);
171  ~Graph();
173 
176  Graph();
178  explicit Graph(PrivateGraph&& inner);
180 
183 
187  bool adjacent(AtomIndex a, AtomIndex b) const;
192  std::vector<AtomIndex> atomsOfElement(Utils::ElementType e) const;
197  boost::optional<BondIndex> bond(AtomIndex a, AtomIndex b) const;
202  Utils::BondOrderCollection bondOrders() const;
207  BondType bondType(const BondIndex& edge) const;
215  bool canRemove(AtomIndex a) const;
223  bool canRemove(const BondIndex& edge) const;
231  const Cycles& cycles() const;
236  unsigned degree(AtomIndex a) const;
238  std::string dumpGraphviz() const;
243  Utils::ElementTypeCollection elementCollection() const;
248  Utils::ElementType elementType(AtomIndex a) const;
249 
254  AtomIndex N() const;
259  unsigned B() const;
260 
266  boost::optional<std::vector<AtomIndex>> modularIsomorphism(
267  const Graph& other,
269  ) const;
270 
279  std::pair<
280  std::vector<AtomIndex>,
281  std::vector<AtomIndex>
282  > splitAlongBridge(BondIndex bridge) const;
284 
288  bool operator == (const Graph& other) const;
289  inline bool operator != (const Graph& other) const {
290  return !(*this == other);
291  }
293 
296 
301  IteratorRange<AtomIterator> atoms() const;
307  IteratorRange<BondIterator> bonds() const;
315  IteratorRange<AdjacencyIterator> adjacents(AtomIndex a) const;
326 
334  MASM_NO_EXPORT PrivateGraph& inner();
335 
343  MASM_NO_EXPORT const PrivateGraph& inner() const;
344 
345 private:
346  std::unique_ptr<PrivateGraph> innerPtr_;
347 };
348 
349 } // namespace Molassembler
350 } // namespace Scine
351 
352 #endif
Defines basic types widely shared across the project.
Represents the connectivity of atoms of a molecule.
Definition: Graph.h:57
Templated iterator facade based on PrivateGraph to provide iterative access to atom indices and edge ...
Definition: Graph.h:75
AtomEnvironmentComponents
For bitmasks grouping components of immediate atom environments.
Definition: Types.h:103
Wrapper class to make working with RDL in C++ more pleasant.
Definition: Cycles.h:44
Homogeneous pair of iterators with begin and end member fns.
Definition: IteratorRange.h:26
Range type.
std::size_t AtomIndex
Unsigned integer atom index type. Used to refer to particular atoms.
Definition: Types.h:51
Library internal graph class wrapping BGL types.
Definition: PrivateGraph.h:24
BondType
Discrete bond type numeration.
Definition: Types.h:26
Type used to refer to particular bonds. Orders first &lt; second.
Definition: Types.h:54