Chemical Data Processing Library Python API - Version 1.4.0
Classes | Public Member Functions | Properties | 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 fragmentation rules. More...

+ Inheritance diagram for CDPL.Chem.FragmentGenerator:

Classes

class  ExcludePattern
 A pattern descriptor specifying bonds that shall not be cleaved. More...
 
class  FragmentationRule
 A single fragmentation rule, consisting of a bond substructure match pattern and a numeric rule ID. More...
 
class  FragmentLink
 Records the connectivity between two fragments produced by a single bond cleavage. More...
 

Public Member Functions

None __init__ ()
 Constructs the FragmentGenerator instance.
 
None __init__ (FragmentGenerator gen)
 Constructs a copy of the FragmentGenerator instance gen. More...
 
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
FragmentGenerator assign (FragmentGenerator gen)
 Replaces the state of this generator by a copy of the state of gen. More...
 
None addFragmentationRule (MolecularGraph match_ptn, int rule_id)
 Registers a new fragmentation rule by its bond substructure match pattern and rule ID. More...
 
None addFragmentationRule (FragmentationRule rule)
 Appends a copy of the pre-built fragmentation rule rule. More...
 
None removeFragmentationRule (int idx)
 Removes the fragmentation rule at index idx. More...
 
FragmentationRule getFragmentationRule (int idx)
 Returns the fragmentation rule at index idx. More...
 
None clearFragmentationRules ()
 Removes all registered fragmentation rules.
 
int getNumFragmentationRules ()
 Returns the number of registered fragmentation rules. More...
 
None addExcludePattern (MolecularGraph match_ptn, int rule_id)
 Registers a rule-specific exclude pattern. More...
 
None addExcludePattern (ExcludePattern excl_ptn)
 Appends a copy of the pre-built exclude pattern excl_ptn. More...
 
None removeExcludePattern (int idx)
 Removes the exclude pattern at index idx. More...
 
ExcludePattern getExcludePattern (int idx)
 Returns the exclude pattern at index idx. More...
 
None clearExcludePatterns ()
 Removes all registered exclude patterns.
 
int getNumExcludePatterns ()
 Returns the number of registered exclude patterns. More...
 
None setFragmentFilterFunction (BoolConstMolecularGraphFunctor func)
 Sets the predicate used to filter the generated fragments (fragments for which the predicate returns False are discarded). More...
 
BoolConstMolecularGraphFunctor getFragmentFilterFunction ()
 Returns the predicate used to filter the generated fragments. More...
 
None generate (MolecularGraph molgraph, FragmentList frag_list, bool append=False)
 Performs the fragmentation of molgraph and appends the resulting fragments to frag_list. More...
 
FragmentLink getFragmentLink (int idx)
 Returns the fragment link at index idx. More...
 
int getNumFragmentLinks ()
 Returns the number of fragment links produced by the most recent generate() call. More...
 
None includeSplitBonds (bool include)
 Specifies whether the split (cleaved) bonds shall be retained in the output fragments. More...
 

Properties

 objectID = property(getObjectID)
 
 fragmentFilterFunction = property(getFragmentFilterFunction, setFragmentFilterFunction)
 
 incSplitBonds = property(splitBondsIncluded, includeSplitBonds)
 
 numFragmentationRules = property(getNumFragmentationRules)
 
 numExcludePatterns = property(getNumExcludePatterns)
 
 numFragmentLinks = property(getNumFragmentLinks)
 

Detailed Description

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

Fragmentation rules are added via addFragmentationRule() (each rule has a substructure pattern describing 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.

Constructor & Destructor Documentation

◆ __init__()

None CDPL.Chem.FragmentGenerator.__init__ ( FragmentGenerator  gen)

Constructs a copy of the FragmentGenerator instance gen.

Parameters
genThe FragmentGenerator to copy.

Member Function Documentation

◆ getObjectID()

int CDPL.Chem.FragmentGenerator.getObjectID ( )

Returns the numeric identifier (ID) of the wrapped C++ class instance.

Different Python FragmentGenerator instances may reference the same underlying C++ class instance. The commonly used Python expression a is not b thus cannot tell reliably whether the two FragmentGenerator instances a and b reference different C++ objects. The numeric identifier returned by this method allows to correctly implement such an identity test via the simple expression a.getObjectID() != b.getObjectID().

Returns
The numeric ID of the internally referenced C++ class instance.

◆ assign()

FragmentGenerator CDPL.Chem.FragmentGenerator.assign ( FragmentGenerator  gen)

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

Parameters
genThe FragmentGenerator instance to copy.
Returns
self

◆ addFragmentationRule() [1/2]

None CDPL.Chem.FragmentGenerator.addFragmentationRule ( MolecularGraph  match_ptn,
int  rule_id 
)

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

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

◆ addFragmentationRule() [2/2]

None CDPL.Chem.FragmentGenerator.addFragmentationRule ( FragmentationRule  rule)

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

Parameters
ruleThe rule to copy and register.

◆ removeFragmentationRule()

None CDPL.Chem.FragmentGenerator.removeFragmentationRule ( int  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].

◆ getFragmentationRule()

FragmentationRule CDPL.Chem.FragmentGenerator.getFragmentationRule ( int  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].

◆ getNumFragmentationRules()

int CDPL.Chem.FragmentGenerator.getNumFragmentationRules ( )

Returns the number of registered fragmentation rules.

Returns
The rule count.

◆ addExcludePattern() [1/2]

None CDPL.Chem.FragmentGenerator.addExcludePattern ( MolecularGraph  match_ptn,
int  rule_id 
)

Registers a rule-specific exclude pattern.

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

◆ addExcludePattern() [2/2]

None CDPL.Chem.FragmentGenerator.addExcludePattern ( ExcludePattern  excl_ptn)

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

Parameters
excl_ptnThe exclude pattern to copy and register.

◆ removeExcludePattern()

None CDPL.Chem.FragmentGenerator.removeExcludePattern ( int  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].

◆ getExcludePattern()

ExcludePattern CDPL.Chem.FragmentGenerator.getExcludePattern ( int  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].

◆ getNumExcludePatterns()

int CDPL.Chem.FragmentGenerator.getNumExcludePatterns ( )

Returns the number of registered exclude patterns.

Returns
The exclude-pattern count.

◆ setFragmentFilterFunction()

None CDPL.Chem.FragmentGenerator.setFragmentFilterFunction ( BoolConstMolecularGraphFunctor  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.

◆ getFragmentFilterFunction()

BoolConstMolecularGraphFunctor CDPL.Chem.FragmentGenerator.getFragmentFilterFunction ( )

Returns the predicate used to filter the generated fragments.

Returns
A reference to the fragment filter function.

◆ generate()

None CDPL.Chem.FragmentGenerator.generate ( MolecularGraph  molgraph,
FragmentList  frag_list,
bool   append = False 
)

Performs the fragmentation of molgraph and appends 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.

◆ getFragmentLink()

FragmentLink CDPL.Chem.FragmentGenerator.getFragmentLink ( int  idx)

Returns the fragment link at index idx.

Parameters
idxThe zero-based link index.
Returns
A 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].

◆ getNumFragmentLinks()

int CDPL.Chem.FragmentGenerator.getNumFragmentLinks ( )

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

Returns
The fragment link count.

◆ includeSplitBonds()

None 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.