00001 /********************************************************************** 00002 obiter.h - STL-style iterators for Open Babel. 00003 00004 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. 00005 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison 00006 00007 This file is part of the Open Babel project. 00008 For more information, see <http://openbabel.org/> 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_OBITER_H 00021 #define OB_OBITER_H 00022 00023 #include <openbabel/babelconfig.h> 00024 #include <openbabel/base.h> 00025 #include <openbabel/bitvec.h> 00026 00027 #include <vector> 00028 #include <stack> 00029 #include <queue> 00030 00031 namespace OpenBabel 00032 { 00033 00034 class OBMol; 00035 class OBAtom; 00036 class OBBond; 00037 class OBResidue; 00038 00039 // more detailed descriptions and documentation in obiter.cpp 00040 00042 class OBAPI OBMolAtomIter { 00043 std::vector<OBAtom*>::iterator _i; 00044 OBMol *_parent; 00045 OBAtom *_ptr; 00046 public: 00047 00048 OBMolAtomIter() :_parent(NULL), _ptr(NULL) { } 00049 OBMolAtomIter(OBMol *mol); 00050 OBMolAtomIter(OBMol &mol); 00051 OBMolAtomIter(const OBMolAtomIter &ai); 00052 ~OBMolAtomIter() { } 00053 00054 OBMolAtomIter& operator=(const OBMolAtomIter &ai); 00056 operator bool() const { return _ptr != NULL; } 00058 OBMolAtomIter& operator++(); 00060 OBMolAtomIter operator++(int); 00062 OBAtom* operator->() const { return _ptr; } 00064 OBAtom& operator*() const { return *_ptr; } 00065 }; 00066 00068 class OBAPI OBMolAtomDFSIter { 00069 OBMol *_parent; 00070 OBAtom *_ptr; 00071 OBBitVec _notVisited; 00072 std::stack<OBAtom *> _stack; 00073 public: 00074 00075 OBMolAtomDFSIter() : _parent(NULL), _ptr(NULL) { } 00076 OBMolAtomDFSIter(OBMol *mol, int StartIndex=1); 00077 OBMolAtomDFSIter(OBMol &mol, int StartIndex=1); 00078 OBMolAtomDFSIter(const OBMolAtomDFSIter &ai); 00079 ~OBMolAtomDFSIter() { } 00080 00081 OBMolAtomDFSIter& operator=(const OBMolAtomDFSIter &ai); 00083 operator bool() const { return _ptr != NULL; } 00085 OBMolAtomDFSIter& operator++(); 00087 OBMolAtomDFSIter operator++(int); 00089 OBAtom* operator->() const { return _ptr; } 00091 OBAtom& operator*() const { return *_ptr; } 00093 OBAtom* next() 00094 { 00095 if(_stack.empty()) 00096 return NULL; //end of a disconnected fragment 00097 else 00098 return _stack.top(); //the next atom 00099 } 00100 }; 00101 00103 class OBAPI OBMolAtomBFSIter { 00104 OBMol *_parent; 00105 OBAtom *_ptr; 00106 OBBitVec _notVisited; 00107 std::queue<OBAtom *> _queue; 00108 std::vector<int> _depth; 00109 public: 00110 00111 OBMolAtomBFSIter(): _parent(NULL), _ptr(NULL) { } 00112 OBMolAtomBFSIter(OBMol *mol, int StartIndex = 1); 00113 OBMolAtomBFSIter(OBMol &mol, int StartIndex = 1); 00114 OBMolAtomBFSIter(const OBMolAtomBFSIter &ai); 00115 ~OBMolAtomBFSIter() { } 00116 00117 OBMolAtomBFSIter& operator=(const OBMolAtomBFSIter &ai); 00119 operator bool() const { return _ptr != NULL; } 00121 OBMolAtomBFSIter& operator++(); 00123 OBMolAtomBFSIter operator++(int); 00125 OBAtom* operator->() const { return _ptr; } 00127 OBAtom& operator*() const { return *_ptr; } 00130 int CurrentDepth() const; 00131 }; 00132 00134 class OBAPI OBMolBondBFSIter { 00135 OBMol *_parent; 00136 OBBond *_ptr; 00137 OBBitVec _notVisited; 00138 std::queue<OBBond *> _queue; 00139 std::vector<int> _depth; 00140 public: 00141 00142 OBMolBondBFSIter(): _parent(NULL), _ptr(NULL) { } 00143 OBMolBondBFSIter(OBMol *mol, int StartIndex = 0); 00144 OBMolBondBFSIter(OBMol &mol, int StartIndex = 0); 00145 OBMolBondBFSIter(const OBMolBondBFSIter &ai); 00146 ~OBMolBondBFSIter() { } 00147 00148 OBMolBondBFSIter& operator=(const OBMolBondBFSIter &ai); 00150 operator bool() const { return _ptr != NULL; } 00152 OBMolBondBFSIter& operator++(); 00154 OBMolBondBFSIter operator++(int); 00156 OBBond* operator->() const { return _ptr; } 00158 OBBond& operator*() const { return *_ptr; } 00161 int CurrentDepth() const; 00162 }; 00163 00165 class OBAPI OBMolBondIter { 00166 std::vector<OBBond*>::iterator _i; 00167 OBMol *_parent; 00168 OBBond *_ptr; 00169 public: 00170 00171 OBMolBondIter() : _parent(NULL), _ptr(NULL) {} 00172 OBMolBondIter(OBMol *mol); 00173 OBMolBondIter(OBMol &mol); 00174 OBMolBondIter(const OBMolBondIter &bi); 00175 ~OBMolBondIter() { } 00176 00177 OBMolBondIter& operator=(const OBMolBondIter &bi); 00179 operator bool() const { return _ptr != NULL; } 00181 OBMolBondIter& operator++(); 00183 OBMolBondIter operator++(int); 00185 OBBond* operator->() const { return _ptr; } 00187 OBBond& operator*() const { return *_ptr; } 00188 }; 00189 00191 class OBAPI OBAtomAtomIter { 00192 std::vector<OBBond*>::iterator _i; 00193 OBAtom *_parent; 00194 OBAtom *_ptr; 00195 public: 00196 00197 OBAtomAtomIter() : _parent(NULL), _ptr(NULL) { } 00198 OBAtomAtomIter(OBAtom *atm); 00199 OBAtomAtomIter(OBAtom &atm); 00200 OBAtomAtomIter(const OBAtomAtomIter &ai); 00201 ~OBAtomAtomIter() { } 00202 00203 OBAtomAtomIter& operator=(const OBAtomAtomIter &ai); 00205 operator bool() const { return _ptr != NULL; } 00207 OBAtomAtomIter& operator++(); 00209 OBAtomAtomIter operator++(int); 00211 OBAtom* operator->() const { return _ptr; } 00213 OBAtom& operator*() const { return *_ptr; } 00214 }; 00215 00217 class OBAPI OBAtomBondIter { 00218 std::vector<OBBond*>::iterator _i; 00219 OBAtom *_parent; 00220 OBBond *_ptr; 00221 public: 00222 00223 OBAtomBondIter(): _parent(NULL), _ptr(NULL) { } 00224 OBAtomBondIter(OBAtom *atm); 00225 OBAtomBondIter(OBAtom &atm); 00226 OBAtomBondIter(const OBAtomBondIter &bi); 00227 ~OBAtomBondIter() { } 00228 00229 OBAtomBondIter& operator=(const OBAtomBondIter &bi); 00231 operator bool() const { return _ptr != NULL; } 00233 OBAtomBondIter& operator++(); 00235 OBAtomBondIter operator++(int); 00237 OBBond* operator->() const { return _ptr; } 00239 OBBond& operator*() const { return *_ptr;} 00240 }; 00241 00243 class OBAPI OBResidueIter { 00244 std::vector<OBResidue*>::iterator _i; 00245 OBResidue *_ptr; 00246 OBMol *_parent; 00247 public: 00248 00249 OBResidueIter() : _ptr(NULL), _parent(NULL) { } 00250 OBResidueIter(OBMol *mol); 00251 OBResidueIter(OBMol &mol); 00252 OBResidueIter(const OBResidueIter &ri); 00253 ~OBResidueIter() { } 00254 00255 OBResidueIter& operator=(const OBResidueIter &ri); 00257 operator bool() const { return _ptr != NULL; } 00259 OBResidueIter& operator++(); 00261 OBResidueIter operator++(int); 00263 OBResidue* operator->() const{ return _ptr; } 00265 OBResidue& operator*() const { return *_ptr;} 00266 }; 00267 00269 class OBAPI OBResidueAtomIter { 00270 std::vector<OBAtom*>::iterator _i; 00271 OBResidue *_parent; 00272 OBAtom *_ptr; 00273 public: 00274 00275 OBResidueAtomIter() : _parent(NULL), _ptr(NULL) { } 00276 OBResidueAtomIter(OBResidue *res); 00277 OBResidueAtomIter(OBResidue &res); 00278 OBResidueAtomIter(const OBResidueAtomIter &ri); 00279 ~OBResidueAtomIter() { } 00280 00281 OBResidueAtomIter &operator = (const OBResidueAtomIter &ri); 00283 operator bool() const { return _ptr != NULL; } 00285 OBResidueAtomIter& operator++ (); 00287 OBResidueAtomIter operator++ (int); 00289 OBAtom *operator->() const { return _ptr; } 00291 OBAtom &operator*() const { return *_ptr;} 00292 }; 00293 00295 class OBAPI OBMolAngleIter { 00296 OBMol *_parent; 00297 std::vector<std::vector<unsigned int> > _vangle; 00298 std::vector<std::vector<unsigned int> >::iterator _i; 00299 std::vector<unsigned int> _angle; 00300 public: 00301 00302 OBMolAngleIter() :_parent(NULL) { } 00303 OBMolAngleIter(OBMol *mol); 00304 OBMolAngleIter(OBMol &mol); 00305 OBMolAngleIter(const OBMolAngleIter &ai); 00306 ~OBMolAngleIter() { } 00307 00308 OBMolAngleIter& operator=(const OBMolAngleIter &ai); 00310 operator bool() const { return (_i != _vangle.end()); } 00312 OBMolAngleIter& operator++(); 00315 std::vector<unsigned int> operator*() const { return _angle; } 00316 }; 00317 00319 class OBAPI OBMolTorsionIter { 00320 OBMol *_parent; 00321 std::vector<std::vector<unsigned int> > _vtorsion; 00322 std::vector<std::vector<unsigned int> >::iterator _i; 00323 std::vector<unsigned int> _torsion; 00324 public: 00325 00326 OBMolTorsionIter() :_parent(NULL) { } 00327 OBMolTorsionIter(OBMol *mol); 00328 OBMolTorsionIter(OBMol &mol); 00329 OBMolTorsionIter(const OBMolTorsionIter &ai); 00330 ~OBMolTorsionIter() { } 00331 00332 OBMolTorsionIter& operator=(const OBMolTorsionIter &ai); 00334 operator bool() const { return (_i != _vtorsion.end()); } 00336 OBMolTorsionIter& operator++(); 00339 std::vector<unsigned int> operator*() const { return _torsion; } 00340 }; 00341 00343 class OBAPI OBMolPairIter { 00344 std::vector<OBAtom*>::iterator _i; 00345 std::vector<OBAtom*>::iterator _j; 00346 OBMol *_parent; 00347 //std::vector<std::vector<unsigned int> > _vpair; 00348 //std::vector<std::vector<unsigned int> >::iterator _i; 00349 std::vector<unsigned int> _pair; 00350 00351 public: 00352 00353 OBMolPairIter() :_parent(NULL) { } 00354 OBMolPairIter(OBMol *mol); 00355 OBMolPairIter(OBMol &mol); 00356 OBMolPairIter(const OBMolPairIter &ai); 00357 ~OBMolPairIter() { } 00358 00359 OBMolPairIter& operator=(const OBMolPairIter &ai); 00361 operator bool() const { return _pair.size()>0; } 00363 OBMolPairIter& operator++(); 00366 std::vector<unsigned int> operator*() const { return _pair; } 00367 }; 00368 00369 class OBRing; 00370 class OBRingData; 00371 00373 class OBAPI OBMolRingIter { 00374 std::vector<OBRing*>::iterator _i; 00375 OBRing *_ptr; 00376 OBMol *_parent; 00377 OBRingData *_rings; 00378 public: 00379 00380 OBMolRingIter() : _ptr(NULL), _parent(NULL), _rings(NULL) { } 00381 OBMolRingIter(OBMol *mol); 00382 OBMolRingIter(OBMol &mol); 00383 OBMolRingIter(const OBMolRingIter &ri); 00384 ~OBMolRingIter() { } 00385 00386 OBMolRingIter& operator=(const OBMolRingIter &ri); 00388 operator bool() const { return _ptr != NULL; } 00390 OBMolRingIter& operator++(); 00392 OBMolRingIter operator++(int); 00394 OBRing* operator->() const { return _ptr; } 00396 OBRing& operator*() const { return *_ptr;} 00397 }; 00398 00399 #define FOR_ATOMS_OF_MOL(a,m) for( OBMolAtomIter a(m); a; ++a ) 00400 #define FOR_BONDS_OF_MOL(b,m) for( OBMolBondIter b(m); b; ++b ) 00401 #define FOR_NBORS_OF_ATOM(a,p) for( OBAtomAtomIter a(p); a; ++a ) 00402 #define FOR_BONDS_OF_ATOM(b,p) for( OBAtomBondIter b(p); b; ++b ) 00403 #define FOR_RESIDUES_OF_MOL(r,m) for( OBResidueIter r(m); r; ++r ) 00404 #define FOR_ATOMS_OF_RESIDUE(a,r) for( OBResidueAtomIter a(r); a; ++a ) 00405 #define FOR_DFS_OF_MOL(a,m) for( OBMolAtomDFSIter a(m); a; ++a ) 00406 #define FOR_BFS_OF_MOL(a,m) for( OBMolAtomBFSIter a(m); a; ++a ) 00407 #define FOR_BONDBFS_OF_MOL(b,m) for( OBMolBondBFSIter b(m); b; ++b ) 00408 #define FOR_RINGS_OF_MOL(r,m) for( OBMolRingIter r(m); r; ++r ) 00409 #define FOR_ANGLES_OF_MOL(a,m) for( OBMolAngleIter a(m); a; ++a ) 00410 #define FOR_TORSIONS_OF_MOL(t,m) for( OBMolTorsionIter t(m); t; ++t ) 00411 #define FOR_PAIRS_OF_MOL(p,m) for( OBMolPairIter p(m); p; ++p ) 00412 00413 } // namespace OpenBabel 00414 #endif // OB_OBITER_H 00415
This file is part of the documentation for Open Babel, version 2.3.