RDKit
Open-source cheminformatics and machine learning.
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 
14 #include <boost/tuple/tuple.hpp>
15 #include <boost/dynamic_bitset.hpp>
17 
18 namespace RDKit {
19 class ROMol;
20 class Atom;
21 class Bond;
22 
23 namespace Canon {
24 const int MAX_NATOMS = 5000; //!< used in the canonical traversal code
25 const int MAX_CYCLES = 1000; //!< used in the canonical traversal code
26 const int MAX_BONDTYPE = 32; //!< used in the canonical traversal code
27 
28 //! used in traversals of the molecule
29 typedef enum {
30  WHITE_NODE = 0, //! not visited
31  GREY_NODE, //! visited, but not finished
32  BLACK_NODE, //! visited and finished
33 } AtomColors;
34 
35 //! used to indicate types of entries in the molecular stack:
36 typedef enum {
37  MOL_STACK_ATOM = 0, //!< an Atom
38  MOL_STACK_BOND, //!< a Bond
39  MOL_STACK_RING, //!< a ring closure
40  MOL_STACK_BRANCH_OPEN, //!< beginning of a branch
41  MOL_STACK_BRANCH_CLOSE, //!< end of a branch
43 
44 //! used to store components in the molecular stack
45 typedef union {
49 
50 //! these are the actual elements in the molecular stack
51 class MolStackElem {
52  public:
53  //! construct an Atom node
54  explicit MolStackElem(Atom *at) {
56  obj.atom = at;
57  };
58  //! construct a bond node
59  /*!
60 
61  \param bond pointer to the Bond being added
62  \param idx index of the Atom traversed before this Bond
63  (beginAtom in the canonical traversal order)
64  */
65  explicit MolStackElem(Bond *bond, int idx) {
67  obj.bond = bond;
68  number = idx;
69  };
70  //! construct for a ring closure
71  explicit MolStackElem(int idx) {
73  number = idx;
74  };
75  //! construct for a branch opening or closing
76  explicit MolStackElem(const char *chr, int idx) {
77  switch (chr[0]) {
78  case '(':
80  break;
81  case ')':
83  break;
84  default:
85  break;
86  }
87  number = idx;
88  }
89  MolStackTypes type; //!< stores the type of node
90  MolStackUnion obj; //!< holds our pointer (if appropriate)
91  int number; //!< stores our number (relevant for bonds and ring closures)
92 };
93 typedef std::vector<MolStackElem> MolStack;
94 
95 //! used to represent possible branches from an atom
96 typedef boost::tuple<int, int, Bond *> PossibleType;
97 
98 //! constructs the canonical traversal order for a molecular fragment
99 /*!
100 
101  \param mol the ROMol we're working on
102  \param atomIdx the index of the atom to start the traversal from
103  \param colors the traversal status of each atom in \c mol
104  \param ranks the assigned rank of each atom in \c mol
105  \param molStack the current traversal stack (used to return the results)
106 
107  <b>Notes</b>
108  - \c mol will, in general, be modified by this operation as bond directions
109  and the like are changed to fit the canonical traversal order
110 
111  */
112 void canonicalizeFragment(ROMol &mol, int atomIdx,
113  std::vector<AtomColors> &colors,
114  const std::vector<unsigned int> &ranks,
115  MolStack &molStack,
116  const boost::dynamic_bitset<> *bondsInPlay = 0,
117  const std::vector<std::string> *bondSymbols = 0,
118  bool doIsomericSmiles = false);
119 
120 } // end of namespace Canon
121 } // end of namespace RDKit
122 #endif
const int MAX_CYCLES
used in the canonical traversal code
Definition: Canon.h:25
int number
stores our number (relevant for bonds and ring closures)
Definition: Canon.h:91
MolStackElem(Atom *at)
construct an Atom node
Definition: Canon.h:54
AtomColors
used in traversals of the molecule
Definition: Canon.h:29
MolStackElem(Bond *bond, int idx)
construct a bond node
Definition: Canon.h:65
used to store components in the molecular stack
Definition: Canon.h:45
boost::tuple< int, int, Bond * > PossibleType
used to represent possible branches from an atom
Definition: Canon.h:96
these are the actual elements in the molecular stack
Definition: Canon.h:51
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:106
MolStackUnion obj
holds our pointer (if appropriate)
Definition: Canon.h:90
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
visited, but not finished
Definition: Canon.h:32
not visited
Definition: Canon.h:31
a ring closure
Definition: Canon.h:39
MolStackTypes type
stores the type of node
Definition: Canon.h:89
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
MolStackTypes
used to indicate types of entries in the molecular stack:
Definition: Canon.h:36
beginning of a branch
Definition: Canon.h:40
MolStackElem(const char *chr, int idx)
construct for a branch opening or closing
Definition: Canon.h:76
class for representing a bond
Definition: Bond.h:47
const int MAX_BONDTYPE
used in the canonical traversal code
Definition: Canon.h:26
MolStackElem(int idx)
construct for a ring closure
Definition: Canon.h:71
const int MAX_NATOMS
used in the canonical traversal code
Definition: Canon.h:24
std::vector< MolStackElem > MolStack
Definition: Canon.h:93
The class for representing atoms.
Definition: Atom.h:68