rxnmapper 0.3.1__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {rxnmapper-0.3.1/rxnmapper.egg-info → rxnmapper-0.4.0}/PKG-INFO +1 -1
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/__init__.py +1 -1
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/core.py +8 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/smiles_utils.py +1 -1
- {rxnmapper-0.3.1 → rxnmapper-0.4.0/rxnmapper.egg-info}/PKG-INFO +1 -1
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/test_mapper.py +28 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/LICENSE +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/MANIFEST.in +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/README.md +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/pyproject.toml +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/attention.py +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/batched_mapper.py +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/config.json +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/pytorch_model.bin +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/special_tokens_map.json +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/tokenizer_config.json +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/training_args.bin +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/vocab.txt +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/py.typed +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/tokenization_smiles.py +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/SOURCES.txt +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/dependency_links.txt +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/not-zip-safe +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/requires.txt +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/top_level.txt +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/setup.cfg +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/setup.py +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/__init__.py +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/test_batched_mapper.py +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/test_smiles_utils.py +0 -0
- {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/utils.py +0 -0
|
@@ -128,6 +128,14 @@ class RXNMapper:
|
|
|
128
128
|
return_tensors="pt",
|
|
129
129
|
)
|
|
130
130
|
parsed_input = {k: v.to(self.device) for k, v in encoded_ids.items()}
|
|
131
|
+
|
|
132
|
+
max_input_length = parsed_input["input_ids"].shape[1]
|
|
133
|
+
max_supported_by_model = self.model.config.max_position_embeddings
|
|
134
|
+
if max_input_length > max_supported_by_model:
|
|
135
|
+
raise ValueError(
|
|
136
|
+
f"Reaction SMILES has {max_input_length} tokens, should be at most {max_supported_by_model}."
|
|
137
|
+
)
|
|
138
|
+
|
|
131
139
|
with torch.no_grad():
|
|
132
140
|
output = self.model(**parsed_input)
|
|
133
141
|
attentions = output[2]
|
|
@@ -89,7 +89,7 @@ def is_atom(token: str, special_tokens: List[str] = BAD_TOKS) -> bool:
|
|
|
89
89
|
bool: True if atom, False if not
|
|
90
90
|
"""
|
|
91
91
|
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
|
|
93
93
|
is_bad = token in bad_toks
|
|
94
94
|
return (not is_bad) and normal_atom
|
|
95
95
|
|
|
@@ -121,3 +121,31 @@ def test_reaction_with_dative_bond(rxn_mapper: RXNMapper):
|
|
|
121
121
|
|
|
122
122
|
results = rxn_mapper.get_attention_guided_atom_maps(rxns, canonicalize_rxns=False)
|
|
123
123
|
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)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_too_long_reaction_smiles_produce_exception_with_understandable_error_message(
|
|
143
|
+
rxn_mapper: RXNMapper,
|
|
144
|
+
):
|
|
145
|
+
# dummy reaction with 1 + 3 + 500 * 2 + 3 + 1 = 1008 tokens
|
|
146
|
+
rxn = "C=C" + "[C+][C-]" * 500 + ">>CC"
|
|
147
|
+
|
|
148
|
+
with pytest.raises(ValueError) as excinfo:
|
|
149
|
+
_ = rxn_mapper.get_attention_guided_atom_maps([rxn], canonicalize_rxns=False)
|
|
150
|
+
|
|
151
|
+
assert "Reaction SMILES has 1008 tokens, should be" in str(excinfo.value)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|