Chemical Data Processing Library C++ API - Version 1.1.1
BasicAtom.hpp
Go to the documentation of this file.
1 /*
2  * BasicAtom.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_CHEM_BASICATOM_HPP
30 #define CDPL_CHEM_BASICATOM_HPP
31 
32 #include <vector>
33 #include <utility>
34 
35 #include <boost/iterator/transform_iterator.hpp>
36 
37 #include "CDPL/Chem/APIPrefix.hpp"
38 #include "CDPL/Chem/Atom.hpp"
39 
40 
41 namespace CDPL
42 {
43 
44  namespace Chem
45  {
46 
47  class BasicMolecule;
48  class BasicBond;
49 
53  class CDPL_CHEM_API BasicAtom : public Atom
54  {
55 
56  friend class BasicMolecule;
57 
58  typedef std::pair<BasicAtom*, BasicBond*> AtomBondPair;
59  typedef std::vector<AtomBondPair> NeighborList;
60 
61  template <typename AtomType>
62  struct AtomAccessor
63  {
64 
65  typedef AtomType& result_type;
66 
67  AtomType& operator()(const AtomBondPair& ab_pair) const
68  {
69  return *ab_pair.first;
70  }
71  };
72 
73  template <typename BondType>
74  struct BondAccessor
75  {
76 
77  typedef BondType& result_type;
78 
79  BondType& operator()(const AtomBondPair& ab_pair) const
80  {
81  return *ab_pair.second;
82  }
83  };
84 
85  public:
86  typedef boost::transform_iterator<AtomAccessor<BasicAtom>, NeighborList::iterator> AtomIterator;
87  typedef boost::transform_iterator<AtomAccessor<const BasicAtom>, NeighborList::const_iterator> ConstAtomIterator;
88  typedef boost::transform_iterator<BondAccessor<BasicBond>, NeighborList::iterator> BondIterator;
89  typedef boost::transform_iterator<BondAccessor<const BasicBond>, NeighborList::const_iterator> ConstBondIterator;
90 
91  const Molecule& getMolecule() const;
92 
94 
95  std::size_t getNumAtoms() const;
96 
97  std::size_t getNumBonds() const;
98 
99  const Bond& getBond(std::size_t idx) const;
100 
101  Bond& getBond(std::size_t idx);
102 
103  const Bond& getBondToAtom(const Atom& atom) const;
104 
105  Bond& getBondToAtom(const Atom& atom);
106 
107  const Bond* findBondToAtom(const Atom& atom) const;
108 
109  Bond* findBondToAtom(const Atom& atom);
110 
111  const Atom& getAtom(std::size_t idx) const;
112 
113  Atom& getAtom(std::size_t idx);
114 
115  /*
116  * \brief Returns a constant iterator pointing to the beginning of the connected atoms.
117  * \return A constant iterator pointing to the beginning of the connected atoms.
118  */
120 
121  /*
122  * \brief Returns a mutable iterator pointing to the beginning of the connected atoms.
123  * \return A mutable iterator pointing to the beginning of the connected atoms.
124  */
126 
132 
138 
144 
150 
156 
162 
163  bool containsAtom(const Atom& atom) const;
164 
165  bool containsBond(const Bond& bond) const;
166 
167  std::size_t getAtomIndex(const Atom& atom) const;
168 
169  std::size_t getBondIndex(const Bond& bond) const;
170 
171  std::size_t getIndex() const;
172 
173  void orderAtoms(const AtomCompareFunction& func);
174 
175  void orderBonds(const BondCompareFunction& func);
176 
183 
184  using Atom::operator=;
185 
186  private:
187  BasicAtom(BasicMolecule* mol);
188 
189  BasicAtom(const BasicAtom& atom);
190 
191  ~BasicAtom();
192 
193  void setIndex(std::size_t idx);
194 
195  void clearAdjacencyLists();
196 
197  static void reserveMemForNewBond(BasicAtom& atom1, BasicAtom& atom2);
198  static void connectAtoms(BasicAtom& atom1, BasicAtom& atom2, BasicBond& bond);
199  static void disconnectAtoms(BasicBond& bond);
200 
201  BasicMolecule* molecule;
202  std::size_t index;
203  NeighborList neighbors;
204  };
205  } // namespace Chem
206 } // namespace CDPL
207 
208 #endif // CDPL_CHEM_BASICATOM_HPP
CDPL::Chem::BasicAtom::ConstBondIterator
boost::transform_iterator< BondAccessor< const BasicBond >, NeighborList::const_iterator > ConstBondIterator
Definition: BasicAtom.hpp:89
CDPL::Chem::BasicAtom
BasicAtom.
Definition: BasicAtom.hpp:54
CDPL::Chem::AtomCompareFunction
std::function< bool(const Chem::Atom &, const Chem::Atom &)> AtomCompareFunction
A generic wrapper class used to store a user-defined atom compare function.
Definition: AtomCompareFunction.hpp:41
CDPL::Chem::BasicAtom::getMolecule
const Molecule & getMolecule() const
Returns a const reference to the parent molecule.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL::Chem::BasicAtom::getBondToAtom
Bond & getBondToAtom(const Atom &atom)
Returns a non-const reference to the Chem::Bond object that connects this atom to the argument atom.
CDPL::Chem::BasicAtom::getBondsEnd
ConstBondIterator getBondsEnd() const
Returns a constant iterator pointing to the end of the incident bonds.
CDPL::Chem::BasicAtom::getBondsEnd
BondIterator getBondsEnd()
Returns a mutable iterator pointing to the end of the incident bonds.
CDPL::Chem::BasicAtom::findBondToAtom
Bond * findBondToAtom(const Atom &atom)
Returns a pointer to the non-const Chem::Bond object that connects this atom to the argument atom.
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::Bond
Bond.
Definition: Bond.hpp:50
CDPL::Chem::BasicAtom::getIndex
std::size_t getIndex() const
Returns the index of the atom in its parent molecule.
CDPL::Chem::BasicAtom::getBond
const Bond & getBond(std::size_t idx) const
Returns a const reference to the incident bond at index idx.
CDPL::Chem::BasicAtom::getBondsBegin
BondIterator getBondsBegin()
Returns a mutable iterator pointing to the beginning of the incident bonds.
CDPL::Chem::BasicMolecule
BasicMolecule.
Definition: BasicMolecule.hpp:54
CDPL::Chem::BasicAtom::getBondIndex
std::size_t getBondIndex(const Bond &bond) const
Returns the index of the specified incident bond.
CDPL::Util::IndexedElementIterator
A STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Chem::BasicAtom::BondIterator
boost::transform_iterator< BondAccessor< BasicBond >, NeighborList::iterator > BondIterator
Definition: BasicAtom.hpp:88
CDPL::Chem::BasicAtom::getAtomsEnd
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the connected atoms.
CDPL::Chem::BasicBond
BasicBond.
Definition: BasicBond.hpp:49
CDPL::Chem::BasicAtom::ConstAtomIterator
boost::transform_iterator< AtomAccessor< const BasicAtom >, NeighborList::const_iterator > ConstAtomIterator
Definition: BasicAtom.hpp:87
CDPL::Chem::connectAtoms
CDPL_CHEM_API void connectAtoms(Molecule &mol, double dist_tol=0.3, std::size_t atom_idx_offs=0)
CDPL::Chem::BasicAtom::getBondToAtom
const Bond & getBondToAtom(const Atom &atom) const
Returns a const reference to the Chem::Bond object that connects this atom to the argument atom.
CDPL::Chem::BasicAtom::containsAtom
bool containsAtom(const Atom &atom) const
Tells whether this atom and the argument atom are connected by a bond.
CDPL::Chem::Molecule
Molecule.
Definition: Molecule.hpp:49
CDPL::Chem::BasicAtom::orderBonds
void orderBonds(const BondCompareFunction &func)
Orders the stored bonds according to criteria implemented by the provided bond comparison function.
CDPL::Chem::BasicAtom::getAtom
Atom & getAtom(std::size_t idx)
Returns a non-const reference to the connected atom at index idx.
CDPL::Chem::BasicAtom::findBondToAtom
const Bond * findBondToAtom(const Atom &atom) const
Returns a pointer to the const Chem::Bond object that connects this atom to the argument atom.
CDPL::Chem::BasicAtom::getNumBonds
std::size_t getNumBonds() const
Returns the number of incident bonds.
CDPL::Chem::BondCompareFunction
std::function< bool(const Chem::Bond &, const Chem::Bond &)> BondCompareFunction
A generic wrapper class used to store a user-defined bond compare function.
Definition: BondCompareFunction.hpp:41
Atom.hpp
Definition of the class CDPL::Chem::Atom.
CDPL::Chem::BasicAtom::getAtomIndex
std::size_t getAtomIndex(const Atom &atom) const
Returns the index of the specified connected atom.
CDPL::Chem::BasicAtom::getAtomsEnd
AtomIterator getAtomsEnd()
Returns a mutable iterator pointing to the end of the connected atoms.
CDPL::Chem::BasicAtom::getMolecule
Molecule & getMolecule()
Returns a non-const reference to the parent molecule.
CDPL::Chem::BasicAtom::getBondsBegin
ConstBondIterator getBondsBegin() const
Returns a constant iterator pointing to the beginning of the incident bonds.
CDPL::Chem::BasicAtom::containsBond
bool containsBond(const Bond &bond) const
Tells whether the specified bond is incident to this atom.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::BasicAtom::getAtomsBegin
AtomIterator getAtomsBegin()
CDPL::Chem::BasicAtom::getAtomsBegin
ConstAtomIterator getAtomsBegin() const
CDPL::Chem::BasicAtom::AtomIterator
boost::transform_iterator< AtomAccessor< BasicAtom >, NeighborList::iterator > AtomIterator
Definition: BasicAtom.hpp:86
CDPL::Chem::BasicAtom::getNumAtoms
std::size_t getNumAtoms() const
Returns the number of connected atoms.
CDPL::Chem::BasicAtom::getBond
Bond & getBond(std::size_t idx)
Returns a non-const reference to the incident bond at index idx.
CDPL::Chem::BasicAtom::operator=
BasicAtom & operator=(const BasicAtom &atom)
Assignment operator that replaces the current set of properties with the properties of atom;.
CDPL::Chem::BasicAtom::orderAtoms
void orderAtoms(const AtomCompareFunction &func)
Orders the stored atoms according to criteria implemented by the provided atom comparison function.
CDPL::Chem::BasicAtom::getAtom
const Atom & getAtom(std::size_t idx) const
Returns a const reference to the connected atom at index idx.