Chemical Data Processing Library C++ API - Version 1.0.0
AutomorphismGroupSearch.hpp
Go to the documentation of this file.
1 /*
2  * AutomorphismGroupSearch.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_AUTOMORPHISMGROUPSEARCH_HPP
30 #define CDPL_CHEM_AUTOMORPHISMGROUPSEARCH_HPP
31 
32 #include <memory>
33 #include <functional>
34 
35 #include "CDPL/Chem/APIPrefix.hpp"
40 
41 
42 namespace CDPL
43 {
44 
45  namespace Chem
46  {
47 
52  {
53  public:
57  static constexpr unsigned int DEF_ATOM_PROPERTY_FLAGS =
62 
66  static constexpr unsigned int DEF_BOND_PROPERTY_FLAGS =
69 
70  typedef std::shared_ptr<AutomorphismGroupSearch> SharedPointer;
71 
76 
81 
82  typedef std::function<bool(const MolecularGraph&, const AtomBondMapping&)> MappingCallbackFunction;
83 
87  AutomorphismGroupSearch(unsigned int atom_flags = DEF_ATOM_PROPERTY_FLAGS,
88  unsigned int bond_flags = DEF_BOND_PROPERTY_FLAGS);
89 
90  void setAtomPropertyFlags(unsigned int flags);
91 
92  unsigned int getAtomPropertyFlags() const;
93 
94  void setBondPropertyFlags(unsigned int flags);
95 
96  unsigned int getBondPropertyFlags() const;
97 
98  void includeIdentityMapping(bool include);
99 
101 
114  bool findMappings(const MolecularGraph& molgraph);
115 
116  void stopSearch();
117 
122  std::size_t getNumMappings() const;
123 
130  AtomBondMapping& getMapping(std::size_t idx);
131 
138  const AtomBondMapping& getMapping(std::size_t idx) const;
139 
145 
151 
157 
163 
169 
175 
181 
187 
198  void setMaxNumMappings(std::size_t max_num_mappings);
199 
205  std::size_t getMaxNumMappings() const;
206 
208 
210 
211  private:
213 
215 
217  getAtomMatchExpression(const Atom& atom) const;
218 
220  getBondMatchExpression(const Bond& bond) const;
221 
223  getMolGraphMatchExpression(const MolecularGraph& molgraph) const;
224 
225  class AtomMatchExpression : public MatchExpression<Atom, MolecularGraph>
226  {
227 
228  public:
229  AtomMatchExpression(AutomorphismGroupSearch* parent):
230  parent(parent) {}
231 
232  bool requiresAtomBondMapping() const;
233 
234  bool operator()(const Atom& query_atom, const MolecularGraph& query_molgraph,
235  const Atom& target_atom, const MolecularGraph& target_molgraph,
236  const Base::Any& aux_data) const;
237 
238  bool operator()(const Atom& query_atom, const MolecularGraph& query_molgraph,
239  const Atom& target_atom, const MolecularGraph& target_molgraph,
240  const AtomBondMapping& mapping, const Base::Any& aux_data) const;
241 
242  private:
243  AutomorphismGroupSearch* parent;
244  mutable unsigned int type;
245  mutable unsigned int hybState;
246  mutable std::size_t isotope;
247  mutable std::size_t hCount;
248  mutable long charge;
249  mutable bool aromatic;
250  mutable std::size_t expBondCount;
251  };
252 
253  class BondMatchExpression : public MatchExpression<Bond, MolecularGraph>
254  {
255 
256  public:
257  BondMatchExpression(AutomorphismGroupSearch* parent):
258  parent(parent) {}
259 
260  bool requiresAtomBondMapping() const;
261 
262  bool operator()(const Bond& query_bond, const MolecularGraph& query_molgraph,
263  const Bond& target_bond, const MolecularGraph& target_molgraph,
264  const Base::Any& aux_data) const;
265 
266  bool operator()(const Bond& query_bond, const MolecularGraph& query_molgraph,
267  const Bond& target_bond, const MolecularGraph& target_molgraph,
268  const AtomBondMapping& mapping, const Base::Any& aux_data) const;
269 
270  private:
271  AutomorphismGroupSearch* parent;
272  mutable std::size_t order;
273  mutable bool inRing;
274  mutable bool aromatic;
275  };
276 
277  class MolGraphMatchExpression : public MatchExpression<MolecularGraph>
278  {
279 
280  public:
281  MolGraphMatchExpression(const AutomorphismGroupSearch* parent):
282  parent(parent) {}
283 
284  bool requiresAtomBondMapping() const;
285 
286  bool operator()(const MolecularGraph& query_molgraph,
287  const MolecularGraph& target_molgraph,
288  const Base::Any& aux_data) const;
289 
290  bool operator()(const MolecularGraph& query_molgraph,
291  const MolecularGraph& target_molgraph,
292  const AtomBondMapping& mapping, const Base::Any& aux_data) const;
293 
294  private:
295  const AutomorphismGroupSearch* parent;
296  };
297 
300  typedef MatchExpression<MolecularGraph>::SharedPointer MolGraphMatchExprPtr;
301 
302  SubstructureSearch substructSearch;
303  bool incIdentityMapping;
304  unsigned int atomPropFlags;
305  unsigned int bondPropFlags;
306  AtomMatchExprPtr atomMatchExpr;
307  BondMatchExprPtr bondMatchExpr;
308  MolGraphMatchExprPtr molGraphMatchExpr;
309  MappingCallbackFunction mappingCallbackFunc;
310  const Atom* lastQueryAtom;
311  const Bond* lastQueryBond;
312  };
313  } // namespace Chem
314 } // namespace CDPL
315 
316 #endif // CDPL_CHEM_AUTOMORPHISMGROUPSEARCH_HPP
CDPL::Chem::AutomorphismGroupSearch::begin
ConstMappingIterator begin() const
Returns a constant iterator pointing to the beginning of the stored atom/bond mapping objects.
CDPL::Chem::AtomPropertyFlag::FORMAL_CHARGE
const unsigned int FORMAL_CHARGE
Specifies the formal charge of an atom.
Definition: Chem/AtomPropertyFlag.hpp:73
CDPL::Chem::AutomorphismGroupSearch::includeIdentityMapping
void includeIdentityMapping(bool include)
CDPL::Chem::AutomorphismGroupSearch::getMaxNumMappings
std::size_t getMaxNumMappings() const
Returns the specified limit on the number of stored atom/bond mappings.
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::SybylAtomType::Any
const unsigned int Any
Specifies any atom.
Definition: SybylAtomType.hpp:198
CDPL::Chem::AutomorphismGroupSearch::getFoundMappingCallback
const MappingCallbackFunction & getFoundMappingCallback() const
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::AutomorphismGroupSearch::end
ConstMappingIterator end() const
Returns a constant iterator pointing to the end of the stored atom/bond mapping objects.
CDPL::Chem::Bond
Bond.
Definition: Bond.hpp:50
CDPL::Chem::BondPropertyFlag::CONFIGURATION
const unsigned int CONFIGURATION
Specifies the steric configuration of a double bond.
Definition: BondPropertyFlag.hpp:78
CDPL::Chem::AutomorphismGroupSearch::setMaxNumMappings
void setMaxNumMappings(std::size_t max_num_mappings)
Allows to specify a limit on the number of stored atom/bond mappings.
CDPL::Chem::AutomorphismGroupSearch::end
MappingIterator end()
Returns a mutable iterator pointing to the end of the stored atom/bond mapping objects.
CDPL::Chem::AutomorphismGroupSearch::AutomorphismGroupSearch
AutomorphismGroupSearch(unsigned int atom_flags=DEF_ATOM_PROPERTY_FLAGS, unsigned int bond_flags=DEF_BOND_PROPERTY_FLAGS)
Constructs and initializes a AutomorphismGroupSearch instance.
CDPL::Chem::AutomorphismGroupSearch::getNumMappings
std::size_t getNumMappings() const
Returns the number of atom/bond mappings that were recorded in the last call to findMappings().
CDPL::Chem::AutomorphismGroupSearch::getMappingsBegin
ConstMappingIterator getMappingsBegin() const
Returns a constant iterator pointing to the beginning of the stored atom/bond mapping objects.
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Chem::AutomorphismGroupSearch::MappingCallbackFunction
std::function< bool(const MolecularGraph &, const AtomBondMapping &)> MappingCallbackFunction
Definition: AutomorphismGroupSearch.hpp:82
CDPL::Chem::AtomPropertyFlag::EXPLICIT_BOND_COUNT
const unsigned int EXPLICIT_BOND_COUNT
Specifies the explicit bond count of an atom.
Definition: Chem/AtomPropertyFlag.hpp:118
bool
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
CDPL::Chem::AutomorphismGroupSearch::getMapping
const AtomBondMapping & getMapping(std::size_t idx) const
Returns a const reference to the stored atom/bond mapping object at index idx.
AtomPropertyFlag.hpp
Definition of constants in namespace CDPL::Chem::AtomPropertyFlag.
CDPL::Chem::AtomPropertyFlag::CONFIGURATION
const unsigned int CONFIGURATION
Specifies the configuration of a stereogenic atom.
Definition: Chem/AtomPropertyFlag.hpp:98
CDPL::Base::Any
A safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:59
CDPL::Chem::AutomorphismGroupSearch::begin
MappingIterator begin()
Returns a mutable iterator pointing to the beginning of the stored atom/bond mapping objects.
CDPL::Chem::AutomorphismGroupSearch::setAtomPropertyFlags
void setAtomPropertyFlags(unsigned int flags)
CDPL::Chem::MatchExpression< Atom, MolecularGraph >::SharedPointer
std::shared_ptr< MatchExpression > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MatchExpression instances.
Definition: MatchExpression.hpp:81
CDPL::Chem::BondPropertyFlag::ORDER
const unsigned int ORDER
Specifies the order of a bond.
Definition: BondPropertyFlag.hpp:63
CDPL::Chem::AutomorphismGroupSearch::findMappings
bool findMappings(const MolecularGraph &molgraph)
Searches for the possible atom/bond mappings in the automorphism group of the given molecular graph.
CDPL::Chem::AutomorphismGroupSearch::getMappingsEnd
ConstMappingIterator getMappingsEnd() const
Returns a constant iterator pointing to the end of the stored atom/bond mapping objects.
CDPL::Chem::SubstructureSearch::ConstMappingIterator
boost::indirect_iterator< ABMappingList::const_iterator, const AtomBondMapping > ConstMappingIterator
A constant random access iterator used to iterate over the stored atom/bond mapping objects.
Definition: SubstructureSearch.hpp:83
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::MatchExpression
A generic boolean expression interface for the implementation of query/target object equivalence test...
Definition: MatchExpression.hpp:75
CDPL::Chem::AutomorphismGroupSearch::getBondPropertyFlags
unsigned int getBondPropertyFlags() const
MatchExpression.hpp
Definition of the class CDPL::Chem::MatchExpression.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::AutomorphismGroupSearch::getAtomPropertyFlags
unsigned int getAtomPropertyFlags() const
CDPL::Chem::AutomorphismGroupSearch::setFoundMappingCallback
void setFoundMappingCallback(const MappingCallbackFunction &func)
CDPL::Chem::AutomorphismGroupSearch::MappingIterator
SubstructureSearch::MappingIterator MappingIterator
A mutable random access iterator used to iterate over the stored atom/bond mapping objects.
Definition: AutomorphismGroupSearch.hpp:75
CDPL::Chem::AutomorphismGroupSearch::getMappingsBegin
MappingIterator getMappingsBegin()
Returns a mutable iterator pointing to the beginning of the stored atom/bond mapping objects.
CDPL::Chem::AtomPropertyFlag::AROMATICITY
const unsigned int AROMATICITY
Specifies the membership of an atom in aromatic rings.
Definition: Chem/AtomPropertyFlag.hpp:93
CDPL::Chem::AtomBondMapping
A data structure for the common storage of related atom to atom and bond to bond mappings.
Definition: AtomBondMapping.hpp:55
SubstructureSearch.hpp
Definition of the class CDPL::Chem::SubstructureSearch.
CDPL::Chem::AutomorphismGroupSearch::SharedPointer
std::shared_ptr< AutomorphismGroupSearch > SharedPointer
Definition: AutomorphismGroupSearch.hpp:70
CDPL::Chem::AtomPropertyFlag::H_COUNT
const unsigned int H_COUNT
Specifies the hydrogen count of an atom.
Definition: Chem/AtomPropertyFlag.hpp:78
CDPL::Chem::SubstructureSearch::MappingIterator
boost::indirect_iterator< ABMappingList::iterator, AtomBondMapping > MappingIterator
A mutable random access iterator used to iterate over the stored atom/bond mapping objects.
Definition: SubstructureSearch.hpp:78
CDPL::Chem::AutomorphismGroupSearch::ConstMappingIterator
SubstructureSearch::ConstMappingIterator ConstMappingIterator
A constant random access iterator used to iterate over the stored atom/bond mapping objects.
Definition: AutomorphismGroupSearch.hpp:80
BondPropertyFlag.hpp
Definition of constants in namespace CDPL::Chem::BondPropertyFlag.
CDPL::Chem::AutomorphismGroupSearch::identityMappingIncluded
bool identityMappingIncluded() const
CDPL::Chem::AutomorphismGroupSearch
AutomorphismGroupSearch.
Definition: AutomorphismGroupSearch.hpp:52
CDPL::Chem::AtomPropertyFlag::HYBRIDIZATION_STATE
const unsigned int HYBRIDIZATION_STATE
Specifies the hybridization state an atom.
Definition: Chem/AtomPropertyFlag.hpp:123
CDPL::Chem::AutomorphismGroupSearch::stopSearch
void stopSearch()
CDPL::Chem::AutomorphismGroupSearch::getMapping
AtomBondMapping & getMapping(std::size_t idx)
Returns a non-const reference to the stored atom/bond mapping object at index idx.
CDPL::Chem::AutomorphismGroupSearch::getMappingsEnd
MappingIterator getMappingsEnd()
Returns a mutable iterator pointing to the end of the stored atom/bond mapping objects.
CDPL::Chem::AutomorphismGroupSearch::setBondPropertyFlags
void setBondPropertyFlags(unsigned int flags)