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
14namespace RDKit {
15class ROMol;
16class Atom;
17class Bond;
18
19namespace Canon {
20constexpr int MAX_NATOMS = 5000; //!< used in the canonical traversal code
21constexpr int MAX_CYCLES = 1024; //!< used in the canonical traversal code
22constexpr int MAX_BONDTYPE = 32; //!< used in the canonical traversal code
23
24//! used in traversals of the molecule
25typedef enum {
26 WHITE_NODE = 0, //!< not visited
27 GREY_NODE, //!< visited, but not finished
28 BLACK_NODE, //!< visited and finished
30
31//! used to indicate types of entries in the molecular stack:
32typedef enum {
33 MOL_STACK_ATOM = 0, //!< an Atom
34 MOL_STACK_BOND, //!< a Bond
35 MOL_STACK_RING, //!< a ring closure
36 MOL_STACK_BRANCH_OPEN, //!< beginning of a branch
37 MOL_STACK_BRANCH_CLOSE, //!< end of a branch
39
40//! used to store components in the molecular stack
41typedef union {
45
46//! these are the actual elements in the molecular stack
48 public:
49 //! construct an Atom node
50 explicit MolStackElem(Atom *at) {
52 obj.atom = at;
53 }
54 //! construct a bond node
55 /*!
56
57 \param bond pointer to the Bond being added
58 \param idx index of the Atom traversed before this Bond
59 (beginAtom in the canonical traversal order)
60 */
61 explicit MolStackElem(Bond *bond, int idx) {
63 obj.bond = bond;
64 number = idx;
65 }
66 //! construct for a ring closure
67 explicit MolStackElem(int idx) {
69 number = idx;
70 }
71 //! construct for a branch opening or closing
72 explicit MolStackElem(const char *chr, int idx) {
73 switch (chr[0]) {
74 case '(':
76 break;
77 case ')':
79 break;
80 default:
81 break;
82 }
83 number = idx;
84 }
85 MolStackTypes type; //!< stores the type of node
86 MolStackUnion obj; //!< holds our pointer (if appropriate)
87 int number =
88 -1; //!< stores our number (relevant for bonds and ring closures)
89};
90typedef std::vector<MolStackElem> MolStack;
91
92//! used to represent possible branches from an atom
93typedef std::tuple<int, int, Bond *> PossibleType;
94
95//! constructs the canonical traversal order for a molecular fragment
96/*!
97
98 \param mol the ROMol we're working on
99 \param atomIdx the index of the atom to start the traversal from
100 \param colors the traversal status of each atom in \c mol
101 \param ranks the assigned rank of each atom in \c mol
102 \param molStack the current traversal stack (used to return the results)
103
104 <b>Notes</b>
105 - \c mol will, in general, be modified by this operation as bond directions
106 and the like are changed to fit the canonical traversal order
107
108 */
110 ROMol &mol, int atomIdx, std::vector<AtomColors> &colors,
111 const std::vector<unsigned int> &ranks, MolStack &molStack,
112 const boost::dynamic_bitset<> *bondsInPlay = nullptr,
113 const std::vector<std::string> *bondSymbols = nullptr,
114 bool doIsomericSmiles = false, bool doRandom = false,
115 bool doChiralInversions = true);
117 ROMol &mol, int atomIdx, std::vector<AtomColors> &colors,
118 const std::vector<unsigned int> &ranks, MolStack &molStack,
119 const boost::dynamic_bitset<> *atomsInPlay,
120 const boost::dynamic_bitset<> *bondsInPlay,
121 const std::vector<std::string> *bondSymbols = nullptr,
122 bool doIsomericSmiles = false, bool doRandom = false,
123 bool doChiralInversions = true);
124
125//! Check if a chiral atom needs to have its tag flipped after reading or before
126//! writing SMILES
128 const RDKit::Atom *atom,
129 bool isAtomFirst,
130 size_t numClosures);
131
132//! Canonicalizes the atom stereo labels in enhanced stereo groups
133/*!
134
135 For example, after calling this function the chiral centers in the
136 molecules `C[C@H](F)Cl |&1:1|` and `C[C@@H](F)Cl |&1:1|` will have the same
137 chiral tags.
138
139*/
141 ROMol &mol, const std::vector<unsigned int> *atomRanks = nullptr);
142
143} // end of namespace Canon
144} // end of namespace RDKit
145#endif
The class for representing atoms.
Definition Atom.h:74
class for representing a bond
Definition Bond.h:46
MolStackTypes type
stores the type of node
Definition Canon.h:85
MolStackElem(Atom *at)
construct an Atom node
Definition Canon.h:50
MolStackElem(const char *chr, int idx)
construct for a branch opening or closing
Definition Canon.h:72
MolStackUnion obj
holds our pointer (if appropriate)
Definition Canon.h:86
int number
stores our number (relevant for bonds and ring closures)
Definition Canon.h:87
MolStackElem(int idx)
construct for a ring closure
Definition Canon.h:67
MolStackElem(Bond *bond, int idx)
construct a bond node
Definition Canon.h:61
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:257
constexpr int MAX_CYCLES
used in the canonical traversal code
Definition Canon.h:21
std::tuple< int, int, Bond * > PossibleType
used to represent possible branches from an atom
Definition Canon.h:93
constexpr int MAX_BONDTYPE
used in the canonical traversal code
Definition Canon.h:22
MolStackTypes
used to indicate types of entries in the molecular stack:
Definition Canon.h:32
@ MOL_STACK_BOND
a Bond
Definition Canon.h:34
@ MOL_STACK_BRANCH_OPEN
beginning of a branch
Definition Canon.h:36
@ MOL_STACK_RING
a ring closure
Definition Canon.h:35
@ MOL_STACK_BRANCH_CLOSE
end of a branch
Definition Canon.h:37
@ MOL_STACK_ATOM
an Atom
Definition Canon.h:33
std::vector< MolStackElem > MolStack
Definition Canon.h:90
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:20
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:25
@ GREY_NODE
visited, but not finished
Definition Canon.h:27
@ BLACK_NODE
visited and finished
Definition Canon.h:28
@ WHITE_NODE
not visited
Definition Canon.h:26
Std stuff.
used to store components in the molecular stack
Definition Canon.h:41