polymerist.rdutils.reactions.reactions

Classes for representing information about reaction mechanisms and tracing bonds and atoms along a reaction

Attributes

L

Classes

AnnotatedReaction

RDKit ChemicalReaction subclass with additional useful information about product atom and bond mappings and reaction naming

Functions

map_numbers_to_neighbor_bonds(→ dict[int, ...)

Given an atom, get a mapping from the atom map numbers of explicitly-mapped

Module Contents

polymerist.rdutils.reactions.reactions.L
polymerist.rdutils.reactions.reactions.map_numbers_to_neighbor_bonds(mol: rdkit.Chem.rdchem.Mol, atom_idx: int) dict[int, rdkit.Chem.rdchem.BondType][source]

Given an atom, get a mapping from the atom map numbers of explicitly-mapped neighbor atoms to the bond types of the bonds connecting the atoms

class polymerist.rdutils.reactions.reactions.AnnotatedReaction(*args, **kwargs)[source]

Bases: rdkit.Chem.rdChemReactions.ChemicalReaction

RDKit ChemicalReaction subclass with additional useful information about product atom and bond mappings and reaction naming Initialization must be done either via AnnotatedReaction.from_smarts, AnnotatedReaction.from_rdmols, or AnnotatedReaction.from_rxnfile

RXNNAME_LINE_NO: ClassVar[int] = 1
RXNNAME_RE: ClassVar[re.Pattern]
classmethod from_smarts(rxn_smarts: str) AnnotatedReaction[source]

Instantiate reaction from mapped SMARTS string

to_smarts() str[source]

Export reaction as mapped SMARTS string

property smarts: str

Mapped SMARTS string representation of reaction

to_smiles() str[source]

Export reaction as mapped SMILES string

property smiles: str

Mapped SMILES string representation of reaction

classmethod from_rdmols(reactant_templates: Iterable[rdkit.Chem.rdchem.Mol], product_templates: Iterable[rdkit.Chem.rdchem.Mol], agent_templates: Iterable[rdkit.Chem.rdchem.Mol] | None = None) AnnotatedReaction[source]

For instantiating reactions directly from molecules instead of SMARTS strings

classmethod rxnname_from_rxnfile(rxnfile_path: str | pathlib.Path) str[source]

Extract the reaction name from a (properly-formatted) .RXN file

property rxnname: str

A string handle associated with this reaction

classmethod from_rxnfile(rxnfile_path: str | pathlib.Path) AnnotatedReaction[source]

For instantiating reactions directly from MDL .rxn files

to_rxnfile(rxnfile_path: str | pathlib.Path, wilds_to_R_groups: bool = True) None[source]

Save reaction to an MDL .RXN file. Replaces ports with R-groups to enable proper loading

property mapped_atom_info_by_map_number: dict[int, polymerist.rdutils.reactions.reactinfo.AtomTraceInfo]

Provenance info about the reactant origin and product destination of all mapped atoms, keyed by atom map numbers

property mapped_atom_info: set[polymerist.rdutils.reactions.reactinfo.AtomTraceInfo]

Compile provenance info about the reactant origin and product destination of all mapped atoms

property mapped_atom_info_by_product_idx: dict[str, set[polymerist.rdutils.reactions.reactinfo.AtomTraceInfo]]

Sets of provenance info about the reactant origin and product destination of all mapped atoms grouped by the indices of the products in which they appear

property reactive_atom_info: dict[int, polymerist.rdutils.reactions.reactinfo.AtomTraceInfo]

Compile reactant origin and product destination of all mapped atoms which are changed by the reaction

property mapped_bond_info: set[polymerist.rdutils.reactions.reactinfo.BondTraceInfo]

All provenance info on how bonds between mapped atoms (at least one of which is reactive) change over the reaction

property mapped_bond_info_by_change_type: dict[str | polymerist.rdutils.reactions.reactinfo.BondChange, set[polymerist.rdutils.reactions.reactinfo.BondTraceInfo]]

Mapped bond provenance information, grouped by the types of bond changes each bond experienced

property mapped_bond_info_by_product_idx: dict[str | polymerist.rdutils.reactions.reactinfo.BondChange, set[polymerist.rdutils.reactions.reactinfo.BondTraceInfo]]

Mapped bond provenance information, grouped by the index of the product the bond ends up in

compile_functional_group_inventory(labeled_reactants: dict[L, rdkit.Chem.rdchem.Mol]) polymerist.genutils.sequences.discernment.SymbolInventory[int, L][source]

Construct an inventory of numbers of functional groups (reactant templates) found in an ordered pool of reactant Mols, which can be evaluated as a DISCERNMENT-type problem to determine valid reactant ordering(s), if some exist

Isomorphisms to the DISCERNMENT problem in this instance are as follows:

“symbols” <-> indices of functional groups, as-defined by reactant templates “target word” <-> the sequence of indices [n-1] = [0, 1, …, n-1] where “n” is the number of reactant templates “magazine” <-> an ordered collection of reactant molecules, which may contain any number of functional groups apiece each “word labels” <-> the output of the provided labeling method on the reactant Mol or, if no labeling method is provided, the index of the reactant in the sequence

enumerate_valid_reactant_orderings(reactant_pool: Iterable[rdkit.Chem.rdchem.Mol] | Mapping[L, rdkit.Chem.rdchem.Mol], labeling_method: Callable[[rdkit.Chem.rdchem.Mol], L] | None = None, as_mols: bool = True, allow_resampling: bool = False, deterministic: bool = True) Generator[None | tuple[L] | tuple[rdkit.Chem.rdchem.Mol], None, None][source]

Enumerates all orderings of reactants compatible with the reactant templates defined in this reaction

Yields: * a single NoneType if no such ordering exists * tuples of Chem.Mol objects if as_mols=True * tuples of molecule labels if as_mols=False. Labels can be:

** Indices of molecules in-sequence if labeling_method is not provided ** Any molecule label is labeling_method is provided;

Note that the labels provided must be valid keys for indexing reactant_pool to support as_mols

If allow_resampling=False, each reactant will only be allowed to contribute exactly 1 of its functional groups 1 to any solution

valid_reactant_ordering(reactant_pool: Sequence[rdkit.Chem.rdchem.Mol], as_mols: bool = True, allow_resampling: bool = False, deterministic: bool = True) None | tuple[int] | tuple[rdkit.Chem.rdchem.Mol][source]

Get first ordering of reactants compatible with the reactant templates defined in this reaction

Yields: * a single NoneType if no such ordering exists * a tuple of Chem.Mol objects if as_mols=True * a tuple of indices of reactants in the passed sequence if as_mols=False

If allow_resampling=False, each reactant will only be allowed to contribute exactly 1 of its functional groups 1 to any solution

has_reactable_subset(reactant_pool: Sequence[rdkit.Chem.rdchem.Mol], allow_resampling: bool = False) bool[source]

Determine if a sequence of reactants Mols contains any subset of Mols which are compatible with the reactant templates defined by this reaction If allow_resampling=False, each reactant will only be allowed to contribute exactly 1 of its functional groups 1 to any solution

validate_reactants(reactants: Sequence[rdkit.Chem.rdchem.Mol], allow_resampling: bool = False) None[source]

Check whether a collection of reactant Mols can be reacted with this reaction definition

reactants_are_compatible(reactants: Sequence[rdkit.Chem.rdchem.Mol], allow_resampling: bool = False) bool[source]

Determine whether a collection of reactants can be reacted with this reaction or not

static apply_atom_info_to_product(product: rdkit.Chem.rdchem.Mol, product_atom_infos: Iterable[polymerist.rdutils.reactions.reactinfo.AtomTraceInfo], reactants: Sequence[rdkit.Chem.rdchem.Mol], apply_map_labels: bool = True) None[source]

Transfer props and (if requested) map number information from atoms in reactant Mols to their corresponding atoms in a product Mol Acts in-place on the “product” Mol instance

static apply_bond_info_to_product(product: rdkit.Chem.rdchem.Mol, product_bond_infos: Iterable[polymerist.rdutils.reactions.reactinfo.BondTraceInfo]) None[source]

Mark any changed bonds with bond props and clean up bond type info in places where bonds get modified Acts in-place on the “product” Mol instance

react(reactants: Sequence[rdkit.Chem.rdchem.Mol], repetitions: int = 1, keep_map_labels: bool = True, _suppress_reactant_validation: bool = False) Generator[rdkit.Chem.rdchem.Mol, None, None][source]

Execute reaction over a collection of reactants and generate product molecule(s) Does not require reactants to match the ORDER of the expected reactant templates by default (only to have the correct number of reactants)