rxnmapper 0.4.0__tar.gz → 0.4.2__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.4.0/rxnmapper.egg-info → rxnmapper-0.4.2}/PKG-INFO +4 -3
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/pyproject.toml +1 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/__init__.py +1 -1
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/core.py +19 -4
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/tokenization_smiles.py +3 -3
- {rxnmapper-0.4.0 → rxnmapper-0.4.2/rxnmapper.egg-info}/PKG-INFO +4 -3
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper.egg-info/requires.txt +1 -1
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/setup.cfg +1 -1
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/LICENSE +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/MANIFEST.in +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/README.md +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/attention.py +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/batched_mapper.py +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/config.json +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/pytorch_model.bin +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/special_tokens_map.json +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/tokenizer_config.json +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/training_args.bin +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/vocab.txt +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/py.typed +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper/smiles_utils.py +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper.egg-info/SOURCES.txt +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper.egg-info/dependency_links.txt +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper.egg-info/not-zip-safe +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/rxnmapper.egg-info/top_level.txt +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/setup.py +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/tests/__init__.py +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/tests/test_batched_mapper.py +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/tests/test_mapper.py +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/tests/test_smiles_utils.py +0 -0
- {rxnmapper-0.4.0 → rxnmapper-0.4.2}/tests/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: rxnmapper
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Reaction atom-mapping from transformers
|
|
5
5
|
Home-page: https://github.com/rxn4chemistry/rxnmapper
|
|
6
6
|
Author: IBM RXN team
|
|
@@ -24,7 +24,7 @@ License-File: LICENSE
|
|
|
24
24
|
Requires-Dist: pandas>=1.0.3
|
|
25
25
|
Requires-Dist: rxn-chem-utils>=1.0.3
|
|
26
26
|
Requires-Dist: scipy>=1.4.1
|
|
27
|
-
Requires-Dist: torch
|
|
27
|
+
Requires-Dist: torch>=1.5.0
|
|
28
28
|
Requires-Dist: transformers>=4.0.0
|
|
29
29
|
Provides-Extra: dev
|
|
30
30
|
Requires-Dist: black>=22.1.0; extra == "dev"
|
|
@@ -40,6 +40,7 @@ Requires-Dist: types-setuptools>=62.6.0; extra == "dev"
|
|
|
40
40
|
Provides-Extra: rdkit
|
|
41
41
|
Requires-Dist: rdkit-pypi>=2021.3.2; python_version < "3.7" and extra == "rdkit"
|
|
42
42
|
Requires-Dist: rdkit>=2022.3.4; python_version >= "3.7" and extra == "rdkit"
|
|
43
|
+
Dynamic: license-file
|
|
43
44
|
|
|
44
45
|
# Extraction of organic chemistry grammar from unsupervised learning of chemical reactions
|
|
45
46
|
Enable robust atom mapping on valid reaction SMILES. The atom-mapping information was learned by an ALBERT model trained in an unsupervised fashion on a large dataset of chemical reactions.
|
|
@@ -4,6 +4,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
6
|
import os
|
|
7
|
+
from contextlib import contextmanager
|
|
7
8
|
from typing import Any, Dict, Iterator, List, Optional, Tuple
|
|
8
9
|
|
|
9
10
|
import numpy as np
|
|
@@ -28,6 +29,17 @@ _logger = logging.getLogger(__name__)
|
|
|
28
29
|
_logger.addHandler(logging.NullHandler())
|
|
29
30
|
|
|
30
31
|
|
|
32
|
+
@contextmanager
|
|
33
|
+
def suppress_transformers_warnings():
|
|
34
|
+
logger = logging.getLogger("transformers")
|
|
35
|
+
previous_level = logger.level
|
|
36
|
+
logger.setLevel(logging.ERROR)
|
|
37
|
+
try:
|
|
38
|
+
yield
|
|
39
|
+
finally:
|
|
40
|
+
logger.setLevel(previous_level)
|
|
41
|
+
|
|
42
|
+
|
|
31
43
|
class RXNMapper:
|
|
32
44
|
"""Wrap the Transformer model, corresponding tokenizer, and attention scoring algorithms.
|
|
33
45
|
|
|
@@ -136,8 +148,11 @@ class RXNMapper:
|
|
|
136
148
|
f"Reaction SMILES has {max_input_length} tokens, should be at most {max_supported_by_model}."
|
|
137
149
|
)
|
|
138
150
|
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
# suppress warning that suggests setting "attn_implementation"; doing
|
|
152
|
+
# so would break compatibility for old `transformers` versions.
|
|
153
|
+
with suppress_transformers_warnings():
|
|
154
|
+
with torch.no_grad():
|
|
155
|
+
output = self.model(**parsed_input)
|
|
141
156
|
attentions = output[2]
|
|
142
157
|
selected_attns = torch.cat(
|
|
143
158
|
[a.unsqueeze(1) for i, a in enumerate(attentions) if i in use_layers],
|
|
@@ -271,14 +286,14 @@ class RXNMapper:
|
|
|
271
286
|
rxn, output["pxr_mapping_vector"], canonical=canonicalize_rxns
|
|
272
287
|
)
|
|
273
288
|
result = {
|
|
274
|
-
"confidence": np.prod(output["confidences"]),
|
|
289
|
+
"confidence": float(np.prod(output["confidences"])),
|
|
275
290
|
}
|
|
276
291
|
if detailed_output:
|
|
277
292
|
result["pxr_mapping_vector"] = output["pxr_mapping_vector"]
|
|
278
293
|
result["pxr_confidences"] = output["confidences"]
|
|
279
294
|
result["mapping_tuples"] = output["mapping_tuples"]
|
|
280
295
|
result["pxrrxp_attns"] = output["pxrrxp_attns"]
|
|
281
|
-
result["tokensxtokens_attns"] = tokensxtokens_attn
|
|
296
|
+
result["tokensxtokens_attns"] = tokensxtokens_attn # type: ignore[assignment]
|
|
282
297
|
result["tokens"] = just_tokens
|
|
283
298
|
|
|
284
299
|
yield mapped_reaction, result
|
|
@@ -49,7 +49,7 @@ class SmilesTokenizer(BertTokenizer):
|
|
|
49
49
|
self.ids_to_tokens = collections.OrderedDict(
|
|
50
50
|
[(ids, tok) for tok, ids in self.vocab.items()]
|
|
51
51
|
)
|
|
52
|
-
self.basic_tokenizer = BasicSmilesTokenizer()
|
|
52
|
+
self.basic_tokenizer = BasicSmilesTokenizer() # type: ignore[assignment]
|
|
53
53
|
self.init_kwargs["model_max_length"] = self.model_max_length
|
|
54
54
|
|
|
55
55
|
@property
|
|
@@ -60,7 +60,7 @@ class SmilesTokenizer(BertTokenizer):
|
|
|
60
60
|
def vocab_list(self):
|
|
61
61
|
return list(self.vocab.keys())
|
|
62
62
|
|
|
63
|
-
def _tokenize(self, text):
|
|
63
|
+
def _tokenize(self, text): # type: ignore[override]
|
|
64
64
|
split_tokens = [token for token in self.basic_tokenizer.tokenize(text)]
|
|
65
65
|
return split_tokens
|
|
66
66
|
|
|
@@ -120,7 +120,7 @@ class SmilesTokenizer(BertTokenizer):
|
|
|
120
120
|
else:
|
|
121
121
|
return padding + token_ids
|
|
122
122
|
|
|
123
|
-
def save_vocabulary(self, vocab_path):
|
|
123
|
+
def save_vocabulary(self, vocab_path): # type: ignore[override]
|
|
124
124
|
"""Save the tokenizer vocabulary to a file."""
|
|
125
125
|
index = 0
|
|
126
126
|
vocab_file = vocab_path
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: rxnmapper
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Reaction atom-mapping from transformers
|
|
5
5
|
Home-page: https://github.com/rxn4chemistry/rxnmapper
|
|
6
6
|
Author: IBM RXN team
|
|
@@ -24,7 +24,7 @@ License-File: LICENSE
|
|
|
24
24
|
Requires-Dist: pandas>=1.0.3
|
|
25
25
|
Requires-Dist: rxn-chem-utils>=1.0.3
|
|
26
26
|
Requires-Dist: scipy>=1.4.1
|
|
27
|
-
Requires-Dist: torch
|
|
27
|
+
Requires-Dist: torch>=1.5.0
|
|
28
28
|
Requires-Dist: transformers>=4.0.0
|
|
29
29
|
Provides-Extra: dev
|
|
30
30
|
Requires-Dist: black>=22.1.0; extra == "dev"
|
|
@@ -40,6 +40,7 @@ Requires-Dist: types-setuptools>=62.6.0; extra == "dev"
|
|
|
40
40
|
Provides-Extra: rdkit
|
|
41
41
|
Requires-Dist: rdkit-pypi>=2021.3.2; python_version < "3.7" and extra == "rdkit"
|
|
42
42
|
Requires-Dist: rdkit>=2022.3.4; python_version >= "3.7" and extra == "rdkit"
|
|
43
|
+
Dynamic: license-file
|
|
43
44
|
|
|
44
45
|
# Extraction of organic chemistry grammar from unsupervised learning of chemical reactions
|
|
45
46
|
Enable robust atom mapping on valid reaction SMILES. The atom-mapping information was learned by an ALBERT model trained in an unsupervised fashion on a large dataset of chemical reactions.
|
|
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
|