Canon.h
Go to the documentation of this file.
//
// Copyright (C) 2004-2006 Rational Discovery LLC
//
// @@ 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_
#include <RDGeneral/BoostStartInclude.h>
#include <boost/tuple/tuple.hpp>
#include <boost/dynamic_bitset.hpp>
#include <RDGeneral/BoostEndInclude.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 boost::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);
//! 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);
} // end of namespace Canon
} // end of namespace RDKit
#endif
BoostEndInclude.h
BoostStartInclude.h
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:68
RDKit::Bond
class for representing a bond
Definition: Bond.h:46
RDKit::Canon::MolStackElem
these are the actual elements in the molecular stack
Definition: Canon.h:52
RDKit::Canon::MolStackElem::type
MolStackTypes type
stores the type of node
Definition: Canon.h:90
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(Atom *at)
construct an Atom node
Definition: Canon.h:55
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(const char *chr, int idx)
construct for a branch opening or closing
Definition: Canon.h:77
RDKit::Canon::MolStackElem::obj
MolStackUnion obj
holds our pointer (if appropriate)
Definition: Canon.h:91
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(int idx)
construct for a ring closure
Definition: Canon.h:72
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(Bond *bond, int idx)
construct a bond node
Definition: Canon.h:66
RDKit::ROMol
Definition: ROMol.h:178
export.h
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:209
RDKit::Canon::PossibleType
boost::tuple< int, int, Bond * > PossibleType
used to represent possible branches from an atom
Definition: Canon.h:98
RDKit::Canon::MolStackTypes
MolStackTypes
used to indicate types of entries in the molecular stack:
Definition: Canon.h:37
RDKit::Canon::MOL_STACK_BOND
@ MOL_STACK_BOND
a Bond
Definition: Canon.h:39
RDKit::Canon::MOL_STACK_BRANCH_OPEN
@ MOL_STACK_BRANCH_OPEN
beginning of a branch
Definition: Canon.h:41
RDKit::Canon::MOL_STACK_RING
@ MOL_STACK_RING
a ring closure
Definition: Canon.h:40
RDKit::Canon::MOL_STACK_BRANCH_CLOSE
@ MOL_STACK_BRANCH_CLOSE
end of a branch
Definition: Canon.h:42
RDKit::Canon::MOL_STACK_ATOM
@ MOL_STACK_ATOM
an Atom
Definition: Canon.h:38
RDKit::Canon::MolStack
std::vector< MolStackElem > MolStack
Definition: Canon.h:95
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:27
RDKit::Canon::MAX_CYCLES
const int MAX_CYCLES
used in the canonical traversal code
Definition: Canon.h:26
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)
constructs the canonical traversal order for a molecular fragment
RDKit::Canon::AtomColors
AtomColors
used in traversals of the molecule
Definition: Canon.h:30
RDKit::Canon::GREY_NODE
@ GREY_NODE
not visited
Definition: Canon.h:32
RDKit::Canon::BLACK_NODE
@ BLACK_NODE
visited, but not finished
Definition: Canon.h:33
RDKit::Canon::WHITE_NODE
@ WHITE_NODE
Definition: Canon.h:31
RDKit::Canon::MAX_NATOMS
const int MAX_NATOMS
used in the canonical traversal code
Definition: Canon.h:25
RDKit
Std stuff.
Definition: Abbreviations.h:18
RDKit::Canon::MolStackUnion
used to store components in the molecular stack
Definition: Canon.h:46
RDKit::Canon::MolStackUnion::bond
Bond * bond
Definition: Canon.h:48
RDKit::Canon::MolStackUnion::atom
Atom * atom
Definition: Canon.h:47