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.
Files changed (31) hide show
  1. {rxnmapper-0.3.1/rxnmapper.egg-info → rxnmapper-0.4.0}/PKG-INFO +1 -1
  2. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/__init__.py +1 -1
  3. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/core.py +8 -0
  4. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/smiles_utils.py +1 -1
  5. {rxnmapper-0.3.1 → rxnmapper-0.4.0/rxnmapper.egg-info}/PKG-INFO +1 -1
  6. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/test_mapper.py +28 -0
  7. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/LICENSE +0 -0
  8. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/MANIFEST.in +0 -0
  9. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/README.md +0 -0
  10. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/pyproject.toml +0 -0
  11. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/attention.py +0 -0
  12. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/batched_mapper.py +0 -0
  13. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/config.json +0 -0
  14. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/pytorch_model.bin +0 -0
  15. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/special_tokens_map.json +0 -0
  16. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/tokenizer_config.json +0 -0
  17. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/training_args.bin +0 -0
  18. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/vocab.txt +0 -0
  19. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/py.typed +0 -0
  20. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper/tokenization_smiles.py +0 -0
  21. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/SOURCES.txt +0 -0
  22. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/dependency_links.txt +0 -0
  23. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/not-zip-safe +0 -0
  24. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/requires.txt +0 -0
  25. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/rxnmapper.egg-info/top_level.txt +0 -0
  26. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/setup.cfg +0 -0
  27. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/setup.py +0 -0
  28. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/__init__.py +0 -0
  29. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/test_batched_mapper.py +0 -0
  30. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/test_smiles_utils.py +0 -0
  31. {rxnmapper-0.3.1 → rxnmapper-0.4.0}/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rxnmapper
3
- Version: 0.3.1
3
+ Version: 0.4.0
4
4
  Summary: Reaction atom-mapping from transformers
5
5
  Home-page: https://github.com/rxn4chemistry/rxnmapper
6
6
  Author: IBM RXN team
@@ -1,7 +1,7 @@
1
1
  """rxnmapper initialization."""
2
2
 
3
3
  __name__ = "rxnmapper"
4
- __version__ = "0.3.1" # managed by bump2version
4
+ __version__ = "0.4.0" # managed by bump2version
5
5
 
6
6
 
7
7
  from .batched_mapper import BatchedMapper
@@ -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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rxnmapper
3
- Version: 0.3.1
3
+ Version: 0.4.0
4
4
  Summary: Reaction atom-mapping from transformers
5
5
  Home-page: https://github.com/rxn4chemistry/rxnmapper
6
6
  Author: IBM RXN team
@@ -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