-
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.
Adding code for route comparison, RetroBLEU and TED
- Loading branch information
Showing
38 changed files
with
3,284 additions
and
196 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
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
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 pandas as pd | ||
import numpy as np | ||
|
||
|
||
@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.