Chemical Data Processing Library C++ API - Version 1.4.0
Molecule.hpp
Go to the documentation of this file.
1 /*
2  * Molecule.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_MOLECULE_HPP
30 #define CDPL_CHEM_MOLECULE_HPP
31 
32 #include <memory>
33 #include <functional>
34 
35 #include "CDPL/Chem/APIPrefix.hpp"
37 
38 
39 namespace CDPL
40 {
41 
42  namespace Chem
43  {
44 
53  {
54 
55  public:
59  typedef std::shared_ptr<Molecule> SharedPointer;
60 
65 
70 
75 
80 
85  typedef std::function<void(Molecule&, const MolecularGraph&)> CopyPostprocessingFunction;
86 
87 
93  virtual ~Molecule() {}
94 
97 
100 
104  virtual void clear() = 0;
105 
110  virtual std::size_t getNumAtoms() const = 0;
111 
116  virtual std::size_t getNumBonds() const = 0;
117 
124  virtual const Atom& getAtom(std::size_t idx) const = 0;
125 
132  virtual Atom& getAtom(std::size_t idx) = 0;
133 
141  virtual Atom& addAtom() = 0;
142 
152  virtual void removeAtom(std::size_t idx) = 0;
153 
166 
173  virtual const Bond& getBond(std::size_t idx) const = 0;
174 
181  virtual Bond& getBond(std::size_t idx) = 0;
182 
197  virtual Bond& addBond(std::size_t atom1_idx, std::size_t atom2_idx) = 0;
198 
204  virtual void removeBond(std::size_t idx) = 0;
205 
214 
220  virtual bool containsAtom(const Atom& atom) const = 0;
221 
227  virtual bool containsBond(const Bond& bond) const = 0;
228 
235  virtual std::size_t getAtomIndex(const Atom& atom) const = 0;
236 
243  virtual std::size_t getBondIndex(const Bond& bond) const = 0;
244 
250  virtual void copy(const Molecule& mol) = 0;
251 
257  virtual void copy(const MolecularGraph& molgraph) = 0;
258 
265  virtual void append(const Molecule& mol) = 0;
266 
273  virtual void append(const MolecularGraph& molgraph) = 0;
274 
280  virtual void remove(const MolecularGraph& molgraph) = 0;
281 
289  virtual void reserveMemoryForAtoms(std::size_t num_atoms) {}
290 
298  virtual void reserveMemoryForBonds(std::size_t num_bonds) {}
299 
310 
320  Molecule& operator=(const MolecularGraph& molgraph);
321 
332 
342  Molecule& operator+=(const MolecularGraph& molgraph);
343 
352  Molecule& operator-=(const MolecularGraph& molgraph);
353 
363 
364  protected:
370  };
371  } // namespace Chem
372 } // namespace CDPL
373 
374 #endif // CDPL_CHEM_MOLECULE_HPP
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::MolecularGraph.
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Atom objects.
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::Atom objects.
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:57
ConstBondIterator getBondsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::Bond objects.
ConstBondIterator getBondsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Bond objects.
Abstract base class representing a chemical bond between two Chem::Atom instances.
Definition: Bond.hpp:54
Abstract base class for representations of a chemical structure as a graph of bonded atoms.
Definition: MolecularGraph.hpp:57
Abstract base class representing a mutable molecular graph that owns its atoms and bonds.
Definition: Molecule.hpp:53
virtual bool containsAtom(const Atom &atom) const =0
Tells whether the specified atom is part of this molecule.
AtomContainer::ConstAtomIterator ConstAtomIterator
A constant random access iterator used to iterate over the atoms of the molecule.
Definition: Molecule.hpp:64
virtual void copy(const MolecularGraph &molgraph)=0
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
virtual void reserveMemoryForBonds(std::size_t num_bonds)
Reserves memory for num_bonds bonds.
Definition: Molecule.hpp:298
virtual const Bond & getBond(std::size_t idx) const =0
Returns a const reference to the bond at index idx.
virtual void remove(const MolecularGraph &molgraph)=0
Removes atoms and bonds referenced by the molecular graph molgraph that are part of this Molecule ins...
virtual void append(const Molecule &mol)=0
Extends the current set of atoms and bonds by a copy of the atoms and bonds in the molecule mol.
Molecule & operator=(const MolecularGraph &molgraph)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
virtual bool containsBond(const Bond &bond) const =0
Tells whether the specified bond is part of this molecule.
std::shared_ptr< Molecule > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Molecule instances.
Definition: Molecule.hpp:59
virtual Bond & getBond(std::size_t idx)=0
Returns a non-const reference to the bond at index idx.
virtual std::size_t getBondIndex(const Bond &bond) const =0
Returns the index of the specified bond.
BondContainer::ConstBondIterator ConstBondIterator
A constant random access iterator used to iterate over the bonds of the molecule.
Definition: Molecule.hpp:74
virtual Bond & addBond(std::size_t atom1_idx, std::size_t atom2_idx)=0
Creates a new or returns an already existing bond between the atoms specified by atom1_idx and atom2_...
BondIterator removeBond(const BondIterator &it)
Removes the bond specified by the iterator it.
Molecule & operator-=(const MolecularGraph &molgraph)
Removes atoms and bonds referenced by the molecular graph molgraph that are part of this Molecule ins...
Molecule & operator=(const Molecule &mol)
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
AtomContainer::AtomIterator AtomIterator
A mutable random access iterator used to iterate over the atoms of the molecule.
Definition: Molecule.hpp:69
virtual void append(const MolecularGraph &molgraph)=0
Extends the current set of atoms and bonds by a copy of the atoms and bonds in the molecular graph mo...
virtual std::size_t getNumAtoms() const =0
Returns the number of explicit atoms.
virtual void reserveMemoryForAtoms(std::size_t num_atoms)
Reserves memory for num_atoms atoms.
Definition: Molecule.hpp:289
virtual ~Molecule()
Virtual destructor.
Definition: Molecule.hpp:93
virtual Atom & getAtom(std::size_t idx)=0
Returns a non-const reference to the atom at index idx.
virtual const Atom & getAtom(std::size_t idx) const =0
Returns a const reference to the atom at index idx.
virtual std::size_t getNumBonds() const =0
Returns the number of explicit bonds.
virtual void clear()=0
Removes all atoms and bonds and clears all properties of the molecule.
Molecule & operator+=(const Molecule &mol)
Extends the current set of atoms and bonds by a copy of the atoms and bonds in the molecule mol.
static void registerCopyPostprocessingFunction(const CopyPostprocessingFunction &func)
Registers a new copy-postprocessing function in the global registry.
virtual void removeBond(std::size_t idx)=0
Removes the bond at the specified index.
std::function< void(Molecule &, const MolecularGraph &)> CopyPostprocessingFunction
Type of a callback invoked after a molecule has been copied from a source molecular graph (first argu...
Definition: Molecule.hpp:85
virtual std::size_t getAtomIndex(const Atom &atom) const =0
Returns the index of the specified atom.
void invokeCopyPostprocessingFunctions(const MolecularGraph &src_molgraph)
Invokes all registered copy-postprocessing functions on this molecule with src_molgraph as the source...
virtual void removeAtom(std::size_t idx)=0
Removes the atom at the specified index.
virtual void copy(const Molecule &mol)=0
Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties ...
virtual Atom & addAtom()=0
Creates a new atom and adds it to the molecule.
AtomIterator removeAtom(const AtomIterator &it)
Removes the atom specified by the iterator it.
Molecule & operator+=(const MolecularGraph &molgraph)
Extends the current set of atoms and bonds by a copy of the atoms and bonds in the molecular graph mo...
BondContainer::BondIterator BondIterator
A mutable random access iterator used to iterate over the bonds of the molecule.
Definition: Molecule.hpp:79
STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
The namespace of the Chemical Data Processing Library.