Chemical Data Processing Library C++ API - Version 1.4.0
HashCodeCalculator.hpp
Go to the documentation of this file.
1 /*
2  * HashCodeCalculator.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_HASHCODECALCULATOR_HPP
30 #define CDPL_CHEM_HASHCODECALCULATOR_HPP
31 
32 #include <cstddef>
33 #include <cstdint>
34 #include <vector>
35 #include <functional>
36 
37 #include "CDPL/Chem/APIPrefix.hpp"
40 
41 
42 namespace CDPL
43 {
44 
45  namespace Chem
46  {
47 
48  class MolecularGraph;
49  class Atom;
50  class Bond;
51 
68  {
69 
70  public:
75  static constexpr unsigned int DEF_ATOM_PROPERTY_FLAGS =
79 
84  static constexpr unsigned int DEF_BOND_PROPERTY_FLAGS =
87 
92  {
93 
94  public:
110  DefAtomHashSeedFunctor(const HashCodeCalculator& calculator, unsigned int flags = DEF_ATOM_PROPERTY_FLAGS):
111  calculator(calculator), flags(flags) {}
112 
122  std::uint64_t operator()(const Atom& atom) const;
123 
124  private:
125  std::uint64_t getAtomTypeHashSeed(const Atom&) const;
126  std::uint64_t getAtomIsotopeHashSeed(const Atom&) const;
127  std::uint64_t getAtomChargeHashSeed(const Atom&) const;
128  std::uint64_t getAtomHCountHashSeed(const Atom&) const;
129  std::uint64_t getAtomConfigHashSeed(const Atom&) const;
130  std::uint64_t getAtomAromaticityHashSeed(const Atom&) const;
131 
132  const HashCodeCalculator& calculator;
133  unsigned int flags;
134  };
135 
140  {
141 
142  public:
155  DefBondHashSeedFunctor(unsigned int flags = DEF_BOND_PROPERTY_FLAGS):
156  flags(flags) {}
157 
167  std::uint64_t operator()(const Bond& bond) const;
168 
169  private:
170  std::uint64_t getBondTypeHashSeed(const Bond&) const;
171  std::uint64_t getBondConfigHashSeed(const Bond&) const;
172  std::uint64_t getBondTopologyHashSeed(const Bond&) const;
173 
174  unsigned int flags;
175  };
176 
185  typedef std::function<std::uint64_t(const Atom&)> AtomHashSeedFunction;
186 
195  typedef std::function<std::uint64_t(const Bond&)> BondHashSeedFunction;
196 
201 
211 
213 
215 
222 
229 
235  std::uint64_t calculate(const MolecularGraph& molgraph);
236 
241  std::uint64_t getResult() const;
242 
243  private:
244  void init(const MolecularGraph&);
245 
246  void calcAtomHashCodes();
247  void calcBondHashCodes();
248  void calcSHAHashCode();
249 
250  typedef std::vector<std::uint64_t> UInt64Array;
251  typedef std::vector<std::size_t> IndexList;
252 
253  const MolecularGraph* molGraph;
254  AtomHashSeedFunction atomHashSeedFunc;
255  BondHashSeedFunction bondHashSeedFunc;
256  UInt64Array atomHashCodes;
257  UInt64Array bondHashCodes;
258  UInt64Array tmpHashCodes1;
259  UInt64Array tmpHashCodes2;
260  UInt64Array shaInput;
261  std::uint8_t shaHashCode[20];
262  };
263  } // namespace Chem
264 } // namespace CDPL
265 
266 #endif // CDPL_CHEM_HASHCODECALCULATOR_HPP
Definition of constants in namespace CDPL::Chem::BondPropertyFlag.
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 constants in namespace CDPL::Chem::AtomPropertyFlag.
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:58
Abstract base class representing a chemical bond between two atoms (represented by Chem::Atom instanc...
Definition: Bond.hpp:54
Default functor for the generation of atom hash seeds.
Definition: HashCodeCalculator.hpp:92
std::uint64_t operator()(const Atom &atom) const
Generates an initial hash code value (seed) for the specified atom.
DefAtomHashSeedFunctor(const HashCodeCalculator &calculator, unsigned int flags=DEF_ATOM_PROPERTY_FLAGS)
Constructs the DefAtomHashSeedFunctor instance for the specified set of atomic properties.
Definition: HashCodeCalculator.hpp:110
Default functor for the generation of bond hash seeds.
Definition: HashCodeCalculator.hpp:140
DefBondHashSeedFunctor(unsigned int flags=DEF_BOND_PROPERTY_FLAGS)
Constructs the DefBondHashSeedFunctor instance for the specified set of bond properties.
Definition: HashCodeCalculator.hpp:155
std::uint64_t operator()(const Bond &bond) const
Generates an initial hash code value (seed) for the specified bond.
Computes 64-bit hash codes that are characteristic for the topology of a molecular graph and the prop...
Definition: HashCodeCalculator.hpp:68
std::function< std::uint64_t(const Atom &)> AtomHashSeedFunction
Type of the generic functor class used to store user-defined functions or function objects for the ge...
Definition: HashCodeCalculator.hpp:185
void setBondHashSeedFunction(const BondHashSeedFunction &func)
Allows to specify a custom function for the generation of initial bond hash codes.
std::uint64_t calculate(const MolecularGraph &molgraph)
Calculates the hash code of the molecular graph molgraph.
void setAtomHashSeedFunction(const AtomHashSeedFunction &func)
Allows to specify a custom function for the generation of initial atom hash codes.
std::uint64_t getResult() const
Returns the result of the last hash code calculation.
HashCodeCalculator & operator=(const HashCodeCalculator &)=delete
HashCodeCalculator(const HashCodeCalculator &)=delete
HashCodeCalculator()
Constructs the HashCodeCalculator instance.
HashCodeCalculator(const MolecularGraph &molgraph)
Constructs the HashCodeCalculator instance and calculates the hash code of the molecular graph molgra...
std::function< std::uint64_t(const Bond &)> BondHashSeedFunction
Type of the generic functor class used to store user-defined functions or function objects for the ge...
Definition: HashCodeCalculator.hpp:195
Abstract base class for data structures that represent chemical structures as molecular graphs.
Definition: MolecularGraph.hpp:60
constexpr unsigned int FORMAL_CHARGE
Specifies the formal charge of an atom.
Definition: Chem/AtomPropertyFlag.hpp:73
constexpr unsigned int H_COUNT
Specifies the hydrogen count of an atom.
Definition: Chem/AtomPropertyFlag.hpp:78
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 CIP_CONFIGURATION
Specifies the CIP-configuration of a chiral atom.
Definition: Chem/AtomPropertyFlag.hpp:58
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 CIP_CONFIGURATION
Specifies the CIP-configuration of a double bond.
Definition: BondPropertyFlag.hpp:58
constexpr unsigned int TOPOLOGY
Specifies the ring/chain topology of a bond.
Definition: BondPropertyFlag.hpp:68
The namespace of the Chemical Data Processing Library.