RDKit: Canon.h Source File

| 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
19 namespace Canon {
20 const int MAX_NATOMS = 5000; //!< used in the canonical traversal code
21 const int MAX_CYCLES = 1000; //!< used in the canonical traversal code
22 const int MAX_BONDTYPE = 32; //!< used in the canonical traversal code
23
24//! used in traversals of the molecule
25 typedef enum {
26 WHITE_NODE = 0, //!< not visited
27 GREY_NODE, //!< visited, but not finished
28 BLACK_NODE, //!< visited and finished
29} AtomColors;
30
31//! used to indicate types of entries in the molecular stack:
32 typedef 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
38} MolStackTypes;
39
40//! used to store components in the molecular stack
41 typedef union {
42 Atom *atom;
43 Bond *bond;
44} MolStackUnion;
45
46//! these are the actual elements in the molecular stack
47 class RDKIT_GRAPHMOL_EXPORT MolStackElem {
48 public:
49 //! construct an Atom node
50 explicit MolStackElem(Atom *at) {
51 type = MOL_STACK_ATOM;
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) {
62 type = MOL_STACK_BOND;
63 obj.bond = bond;
64 number = idx;
65 }
66 //! construct for a ring closure
67 explicit MolStackElem(int idx) {
68 type = MOL_STACK_RING;
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 '(':
75 type = MOL_STACK_BRANCH_OPEN;
76 break;
77 case ')':
78 type = MOL_STACK_BRANCH_CLOSE;
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};
90 typedef std::vector<MolStackElem> MolStack;
91
92//! used to represent possible branches from an atom
93 typedef 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 */
109 RDKIT_GRAPHMOL_EXPORT void canonicalizeFragment(
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);
116
117//! Check if a chiral atom needs to have its tag flipped after reading or before
118//! writing SMILES
119 RDKIT_GRAPHMOL_EXPORT bool chiralAtomNeedsTagInversion(const RDKit::ROMol &mol,
120 const RDKit::Atom *atom,
121 bool isAtomFirst,
122 size_t numClosures);
123
124//! Canonicalizes the atom stereo labels in enhanced stereo groups
125/*!
126
127 For example, after calling this function the chiral centers in the
128 molecules `C[C@H](F)Cl |&1:1|` and `C[C@@H](F)Cl |&1:1|` will have the same
129 chiral tags.
130
131*/
132 RDKIT_GRAPHMOL_EXPORT void canonicalizeEnhancedStereo(
133 ROMol &mol, const std::vector<unsigned int> *atomRanks = nullptr);
134
135} // end of namespace Canon
136} // end of namespace RDKit
137#endif
RDKit::Atom
The class for representing atoms.
Definition Atom.h:74
RDKit::Bond
class for representing a bond
Definition Bond.h:46
RDKit::Canon::MolStackElem::type
MolStackTypes type
stores the type of node
Definition Canon.h:85
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(Atom *at)
construct an Atom node
Definition Canon.h:50
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(const char *chr, int idx)
construct for a branch opening or closing
Definition Canon.h:72
RDKit::Canon::MolStackElem::obj
MolStackUnion obj
holds our pointer (if appropriate)
Definition Canon.h:86
RDKit::Canon::MolStackElem::number
int number
stores our number (relevant for bonds and ring closures)
Definition Canon.h:87
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(int idx)
construct for a ring closure
Definition Canon.h:67
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(Bond *bond, int idx)
construct a bond node
Definition Canon.h:61
RDKit::ROMol
Definition ROMol.h:199
export.h
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:249
RDKit::Canon
Definition Canon.h:19
RDKit::Canon::PossibleType
std::tuple< int, int, Bond * > PossibleType
used to represent possible branches from an atom
Definition Canon.h:93
RDKit::Canon::MolStackTypes
MolStackTypes
used to indicate types of entries in the molecular stack:
Definition Canon.h:32
RDKit::Canon::MOL_STACK_BOND
@ MOL_STACK_BOND
a Bond
Definition Canon.h:34
RDKit::Canon::MOL_STACK_BRANCH_OPEN
@ MOL_STACK_BRANCH_OPEN
beginning of a branch
Definition Canon.h:36
RDKit::Canon::MOL_STACK_RING
@ MOL_STACK_RING
a ring closure
Definition Canon.h:35
RDKit::Canon::MOL_STACK_BRANCH_CLOSE
@ MOL_STACK_BRANCH_CLOSE
end of a branch
Definition Canon.h:37
RDKit::Canon::MOL_STACK_ATOM
@ MOL_STACK_ATOM
an Atom
Definition Canon.h:33
RDKit::Canon::MolStack
std::vector< MolStackElem > MolStack
Definition Canon.h:90
RDKit::Canon::chiralAtomNeedsTagInversion
RDKIT_GRAPHMOL_EXPORT bool chiralAtomNeedsTagInversion(const RDKit::ROMol &mol, const RDKit::Atom *atom, bool isAtomFirst, size_t numClosures)
RDKit::Canon::MAX_BONDTYPE
const int MAX_BONDTYPE
used in the canonical traversal code
Definition Canon.h:22
RDKit::Canon::MAX_CYCLES
const int MAX_CYCLES
used in the canonical traversal code
Definition Canon.h:21
RDKit::Canon::canonicalizeEnhancedStereo
RDKIT_GRAPHMOL_EXPORT void canonicalizeEnhancedStereo(ROMol &mol, const std::vector< unsigned int > *atomRanks=nullptr)
Canonicalizes the atom stereo labels in enhanced stereo groups.
RDKit::Canon::canonicalizeFragment
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
RDKit::Canon::AtomColors
AtomColors
used in traversals of the molecule
Definition Canon.h:25
RDKit::Canon::GREY_NODE
@ GREY_NODE
visited, but not finished
Definition Canon.h:27
RDKit::Canon::BLACK_NODE
@ BLACK_NODE
visited and finished
Definition Canon.h:28
RDKit::Canon::WHITE_NODE
@ WHITE_NODE
not visited
Definition Canon.h:26
RDKit::Canon::MAX_NATOMS
const int MAX_NATOMS
used in the canonical traversal code
Definition Canon.h:20
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::Canon::MolStackUnion
used to store components in the molecular stack
Definition Canon.h:41
RDKit::Canon::MolStackUnion::bond
Bond * bond
Definition Canon.h:43
RDKit::Canon::MolStackUnion::atom
Atom * atom
Definition Canon.h:42