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 <cstdint>
21#include <list>
22#include <vector>
23
25#include <boost/rational.hpp>
27
29
30namespace RDKit {
31
32class Atom;
33class Bond;
34
35namespace CIPLabeler {
36
37class Node;
38class Edge;
39class CIPMol;
40
41/**
42 * A class to hold directed acyclic graphs representing the molecule.
43 *
44 * The root of the DAG is one of the foci of the configuration for
45 * which the label is being calculated. The tmproot may be set to
46 * other nodes that may become relevant in the calculation.
47 *
48 */
49class Digraph {
50 public:
51 Digraph() = delete;
52 Digraph(const Digraph &) = delete;
53 Digraph &operator=(const Digraph &) = delete;
54
55 Digraph(const CIPMol &mol, Atom *atom, bool atropsomerMode = false);
56 Digraph(CIPMol &&mol, Atom *atom, bool atropsomerMode = false) = delete;
57 Digraph(const CIPMol &&mol, Atom *atom, bool atropsomerMode = false) = delete;
58
59 const CIPMol &getMol() const;
60
62
64
65 int getNumNodes() const;
66
67 /**
68 * Get all nodes which refer to `atom` in order of
69 * distance from the root.
70 */
71 std::vector<Node *> getNodes(Atom *atom) const;
72
73 /**
74 * Access the reference atom for Rule 6 (if one is set).
75 */
76 Atom *getRule6Ref() const;
77
78 /**
79 * Used exclusively for Rule 6, we set one atom as the reference.
80 * @param ref reference atom
81 */
82 void setRule6Ref(Atom *ref);
83
84 /**
85 * Sets the root node of this digraph by flipping the directions
86 * of edges as required.
87 *
88 * This is more efficient than building a new Digraph, but is
89 * only valid for neighboring Nodes.
90 *
91 * @param newroot the new root
92 */
93 void changeRoot(Node *newroot);
94
95 void expand(Node *beg);
96
97 Node &addNode(std::vector<std::uint32_t> &&visit, Atom *atom,
98 boost::rational<int> &&frac, int dist, uint8_t flags);
99
100 // Has `atom` been seen yet?
101 bool seenAtom(Atom *atom) const;
102
103 private:
104 const CIPMol &d_mol;
105
106 // The node from which the Digraph is first initialized.
107 // It matches the atom that is being labeled.
108 Node *dp_origin = nullptr;
109
110 // in atropisomer mode, we expand the two atoms of the atrop bond
111
112 bool d_atropisomerMode = false;
113
114 // The current root of the Digraph
115 Node *dp_root = nullptr;
116
117 Atom *dp_rule6Ref = nullptr;
118
119 // We can't store these in a vector, as adding new items will
120 // cause it to reallocate and invalidate the references
121 std::list<Node> d_nodes;
122 std::list<Edge> d_edges;
123
124 void addEdge(Node *beg, Bond *bond, Node *end);
125};
126
127} // namespace CIPLabeler
128} // namespace RDKit
The class for representing atoms.
Definition Atom.h:75
class for representing a bond
Definition Bond.h:48
Digraph(const CIPMol &mol, Atom *atom, bool atropsomerMode=false)
Digraph & operator=(const Digraph &)=delete
void changeRoot(Node *newroot)
Node * getOriginalRoot() const
void setRule6Ref(Atom *ref)
Atom * getRule6Ref() const
Digraph(const CIPMol &&mol, Atom *atom, bool atropsomerMode=false)=delete
const CIPMol & getMol() const
Node * getCurrentRoot() const
Digraph(CIPMol &&mol, Atom *atom, bool atropsomerMode=false)=delete
bool seenAtom(Atom *atom) const
Digraph(const Digraph &)=delete
Node & addNode(std::vector< std::uint32_t > &&visit, Atom *atom, boost::rational< int > &&frac, int dist, uint8_t flags)
std::vector< Node * > getNodes(Atom *atom) const
Std stuff.