Canon.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (C) 2004-2006 Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved  @@
00005 //
00006 #ifndef _RD_CANON_H_
00007 #define _RD_CANON_H_
00008 
00009 namespace RDKit {
00010   class ROMol;
00011   class Atom;
00012   class Bond;
00013 };
00014 
00015 namespace Canon {
00016   const int MAX_NATOMS=1000; //!< used in the canonical traversal code
00017   const int MAX_CYCLES=50;   //!< used in the canonical traversal code
00018 
00019   //! used in traversals of the molecule
00020   typedef enum {
00021     WHITE_NODE=0,  //! not visited
00022     GREY_NODE,     //! visited, but not finished
00023     BLACK_NODE,    //! visited and finished
00024   } AtomColors; 
00025 
00026   //! used to indicate types of entries in the molecular stack:
00027   typedef enum {
00028     MOL_STACK_ATOM=0,       //!< an Atom
00029     MOL_STACK_BOND,         //!< a Bond
00030     MOL_STACK_RING,         //!< a ring closure
00031     MOL_STACK_BRANCH_OPEN,  //!< beginning of a branch
00032     MOL_STACK_BRANCH_CLOSE, //!< end of a branch
00033   } MolStackTypes;
00034 
00035   //! used to store components in the molecular stack
00036   typedef union{
00037     RDKit::Atom *atom;
00038     RDKit::Bond *bond;
00039   } MolStackUnion;
00040 
00041   //! these are the actual elements in the molecular stack
00042   class MolStackElem {
00043   public:
00044     //! construct an Atom node
00045     explicit MolStackElem(RDKit::Atom *at) {
00046       type = MOL_STACK_ATOM;
00047       obj.atom = at;
00048     };
00049     //! construct a bond node
00050     /*!
00051 
00052        \param bond  pointer to the Bond being added
00053        \param idx   index of the Atom traversed before this Bond
00054          (beginAtom in the canonical traversal order)
00055     */
00056     explicit MolStackElem(RDKit::Bond *bond,int idx) {
00057       type = MOL_STACK_BOND;
00058       obj.bond = bond;
00059       number = idx;
00060     };
00061     //! construct for a ring closure
00062     explicit MolStackElem(int idx) {
00063       type = MOL_STACK_RING;
00064       number = idx;
00065     };
00066     //! construct for a branch opening or closing
00067     explicit MolStackElem(const char *chr,int idx) {
00068       switch(chr[0]){
00069       case '(':
00070         type = MOL_STACK_BRANCH_OPEN;
00071         break;
00072       case ')':
00073         type = MOL_STACK_BRANCH_CLOSE;
00074         break;
00075       default:
00076         break;
00077       }
00078       number=idx;
00079     }
00080     MolStackTypes type; //!< stores the type of node
00081     MolStackUnion obj;  //!< holds our pointer (if appropriate)
00082     int number;         //!< stores our number (relevant for bonds and ring closures)
00083   };
00084   typedef std::vector<MolStackElem> MolStack;
00085 
00086 
00087   //! used to represent possible branches from an atom
00088   typedef std::pair< int, std::pair< int, RDKit::Bond * > > PossibleType;
00089   //! returns a PossibleType
00090   PossibleType makePossible(int rank,int atomIdx,RDKit::Bond *bond);
00091   //! compare two PossibleTypes
00092   int _possibleComp(const PossibleType &arg1,const PossibleType &arg2);
00093 
00094   //! constructs the canonical traversal order for a molecular fragment
00095   /*!
00096 
00097     \param mol       the ROMol we're working on
00098     \param atomIdx   the index of the atom to start the traversal from
00099     \param colors    the traversal status of each atom in \c mol
00100     \param ranks     the assigned rank of each atom in \c mol
00101     \param molStack  the current traversal stack (used to return the results)
00102 
00103     <b>Notes</b>
00104       - \c mol will, in general, be modified by this operation as bond directions
00105         and the like are changed to fit the canonical traversal order
00106 
00107    */
00108   void canonicalizeFragment(RDKit::ROMol &mol,int atomIdx,
00109                             std::vector<AtomColors> &colors,
00110                             std::vector<int> &ranks,
00111                             MolStack &molStack);
00112 
00113 };
00114 
00115 #endif

Generated on Fri Apr 3 06:03:01 2009 for RDCode by  doxygen 1.5.6