29 #ifndef CDPL_CHEM_SUBSTRUCTURESEARCH_HPP
30 #define CDPL_CHEM_SUBSTRUCTURESEARCH_HPP
36 #include <unordered_map>
40 #include <boost/iterator/indirect_iterator.hpp>
80 typedef std::vector<AtomBondMapping*> ABMappingList;
95 typedef boost::indirect_iterator<ABMappingList::iterator, AtomBondMapping>
MappingIterator;
355 void initMatchExpressions();
357 bool findEquivAtoms();
358 bool findEquivBonds();
362 std::size_t nextQueryAtom()
const;
363 bool nextTargetAtom(std::size_t, std::size_t&, std::size_t&)
const;
365 bool atomMappingAllowed(std::size_t, std::size_t)
const;
366 bool checkAtomMappingConstraints(std::size_t, std::size_t)
const;
367 bool checkBondMappingConstraints(std::size_t, std::size_t)
const;
369 bool mapBonds(std::size_t, std::size_t);
370 bool mapAtoms(std::size_t);
371 bool mapAtoms(std::size_t, std::size_t);
375 bool hasPostMappingMatchExprs()
const;
378 bool foundMappingUnique();
380 void freeAtomBondMappings();
381 void freeAtomBondMapping();
389 void initAtomMask(std::size_t);
390 void initBondMask(std::size_t);
392 void setAtomBit(std::size_t);
393 void resetAtomBit(std::size_t);
395 bool testAtomBit(std::size_t)
const;
397 void setBondBit(std::size_t);
398 void resetBondMask();
400 bool operator<(
const ABMappingMask&)
const;
401 bool operator>(
const ABMappingMask&)
const;
408 typedef std::vector<Util::BitSet> BitMatrix;
409 typedef std::vector<const Atom*> AtomMappingTable;
410 typedef std::vector<const Bond*> BondMappingTable;
411 typedef std::deque<std::size_t> AtomQueue;
412 typedef std::set<ABMappingMask> UniqueMappingList;
413 typedef std::vector<const Atom*> AtomList;
414 typedef std::vector<const Bond*> BondList;
415 typedef std::vector<AtomMatchExprPtr> AtomMatchExprTable;
416 typedef std::vector<BondMatchExprPtr> BondMatchExprTable;
417 typedef std::unordered_multimap<std::size_t, std::size_t> MappingConstraintMap;
422 AtomMatchExpressionFunction atomMatchExprFunc;
423 BondMatchExpressionFunction bondMatchExprFunc;
424 MolecularGraphMatchExpressionFunction molGraphMatchExprFunc;
425 BitMatrix atomEquivMatrix;
426 BitMatrix bondEquivMatrix;
427 MappingConstraintMap atomMappingConstrs;
428 MappingConstraintMap bondMappingConstrs;
429 AtomQueue termQueryAtoms;
430 AtomMappingTable queryAtomMapping;
431 BondMappingTable queryBondMapping;
433 ABMappingMask targetMappingMask;
434 ABMappingList foundMappings;
435 UniqueMappingList uniqueMappings;
436 AtomMatchExprTable atomMatchExprTable;
437 BondMatchExprTable bondMatchExprTable;
438 MolGraphMatchExprPtr molGraphMatchExpr;
439 AtomList postMappingMatchAtoms;
440 BondList postMappingMatchBonds;
441 MappingCache mappingCache;
447 std::size_t numQueryAtoms;
448 std::size_t numQueryBonds;
449 std::size_t numTargetAtoms;
450 std::size_t numTargetBonds;
451 std::size_t numMappedAtoms;
452 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:58
Abstract base class representing a chemical bond between two atoms (represented by Chem::Atom instanc...
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 data structures that represent chemical structures as molecular graphs.
Definition: MolecularGraph.hpp:60
Searches for substructures of a target molecular graph that match the topology of a given query molec...
Definition: SubstructureSearch.hpp:78
MappingIterator getMappingsBegin()
Returns a mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping objects.
void clearAtomMappingConstraints()
Clears all previously defined query to target molecular graph atom mapping constraints.
void clearBondMappingConstraints()
Clears all previously defined query to target molecular graph 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 molecular graph bonds.
~SubstructureSearch()
Destructor.
void stopSearch()
Aborts the currently running substructure search process.
void setMolecularGraphMatchExpressionFunction(const MolecularGraphMatchExpressionFunction &func)
Installs a function that resolves the Chem::MatchExpression implementation instance for the query mol...
std::function< const BondMatchExprPtr &(const Bond &)> BondMatchExpressionFunction
Type of the functor used to retrieve the Chem::MatchExpression implementation instance for a query bo...
Definition: SubstructureSearch.hpp:110
bool uniqueMappingsOnly() const
Tells whether duplicate atom/bond mappings are discarded.
MappingIterator begin()
Returns a mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping 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 const Chem::AtomBondMapping objec...
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 Chem::AtomBondMapping 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 molecular graph 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)
Sets query as the new query molecular graph.
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 molecular graph matches a substructure of the target molecular graph target.
void setBondMatchExpressionFunction(const BondMatchExpressionFunction &func)
Installs a function that resolves the Chem::MatchExpression implementation instance for a query bond.
std::shared_ptr< SubstructureSearch > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated SubstructureSearch instances.
Definition: SubstructureSearch.hpp:90
SubstructureSearch()
Constructs and initializes the SubstructureSearch instance.
bool findMappings(const MolecularGraph &target)
Searches for all possible atom/bond mappings of the query molecular graph to substructures of the tar...
SubstructureSearch(const MolecularGraph &query)
Constructs and initializes the SubstructureSearch instance for the query molecular graph query.
ConstMappingIterator begin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::AtomBondMapping objec...
std::function< const MolGraphMatchExprPtr &(const MolecularGraph &)> MolecularGraphMatchExpressionFunction
Type of the functor used to retrieve the Chem::MatchExpression implementation instance for the query ...
Definition: SubstructureSearch.hpp:115
void setAtomMatchExpressionFunction(const AtomMatchExpressionFunction &func)
Installs a function that resolves the Chem::MatchExpression implementation instance for a query atom.
boost::indirect_iterator< ABMappingList::const_iterator, const AtomBondMapping > ConstMappingIterator
A constant random access iterator used to iterate over the stored const Chem::AtomBondMapping objects...
Definition: SubstructureSearch.hpp:100
std::function< const AtomMatchExprPtr &(const Atom &)> AtomMatchExpressionFunction
Type of the functor used to retrieve the Chem::MatchExpression implementation instance for a query at...
Definition: SubstructureSearch.hpp:105
boost::indirect_iterator< ABMappingList::iterator, AtomBondMapping > MappingIterator
A mutable random access iterator used to iterate over the stored Chem::AtomBondMapping objects.
Definition: SubstructureSearch.hpp:95
MappingIterator getMappingsEnd()
Returns a mutable iterator pointing to the end of the stored Chem::AtomBondMapping 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 const Chem::AtomBondMapping objects.
SubstructureSearch(const SubstructureSearch &)=delete
ConstMappingIterator getMappingsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::AtomBondMapping 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.