Chemical Data Processing Library C++ API - Version 1.2.0
PathFingerprintGenerator.hpp
Go to the documentation of this file.
1 /*
2  * PathFingerprintGenerator.hpp
3  *
4  * Implementation of Daylight style Path Fingerprints
5  *
6  * This file is part of the Chemical Data Processing Toolkit
7  *
8  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; see the file COPYING. If not, write to
22  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */
25 
31 #ifndef CDPL_DESCR_PATHFINGERPRINTGENERATOR_HPP
32 #define CDPL_DESCR_PATHFINGERPRINTGENERATOR_HPP
33 
34 #include <cstddef>
35 #include <cstdint>
36 #include <vector>
37 #include <functional>
38 
39 #include <boost/random/linear_congruential.hpp>
40 
41 #include "CDPL/Descr/APIPrefix.hpp"
44 #include "CDPL/Util/BitSet.hpp"
45 
46 
47 namespace CDPL
48 {
49 
50  namespace Chem
51  {
52 
53  class MolecularGraph;
54  class Atom;
55  class Bond;
56  } // namespace Chem
57 
58  namespace Descr
59  {
60 
66  {
67 
68  public:
73  static constexpr unsigned int DEF_ATOM_PROPERTY_FLAGS =
76 
81  static constexpr unsigned int DEF_BOND_PROPERTY_FLAGS =
83 
88  {
89 
90  public:
103  DefAtomDescriptorFunctor(unsigned int flags = DEF_ATOM_PROPERTY_FLAGS):
104  flags(flags) {}
105 
115  std::uint64_t operator()(const Chem::Atom& atom) const;
116 
117  private:
118  unsigned int flags;
119  };
120 
125  {
126 
127  public:
139  DefBondDescriptorFunctor(unsigned int flags = DEF_BOND_PROPERTY_FLAGS):
140  flags(flags) {}
141 
151  std::uint64_t operator()(const Chem::Bond& bond) const;
152 
153  private:
154  unsigned int flags;
155  };
156 
165  typedef std::function<std::uint64_t(const Chem::Atom&)> AtomDescriptorFunction;
166 
175  typedef std::function<std::uint64_t(const Chem::Bond&)> BondDescriptorFunction;
176 
181 
189 
196 
203 
213  void setMinPathLength(std::size_t min_length);
214 
220  std::size_t getMinPathLength() const;
221 
231  void setMaxPathLength(std::size_t max_length);
232 
238  std::size_t getMaxPathLength() const;
239 
245  void generate(const Chem::MolecularGraph& molgraph, Util::BitSet& fp);
246 
247  private:
248  void calcFingerprint(const Chem::MolecularGraph&, Util::BitSet&);
249 
250  void growPath(const Chem::Atom&, Util::BitSet&);
251 
252  std::size_t calcBitIndex(const Util::BitSet&);
253 
254  typedef std::vector<std::size_t> IndexList;
255  typedef std::vector<std::uint64_t> UInt64Array;
256 
257  const Chem::MolecularGraph* molGraph;
258  std::size_t minPathLength;
259  std::size_t maxPathLength;
260  AtomDescriptorFunction atomDescriptorFunc;
261  BondDescriptorFunction bondDescriptorFunc;
262  Util::BitSet visBondMask;
263  UInt64Array atomDescriptors;
264  UInt64Array bondDescriptors;
265  IndexList atomPath;
266  IndexList bondPath;
267  UInt64Array fwdPathDescriptor;
268  UInt64Array revPathDescriptor;
269  boost::rand48 randGenerator;
270  };
271  } // namespace Descr
272 } // namespace CDPL
273 
274 #endif // CDPL_DESCR_PATHFINGERPRINTGENERATOR_HPP
Definition of the type CDPL::Util::BitSet.
Definition of constants in namespace CDPL::Chem::BondPropertyFlag.
Definition of constants in namespace CDPL::Chem::AtomPropertyFlag.
Definition of the preprocessor macro CDPL_DESCR_API.
#define CDPL_DESCR_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Atom.
Definition: Atom.hpp:52
Bond.
Definition: Bond.hpp:50
MolecularGraph.
Definition: MolecularGraph.hpp:52
The default functor for the generation of atom descriptors.
Definition: PathFingerprintGenerator.hpp:88
DefAtomDescriptorFunctor(unsigned int flags=DEF_ATOM_PROPERTY_FLAGS)
Constructs the atom descriptor functor object for the specified set of atomic properties.
Definition: PathFingerprintGenerator.hpp:103
std::uint64_t operator()(const Chem::Atom &atom) const
Generates a descriptor for the argument atom.
The default functor for the generation of bond descriptors.
Definition: PathFingerprintGenerator.hpp:125
DefBondDescriptorFunctor(unsigned int flags=DEF_BOND_PROPERTY_FLAGS)
Constructs the bond descriptor functor object for the specified set of bond properties.
Definition: PathFingerprintGenerator.hpp:139
std::uint64_t operator()(const Chem::Bond &bond) const
Generates a descriptor for the argument bond.
PathFingerprintGenerator.
Definition: PathFingerprintGenerator.hpp:66
void setBondDescriptorFunction(const BondDescriptorFunction &func)
Allows to specify a custom function for the generation of bond descriptors.
PathFingerprintGenerator()
Constructs the PathFingerprintGenerator instance.
void generate(const Chem::MolecularGraph &molgraph, Util::BitSet &fp)
Generates the fingerprint of the molecular graph molgraph.
std::function< std::uint64_t(const Chem::Bond &)> BondDescriptorFunction
Type of the generic functor class used to store user-defined functions or function objects for the ge...
Definition: PathFingerprintGenerator.hpp:175
void setAtomDescriptorFunction(const AtomDescriptorFunction &func)
Allows to specify a custom function for the generation of atom descriptors.
std::size_t getMaxPathLength() const
Returns the maximum considered path length.
void setMinPathLength(std::size_t min_length)
Allows to specify the minimum length a path must have to contribute to the generated fingerprint.
std::size_t getMinPathLength() const
Returns the minimum length a path must have to contribute to the generated fingerprint.
PathFingerprintGenerator(const Chem::MolecularGraph &molgraph, Util::BitSet &fp)
Constructs the PathFingerprintGenerator instance and generates the fingerprint of the molecular graph...
void setMaxPathLength(std::size_t max_length)
Allows to specify the maximum considered path length.
std::function< std::uint64_t(const Chem::Atom &)> AtomDescriptorFunction
Type of the generic functor class used to store user-defined functions or function objects for the ge...
Definition: PathFingerprintGenerator.hpp:165
constexpr unsigned int FORMAL_CHARGE
Specifies the formal charge of an atom.
Definition: Chem/AtomPropertyFlag.hpp:73
constexpr unsigned int AROMATICITY
Specifies the membership of an atom in aromatic rings.
Definition: Chem/AtomPropertyFlag.hpp:93
constexpr unsigned int ISOTOPE
Specifies the isotopic mass of an atom.
Definition: Chem/AtomPropertyFlag.hpp:68
constexpr unsigned int TYPE
Specifies the generic type or element of an atom.
Definition: Chem/AtomPropertyFlag.hpp:63
constexpr unsigned int AROMATICITY
Specifies the membership of a bond in aromatic rings.
Definition: BondPropertyFlag.hpp:73
constexpr unsigned int ORDER
Specifies the order of a bond.
Definition: BondPropertyFlag.hpp:63
constexpr unsigned int TOPOLOGY
Specifies the ring/chain topology of a bond.
Definition: BondPropertyFlag.hpp:68
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.