RDKit: Canon.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Canon.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 Rational Discovery LLC
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 #ifndef _RD_CANON_H_
11 #define _RD_CANON_H_
12
13 #include <boost/tuple/tuple.hpp>
14 #include <boost/dynamic_bitset.hpp>
15
16 namespace RDKit {
17 class ROMol;
18 class Atom;
19 class Bond;
20
21 namespace Canon {
22 const int MAX_NATOMS = 5000; //!< used in the canonical traversal code
23 const int MAX_CYCLES = 1000; //!< used in the canonical traversal code
24 const 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 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; //!< stores our number (relevant for bonds and ring closures)
90 };
91 typedef std::vector<MolStackElem> MolStack;
92
93 //! used to represent possible branches from an atom
94 typedef boost::tuple<int, int, Bond *> PossibleType;
95
96 //! constructs the canonical traversal order for a molecular fragment
97 /*!
98
99 \param mol the ROMol we're working on
100 \param atomIdx the index of the atom to start the traversal from
101 \param colors the traversal status of each atom in \c mol
102 \param ranks the assigned rank of each atom in \c mol
103 \param molStack the current traversal stack (used to return the results)
104
105 <b>Notes</b>
106 - \c mol will, in general, be modified by this operation as bond directions
107 and the like are changed to fit the canonical traversal order
108
109 */
110 void canonicalizeFragment(ROMol &mol, int atomIdx,
111 std::vector<AtomColors> &colors,
112 const std::vector<unsigned int> &ranks,
113 MolStack &molStack,
114 const boost::dynamic_bitset<> *bondsInPlay = 0,
115 const std::vector<std::string> *bondSymbols = 0,
116 bool doIsomericSmiles = false);
117
118 } // end of namespace Canon
119 } // end of namespace RDKit
120 #endif
RDKit::Canon::MAX_CYCLES
const int MAX_CYCLES
used in the canonical traversal code
Definition: Canon.h:23
RDKit::Canon::MolStackElem::number
int number
stores our number (relevant for bonds and ring closures)
Definition: Canon.h:89
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(Atom *at)
construct an Atom node
Definition: Canon.h:52
RDKit::Canon::MOL_STACK_ATOM
an Atom
Definition: Canon.h:35
RDKit::Canon::AtomColors
AtomColors
used in traversals of the molecule
Definition: Canon.h:27
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(Bond *bond, int idx)
construct a bond node
Definition: Canon.h:63
RDKit::Canon::MolStackUnion
used to store components in the molecular stack
Definition: Canon.h:43
RDKit::Canon::PossibleType
boost::tuple< int, int, Bond * > PossibleType
used to represent possible branches from an atom
Definition: Canon.h:94
RDKit::Canon::MolStackElem
these are the actual elements in the molecular stack
Definition: Canon.h:49
RDKit::ROMol
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:102
RDKit::Canon::MolStackElem::obj
MolStackUnion obj
holds our pointer (if appropriate)
Definition: Canon.h:88
RDKit::Canon::canonicalizeFragment
void canonicalizeFragment(ROMol &mol, int atomIdx, std::vector< AtomColors > &colors, const std::vector< unsigned int > &ranks, MolStack &molStack, const boost::dynamic_bitset<> *bondsInPlay=0, const std::vector< std::string > *bondSymbols=0, bool doIsomericSmiles=false)
constructs the canonical traversal order for a molecular fragment
RDKit::Canon::WHITE_NODE
Definition: Canon.h:28
RDKit::Canon::BLACK_NODE
visited, but not finished
Definition: Canon.h:30
RDKit::Canon::GREY_NODE
not visited
Definition: Canon.h:29
RDKit::Canon::MOL_STACK_RING
a ring closure
Definition: Canon.h:37
RDKit::Canon::MolStackElem::type
MolStackTypes type
stores the type of node
Definition: Canon.h:87
RDKit
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
RDKit::Canon::MolStackTypes
MolStackTypes
used to indicate types of entries in the molecular stack:
Definition: Canon.h:34
RDKit::Canon::MOL_STACK_BRANCH_OPEN
beginning of a branch
Definition: Canon.h:38
RDKit::Canon::MolStackUnion::bond
Bond * bond
Definition: Canon.h:45
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(const char *chr, int idx)
construct for a branch opening or closing
Definition: Canon.h:74
RDKit::Bond
class for representing a bond
Definition: Bond.h:46
RDKit::Canon::MAX_BONDTYPE
const int MAX_BONDTYPE
used in the canonical traversal code
Definition: Canon.h:24
RDKit::Canon::MolStackElem::MolStackElem
MolStackElem(int idx)
construct for a ring closure
Definition: Canon.h:69
RDKit::Canon::MOL_STACK_BRANCH_CLOSE
end of a branch
Definition: Canon.h:39
RDKit::Canon::MOL_STACK_BOND
a Bond
Definition: Canon.h:36
RDKit::Canon::MAX_NATOMS
const int MAX_NATOMS
used in the canonical traversal code
Definition: Canon.h:22
RDKit::Canon::MolStack
std::vector< MolStackElem > MolStack
Definition: Canon.h:91
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:67
RDKit::Canon::MolStackUnion::atom
Atom * atom
Definition: Canon.h:44