ring.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ring.h - Deal with rings, find smallest set of smallest rings (SSSR).
00003  
00004 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
00005 Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison
00006  
00007 This file is part of the Open Babel project.
00008 For more information, see <http://openbabel.sourceforge.net/>
00009  
00010 This program is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU General Public License as published by
00012 the Free Software Foundation version 2 of the License.
00013  
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 ***********************************************************************/
00019 
00020 #ifndef OB_RING_H
00021 #define OB_RING_H
00022 
00023 #include <deque>
00024 #include <algorithm>
00025 
00026 // TODO: Make this work as a free-standing header
00027 // Currently only used in ring.cpp which imports mol.h beforehand
00028 #include <openbabel/bitvec.h>
00029 
00030 namespace OpenBabel
00031 {
00032 
00033   class OBMol;
00034   class OBAtom;
00035   class OBBond;
00036 
00037   // class introduction in ring.cpp
00038   class OBAPI OBRing
00039   {
00040     OBMol *_parent; 
00041   public:
00042     //public data members
00043     std::vector<int> _path; 
00044     OBBitVec _pathset;      
00045 
00047 
00048     OBRing()    {}
00050     OBRing(std::vector<int>& path, int size);
00051   OBRing(std::vector<int>& path, OBBitVec set) : _path(path), _pathset(set) {}
00052     OBRing(const OBRing &src);
00053     OBRing& operator=(const OBRing &src);
00055     
00056     //member functions
00057 
00059     int    Size()     const  {    return(_path.size());  }
00062     int    PathSize() const  {    return(_path.size());  }
00063 
00067     bool   IsAromatic();
00068 
00070     bool   IsMember(OBAtom *a);
00073     bool         IsMember(OBBond *b);
00075     bool   IsInRing(int i)
00076     {
00077       return(_pathset.BitIsOn(i));
00078     }
00079 
00081     void   SetParent(OBMol *m)  {    _parent = m;    }
00083     OBMol *GetParent()          {    return(_parent);}
00084 
00091     bool findCenterAndNormal(vector3 & center, vector3 &norm1, vector3 &norm2);
00092   };
00093 
00096   OBAPI bool CompareRingSize(const OBRing *,const OBRing *);
00097 
00098 
00102   class OBAPI OBRingSearch
00103   {
00104     std::vector<OBBond*> _bonds; 
00105     std::vector<OBRing*> _rlist; 
00106   public:
00107     OBRingSearch()    {}
00108     ~OBRingSearch();
00109   
00111     void    SortRings()
00112     {
00113       std::sort(_rlist.begin(),_rlist.end(),CompareRingSize);
00114     }
00116     void    RemoveRedundant(int);
00118     void    AddRingFromClosure(OBMol &,OBBond *);
00119 
00120     bool    SaveUniqueRing(std::deque<int>&,std::deque<int>&);
00121 
00123     void    WriteRings();
00124 
00126 
00127 
00128     std::vector<OBRing*>::iterator BeginRings()
00129       {
00130         return(_rlist.begin());
00131       }
00133     std::vector<OBRing*>::iterator EndRings()
00134       {
00135         return(_rlist.end());
00136       }
00138   };
00139 
00144   class OBAPI OBRTree
00145   {
00146     OBAtom  *_atom; 
00147     OBRTree *_prv;  
00148   public:
00150     OBRTree(OBAtom*,OBRTree*);
00151     ~OBRTree()    {}
00152   
00154     int  GetAtomIdx();
00156     void PathToRoot(std::vector<OBAtom*>&);
00157   };
00158 
00159 } // end namespace OpenBabel
00160 
00161 #endif // OB_RING_H
00162