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 
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
41 
42 //! used to store components in the molecular stack
43 typedef union {
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) {
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) {
65  obj.bond = bond;
66  number = idx;
67  };
68  //! construct for a ring closure
69  explicit MolStackElem(int idx) {
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 '(':
78  break;
79  case ')':
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
const int MAX_CYCLES
used in the canonical traversal code
Definition: Canon.h:23
int number
stores our number (relevant for bonds and ring closures)
Definition: Canon.h:89
MolStackElem(Atom *at)
construct an Atom node
Definition: Canon.h:52
AtomColors
used in traversals of the molecule
Definition: Canon.h:27
MolStackElem(Bond *bond, int idx)
construct a bond node
Definition: Canon.h:63
used to store components in the molecular stack
Definition: Canon.h:43
boost::tuple< int, int, Bond * > PossibleType
used to represent possible branches from an atom
Definition: Canon.h:94
these are the actual elements in the molecular stack
Definition: Canon.h:49
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:103
MolStackUnion obj
holds our pointer (if appropriate)
Definition: Canon.h:88
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:30
not visited
Definition: Canon.h:29
a ring closure
Definition: Canon.h:37
MolStackTypes type
stores the type of node
Definition: Canon.h:87
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:34
beginning of a branch
Definition: Canon.h:38
MolStackElem(const char *chr, int idx)
construct for a branch opening or closing
Definition: Canon.h:74
class for representing a bond
Definition: Bond.h:47
const int MAX_BONDTYPE
used in the canonical traversal code
Definition: Canon.h:24
MolStackElem(int idx)
construct for a ring closure
Definition: Canon.h:69
const int MAX_NATOMS
used in the canonical traversal code
Definition: Canon.h:22
std::vector< MolStackElem > MolStack
Definition: Canon.h:91
The class for representing atoms.
Definition: Atom.h:68