Chemical Data Processing Library C++ API - Version 1.4.0
BasicMolecule.hpp
Go to the documentation of this file.
1 /*
2  * BasicMolecule.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_BASICMOLECULE_HPP
30 #define CDPL_CHEM_BASICMOLECULE_HPP
31 
32 #include <vector>
33 #include <memory>
34 
35 #include <boost/iterator/indirect_iterator.hpp>
36 
37 #include "CDPL/Chem/APIPrefix.hpp"
38 #include "CDPL/Chem/Molecule.hpp"
39 #include "CDPL/Chem/BasicAtom.hpp"
40 #include "CDPL/Chem/BasicBond.hpp"
41 #include "CDPL/Util/ObjectPool.hpp"
42 
43 
44 namespace CDPL
45 {
46 
47  namespace Chem
48  {
49 
58  {
59 
62  typedef AtomCache::SharedObjectPointer AtomPtr;
63  typedef BondCache::SharedObjectPointer BondPtr;
64  typedef std::vector<AtomPtr> AtomList;
65  typedef std::vector<BondPtr> BondList;
66 
67  public:
71  typedef std::shared_ptr<BasicMolecule> SharedPointer;
72 
76  typedef boost::indirect_iterator<AtomList::iterator, BasicAtom> AtomIterator;
77 
81  typedef boost::indirect_iterator<AtomList::const_iterator, const BasicAtom> ConstAtomIterator;
82 
86  typedef boost::indirect_iterator<BondList::iterator, BasicBond> BondIterator;
87 
91  typedef boost::indirect_iterator<BondList::const_iterator, const BasicBond> ConstBondIterator;
92 
97 
103 
108  BasicMolecule(const Molecule& mol);
109 
115  explicit BasicMolecule(const MolecularGraph& molgraph);
116 
123 
124  void clear();
125 
126  std::size_t getNumAtoms() const;
127 
128  std::size_t getNumBonds() const;
129 
135 
141 
147 
153 
159 
165 
171 
177 
178  const BasicAtom& getAtom(std::size_t idx) const;
179 
180  BasicAtom& getAtom(std::size_t idx);
181 
183 
184  void removeAtom(std::size_t idx);
185 
197 
198  const BasicBond& getBond(std::size_t idx) const;
199 
200  BasicBond& getBond(std::size_t idx);
201 
202  BasicBond& addBond(std::size_t atom1_idx, std::size_t atom2_idx);
203 
204  void removeBond(std::size_t idx);
205 
213 
214  bool containsAtom(const Atom& atom) const;
215 
216  bool containsBond(const Bond& bond) const;
217 
218  std::size_t getAtomIndex(const Atom& atom) const;
219 
220  std::size_t getBondIndex(const Bond& bond) const;
221 
222  void orderAtoms(const AtomCompareFunction& func);
223 
224  void orderBonds(const BondCompareFunction& func);
225 
236 
237  using Molecule::operator=;
238 
249 
250  using Molecule::operator+=;
251 
253 
259  void copy(const BasicMolecule& mol);
260 
261  void copy(const Molecule& mol);
262 
263  void copy(const MolecularGraph& molgraph);
264 
271  void append(const BasicMolecule& mol);
272 
273  void append(const Molecule& mol);
274 
275  void append(const MolecularGraph& molgraph);
276 
277  void remove(const MolecularGraph& molgraph);
278 
279  void reserveMemoryForAtoms(std::size_t num_atoms);
280 
281  void reserveMemoryForBonds(std::size_t num_bonds);
282 
283  private:
284  template <typename T>
285  void doCopy(const T& mol);
286 
287  template <typename T>
288  void doAppend(const T& mol);
289 
290  void clearAtomsAndBonds();
291 
292  void renumberAtoms(std::size_t idx);
293  void renumberBonds(std::size_t idx);
294 
295  BasicAtom* createAtom();
296  BasicBond* createBond();
297 
298  static void destroyAtom(BasicAtom* atom);
299  static void destroyBond(BasicBond* bond);
300 
301  static void clearAtom(BasicAtom& atom);
302  static void clearBond(BasicBond& bond);
303 
304  AtomCache atomCache;
305  BondCache bondCache;
306  AtomList atoms;
307  BondList bonds;
308  };
309  } // namespace Chem
310 } // namespace CDPL
311 
312 #endif // CDPL_CHEM_BASICMOLECULE_HPP
Definition of class CDPL::Chem::BasicAtom.
Definition of class CDPL::Chem::BasicBond.
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.
Definition of class CDPL::Chem::Molecule.
Definition of class CDPL::Util::ObjectPool.
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
Default implementation of the Chem::Bond interface.
Definition: BasicBond.hpp:52
Default implementation of the Chem::Molecule interface.
Definition: BasicMolecule.hpp:58
void removeAtom(std::size_t idx)
Removes the atom at the specified index.
void orderAtoms(const AtomCompareFunction &func)
Orders the atoms according to criteria implemented by the provided atom comparison function.
BasicBond & addBond(std::size_t atom1_idx, std::size_t atom2_idx)
Creates a new or returns an already existing bond between the atoms specified by atom1_idx and atom2_...
std::size_t getBondIndex(const Bond &bond) const
Returns the index of the specified bond.
const BasicBond & getBond(std::size_t idx) const
Returns a const reference to the bond at index idx.
std::shared_ptr< BasicMolecule > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated BasicMolecule instances.
Definition: BasicMolecule.hpp:71
boost::indirect_iterator< AtomList::const_iterator, const BasicAtom > ConstAtomIterator
A constant random access iterator used to iterate over the stored const Chem::BasicAtom objects.
Definition: BasicMolecule.hpp:81
void append(const MolecularGraph &molgraph)
Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecular graph mo...
boost::indirect_iterator< BondList::iterator, BasicBond > BondIterator
A mutable random access iterator used to iterate over the stored Chem::BasicBond objects.
Definition: BasicMolecule.hpp:86
bool containsBond(const Bond &bond) const
Tells whether the specified bond is part of the bond sequence.
BondIterator removeBond(const BondIterator &it)
Removes the bond specified by the iterator it.
void clear()
Removes all atoms and bonds and clears all properties of the molecule.
void append(const Molecule &mol)
Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecule mol.
BasicAtom & addAtom()
Creates a new atom and adds it to the molecule.
void removeBond(std::size_t idx)
Removes the bond at the specified index.
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::BasicAtom objects.
const BasicAtom & getAtom(std::size_t idx) const
Returns a const reference to the atom at index idx.
void copy(const Molecule &mol)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
void orderBonds(const BondCompareFunction &func)
Orders the bonds according to criteria implemented by the provided bond comparison function.
BasicMolecule(const Molecule &mol)
Constructs a BasicMolecule instance that is a copy of the molecule mol.
ConstBondIterator getBondsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::BasicBond objects.
std::size_t getNumAtoms() const
Returns the number of atoms.
void copy(const MolecularGraph &molgraph)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
std::size_t getAtomIndex(const Atom &atom) const
Returns the index of the specified atom.
AtomIterator removeAtom(const AtomIterator &it)
Removes the atom specified by the iterator it.
BasicMolecule & operator=(const BasicMolecule &mol)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
std::size_t getNumBonds() const
Returns the number of bonds.
void copy(const BasicMolecule &mol)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
BasicBond & getBond(std::size_t idx)
Returns a non-const reference to the bond at index idx.
boost::indirect_iterator< BondList::const_iterator, const BasicBond > ConstBondIterator
A constant random access iterator used to iterate over the stored const Chem::BasicBond objects.
Definition: BasicMolecule.hpp:91
void reserveMemoryForAtoms(std::size_t num_atoms)
Reserves memory for num_atoms atoms.
BasicAtom & getAtom(std::size_t idx)
Returns a non-const reference to the atom at index idx.
boost::indirect_iterator< AtomList::iterator, BasicAtom > AtomIterator
A mutable random access iterator used to iterate over the stored Chem::BasicAtom objects.
Definition: BasicMolecule.hpp:76
BondIterator getBondsEnd()
Returns a mutable iterator pointing to the end of the stored Chem::BasicBond objects.
MolecularGraph::SharedPointer clone() const
Creates a deep copy of the molecular graph.
BasicMolecule()
Constructs an empty BasicMolecule instance.
BasicMolecule & operator+=(const BasicMolecule &mol)
Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecule mol.
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::BasicAtom objects.
BasicMolecule(const MolecularGraph &molgraph)
Constructs a BasicMolecule instance with copies of the atoms, bonds and properties provided by the mo...
ConstBondIterator getBondsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::BasicBond objects.
bool containsAtom(const Atom &atom) const
Tells whether the specified atom is part of the atom sequence.
void reserveMemoryForBonds(std::size_t num_bonds)
Reserves memory for num_bonds bonds.
AtomIterator getAtomsBegin()
Returns a mutable iterator pointing to the beginning of the stored Chem::BasicAtom objects.
AtomIterator getAtomsEnd()
Returns a mutable iterator pointing to the end of the stored Chem::BasicAtom objects.
BondIterator getBondsBegin()
Returns a mutable iterator pointing to the beginning of the stored Chem::BasicBond objects.
void remove(const MolecularGraph &molgraph)
Removes atoms and bonds referenced by the molecular graph molgraph that are part of this Molecule ins...
void append(const BasicMolecule &mol)
Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecule mol.
BasicMolecule(const BasicMolecule &mol)
Constructs a BasicMolecule instance that is a copy of the molecule mol.
Abstract base class representing a chemical bond between two atoms (represented by Chem::Atom instanc...
Definition: Bond.hpp:54
Abstract base class for data structures that represent chemical structures as molecular graphs.
Definition: MolecularGraph.hpp:60
std::shared_ptr< MolecularGraph > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MolecularGraph instances.
Definition: MolecularGraph.hpp:66
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::shared_ptr< ObjectType > SharedObjectPointer
A smart pointer to a borrowed object that returns the object to the pool on destruction.
Definition: ObjectPool.hpp:71
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
std::function< bool(const Atom &, const Atom &)> AtomCompareFunction
Generic wrapper class used to store a user-defined atom compare function.
Definition: AtomCompareFunction.hpp:41
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.