Chemical Data Processing Library C++ API - Version 1.2.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 
91 
93 
94  void setAtomPropertyFlags(unsigned int flags);
95 
96  unsigned int getAtomPropertyFlags() const;
97 
98  void setBondPropertyFlags(unsigned int flags);
99 
100  unsigned int getBondPropertyFlags() const;
101 
102  void includeIdentityMapping(bool include);
103 
105 
118  bool findMappings(const MolecularGraph& molgraph);
119 
120  void stopSearch();
121 
126  std::size_t getNumMappings() const;
127 
134  AtomBondMapping& getMapping(std::size_t idx);
135 
142  const AtomBondMapping& getMapping(std::size_t idx) const;
143 
149 
155 
161 
167 
173 
179 
185 
191 
202  void setMaxNumMappings(std::size_t max_num_mappings);
203 
209  std::size_t getMaxNumMappings() const;
210 
223  void addAtomMappingConstraint(std::size_t atom1_idx, std::size_t atom2_idx);
224 
230 
243  void addBondMappingConstraint(std::size_t bond1_idx, std::size_t bond2_idx);
244 
250 
252 
254 
255  private:
257  getAtomMatchExpression(const Atom& atom) const;
258 
260  getBondMatchExpression(const Bond& bond) const;
261 
263  getMolGraphMatchExpression(const MolecularGraph& molgraph) const;
264 
265  class AtomMatchExpression : public MatchExpression<Atom, MolecularGraph>
266  {
267 
268  public:
269  AtomMatchExpression(AutomorphismGroupSearch* parent):
270  parent(parent) {}
271 
272  bool requiresAtomBondMapping() const;
273 
274  bool operator()(const Atom& query_atom, const MolecularGraph& query_molgraph,
275  const Atom& target_atom, const MolecularGraph& target_molgraph,
276  const Base::Any& aux_data) const;
277 
278  bool operator()(const Atom& query_atom, const MolecularGraph& query_molgraph,
279  const Atom& target_atom, const MolecularGraph& target_molgraph,
280  const AtomBondMapping& mapping, const Base::Any& aux_data) const;
281 
282  private:
283  AutomorphismGroupSearch* parent;
284  mutable unsigned int type;
285  mutable unsigned int hybState;
286  mutable std::size_t isotope;
287  mutable std::size_t hCount;
288  mutable long charge;
289  mutable bool aromatic;
290  mutable std::size_t expBondCount;
291  };
292 
293  class BondMatchExpression : public MatchExpression<Bond, MolecularGraph>
294  {
295 
296  public:
297  BondMatchExpression(AutomorphismGroupSearch* parent):
298  parent(parent) {}
299 
300  bool requiresAtomBondMapping() const;
301 
302  bool operator()(const Bond& query_bond, const MolecularGraph& query_molgraph,
303  const Bond& target_bond, const MolecularGraph& target_molgraph,
304  const Base::Any& aux_data) const;
305 
306  bool operator()(const Bond& query_bond, const MolecularGraph& query_molgraph,
307  const Bond& target_bond, const MolecularGraph& target_molgraph,
308  const AtomBondMapping& mapping, const Base::Any& aux_data) const;
309 
310  private:
311  AutomorphismGroupSearch* parent;
312  mutable std::size_t order;
313  mutable bool inRing;
314  mutable bool aromatic;
315  };
316 
317  class MolGraphMatchExpression : public MatchExpression<MolecularGraph>
318  {
319 
320  public:
321  MolGraphMatchExpression(const AutomorphismGroupSearch* parent):
322  parent(parent) {}
323 
324  bool requiresAtomBondMapping() const;
325 
326  bool operator()(const MolecularGraph& query_molgraph,
327  const MolecularGraph& target_molgraph,
328  const Base::Any& aux_data) const;
329 
330  bool operator()(const MolecularGraph& query_molgraph,
331  const MolecularGraph& target_molgraph,
332  const AtomBondMapping& mapping, const Base::Any& aux_data) const;
333 
334  private:
335  const AutomorphismGroupSearch* parent;
336  };
337 
340  typedef MatchExpression<MolecularGraph>::SharedPointer MolGraphMatchExprPtr;
341 
342  SubstructureSearch substructSearch;
343  bool incIdentityMapping;
344  unsigned int atomPropFlags;
345  unsigned int bondPropFlags;
346  AtomMatchExprPtr atomMatchExpr;
347  BondMatchExprPtr bondMatchExpr;
348  MolGraphMatchExprPtr molGraphMatchExpr;
349  MappingCallbackFunction mappingCallbackFunc;
350  const Atom* lastQueryAtom;
351  const Bond* lastQueryBond;
352  };
353  } // namespace Chem
354 } // namespace CDPL
355 
356 #endif // CDPL_CHEM_AUTOMORPHISMGROUPSEARCH_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.
Definition of the class CDPL::Chem::MatchExpression.
Definition of the class CDPL::Chem::SubstructureSearch.
A safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:59
A data structure for the common storage of related atom to atom and bond to bond mappings.
Definition: AtomBondMapping.hpp:55
Atom.
Definition: Atom.hpp:52
AutomorphismGroupSearch.
Definition: AutomorphismGroupSearch.hpp:52
AutomorphismGroupSearch(const AutomorphismGroupSearch &)=delete
AutomorphismGroupSearch(unsigned int atom_flags=DEF_ATOM_PROPERTY_FLAGS, unsigned int bond_flags=DEF_BOND_PROPERTY_FLAGS)
Constructs and initializes a AutomorphismGroupSearch instance.
MappingIterator getMappingsEnd()
Returns a mutable iterator pointing to the end of the stored atom/bond mapping objects.
AutomorphismGroupSearch & operator=(const AutomorphismGroupSearch &)=delete
SubstructureSearch::ConstMappingIterator ConstMappingIterator
A constant random access iterator used to iterate over the stored atom/bond mapping objects.
Definition: AutomorphismGroupSearch.hpp:80
void clearAtomMappingConstraints()
Clears all previously defined atom mapping constraints.
bool findMappings(const MolecularGraph &molgraph)
Searches for the possible atom/bond mappings in the automorphism group of the given molecular graph.
MappingIterator end()
Returns a mutable iterator pointing to the end of the stored atom/bond mapping objects.
void addAtomMappingConstraint(std::size_t atom1_idx, std::size_t atom2_idx)
Adds a constraint on the allowed atom mappings.
void includeIdentityMapping(bool include)
void setMaxNumMappings(std::size_t max_num_mappings)
Allows to specify a limit on the number of stored atom/bond mappings.
ConstMappingIterator getMappingsBegin() const
Returns a constant iterator pointing to the beginning of the stored atom/bond mapping objects.
const AtomBondMapping & getMapping(std::size_t idx) const
Returns a const reference to the stored atom/bond mapping object at index idx.
ConstMappingIterator getMappingsEnd() const
Returns a constant iterator pointing to the end of the stored atom/bond mapping objects.
std::shared_ptr< AutomorphismGroupSearch > SharedPointer
Definition: AutomorphismGroupSearch.hpp:70
void setBondPropertyFlags(unsigned int flags)
unsigned int getAtomPropertyFlags() const
const MappingCallbackFunction & getFoundMappingCallback() const
ConstMappingIterator end() const
Returns a constant iterator pointing to the end of the stored atom/bond mapping objects.
void addBondMappingConstraint(std::size_t bond1_idx, std::size_t bond2_idx)
Adds a constraint on the allowed bond mappings.
std::size_t getMaxNumMappings() const
Returns the specified limit on the number of stored atom/bond mappings.
ConstMappingIterator begin() const
Returns a constant iterator pointing to the beginning of the stored atom/bond mapping objects.
void setFoundMappingCallback(const MappingCallbackFunction &func)
std::function< bool(const MolecularGraph &, const AtomBondMapping &)> MappingCallbackFunction
Definition: AutomorphismGroupSearch.hpp:82
std::size_t getNumMappings() const
Returns the number of atom/bond mappings that were recorded in the last call to findMappings().
MappingIterator begin()
Returns a mutable iterator pointing to the beginning of the stored atom/bond mapping objects.
unsigned int getBondPropertyFlags() const
SubstructureSearch::MappingIterator MappingIterator
A mutable random access iterator used to iterate over the stored atom/bond mapping objects.
Definition: AutomorphismGroupSearch.hpp:75
void setAtomPropertyFlags(unsigned int flags)
AtomBondMapping & getMapping(std::size_t idx)
Returns a non-const reference to the stored atom/bond mapping object at index idx.
void clearBondMappingConstraints()
Clears all previously defined bond mapping constraints.
MappingIterator getMappingsBegin()
Returns a mutable iterator pointing to the beginning of the stored atom/bond mapping objects.
Bond.
Definition: Bond.hpp:50
A generic boolean expression interface for the implementation of query/target object equivalence test...
Definition: MatchExpression.hpp:75
std::shared_ptr< MatchExpression > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MatchExpression instances.
Definition: MatchExpression.hpp:81
MolecularGraph.
Definition: MolecularGraph.hpp:52
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
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
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 CONFIGURATION
Specifies the configuration of a stereogenic atom.
Definition: Chem/AtomPropertyFlag.hpp:98
constexpr unsigned int HYBRIDIZATION_STATE
Specifies the hybridization state an atom.
Definition: Chem/AtomPropertyFlag.hpp:123
constexpr unsigned int TYPE
Specifies the generic type or element of an atom.
Definition: Chem/AtomPropertyFlag.hpp:63
constexpr unsigned int EXPLICIT_BOND_COUNT
Specifies the explicit bond count of an atom.
Definition: Chem/AtomPropertyFlag.hpp:118
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 CONFIGURATION
Specifies the steric configuration of a double bond.
Definition: BondPropertyFlag.hpp:78
constexpr unsigned int TOPOLOGY
Specifies the ring/chain topology of a bond.
Definition: BondPropertyFlag.hpp:68
constexpr unsigned int Any
Specifies any atom.
Definition: SybylAtomType.hpp:198
The namespace of the Chemical Data Processing Library.