RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
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
16
namespace
RDKit
{
17
class
ROMol
;
18
class
Atom
;
19
class
Bond
;
20
21
namespace
Canon
{
22
constexpr
int
MAX_NATOMS
= 5000;
//!< used in the canonical traversal code
23
constexpr
int
MAX_CYCLES
= 1024;
//!< used in the canonical traversal code
24
constexpr
int
MAX_BONDTYPE
= 32;
//!< used in the canonical traversal code
25
26
//! used in traversals of the molecule
27
typedef
enum
{
28
WHITE_NODE
= 0,
//!< not visited
29
GREY_NODE
,
//!< visited, but not finished
30
BLACK_NODE
,
//!< visited and finished
31
}
AtomColors
;
32
33
//! used to indicate types of entries in the molecular stack:
34
typedef
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
40
}
MolStackTypes
;
41
42
//! used to store components in the molecular stack
43
typedef
union
{
44
Atom
*
atom
;
45
Bond
*
bond
;
46
}
MolStackUnion
;
47
48
//! these are the actual elements in the molecular stack
49
class
RDKIT_GRAPHMOL_EXPORT
MolStackElem
{
50
public
:
51
//! construct an Atom node
52
explicit
MolStackElem
(
Atom
*at) {
53
type
=
MOL_STACK_ATOM
;
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) {
64
type
=
MOL_STACK_BOND
;
65
obj
.bond = bond;
66
number
= idx;
67
}
68
//! construct for a ring closure
69
explicit
MolStackElem
(
int
idx) {
70
type
=
MOL_STACK_RING
;
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
'('
:
77
type
=
MOL_STACK_BRANCH_OPEN
;
78
break
;
79
case
')'
:
80
type
=
MOL_STACK_BRANCH_CLOSE
;
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
};
92
typedef
std::vector<MolStackElem>
MolStack
;
93
94
//! used to represent possible branches from an atom
95
typedef
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
*/
111
RDKIT_GRAPHMOL_EXPORT
void
canonicalizeFragment
(
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
);
118
RDKIT_GRAPHMOL_EXPORT
void
canonicalizeFragment
(
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
129
RDKIT_GRAPHMOL_EXPORT
bool
chiralAtomNeedsTagInversion
(
const
RDKit::ROMol
&mol,
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
*/
142
RDKIT_GRAPHMOL_EXPORT
void
canonicalizeEnhancedStereo
(
143
ROMol
&mol,
const
std::vector<unsigned int> *atomRanks =
nullptr
);
144
145
}
// end of namespace Canon
146
}
// end of namespace RDKit
147
#endif
RDKit::Atom
The class for representing atoms.
Definition
Atom.h:75
RDKit::Bond
class for representing a bond
Definition
Bond.h:48
RDKit::Canon::MolStackElem::type
MolStackTypes type
stores the type of node
Definition
Canon.h:87
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(Atom *at)
construct an Atom node
Definition
Canon.h:52
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(const char *chr, int idx)
construct for a branch opening or closing
Definition
Canon.h:74
RDKit::Canon::MolStackElem::obj
MolStackUnion obj
holds our pointer (if appropriate)
Definition
Canon.h:88
RDKit::Canon::MolStackElem::number
int number
stores our number (relevant for bonds and ring closures)
Definition
Canon.h:89
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(int idx)
construct for a ring closure
Definition
Canon.h:69
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(Bond *bond, int idx)
construct a bond node
Definition
Canon.h:63
RDKit::ROMol
Definition
ROMol.h:344
export.h
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition
export.h:321
RDKit::Canon
Definition
Canon.h:21
RDKit::Canon::MAX_CYCLES
constexpr int MAX_CYCLES
used in the canonical traversal code
Definition
Canon.h:23
RDKit::Canon::PossibleType
std::tuple< int, int, Bond * > PossibleType
used to represent possible branches from an atom
Definition
Canon.h:95
RDKit::Canon::MAX_BONDTYPE
constexpr int MAX_BONDTYPE
used in the canonical traversal code
Definition
Canon.h:24
RDKit::Canon::MolStackTypes
MolStackTypes
used to indicate types of entries in the molecular stack:
Definition
Canon.h:34
RDKit::Canon::MOL_STACK_BOND
@ MOL_STACK_BOND
a Bond
Definition
Canon.h:36
RDKit::Canon::MOL_STACK_BRANCH_OPEN
@ MOL_STACK_BRANCH_OPEN
beginning of a branch
Definition
Canon.h:38
RDKit::Canon::MOL_STACK_RING
@ MOL_STACK_RING
a ring closure
Definition
Canon.h:37
RDKit::Canon::MOL_STACK_BRANCH_CLOSE
@ MOL_STACK_BRANCH_CLOSE
end of a branch
Definition
Canon.h:39
RDKit::Canon::MOL_STACK_ATOM
@ MOL_STACK_ATOM
an Atom
Definition
Canon.h:35
RDKit::Canon::MolStack
std::vector< MolStackElem > MolStack
Definition
Canon.h:92
RDKit::Canon::chiralAtomNeedsTagInversion
RDKIT_GRAPHMOL_EXPORT bool chiralAtomNeedsTagInversion(const RDKit::ROMol &mol, const RDKit::Atom *atom, bool isAtomFirst, size_t numClosures)
RDKit::Canon::MAX_NATOMS
constexpr int MAX_NATOMS
used in the canonical traversal code
Definition
Canon.h:22
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:27
RDKit::Canon::GREY_NODE
@ GREY_NODE
visited, but not finished
Definition
Canon.h:29
RDKit::Canon::BLACK_NODE
@ BLACK_NODE
visited and finished
Definition
Canon.h:30
RDKit::Canon::WHITE_NODE
@ WHITE_NODE
not visited
Definition
Canon.h:28
RDKit
Std stuff.
Definition
Abbreviations.h:19
RDKit::Canon::MolStackUnion
used to store components in the molecular stack
Definition
Canon.h:43
RDKit::Canon::MolStackUnion::bond
Bond * bond
Definition
Canon.h:45
RDKit::Canon::MolStackUnion::atom
Atom * atom
Definition
Canon.h:44
GraphMol
Canon.h
Generated on
for RDKit by
1.17.0