Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified SMILES regex in data pipeline to disallow three-digit ring numbers. #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 0 additions & 27 deletions reinvent/datapipeline/filters/chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,6 @@ def clean_smiles(self, smiles, config: FilterSection):
else:
raise

# FIXME: an atom may have 3 ring numbers or more e.g.
# C%108%11 which is %10 8 %11 and should become 8%11 %10
# for the tokenizer or be caught in a single regex maybe like
# "\d*(?:%\d+){1,}"
# clean up unwanted halogens here!
if "%" in new_smiles:
smiles_patterns = SMILES_TOKENS_REGEX.findall(new_smiles)
patterns = []

for pattern in smiles_patterns:
# This needs to be done here because RDKit may change
# ring numbering
# Handles labels in the form %NNN or %NNNN
if pattern[0] == "%":
# FIXME: safeguard against multi ring labels for now
if int(pattern[1:]) > config.max_num_rings:
return None

elem_len = len(pattern[1:])

if elem_len == 3:
pattern = f"{pattern[3:]}%{pattern[1:3]}"
elif elem_len == 4:
pattern = f"%{pattern[1:3]}%{pattern[3:]}"

patterns.append(pattern)

new_smiles = "".join(patterns)

return new_smiles
2 changes: 1 addition & 1 deletion reinvent/datapipeline/filters/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# adapted from SmilesPE-0.0.3
SMILES_TOKENS_REGEX = re.compile(
r"(\[[^]]+]|Br?|Cl?|N|O|S|P|F|I|b|c|n|o|s|p|\(|\)|\.|=|#|-|\+|\\|/|:|~|@|\?|>>?|\*|\$|%\d+|\d)"
r"(\[[^]]+]|Br?|Cl?|N|O|S|P|F|I|b|c|n|o|s|p|\(|\)|\.|=|#|-|\+|\\|/|:|~|@|\?|>>?|\*|\$|%\d{2}|\d)"
)
ELEMENT = re.compile(r"[A-Za-z]+")
ISOTOPE = re.compile(r"\[\d+")
Expand Down