29 #ifndef CDPL_CHEM_SUBSTRUCTURESEARCH_HPP
30 #define CDPL_CHEM_SUBSTRUCTURESEARCH_HPP
36 #include <unordered_map>
40 #include <boost/iterator/indirect_iterator.hpp>
76 typedef std::vector<AtomBondMapping*> ABMappingList;
91 typedef boost::indirect_iterator<ABMappingList::iterator, AtomBondMapping>
MappingIterator;
96 typedef boost::indirect_iterator<ABMappingList::const_iterator, const AtomBondMapping>
ConstMappingIterator;
351 void initMatchExpressions();
353 bool findEquivAtoms();
354 bool findEquivBonds();
358 std::size_t nextQueryAtom()
const;
359 bool nextTargetAtom(std::size_t, std::size_t&, std::size_t&)
const;
361 bool atomMappingAllowed(std::size_t, std::size_t)
const;
362 bool checkAtomMappingConstraints(std::size_t, std::size_t)
const;
363 bool checkBondMappingConstraints(std::size_t, std::size_t)
const;
365 bool mapBonds(std::size_t, std::size_t);
366 bool mapAtoms(std::size_t);
367 bool mapAtoms(std::size_t, std::size_t);
371 bool hasPostMappingMatchExprs()
const;
374 bool foundMappingUnique();
376 void freeAtomBondMappings();
377 void freeAtomBondMapping();
385 void initAtomMask(std::size_t);
386 void initBondMask(std::size_t);
388 void setAtomBit(std::size_t);
389 void resetAtomBit(std::size_t);
391 bool testAtomBit(std::size_t)
const;
393 void setBondBit(std::size_t);
394 void resetBondMask();
396 bool operator<(
const ABMappingMask&)
const;
397 bool operator>(
const ABMappingMask&)
const;
404 typedef std::vector<Util::BitSet> BitMatrix;
405 typedef std::vector<const Atom*> AtomMappingTable;
406 typedef std::vector<const Bond*> BondMappingTable;
407 typedef std::deque<std::size_t> AtomQueue;
408 typedef std::set<ABMappingMask> UniqueMappingList;
409 typedef std::vector<const Atom*> AtomList;
410 typedef std::vector<const Bond*> BondList;
411 typedef std::vector<AtomMatchExprPtr> AtomMatchExprTable;
412 typedef std::vector<BondMatchExprPtr> BondMatchExprTable;
413 typedef std::unordered_multimap<std::size_t, std::size_t> MappingConstraintMap;
418 AtomMatchExpressionFunction atomMatchExprFunc;
419 BondMatchExpressionFunction bondMatchExprFunc;
420 MolecularGraphMatchExpressionFunction molGraphMatchExprFunc;
421 BitMatrix atomEquivMatrix;
422 BitMatrix bondEquivMatrix;
423 MappingConstraintMap atomMappingConstrs;
424 MappingConstraintMap bondMappingConstrs;
425 AtomQueue termQueryAtoms;
426 AtomMappingTable queryAtomMapping;
427 BondMappingTable queryBondMapping;
429 ABMappingMask targetMappingMask;
430 ABMappingList foundMappings;
431 UniqueMappingList uniqueMappings;
432 AtomMatchExprTable atomMatchExprTable;
433 BondMatchExprTable bondMatchExprTable;
434 MolGraphMatchExprPtr molGraphMatchExpr;
435 AtomList postMappingMatchAtoms;
436 BondList postMappingMatchBonds;
437 MappingCache mappingCache;
443 std::size_t numQueryAtoms;
444 std::size_t numQueryBonds;
445 std::size_t numTargetAtoms;
446 std::size_t numTargetBonds;
447 std::size_t numMappedAtoms;
448 std::size_t maxNumMappings;
Definition of class CDPL::Chem::AtomBondMapping.
Declaration of type CDPL::Util::BitSet.
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 class CDPL::Chem::MatchExpression.
Definition of class CDPL::Util::ObjectStack.
Data structure for the common storage of related atom to atom and bond to bond mappings.
Definition: AtomBondMapping.hpp:55
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:57
Abstract base class representing a chemical bond between two Chem::Atom instances.
Definition: Bond.hpp:54
Generic boolean expression interface for the implementation of query/target object equivalence tests ...
Definition: MatchExpression.hpp:75
Abstract base class for representations of a chemical structure as a graph of bonded atoms.
Definition: MolecularGraph.hpp:57
Subgraph-isomorphism search of a query molecular graph against a target molecular graph,...
Definition: SubstructureSearch.hpp:74
MappingIterator getMappingsBegin()
Returns a mutable iterator pointing to the beginning of the stored atom/bond mapping objects.
void clearAtomMappingConstraints()
Clears all previously defined query to target atom mapping constraints.
void clearBondMappingConstraints()
Clears all previously defined query to target bond mapping constraints.
void addBondMappingConstraint(std::size_t query_bond_idx, std::size_t target_bond_idx)
Adds a constraint on the allowed mappings between query and target structure bonds.
~SubstructureSearch()
Destructor.
void stopSearch()
Aborts the currently running subgraph mapping search.
void setMolecularGraphMatchExpressionFunction(const MolecularGraphMatchExpressionFunction &func)
Installs a function that resolves the graph-level Chem::MatchExpression for the query molecular graph...
std::function< const BondMatchExprPtr &(const Bond &)> BondMatchExpressionFunction
Type of the functor used to retrieve the bond-level Chem::MatchExpression for a query bond.
Definition: SubstructureSearch.hpp:106
bool uniqueMappingsOnly() const
Tells whether duplicate atom/bond mappings are discarded.
MappingIterator begin()
Returns a mutable iterator pointing to the beginning of the stored atom/bond mapping objects.
void uniqueMappingsOnly(bool unique)
Allows to specify whether or not to store only unique atom/bond mappings.
ConstMappingIterator getMappingsBegin() const
Returns a constant iterator pointing to the beginning of the stored atom/bond mapping objects.
AtomBondMapping & getMapping(std::size_t idx)
Returns a non-const reference to the stored atom/bond mapping object at index idx.
MappingIterator end()
Returns a mutable iterator pointing to the end of the stored atom/bond mapping objects.
void addAtomMappingConstraint(std::size_t query_atom_idx, std::size_t target_atom_idx)
Adds a constraint on the allowed mappings between query and target structure atoms.
std::size_t getNumMappings() const
Returns the number of atom/bond mappings that were recorded in the last call to findMappings().
void setQuery(const MolecularGraph &query)
Allows to specify a new query structure.
void setMaxNumMappings(std::size_t max_num_mappings)
Allows to specify a limit on the number of stored atom/bond mappings.
bool mappingExists(const MolecularGraph &target)
Tells whether the query structure matches a substructure of the specified target molecular graph.
void setBondMatchExpressionFunction(const BondMatchExpressionFunction &func)
Installs a function that resolves the bond-level Chem::MatchExpression for a query bond.
std::shared_ptr< SubstructureSearch > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated SubstructureSearch instances.
Definition: SubstructureSearch.hpp:86
SubstructureSearch()
Constructs and initializes a SubstructureSearch instance.
bool findMappings(const MolecularGraph &target)
Searches for all possible atom/bond mappings of the query structure to substructures of the specified...
SubstructureSearch(const MolecularGraph &query)
Constructs and initializes a SubstructureSearch instance for the specified query structure.
ConstMappingIterator begin() const
Returns a constant iterator pointing to the beginning of the stored atom/bond mapping objects.
std::function< const MolGraphMatchExprPtr &(const MolecularGraph &)> MolecularGraphMatchExpressionFunction
Type of the functor used to retrieve the graph-level Chem::MatchExpression for the query molecular gr...
Definition: SubstructureSearch.hpp:111
void setAtomMatchExpressionFunction(const AtomMatchExpressionFunction &func)
Installs a function that resolves the atom-level Chem::MatchExpression for a query atom.
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:96
std::function< const AtomMatchExprPtr &(const Atom &)> AtomMatchExpressionFunction
Type of the functor used to retrieve the atom-level Chem::MatchExpression for a query atom.
Definition: SubstructureSearch.hpp:101
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:91
MappingIterator getMappingsEnd()
Returns a mutable iterator pointing to the end of the stored atom/bond mapping objects.
SubstructureSearch & operator=(const SubstructureSearch &)=delete
const AtomBondMapping & getMapping(std::size_t idx) const
Returns a const reference to the stored atom/bond mapping object at index idx.
std::size_t getMaxNumMappings() const
Returns the specified limit on the number of stored atom/bond mappings.
ConstMappingIterator end() const
Returns a constant iterator pointing to the end of the stored atom/bond mapping objects.
SubstructureSearch(const SubstructureSearch &)=delete
ConstMappingIterator getMappingsEnd() const
Returns a constant iterator pointing to the end of the stored atom/bond mapping objects.
bool operator<(const Array< ValueType > &array1, const Array< ValueType > &array2)
Less than comparison operator.
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
bool operator>(const Array< ValueType > &array1, const Array< ValueType > &array2)
Greater than comparison operator.
The namespace of the Chemical Data Processing Library.