rdkit.Chem.rdChemReactions module

Module containing classes and functions for working with chemical reactions.

class rdkit.Chem.rdChemReactions.CartesianProductStrategy(self)

Bases: EnumerationStrategyBase

CartesianProductStrategy produces a standard walk through all possible reagent combinations:

(0,0,0), (1,0,0), (2,0,0) …

class rdkit.Chem.rdChemReactions.ChemicalReaction(self)
class rdkit.Chem.rdChemReactions.ChemicalReaction(self, binStr: bytes)
class rdkit.Chem.rdChemReactions.ChemicalReaction(self, binStr: str)
class rdkit.Chem.rdChemReactions.ChemicalReaction(self, other: rdkit.Chem.rdChemReactions.ChemicalReaction)

Bases: object

A class for storing and applying chemical reactions.

Sample Usage:
>>> from rdkit import Chem
>>> from rdkit.Chem import rdChemReactions
>>> rxn = rdChemReactions.ReactionFromSmarts('[C:1](=[O:2])O.[N:3]>>[C:1](=[O:2])[N:3]')
>>> reacts = (Chem.MolFromSmiles('C(=O)O'),Chem.MolFromSmiles('CNC'))
>>> products = rxn.RunReactants(reacts)
>>> len(products)
1
>>> len(products[0])
1
>>> Chem.MolToSmiles(products[0][0])
'CN(C)C=O'

Overloaded function.

  1. __init__(self) -> None

Constructor, takes no arguments

  1. __init__(self, binStr: bytes) -> None

  2. __init__(self, binStr: str) -> None

  3. __init__(self, other: rdkit.Chem.rdChemReactions.ChemicalReaction) -> None

AddAgentTemplate(self, mol: rdkit.Chem.rdchem.Mol) int

adds a agent (a Molecule)

AddProductTemplate(self, mol: rdkit.Chem.rdchem.Mol) int

adds a product (a Molecule)

AddReactantTemplate(self, mol: rdkit.Chem.rdchem.Mol) int

adds a reactant (a Molecule) to the reaction

AddRecursiveQueriesToReaction(self, queries: dict = {}, propName: str = 'molFileValue', getLabels: bool = False) object

adds recursive queries and returns reactant labels

ClearComputedProps(self) None

Removes all computed properties from the reaction.

ClearProp(self, key: str) None

Removes a property from the reaction.

ARGUMENTS:
  • key: the name of the property to clear (a string).

GetAgentTemplate(self, which: int) rdkit.Chem.rdchem.Mol

returns one of our agent templates

GetAgents(self) list

get the agent templates

GetBoolProp(self, key: str) object

Returns the Bool value of the property if possible.

ARGUMENTS:
  • key: the name of the property to return (a string).

RETURNS: a bool

NOTE:
  • If the property has not been set, a KeyError exception will be raised.

GetDoubleProp(self, key: str) object

Returns the double value of the property if possible.

ARGUMENTS:
  • key: the name of the property to return (a string).

RETURNS: a double

NOTE:
  • If the property has not been set, a KeyError exception will be raised.

GetIntProp(self, key: str) object

Returns the integer value of the property if possible.

ARGUMENTS:
  • key: the name of the property to return (a string).

RETURNS: an integer

NOTE:
  • If the property has not been set, a KeyError exception will be raised.

GetNumAgentTemplates(self) int

returns the number of agents this reaction expects

GetNumProductTemplates(self) int

returns the number of products this reaction generates

GetNumReactantTemplates(self) int

returns the number of reactants this reaction expects

GetProductTemplate(self, which: int) rdkit.Chem.rdchem.Mol

returns one of our product templates

GetProducts(self) list

get the product templates

GetProp(self, key: str) object

Returns the value of the property.

ARGUMENTS:
  • key: the name of the property to return (a string).

RETURNS: a string

NOTE:
  • If the property has not been set, a KeyError exception will be raised.

GetPropNames(self, includePrivate: bool = False, includeComputed: bool = False) list[str]

Returns a tuple with all property names for this reaction.

ARGUMENTS:
  • includePrivate: (optional) toggles inclusion of private properties in the result set.

    Defaults to 0.

  • includeComputed: (optional) toggles inclusion of computed properties in the result set.

    Defaults to 0.

RETURNS: a tuple of strings

GetPropsAsDict(self, includePrivate: bool = False, includeComputed: bool = False, autoConvertStrings: bool = True) dict
Returns a dictionary populated with the reaction’s properties.

n.b. Some properties are not able to be converted to python types.

ARGUMENTS:
  • includePrivate: (optional) toggles inclusion of private properties in the result set.

    Defaults to False.

  • includeComputed: (optional) toggles inclusion of computed properties in the result set.

    Defaults to False.

RETURNS: a dictionary

GetReactantTemplate(self, which: int) rdkit.Chem.rdchem.Mol

returns one of our reactant templates

GetReactants(self) list

get the reactant templates

GetReactingAtoms(self, mappedAtomsOnly: bool = False) tuple

returns a sequence of sequences with the atoms that change in the reaction

GetSubstructParams(self) rdkit.Chem.rdchem.SubstructMatchParameters

get the parameter object controlling the substructure matching

GetUnsignedProp(self, key: str) object

Returns the unsigned int value of the property if possible.

ARGUMENTS:
  • key: the name of the property to return (a string).

RETURNS: an unsigned integer

NOTE:
  • If the property has not been set, a KeyError exception will be raised.

HasProp(self, key: str) int

Queries a molecule to see if a particular property has been assigned.

ARGUMENTS:
  • key: the name of the property to check for (a string).

Initialize(self, silent: bool = False) None

initializes the reaction so that it can be used

IsInitialized(self) bool

checks if the reaction is ready for use

IsMoleculeAgent(self, mol: rdkit.Chem.rdchem.Mol) bool

returns whether or not the molecule has a substructure match to one of the agents.

IsMoleculeProduct(self, mol: rdkit.Chem.rdchem.Mol) bool

returns whether or not the molecule has a substructure match to one of the products.

IsMoleculeReactant(self, mol: rdkit.Chem.rdchem.Mol) bool

returns whether or not the molecule has a substructure match to one of the reactants.

RemoveAgentTemplates(self, targetList: object | None = None) None

Removes agents from reaction. If targetList is provide the agents will be transferred to that list.

RemoveUnmappedProductTemplates(self, thresholdUnmappedAtoms: float = 0.2, moveToAgentTemplates: bool = True, targetList: object | None = None) None

Removes molecules with an atom mapping ratio below thresholdUnmappedAtoms from product templates to the agent templates or to a given targetList

RemoveUnmappedReactantTemplates(self, thresholdUnmappedAtoms: float = 0.2, moveToAgentTemplates: bool = True, targetList: object | None = None) None

Removes molecules with an atom mapping ratio below thresholdUnmappedAtoms from reactant templates to the agent templates or to a given targetList

RunReactant(self, reactant: rdkit.Chem.rdchem.Mol, reactionIdx: int) tuple

apply the reaction to a single reactant

RunReactantInPlace(self, reactant: rdkit.Chem.rdchem.Mol, removeUnmatchedAtoms: bool = True) bool

apply the reaction to a single reactant in place. The reactant itself is modified. This can only be used for single reactant - single product reactions.

RunReactants(self, reactants: object, maxProducts: int = 1000) tuple

apply the reaction to a sequence of reactant molecules and return the products as a tuple of tuples. If maxProducts is not zero,

stop the reaction when maxProducts have been generated [default=1000]

SetBoolProp(self, key: str, val: bool, computed: bool = False) None

Sets a boolean valued molecular property

ARGUMENTS:
  • key: the name of the property to be set (a string).

  • value: the property value as a bool.

  • computed: (optional) marks the property as being computed.

    Defaults to False.

SetDoubleProp(self, key: str, val: float, computed: bool = False) None

Sets a double valued molecular property

ARGUMENTS:
  • key: the name of the property to be set (a string).

  • value: the property value as a double.

  • computed: (optional) marks the property as being computed.

    Defaults to 0.

SetIntProp(self, key: str, val: int, computed: bool = False) None

Sets an integer valued molecular property

ARGUMENTS:
  • key: the name of the property to be set (an unsigned number).

  • value: the property value as an integer.

  • computed: (optional) marks the property as being computed.

    Defaults to False.

SetProp(self, key: str, val: str, computed: bool = False) None

Sets a molecular property

ARGUMENTS:
  • key: the name of the property to be set (a string).

  • value: the property value (a string).

  • computed: (optional) marks the property as being computed.

    Defaults to False.

SetUnsignedProp(self, key: str, val: int, computed: bool = False) None

Sets an unsigned integer valued molecular property

ARGUMENTS:
  • key: the name of the property to be set (a string).

  • value: the property value as an unsigned integer.

  • computed: (optional) marks the property as being computed.

    Defaults to False.

ToBinary(self) bytes
ToBinary(self, propertyFlags: object) bytes

Returns a binary string representation of the reaction.

Validate(self, silent: bool = False) tuple[int, int]

checks the reaction for potential problems, returns (numWarnings,numErrors)

exception rdkit.Chem.rdChemReactions.ChemicalReactionException

Bases: ValueError

exception rdkit.Chem.rdChemReactions.ChemicalReactionParserException

Bases: ValueError

class rdkit.Chem.rdChemReactions.EnumerateLibrary

Bases: EnumerateLibraryBase

This class allows easy enumeration of reactions. Simply provide a reaction and a set of reagents and you are off the races.

Note that this functionality should be considered beta and that the API may change in a future release.

EnumerateLibrary follows the python enumerator protocol, for example:

library = EnumerateLibrary(rxn, bbs) for products in library:

… do something with the product

It is useful to sanitize reactions before hand:

SanitizeRxn(rxn) library = EnumerateLibrary(rxn, bbs)

If ChemDraw style reaction semantics are prefereed, you can apply the ChemDraw parameters:

SanitizeRxn(rxn, params=GetChemDrawRxnAdjustParams())

For one, this enforces only matching RGroups and assumes all atoms have fully satisfied valences.

Each product has the same output as applying a set of reagents to the libraries reaction.

This can be a bit confusing as each product can have multiple molecules generated. The returned data structure is as follows:

[ [products1], [products2],… ]

Where products1 are the molecule products for the reactions first product template and products2 are the molecule products for the second product template. Since each reactant can match more than once, there may be multiple product molecules for each template.

for products in library:
for results_for_product_template in products:
for mol in results_for_product_template:

Chem.MolToSmiles(mol) # finally have a molecule!

For sufficiently large libraries, using this iteration strategy is not recommended as the library may contain more products than atoms in the universe. To help with this, you can supply an enumeration strategy. The default strategy is a CartesianProductStrategy which enumerates everything. RandomSampleStrategy randomly samples the products but this strategy never terminates, however, python supplies itertools:

import itertools library = EnumerateLibrary(rxn, bbs, rdChemReactions.RandomSampleStrategy()) for result in itertools.islice(library, 1000):

# do something with the first 1000 samples

for result in itertools.islice(library, 1000):

# do something with the next 1000 samples

Libraries are also serializable, including their current state:

s = library.Serialize() library2 = EnumerateLibrary() library2.InitFromString(s) for result in itertools.islice(libary2, 1000):

# do something with the next 1000 samples

__init__(self) -> None __init__(self, rxn: rdkit.Chem.rdChemReactions.ChemicalReaction, reagents: object, params: rdkit.Chem.rdChemReactions.EnumerationParams = <rdkit.Chem.rdChemReactions.EnumerationParams object at 0x7e0a5193a0b0>) -> None __init__(self, rxn: rdkit.Chem.rdChemReactions.ChemicalReaction, reagents: object, enumerator: rdkit.Chem.rdChemReactions.EnumerationStrategyBase, params: rdkit.Chem.rdChemReactions.EnumerationParams = <rdkit.Chem.rdChemReactions.EnumerationParams object at 0x7e0a519393f0>) -> None

GetReagents(self) list

Return the reagents used in this library. These are the subset of the input reagents that are compatible with the reaction so may be smaller than the input reagent sets.

class rdkit.Chem.rdChemReactions.EnumerateLibraryBase

Bases: object

GetEnumerator(self) rdkit.Chem.rdChemReactions.EnumerationStrategyBase

Returns the enumation strategy for the current library

GetPosition(self) list[int]

Returns the current enumeration position into the reagent vectors, as returned by GetReagents(). They do not necessarily refer to the input reagent sets as they only refer to reagents compatible with the reaction.

GetReaction(self) rdkit.Chem.rdChemReactions.ChemicalReaction

Returns the chemical reaction for this library

GetState(self) str

Returns the current enumeration state (position) of the library. This position can be used to restart the library from a known position

InitFromString(self, data: str) None
InitFromString(self, data: bytes) None

Initialize the library from a binary string

ResetState(self) None

Returns the current enumeration state (position) of the library to the start.

Serialize(self) bytes

Serialize the library to a binary string. Note that the position in the library is serialized as well. Care should be taken when serializing. See GetState/SetState for position manipulation.

SetState(self, state: str) None

Sets the enumeration state (position) of the library.

next(self) tuple

Return the next molecule from the enumeration.

nextSmiles(self) list[list[str]]

Return the next smiles string from the enumeration.

class rdkit.Chem.rdChemReactions.EnumerationParams

Bases: object

Controls some aspects of how the enumeration is performed. Options:

reagentMaxMatchCount [ default Infinite ]

This specifies how many times the reactant template can match a reagent.

sanePartialProducts [default false]
If true, forces all products of the reagent plus the product templates

pass chemical sanitization. Note that if the product template itself does not pass sanitization, then none of the products will.

__init__(self) -> None

property reagentMaxMatchCount

(self) -> int

property sanePartialProducts

(self) -> bool

class rdkit.Chem.rdChemReactions.EnumerationStrategyBase

Bases: object

GetNumPermutations(self) int

Returns the total number of results for this enumeration strategy. Note that some strategies are effectively infinite.

GetPosition(self) list[int]

Return the current indices into the arrays of reagents, as returned by GetReagents(). They do not necessarily refer to the input reagent sets as they only refer to reagents compatible with the reaction.

Initialize(self, rxn: rdkit.Chem.rdChemReactions.ChemicalReaction, ob: object) None
Skip(self, skipCount: int) bool

Skip the next Nth results. note: this may be an expensive operation depending on the enumeration strategy used. It is recommended to use the enumerator state to advance to a known position

Type(self) str

Returns the enumeration strategy type as a string.

next(self) list[int]

Return the next indices into the arrays of reagents

class rdkit.Chem.rdChemReactions.EvenSamplePairsStrategy(self)

Bases: EnumerationStrategyBase

Randomly sample Pairs evenly from a collection of building blocks This is a good strategy for choosing a relatively small selection of building blocks from a larger set. As the amount of work needed to retrieve the next evenly sample building block grows with the number of samples, this method performs progressively worse as the number of samples gets larger. See EnumerationStrategyBase for more details.

Stats(self) str

Return the statistics log of the pairs used in the current enumeration.

class rdkit.Chem.rdChemReactions.FingerprintType(*values)

Bases: Enum

AtomPairFP = 1
MorganFP = 3
PatternFP = 5
RDKitFP = 4
TopologicalTorsion = 2
class rdkit.Chem.rdChemReactions.RandomSampleAllBBsStrategy(self)

Bases: EnumerationStrategyBase

RandomSampleAllBBsStrategy randomly samples from the reagent sets with the constraint that all building blocks are samples as early as possible. Note that this strategy never halts and can produce duplicates.

class rdkit.Chem.rdChemReactions.RandomSampleStrategy(self)

Bases: EnumerationStrategyBase

RandomSampleStrategy simply randomly samples from the reagent sets. Note that this strategy never halts and can produce duplicates.

class rdkit.Chem.rdChemReactions.ReactionFingerprintParams(self)
class rdkit.Chem.rdChemReactions.ReactionFingerprintParams(self, includeAgents: bool, bitRatioAgents: float, nonAgentWeight: int, agentWeight: int, fpSize: int, fpType: rdkit.Chem.rdChemReactions.FingerprintType)

Bases: object

A class for storing parameters to manipulate the calculation of fingerprints of chemical reactions.

Overloaded function.

  1. __init__(self) -> None

Constructor, takes no arguments

  1. __init__(self, includeAgents: bool, bitRatioAgents: float, nonAgentWeight: int, agentWeight: int, fpSize: int, fpType: rdkit.Chem.rdChemReactions.FingerprintType) -> None

property agentWeight

(self) -> int

property bitRatioAgents

(self) -> float

property fpSize

(self) -> int

property fpType

(self) -> rdkit.Chem.rdChemReactions.FingerprintType

property includeAgents

(self) -> bool

property nonAgentWeight

(self) -> int

class rdkit.Chem.rdChemReactions.SanitizeFlags(*values)

Bases: Enum

SANITIZE_ADJUST_REACTANTS = 4
SANITIZE_ALL = 4294967295
SANITIZE_ATOM_MAPS = 2
SANITIZE_MERGEHS = 8
SANITIZE_NONE = 0
SANITIZE_RGROUP_NAMES = 1