![]() |
Chemical Data Processing Library C++ API - Version 1.4.0
|
Searches for substructures of a target molecular graph that match the topology of a given query molecular graph. More...
#include <SubstructureSearch.hpp>
Public Types | |
| typedef std::shared_ptr< SubstructureSearch > | SharedPointer |
A reference-counted smart pointer [SHPTR] for dynamically allocated SubstructureSearch instances. More... | |
| typedef boost::indirect_iterator< ABMappingList::iterator, AtomBondMapping > | MappingIterator |
| A mutable random access iterator used to iterate over the stored Chem::AtomBondMapping objects. More... | |
| typedef boost::indirect_iterator< ABMappingList::const_iterator, const AtomBondMapping > | ConstMappingIterator |
A constant random access iterator used to iterate over the stored const Chem::AtomBondMapping objects. More... | |
| typedef std::function< const AtomMatchExprPtr &(const Atom &)> | AtomMatchExpressionFunction |
| Type of the functor used to retrieve the Chem::MatchExpression implementation instance for a query atom. More... | |
| typedef std::function< const BondMatchExprPtr &(const Bond &)> | BondMatchExpressionFunction |
| Type of the functor used to retrieve the Chem::MatchExpression implementation instance for a query bond. More... | |
| typedef std::function< const MolGraphMatchExprPtr &(const MolecularGraph &)> | MolecularGraphMatchExpressionFunction |
| Type of the functor used to retrieve the Chem::MatchExpression implementation instance for the query molecular graph. More... | |
Public Member Functions | |
| SubstructureSearch () | |
Constructs and initializes the SubstructureSearch instance. More... | |
| SubstructureSearch (const MolecularGraph &query) | |
Constructs and initializes the SubstructureSearch instance for the query molecular graph query. More... | |
| SubstructureSearch (const SubstructureSearch &)=delete | |
| ~SubstructureSearch () | |
| Destructor. More... | |
| SubstructureSearch & | operator= (const SubstructureSearch &)=delete |
| void | setAtomMatchExpressionFunction (const AtomMatchExpressionFunction &func) |
| Installs a function that resolves the Chem::MatchExpression implementation instance for a query atom. More... | |
| void | setBondMatchExpressionFunction (const BondMatchExpressionFunction &func) |
| Installs a function that resolves the Chem::MatchExpression implementation instance for a query bond. More... | |
| void | setMolecularGraphMatchExpressionFunction (const MolecularGraphMatchExpressionFunction &func) |
| Installs a function that resolves the Chem::MatchExpression implementation instance for the query molecular graph. More... | |
| void | setQuery (const MolecularGraph &query) |
| Sets query as the new query molecular graph. More... | |
| bool | mappingExists (const MolecularGraph &target) |
| Tells whether the query molecular graph matches a substructure of the target molecular graph target. More... | |
| bool | findMappings (const MolecularGraph &target) |
| Searches for all possible atom/bond mappings of the query molecular graph to substructures of the target molecular graph target. More... | |
| void | stopSearch () |
| Aborts the currently running substructure search process. More... | |
| std::size_t | getNumMappings () const |
| Returns the number of atom/bond mappings that were recorded in the last call to findMappings(). More... | |
| AtomBondMapping & | getMapping (std::size_t idx) |
Returns a non-const reference to the stored atom/bond mapping object at index idx. More... | |
| const AtomBondMapping & | getMapping (std::size_t idx) const |
Returns a const reference to the stored atom/bond mapping object at index idx. More... | |
| MappingIterator | getMappingsBegin () |
| Returns a mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping objects. More... | |
| ConstMappingIterator | getMappingsBegin () const |
Returns a constant iterator pointing to the beginning of the stored const Chem::AtomBondMapping objects. More... | |
| MappingIterator | getMappingsEnd () |
| Returns a mutable iterator pointing to the end of the stored Chem::AtomBondMapping objects. More... | |
| ConstMappingIterator | getMappingsEnd () const |
Returns a constant iterator pointing to the end of the stored const Chem::AtomBondMapping objects. More... | |
| MappingIterator | begin () |
| Returns a mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping objects. More... | |
| ConstMappingIterator | begin () const |
Returns a constant iterator pointing to the beginning of the stored const Chem::AtomBondMapping objects. More... | |
| MappingIterator | end () |
| Returns a mutable iterator pointing to the end of the stored Chem::AtomBondMapping objects. More... | |
| ConstMappingIterator | end () const |
Returns a constant iterator pointing to the end of the stored const Chem::AtomBondMapping objects. More... | |
| void | uniqueMappingsOnly (bool unique) |
| Allows to specify whether or not to store only unique atom/bond mappings. More... | |
| bool | uniqueMappingsOnly () const |
| Tells whether duplicate atom/bond mappings are discarded. More... | |
| void | setMaxNumMappings (std::size_t max_num_mappings) |
| Allows to specify a limit on the number of stored atom/bond mappings. More... | |
| std::size_t | getMaxNumMappings () const |
| Returns the specified limit on the number of stored atom/bond mappings. More... | |
| 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. More... | |
| void | clearAtomMappingConstraints () |
| Clears all previously defined query to target molecular graph atom mapping constraints. More... | |
| 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. More... | |
| void | clearBondMappingConstraints () |
| Clears all previously defined query to target molecular graph bond mapping constraints. More... | |
Searches for substructures of a target molecular graph that match the topology of a given query molecular graph.
Successive calls to setQuery() and findMappings() produce all possible atom/bond mapping solutions. If just the information whether or not a mapping exists is of interest then the more efficient method mappingExists() can be used. Found mappings are recorded as Chem::AtomBondMapping objects that can be accessed via index through the method getMapping() or iteration using the iterator pair returned by the methods begin() and end(), respectively. User-defined per-atom, per-bond and per-molecular graph Chem::MatchExpression implementation instance accessor functions can be installed to extend equivalence tests beyond pure topology. The default functions retrieve the expressions saved as corresponding atom, bond and molecular graph property values (see Chem::AtomProperty::MATCH_EXPRESSION, Chem::BondProperty::MATCH_EXPRESSION and Chem::MolecularGraphProperty::MATCH_EXPRESSION). Result accumulation can be bounded by setMaxNumMappings() and uniqueMappingsOnly(). stopSearch() allows an immediate abort of the search process. Furthermore, query ↔ target atom and bond mappings can be restricted to user-defined subsets by the methods addAtomMappingConstraint() and addBondMappingConstraint(), respectively.
| typedef std::shared_ptr<SubstructureSearch> CDPL::Chem::SubstructureSearch::SharedPointer |
A reference-counted smart pointer [SHPTR] for dynamically allocated SubstructureSearch instances.
| typedef boost::indirect_iterator<ABMappingList::iterator, AtomBondMapping> CDPL::Chem::SubstructureSearch::MappingIterator |
A mutable random access iterator used to iterate over the stored Chem::AtomBondMapping objects.
| typedef boost::indirect_iterator<ABMappingList::const_iterator, const AtomBondMapping> CDPL::Chem::SubstructureSearch::ConstMappingIterator |
A constant random access iterator used to iterate over the stored const Chem::AtomBondMapping objects.
| typedef std::function<const AtomMatchExprPtr&(const Atom&)> CDPL::Chem::SubstructureSearch::AtomMatchExpressionFunction |
Type of the functor used to retrieve the Chem::MatchExpression implementation instance for a query atom.
| typedef std::function<const BondMatchExprPtr&(const Bond&)> CDPL::Chem::SubstructureSearch::BondMatchExpressionFunction |
Type of the functor used to retrieve the Chem::MatchExpression implementation instance for a query bond.
| typedef std::function<const MolGraphMatchExprPtr&(const MolecularGraph&)> CDPL::Chem::SubstructureSearch::MolecularGraphMatchExpressionFunction |
Type of the functor used to retrieve the Chem::MatchExpression implementation instance for the query molecular graph.
| CDPL::Chem::SubstructureSearch::SubstructureSearch | ( | ) |
Constructs and initializes the SubstructureSearch instance.
| CDPL::Chem::SubstructureSearch::SubstructureSearch | ( | const MolecularGraph & | query | ) |
Constructs and initializes the SubstructureSearch instance for the query molecular graph query.
| query | A molecular graph that represents the query structure. |
|
delete |
| CDPL::Chem::SubstructureSearch::~SubstructureSearch | ( | ) |
Destructor.
Destroys the SubstructureSearch instance and frees all allocated resources.
|
delete |
| void CDPL::Chem::SubstructureSearch::setAtomMatchExpressionFunction | ( | const AtomMatchExpressionFunction & | func | ) |
Installs a function that resolves the Chem::MatchExpression implementation instance for a query atom.
| func | The accessor function to use. |
| void CDPL::Chem::SubstructureSearch::setBondMatchExpressionFunction | ( | const BondMatchExpressionFunction & | func | ) |
Installs a function that resolves the Chem::MatchExpression implementation instance for a query bond.
| func | The accessor function to use. |
| void CDPL::Chem::SubstructureSearch::setMolecularGraphMatchExpressionFunction | ( | const MolecularGraphMatchExpressionFunction & | func | ) |
Installs a function that resolves the Chem::MatchExpression implementation instance for the query molecular graph.
| func | The accessor function to use. |
| void CDPL::Chem::SubstructureSearch::setQuery | ( | const MolecularGraph & | query | ) |
Sets query as the new query molecular graph.
| query | A molecular graph that represents the new query. |
| bool CDPL::Chem::SubstructureSearch::mappingExists | ( | const MolecularGraph & | target | ) |
Tells whether the query molecular graph matches a substructure of the target molecular graph target.
The method does not store any atom/bond mappings between the query and target molecular graph — it just tells if a complete mapping of the query is possible. If you need access to the atom/bond mappings, use findMappings() instead.
| target | The target molecular graph that has to be searched for a match of the query. |
true if the query matches a substructure of the target molecular graph, and false otherwise. | bool CDPL::Chem::SubstructureSearch::findMappings | ( | const MolecularGraph & | target | ) |
Searches for all possible atom/bond mappings of the query molecular graph to substructures of the target molecular graph target.
The method will store all found subgraph mapping solutions up to the maximum number of recorded mappings specified by setMaxNumMappings(). If only unique mappings have to be stored (see uniqueMappingsOnly(bool unique)), any duplicates of previously found mappings will be discarded.
| target | The target molecular graph that has to be searched for matches of the query. |
true if the query matches at least one substructure of the specified target molecular graph, and false otherwise. | void CDPL::Chem::SubstructureSearch::stopSearch | ( | ) |
Aborts the currently running substructure search process.
Intended to be invoked from a callback (typically a match expression evaluator) running on the same thread as findMappings(). Once flagged, findMappings() returns at the next loop boundary.
| std::size_t CDPL::Chem::SubstructureSearch::getNumMappings | ( | ) | const |
Returns the number of atom/bond mappings that were recorded in the last call to findMappings().
| AtomBondMapping& CDPL::Chem::SubstructureSearch::getMapping | ( | std::size_t | idx | ) |
Returns a non-const reference to the stored atom/bond mapping object at index idx.
| idx | The zero-based index of the atom/bond mapping object to return. |
const reference to the Chem::AtomBondMapping object at index idx. | Base::IndexError | if idx is not in the range [0, getNumMappings()). |
| const AtomBondMapping& CDPL::Chem::SubstructureSearch::getMapping | ( | std::size_t | idx | ) | const |
Returns a const reference to the stored atom/bond mapping object at index idx.
| idx | The zero-based index of the atom/bond mapping object to return. |
const reference to the Chem::AtomBondMapping object at index idx. | Base::IndexError | if idx is not in the range [0, getNumMappings()). |
| MappingIterator CDPL::Chem::SubstructureSearch::getMappingsBegin | ( | ) |
Returns a mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping objects.
| ConstMappingIterator CDPL::Chem::SubstructureSearch::getMappingsBegin | ( | ) | const |
Returns a constant iterator pointing to the beginning of the stored const Chem::AtomBondMapping objects.
const Chem::AtomBondMapping objects. | MappingIterator CDPL::Chem::SubstructureSearch::getMappingsEnd | ( | ) |
Returns a mutable iterator pointing to the end of the stored Chem::AtomBondMapping objects.
| ConstMappingIterator CDPL::Chem::SubstructureSearch::getMappingsEnd | ( | ) | const |
Returns a constant iterator pointing to the end of the stored const Chem::AtomBondMapping objects.
const Chem::AtomBondMapping objects. | MappingIterator CDPL::Chem::SubstructureSearch::begin | ( | ) |
Returns a mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping objects.
| ConstMappingIterator CDPL::Chem::SubstructureSearch::begin | ( | ) | const |
Returns a constant iterator pointing to the beginning of the stored const Chem::AtomBondMapping objects.
const Chem::AtomBondMapping objects. | MappingIterator CDPL::Chem::SubstructureSearch::end | ( | ) |
Returns a mutable iterator pointing to the end of the stored Chem::AtomBondMapping objects.
| ConstMappingIterator CDPL::Chem::SubstructureSearch::end | ( | ) | const |
Returns a constant iterator pointing to the end of the stored const Chem::AtomBondMapping objects.
const Chem::AtomBondMapping objects. | void CDPL::Chem::SubstructureSearch::uniqueMappingsOnly | ( | bool | unique | ) |
Allows to specify whether or not to store only unique atom/bond mappings.
A mapping of the query to a substructure of the target molecular graph is considered to be unique if it differs from all previously found mappings by at least one atom or bond. If the unique argument is true, and a newly discovered mapping covers the same atoms and bonds of the target (including all permutations) as a mapping that was found earlier in the search process, it is considered as a duplicate and will be discarded.
| unique | If true, only unique mappings will be stored, and all found mappings otherwise. |
| bool CDPL::Chem::SubstructureSearch::uniqueMappingsOnly | ( | ) | const |
Tells whether duplicate atom/bond mappings are discarded.
true if duplicate mappings are discarded, and false otherwise. | void CDPL::Chem::SubstructureSearch::setMaxNumMappings | ( | std::size_t | max_num_mappings | ) |
Allows to specify a limit on the number of stored atom/bond mappings.
In a call to findMappings() the substructure search will terminate as soon as the specified maximum number of stored atom/bond mappings has been reached. A previously set limit on the number of mappings can be disabled by providing zero for the value of max_num_mappings.
| max_num_mappings | The maximum number of atom/bond mappings to store. |
| std::size_t CDPL::Chem::SubstructureSearch::getMaxNumMappings | ( | ) | const |
Returns the specified limit on the number of stored atom/bond mappings.
| void CDPL::Chem::SubstructureSearch::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.
By default, an atom of the query molecular graph is free to match any suitable target atom. When this method gets called for a particular query/target atom pair (specified by query_atom_idx and target_atom_idx), future substructure searches will find only those subgraph mapping solutions (if any) where the given query atom maps to the specified target molecular graph atom. Multiple calls to addAtomMappingConstraint() for the same query atom have an additive effect and allow to restrict the valid query atom mappings not only to a single but also a larger set of target molecular graph atoms.
| query_atom_idx | The index of the query molecular graph atom. |
| target_atom_idx | The index of the target molecular graph atom that has to be matched by the query atom. |
| void CDPL::Chem::SubstructureSearch::clearAtomMappingConstraints | ( | ) |
Clears all previously defined query to target molecular graph atom mapping constraints.
| void CDPL::Chem::SubstructureSearch::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.
By default, a bond of the query molecular graph is free to match any suitable target bond. When this method gets called for a particular query/target bond pair (specified by query_bond_idx and target_bond_idx), future substructure searches will find only those subgraph mapping solutions (if any) where the given query bond maps to the specified target molecular graph bond. Multiple calls to addBondMappingConstraint() for the same query bond have an additive effect and allow to restrict the valid query bond mappings not only to a single but also a larger set of target molecular graph bonds.
| query_bond_idx | The index of the query molecular graph bond. |
| target_bond_idx | The index of the target molecular graph bond that has to be matched by the query bond. |
| void CDPL::Chem::SubstructureSearch::clearBondMappingConstraints | ( | ) |
Clears all previously defined query to target molecular graph bond mapping constraints.