-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from MolecularAI/route-comp-updates
Route comparison and scoring updates
- Loading branch information
Showing
53 changed files
with
3,503 additions
and
425 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "reaction_utils" | ||
version = "1.6.0" | ||
version = "1.7.0" | ||
description = "Utilities for working with reactions, reaction templates and template extraction" | ||
authors = ["Genheden, Samuel <[email protected]>", "Kannas, Christos <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
@@ -28,6 +28,8 @@ numpy = "^1.0.0" | |
rdkit = "^2023.9.1" | ||
cgrtools = "^4.1.35" | ||
scipy = "^1.11.4" | ||
pydantic = "^2.8.2" | ||
apted = "^1.0.3" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "^6.2.2" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" Routines for augmenting chemical reactions | ||
""" | ||
|
||
_SINGLE_REACTANT_REAGENTS = {"10.1.1": "Br", "10.1.2": "Cl"} | ||
|
||
|
||
def single_reactant_augmentation(smiles: str, classification: str) -> str: | ||
""" | ||
Augment single-reactant reaction with additional reagent if possible | ||
based on the classification of the reaction | ||
:param smiles: the reaction SMILES to augment | ||
:param classification: the classification of the reaction or an empty string | ||
:return: the processed SMILES | ||
""" | ||
reactants = smiles.split(">")[0] | ||
if "." in reactants: | ||
return smiles | ||
classification = classification.split(" ")[0] | ||
new_reactant = _SINGLE_REACTANT_REAGENTS.get(classification) | ||
if new_reactant: | ||
return new_reactant + "." + smiles | ||
return smiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Code for curating USPTO yields. | ||
Inspiration from this code: https://github.com/DocMinus/Yield_curation_USPTO | ||
This could potentially be an action, but since it only make sens to use it | ||
with USPTO data, it resides here for now. | ||
""" | ||
|
||
from dataclasses import dataclass | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
@dataclass | ||
class UsptoYieldCuration: | ||
""" | ||
Action for curating USPTO yield columns | ||
""" | ||
|
||
text_yield_column: str = "TextMinedYield" | ||
calc_yield_column: str = "CalculatedYield" | ||
out_column: str = "CuratedYield" | ||
|
||
def __call__(self, data: pd.DataFrame) -> pd.DataFrame: | ||
calc_yield = data[self.calc_yield_column].str.rstrip("%") | ||
calc_yield = pd.to_numeric(calc_yield, errors="coerce") | ||
calc_yield[(calc_yield < 0) | (calc_yield > 100)] = np.nan | ||
|
||
text_yield = data[self.text_yield_column].str.lstrip("~") | ||
text_yield = text_yield.str.rstrip("%") | ||
text_yield = text_yield.str.replace(">=", "", regex=False) | ||
text_yield = text_yield.str.replace(">", "", regex=False) | ||
text_yield = text_yield.str.replace("<", "", regex=False) | ||
text_yield = text_yield.str.replace(r"\d{1,2}\sto\s", "", regex=True) | ||
text_yield = pd.to_numeric(text_yield, errors="coerce") | ||
text_yield[(text_yield < 0) | (text_yield > 100)] = np.nan | ||
|
||
curated_yield = text_yield.copy() | ||
|
||
sel = (~calc_yield.isna()) & (~text_yield.isna()) | ||
curated_yield[sel] = np.maximum(calc_yield[sel], text_yield[sel]) | ||
|
||
sel = (~calc_yield.isna()) & (text_yield.isna()) | ||
curated_yield[sel] = calc_yield[sel] | ||
|
||
return data.assign(**{self.out_column: curated_yield}) | ||
|
||
def __str__(self) -> str: | ||
return f"{self.pretty_name} (create one column with curated yield values)" |
Oops, something went wrong.