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 
56  class CDPL_CHEM_API BasicAtom : public Atom
57  {
58 
59  friend class BasicMolecule;
60 
61  typedef std::pair<BasicAtom*, BasicBond*> AtomBondPair;
62  typedef std::vector<AtomBondPair> NeighborList;
63 
64  template <typename AtomType>
65  struct AtomAccessor
66  {
67 
68  typedef AtomType& result_type;
69 
70  AtomType& operator()(const AtomBondPair& ab_pair) const
71  {
72  return *ab_pair.first;
73  }
74  };
75 
76  template <typename BondType>
77  struct BondAccessor
78  {
79 
80  typedef BondType& result_type;
81 
82  BondType& operator()(const AtomBondPair& ab_pair) const
83  {
84  return *ab_pair.second;
85  }
86  };
87 
88  public:
92  typedef boost::transform_iterator<AtomAccessor<BasicAtom>, NeighborList::iterator> AtomIterator;
93 
97  typedef boost::transform_iterator<AtomAccessor<const BasicAtom>, NeighborList::const_iterator> ConstAtomIterator;
98 
102  typedef boost::transform_iterator<BondAccessor<BasicBond>, NeighborList::iterator> BondIterator;
103 
107  typedef boost::transform_iterator<BondAccessor<const BasicBond>, NeighborList::const_iterator> ConstBondIterator;
108 
109  const Molecule& getMolecule() const;
110 
112 
113  std::size_t getNumAtoms() const;
114 
115  std::size_t getNumBonds() const;
116 
117  const Bond& getBond(std::size_t idx) const;
118 
119  Bond& getBond(std::size_t idx);
120 
121  const Bond& getBondToAtom(const Atom& atom) const;
122 
123  Bond& getBondToAtom(const Atom& atom);
124 
125  const Bond* findBondToAtom(const Atom& atom) const;
126 
127  Bond* findBondToAtom(const Atom& atom);
128 
129  const Atom& getAtom(std::size_t idx) const;
130 
131  Atom& getAtom(std::size_t idx);
132 
138 
144 
150 
156 
162 
168 
174 
180 
181  bool containsAtom(const Atom& atom) const;
182 
183  bool containsBond(const Bond& bond) const;
184 
185  std::size_t getAtomIndex(const Atom& atom) const;
186 
187  std::size_t getBondIndex(const Bond& bond) const;
188 
189  std::size_t getIndex() const;
190 
191  void orderAtoms(const AtomCompareFunction& func);
192 
193  void orderBonds(const BondCompareFunction& func);
194 
201 
202  using Atom::operator=;
203 
204  private:
205  BasicAtom(BasicMolecule* mol);
206 
207  BasicAtom(const BasicAtom& atom);
208 
209  ~BasicAtom();
210 
211  void setIndex(std::size_t idx);
212 
213  void clearAdjacencyLists();
214 
215  static void reserveMemForNewBond(BasicAtom& atom1, BasicAtom& atom2);
216  static void connectAtoms(BasicAtom& atom1, BasicAtom& atom2, BasicBond& bond);
217  static void disconnectAtoms(BasicBond& bond);
218 
219  BasicMolecule* molecule;
220  std::size_t index;
221  NeighborList neighbors;
222  };
223  } // namespace Chem
224 } // namespace CDPL
225 
226 #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:58
Default implementation of the Chem::Atom interface.
Definition: BasicAtom.hpp:57
void orderAtoms(const AtomCompareFunction &func)
Orders the atoms according to criteria implemented by the provided atom comparison function.
AtomIterator getAtomsEnd()
Returns a mutable iterator pointing to the end of the connected Chem::BasicAtom objects.
Bond & getBondToAtom(const Atom &atom)
Returns a non-const reference to the bond that connects this atom to the argument atom.
BondIterator getBondsEnd()
Returns a mutable iterator pointing to the end of the incident Chem::BasicBond objects.
ConstBondIterator getBondsEnd() const
Returns a constant iterator pointing to the end of the incident const Chem::BasicBond objects.
boost::transform_iterator< AtomAccessor< const BasicAtom >, NeighborList::const_iterator > ConstAtomIterator
A constant random access iterator used to iterate over the connected const Chem::BasicAtom objects.
Definition: BasicAtom.hpp:97
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the connected const Chem::BasicAtom objects.
BondIterator getBondsBegin()
Returns a mutable iterator pointing to the beginning of the incident Chem::BasicBond objects.
bool containsAtom(const Atom &atom) const
Tells whether this atom and the specified atom are connected by a bond.
std::size_t getIndex() const
Returns the index of the atom in its parent molecule.
bool containsBond(const Bond &bond) const
Tells whether the specified bond is incident to this atom.
ConstBondIterator getBondsBegin() const
Returns a constant iterator pointing to the beginning of the incident const Chem::BasicBond objects.
Bond * findBondToAtom(const Atom &atom)
Returns a pointer to the non-const bond that connects this atom to the argument atom.
std::size_t getNumBonds() const
Returns the number of incident bonds.
std::size_t getBondIndex(const Bond &bond) const
Returns the index of the specified incident bond.
BasicAtom & operator=(const BasicAtom &atom)
Assignment operator that replaces the current set of properties with the properties of atom.
Molecule & getMolecule()
Returns a non-const reference to the parent molecule.
boost::transform_iterator< BondAccessor< BasicBond >, NeighborList::iterator > BondIterator
A mutable random access iterator used to iterate over the incident Chem::BasicBond objects.
Definition: BasicAtom.hpp:102
const Bond & getBondToAtom(const Atom &atom) const
Returns a const reference to the bond that connects this atom to the argument atom.
void orderBonds(const BondCompareFunction &func)
Orders the bonds according to criteria implemented by the provided bond comparison function.
AtomIterator getAtomsBegin()
Returns a mutable iterator pointing to the end of the connected Chem::BasicAtom objects.
boost::transform_iterator< AtomAccessor< BasicAtom >, NeighborList::iterator > AtomIterator
A mutable random access iterator used to iterate over the connected Chem::BasicAtom objects.
Definition: BasicAtom.hpp:92
const Bond * findBondToAtom(const Atom &atom) const
Returns a pointer to the const bond that connects this atom to the argument atom.
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the beginning of the connected const Chem::BasicAtom objects.
std::size_t getAtomIndex(const Atom &atom) const
Returns the index of the specified connected atom.
Bond & getBond(std::size_t idx)
Returns a non-const reference to the incident bond at index idx.
std::size_t getNumAtoms() const
Returns the number of connected 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
A constant random access iterator used to iterate over the incident const Chem::BasicBond objects.
Definition: BasicAtom.hpp:107
const Molecule & getMolecule() const
Returns a const reference to the parent molecule.
Atom & getAtom(std::size_t idx)
Returns a non-const reference to the connected atom at index idx.
const Atom & getAtom(std::size_t idx) const
Returns a const reference to the connected atom at index idx.
Default implementation of the Chem::Bond interface.
Definition: BasicBond.hpp:52
Default implementation of the Chem::Molecule interface.
Definition: BasicMolecule.hpp:58
Abstract base class representing a chemical bond between two atoms (represented by Chem::Atom instanc...
Definition: Bond.hpp:54
Abstract base class representing a mutable molecular graph that owns and manages 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.