Chemical Data Processing Library C++ API - Version 1.1.1
ElectronSystem.hpp
Go to the documentation of this file.
1 /*
2  * ElectronSystem.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_ELECTRONSYSTEM_HPP
30 #define CDPL_CHEM_ELECTRONSYSTEM_HPP
31 
32 #include <vector>
33 #include <utility>
34 #include <unordered_map>
35 #include <memory>
36 
37 #include <boost/iterator/indirect_iterator.hpp>
38 
39 #include "CDPL/Chem/APIPrefix.hpp"
41 
42 
43 namespace CDPL
44 {
45 
46  namespace Chem
47  {
48 
49  class BondContainer;
50 
55  {
56 
57  typedef std::vector<Atom*> AtomList;
58 
59  public:
63  typedef std::shared_ptr<ElectronSystem> SharedPointer;
64 
68  typedef boost::indirect_iterator<AtomList::const_iterator, const Atom> ConstAtomIterator;
69 
73  typedef boost::indirect_iterator<AtomList::iterator, Atom> AtomIterator;
74 
79 
84  std::size_t getNumAtoms() const;
85 
91  bool containsAtom(const Atom& atom) const;
92 
99  std::size_t getAtomIndex(const Atom& atom) const;
100 
107  const Atom& getAtom(std::size_t idx) const;
108 
115  Atom& getAtom(std::size_t idx);
116 
122 
128 
134 
140 
144  void clear();
145 
150  void orderAtoms(const AtomCompareFunction& func);
151 
159  bool addAtom(const Chem::Atom& atom, std::size_t elec_contrib);
160 
169  bool addAtoms(const ElectronSystem& elec_sys);
170 
176  void removeAtom(std::size_t idx);
177 
186 
192  bool removeAtom(const Atom& atom);
193 
198  std::size_t getNumElectrons() const;
199 
206  std::size_t getElectronContrib(const Atom& atom) const;
207 
214  std::size_t getElectronContrib(std::size_t idx) const;
215 
222  void setElectronContrib(const Atom& atom, std::size_t elec_contrib);
223 
230  void setElectronContrib(std::size_t idx, std::size_t elec_contrib);
231 
240  void merge(const ElectronSystem& elec_sys);
241 
247  bool overlaps(const ElectronSystem& elec_sys) const;
248 
254  bool contains(const ElectronSystem& elec_sys) const;
255 
262  bool connected(const ElectronSystem& elec_sys, const BondContainer& bonds) const;
263 
268  void swap(ElectronSystem& elec_sys);
269 
270  private:
271  typedef std::pair<std::size_t, std::size_t> UIPair;
272  typedef std::unordered_map<const Atom*, UIPair> AtomIdxAndElecContribMap;
273 
274  AtomList atoms;
275  AtomIdxAndElecContribMap atomIndsAndElecContribs;
276  std::size_t numElectrons;
277  };
278  } // namespace Chem
279 } // namespace CDPL
280 
281 #endif // CDPL_CHEM_ELECTRONSYSTEM_HPP
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
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL::Chem::ElectronSystem::setElectronContrib
void setElectronContrib(const Atom &atom, std::size_t elec_contrib)
Changes the number of electrons that are contributed by the specified atom.
CDPL::Chem::ElectronSystem::getAtomsEnd
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::Atom objects.
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::ElectronSystem::connected
bool connected(const ElectronSystem &elec_sys, const BondContainer &bonds) const
Checks if the atom sets of the electron systems do not intersect but are linked by at least one bond.
CDPL::Chem::ElectronSystem::getNumAtoms
std::size_t getNumAtoms() const
Returns the number of atoms contributing to the electron system.
CDPL::Chem::ElectronSystem::removeAtom
AtomIterator removeAtom(const AtomIterator &it)
Removes the atom specified by the iterator it.
CDPL::Chem::ElectronSystem::getAtomsBegin
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Atom objects.
CDPL::Util::IndexedElementIterator
A STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
CDPL::Chem::ElectronSystem::removeAtom
bool removeAtom(const Atom &atom)
Removes the specified atom.
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Chem::ElectronSystem::clear
void clear()
Removes all atoms.
CDPL::Chem::ElectronSystem::contains
bool contains(const ElectronSystem &elec_sys) const
Checks if all atoms in the electron system elec_sys are also part of this electron system.
CDPL::Chem::ElectronSystem::getAtom
const Atom & getAtom(std::size_t idx) const
Returns a const reference to the atom at index idx.
CDPL::Chem::ElectronSystem::orderAtoms
void orderAtoms(const AtomCompareFunction &func)
Orders the stored atoms according to criteria implemented by the provided atom comparison function.
CDPL::Chem::ElectronSystem
Describes an electron system of a molecule in terms of involved atoms and their electron contribution...
Definition: ElectronSystem.hpp:55
CDPL::Chem::ElectronSystem::getElectronContrib
std::size_t getElectronContrib(std::size_t idx) const
Returns the number of electrons contributed by the atom at the specified index.
CDPL::Chem::AtomContainer
A common interface for data-structures that support a random access to stored Chem::Atom instances.
Definition: AtomContainer.hpp:55
AtomContainer.hpp
Definition of the class CDPL::Chem::AtomContainer.
CDPL::Chem::ElectronSystem::removeAtom
void removeAtom(std::size_t idx)
Removes the atom at the specified index.
CDPL::Chem::ElectronSystem::addAtoms
bool addAtoms(const ElectronSystem &elec_sys)
Adds the atoms and associated electron contributions in the electron system elec_sys to this system.
CDPL::Chem::ElectronSystem::ElectronSystem
ElectronSystem()
Constructs an empty ElectronSystem instance.
CDPL::Chem::ElectronSystem::getElectronContrib
std::size_t getElectronContrib(const Atom &atom) const
Returns the number of electrons contributed by the specified atom.
CDPL::Chem::ElectronSystem::SharedPointer
std::shared_ptr< ElectronSystem > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ElectronSystem instances.
Definition: ElectronSystem.hpp:63
CDPL::Chem::ElectronSystem::getNumElectrons
std::size_t getNumElectrons() const
Returns the total number of electrons contributed by the involved atoms.
CDPL::Chem::ElectronSystem::getAtomsBegin
AtomIterator getAtomsBegin()
Returns a mutable iterator pointing to the beginning of the stored const Chem::Atom objects.
CDPL::Chem::ElectronSystem::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: ElectronSystem.hpp:68
CDPL::Chem::ElectronSystem::addAtom
bool addAtom(const Chem::Atom &atom, std::size_t elec_contrib)
Extends the electron system by the specified atom and its electron contributions.
CDPL::Chem::ElectronSystem::getAtom
Atom & getAtom(std::size_t idx)
Returns a non-const reference to the atom at index idx.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::ElectronSystem::merge
void merge(const ElectronSystem &elec_sys)
Merges the atoms and associated electron contributions in the electron system elec_sys with this syst...
CDPL::Chem::ElectronSystem::setElectronContrib
void setElectronContrib(std::size_t idx, std::size_t elec_contrib)
Changes the number of electrons that are contributed by the atom at the specified index.
CDPL::Chem::BondContainer
A common interface for data-structures that support a random access to stored Chem::Bond instances.
Definition: BondContainer.hpp:54
CDPL::Chem::ElectronSystem::AtomIterator
boost::indirect_iterator< AtomList::iterator, Atom > AtomIterator
A mutable random access iterator used to iterate over the stored const Chem::Atom objects.
Definition: ElectronSystem.hpp:73
CDPL::Chem::ElectronSystem::getAtomIndex
std::size_t getAtomIndex(const Atom &atom) const
Returns the index of the specified atom.
CDPL::Chem::ElectronSystem::containsAtom
bool containsAtom(const Atom &atom) const
Tells whether the specified atom is part of the electron system.
CDPL::Chem::ElectronSystem::swap
void swap(ElectronSystem &elec_sys)
Exchanges the state of this electron system with the state of the system elec_sys.
CDPL::Chem::ElectronSystem::overlaps
bool overlaps(const ElectronSystem &elec_sys) const
Checks if the electron system shares at least one atom with the system elec_sys.
CDPL::Chem::ElectronSystem::getAtomsEnd
AtomIterator getAtomsEnd()
Returns a mutable iterator pointing to the end of the stored const Chem::Atom objects.