datamol.reactions
¶
Working with chemical reactions¶
apply_reaction(rxn, mol, react_pos, single_output=False)
¶
Apply a chemical reaction on a molecule
Source code in datamol/reactions/_reactions.py
@singledispatch
def apply_reaction(rxn, mol, react_pos, single_output=False):
"""Apply a chemical reaction on a molecule"""
raise ValueError
can_react(rxn, mol)
¶
Check if a molecule is a reactant to a chemical reaction and return position
Source code in datamol/reactions/_reactions.py
@singledispatch
def can_react(rxn, mol):
"""Check if a molecule is a reactant to a chemical reaction and return position"""
raise ValueError
compute_reaction_product(out, single_output=True)
¶
Compute the product of a reaction
Source code in datamol/reactions/_reactions.py
def compute_reaction_product(out, single_output=True):
"""Compute the product of a reaction"""
out = [dm.fix_mol(x[0], n_iter=0) for x in out]
if not single_output:
return [dm.sanitize_mol(x) for x in out]
# Might be a important to make a tradeoff decision in selecting products for greater speed.
# product = sorted(out, key=lambda x: MoleculeEnv.compute_reward_from_mol(x, True))[-1]
# sampling from list of products is an alternative
return dm.sanitize_first(np.random.permutation(out))
inverse_reaction(rxn)
¶
Get the reverse reaction of the input reaction
Source code in datamol/reactions/_reactions.py
def inverse_reaction(rxn):
"""Get the reverse reaction of the input reaction"""
rxn2 = AllChem.ChemicalReaction()
for i in range(rxn.GetNumReactantTemplates()):
rxn2.AddProductTemplate(rxn.GetReactantTemplate(i))
for i in range(rxn.GetNumProductTemplates()):
rxn2.AddReactantTemplate(rxn.GetProductTemplate(i))
rxn2.Initialize()
return rxn2
is_reaction_ok(rxn)
¶
Check is the reaction is synthetically valid
Source code in datamol/reactions/_reactions.py
def is_reaction_ok(rxn):
"""Check is the reaction is synthetically valid"""
return rdChemReactions.SanitizeRxn(rxn) == rdChemReactions.SanitizeFlags.SANITIZE_NONE