Chemical Data Processing Library C++ API - Version 1.1.1
Fragment.hpp
Go to the documentation of this file.
1 /*
2  * Fragment.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_FRAGMENT_HPP
30 #define CDPL_CHEM_FRAGMENT_HPP
31 
32 #include <vector>
33 #include <unordered_map>
34 #include <memory>
35 
36 #include <boost/iterator/indirect_iterator.hpp>
37 
38 #include "CDPL/Chem/APIPrefix.hpp"
40 
41 
42 namespace CDPL
43 {
44 
45  namespace Chem
46  {
47 
52  {
53 
54  typedef std::vector<Atom*> AtomList;
55  typedef std::vector<Bond*> BondList;
56 
57  public:
61  typedef std::shared_ptr<Fragment> SharedPointer;
62 
66  typedef boost::indirect_iterator<AtomList::const_iterator, const Atom> ConstAtomIterator;
67 
71  typedef boost::indirect_iterator<AtomList::iterator, Atom> AtomIterator;
72 
76  typedef boost::indirect_iterator<BondList::const_iterator, const Bond> ConstBondIterator;
77 
81  typedef boost::indirect_iterator<BondList::iterator, Bond> BondIterator;
82 
87 
92  Fragment(const Fragment& frag);
93 
98  explicit Fragment(const MolecularGraph& molgraph);
99 
106 
111  std::size_t getNumAtoms() const;
112 
117  std::size_t getNumBonds() const;
118 
124  bool containsAtom(const Atom& atom) const;
125 
131  bool containsBond(const Bond& bond) const;
132 
139  std::size_t getAtomIndex(const Atom& atom) const;
140 
147  std::size_t getBondIndex(const Bond& bond) const;
148 
154 
160 
166 
172 
178 
184 
190 
196 
203  const Atom& getAtom(std::size_t idx) const;
204 
211  Atom& getAtom(std::size_t idx);
212 
219  const Bond& getBond(std::size_t idx) const;
220 
227  Bond& getBond(std::size_t idx);
228 
234  bool addAtom(const Atom& atom);
235 
245  bool addBond(const Bond& bond);
246 
256  void removeAtom(std::size_t idx);
257 
270 
280  bool removeAtom(const Atom& atom);
281 
287  void removeBond(std::size_t idx);
288 
297 
303  bool removeBond(const Bond& bond);
304 
308  void clear();
309 
311 
317  void swap(Fragment& frag);
318 
323  void orderAtoms(const AtomCompareFunction& func);
324 
329  void orderBonds(const BondCompareFunction& func);
330 
337  Fragment& operator=(const Fragment& frag);
338 
345  Fragment& operator=(const MolecularGraph& molgraph);
346 
354  Fragment& operator+=(const MolecularGraph& molgraph);
355 
362  Fragment& operator-=(const MolecularGraph& molgraph);
363 
365 
366  void reserveMemoryForAtoms(std::size_t num_atoms);
367 
368  void reserveMemoryForBonds(std::size_t num_bonds);
369 
370  private:
371  typedef std::unordered_map<const Atom*, std::size_t> AtomIndexMap;
372  typedef std::unordered_map<const Bond*, std::size_t> BondIndexMap;
373 
374  AtomList atoms;
375  BondList bonds;
376  AtomIndexMap atomIndices;
377  BondIndexMap bondIndices;
378  };
379  } // namespace Chem
380 } // namespace CDPL
381 
382 #endif // CDPL_CHEM_FRAGMENT_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
CDPL::Chem::Fragment::Fragment
Fragment(const MolecularGraph &molgraph)
Constructs a Fragment instance storing the atoms, bonds and properties of the molecular graph molgrap...
CDPL::Chem::Fragment::ConstBondIterator
boost::indirect_iterator< BondList::const_iterator, const Bond > ConstBondIterator
A constant random access iterator used to iterate over the stored const Chem::Bond objects.
Definition: Fragment.hpp:76
CDPL::Chem::Fragment::orderBonds
void orderBonds(const BondCompareFunction &func)
Orders the stored bonds according to criteria implemented by the provided bond comparison function.
CDPL::Base::PropertyContainer::swap
void swap(PropertyContainer &cntnr)
Exchanges the properties of this container with the properties of the container cntnr.
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::Fragment::operator=
Fragment & operator=(const MolecularGraph &molgraph)
Replaces the current set of atoms, bonds and properties by the atoms, bonds and properties of the mol...
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::Fragment::BondIterator
boost::indirect_iterator< BondList::iterator, Bond > BondIterator
A mutable random access iterator used to iterate over the stored const Chem::Bond objects.
Definition: Fragment.hpp:81
CDPL::Chem::Fragment::containsBond
bool containsBond(const Bond &bond) const
Tells whether the specified bond is part of this fragment.
CDPL::Chem::Bond
Bond.
Definition: Bond.hpp:50
CDPL::Chem::Fragment::swap
void swap(Fragment &frag)
Exchanges the atoms, bonds and properties of this fragment with the atoms, bonds and properties of th...
CDPL::Chem::Fragment::getBondsBegin
BondIterator getBondsBegin()
Returns a mutable iterator pointing to the beginning of the stored const Chem::Bond objects.
CDPL::Chem::Fragment::getBondsBegin
ConstBondIterator getBondsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Bond objects.
CDPL::Chem::Fragment::addAtom
bool addAtom(const Atom &atom)
Extends the fragment by the specified atom.
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::Fragment::clear
void clear()
Removes all atoms and bonds.
CDPL::Chem::Fragment
Fragment.
Definition: Fragment.hpp:52
CDPL::Chem::Fragment::ConstAtomIterator
boost::indirect_iterator< AtomList::const_iterator, const Atom > ConstAtomIterator
A constant random access iterator used to iterate over the stored const Chem::Atom objects.
Definition: Fragment.hpp:66
CDPL::Chem::Fragment::~Fragment
~Fragment()
Destructor.
CDPL::Chem::Fragment::getAtomsEnd
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::Atom objects.
CDPL::Chem::Fragment::getBondsEnd
ConstBondIterator getBondsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::Bond objects.
CDPL::Chem::Fragment::reserveMemoryForBonds
void reserveMemoryForBonds(std::size_t num_bonds)
CDPL::Chem::Fragment::operator+=
Fragment & operator+=(const MolecularGraph &molgraph)
Extends the current set of atoms and bonds by the atoms and bonds in the molecular graph molgraph.
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
CDPL::Chem::Fragment::orderAtoms
void orderAtoms(const AtomCompareFunction &func)
Orders the stored atoms according to criteria implemented by the provided atom comparison function.
CDPL::Chem::Fragment::Fragment
Fragment(const Fragment &frag)
Constructs a copy of the Fragment instance frag.
CDPL::Chem::Fragment::getAtom
const Atom & getAtom(std::size_t idx) const
Returns a const reference to the atom at index idx.
CDPL::Chem::Fragment::getNumBonds
std::size_t getNumBonds() const
Returns the number of bonds.
CDPL::Chem::Fragment::getBondsEnd
BondIterator getBondsEnd()
Returns a mutable iterator pointing to the end of the stored const Chem::Bond objects.
CDPL::Chem::Fragment::getAtomIndex
std::size_t getAtomIndex(const Atom &atom) const
Returns the index of the specified atom.
MolecularGraph.hpp
Definition of the class CDPL::Chem::MolecularGraph.
CDPL::Chem::Fragment::SharedPointer
std::shared_ptr< Fragment > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Fragment instances.
Definition: Fragment.hpp:61
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::Fragment::removeBond
bool removeBond(const Bond &bond)
Removes the specified bond.
CDPL::Chem::Fragment::getAtom
Atom & getAtom(std::size_t idx)
Returns a non-const reference to the atom at index idx.
CDPL::Chem::Fragment::clone
MolecularGraph::SharedPointer clone() const
Creates a copy of the molecular graph.
CDPL::Chem::Fragment::addBond
bool addBond(const Bond &bond)
Extends the fragment by the specified bond.
CDPL::Chem::Fragment::removeBond
BondIterator removeBond(const BondIterator &it)
Removes the bond specified by the iterator it.
CDPL::Chem::Fragment::getBond
const Bond & getBond(std::size_t idx) const
Returns a const reference to the bond at index idx.
CDPL::Chem::Fragment::getAtomsBegin
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Atom objects.
CDPL::Chem::Fragment::AtomIterator
boost::indirect_iterator< AtomList::iterator, Atom > AtomIterator
A mutable random access iterator used to iterate over the stored const Chem::Atom objects.
Definition: Fragment.hpp:71
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::Fragment::getNumAtoms
std::size_t getNumAtoms() const
Returns the number of atoms.
CDPL::Chem::Fragment::Fragment
Fragment()
Constructs an empty Fragment instance.
CDPL::Chem::Fragment::removeAtom
void removeAtom(std::size_t idx)
Removes the atom at the specified index.
CDPL::Chem::Fragment::getBond
Bond & getBond(std::size_t idx)
Returns a non-const reference to the bond at index idx.
CDPL::Chem::Fragment::reserveMemoryForAtoms
void reserveMemoryForAtoms(std::size_t num_atoms)
CDPL::Chem::Fragment::removeBond
void removeBond(std::size_t idx)
Removes the bond at the specified index.
CDPL::Chem::Fragment::operator=
Fragment & operator=(const Fragment &frag)
Replaces the current set of atoms, bonds and properties by the atoms, bonds and properties of the fra...
CDPL::Chem::Fragment::removeAtom
AtomIterator removeAtom(const AtomIterator &it)
Removes the atom specified by the iterator it.
CDPL::Chem::Fragment::containsAtom
bool containsAtom(const Atom &atom) const
Tells whether the specified atom is part of this fragment.
CDPL::Chem::Fragment::getAtomsBegin
AtomIterator getAtomsBegin()
Returns a mutable iterator pointing to the beginning of the stored const Chem::Atom objects.
CDPL::Chem::Fragment::getBondIndex
std::size_t getBondIndex(const Bond &bond) const
Returns the index of the specified bond.
CDPL::Chem::Fragment::operator-=
Fragment & operator-=(const MolecularGraph &molgraph)
Removes the atoms and bonds referenced by the molecular graph molgraph from this Fragment instance.
CDPL::Chem::Fragment::removeAtom
bool removeAtom(const Atom &atom)
Removes the specified atom.
CDPL::Chem::Fragment::getAtomsEnd
AtomIterator getAtomsEnd()
Returns a mutable iterator pointing to the end of the stored const Chem::Atom objects.