rxnmapper 0.2.9__tar.gz → 0.3.1__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.2.9/rxnmapper.egg-info → rxnmapper-0.3.1}/PKG-INFO +20 -3
  2. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/__init__.py +2 -1
  3. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/attention.py +1 -0
  4. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/batched_mapper.py +35 -2
  5. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/core.py +1 -0
  6. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/smiles_utils.py +6 -5
  7. {rxnmapper-0.2.9 → rxnmapper-0.3.1/rxnmapper.egg-info}/PKG-INFO +20 -3
  8. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper.egg-info/requires.txt +1 -1
  9. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/setup.cfg +2 -2
  10. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/tests/test_mapper.py +13 -0
  11. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/LICENSE +0 -0
  12. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/MANIFEST.in +0 -0
  13. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/README.md +0 -0
  14. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/pyproject.toml +0 -0
  15. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/config.json +0 -0
  16. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/pytorch_model.bin +0 -0
  17. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/special_tokens_map.json +0 -0
  18. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/tokenizer_config.json +0 -0
  19. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/training_args.bin +0 -0
  20. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/models/transformers/albert_heads_8_uspto_all_1310k/vocab.txt +0 -0
  21. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/py.typed +0 -0
  22. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper/tokenization_smiles.py +0 -0
  23. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper.egg-info/SOURCES.txt +0 -0
  24. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper.egg-info/dependency_links.txt +0 -0
  25. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper.egg-info/not-zip-safe +0 -0
  26. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/rxnmapper.egg-info/top_level.txt +0 -0
  27. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/setup.py +0 -0
  28. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/tests/__init__.py +0 -0
  29. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/tests/test_batched_mapper.py +0 -0
  30. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/tests/test_smiles_utils.py +0 -0
  31. {rxnmapper-0.2.9 → rxnmapper-0.3.1}/tests/utils.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rxnmapper
3
- Version: 0.2.9
4
- Summary: Reaction atom-mapping from transfomers
3
+ Version: 0.3.1
4
+ Summary: Reaction atom-mapping from transformers
5
5
  Home-page: https://github.com/rxn4chemistry/rxnmapper
6
6
  Author: IBM RXN team
7
7
  Author-email: rxn4chemistry@zurich.ibm.com
@@ -20,9 +20,26 @@ Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
21
  Requires-Python: >=3.6
22
22
  Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: pandas>=1.0.3
25
+ Requires-Dist: rxn-chem-utils>=1.0.3
26
+ Requires-Dist: scipy>=1.4.1
27
+ Requires-Dist: torch<2.5,>=1.5.0
28
+ Requires-Dist: transformers>=4.0.0
23
29
  Provides-Extra: dev
30
+ Requires-Dist: black>=22.1.0; extra == "dev"
31
+ Requires-Dist: bump2version>=1.0.1; extra == "dev"
32
+ Requires-Dist: flake8>=3.7.9; extra == "dev"
33
+ Requires-Dist: isort>=5.10.0; extra == "dev"
34
+ Requires-Dist: mypy>=0.910; extra == "dev"
35
+ Requires-Dist: pytest>=5.4.1; extra == "dev"
36
+ Requires-Dist: sphinx-rtd-theme==0.4.3; extra == "dev"
37
+ Requires-Dist: sphinx==2.2.1; extra == "dev"
38
+ Requires-Dist: twine==3.1.1; extra == "dev"
39
+ Requires-Dist: types-setuptools>=62.6.0; extra == "dev"
24
40
  Provides-Extra: rdkit
25
- License-File: LICENSE
41
+ Requires-Dist: rdkit-pypi>=2021.3.2; python_version < "3.7" and extra == "rdkit"
42
+ Requires-Dist: rdkit>=2022.3.4; python_version >= "3.7" and extra == "rdkit"
26
43
 
27
44
  # Extraction of organic chemistry grammar from unsupervised learning of chemical reactions
28
45
  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.
@@ -1,6 +1,7 @@
1
1
  """rxnmapper initialization."""
2
+
2
3
  __name__ = "rxnmapper"
3
- __version__ = "0.2.9" # managed by bump2version
4
+ __version__ = "0.3.1" # managed by bump2version
4
5
 
5
6
 
6
7
  from .batched_mapper import BatchedMapper
@@ -7,6 +7,7 @@ This module contains all of the helper methods needed to convert the attention m
7
7
  separating on reactants and products, including special tokens and not including special tokens, in the atom
8
8
  domain / in the token domain, and accounting for adjacent atoms in molecules.
9
9
  """
10
+
10
11
  import logging
11
12
  from typing import List, Optional
12
13
 
@@ -1,7 +1,9 @@
1
1
  import logging
2
- from typing import Any, Dict, Iterable, Iterator, List
2
+ from typing import Any, Dict, Iterable, Iterator, List, Optional
3
3
 
4
+ import pkg_resources
4
5
  from rxn.utilities.containers import chunker
6
+ from rxn.utilities.files import PathLike
5
7
 
6
8
  from .core import RXNMapper
7
9
 
@@ -20,10 +22,41 @@ class BatchedMapper:
20
22
  def __init__(
21
23
  self,
22
24
  batch_size: int,
25
+ model_path: Optional[PathLike] = None,
26
+ head: int = 5,
27
+ attention_multiplier: float = 90.0,
28
+ layer: int = 10,
29
+ model_type: str = "albert",
23
30
  canonicalize: bool = False,
24
31
  placeholder_for_invalid: str = ">>",
25
32
  ):
26
- self.mapper = RXNMapper()
33
+ """
34
+ Args:
35
+ batch_size: batch size for inference.
36
+ model_path: path to the model directory, defaults to the model from
37
+ the original publication.
38
+ head: head related to atom mapping in the model. The default is the
39
+ one for the original publication.
40
+ attention_multiplier: attention multiplier, no need to change the default.
41
+ layer: layer, no need to change the default.
42
+ model_type: model type.
43
+ canonicalize: whether to canonicalize before predicting the atom mappings.
44
+ placeholder_for_invalid: placeholder to use in the output when there
45
+ is an issue in the prediction (number of tokens, invalid SMILES, ...).
46
+ """
47
+ if model_path is None:
48
+ model_path = pkg_resources.resource_filename(
49
+ "rxnmapper", "models/transformers/albert_heads_8_uspto_all_1310k"
50
+ )
51
+ self.mapper = RXNMapper(
52
+ config=dict(
53
+ model_path=str(model_path),
54
+ head=head,
55
+ layers=[layer],
56
+ model_type=model_type,
57
+ attention_multiplier=attention_multiplier,
58
+ ),
59
+ )
27
60
  self.batch_size = batch_size
28
61
  self.canonicalize = canonicalize
29
62
  self.placeholder_for_invalid = placeholder_for_invalid
@@ -1,4 +1,5 @@
1
1
  """Core RXN Attention Mapper module."""
2
+
2
3
  from __future__ import absolute_import, division, print_function, unicode_literals
3
4
 
4
5
  import logging
@@ -1,4 +1,5 @@
1
1
  """Contains functions needed to process reaction SMILES and their tokens"""
2
+
2
3
  from __future__ import absolute_import, division, print_function, unicode_literals
3
4
 
4
5
  import logging
@@ -72,7 +73,7 @@ def get_atom_types_smiles(smiles: str) -> List[int]:
72
73
  # If `smiles` is a set of molecules, it may contain a "~".
73
74
  smiles_mol = smiles_to_mol(smiles.replace("~", "."), sanitize=False)
74
75
 
75
- atom_types = [atom.GetAtomicNum() for atom in smiles_mol.GetAtoms()]
76
+ atom_types = [atom.GetAtomicNum() for atom in smiles_mol.GetAtoms()] # type: ignore[call-arg]
76
77
 
77
78
  return atom_types
78
79
 
@@ -315,7 +316,7 @@ def canonicalize_and_atom_map(smi: str, return_equivalent_atoms=False):
315
316
 
316
317
  """
317
318
  mol = smiles_to_mol(smi, sanitize=False)
318
- for atom in mol.GetAtoms():
319
+ for atom in mol.GetAtoms(): # type: ignore[call-arg]
319
320
  if atom.HasProp("molAtomMapNumber"):
320
321
  atom_map = atom.GetAtomMapNum()
321
322
  atom.SetProp("atom_map", str(atom_map))
@@ -329,7 +330,7 @@ def canonicalize_and_atom_map(smi: str, return_equivalent_atoms=False):
329
330
  ]
330
331
  )
331
332
 
332
- atom_maps_canonical = [mol.GetAtoms()[idx].GetProp("atom_map") for idx in order]
333
+ atom_maps_canonical = [mol.GetAtoms()[idx].GetProp("atom_map") for idx in order] # type: ignore[call-arg]
333
334
 
334
335
  if not return_equivalent_atoms:
335
336
  return (can_smi, atom_maps_canonical)
@@ -366,7 +367,7 @@ def generate_atom_mapped_reaction_atoms(
366
367
  i = -1
367
368
  atom_mapped_precursors_list = []
368
369
  for precursor_mol in precursors_mols:
369
- for atom in precursor_mol.GetAtoms():
370
+ for atom in precursor_mol.GetAtoms(): # type: ignore[call-arg]
370
371
  i += 1
371
372
  if i in product_atom_maps:
372
373
  # atom maps start at an index of 1
@@ -394,7 +395,7 @@ def generate_atom_mapped_reaction_atoms(
394
395
  i = -1
395
396
  atom_mapped_products_list = []
396
397
  for products_mol in products_mols:
397
- for atom in products_mol.GetAtoms():
398
+ for atom in products_mol.GetAtoms(): # type: ignore[call-arg]
398
399
  i += 1
399
400
  atom_map = product_mapping_dict.get(i, i + 1)
400
401
  atom.SetProp("molAtomMapNumber", str(atom_map))
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rxnmapper
3
- Version: 0.2.9
4
- Summary: Reaction atom-mapping from transfomers
3
+ Version: 0.3.1
4
+ Summary: Reaction atom-mapping from transformers
5
5
  Home-page: https://github.com/rxn4chemistry/rxnmapper
6
6
  Author: IBM RXN team
7
7
  Author-email: rxn4chemistry@zurich.ibm.com
@@ -20,9 +20,26 @@ Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
21
  Requires-Python: >=3.6
22
22
  Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: pandas>=1.0.3
25
+ Requires-Dist: rxn-chem-utils>=1.0.3
26
+ Requires-Dist: scipy>=1.4.1
27
+ Requires-Dist: torch<2.5,>=1.5.0
28
+ Requires-Dist: transformers>=4.0.0
23
29
  Provides-Extra: dev
30
+ Requires-Dist: black>=22.1.0; extra == "dev"
31
+ Requires-Dist: bump2version>=1.0.1; extra == "dev"
32
+ Requires-Dist: flake8>=3.7.9; extra == "dev"
33
+ Requires-Dist: isort>=5.10.0; extra == "dev"
34
+ Requires-Dist: mypy>=0.910; extra == "dev"
35
+ Requires-Dist: pytest>=5.4.1; extra == "dev"
36
+ Requires-Dist: sphinx-rtd-theme==0.4.3; extra == "dev"
37
+ Requires-Dist: sphinx==2.2.1; extra == "dev"
38
+ Requires-Dist: twine==3.1.1; extra == "dev"
39
+ Requires-Dist: types-setuptools>=62.6.0; extra == "dev"
24
40
  Provides-Extra: rdkit
25
- License-File: LICENSE
41
+ Requires-Dist: rdkit-pypi>=2021.3.2; python_version < "3.7" and extra == "rdkit"
42
+ Requires-Dist: rdkit>=2022.3.4; python_version >= "3.7" and extra == "rdkit"
26
43
 
27
44
  # Extraction of organic chemistry grammar from unsupervised learning of chemical reactions
28
45
  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.
@@ -1,7 +1,7 @@
1
1
  pandas>=1.0.3
2
2
  rxn-chem-utils>=1.0.3
3
3
  scipy>=1.4.1
4
- torch<2.1,>=1.5.0
4
+ torch<2.5,>=1.5.0
5
5
  transformers>=4.0.0
6
6
 
7
7
  [dev]
@@ -1,7 +1,7 @@
1
1
  [metadata]
2
2
  name = rxnmapper
3
3
  version = attr: rxnmapper.__version__
4
- description = Reaction atom-mapping from transfomers
4
+ description = Reaction atom-mapping from transformers
5
5
  author = IBM RXN team
6
6
  author_email = rxn4chemistry@zurich.ibm.com
7
7
  license = MIT
@@ -31,7 +31,7 @@ install_requires =
31
31
  pandas>=1.0.3
32
32
  rxn-chem-utils>=1.0.3
33
33
  scipy>=1.4.1
34
- torch>=1.5.0,<2.1
34
+ torch>=1.5.0,<2.5
35
35
  transformers>=4.0.0
36
36
 
37
37
  [options.package_data]
@@ -108,3 +108,16 @@ def test_multiple_products(rxn_mapper: RXNMapper):
108
108
 
109
109
  results = rxn_mapper.get_attention_guided_atom_maps(rxns)
110
110
  assert_correct_maps(results, expected)
111
+
112
+
113
+ def test_reaction_with_dative_bond(rxn_mapper: RXNMapper):
114
+ rxns = ["COC(=O)CCBr.O=C[O-]->[K+]>>COC(=O)CCOC(=O)C"]
115
+ expected = [
116
+ {
117
+ "mapped_rxn": "[CH3:1][O:2][C:3](=[O:4])[CH2:5][CH2:6]Br.[O:9]=[CH:8][O-:7]->[K+]>>[CH3:1][O:2][C:3](=[O:4])[CH2:5][CH2:6][O:7][C:8](=[O:9])[CH3:10]",
118
+ "confidence": 0.9322116305783666,
119
+ }
120
+ ]
121
+
122
+ results = rxn_mapper.get_attention_guided_atom_maps(rxns, canonicalize_rxns=False)
123
+ assert_correct_maps(results, expected)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes