Loading...
Searching...
No Matches
Canon.h
Go to the documentation of this file.
//
// Copyright (C) 2004-2022 Greg Landrum and other RDKit contributors
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <RDGeneral/export.h>
#ifndef RD_CANON_H
#define RD_CANON_H
namespace RDKit {
class ROMol;
class Atom;
class Bond;
namespace Canon {
const int MAX_NATOMS = 5000; //!< used in the canonical traversal code
const int MAX_CYCLES = 1000; //!< used in the canonical traversal code
const int MAX_BONDTYPE = 32; //!< used in the canonical traversal code
//! used in traversals of the molecule
typedef enum {
WHITE_NODE = 0, //!< not visited
GREY_NODE, //!< visited, but not finished
BLACK_NODE, //!< visited and finished
} AtomColors;
//! used to indicate types of entries in the molecular stack:
typedef enum {
MOL_STACK_ATOM = 0, //!< an Atom
MOL_STACK_BOND, //!< a Bond
MOL_STACK_RING, //!< a ring closure
MOL_STACK_BRANCH_OPEN, //!< beginning of a branch
MOL_STACK_BRANCH_CLOSE, //!< end of a branch
} MolStackTypes;
//! used to store components in the molecular stack
typedef union {
Atom *atom;
Bond *bond;
} MolStackUnion;
//! these are the actual elements in the molecular stack
class RDKIT_GRAPHMOL_EXPORT MolStackElem {
public:
//! construct an Atom node
explicit MolStackElem(Atom *at) {
type = MOL_STACK_ATOM;
obj.atom = at;
}
//! construct a bond node
/*!
\param bond pointer to the Bond being added
\param idx index of the Atom traversed before this Bond
(beginAtom in the canonical traversal order)
*/
explicit MolStackElem(Bond *bond, int idx) {
type = MOL_STACK_BOND;
obj.bond = bond;
number = idx;
}
//! construct for a ring closure
explicit MolStackElem(int idx) {
type = MOL_STACK_RING;
number = idx;
}
//! construct for a branch opening or closing
explicit MolStackElem(const char *chr, int idx) {
switch (chr[0]) {
case '(':
type = MOL_STACK_BRANCH_OPEN;
break;
case ')':
type = MOL_STACK_BRANCH_CLOSE;
break;
default:
break;
}
number = idx;
}
MolStackTypes type; //!< stores the type of node
MolStackUnion obj; //!< holds our pointer (if appropriate)
int number =
-1; //!< stores our number (relevant for bonds and ring closures)
};
typedef std::vector<MolStackElem> MolStack;
//! used to represent possible branches from an atom
typedef std::tuple<int, int, Bond *> PossibleType;
//! constructs the canonical traversal order for a molecular fragment
/*!
\param mol the ROMol we're working on
\param atomIdx the index of the atom to start the traversal from
\param colors the traversal status of each atom in \c mol
\param ranks the assigned rank of each atom in \c mol
\param molStack the current traversal stack (used to return the results)
<b>Notes</b>
- \c mol will, in general, be modified by this operation as bond directions
and the like are changed to fit the canonical traversal order
*/
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);
//! Check if a chiral atom needs to have its tag flipped after reading or before
//! writing SMILES
RDKIT_GRAPHMOL_EXPORT bool chiralAtomNeedsTagInversion(const RDKit::ROMol &mol,
const RDKit::Atom *atom,
bool isAtomFirst,
size_t numClosures);
//! Canonicalizes the atom stereo labels in enhanced stereo groups
/*!
For example, after calling this function the chiral centers in the
molecules `C[C@H](F)Cl |&1:1|` and `C[C@@H](F)Cl |&1:1|` will have the same
chiral tags.
*/
RDKIT_GRAPHMOL_EXPORT void canonicalizeEnhancedStereo(
ROMol &mol, const std::vector<unsigned int> *atomRanks = nullptr);
} // end of namespace Canon
} // end of namespace RDKit
#endif
RDKit::Atom
The class for representing atoms.
Definition Atom.h:75
RDKit::Bond
class for representing a bond
Definition Bond.h:47
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