Skip to content

Commit 89df26c

Browse files
authored
Support for atom placeholders (as asterisks) in reaction SMILES (#57)
1 parent c9c2cdf commit 89df26c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

rxnmapper/smiles_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def is_atom(token: str, special_tokens: List[str] = BAD_TOKS) -> bool:
8989
bool: True if atom, False if not
9090
"""
9191
bad_toks = set(special_tokens)
92-
normal_atom = token[0].isalpha() or token[0] == "["
92+
normal_atom = token[0].isalpha() or token[0] == "[" or "*" in token
9393
is_bad = token in bad_toks
9494
return (not is_bad) and normal_atom
9595

tests/test_mapper.py

+16
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,19 @@ def test_reaction_with_dative_bond(rxn_mapper: RXNMapper):
121121

122122
results = rxn_mapper.get_attention_guided_atom_maps(rxns, canonicalize_rxns=False)
123123
assert_correct_maps(results, expected)
124+
125+
126+
def test_reaction_with_asterisks(rxn_mapper: RXNMapper):
127+
# Some reaction SMILES contains asterisks as atom placeholders
128+
# especially if some of the asterisks were inside brackets.
129+
rxns = ["[1*]C=C.O>>*CCO"]
130+
131+
expected = [
132+
{
133+
"mapped_rxn": "[1*:1][CH:2]=[CH2:3].[OH2:4]>>[*:1][CH2:2][CH2:3][OH:4]",
134+
"confidence": 0.9988284870307568,
135+
}
136+
]
137+
138+
results = rxn_mapper.get_attention_guided_atom_maps(rxns, canonicalize_rxns=False)
139+
assert_correct_maps(results, expected)

0 commit comments

Comments
 (0)