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

Support for atom placeholders (as asterisks) in reaction SMILES #57

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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
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)
Loading