Chemical Data Processing Library C++ API - Version 1.1.1
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 
57  {
58 
59  public:
64  static constexpr unsigned int DEF_ATOM_PROPERTY_FLAGS =
68 
73  static constexpr unsigned int DEF_BOND_PROPERTY_FLAGS =
76 
81  {
82 
83  public:
99  DefAtomHashSeedFunctor(const HashCodeCalculator& calculator, unsigned int flags = DEF_ATOM_PROPERTY_FLAGS):
100  calculator(calculator), flags(flags) {}
101 
111  std::uint64_t operator()(const Atom& atom) const;
112 
113  private:
114  std::uint64_t getAtomTypeHashSeed(const Atom&) const;
115  std::uint64_t getAtomIsotopeHashSeed(const Atom&) const;
116  std::uint64_t getAtomChargeHashSeed(const Atom&) const;
117  std::uint64_t getAtomHCountHashSeed(const Atom&) const;
118  std::uint64_t getAtomConfigHashSeed(const Atom&) const;
119  std::uint64_t getAtomAromaticityHashSeed(const Atom&) const;
120 
121  const HashCodeCalculator& calculator;
122  unsigned int flags;
123  };
124 
129  {
130 
131  public:
144  DefBondHashSeedFunctor(unsigned int flags = DEF_BOND_PROPERTY_FLAGS):
145  flags(flags) {}
146 
156  std::uint64_t operator()(const Bond& bond) const;
157 
158  private:
159  std::uint64_t getBondTypeHashSeed(const Bond&) const;
160  std::uint64_t getBondConfigHashSeed(const Bond&) const;
161  std::uint64_t getBondTopologyHashSeed(const Bond&) const;
162 
163  unsigned int flags;
164  };
165 
174  typedef std::function<std::uint64_t(const Atom&)> AtomHashSeedFunction;
175 
184  typedef std::function<std::uint64_t(const Bond&)> BondHashSeedFunction;
185 
190 
200 
207 
214 
220  std::uint64_t calculate(const MolecularGraph& molgraph);
221 
226  std::uint64_t getResult() const;
227 
228  private:
230 
231  HashCodeCalculator& operator=(const HashCodeCalculator&);
232 
233  void init(const MolecularGraph&);
234 
235  void calcAtomHashCodes();
236  void calcBondHashCodes();
237  void calcSHAHashCode();
238 
239  typedef std::vector<std::uint64_t> UInt64Array;
240  typedef std::vector<std::size_t> IndexList;
241 
242  const MolecularGraph* molGraph;
243  AtomHashSeedFunction atomHashSeedFunc;
244  BondHashSeedFunction bondHashSeedFunc;
245  UInt64Array atomHashCodes;
246  UInt64Array bondHashCodes;
247  UInt64Array tmpHashCodes1;
248  UInt64Array tmpHashCodes2;
249  UInt64Array shaInput;
250  std::uint8_t shaHashCode[20];
251  };
252  } // namespace Chem
253 } // namespace CDPL
254 
255 #endif // CDPL_CHEM_HASHCODECALCULATOR_HPP
CDPL::Chem::AtomPropertyFlag::FORMAL_CHARGE
const unsigned int FORMAL_CHARGE
Specifies the formal charge of an atom.
Definition: Chem/AtomPropertyFlag.hpp:73
CDPL::Chem::BondPropertyFlag::AROMATICITY
const unsigned int AROMATICITY
Specifies the membership of a bond in aromatic rings.
Definition: BondPropertyFlag.hpp:73
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::Bond
Bond.
Definition: Bond.hpp:50
CDPL::Chem::HashCodeCalculator::DefBondHashSeedFunctor::operator()
std::uint64_t operator()(const Bond &bond) const
Generates an initial hash code value (seed) for the specified bond.
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Chem::BondPropertyFlag::CIP_CONFIGURATION
const unsigned int CIP_CONFIGURATION
Specifies the CIP-configuration of a double bond.
Definition: BondPropertyFlag.hpp:58
CDPL::Chem::HashCodeCalculator::DefBondHashSeedFunctor::DefBondHashSeedFunctor
DefBondHashSeedFunctor(unsigned int flags=DEF_BOND_PROPERTY_FLAGS)
Constructs the bond hash seed functor object for the specified set of bond properties.
Definition: HashCodeCalculator.hpp:144
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
AtomPropertyFlag.hpp
Definition of constants in namespace CDPL::Chem::AtomPropertyFlag.
CDPL::Chem::HashCodeCalculator::getResult
std::uint64_t getResult() const
Returns the result of the last hash code calculation.
CDPL::Chem::HashCodeCalculator::calculate
std::uint64_t calculate(const MolecularGraph &molgraph)
Calculates the hash code of the molecular graph molgraph.
CDPL::Chem::HashCodeCalculator::setAtomHashSeedFunction
void setAtomHashSeedFunction(const AtomHashSeedFunction &func)
Allows to specify a custom function for the generation of initial atom hash codes.
CDPL::Chem::HashCodeCalculator::HashCodeCalculator
HashCodeCalculator(const MolecularGraph &molgraph)
Constructs the HashCodeCalculator instance and calculates the hash code of the molecular graph molgra...
CDPL::Chem::HashCodeCalculator::BondHashSeedFunction
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:184
CDPL::Chem::BondPropertyFlag::ORDER
const unsigned int ORDER
Specifies the order of a bond.
Definition: BondPropertyFlag.hpp:63
CDPL::Chem::HashCodeCalculator::DefAtomHashSeedFunctor::DefAtomHashSeedFunctor
DefAtomHashSeedFunctor(const HashCodeCalculator &calculator, unsigned int flags=DEF_ATOM_PROPERTY_FLAGS)
Constructs the atom hash seed functor object for the specified set of atomic properties.
Definition: HashCodeCalculator.hpp:99
CDPL::Chem::HashCodeCalculator::DefBondHashSeedFunctor
The default functor for the generation of bond hash seeds.
Definition: HashCodeCalculator.hpp:129
CDPL::Chem::BondPropertyFlag::TOPOLOGY
const unsigned int TOPOLOGY
Specifies the ring/chain topology of a bond.
Definition: BondPropertyFlag.hpp:68
CDPL::Chem::AtomPropertyFlag::TYPE
const unsigned int TYPE
Specifies the generic type or element of an atom.
Definition: Chem/AtomPropertyFlag.hpp:63
CDPL::Chem::AtomPropertyFlag::ISOTOPE
const unsigned int ISOTOPE
Specifies the isotopic mass of an atom.
Definition: Chem/AtomPropertyFlag.hpp:68
CDPL::Chem::HashCodeCalculator::DefAtomHashSeedFunctor
The default functor for the generation of atom hash seeds.
Definition: HashCodeCalculator.hpp:81
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::AtomPropertyFlag::CIP_CONFIGURATION
const unsigned int CIP_CONFIGURATION
Specifies the CIP-configuration of a chiral atom.
Definition: Chem/AtomPropertyFlag.hpp:58
CDPL::Chem::HashCodeCalculator::HashCodeCalculator
HashCodeCalculator()
Constructs the HashCodeCalculator instance.
CDPL::Chem::AtomPropertyFlag::AROMATICITY
const unsigned int AROMATICITY
Specifies the membership of an atom in aromatic rings.
Definition: Chem/AtomPropertyFlag.hpp:93
CDPL::Chem::HashCodeCalculator::AtomHashSeedFunction
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:174
CDPL::Chem::HashCodeCalculator
HashCodeCalculator.
Definition: HashCodeCalculator.hpp:57
CDPL::Chem::AtomPropertyFlag::H_COUNT
const unsigned int H_COUNT
Specifies the hydrogen count of an atom.
Definition: Chem/AtomPropertyFlag.hpp:78
BondPropertyFlag.hpp
Definition of constants in namespace CDPL::Chem::BondPropertyFlag.
CDPL::Chem::HashCodeCalculator::DefAtomHashSeedFunctor::operator()
std::uint64_t operator()(const Atom &atom) const
Generates an initial hash code value (seed) for the specified atom.
CDPL::Chem::HashCodeCalculator::setBondHashSeedFunction
void setBondHashSeedFunction(const BondHashSeedFunction &func)
Allows to specify a custom function for the generation of initial bond hash codes.