Chemical Data Processing Library C++ API - Version 1.4.0
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 
57  class CDPL_CHEM_API BasicAtom : public Atom
58  {
59 
60  friend class BasicMolecule;
61 
62  typedef std::pair<BasicAtom*, BasicBond*> AtomBondPair;
63  typedef std::vector<AtomBondPair> NeighborList;
64 
65  template <typename AtomType>
66  struct AtomAccessor
67  {
68 
69  typedef AtomType& result_type;
70 
71  AtomType& operator()(const AtomBondPair& ab_pair) const
72  {
73  return *ab_pair.first;
74  }
75  };
76 
77  template <typename BondType>
78  struct BondAccessor
79  {
80 
81  typedef BondType& result_type;
82 
83  BondType& operator()(const AtomBondPair& ab_pair) const
84  {
85  return *ab_pair.second;
86  }
87  };
88 
89  public:
93  typedef boost::transform_iterator<AtomAccessor<BasicAtom>, NeighborList::iterator> AtomIterator;
94 
98  typedef boost::transform_iterator<AtomAccessor<const BasicAtom>, NeighborList::const_iterator> ConstAtomIterator;
99 
103  typedef boost::transform_iterator<BondAccessor<BasicBond>, NeighborList::iterator> BondIterator;
104 
108  typedef boost::transform_iterator<BondAccessor<const BasicBond>, NeighborList::const_iterator> ConstBondIterator;
109 
114  const Molecule& getMolecule() const;
115 
121 
126  std::size_t getNumAtoms() const;
127 
132  std::size_t getNumBonds() const;
133 
140  const Bond& getBond(std::size_t idx) const;
141 
148  Bond& getBond(std::size_t idx);
149 
156  const Bond& getBondToAtom(const Atom& atom) const;
157 
164  Bond& getBondToAtom(const Atom& atom);
165 
171  const Bond* findBondToAtom(const Atom& atom) const;
172 
178  Bond* findBondToAtom(const Atom& atom);
179 
186  const Atom& getAtom(std::size_t idx) const;
187 
194  Atom& getAtom(std::size_t idx);
195 
201 
207 
213 
219 
225 
231 
237 
243 
249  bool containsAtom(const Atom& atom) const;
250 
256  bool containsBond(const Bond& bond) const;
257 
264  std::size_t getAtomIndex(const Atom& atom) const;
265 
272  std::size_t getBondIndex(const Bond& bond) const;
273 
278  std::size_t getIndex() const;
279 
284  void orderAtoms(const AtomCompareFunction& func);
285 
290  void orderBonds(const BondCompareFunction& func);
291 
298 
299  using Atom::operator=;
300 
301  private:
302  BasicAtom(BasicMolecule* mol);
303 
304  BasicAtom(const BasicAtom& atom);
305 
306  ~BasicAtom();
307 
308  void setIndex(std::size_t idx);
309 
310  void clearAdjacencyLists();
311 
312  static void reserveMemForNewBond(BasicAtom& atom1, BasicAtom& atom2);
313  static void connectAtoms(BasicAtom& atom1, BasicAtom& atom2, BasicBond& bond);
314  static void disconnectAtoms(BasicBond& bond);
315 
316  BasicMolecule* molecule;
317  std::size_t index;
318  NeighborList neighbors;
319  };
320  } // namespace Chem
321 } // namespace CDPL
322 
323 #endif // CDPL_CHEM_BASICATOM_HPP
Definition of class CDPL::Chem::Atom.
Definition of the preprocessor macro CDPL_CHEM_API.
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:57
Concrete Chem::Atom implementation used as the atom type of Chem::BasicMolecule.
Definition: BasicAtom.hpp:58
void orderAtoms(const AtomCompareFunction &func)
Reorders the connected (neighbor) atom list using the binary comparator func.
AtomIterator getAtomsEnd()
Returns a mutable iterator pointing to the end of the connected atoms.
Bond & getBondToAtom(const Atom &atom)
Returns the incident bond that connects this atom with atom.
BondIterator getBondsEnd()
Returns a mutable iterator pointing to the end of the incident bonds.
ConstBondIterator getBondsEnd() const
Returns a constant iterator pointing to the end of the incident bonds.
boost::transform_iterator< AtomAccessor< const BasicAtom >, NeighborList::const_iterator > ConstAtomIterator
Constant random-access iterator over the connected (neighbor) atoms.
Definition: BasicAtom.hpp:98
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the connected atoms.
BondIterator getBondsBegin()
Returns a mutable iterator pointing to the beginning of the incident bonds.
bool containsAtom(const Atom &atom) const
Tells whether atom is a neighbor of this atom.
std::size_t getIndex() const
Returns the index of this atom in its owning molecule's atom list.
bool containsBond(const Bond &bond) const
Tells whether bond is an incident bond of this atom.
ConstBondIterator getBondsBegin() const
Returns a constant iterator pointing to the beginning of the incident bonds.
Bond * findBondToAtom(const Atom &atom)
Looks up the incident bond that connects this atom with atom without throwing.
std::size_t getNumBonds() const
Returns the number of incident bonds (equal to getNumAtoms()).
std::size_t getBondIndex(const Bond &bond) const
Returns the index of the incident bond bond.
BasicAtom & operator=(const BasicAtom &atom)
Assignment operator that replaces the current set of properties with the properties of atom;.
Molecule & getMolecule()
Returns a mutable reference to the molecule owning this atom.
boost::transform_iterator< BondAccessor< BasicBond >, NeighborList::iterator > BondIterator
Mutable random-access iterator over the incident bonds.
Definition: BasicAtom.hpp:103
const Bond & getBondToAtom(const Atom &atom) const
Returns the incident bond that connects this atom with atom.
void orderBonds(const BondCompareFunction &func)
Reorders the incident bond list using the binary comparator func.
AtomIterator getAtomsBegin()
Returns a mutable iterator pointing to the beginning of the connected atoms.
boost::transform_iterator< AtomAccessor< BasicAtom >, NeighborList::iterator > AtomIterator
Mutable random-access iterator over the connected (neighbor) atoms.
Definition: BasicAtom.hpp:93
const Bond * findBondToAtom(const Atom &atom) const
Looks up the incident bond that connects this atom with atom without throwing.
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the beginning of the connected atoms.
std::size_t getAtomIndex(const Atom &atom) const
Returns the index of the neighbor atom atom in the connected-atoms list.
Bond & getBond(std::size_t idx)
Returns a mutable reference to the incident bond at index idx.
std::size_t getNumAtoms() const
Returns the number of connected (neighbor) atoms.
const Bond & getBond(std::size_t idx) const
Returns a const reference to the incident bond at index idx.
boost::transform_iterator< BondAccessor< const BasicBond >, NeighborList::const_iterator > ConstBondIterator
Constant random-access iterator over the incident bonds.
Definition: BasicAtom.hpp:108
const Molecule & getMolecule() const
Returns a const reference to the molecule owning this atom.
Atom & getAtom(std::size_t idx)
Returns a mutable reference to the connected (neighbor) atom at index idx.
const Atom & getAtom(std::size_t idx) const
Returns a const reference to the connected (neighbor) atom at index idx.
Default implementation of the Chem::Bond interface.
Definition: BasicBond.hpp:52
Concrete Chem::Molecule implementation that owns Chem::BasicAtom and Chem::BasicBond instances.
Definition: BasicMolecule.hpp:60
Abstract base class representing a chemical bond between two Chem::Atom instances.
Definition: Bond.hpp:54
Abstract base class representing a mutable molecular graph that owns its atoms and bonds.
Definition: Molecule.hpp:53
STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
std::function< bool(const Atom &, const Atom &)> AtomCompareFunction
Generic wrapper class used to store a user-defined atom compare function.
Definition: AtomCompareFunction.hpp:41
CDPL_CHEM_API void connectAtoms(Molecule &mol, double dist_tol=0.3, std::size_t atom_idx_offs=0)
Adds bonds between atoms of the molecule mol whose 3D distance falls within the covalent-radii sum pl...
std::function< bool(const Chem::Bond &, const Chem::Bond &)> BondCompareFunction
Generic wrapper class used to store a user-defined bond compare function.
Definition: BondCompareFunction.hpp:41
The namespace of the Chemical Data Processing Library.