Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions rxnutils/routes/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,20 @@ def reaction_dataframe2routes(subdata):
return grouped.apply(reaction_dataframe2routes)


def reactions2route(reactions: Sequence[str], metadata: Sequence[Dict[str, Any]] = None) -> SynthesisRoute:
def reactions2route(
reactions: Sequence[str],
metadata: Sequence[Dict[str, Any]] = None,
ignore_stereo: bool = True,
) -> SynthesisRoute:
"""
Convert a list of reactions into a retrosynthesis tree

This is based on matching partial InChI keys of the reactants in one
reaction with the partial InChI key of a product.

:params reactions: list of reaction SMILES
:params metadata: optional list of metadata dictionaries for each reaction
:params ignore_stereo: whether to ignore stereochemistry when matching reactants and products
:returns: the created trees
"""

Expand All @@ -126,7 +132,7 @@ def make_dict(product_smiles):
"type": "mol",
"smiles": product_smiles,
}
product_inchi = smiles2inchikey(product_smiles, ignore_stereo=True)
product_inchi = smiles2inchikey(product_smiles, ignore_stereo=ignore_stereo)
reaction = product2reaction.get(product_inchi)
if reaction is not None:
metadata = dict(reaction["metadata"])
Expand All @@ -147,14 +153,18 @@ def make_dict(product_smiles):
for reaction, meta in zip(reactions, metadata):
reactants_smiles, _, product_smiles = split_rsmi(reaction)
product_smiles = Chem.CanonSmiles(product_smiles)
partial_product_inchi = smiles2inchikey(product_smiles, ignore_stereo=True)
partial_product_inchi = smiles2inchikey(
Comment thread
SGenheden marked this conversation as resolved.
product_smiles, ignore_stereo=ignore_stereo
)
inchi_map[partial_product_inchi] = product_smiles
reactants = split_smiles_from_reaction(reactants_smiles)
try:
reactants = [Chem.CanonSmiles(smi) for smi in reactants]
except:
raise ValueError(f"Cannot canonicalize SMILES: {reactants_smiles}")
all_reactants = all_reactants.union([smiles2inchikey(smi, ignore_stereo=True) for smi in reactants])
all_reactants = all_reactants.union(
[smiles2inchikey(smi, ignore_stereo=ignore_stereo) for smi in reactants]
)
product2reaction[partial_product_inchi] = {
"smiles": reaction,
"product": product_smiles,
Expand Down