Molassembler  3.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 
13 
14 #include <memory>
15 #include <vector>
16 
17 namespace Scine {
18 // Forward-declarations
19 namespace Utils {
20 using ElementTypeCollection = std::vector<ElementType>;
21 class BondOrderCollection;
22 } // namespace Utils
23 
24 namespace Molassembler {
25 
26 // Forward-declare PrivateGraph
27 class PrivateGraph;
28 class Cycles;
29 
54 class MASM_EXPORT Graph final : public GraphInterface {
55 public:
58 
71  template<typename T, bool isVertexInitialized>
73  public:
74  static_assert(
75  std::is_same<T, AtomIndex>::value || std::is_same<T, BondIndex>::value,
76  "You may not instantiate this type for other Ts than AtomIndex or BondIndex"
77  );
78 
79  using iterator_category = std::forward_iterator_tag;
80  using difference_type = std::ptrdiff_t;
81  using value_type = T;
82  using pointer = T;
83  using reference = T;
84 
85  InnerBasedIterator(InnerBasedIterator&& other) noexcept;
86  InnerBasedIterator& operator = (InnerBasedIterator&& other) noexcept;
88  InnerBasedIterator& operator = (const InnerBasedIterator& other);
90 
91  // Default constructor
93 
94  /* We want to use this iterator facade in four ways:
95  *
96  * Iterate through all valid atom indices: (graph) -> AtomIndex
97  * Iterate through all valid bond indices: (graph) -> BondIndex
98  * Iterate through all atom indices adjacent to i: (graph, i) -> AtomIndex
99  * Iterate through all bonds incident on i: (graph, i) -> BondIndex
100  *
101  * So, we template and enable-if constructors for the cases that the
102  * template parameter isVertexInitialized (which denotes whether
103  * additionally to the graph, a vertex descriptor is required in the
104  * constructor):
105  */
106 
117  template<bool Dependent = isVertexInitialized, std::enable_if_t<!Dependent, int>...>
118  InnerBasedIterator(const PrivateGraph& inner, bool begin);
119 
132  template<bool Dependent = isVertexInitialized, std::enable_if_t<Dependent, int>...>
133  InnerBasedIterator(AtomIndex a, const PrivateGraph& inner, bool begin);
134 
136  InnerBasedIterator& operator ++ ();
138  InnerBasedIterator operator ++ (int);
140  value_type operator * () const;
141 
143  bool operator == (const InnerBasedIterator& other) const;
145  bool operator != (const InnerBasedIterator& other) const;
146 
147  private:
148  struct Impl;
149  std::unique_ptr<Impl> pImpl_;
150  };
151 
161 
164  Graph(Graph&& other) noexcept;
165  Graph& operator = (Graph&& other) noexcept;
166  Graph(const Graph& other);
167  Graph& operator = (const Graph& other);
168  ~Graph() final;
170 
173  Graph();
175  explicit Graph(PrivateGraph&& inner);
177 
180  AtomIndex addAtom(Utils::ElementType e, AtomIndex i, BondType type) final;
181 
182  BondIndex addBond(AtomIndex i, AtomIndex j, BondType type) final;
183 
184  void setElementType(AtomIndex i, Utils::ElementType type) final;
185 
186  bool setBondType(AtomIndex i, AtomIndex j, BondType type) final;
187 
188  void removeAtom(AtomIndex i) final;
189 
190  void removeBond(const BondIndex& bond) final;
192 
195 
199  bool adjacent(AtomIndex a, AtomIndex b) const final;
204  std::vector<AtomIndex> atomsOfElement(Utils::ElementType e) const;
209  boost::optional<BondIndex> bond(AtomIndex a, AtomIndex b) const final;
214  Utils::BondOrderCollection bondOrders() const;
219  BondType bondType(const BondIndex& edge) const final;
227  bool canRemove(AtomIndex a) const final;
235  bool canRemove(const BondIndex& edge) const final;
243  const Cycles& cycles() const final;
248  unsigned degree(AtomIndex a) const final;
250  std::string dumpGraphviz() const;
255  Utils::ElementTypeCollection elementCollection() const;
260  Utils::ElementType elementType(AtomIndex a) const final;
261 
266  [[deprecated("Prefer V")]]
267  AtomIndex N() const;
268 
273  AtomIndex V() const final;
278  [[deprecated("Prefer E")]]
279  unsigned B() const;
280 
285  unsigned E() const final;
286 
292  boost::optional<std::vector<AtomIndex>> modularIsomorphism(
293  const Graph& other,
295  ) const;
296 
305  std::pair<
306  std::vector<AtomIndex>,
307  std::vector<AtomIndex>
308  > splitAlongBridge(BondIndex bridge) const;
310 
314  bool operator == (const Graph& other) const;
315  inline bool operator != (const Graph& other) const {
316  return !(*this == other);
317  }
319 
322 
327  IteratorRange<AtomIterator> atoms() const;
333  IteratorRange<BondIterator> bonds() const;
341  IteratorRange<AdjacencyIterator> adjacents(AtomIndex a) const;
352 
360  MASM_NO_EXPORT PrivateGraph& inner();
361 
369  MASM_NO_EXPORT const PrivateGraph& inner() const;
370 
371 private:
372  std::unique_ptr<PrivateGraph> innerPtr_;
373 };
374 
375 } // namespace Molassembler
376 } // namespace Scine
377 
378 #endif
Interface class for the molecular graph.
Represents the connectivity of atoms of a molecule.
Definition: Graph.h:54
Templated iterator facade based on PrivateGraph to provide iterative access to atom indices and edge ...
Definition: Graph.h:72
AtomEnvironmentComponents
For bitmasks grouping components of immediate atom environments.
Definition: Types.h:103
Definition: GraphInterface.h:21
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:26
BondType
Discrete bond type numeration.
Definition: Types.h:26
Type used to refer to particular bonds. Orders first &lt; second.
Definition: Types.h:54