Chemical Data Processing Library C++ API - Version 1.4.0
Classes | Public Types | Public Member Functions | List of all members
CDPL::Chem::CommonConnectedSubstructureSearch Class Reference

Enumerates all maximal common connected substructures shared between a query and a target molecular graph. More...

#include <CommonConnectedSubstructureSearch.hpp>

Public Types

typedef std::shared_ptr< CommonConnectedSubstructureSearchSharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated CommonConnectedSubstructureSearch instances. More...
 
typedef boost::indirect_iterator< ABMappingList::iterator, AtomBondMappingMappingIterator
 A mutable random access iterator used to iterate over the stored Chem::AtomBondMapping objects. More...
 
typedef boost::indirect_iterator< ABMappingList::const_iterator, const AtomBondMappingConstMappingIterator
 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

 CommonConnectedSubstructureSearch ()
 Constructs and initializes the CommonConnectedSubstructureSearch instance. More...
 
 CommonConnectedSubstructureSearch (const MolecularGraph &query)
 Constructs and initializes the CommonConnectedSubstructureSearch instance for the query molecular graph query. More...
 
 CommonConnectedSubstructureSearch (const CommonConnectedSubstructureSearch &)=delete
 
 ~CommonConnectedSubstructureSearch ()
 Destructor. More...
 
CommonConnectedSubstructureSearchoperator= (const CommonConnectedSubstructureSearch &)=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)
 Searches for a common connected substructure between the query and the target molecular graph target. More...
 
bool findAllMappings (const MolecularGraph &target)
 Searches for all possible atom/bond mappings of connected query subgraphs to substructures of the target molecular graph target. More...
 
bool findMaxMappings (const MolecularGraph &target)
 Searches for all maximum-sized atom/bond mappings of connected query subgraphs to substructures of the target molecular graph target. More...
 
std::size_t getNumMappings () const
 Returns the number of atom/bond mappings that were recorded in the last search for common substructures. More...
 
AtomBondMappinggetMapping (std::size_t idx)
 Returns a non-const reference to the stored atom/bond mapping object at index idx. More...
 
const AtomBondMappinggetMapping (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 setMinSubstructureSize (std::size_t min_size)
 Allows to specify the minimum accepted common substructure size. More...
 
std::size_t getMinSubstructureSize () const
 Returns the minimum accepted common substructure size. More...
 

Detailed Description

Enumerates all maximal common connected substructures shared between a query and a target molecular graph.

Unlike Chem::MaxCommonAtomSubstructureSearch and Chem::MaxCommonBondSubstructureSearch, the matches reported here are required to be connected — i.e. each mapping covers a single connected subgraph of both the query and the target. Successive calls to setQuery() and findAllMappings() or findMaxMappings() produce all possible common substructure atom/bond mapping solutions (subject to an atom count lower bound set by setMinSubstructureSize()). If just the information whether or not a common substructure (fulfilling the size lower bound) exists is of interest then the more efficient method mappingExists() can be used. Found common substructures 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().

See also
[MCSA]

Member Typedef Documentation

◆ SharedPointer

A reference-counted smart pointer [SHPTR] for dynamically allocated CommonConnectedSubstructureSearch instances.

◆ MappingIterator

typedef boost::indirect_iterator<ABMappingList::iterator, AtomBondMapping> CDPL::Chem::CommonConnectedSubstructureSearch::MappingIterator

A mutable random access iterator used to iterate over the stored Chem::AtomBondMapping objects.

◆ ConstMappingIterator

typedef boost::indirect_iterator<ABMappingList::const_iterator, const AtomBondMapping> CDPL::Chem::CommonConnectedSubstructureSearch::ConstMappingIterator

A constant random access iterator used to iterate over the stored const Chem::AtomBondMapping objects.

◆ AtomMatchExpressionFunction

typedef std::function<const AtomMatchExprPtr&(const Atom&)> CDPL::Chem::CommonConnectedSubstructureSearch::AtomMatchExpressionFunction

Type of the functor used to retrieve the Chem::MatchExpression implementation instance for a query atom.

◆ BondMatchExpressionFunction

typedef std::function<const BondMatchExprPtr&(const Bond&)> CDPL::Chem::CommonConnectedSubstructureSearch::BondMatchExpressionFunction

Type of the functor used to retrieve the Chem::MatchExpression implementation instance for a query bond.

◆ MolecularGraphMatchExpressionFunction

Type of the functor used to retrieve the Chem::MatchExpression implementation instance for the query molecular graph.

Constructor & Destructor Documentation

◆ CommonConnectedSubstructureSearch() [1/3]

CDPL::Chem::CommonConnectedSubstructureSearch::CommonConnectedSubstructureSearch ( )

Constructs and initializes the CommonConnectedSubstructureSearch instance.

◆ CommonConnectedSubstructureSearch() [2/3]

CDPL::Chem::CommonConnectedSubstructureSearch::CommonConnectedSubstructureSearch ( const MolecularGraph query)

Constructs and initializes the CommonConnectedSubstructureSearch instance for the query molecular graph query.

Parameters
queryA molecular graph that represents the query structure.

◆ CommonConnectedSubstructureSearch() [3/3]

CDPL::Chem::CommonConnectedSubstructureSearch::CommonConnectedSubstructureSearch ( const CommonConnectedSubstructureSearch )
delete

◆ ~CommonConnectedSubstructureSearch()

CDPL::Chem::CommonConnectedSubstructureSearch::~CommonConnectedSubstructureSearch ( )

Destructor.

Destroys the CommonConnectedSubstructureSearch instance and frees all allocated resources.

Member Function Documentation

◆ operator=()

CommonConnectedSubstructureSearch& CDPL::Chem::CommonConnectedSubstructureSearch::operator= ( const CommonConnectedSubstructureSearch )
delete

◆ setAtomMatchExpressionFunction()

void CDPL::Chem::CommonConnectedSubstructureSearch::setAtomMatchExpressionFunction ( const AtomMatchExpressionFunction func)

Installs a function that resolves the Chem::MatchExpression implementation instance for a query atom.

Parameters
funcThe accessor function to use.

◆ setBondMatchExpressionFunction()

void CDPL::Chem::CommonConnectedSubstructureSearch::setBondMatchExpressionFunction ( const BondMatchExpressionFunction func)

Installs a function that resolves the Chem::MatchExpression implementation instance for a query bond.

Parameters
funcThe accessor function to use.

◆ setMolecularGraphMatchExpressionFunction()

void CDPL::Chem::CommonConnectedSubstructureSearch::setMolecularGraphMatchExpressionFunction ( const MolecularGraphMatchExpressionFunction func)

Installs a function that resolves the Chem::MatchExpression implementation instance for the query molecular graph.

Parameters
funcThe accessor function to use.

◆ setQuery()

void CDPL::Chem::CommonConnectedSubstructureSearch::setQuery ( const MolecularGraph query)

Sets query as the new query molecular graph.

Parameters
queryA molecular graph that represents the new query.

◆ mappingExists()

bool CDPL::Chem::CommonConnectedSubstructureSearch::mappingExists ( const MolecularGraph target)

Searches for a common connected substructure between the query and the target molecular graph target.

The method does not store any atom/bond mappings between query and target molecular graphs — it just tells if a valid common substructure mapping solution involving at least getMinSubstructureSize() atoms could be found. If you need access to the atom/bond mappings, use findAllMappings() or findMaxMappings() instead.

Parameters
targetThe molecular graph that has to be searched for a connected substructure in common with the query.
Returns
true if a common substructure of at least the minimum accepted size could be found, and false otherwise.
Note
Any atom/bond mappings that were recorded in a previous call to findAllMappings() or findMaxMappings() will be discarded.

◆ findAllMappings()

bool CDPL::Chem::CommonConnectedSubstructureSearch::findAllMappings ( const MolecularGraph target)

Searches for all possible atom/bond mappings of connected query subgraphs to substructures of the target molecular graph target.

The method will store all found common substructure mapping solutions involving at least getMinSubstructureSize() atoms 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.

Parameters
targetThe target molecular graph that has to be searched for all connected substructures in common with the query.
Returns
true if common substructures of at least the minimum accepted size were found, and false otherwise.
Note
Any atom/bond mappings that were recorded in a previous call to findAllMappings() or findMaxMappings() will be discarded.

◆ findMaxMappings()

bool CDPL::Chem::CommonConnectedSubstructureSearch::findMaxMappings ( const MolecularGraph target)

Searches for all maximum-sized atom/bond mappings of connected query subgraphs to substructures of the target molecular graph target.

The method will store all maximum-sized common substructure mapping solutions involving at least getMinSubstructureSize() atoms 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.

Parameters
targetThe target molecular graph that has to be searched for all maximum-sized connected substructures in common with the query.
Returns
true if common substructures of at least the minimum accepted size were found, and false otherwise.
Note
Any atom/bond mappings that were recorded in a previous call to findAllMappings() or findMaxMappings() will be discarded.

◆ getNumMappings()

std::size_t CDPL::Chem::CommonConnectedSubstructureSearch::getNumMappings ( ) const

Returns the number of atom/bond mappings that were recorded in the last search for common substructures.

Returns
The number of atom/bond mappings that were recorded in the last search for common substructures.
See also
findAllMappings(), findMaxMappings()

◆ getMapping() [1/2]

AtomBondMapping& CDPL::Chem::CommonConnectedSubstructureSearch::getMapping ( std::size_t  idx)

Returns a non-const reference to the stored atom/bond mapping object at index idx.

Parameters
idxThe zero-based index of the atom/bond mapping object to return.
Returns
A non-const reference to the Chem::AtomBondMapping object at index idx.
Exceptions
Base::IndexErrorif idx is not in the range [0, getNumMappings()).

◆ getMapping() [2/2]

const AtomBondMapping& CDPL::Chem::CommonConnectedSubstructureSearch::getMapping ( std::size_t  idx) const

Returns a const reference to the stored atom/bond mapping object at index idx.

Parameters
idxThe zero-based index of the atom/bond mapping object to return.
Returns
A const reference to the Chem::AtomBondMapping object at index idx.
Exceptions
Base::IndexErrorif idx is not in the range [0, getNumMappings()).

◆ getMappingsBegin() [1/2]

MappingIterator CDPL::Chem::CommonConnectedSubstructureSearch::getMappingsBegin ( )

Returns a mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping objects.

Returns
A mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping objects.

◆ getMappingsBegin() [2/2]

ConstMappingIterator CDPL::Chem::CommonConnectedSubstructureSearch::getMappingsBegin ( ) const

Returns a constant iterator pointing to the beginning of the stored const Chem::AtomBondMapping objects.

Returns
A constant iterator pointing to the beginning of the stored const Chem::AtomBondMapping objects.

◆ getMappingsEnd() [1/2]

MappingIterator CDPL::Chem::CommonConnectedSubstructureSearch::getMappingsEnd ( )

Returns a mutable iterator pointing to the end of the stored Chem::AtomBondMapping objects.

Returns
A mutable iterator pointing to the end of the stored Chem::AtomBondMapping objects.

◆ getMappingsEnd() [2/2]

ConstMappingIterator CDPL::Chem::CommonConnectedSubstructureSearch::getMappingsEnd ( ) const

Returns a constant iterator pointing to the end of the stored const Chem::AtomBondMapping objects.

Returns
A constant iterator pointing to the end of the stored const Chem::AtomBondMapping objects.

◆ begin() [1/2]

MappingIterator CDPL::Chem::CommonConnectedSubstructureSearch::begin ( )

Returns a mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping objects.

Returns
A mutable iterator pointing to the beginning of the stored Chem::AtomBondMapping objects.

◆ begin() [2/2]

ConstMappingIterator CDPL::Chem::CommonConnectedSubstructureSearch::begin ( ) const

Returns a constant iterator pointing to the beginning of the stored const Chem::AtomBondMapping objects.

Returns
A constant iterator pointing to the beginning of the stored const Chem::AtomBondMapping objects.

◆ end() [1/2]

MappingIterator CDPL::Chem::CommonConnectedSubstructureSearch::end ( )

Returns a mutable iterator pointing to the end of the stored Chem::AtomBondMapping objects.

Returns
A mutable iterator pointing to the end of the stored Chem::AtomBondMapping objects.

◆ end() [2/2]

ConstMappingIterator CDPL::Chem::CommonConnectedSubstructureSearch::end ( ) const

Returns a constant iterator pointing to the end of the stored const Chem::AtomBondMapping objects.

Returns
A constant iterator pointing to the end of the stored const Chem::AtomBondMapping objects.

◆ uniqueMappingsOnly() [1/2]

void CDPL::Chem::CommonConnectedSubstructureSearch::uniqueMappingsOnly ( bool  unique)

Allows to specify whether or not to store only unique atom/bond mappings.

The mapping of a query subgraph 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.

Parameters
uniqueIf true, only unique mappings will be stored, and all found mappings otherwise.
Note
By default, duplicate mappings are not discarded.

◆ uniqueMappingsOnly() [2/2]

bool CDPL::Chem::CommonConnectedSubstructureSearch::uniqueMappingsOnly ( ) const

Tells whether duplicate atom/bond mappings are discarded.

Returns
true if duplicate mappings are discarded, and false otherwise.
See also
uniqueMappingsOnly(bool unique)

◆ setMaxNumMappings()

void CDPL::Chem::CommonConnectedSubstructureSearch::setMaxNumMappings ( std::size_t  max_num_mappings)

Allows to specify a limit on the number of stored atom/bond mappings.

In a call to findAllMappings() or findMaxMappings() the common 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.

Parameters
max_num_mappingsThe maximum number of atom/bond mappings to store.
Note
By default, no limit is imposed on the number of stored mappings.

◆ getMaxNumMappings()

std::size_t CDPL::Chem::CommonConnectedSubstructureSearch::getMaxNumMappings ( ) const

Returns the specified limit on the number of stored atom/bond mappings.

Returns
The specified maximum number of stored atom/bond mappings.
See also
setMaxNumMappings(), findAllMappings(), findMaxMappings()

◆ setMinSubstructureSize()

void CDPL::Chem::CommonConnectedSubstructureSearch::setMinSubstructureSize ( std::size_t  min_size)

Allows to specify the minimum accepted common substructure size.

Any found common substructures which cover less than min_size atoms are not accepted as a valid solution and will be discarded.

Parameters
min_sizeThe minimum accepted common substructure size in number of atoms.
Note
By default, the minimum common substructure size is set to zero.

◆ getMinSubstructureSize()

std::size_t CDPL::Chem::CommonConnectedSubstructureSearch::getMinSubstructureSize ( ) const

Returns the minimum accepted common substructure size.

Returns
The minimum accepted common substructure size in number of atoms.
See also
setMinSubstructureSize()

The documentation for this class was generated from the following file: