Chemical Data Processing Library C++ API - Version 1.4.0
CanonicalFragment.hpp
Go to the documentation of this file.
1 /*
2  * CanonicalFragment.hpp
3  *
4  * This file is part of the ConfGenical 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_CONFGEN_CANONICALFRAGMENT_HPP
30 #define CDPL_CONFGEN_CANONICALFRAGMENT_HPP
31 
32 #include <vector>
33 #include <cstddef>
34 #include <cstdint>
35 #include <memory>
36 
41 #include "CDPL/Util/Array.hpp"
42 
43 
44 namespace CDPL
45 {
46 
47  namespace ConfGen
48  {
49 
61  {
62 
63  public:
67  typedef std::shared_ptr<CanonicalFragment> SharedPointer;
68 
73 
78 
83 
88 
92  typedef std::vector<const Chem::Atom*> AtomMapping;
93 
98 
105 
111 
115  void clear();
116 
121  std::size_t getNumAtoms() const;
122 
128  const Chem::Atom& getAtom(std::size_t idx) const;
129 
135  Chem::Atom& getAtom(std::size_t idx);
136 
142 
148 
154 
160 
166  bool containsAtom(const Chem::Atom& atom) const;
167 
173  std::size_t getAtomIndex(const Chem::Atom& atom) const;
174 
179  std::size_t getNumEntities() const;
180 
186  const Chem::Entity3D& getEntity(std::size_t idx) const;
187 
193  Chem::Entity3D& getEntity(std::size_t idx);
194 
199  std::size_t getNumBonds() const;
200 
206  const Chem::Bond& getBond(std::size_t idx) const;
207 
213  Chem::Bond& getBond(std::size_t idx);
214 
220 
226 
232 
238 
244  bool containsBond(const Chem::Bond& bond) const;
245 
251  std::size_t getBondIndex(const Chem::Bond& bond) const;
252 
258 
264 
269  std::uint64_t getHashCode() const;
270 
276 
283 
291  void create(const Chem::MolecularGraph& molgraph, const Chem::MolecularGraph& parent,
292  bool modify = true, bool strip_aro_subst = true);
293 
298  const AtomMapping& getAtomMapping() const;
299 
303  void perceiveSSSR();
304 
305  private:
306  void copyAtoms(const Chem::MolecularGraph& molgraph, const Chem::MolecularGraph& parent,
307  bool modify, bool strip_aro_subst);
308  bool copyBonds(const Chem::MolecularGraph& molgraph);
309 
310  void fixStereoDescriptors(const Chem::MolecularGraph& molgraph, bool clear_stereo);
311  void hydrogenize();
312  void canonicalize(bool stereo);
313  void calcHashCode(bool stereo);
314 
315  bool compareCanonNumber(const Chem::Atom& atom1, const Chem::Atom& atom2) const;
316 
317  typedef std::vector<std::uint32_t> HashInputData;
318  typedef Chem::SmallestSetOfSmallestRings::SharedPointer SmallestSetOfSmallestRingsPtr;
319 
320  Chem::BasicMolecule molecule;
321  std::uint64_t hashCode;
323  SmallestSetOfSmallestRingsPtr sssr;
324  Util::STArray canonNumbers;
325  HashInputData hashInputData;
326  AtomMapping atomMapping;
327  };
328  } // namespace ConfGen
329 } // namespace CDPL
330 
331 #endif // CDPL_CONFGEN_CANONICALFRAGMENT_HPP
Definition of class CDPL::Util::Array.
Definition of class CDPL::Chem::BasicMolecule.
Definition of class CDPL::Chem::CanonicalNumberingCalculator.
Definition of the preprocessor macro CDPL_CONFGEN_API.
#define CDPL_CONFGEN_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Definition of class CDPL::Chem::SmallestSetOfSmallestRings.
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:57
Concrete Chem::Molecule implementation that owns Chem::BasicAtom and Chem::BasicBond instances.
Definition: BasicMolecule.hpp:60
boost::indirect_iterator< AtomList::const_iterator, const BasicAtom > ConstAtomIterator
Constant random-access iterator over the atoms of the molecule.
Definition: BasicMolecule.hpp:78
boost::indirect_iterator< BondList::iterator, BasicBond > BondIterator
Mutable random-access iterator over the bonds of the molecule.
Definition: BasicMolecule.hpp:80
boost::indirect_iterator< BondList::const_iterator, const BasicBond > ConstBondIterator
Constant random-access iterator over the bonds of the molecule.
Definition: BasicMolecule.hpp:82
boost::indirect_iterator< AtomList::iterator, BasicAtom > AtomIterator
Mutable random-access iterator over the atoms of the molecule.
Definition: BasicMolecule.hpp:76
Abstract base class representing a chemical bond between two Chem::Atom instances.
Definition: Bond.hpp:54
Calculation of canonical atom numberings for molecular graphs using McKay's algorithm.
Definition: CanonicalNumberingCalculator.hpp:72
Base class for objects that have a position in 3D space (e.g. Chem::Atom and Chem::Feature).
Definition: Entity3D.hpp:46
Abstract base class for representations of a chemical structure as a graph of bonded atoms.
Definition: MolecularGraph.hpp:57
std::shared_ptr< MolecularGraph > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MolecularGraph instances.
Definition: MolecularGraph.hpp:63
std::shared_ptr< SmallestSetOfSmallestRings > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated SmallestSetOfSmallestRings instan...
Definition: SmallestSetOfSmallestRings.hpp:64
Data structure representing a canonicalized molecular fragment.
Definition: CanonicalFragment.hpp:61
Chem::BasicMolecule::BondIterator BondIterator
A mutable iterator over the contained bonds.
Definition: CanonicalFragment.hpp:82
void orderBonds(const Chem::BondCompareFunction &func)
Reorders the bonds of the fragment according to func.
AtomIterator getAtomsBegin()
Returns a mutable iterator pointing to the first atom.
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the first atom.
const AtomMapping & getAtomMapping() const
Returns the atom mapping from this fragment to the parent molecular graph.
BondIterator getBondsEnd()
Returns a mutable iterator pointing one past the last bond.
void perceiveSSSR()
Perceives the smallest set of smallest rings of the fragment.
std::shared_ptr< CanonicalFragment > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated CanonicalFragment instances.
Definition: CanonicalFragment.hpp:67
ConstBondIterator getBondsBegin() const
Returns a constant iterator pointing to the first bond.
std::size_t getNumEntities() const
Returns the number of 3D entities in the fragment.
void create(const Chem::MolecularGraph &molgraph, const Chem::MolecularGraph &parent, bool modify=true, bool strip_aro_subst=true)
Builds the canonical fragment from the fragment molgraph of the parent molecular graph parent.
bool containsAtom(const Chem::Atom &atom) const
Tells whether the fragment contains atom.
Chem::BasicMolecule::ConstAtomIterator ConstAtomIterator
A constant iterator over the contained atoms.
Definition: CanonicalFragment.hpp:77
CanonicalFragment(const CanonicalFragment &frag)
Constructs a copy of the CanonicalFragment instance frag.
std::size_t getAtomIndex(const Chem::Atom &atom) const
Returns the index of atom in the fragment.
CanonicalFragment & operator=(const CanonicalFragment &frag)
Replaces the contents of this fragment with a copy of frag.
Chem::Bond & getBond(std::size_t idx)
Returns a reference to the bond at index idx.
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing one past the last atom.
std::uint64_t getHashCode() const
Returns the hash code of the fragment.
const Chem::Atom & getAtom(std::size_t idx) const
Returns a const reference to the atom at index idx.
CanonicalFragment(const Chem::MolecularGraph &molgraph, const Chem::MolecularGraph &parent)
Constructs a CanonicalFragment instance from the fragment molgraph of the parent molecular graph pare...
const Chem::Bond & getBond(std::size_t idx) const
Returns a const reference to the bond at index idx.
const Chem::Entity3D & getEntity(std::size_t idx) const
Returns a const reference to the 3D entity at index idx.
Chem::MolecularGraph::SharedPointer clone() const
Creates and returns a deep copy of the fragment.
void clear()
Removes all atoms and bonds and resets the hash code.
bool containsBond(const Chem::Bond &bond) const
Tells whether the fragment contains bond.
std::vector< const Chem::Atom * > AtomMapping
Maps each atom of the fragment (in canonical order) to the corresponding atom of the parent molecular...
Definition: CanonicalFragment.hpp:92
Chem::Atom & getAtom(std::size_t idx)
Returns a reference to the atom at index idx.
CanonicalFragment()
Constructs an empty CanonicalFragment instance.
std::size_t getNumAtoms() const
Returns the number of atoms in the fragment.
Chem::Entity3D & getEntity(std::size_t idx)
Returns a reference to the 3D entity at index idx.
ConstBondIterator getBondsEnd() const
Returns a constant iterator pointing one past the last bond.
BondIterator getBondsBegin()
Returns a mutable iterator pointing to the first bond.
AtomIterator getAtomsEnd()
Returns a mutable iterator pointing one past the last atom.
std::size_t getNumBonds() const
Returns the number of bonds in the fragment.
Chem::BasicMolecule::ConstBondIterator ConstBondIterator
A constant iterator over the contained bonds.
Definition: CanonicalFragment.hpp:87
std::size_t getBondIndex(const Chem::Bond &bond) const
Returns the index of bond in the fragment.
Chem::BasicMolecule::AtomIterator AtomIterator
A mutable iterator over the contained atoms.
Definition: CanonicalFragment.hpp:72
void orderAtoms(const Chem::AtomCompareFunction &func)
Reorders the atoms of the fragment according to func.
STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
std::function< bool(const Atom &, const Atom &)> AtomCompareFunction
Generic wrapper class used to store a user-defined atom compare function.
Definition: AtomCompareFunction.hpp:41
CDPL_CHEM_API std::uint64_t calcHashCode(const MolecularGraph &molgraph, unsigned int atom_flags=AtomPropertyFlag::DEFAULT, unsigned int bond_flags=BondPropertyFlag::DEFAULT, bool ord_h_deplete=true)
Computes a 64-bit hash code for molgraph taking into account the specified atom and bond properties.
CDPL_CHEM_API void canonicalize(MolecularGraph &molgraph, const AtomCompareFunction &func, bool atoms=true, bool atom_nbrs=true, bool bonds=true, bool bond_atoms=false)
Reorders the atoms (and optionally their neighbors and bonds) of molgraph according to a user-supplie...
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
Array< std::size_t > STArray
Array storing unsigned integers of type std::size_t.
Definition: Array.hpp:575
The namespace of the Chemical Data Processing Library.