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

Fix wildcart (*) uses in SMILES #33

Open
wants to merge 2 commits 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
8 changes: 7 additions & 1 deletion safe/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,13 @@ def encoder(
val = str(starting_num) if starting_num < 10 else f"%{starting_num}"
# we cannot have anything of the form "\([@=-#-$/\]*\d+\)"
attach_regexp = re.compile(r"(" + re.escape(attach) + r")")
scaffold_str = attach_regexp.sub(val, scaffold_str)
# check if we have at least 2 matches, if not, we have a dummy
n_matches = len(attach_regexp.findall(scaffold_str))
scaffold_str = (
attach_regexp.sub(val, scaffold_str)
if n_matches > 1
else scaffold_str.replace(attach, "*")
)
starting_num += 1
# now we need to remove all the parenthesis around digit only number
wrong_attach = re.compile(r"\(([\%\d]*)\)")
Expand Down
1 change: 1 addition & 0 deletions tests/test_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def test_rdkit_smiles_parser_issues():
"c1cc2c(cc1[C@@H]1CCC[NH2+]1)OCCO2",
"[13C]1CCCCC1C[238U]C[NH3+]",
"COC[CH2:1][CH2:2]O[CH:2]C[OH:3]",
"C1*CCC1COO",
],
)
def test_bracket_smiles_issues(input_sm):
Expand Down
Loading