RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Digraph.h
Go to the documentation of this file.
1//
2// Digraph is the core data structure for determining
3// Cahn–Ingold–Prelog (CIP) chirality of a molecule.
4//
5// It's a "directed graph" - meaning that each bond
6// has a start and an end. For CIP determination,
7// the start points back towards the atom that is
8// being labelled.
9//
10// Copyright (C) 2020 Schrödinger, LLC
11//
12// @@ All Rights Reserved @@
13// This file is part of the RDKit.
14// The contents are covered by the terms of the BSD license
15// which is included in the file license.txt, found at the root
16// of the RDKit source tree.
17//
18#pragma once
19
20#include <list>
21#include <vector>
22
24#include <boost/rational.hpp>
26
28
29namespace RDKit {
30
31class Atom;
32class Bond;
33
34namespace CIPLabeler {
35
36class Node;
37class Edge;
38class CIPMol;
39
40/**
41 * A class to hold directed acyclic graphs representing the molecule.
42 *
43 * The root of the DAG is one of the foci of the configuration for
44 * which the label is being calculated. The tmproot may be set to
45 * other nodes that may become relevant in the calculation.
46 *
47 */
48class Digraph {
49 public:
50 Digraph() = delete;
51 Digraph(const Digraph &) = delete;
52 Digraph &operator=(const Digraph &) = delete;
53
54 Digraph(const CIPMol &mol, Atom *atom, bool atropsomerMode = false);
55
56 const CIPMol &getMol() const;
57
59
61
62 int getNumNodes() const;
63
64 /**
65 * Get all nodes which refer to `atom` in order of
66 * distance from the root.
67 */
68 std::vector<Node *> getNodes(Atom *atom) const;
69
70 /**
71 * Access the reference atom for Rule 6 (if one is set).
72 */
73 Atom *getRule6Ref() const;
74
75 /**
76 * Used exclusively for Rule 6, we set one atom as the reference.
77 * @param ref reference atom
78 */
79 void setRule6Ref(Atom *ref);
80
81 /**
82 * Sets the root node of this digraph by flipping the directions
83 * of edges as required.
84 *
85 * This is more efficient than building a new Digraph, but is
86 * only valid for neighboring Nodes.
87 *
88 * @param newroot the new root
89 */
91
92 void expand(Node *beg);
93
94 Node &addNode(std::vector<char> &&visit, Atom *atom,
95 boost::rational<int> &&frac, int dist, int flags);
96
97 private:
98 const CIPMol &d_mol;
99
100 // The node from which the Digraph is first initialized.
101 // It matches the atom that is being labeled.
102 Node *dp_origin = nullptr;
103
104 // in atropisomer mode, we expand the two atoms of the atrop bond
105
106 bool d_atropisomerMode = false;
107
108 // The current root of the Digraph
109 Node *dp_root = nullptr;
110
111 Atom *dp_rule6Ref = nullptr;
112
113 // We can't store these in a vector, as adding new items will
114 // cause it to reallocate and invalidate the references
115 std::list<Node> d_nodes;
116 std::list<Edge> d_edges;
117
118 void addEdge(Node *beg, Bond *bond, Node *end);
119};
120
121} // namespace CIPLabeler
122} // namespace RDKit
The class for representing atoms.
Definition Atom.h:75
class for representing a bond
Definition Bond.h:47
Digraph(const CIPMol &mol, Atom *atom, bool atropsomerMode=false)
Digraph & operator=(const Digraph &)=delete
void changeRoot(Node *newroot)
Node * getOriginalRoot() const
Node & addNode(std::vector< char > &&visit, Atom *atom, boost::rational< int > &&frac, int dist, int flags)
void setRule6Ref(Atom *ref)
Atom * getRule6Ref() const
const CIPMol & getMol() const
Node * getCurrentRoot() const
Digraph(const Digraph &)=delete
std::vector< Node * > getNodes(Atom *atom) const
Std stuff.
bool rdvalue_is(const RDValue_cast_t)