LIBRARY¶
In [1]:
Copied!
%%time
from IPython.core.display import HTML
import retropaths.helper_functions as hf
from retropaths.molecules.molecule import Molecule
from ipywidgets import interact
library = hf.pload('../data/reactions.p')
HTML('<script src="//d3js.org/d3.v3.min.js"></script>')
%%time
from IPython.core.display import HTML
import retropaths.helper_functions as hf
from retropaths.molecules.molecule import Molecule
from ipywidgets import interact
library = hf.pload('../data/reactions.p')
HTML('')
CPU times: user 6.29 s, sys: 615 ms, total: 6.9 s Wall time: 7.03 s
Out[1]:
In [2]:
Copied!
library
library
Out[2]:
Library containing 1616 reaction templates.
In [3]:
Copied!
# library['name'].draw() <- this command draws the single Template.
@interact(label=list(library.keys()))
def draw_reaction(label):
global rxn
rxn = library[label]
print(f'Reaction Template: {rxn}')
return rxn.draw(size=(600,600))
# library['name'].draw() <- this command draws the single Template.
@interact(label=list(library.keys()))
def draw_reaction(label):
global rxn
rxn = library[label]
print(f'Reaction Template: {rxn}')
return rxn.draw(size=(600,600))
interactive(children=(Dropdown(description='label', options=('Nucleophilic-Aromatic-Substitution-Lg-Iodine-and…
In [4]:
Copied!
# Show the reactants and products
reac, prod = rxn.reactants, rxn.products
Molecule.draw_list([reac, prod], names=['Reactants', 'Products'])
# Show the reactants and products
reac, prod = rxn.reactants, rxn.products
Molecule.draw_list([reac, prod], names=['Reactants', 'Products'])
Out[4]:
Reactants
Products
In [5]:
Copied!
conditions = rxn.conditions
conditions
conditions = rxn.conditions
conditions
Out[5]:
Acidity basic | Solvent no_water
In [6]:
Copied!
rxn.rules
rxn.rules
Out[6]:
Condition to enforce:
R1 = L-A, A-Aromatic-Carbon
R2 = L-A, A-Aromatic-Carbon
R3 = L-A, A-Aromatic-Carbon
R4 = L-A, A-Aromatic-Carbon
R5 = L-A, A-Aromatic-Carbon
R6 = A-Aliphatic-Carbon, A-Aromatic-Carbon
In [7]:
Copied!
# some properties
print(f'{rxn.side_reaction=}\n{rxn.react_with_itself=}')
# some properties
print(f'{rxn.side_reaction=}\n{rxn.react_with_itself=}')
rxn.side_reaction=False rxn.react_with_itself=False
Template application to a molecule¶
In [8]:
Copied!
from retropaths.reactions.template_utilities import give_me_molecule_with_random_replacement_from_rules
# Given a template, this method will return a molecule that it is subgraph isomorphic to the reactants AND respects the rules
mol = give_me_molecule_with_random_replacement_from_rules(rxn, library.matching)
mol.draw()
from retropaths.reactions.template_utilities import give_me_molecule_with_random_replacement_from_rules
# Given a template, this method will return a molecule that it is subgraph isomorphic to the reactants AND respects the rules
mol = give_me_molecule_with_random_replacement_from_rules(rxn, library.matching)
mol.draw()
Out[8]:
In [9]:
Copied!
# we can apply forward the template to obtain the products. Feel free to pick up another Reaction template!
all_mols = mol + rxn.minor_reactants
results = rxn.apply_forward(all_mols, filter_minor_products=False)
Molecule.draw_list([all_mols] + results, names=[f'Reactants {mol.smiles}']+[f'Product {i}: {x.smiles}' for i, x in enumerate(results)], width=100)
# we can apply forward the template to obtain the products. Feel free to pick up another Reaction template!
all_mols = mol + rxn.minor_reactants
results = rxn.apply_forward(all_mols, filter_minor_products=False)
Molecule.draw_list([all_mols] + results, names=[f'Reactants {mol.smiles}']+[f'Product {i}: {x.smiles}' for i, x in enumerate(results)], width=100)
Out[9]:
Reactants c1ccc(cc1)O.c1ccc(cc1)c2ccc(c(c2)c3ccccc3)I
Product 0: I.c1ccc(cc1)c2ccc(c(c2)c3ccccc3)Oc4ccccc4
Filtering the library¶
In [10]:
Copied!
from retropaths.reactions.conditions import Conditions, Acidity, Solvent
conditions = Conditions(pH=Acidity.acid, solvent=Solvent.water)
new_lib = library.filter_compatible(conditions) # This library is now smaller, with templates that are compatible with conditions.
new_lib
from retropaths.reactions.conditions import Conditions, Acidity, Solvent
conditions = Conditions(pH=Acidity.acid, solvent=Solvent.water)
new_lib = library.filter_compatible(conditions) # This library is now smaller, with templates that are compatible with conditions.
new_lib
Out[10]:
Library containing 50 reaction templates.
In [11]:
Copied!
# we can draw a reaction from this new filtered library to show that is working.
new_lib.sample_one().draw()
# we can draw a reaction from this new filtered library to show that is working.
new_lib.sample_one().draw()
In [ ]:
Copied!
In [ ]:
Copied!
In [ ]:
Copied!