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

Generic rule-based molecule fragmentation engine that splits a molecular graph along bonds matching user-defined SMARTS fragmentation rules. More...

#include <FragmentGenerator.hpp>

+ Inheritance diagram for CDPL::Chem::FragmentGenerator:

Classes

class  ExcludePattern
 A pattern overriding a fragmentation rule: bonds matching the pattern are not cleaved. More...
 
class  FragmentationRule
 A single fragmentation rule, consisting of a SMARTS match pattern and a numeric rule ID. More...
 
class  FragmentLink
 Records the connectivity between two fragments produced by a single bond cleavage. More...
 

Public Types

typedef std::shared_ptr< FragmentGeneratorSharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated FragmentGenerator instances. More...
 
typedef std::function< bool(const MolecularGraph &)> FragmentFilterFunction
 Type of a predicate accepting/rejecting a generated fragment. More...
 
typedef FragmentationRuleList::const_iterator ConstFragmentationRuleIterator
 A constant iterator over the registered fragmentation rules. More...
 
typedef FragmentationRuleList::iterator FragmentationRuleIterator
 A mutable iterator over the registered fragmentation rules. More...
 
typedef ExcludePatternList::const_iterator ConstExcludePatternIterator
 A constant iterator over the registered exclude patterns. More...
 
typedef ExcludePatternList::iterator ExcludePatternIterator
 A mutable iterator over the registered exclude patterns. More...
 
typedef FragmentLinkList::const_iterator ConstFragmentLinkIterator
 A constant iterator over the generated fragment links. More...
 

Public Member Functions

 FragmentGenerator ()
 Constructs the FragmentGenerator instance. More...
 
 FragmentGenerator (const FragmentGenerator &gen)
 Constructs a copy of the FragmentGenerator instance gen. More...
 
virtual ~FragmentGenerator ()
 Virtual destructor. More...
 
FragmentGeneratoroperator= (const FragmentGenerator &gen)
 Replaces the state of this generator by a copy of the state of gen. More...
 
void addFragmentationRule (const MolecularGraph::SharedPointer &match_ptn, unsigned int rule_id)
 Registers a new fragmentation rule by its SMARTS match pattern and rule ID. More...
 
void addFragmentationRule (const FragmentationRule &rule)
 Appends a copy of the pre-built fragmentation rule rule. More...
 
const FragmentationRulegetFragmentationRule (std::size_t idx) const
 Returns the fragmentation rule at index idx. More...
 
FragmentationRulegetFragmentationRule (std::size_t idx)
 Returns the fragmentation rule at index idx. More...
 
ConstFragmentationRuleIterator getFragmentationRulesBegin () const
 Returns a constant iterator pointing to the first registered fragmentation rule. More...
 
ConstFragmentationRuleIterator getFragmentationRulesEnd () const
 Returns a constant iterator pointing one past the last registered fragmentation rule. More...
 
FragmentationRuleIterator getFragmentationRulesBegin ()
 Returns a mutable iterator pointing to the first registered fragmentation rule. More...
 
FragmentationRuleIterator getFragmentationRulesEnd ()
 Returns a mutable iterator pointing one past the last registered fragmentation rule. More...
 
void removeFragmentationRule (std::size_t idx)
 Removes the fragmentation rule at index idx. More...
 
std::size_t getNumFragmentationRules () const
 Returns the number of registered fragmentation rules. More...
 
void clearFragmentationRules ()
 Removes all registered fragmentation rules. More...
 
void addExcludePattern (const MolecularGraph::SharedPointer &match_ptn, unsigned int rule_id)
 Registers a rule-specific exclude pattern. More...
 
void addExcludePattern (const MolecularGraph::SharedPointer &match_ptn)
 Registers a generic exclude pattern (applies to all fragmentation rules). More...
 
void addExcludePattern (const ExcludePattern &excl_ptn)
 Appends a copy of the pre-built exclude pattern excl_ptn. More...
 
const ExcludePatterngetExcludePattern (std::size_t idx) const
 Returns the exclude pattern at index idx. More...
 
ExcludePatterngetExcludePattern (std::size_t idx)
 Returns the exclude pattern at index idx. More...
 
ConstExcludePatternIterator getExcludePatternsBegin () const
 Returns a constant iterator pointing to the first registered exclude pattern. More...
 
ConstExcludePatternIterator getExcludePatternsEnd () const
 Returns a constant iterator pointing one past the last registered exclude pattern. More...
 
ExcludePatternIterator getExcludePatternsBegin ()
 Returns a mutable iterator pointing to the first registered exclude pattern. More...
 
ExcludePatternIterator getExcludePatternsEnd ()
 Returns a mutable iterator pointing one past the last registered exclude pattern. More...
 
void removeExcludePattern (std::size_t idx)
 Removes the exclude pattern at index idx. More...
 
std::size_t getNumExcludePatterns () const
 Returns the number of registered exclude patterns. More...
 
void clearExcludePatterns ()
 Removes all registered exclude patterns. More...
 
bool splitBondsIncluded () const
 Tells whether the split (cleaved) bonds are retained in the output fragments. More...
 
void includeSplitBonds (bool include)
 Specifies whether the split (cleaved) bonds shall be retained in the output fragments. More...
 
const FragmentFilterFunctiongetFragmentFilterFunction () const
 Returns the predicate used to filter the generated fragments. More...
 
void setFragmentFilterFunction (const FragmentFilterFunction &func)
 Sets the predicate used to filter the generated fragments (fragments for which the predicate returns false are discarded). More...
 
void generate (const MolecularGraph &molgraph, FragmentList &frag_list, bool append=false)
 Performs the fragmentation of molgraph and writes the resulting fragments to frag_list. More...
 
std::size_t getNumFragmentLinks () const
 Returns the number of fragment links produced by the most recent generate() call. More...
 
const FragmentLinkgetFragmentLink (std::size_t idx) const
 Returns the fragment link at index idx. More...
 
ConstFragmentLinkIterator getFragmentLinksBegin () const
 Returns a constant iterator pointing to the first fragment link. More...
 
ConstFragmentLinkIterator getFragmentLinksEnd () const
 Returns a constant iterator pointing one past the last fragment link. More...
 

Detailed Description

Generic rule-based molecule fragmentation engine that splits a molecular graph along bonds matching user-defined SMARTS fragmentation rules.

Fragmentation rules are added via addFragmentationRule() (each rule has a SMARTS pattern matching a bond plus a numeric rule ID). Bonds matching any registered rule are scheduled for splitting, unless a registered exclude pattern overrides the split. The optional fragment filter rejects generated fragments based on a user-supplied predicate. The connectivity between the resulting fragments is exposed via the FragmentLink list, recording for each cleaved bond the two adjacent fragment indices, the cleaved bond, the matching rule and per-side atom labels.

Member Typedef Documentation

◆ SharedPointer

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

◆ FragmentFilterFunction

Type of a predicate accepting/rejecting a generated fragment.

◆ ConstFragmentationRuleIterator

typedef FragmentationRuleList::const_iterator CDPL::Chem::FragmentGenerator::ConstFragmentationRuleIterator

A constant iterator over the registered fragmentation rules.

◆ FragmentationRuleIterator

typedef FragmentationRuleList::iterator CDPL::Chem::FragmentGenerator::FragmentationRuleIterator

A mutable iterator over the registered fragmentation rules.

◆ ConstExcludePatternIterator

typedef ExcludePatternList::const_iterator CDPL::Chem::FragmentGenerator::ConstExcludePatternIterator

A constant iterator over the registered exclude patterns.

◆ ExcludePatternIterator

typedef ExcludePatternList::iterator CDPL::Chem::FragmentGenerator::ExcludePatternIterator

A mutable iterator over the registered exclude patterns.

◆ ConstFragmentLinkIterator

typedef FragmentLinkList::const_iterator CDPL::Chem::FragmentGenerator::ConstFragmentLinkIterator

A constant iterator over the generated fragment links.

Constructor & Destructor Documentation

◆ FragmentGenerator() [1/2]

CDPL::Chem::FragmentGenerator::FragmentGenerator ( )

Constructs the FragmentGenerator instance.

◆ FragmentGenerator() [2/2]

CDPL::Chem::FragmentGenerator::FragmentGenerator ( const FragmentGenerator gen)

Constructs a copy of the FragmentGenerator instance gen.

Parameters
genThe FragmentGenerator to copy.

◆ ~FragmentGenerator()

virtual CDPL::Chem::FragmentGenerator::~FragmentGenerator ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

◆ operator=()

FragmentGenerator& CDPL::Chem::FragmentGenerator::operator= ( const FragmentGenerator gen)

Replaces the state of this generator by a copy of the state of gen.

Parameters
genThe source FragmentGenerator.
Returns
A reference to itself.

◆ addFragmentationRule() [1/2]

void CDPL::Chem::FragmentGenerator::addFragmentationRule ( const MolecularGraph::SharedPointer match_ptn,
unsigned int  rule_id 
)

Registers a new fragmentation rule by its SMARTS match pattern and rule ID.

Parameters
match_ptnThe SMARTS match pattern (must match a single bond to be cleaved).
rule_idThe rule identifier.

◆ addFragmentationRule() [2/2]

void CDPL::Chem::FragmentGenerator::addFragmentationRule ( const FragmentationRule rule)

Appends a copy of the pre-built fragmentation rule rule.

Parameters
ruleThe rule to copy and register.

◆ getFragmentationRule() [1/2]

const FragmentationRule& CDPL::Chem::FragmentGenerator::getFragmentationRule ( std::size_t  idx) const

Returns the fragmentation rule at index idx.

Parameters
idxThe zero-based rule index.
Returns
A const reference to the rule.
Exceptions
Base::IndexErrorif the number of rules is zero or idx is not in the range [0, getNumFragmentationRules() - 1].

◆ getFragmentationRule() [2/2]

FragmentationRule& CDPL::Chem::FragmentGenerator::getFragmentationRule ( std::size_t  idx)

Returns the fragmentation rule at index idx.

Parameters
idxThe zero-based rule index.
Returns
A reference to the rule.
Exceptions
Base::IndexErrorif the number of rules is zero or idx is not in the range [0, getNumFragmentationRules() - 1].

◆ getFragmentationRulesBegin() [1/2]

ConstFragmentationRuleIterator CDPL::Chem::FragmentGenerator::getFragmentationRulesBegin ( ) const

Returns a constant iterator pointing to the first registered fragmentation rule.

Returns
A constant iterator pointing to the first rule.

◆ getFragmentationRulesEnd() [1/2]

ConstFragmentationRuleIterator CDPL::Chem::FragmentGenerator::getFragmentationRulesEnd ( ) const

Returns a constant iterator pointing one past the last registered fragmentation rule.

Returns
A constant iterator pointing one past the last rule.

◆ getFragmentationRulesBegin() [2/2]

FragmentationRuleIterator CDPL::Chem::FragmentGenerator::getFragmentationRulesBegin ( )

Returns a mutable iterator pointing to the first registered fragmentation rule.

Returns
A mutable iterator pointing to the first rule.

◆ getFragmentationRulesEnd() [2/2]

FragmentationRuleIterator CDPL::Chem::FragmentGenerator::getFragmentationRulesEnd ( )

Returns a mutable iterator pointing one past the last registered fragmentation rule.

Returns
A mutable iterator pointing one past the last rule.

◆ removeFragmentationRule()

void CDPL::Chem::FragmentGenerator::removeFragmentationRule ( std::size_t  idx)

Removes the fragmentation rule at index idx.

Parameters
idxThe zero-based rule index.
Exceptions
Base::IndexErrorif the number of rules is zero or idx is not in the range [0, getNumFragmentationRules() - 1].

◆ getNumFragmentationRules()

std::size_t CDPL::Chem::FragmentGenerator::getNumFragmentationRules ( ) const

Returns the number of registered fragmentation rules.

Returns
The rule count.

◆ clearFragmentationRules()

void CDPL::Chem::FragmentGenerator::clearFragmentationRules ( )

Removes all registered fragmentation rules.

◆ addExcludePattern() [1/3]

void CDPL::Chem::FragmentGenerator::addExcludePattern ( const MolecularGraph::SharedPointer match_ptn,
unsigned int  rule_id 
)

Registers a rule-specific exclude pattern.

Parameters
match_ptnThe SMARTS match pattern.
rule_idThe rule ID this exclusion applies to.

◆ addExcludePattern() [2/3]

void CDPL::Chem::FragmentGenerator::addExcludePattern ( const MolecularGraph::SharedPointer match_ptn)

Registers a generic exclude pattern (applies to all fragmentation rules).

Parameters
match_ptnThe SMARTS match pattern.

◆ addExcludePattern() [3/3]

void CDPL::Chem::FragmentGenerator::addExcludePattern ( const ExcludePattern excl_ptn)

Appends a copy of the pre-built exclude pattern excl_ptn.

Parameters
excl_ptnThe exclude pattern to copy and register.

◆ getExcludePattern() [1/2]

const ExcludePattern& CDPL::Chem::FragmentGenerator::getExcludePattern ( std::size_t  idx) const

Returns the exclude pattern at index idx.

Parameters
idxThe zero-based pattern index.
Returns
A const reference to the exclude pattern.
Exceptions
Base::IndexErrorif the number of exclude patterns is zero or idx is not in the range [0, getNumExcludePatterns() - 1].

◆ getExcludePattern() [2/2]

ExcludePattern& CDPL::Chem::FragmentGenerator::getExcludePattern ( std::size_t  idx)

Returns the exclude pattern at index idx.

Parameters
idxThe zero-based pattern index.
Returns
A reference to the exclude pattern.
Exceptions
Base::IndexErrorif the number of exclude patterns is zero or idx is not in the range [0, getNumExcludePatterns() - 1].

◆ getExcludePatternsBegin() [1/2]

ConstExcludePatternIterator CDPL::Chem::FragmentGenerator::getExcludePatternsBegin ( ) const

Returns a constant iterator pointing to the first registered exclude pattern.

Returns
A constant iterator pointing to the first exclude pattern.

◆ getExcludePatternsEnd() [1/2]

ConstExcludePatternIterator CDPL::Chem::FragmentGenerator::getExcludePatternsEnd ( ) const

Returns a constant iterator pointing one past the last registered exclude pattern.

Returns
A constant iterator pointing one past the last exclude pattern.

◆ getExcludePatternsBegin() [2/2]

ExcludePatternIterator CDPL::Chem::FragmentGenerator::getExcludePatternsBegin ( )

Returns a mutable iterator pointing to the first registered exclude pattern.

Returns
A mutable iterator pointing to the first exclude pattern.

◆ getExcludePatternsEnd() [2/2]

ExcludePatternIterator CDPL::Chem::FragmentGenerator::getExcludePatternsEnd ( )

Returns a mutable iterator pointing one past the last registered exclude pattern.

Returns
A mutable iterator pointing one past the last exclude pattern.

◆ removeExcludePattern()

void CDPL::Chem::FragmentGenerator::removeExcludePattern ( std::size_t  idx)

Removes the exclude pattern at index idx.

Parameters
idxThe zero-based pattern index.
Exceptions
Base::IndexErrorif the number of exclude patterns is zero or idx is not in the range [0, getNumExcludePatterns() - 1].

◆ getNumExcludePatterns()

std::size_t CDPL::Chem::FragmentGenerator::getNumExcludePatterns ( ) const

Returns the number of registered exclude patterns.

Returns
The exclude-pattern count.

◆ clearExcludePatterns()

void CDPL::Chem::FragmentGenerator::clearExcludePatterns ( )

Removes all registered exclude patterns.

◆ splitBondsIncluded()

bool CDPL::Chem::FragmentGenerator::splitBondsIncluded ( ) const

Tells whether the split (cleaved) bonds are retained in the output fragments.

Returns
true if split bonds are retained, and false otherwise.

◆ includeSplitBonds()

void CDPL::Chem::FragmentGenerator::includeSplitBonds ( bool  include)

Specifies whether the split (cleaved) bonds shall be retained in the output fragments.

Parameters
includeIf true, the cleaved bonds remain part of the adjacent output fragments.

◆ getFragmentFilterFunction()

const FragmentFilterFunction& CDPL::Chem::FragmentGenerator::getFragmentFilterFunction ( ) const

Returns the predicate used to filter the generated fragments.

Returns
A const reference to the fragment-filter function.

◆ setFragmentFilterFunction()

void CDPL::Chem::FragmentGenerator::setFragmentFilterFunction ( const FragmentFilterFunction func)

Sets the predicate used to filter the generated fragments (fragments for which the predicate returns false are discarded).

Parameters
funcThe new fragment-filter function.

◆ generate()

void CDPL::Chem::FragmentGenerator::generate ( const MolecularGraph molgraph,
FragmentList frag_list,
bool  append = false 
)

Performs the fragmentation of molgraph and writes the resulting fragments to frag_list.

Parameters
molgraphThe molecular graph to fragment.
frag_listThe output fragment list.
appendIf true, new fragments are appended to frag_list; otherwise the list is cleared first.

◆ getNumFragmentLinks()

std::size_t CDPL::Chem::FragmentGenerator::getNumFragmentLinks ( ) const

Returns the number of fragment links produced by the most recent generate() call.

Returns
The fragment-link count.

◆ getFragmentLink()

const FragmentLink& CDPL::Chem::FragmentGenerator::getFragmentLink ( std::size_t  idx) const

Returns the fragment link at index idx.

Parameters
idxThe zero-based link index.
Returns
A const reference to the fragment link.
Exceptions
Base::IndexErrorif the number of fragment links is zero or idx is not in the range [0, getNumFragmentLinks() - 1].

◆ getFragmentLinksBegin()

ConstFragmentLinkIterator CDPL::Chem::FragmentGenerator::getFragmentLinksBegin ( ) const

Returns a constant iterator pointing to the first fragment link.

Returns
A constant iterator pointing to the first fragment link.

◆ getFragmentLinksEnd()

ConstFragmentLinkIterator CDPL::Chem::FragmentGenerator::getFragmentLinksEnd ( ) const

Returns a constant iterator pointing one past the last fragment link.

Returns
A constant iterator pointing one past the last fragment link.

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