Skip to content

Commit

Permalink
Support for atom placeholders (as asterisks) in reaction SMILES (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
avaucher authored Sep 19, 2024
1 parent c9c2cdf commit 89df26c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rxnmapper/smiles_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def is_atom(token: str, special_tokens: List[str] = BAD_TOKS) -> bool:
bool: True if atom, False if not
"""
bad_toks = set(special_tokens)
normal_atom = token[0].isalpha() or token[0] == "["
normal_atom = token[0].isalpha() or token[0] == "[" or "*" in token
is_bad = token in bad_toks
return (not is_bad) and normal_atom

Expand Down
16 changes: 16 additions & 0 deletions tests/test_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,19 @@ def test_reaction_with_dative_bond(rxn_mapper: RXNMapper):

results = rxn_mapper.get_attention_guided_atom_maps(rxns, canonicalize_rxns=False)
assert_correct_maps(results, expected)


def test_reaction_with_asterisks(rxn_mapper: RXNMapper):
# Some reaction SMILES contains asterisks as atom placeholders
# especially if some of the asterisks were inside brackets.
rxns = ["[1*]C=C.O>>*CCO"]

expected = [
{
"mapped_rxn": "[1*:1][CH:2]=[CH2:3].[OH2:4]>>[*:1][CH2:2][CH2:3][OH:4]",
"confidence": 0.9988284870307568,
}
]

results = rxn_mapper.get_attention_guided_atom_maps(rxns, canonicalize_rxns=False)
assert_correct_maps(results, expected)

0 comments on commit 89df26c

Please sign in to comment.