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