RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Canon.h
Go to the documentation of this file.
1//
2// Copyright (C) 2004-2022 Greg Landrum and other RDKit contributors
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10#include <RDGeneral/export.h>
11#ifndef RD_CANON_H
12#define RD_CANON_H
13#include <boost/dynamic_bitset.hpp>
14#include <vector>
15
16namespace RDKit {
17class ROMol;
18class Atom;
19class Bond;
20
21namespace Canon {
22constexpr int MAX_NATOMS = 5000; //!< used in the canonical traversal code
23constexpr int MAX_CYCLES = 1024; //!< used in the canonical traversal code
24constexpr int MAX_BONDTYPE = 32; //!< used in the canonical traversal code
25
26//! used in traversals of the molecule
27typedef enum {
28 WHITE_NODE = 0, //!< not visited
29 GREY_NODE, //!< visited, but not finished
30 BLACK_NODE, //!< visited and finished
32
33//! used to indicate types of entries in the molecular stack:
34typedef enum {
35 MOL_STACK_ATOM = 0, //!< an Atom
36 MOL_STACK_BOND, //!< a Bond
37 MOL_STACK_RING, //!< a ring closure
38 MOL_STACK_BRANCH_OPEN, //!< beginning of a branch
39 MOL_STACK_BRANCH_CLOSE, //!< end of a branch
41
42//! used to store components in the molecular stack
43typedef union {
47
48//! these are the actual elements in the molecular stack
50 public:
51 //! construct an Atom node
52 explicit MolStackElem(Atom *at) {
54 obj.atom = at;
55 }
56 //! construct a bond node
57 /*!
58
59 \param bond pointer to the Bond being added
60 \param idx index of the Atom traversed before this Bond
61 (beginAtom in the canonical traversal order)
62 */
63 explicit MolStackElem(Bond *bond, int idx) {
65 obj.bond = bond;
66 number = idx;
67 }
68 //! construct for a ring closure
69 explicit MolStackElem(int idx) {
71 number = idx;
72 }
73 //! construct for a branch opening or closing
74 explicit MolStackElem(const char *chr, int idx) {
75 switch (chr[0]) {
76 case '(':
78 break;
79 case ')':
81 break;
82 default:
83 break;
84 }
85 number = idx;
86 }
87 MolStackTypes type; //!< stores the type of node
88 MolStackUnion obj; //!< holds our pointer (if appropriate)
89 int number =
90 -1; //!< stores our number (relevant for bonds and ring closures)
91};
92typedef std::vector<MolStackElem> MolStack;
93
94//! used to represent possible branches from an atom
95typedef std::tuple<int, int, Bond *> PossibleType;
96
97//! constructs the canonical traversal order for a molecular fragment
98/*!
99
100 \param mol the ROMol we're working on
101 \param atomIdx the index of the atom to start the traversal from
102 \param colors the traversal status of each atom in \c mol
103 \param ranks the assigned rank of each atom in \c mol
104 \param molStack the current traversal stack (used to return the results)
105
106 <b>Notes</b>
107 - \c mol will, in general, be modified by this operation as bond directions
108 and the like are changed to fit the canonical traversal order
109
110 */
112 ROMol &mol, int atomIdx, std::vector<AtomColors> &colors,
113 const std::vector<unsigned int> &ranks, MolStack &molStack,
114 const boost::dynamic_bitset<> *bondsInPlay = nullptr,
115 const std::vector<std::string> *bondSymbols = nullptr,
116 bool doIsomericSmiles = false, bool doRandom = false,
117 bool doChiralInversions = true);
119 ROMol &mol, int atomIdx, std::vector<AtomColors> &colors,
120 const std::vector<unsigned int> &ranks, MolStack &molStack,
121 const boost::dynamic_bitset<> *atomsInPlay,
122 const boost::dynamic_bitset<> *bondsInPlay,
123 const std::vector<std::string> *bondSymbols = nullptr,
124 bool doIsomericSmiles = false, bool doRandom = false,
125 bool doChiralInversions = true);
126
127//! Check if a chiral atom needs to have its tag flipped after reading or before
128//! writing SMILES
130 const RDKit::Atom *atom,
131 bool isAtomFirst,
132 size_t numClosures);
133
134//! Canonicalizes the atom stereo labels in enhanced stereo groups
135/*!
136
137 For example, after calling this function the chiral centers in the
138 molecules `C[C@H](F)Cl |&1:1|` and `C[C@@H](F)Cl |&1:1|` will have the same
139 chiral tags.
140
141*/
143 ROMol &mol, const std::vector<unsigned int> *atomRanks = nullptr);
144
145} // end of namespace Canon
146} // end of namespace RDKit
147#endif
The class for representing atoms.
Definition Atom.h:75
class for representing a bond
Definition Bond.h:48
MolStackTypes type
stores the type of node
Definition Canon.h:87
MolStackElem(Atom *at)
construct an Atom node
Definition Canon.h:52
MolStackElem(const char *chr, int idx)
construct for a branch opening or closing
Definition Canon.h:74
MolStackUnion obj
holds our pointer (if appropriate)
Definition Canon.h:88
int number
stores our number (relevant for bonds and ring closures)
Definition Canon.h:89
MolStackElem(int idx)
construct for a ring closure
Definition Canon.h:69
MolStackElem(Bond *bond, int idx)
construct a bond node
Definition Canon.h:63
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:321
constexpr int MAX_CYCLES
used in the canonical traversal code
Definition Canon.h:23
std::tuple< int, int, Bond * > PossibleType
used to represent possible branches from an atom
Definition Canon.h:95
constexpr int MAX_BONDTYPE
used in the canonical traversal code
Definition Canon.h:24
MolStackTypes
used to indicate types of entries in the molecular stack:
Definition Canon.h:34
@ MOL_STACK_BOND
a Bond
Definition Canon.h:36
@ MOL_STACK_BRANCH_OPEN
beginning of a branch
Definition Canon.h:38
@ MOL_STACK_RING
a ring closure
Definition Canon.h:37
@ MOL_STACK_BRANCH_CLOSE
end of a branch
Definition Canon.h:39
@ MOL_STACK_ATOM
an Atom
Definition Canon.h:35
std::vector< MolStackElem > MolStack
Definition Canon.h:92
RDKIT_GRAPHMOL_EXPORT bool chiralAtomNeedsTagInversion(const RDKit::ROMol &mol, const RDKit::Atom *atom, bool isAtomFirst, size_t numClosures)
constexpr int MAX_NATOMS
used in the canonical traversal code
Definition Canon.h:22
RDKIT_GRAPHMOL_EXPORT void canonicalizeEnhancedStereo(ROMol &mol, const std::vector< unsigned int > *atomRanks=nullptr)
Canonicalizes the atom stereo labels in enhanced stereo groups.
RDKIT_GRAPHMOL_EXPORT void canonicalizeFragment(ROMol &mol, int atomIdx, std::vector< AtomColors > &colors, const std::vector< unsigned int > &ranks, MolStack &molStack, const boost::dynamic_bitset<> *bondsInPlay=nullptr, const std::vector< std::string > *bondSymbols=nullptr, bool doIsomericSmiles=false, bool doRandom=false, bool doChiralInversions=true)
constructs the canonical traversal order for a molecular fragment
AtomColors
used in traversals of the molecule
Definition Canon.h:27
@ GREY_NODE
visited, but not finished
Definition Canon.h:29
@ BLACK_NODE
visited and finished
Definition Canon.h:30
@ WHITE_NODE
not visited
Definition Canon.h:28
Std stuff.
used to store components in the molecular stack
Definition Canon.h:43