RingInfo.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (C) 2004-2006 Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved @@
00005 //  This file is part of the RDKit.
00006 //  The contents are covered by the terms of the BSD license
00007 //  which is included in the file license.txt, found at the root
00008 //  of the RDKit source tree.
00009 //
00010 #ifndef _RD_RINGINFO_H
00011 #define _RD_RINGINFO_H
00012 
00013 #include <map>
00014 #include <vector>
00015 
00016 namespace RDKit {
00017   //! A class to store information about a molecule's rings
00018   /*!
00019 
00020    */
00021   class RingInfo {
00022     friend class MolPickler;
00023   public:
00024     typedef std::vector<int> MemberType;
00025     typedef std::vector<MemberType > DataType;
00026     typedef std::vector<int> INT_VECT;
00027     typedef std::vector< INT_VECT > VECT_INT_VECT;
00028 
00029     RingInfo() : df_init(false) {};
00030     RingInfo(const RingInfo &other) : df_init(other.df_init),
00031                                       d_atomMembers(other.d_atomMembers),
00032                                       d_bondMembers(other.d_bondMembers),
00033                                       d_atomRings(other.d_atomRings),
00034                                       d_bondRings(other.d_bondRings) {};
00035     
00036     //! checks to see if we've been properly initialized
00037     bool isInitialized() const { return df_init; };
00038     //! does initialization
00039     void initialize();
00040 
00041     //! blows out all current data and de-initializes
00042     void reset();
00043 
00044     //! adds a ring to our data
00045     /*!
00046       \param atomIndices the integer indices of the atoms involved in the ring
00047       \param bondIndices the integer indices of the bonds involved in the ring,
00048         this must be the same size as \c atomIndices.
00049 
00050       \return the number of rings
00051       
00052       <b>Notes:</b>
00053         - the object must be initialized before calling this
00054 
00055     */
00056     unsigned int addRing(const INT_VECT &atomIndices,const INT_VECT &bondIndices);
00057 
00058   
00059     //! \name Atom information
00060     //@{
00061 
00062     //! returns whether or not the atom with index \c idx is in a \c size - ring.
00063     /*!
00064       <b>Notes:</b>
00065         - the object must be initialized before calling this
00066     */
00067     bool isAtomInRingOfSize(unsigned int idx,unsigned int size) const;
00068     //! returns the number of rings atom \c idx is involved in
00069     /*!
00070       <b>Notes:</b>
00071         - the object must be initialized before calling this
00072     */
00073     unsigned int numAtomRings(unsigned int idx) const;
00074     //! returns the size of the smallest ring atom \c idx is involved in
00075     /*!
00076       <b>Notes:</b>
00077         - the object must be initialized before calling this
00078     */
00079     unsigned int minAtomRingSize(unsigned int idx) const;
00080 
00081     //! returns our \c atom-rings vectors
00082     /*!
00083       <b>Notes:</b>
00084         - the object must be initialized before calling this
00085     */
00086     const VECT_INT_VECT &atomRings() const { return d_atomRings; };
00087 
00088     //@}
00089 
00090     //! \name Bond information
00091     //@{
00092 
00093     //! returns whether or not the bond with index \c idx is in a \c size - ring.
00094     /*!
00095       <b>Notes:</b>
00096         - the object must be initialized before calling this
00097     */
00098     bool isBondInRingOfSize(unsigned int idx,unsigned int size) const;
00099     //! returns the number of rings bond \c idx is involved in
00100     /*!
00101       <b>Notes:</b>
00102         - the object must be initialized before calling this
00103     */
00104     unsigned int numBondRings(unsigned int idx) const;
00105     //! returns the size of the smallest ring bond \c idx is involved in
00106     /*!
00107       <b>Notes:</b>
00108         - the object must be initialized before calling this
00109     */
00110     unsigned int minBondRingSize(unsigned int idx) const;
00111 
00112     //! returns the total number of rings
00113     /*!
00114       <b>Notes:</b>
00115         - the object must be initialized before calling this
00116     */
00117     unsigned int numRings() const;
00118 
00119     //! returns our \c bond-rings vectors
00120     /*!
00121       <b>Notes:</b>
00122         - the object must be initialized before calling this
00123     */
00124     const VECT_INT_VECT &bondRings() const { return d_bondRings; };
00125 
00126     //@}
00127     
00128   private:
00129     //! pre-allocates some memory to save time later
00130     void preallocate(unsigned int numAtoms,unsigned int numBonds);
00131 
00132     bool df_init;
00133     DataType d_atomMembers,d_bondMembers;
00134     VECT_INT_VECT d_atomRings,d_bondRings;
00135   };
00136 }
00137 
00138 #endif