# Extraction of organic chemistry grammar from unsupervised learning of chemical reactions
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.
- [Extraction of organic chemistry grammar from unsupervised learning of chemical reactions](https://advances.sciencemag.org/content/7/15/eabe4166): peer-reviewed Science Advances publication (open access).
- [Demo](http://rxnmapper.ai/demo.html): give RXNMapper a try!
- [Unsupervised attention-guided atom-mapping preprint](http://dx.doi.org/10.26434/chemrxiv.12298559): presented at the ML Interpretability for Scientific Discovery ICML workshop, 2020.
## Installation
### From pip
```console
conda create -n rxnmapper python=3.6 -y
conda activate rxnmapper
pip install rxnmapper
```
### From github
You can install the package and setup the environment directly from github using:
```console
git clone https://github.com/rxn4chemistry/rxnmapper.git
cd rxnmapper
conda create -n rxnmapper python=3.6 -y
conda activate rxnmapper
pip install -e .
```
### RDkit
In both installation settings above, the `RDKit` dependency is not installed automatically, unless you include the extra when installing: `pip install "rxmapper[rdkit]"`.
It can also be installed via Conda or Pypi:
```bash
# Install RDKit from Conda
conda install -c conda-forge rdkit
# Install RDKit from Pypi
pip install rdkit
# for Python<3.7
# pip install rdkit-pypi
```
## Usage
### Basic usage
```python
from rxnmapper import RXNMapper
rxn_mapper = RXNMapper()
rxns = ['CC(C)S.CN(C)C=O.Fc1cccnc1F.O=C([O-])[O-].[K+].[K+]>>CC(C)Sc1ncccc1F', 'C1COCCO1.CC(C)(C)OC(=O)CONC(=O)NCc1cccc2ccccc12.Cl>>O=C(O)CONC(=O)NCc1cccc2ccccc12']
results = rxn_mapper.get_attention_guided_atom_maps(rxns)
```
The results contain the mapped reactions and confidence scores:
```python
[{'mapped_rxn': 'CN(C)C=O.F[c:5]1[n:6][cH:7][cH:8][cH:9][c:10]1[F:11].O=C([O-])[O-].[CH3:1][CH:2]([CH3:3])[SH:4].[K+].[K+]>>[CH3:1][CH:2]([CH3:3])[S:4][c:5]1[n:6][cH:7][cH:8][cH:9][c:10]1[F:11]',
'confidence': 0.9565619900376546},
{'mapped_rxn': 'C1COCCO1.CC(C)(C)[O:3][C:2](=[O:1])[CH2:4][O:5][NH:6][C:7](=[O:8])[NH:9][CH2:10][c:11]1[cH:12][cH:13][cH:14][c:15]2[cH:16][cH:17][cH:18][cH:19][c:20]12.Cl>>[O:1]=[C:2]([OH:3])[CH2:4][O:5][NH:6][C:7](=[O:8])[NH:9][CH2:10][c:11]1[cH:12][cH:13][cH:14][c:15]2[cH:16][cH:17][cH:18][cH:19][c:20]12',
'confidence': 0.9704424331552834}]
```
To account for batching and error handling automatically, you can use `BatchedMapper` instead:
```python
from rxnmapper import BatchedMapper
rxn_mapper = BatchedMapper(batch_size=32)
rxns = ['CC[O-]~[Na+].BrCC>>CCOCC', 'invalid>>reaction']
# The following calls work with input of arbitrary size. Also, they do not raise
# any exceptions but will return ">>" or an empty dictionary for the second reaction.
results = list(rxn_mapper.map_reactions(rxns)) # results as strings directly
results = list(rxn_mapper.map_reactions_with_info(rxns)) # results as dictionaries (as above)
```
### Testing
You can run the examples above with the test suite as well:
1. In your Conda environment: `pip install -e .[dev]`
2. `pytest tests` from the root
## Examples
To learn more see the [examples](./examples).
## Data
Data can be found at: https://ibm.box.com/v/RXNMapperData
## Citation
```
@article{schwaller2021extraction,
title={Extraction of organic chemistry grammar from unsupervised learning of chemical reactions},
author={Schwaller, Philippe and Hoover, Benjamin and Reymond, Jean-Louis and Strobelt, Hendrik and Laino, Teodoro},
journal={Science Advances},
volume={7},
number={15},
pages={eabe4166},
year={2021},
publisher={American Association for the Advancement of Science}
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/rxn4chemistry/rxnmapper",
"name": "rxnmapper",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "IBM RXN team",
"author_email": "rxn4chemistry@zurich.ibm.com",
"download_url": "https://files.pythonhosted.org/packages/ba/43/4e6c444c9ad7c14b782df6cb22e5c88880707a06973706ca1ecf5e425337/rxnmapper-0.4.0.tar.gz",
"platform": null,
"description": "# Extraction of organic chemistry grammar from unsupervised learning of chemical reactions\nEnable 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.\n\n- [Extraction of organic chemistry grammar from unsupervised learning of chemical reactions](https://advances.sciencemag.org/content/7/15/eabe4166): peer-reviewed Science Advances publication (open access).\n- [Demo](http://rxnmapper.ai/demo.html): give RXNMapper a try! \n- [Unsupervised attention-guided atom-mapping preprint](http://dx.doi.org/10.26434/chemrxiv.12298559): presented at the ML Interpretability for Scientific Discovery ICML workshop, 2020.\n\n## Installation\n\n### From pip\n```console\nconda create -n rxnmapper python=3.6 -y\nconda activate rxnmapper\npip install rxnmapper\n```\n\n### From github\nYou can install the package and setup the environment directly from github using:\n\n```console\ngit clone https://github.com/rxn4chemistry/rxnmapper.git \ncd rxnmapper\nconda create -n rxnmapper python=3.6 -y\nconda activate rxnmapper\npip install -e .\n```\n\n### RDkit\n\nIn both installation settings above, the `RDKit` dependency is not installed automatically, unless you include the extra when installing: `pip install \"rxmapper[rdkit]\"`.\nIt can also be installed via Conda or Pypi:\n\n```bash\n# Install RDKit from Conda\nconda install -c conda-forge rdkit\n\n# Install RDKit from Pypi\npip install rdkit\n# for Python<3.7\n# pip install rdkit-pypi\n```\n\n## Usage\n\n### Basic usage\n\n```python\nfrom rxnmapper import RXNMapper\nrxn_mapper = RXNMapper()\nrxns = ['CC(C)S.CN(C)C=O.Fc1cccnc1F.O=C([O-])[O-].[K+].[K+]>>CC(C)Sc1ncccc1F', 'C1COCCO1.CC(C)(C)OC(=O)CONC(=O)NCc1cccc2ccccc12.Cl>>O=C(O)CONC(=O)NCc1cccc2ccccc12']\nresults = rxn_mapper.get_attention_guided_atom_maps(rxns)\n```\n\nThe results contain the mapped reactions and confidence scores:\n\n```python\n[{'mapped_rxn': 'CN(C)C=O.F[c:5]1[n:6][cH:7][cH:8][cH:9][c:10]1[F:11].O=C([O-])[O-].[CH3:1][CH:2]([CH3:3])[SH:4].[K+].[K+]>>[CH3:1][CH:2]([CH3:3])[S:4][c:5]1[n:6][cH:7][cH:8][cH:9][c:10]1[F:11]',\n 'confidence': 0.9565619900376546},\n {'mapped_rxn': 'C1COCCO1.CC(C)(C)[O:3][C:2](=[O:1])[CH2:4][O:5][NH:6][C:7](=[O:8])[NH:9][CH2:10][c:11]1[cH:12][cH:13][cH:14][c:15]2[cH:16][cH:17][cH:18][cH:19][c:20]12.Cl>>[O:1]=[C:2]([OH:3])[CH2:4][O:5][NH:6][C:7](=[O:8])[NH:9][CH2:10][c:11]1[cH:12][cH:13][cH:14][c:15]2[cH:16][cH:17][cH:18][cH:19][c:20]12',\n 'confidence': 0.9704424331552834}]\n```\n\nTo account for batching and error handling automatically, you can use `BatchedMapper` instead:\n```python\nfrom rxnmapper import BatchedMapper\nrxn_mapper = BatchedMapper(batch_size=32)\nrxns = ['CC[O-]~[Na+].BrCC>>CCOCC', 'invalid>>reaction']\n\n# The following calls work with input of arbitrary size. Also, they do not raise \n# any exceptions but will return \">>\" or an empty dictionary for the second reaction.\nresults = list(rxn_mapper.map_reactions(rxns)) # results as strings directly\nresults = list(rxn_mapper.map_reactions_with_info(rxns)) # results as dictionaries (as above)\n```\n\n### Testing\n\nYou can run the examples above with the test suite as well:\n\n1. In your Conda environment: `pip install -e .[dev]`\n2. `pytest tests` from the root \n\n## Examples\n\nTo learn more see the [examples](./examples).\n\n## Data \n\nData can be found at: https://ibm.box.com/v/RXNMapperData\n\n## Citation\n\n```\n@article{schwaller2021extraction,\n title={Extraction of organic chemistry grammar from unsupervised learning of chemical reactions},\n author={Schwaller, Philippe and Hoover, Benjamin and Reymond, Jean-Louis and Strobelt, Hendrik and Laino, Teodoro},\n journal={Science Advances},\n volume={7},\n number={15},\n pages={eabe4166},\n year={2021},\n publisher={American Association for the Advancement of Science}\n}\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Reaction atom-mapping from transformers",
"version": "0.4.0",
"project_urls": {
"Homepage": "https://github.com/rxn4chemistry/rxnmapper"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b68df5fe0beac8ffcff26f0e513cc74b3b298df54b6100f7a0f53cba46ed81c7",
"md5": "e6e1a7f915dc274c3c9090366d6d0bd9",
"sha256": "f7f7af125051d3db500ef330bc0d75fe1f92931f18aa625d96a23e8cc8c13c1f"
},
"downloads": -1,
"filename": "rxnmapper-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e6e1a7f915dc274c3c9090366d6d0bd9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 3007297,
"upload_time": "2024-09-19T20:41:25",
"upload_time_iso_8601": "2024-09-19T20:41:25.404909Z",
"url": "https://files.pythonhosted.org/packages/b6/8d/f5fe0beac8ffcff26f0e513cc74b3b298df54b6100f7a0f53cba46ed81c7/rxnmapper-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ba434e6c444c9ad7c14b782df6cb22e5c88880707a06973706ca1ecf5e425337",
"md5": "1f5046195a43be42c56459c7f48c023a",
"sha256": "2ea81c3ae2fc5a81dcd875a3af4e5e79d38ea48c9b0d7484c3eddc130d194d76"
},
"downloads": -1,
"filename": "rxnmapper-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "1f5046195a43be42c56459c7f48c023a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 3007132,
"upload_time": "2024-09-19T20:41:28",
"upload_time_iso_8601": "2024-09-19T20:41:28.098703Z",
"url": "https://files.pythonhosted.org/packages/ba/43/4e6c444c9ad7c14b782df6cb22e5c88880707a06973706ca1ecf5e425337/rxnmapper-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-19 20:41:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "rxn4chemistry",
"github_project": "rxnmapper",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "rxnmapper"
}