Chemical Data Processing Library C++ API - Version 1.1.1
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 
54  {
55 
58  typedef AtomCache::SharedObjectPointer AtomPtr;
59  typedef BondCache::SharedObjectPointer BondPtr;
60  typedef std::vector<AtomPtr> AtomList;
61  typedef std::vector<BondPtr> BondList;
62 
63  public:
67  typedef std::shared_ptr<BasicMolecule> SharedPointer;
68 
69  typedef boost::indirect_iterator<AtomList::iterator, BasicAtom> AtomIterator;
70  typedef boost::indirect_iterator<AtomList::const_iterator, const BasicAtom> ConstAtomIterator;
71  typedef boost::indirect_iterator<BondList::iterator, BasicBond> BondIterator;
72  typedef boost::indirect_iterator<BondList::const_iterator, const BasicBond> ConstBondIterator;
73 
78 
84 
89  BasicMolecule(const Molecule& mol);
90 
96  explicit BasicMolecule(const MolecularGraph& molgraph);
97 
104 
105  void clear();
106 
107  std::size_t getNumAtoms() const;
108 
109  std::size_t getNumBonds() const;
110 
116 
122 
128 
134 
140 
146 
152 
158 
159  const BasicAtom& getAtom(std::size_t idx) const;
160 
161  BasicAtom& getAtom(std::size_t idx);
162 
164 
165  void removeAtom(std::size_t idx);
166 
179 
180  const BasicBond& getBond(std::size_t idx) const;
181 
182  BasicBond& getBond(std::size_t idx);
183 
184  BasicBond& addBond(std::size_t atom1_idx, std::size_t atom2_idx);
185 
186  void removeBond(std::size_t idx);
187 
196 
197  bool containsAtom(const Atom& atom) const;
198 
199  bool containsBond(const Bond& bond) const;
200 
201  std::size_t getAtomIndex(const Atom& atom) const;
202 
203  std::size_t getBondIndex(const Bond& bond) const;
204 
205  void orderAtoms(const AtomCompareFunction& func);
206 
207  void orderBonds(const BondCompareFunction& func);
208 
219 
220  using Molecule::operator=;
221 
232 
233  using Molecule::operator+=;
234 
236 
242  void copy(const BasicMolecule& mol);
243 
244  void copy(const Molecule& mol);
245 
246  void copy(const MolecularGraph& molgraph);
247 
254  void append(const BasicMolecule& mol);
255 
256  void append(const Molecule& mol);
257 
258  void append(const MolecularGraph& molgraph);
259 
260  void remove(const MolecularGraph& molgraph);
261 
262  void reserveMemoryForAtoms(std::size_t num_atoms);
263 
264  void reserveMemoryForBonds(std::size_t num_bonds);
265 
266  private:
267  template <typename T>
268  void doCopy(const T& mol);
269 
270  template <typename T>
271  void doAppend(const T& mol);
272 
273  void clearAtomsAndBonds();
274 
275  void renumberAtoms(std::size_t idx);
276  void renumberBonds(std::size_t idx);
277 
278  BasicAtom* createAtom();
279  BasicBond* createBond();
280 
281  static void destroyAtom(BasicAtom* atom);
282  static void destroyBond(BasicBond* bond);
283 
284  static void clearAtom(BasicAtom& atom);
285  static void clearBond(BasicBond& bond);
286 
287  AtomCache atomCache;
288  BondCache bondCache;
289  AtomList atoms;
290  BondList bonds;
291  };
292  } // namespace Chem
293 } // namespace CDPL
294 
295 #endif // CDPL_CHEM_BASICMOLECULE_HPP
CDPL::Chem::MolecularGraph::SharedPointer
std::shared_ptr< MolecularGraph > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MolecularGraph instances.
Definition: MolecularGraph.hpp:58
Molecule.hpp
Definition of the class CDPL::Chem::Molecule.
CDPL::Chem::BasicMolecule::addAtom
BasicAtom & addAtom()
Creates a new atom and adds it to the molecule.
CDPL::Chem::BasicAtom
BasicAtom.
Definition: BasicAtom.hpp:54
ObjectPool.hpp
Definition of the class CDPL::Util::ObjectPool.
CDPL::Chem::BasicMolecule::getAtomIndex
std::size_t getAtomIndex(const Atom &atom) const
Returns the index of the specified atom.
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::BasicMolecule::containsAtom
bool containsAtom(const Atom &atom) const
Tells whether the specified atom is part of this molecule.
CDPL::Chem::BasicMolecule::getBondsEnd
ConstBondIterator getBondsEnd() const
Returns a constant iterator pointing to the end of the bonds.
CDPL::Chem::BasicMolecule::operator+=
BasicMolecule & operator+=(const BasicMolecule &mol)
Extends the current set of atoms and bonds by a copy of the atoms and bonds in the molecule mol.
CDPL::Chem::BasicMolecule::getBondsBegin
ConstBondIterator getBondsBegin() const
Returns a constant iterator pointing to the beginning of the bonds.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL::Chem::BasicMolecule::reserveMemoryForBonds
void reserveMemoryForBonds(std::size_t num_bonds)
Reserves memory for num_bonds bonds.
CDPL::Chem::BasicMolecule::getAtom
const BasicAtom & getAtom(std::size_t idx) const
Returns a const reference to the atom at index idx.
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::BasicMolecule::getAtomsEnd
AtomIterator getAtomsEnd()
Returns a mutable iterator pointing to the end of the atoms.
CDPL::Chem::BasicMolecule::append
void append(const MolecularGraph &molgraph)
Extends the current set of atoms and bonds by a copy of the atoms and bonds in the molecular graph mo...
CDPL::Chem::BasicMolecule::SharedPointer
std::shared_ptr< BasicMolecule > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated BasicMolecule instances.
Definition: BasicMolecule.hpp:67
CDPL::Chem::BasicMolecule
BasicMolecule.
Definition: BasicMolecule.hpp:54
CDPL::Chem::BasicMolecule::BasicMolecule
BasicMolecule(const MolecularGraph &molgraph)
Constructs a BasicMolecule instance with copies of the atoms and bonds of the Chem::MolecularGraph in...
CDPL::Chem::BasicMolecule::append
void append(const BasicMolecule &mol)
Extends the current set of atoms and bonds by a copy of the atoms and bonds in the molecule mol.
CDPL::Chem::BasicMolecule::getAtomsBegin
AtomIterator getAtomsBegin()
Returns a mutable iterator pointing to the beginning of the atoms.
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::BasicMolecule::clear
void clear()
Removes all atoms and bonds and clears all properties of the molecule.
CDPL::Chem::BasicMolecule::getBondsEnd
BondIterator getBondsEnd()
Returns a mutable iterator pointing to the end of the bonds.
CDPL::Chem::BasicMolecule::copy
void copy(const Molecule &mol)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
CDPL::Chem::BasicBond
BasicBond.
Definition: BasicBond.hpp:49
CDPL::Chem::BasicMolecule::clone
MolecularGraph::SharedPointer clone() const
Creates a copy of the molecular graph.
CDPL::Chem::BasicMolecule::addBond
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_...
CDPL::Chem::BasicMolecule::containsBond
bool containsBond(const Bond &bond) const
Tells whether the specified bond is part of this molecule.
CDPL::Chem::BasicMolecule::getBondIndex
std::size_t getBondIndex(const Bond &bond) const
Returns the index of the specified bond.
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
CDPL::Chem::Molecule
Molecule.
Definition: Molecule.hpp:49
CDPL::Chem::BasicMolecule::operator=
BasicMolecule & operator=(const BasicMolecule &mol)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
CDPL::Chem::BasicMolecule::getAtomsEnd
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the atoms.
CDPL::Chem::BasicMolecule::remove
void remove(const MolecularGraph &molgraph)
Removes atoms and bonds referenced by the molecular graph molgraph that are part of this Molecule ins...
BasicAtom.hpp
Definition of the class CDPL::Chem::BasicAtom.
CDPL::Chem::BasicMolecule::~BasicMolecule
~BasicMolecule()
Destructor.
CDPL::Chem::BasicMolecule::getBond
const BasicBond & getBond(std::size_t idx) const
Returns a const reference to the bond at index idx.
CDPL::Chem::BasicMolecule::removeAtom
void removeAtom(std::size_t idx)
Removes the atom at the specified index.
CDPL::Util::ObjectPool< BasicAtom >
CDPL::Chem::BasicMolecule::BasicMolecule
BasicMolecule(const Molecule &mol)
Constructs a copy of the Chem::Molecule instance mol.
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
CDPL::Chem::BasicMolecule::getAtomsBegin
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the beginning of the atoms.
CDPL::Chem::BasicMolecule::ConstBondIterator
boost::indirect_iterator< BondList::const_iterator, const BasicBond > ConstBondIterator
Definition: BasicMolecule.hpp:72
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
CDPL::Chem::BasicMolecule::BondIterator
boost::indirect_iterator< BondList::iterator, BasicBond > BondIterator
Definition: BasicMolecule.hpp:71
CDPL::Chem::BasicMolecule::AtomIterator
boost::indirect_iterator< AtomList::iterator, BasicAtom > AtomIterator
Definition: BasicMolecule.hpp:69
CDPL::Chem::BasicMolecule::copy
void copy(const MolecularGraph &molgraph)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
CDPL::Chem::BasicMolecule::orderBonds
void orderBonds(const BondCompareFunction &func)
Orders the stored bonds according to criteria implemented by the provided bond comparison function.
CDPL::Chem::BasicMolecule::reserveMemoryForAtoms
void reserveMemoryForAtoms(std::size_t num_atoms)
Reserves memory for num_atoms atoms.
CDPL::Chem::BasicMolecule::getBondsBegin
BondIterator getBondsBegin()
Returns a mutable iterator pointing to the beginning of the bonds.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::BasicMolecule::append
void append(const Molecule &mol)
Extends the current set of atoms and bonds by a copy of the atoms and bonds in the molecule mol.
CDPL::Chem::BasicMolecule::BasicMolecule
BasicMolecule()
Constructs an empty BasicMolecule instance.
CDPL::Chem::BasicMolecule::getBond
BasicBond & getBond(std::size_t idx)
Returns a non-const reference to the bond at index idx.
CDPL::Chem::BasicMolecule::ConstAtomIterator
boost::indirect_iterator< AtomList::const_iterator, const BasicAtom > ConstAtomIterator
Definition: BasicMolecule.hpp:70
CDPL::Chem::BasicMolecule::BasicMolecule
BasicMolecule(const BasicMolecule &mol)
Constructs a copy of the BasicMolecule instance mol.
CDPL::Chem::BasicMolecule::orderAtoms
void orderAtoms(const AtomCompareFunction &func)
Orders the stored atoms according to criteria implemented by the provided atom comparison function.
CDPL::Chem::BasicMolecule::removeBond
BondIterator removeBond(const BondIterator &it)
Removes the bond specified by the iterator it.
CDPL::Chem::BasicMolecule::removeAtom
AtomIterator removeAtom(const AtomIterator &it)
Removes the atom specified by the iterator it.
CDPL::Chem::BasicMolecule::getAtom
BasicAtom & getAtom(std::size_t idx)
Returns a non-const reference to the atom at index idx.
CDPL::Chem::BasicMolecule::removeBond
void removeBond(std::size_t idx)
Removes the bond at the specified index.
CDPL::Chem::BasicMolecule::getNumAtoms
std::size_t getNumAtoms() const
Returns the number of explicit atoms.
CDPL::Chem::BasicMolecule::getNumBonds
std::size_t getNumBonds() const
Returns the number of explicit bonds.
BasicBond.hpp
Definition of the class CDPL::Chem::BasicBond.
CDPL::Chem::BasicMolecule::copy
void copy(const BasicMolecule &mol)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...