RDKit: Digraph.h Source File

| 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
23#include <RDGeneral/BoostStartInclude.h>
24#include <boost/rational.hpp>
25#include <RDGeneral/BoostEndInclude.h>
26
27#include "TooManyNodesException.h"
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 */
48 class 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
58 Node *getOriginalRoot() const;
59
60 Node *getCurrentRoot() const;
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 */
90 void changeRoot(Node *newroot);
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
BoostEndInclude.h
BoostStartInclude.h
TooManyNodesException.h
RDKit::Atom
The class for representing atoms.
Definition Atom.h:74
RDKit::Bond
class for representing a bond
Definition Bond.h:46
RDKit::CIPLabeler::CIPMol
Definition CIPMol.h:66
RDKit::CIPLabeler::Digraph::Digraph
Digraph(const CIPMol &mol, Atom *atom, bool atropsomerMode=false)
RDKit::CIPLabeler::Digraph::operator=
Digraph & operator=(const Digraph &)=delete
RDKit::CIPLabeler::Digraph::changeRoot
void changeRoot(Node *newroot)
RDKit::CIPLabeler::Digraph::getOriginalRoot
Node * getOriginalRoot() const
RDKit::CIPLabeler::Digraph::addNode
Node & addNode(std::vector< char > &&visit, Atom *atom, boost::rational< int > &&frac, int dist, int flags)
RDKit::CIPLabeler::Digraph::setRule6Ref
void setRule6Ref(Atom *ref)
RDKit::CIPLabeler::Digraph::getRule6Ref
Atom * getRule6Ref() const
RDKit::CIPLabeler::Digraph::expand
void expand(Node *beg)
RDKit::CIPLabeler::Digraph::getMol
const CIPMol & getMol() const
RDKit::CIPLabeler::Digraph::getCurrentRoot
Node * getCurrentRoot() const
RDKit::CIPLabeler::Digraph::Digraph
Digraph(const Digraph &)=delete
RDKit::CIPLabeler::Digraph::Digraph
Digraph()=delete
RDKit::CIPLabeler::Digraph::getNumNodes
int getNumNodes() const
RDKit::CIPLabeler::Digraph::getNodes
std::vector< Node * > getNodes(Atom *atom) const
RDKit::CIPLabeler::Edge
Definition Edge.h:23
RDKit::CIPLabeler::Node
Definition Node.h:27
RDKit::CIPLabeler
Definition CIPLabeler.h:27
RDKit
Std stuff.
Definition Abbreviations.h:19