Loading...
Searching...
No Matches
obiter.h
Go to the documentation of this file.
/**********************************************************************
obiter.h - STL-style iterators for Open Babel.
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
#ifndef OB_OBITER_H
#define OB_OBITER_H
#include <openbabel/babelconfig.h>
#include <openbabel/bitvec.h>
#include <vector>
#include <stack>
#include <queue>
namespace OpenBabel
{
class OBMol;
class OBAtom;
class OBBond;
class OBResidue;
// more detailed descriptions and documentation in obiter.cpp
class OBAPI OBMolAtomIter {
std::vector<OBAtom*>::iterator _i;
OBMol *_parent;
OBAtom *_ptr;
public:
OBMolAtomIter() :_parent(nullptr), _ptr(nullptr) { }
OBMolAtomIter(OBMol *mol);
OBMolAtomIter(OBMol &mol);
OBMolAtomIter(const OBMolAtomIter &ai);
~OBMolAtomIter() { }
OBMolAtomIter& operator=(const OBMolAtomIter &ai);
operator bool() const { return _ptr != nullptr; }
OBMolAtomIter& operator++();
OBMolAtomIter operator++(int);
OBAtom* operator->() const { return _ptr; }
OBAtom& operator*() const { return *_ptr; }
};
class OBAPI OBMolAtomDFSIter {
OBMol *_parent;
OBAtom *_ptr;
OBBitVec _notVisited;
std::stack<OBAtom *> _stack;
public:
OBMolAtomDFSIter() : _parent(nullptr), _ptr(nullptr) { }
OBMolAtomDFSIter(OBMol *mol, int StartIndex=1);
OBMolAtomDFSIter(OBMol &mol, int StartIndex=1);
OBMolAtomDFSIter(const OBMolAtomDFSIter &ai);
~OBMolAtomDFSIter() { }
OBMolAtomDFSIter& operator=(const OBMolAtomDFSIter &ai);
operator bool() const { return _ptr != nullptr; }
OBMolAtomDFSIter& operator++();
OBMolAtomDFSIter operator++(int);
OBAtom* operator->() const { return _ptr; }
OBAtom& operator*() const { return *_ptr; }
OBAtom* next()
{
if(_stack.empty())
return nullptr; //end of a disconnected fragment
else
return _stack.top(); //the next atom
}
};
class OBAPI OBMolAtomBFSIter {
OBMol *_parent;
OBAtom *_ptr;
OBBitVec _notVisited;
std::queue<OBAtom *> _queue;
std::vector<int> _depth;
public:
OBMolAtomBFSIter(): _parent(nullptr), _ptr(nullptr) { }
OBMolAtomBFSIter(OBMol *mol, int StartIndex = 1);
OBMolAtomBFSIter(OBMol &mol, int StartIndex = 1);
OBMolAtomBFSIter(const OBMolAtomBFSIter &ai);
~OBMolAtomBFSIter() { }
OBMolAtomBFSIter& operator=(const OBMolAtomBFSIter &ai);
operator bool() const { return _ptr != nullptr; }
OBMolAtomBFSIter& operator++();
OBMolAtomBFSIter operator++(int);
OBAtom* operator->() const { return _ptr; }
OBAtom& operator*() const { return *_ptr; }
int CurrentDepth() const;
};
class OBAPI OBMolBondBFSIter {
OBMol *_parent;
OBBond *_ptr;
OBBitVec _notVisited;
std::queue<OBBond *> _queue;
std::vector<int> _depth;
public:
OBMolBondBFSIter(): _parent(nullptr), _ptr(nullptr) { }
OBMolBondBFSIter(OBMol *mol, int StartIndex = 0);
OBMolBondBFSIter(OBMol &mol, int StartIndex = 0);
OBMolBondBFSIter(const OBMolBondBFSIter &ai);
~OBMolBondBFSIter() { }
OBMolBondBFSIter& operator=(const OBMolBondBFSIter &ai);
operator bool() const { return _ptr != nullptr; }
OBMolBondBFSIter& operator++();
OBMolBondBFSIter operator++(int);
OBBond* operator->() const { return _ptr; }
OBBond& operator*() const { return *_ptr; }
int CurrentDepth() const;
};
class OBAPI OBMolBondIter {
std::vector<OBBond*>::iterator _i;
OBMol *_parent;
OBBond *_ptr;
public:
OBMolBondIter() : _parent(nullptr), _ptr(nullptr) {}
OBMolBondIter(OBMol *mol);
OBMolBondIter(OBMol &mol);
OBMolBondIter(const OBMolBondIter &bi);
~OBMolBondIter() { }
OBMolBondIter& operator=(const OBMolBondIter &bi);
operator bool() const { return _ptr != nullptr; }
OBMolBondIter& operator++();
OBMolBondIter operator++(int);
OBBond* operator->() const { return _ptr; }
OBBond& operator*() const { return *_ptr; }
};
class OBAPI OBAtomAtomIter {
std::vector<OBBond*>::iterator _i;
OBAtom *_parent;
OBAtom *_ptr;
public:
OBAtomAtomIter() : _parent(nullptr), _ptr(nullptr) { }
OBAtomAtomIter(OBAtom *atm);
OBAtomAtomIter(OBAtom &atm);
OBAtomAtomIter(const OBAtomAtomIter &ai);
~OBAtomAtomIter() { }
OBAtomAtomIter& operator=(const OBAtomAtomIter &ai);
operator bool() const { return _ptr != nullptr; }
OBAtomAtomIter& operator++();
OBAtomAtomIter operator++(int);
OBAtom* operator->() const { return _ptr; }
OBAtom& operator*() const { return *_ptr; }
};
class OBAPI OBAtomBondIter {
std::vector<OBBond*>::iterator _i;
OBAtom *_parent;
OBBond *_ptr;
public:
OBAtomBondIter(): _parent(nullptr), _ptr(nullptr) { }
OBAtomBondIter(OBAtom *atm);
OBAtomBondIter(OBAtom &atm);
OBAtomBondIter(const OBAtomBondIter &bi);
~OBAtomBondIter() { }
OBAtomBondIter& operator=(const OBAtomBondIter &bi);
operator bool() const { return _ptr != nullptr; }
OBAtomBondIter& operator++();
OBAtomBondIter operator++(int);
OBBond* operator->() const { return _ptr; }
OBBond& operator*() const { return *_ptr;}
};
class OBAPI OBResidueIter {
std::vector<OBResidue*>::iterator _i;
OBResidue *_ptr;
OBMol *_parent;
public:
OBResidueIter() : _ptr(nullptr), _parent(nullptr) { }
OBResidueIter(OBMol *mol);
OBResidueIter(OBMol &mol);
OBResidueIter(const OBResidueIter &ri);
~OBResidueIter() { }
OBResidueIter& operator=(const OBResidueIter &ri);
operator bool() const { return _ptr != nullptr; }
OBResidueIter& operator++();
OBResidueIter operator++(int);
OBResidue* operator->() const{ return _ptr; }
OBResidue& operator*() const { return *_ptr;}
};
class OBAPI OBResidueAtomIter {
std::vector<OBAtom*>::iterator _i;
OBResidue *_parent;
OBAtom *_ptr;
public:
OBResidueAtomIter() : _parent(nullptr), _ptr(nullptr) { }
OBResidueAtomIter(OBResidue *res);
OBResidueAtomIter(OBResidue &res);
OBResidueAtomIter(const OBResidueAtomIter &ri);
~OBResidueAtomIter() { }
OBResidueAtomIter &operator = (const OBResidueAtomIter &ri);
operator bool() const { return _ptr != nullptr; }
OBResidueAtomIter& operator++ ();
OBResidueAtomIter operator++ (int);
OBAtom *operator->() const { return _ptr; }
OBAtom &operator*() const { return *_ptr;}
};
class OBAPI OBMolAngleIter {
OBMol *_parent;
std::vector<std::vector<unsigned int> > _vangle;
std::vector<std::vector<unsigned int> >::iterator _i;
std::vector<unsigned int> _angle;
public:
OBMolAngleIter() :_parent(nullptr) { }
OBMolAngleIter(OBMol *mol);
OBMolAngleIter(OBMol &mol);
OBMolAngleIter(const OBMolAngleIter &ai);
~OBMolAngleIter() { }
OBMolAngleIter& operator=(const OBMolAngleIter &ai);
operator bool() const { return (_i != _vangle.end()); }
OBMolAngleIter& operator++();
std::vector<unsigned int> operator*() const { return _angle; }
};
class OBAPI OBMolTorsionIter {
OBMol *_parent;
std::vector<std::vector<unsigned int> > _vtorsion;
std::vector<std::vector<unsigned int> >::iterator _i;
std::vector<unsigned int> _torsion;
public:
OBMolTorsionIter() :_parent(nullptr) { }
OBMolTorsionIter(OBMol *mol);
OBMolTorsionIter(OBMol &mol);
OBMolTorsionIter(const OBMolTorsionIter &ai);
~OBMolTorsionIter() { }
OBMolTorsionIter& operator=(const OBMolTorsionIter &ai);
operator bool() const { return (_i != _vtorsion.end()); }
OBMolTorsionIter& operator++();
std::vector<unsigned int> operator*() const { return _torsion; }
};
class OBAPI OBMolPairIter {
std::vector<OBAtom*>::iterator _i;
std::vector<OBAtom*>::iterator _j;
OBMol *_parent;
//std::vector<std::vector<unsigned int> > _vpair;
//std::vector<std::vector<unsigned int> >::iterator _i;
std::vector<unsigned int> _pair;
public:
OBMolPairIter() :_parent(nullptr) { }
OBMolPairIter(OBMol *mol);
OBMolPairIter(OBMol &mol);
OBMolPairIter(const OBMolPairIter &ai);
~OBMolPairIter() { }
OBMolPairIter& operator=(const OBMolPairIter &ai);
operator bool() const { return _pair.size()>0; }
OBMolPairIter& operator++();
std::vector<unsigned int> operator*() const { return _pair; }
};
class OBRing;
class OBRingData;
class OBAPI OBMolRingIter {
std::vector<OBRing*>::iterator _i;
OBRing *_ptr;
OBMol *_parent;
OBRingData *_rings;
public:
OBMolRingIter() : _ptr(nullptr), _parent(nullptr), _rings(nullptr) { }
OBMolRingIter(OBMol *mol);
OBMolRingIter(OBMol &mol);
OBMolRingIter(const OBMolRingIter &ri);
~OBMolRingIter() { }
OBMolRingIter& operator=(const OBMolRingIter &ri);
operator bool() const { return _ptr != nullptr; }
OBMolRingIter& operator++();
OBMolRingIter operator++(int);
OBRing* operator->() const { return _ptr; }
OBRing& operator*() const { return *_ptr;}
};
#define FOR_ATOMS_OF_MOL(a,m) for( OpenBabel::OBMolAtomIter a(m); a; ++a )
#define FOR_BONDS_OF_MOL(b,m) for( OpenBabel::OBMolBondIter b(m); b; ++b )
#define FOR_NBORS_OF_ATOM(a,p) for( OpenBabel::OBAtomAtomIter a(p); a; ++a )
#define FOR_BONDS_OF_ATOM(b,p) for( OpenBabel::OBAtomBondIter b(p); b; ++b )
#define FOR_RESIDUES_OF_MOL(r,m) for( OpenBabel::OBResidueIter r(m); r; ++r )
#define FOR_ATOMS_OF_RESIDUE(a,r) for( OpenBabel::OBResidueAtomIter a(r); a; ++a )
#define FOR_DFS_OF_MOL(a,m) for( OpenBabel::OBMolAtomDFSIter a(m); a; ++a )
#define FOR_BFS_OF_MOL(a,m) for( OpenBabel::OBMolAtomBFSIter a(m); a; ++a )
#define FOR_BONDBFS_OF_MOL(b,m) for( OpenBabel::OBMolBondBFSIter b(m); b; ++b )
#define FOR_RINGS_OF_MOL(r,m) for( OpenBabel::OBMolRingIter r(m); r; ++r )
#define FOR_ANGLES_OF_MOL(a,m) for( OpenBabel::OBMolAngleIter a(m); a; ++a )
#define FOR_TORSIONS_OF_MOL(t,m) for( OpenBabel::OBMolTorsionIter t(m); t; ++t )
#define FOR_PAIRS_OF_MOL(p,m) for( OpenBabel::OBMolPairIter p(m); p; ++p )
} // namespace OpenBabel
#endif // OB_OBITER_H
bitvec.h
Fast and efficient bitstring class.
OpenBabel::OBAtomAtomIter
Iterate over all neighboring atoms to an OBAtom.
Definition obiter.h:190
OpenBabel::OBAtomAtomIter::operator*
OBAtom & operator*() const
Definition obiter.h:212
OpenBabel::OBAtomAtomIter::operator->
OBAtom * operator->() const
Definition obiter.h:210
OpenBabel::OBAtomAtomIter::~OBAtomAtomIter
~OBAtomAtomIter()
Definition obiter.h:200
OpenBabel::OBAtomAtomIter::OBAtomAtomIter
OBAtomAtomIter()
Definition obiter.h:196
OpenBabel::OBAtomBondIter
Iterate over all bonds on an OBAtom.
Definition obiter.h:216
OpenBabel::OBAtomBondIter::operator->
OBBond * operator->() const
Definition obiter.h:236
OpenBabel::OBAtomBondIter::~OBAtomBondIter
~OBAtomBondIter()
Definition obiter.h:226
OpenBabel::OBAtomBondIter::operator*
OBBond & operator*() const
Definition obiter.h:238
OpenBabel::OBAtomBondIter::OBAtomBondIter
OBAtomBondIter()
Definition obiter.h:222
OpenBabel::OBAtom
Atom class.
Definition atom.h:72
OpenBabel::OBBitVec
A speed-optimized vector of bits.
Definition bitvec.h:58
OpenBabel::OBBond
Bond class.
Definition bond.h:59
OpenBabel::OBMolAngleIter
Iterate over all angles in an OBMol.
Definition obiter.h:294
OpenBabel::OBMolAngleIter::operator*
std::vector< unsigned int > operator*() const
Definition obiter.h:314
OpenBabel::OBMolAngleIter::OBMolAngleIter
OBMolAngleIter()
Definition obiter.h:301
OpenBabel::OBMolAngleIter::~OBMolAngleIter
~OBMolAngleIter()
Definition obiter.h:305
OpenBabel::OBMolAtomBFSIter
Iterate over all atoms in an OBMol in a breadth-first search (BFS).
Definition obiter.h:102
OpenBabel::OBMolAtomBFSIter::~OBMolAtomBFSIter
~OBMolAtomBFSIter()
Definition obiter.h:114
OpenBabel::OBMolAtomBFSIter::OBMolAtomBFSIter
OBMolAtomBFSIter()
Definition obiter.h:110
OpenBabel::OBMolAtomBFSIter::operator*
OBAtom & operator*() const
Definition obiter.h:126
OpenBabel::OBMolAtomBFSIter::operator->
OBAtom * operator->() const
Definition obiter.h:124
OpenBabel::OBMolAtomDFSIter
Iterate over all atoms in an OBMol in a depth-first search (DFS).
Definition obiter.h:67
OpenBabel::OBMolAtomDFSIter::OBMolAtomDFSIter
OBMolAtomDFSIter()
Definition obiter.h:74
OpenBabel::OBMolAtomDFSIter::operator*
OBAtom & operator*() const
Definition obiter.h:90
OpenBabel::OBMolAtomDFSIter::~OBMolAtomDFSIter
~OBMolAtomDFSIter()
Definition obiter.h:78
OpenBabel::OBMolAtomDFSIter::operator->
OBAtom * operator->() const
Definition obiter.h:88
OpenBabel::OBMolAtomDFSIter::next
OBAtom * next()
Definition obiter.h:92
OpenBabel::OBMolAtomIter
Iterate over all atoms in an OBMol.
Definition obiter.h:41
OpenBabel::OBMolAtomIter::OBMolAtomIter
OBMolAtomIter()
Definition obiter.h:47
OpenBabel::OBMolAtomIter::operator*
OBAtom & operator*() const
Definition obiter.h:63
OpenBabel::OBMolAtomIter::operator->
OBAtom * operator->() const
Definition obiter.h:61
OpenBabel::OBMolAtomIter::~OBMolAtomIter
~OBMolAtomIter()
Definition obiter.h:51
OpenBabel::OBMolBondBFSIter
Iterate over all bonds in an OBMol in a breadth-first search (BFS).
Definition obiter.h:133
OpenBabel::OBMolBondBFSIter::operator->
OBBond * operator->() const
Definition obiter.h:155
OpenBabel::OBMolBondBFSIter::OBMolBondBFSIter
OBMolBondBFSIter()
Definition obiter.h:141
OpenBabel::OBMolBondBFSIter::operator*
OBBond & operator*() const
Definition obiter.h:157
OpenBabel::OBMolBondBFSIter::~OBMolBondBFSIter
~OBMolBondBFSIter()
Definition obiter.h:145
OpenBabel::OBMolBondIter
Iterate over all bonds in an OBMol.
Definition obiter.h:164
OpenBabel::OBMolBondIter::OBMolBondIter
OBMolBondIter()
Definition obiter.h:170
OpenBabel::OBMolBondIter::operator->
OBBond * operator->() const
Definition obiter.h:184
OpenBabel::OBMolBondIter::~OBMolBondIter
~OBMolBondIter()
Definition obiter.h:174
OpenBabel::OBMolBondIter::operator*
OBBond & operator*() const
Definition obiter.h:186
OpenBabel::OBMolPairIter
Iterate over all pairs of atoms (>1-4) in an OBMol.
Definition obiter.h:342
OpenBabel::OBMolPairIter::operator*
std::vector< unsigned int > operator*() const
Definition obiter.h:365
OpenBabel::OBMolPairIter::OBMolPairIter
OBMolPairIter()
Definition obiter.h:352
OpenBabel::OBMolPairIter::~OBMolPairIter
~OBMolPairIter()
Definition obiter.h:356
OpenBabel::OBMolRingIter
Iterate over all rings in an OBMol.
Definition obiter.h:372
OpenBabel::OBMolRingIter::~OBMolRingIter
~OBMolRingIter()
Definition obiter.h:383
OpenBabel::OBMolRingIter::operator*
OBRing & operator*() const
Definition obiter.h:395
OpenBabel::OBMolRingIter::OBMolRingIter
OBMolRingIter()
Definition obiter.h:379
OpenBabel::OBMolRingIter::operator->
OBRing * operator->() const
Definition obiter.h:393
OpenBabel::OBMolTorsionIter
Iterate over all torsions in an OBMol.
Definition obiter.h:318
OpenBabel::OBMolTorsionIter::OBMolTorsionIter
OBMolTorsionIter()
Definition obiter.h:325
OpenBabel::OBMolTorsionIter::operator*
std::vector< unsigned int > operator*() const
Definition obiter.h:338
OpenBabel::OBMolTorsionIter::~OBMolTorsionIter
~OBMolTorsionIter()
Definition obiter.h:329
OpenBabel::OBMol
Molecule Class.
Definition mol.h:121
OpenBabel::OBResidueAtomIter
Iterate over all atoms in an OBResidue.
Definition obiter.h:268
OpenBabel::OBResidueAtomIter::OBResidueAtomIter
OBResidueAtomIter()
Definition obiter.h:274
OpenBabel::OBResidueAtomIter::~OBResidueAtomIter
~OBResidueAtomIter()
Definition obiter.h:278
OpenBabel::OBResidueAtomIter::operator*
OBAtom & operator*() const
Definition obiter.h:290
OpenBabel::OBResidueAtomIter::operator->
OBAtom * operator->() const
Definition obiter.h:288
OpenBabel::OBResidueIter
Iterate over all residues in an OBMol.
Definition obiter.h:242
OpenBabel::OBResidueIter::OBResidueIter
OBResidueIter()
Definition obiter.h:248
OpenBabel::OBResidueIter::operator->
OBResidue * operator->() const
Definition obiter.h:262
OpenBabel::OBResidueIter::operator*
OBResidue & operator*() const
Definition obiter.h:264
OpenBabel::OBResidueIter::~OBResidueIter
~OBResidueIter()
Definition obiter.h:252
OpenBabel::OBResidue
Residue information.
Definition residue.h:51
OpenBabel::OBRingData
Used to store the SSSR set (filled in by OBMol::GetSSSR()).
Definition generic.h:256
OpenBabel::OBRing
Stores information on rings in a molecule from SSSR perception.
Definition ring.h:41
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23