Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Schwaller committed Jul 9, 2020
0 parents commit 3827fdd
Show file tree
Hide file tree
Showing 137 changed files with 79,887 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup conda
uses: s-weigand/setup-conda@v1
with:
update-conda: true
python-version: 3.6
conda-channels: anaconda, tmap, rdkit
- run: conda --version
- run: which python
- name: Install the library
run: |
conda install -c rdkit rdkit -y
conda install -c tmap tmap -y
pip install nbdev jupyter
pip install -e .
- name: Read all notebooks
run: |
nbdev_read_nbs
- name: Check if all notebooks are cleaned
run: |
echo "Check we are starting with clean git checkout"
if [ -n "$(git status -uno -s)" ]; then echo "git status is not clean"; false; fi
echo "Trying to strip out notebooks"
nbdev_clean_nbs
echo "Check that strip out was unnecessary"
git status -s # display the status to see which nbs need cleaning up
if [ -n "$(git status -uno -s)" ]; then echo -e "!!! Detected unstripped out notebooks\n!!!Remember to run nbdev_install_git_hooks"; false; fi
- name: Check if there is no diff library/notebooks
run: |
if [ -n "$(nbdev_diff_nbs)" ]; then echo -e "!!! Detected difference between the notebooks and the library"; false; fi
- name: Run tests
run: |
nbdev_test_nbs
141 changes: 141 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
*.bak
.gitattributes
.last_checked
.gitconfig
*.bak
*.log
*~
~*
_tmp*
tmp*
tags

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.vscode
*.swp

# osx generated files
.DS_Store
.DS_Store?
.Trashes
ehthumbs.db
Thumbs.db
.idea

# pytest
.pytest_cache

# tools/trust-doc-nbs
docs_src/.last_checked

# symlinks to fastai
docs_src/fastai
tools/fastai

# link checker
checklink/cookies.txt

# .gitconfig is now autogenerated
.gitconfig

33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# How to contribute

## How to get started

Before anything else, please install the git hooks that run automatic scripts during each commit and merge to strip the notebooks of superfluous metadata (and avoid merge conflicts). After cloning the repository, run the following command inside it:
```
nbdev_install_git_hooks
```

## Did you find a bug?

* Ensure the bug was not already reported by searching on GitHub under Issues.
* If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring.
* Be sure to add the complete error messages.

#### Did you write a patch that fixes a bug?

* Open a new GitHub pull request with the patch.
* Ensure that your PR includes a test that fails without your patch, and pass with it.
* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.

## PR submission guidelines

* Keep each PR focused. While it's more convenient, do not combine several unrelated fixes together. Create as many branches as needing to keep each PR focused.
* Do not mix style changes/fixes with "functional" changes. It's very difficult to review such PRs and it most likely get rejected.
* Do not add/remove vertical whitespace. Preserve the original style of the file you edit as much as you can.
* Do not turn an already submitted PR into your development playground. If after you submitted PR, you discovered that more work is needed - close the PR, do the required work and then submit a new PR. Otherwise each of your commits requires attention from maintainers of the project.
* If, however, you submitted a PR and received a request for changes, you should proceed with commits inside that PR, so that the maintainer can see the incremental fixes and won't need to review the whole PR again. In the exception case where you realize it'll take many many commits to complete the requests, then it's probably best to close the PR, do the work and then submit it again. Use common sense where you'd choose one way over another.

## Do you want to contribute to the documentation?

* Docs are automatically created from the notebooks in the nbs folder.

7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2020 RXN4Chemistry team / University of Bern

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include settings.ini
include LICENSE
include CONTRIBUTING.md
include README.md
include models/transformers/bert_ft/*
include models/transformers/bert_ft_10k_25s/*
include models/transformers/bert_pretrained/*
recursive-exclude * __pycache__
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
SRC = $(wildcard nbs/*.ipynb)

all: rxnfp docs

rxnfp: $(SRC)
nbdev_build_lib
touch rxnfp

docs_serve: docs
cd docs && bundle exec jekyll serve

docs: $(SRC)
nbdev_build_docs
touch docs

test:
nbdev_test_nbs

release: pypi
nbdev_bump_version

pypi: dist
twine upload --repository pypi dist/*

dist: clean
python setup.py sdist bdist_wheel

clean:
rm -rf dist
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# RXNFP - chemical reaction fingerprints
> This library generates chemical reaction fingerprints from reaction SMILES

## Install


For all installations, we recommend using `conda` to get the necessary `rdkit` and `tmap` dependencies:

### From github
```console
conda create -n rxnfp python=3.6 -y
conda activate rxnfp
conda install -c rdkit rdkit
conda install -c tmap tmap
pip install -e .
```

## How to use

Compute a fingerprint from a reaction SMILES
```python
```

```python
from rxnfp.transformer_fingerprints import (
RXNBERTFingerprintGenerator, get_default_model_and_tokenizer, generate_fingerprints
)

model, tokenizer = get_default_model_and_tokenizer()

rxnfp_generator = RXNBERTFingerprintGenerator(model, tokenizer)

example_rxn = "Nc1cccc2cnccc12.O=C(O)c1cc([N+](=O)[O-])c(Sc2c(Cl)cncc2Cl)s1>>O=C(Nc1cccc2cnccc12)c1cc([N+](=O)[O-])c(Sc2c(Cl)cncc2Cl)s1"

fp = rxnfp_generator.convert(example_rxn)
print(len(fp))
print(fp[:5])
```

256
[-2.0174953937530518, 1.7602033615112305, -1.3323537111282349, -1.1095019578933716, 1.2254549264907837]


Or for a list of reactions:

```python
rxns = [example_rxn, example_rxn]
fps = rxnfp_generator.convert_batch(rxns)
print(len(fps), len(fps[0]))
```

2 256


## Reaction Atlas

### Pistachio
The fingerprints can be used to map the space of chemical reactions:



<div style="text-align: center">
<img src="nbs/images/annotated_atlas.jpg" width="1000">
<p style="text-align: center;"> <b>Figure:</b> Annotated Atlas of the Pistachio test set generated with TMAP (https://tmap.gdb.tools). </p>
</div>


### Schneider 50k set

In the notebooks, we show how to generate an interative reaction atlas for the Schneider 50k set. The end result is similar to this **[interactive Reaction Atlas](./tmaps/tmap_ft_10k.html)**.

Where you will find different reaction properties highlighted in the different layers:

<div style="text-align: center">
<img src="nbs/images/tmap_properties.jpg" width="800">
<p style="text-align: center;"> <b>Figure:</b> Reaction atlas of 50k data set with different properties highlighted. </p>
</div>

## Citation

```
@article{Schwaller2019rxnfp,
author = "Philippe Schwaller and Daniel Probst and Alain C. Vaucher and Vishnu H Nair and Teodoro Laino and Jean-Louis Reymond",
title = "{Data-Driven Chemical Reaction Classification, Fingerprinting and Clustering using Attention-Based Neural Networks}",
year = "2019",
month = "12",
url = "https://chemrxiv.org/articles/preprint/Data-Driven_Chemical_Reaction_Classification_with_Attention-Based_Neural_Networks/9897365",
doi = "10.26434/chemrxiv.9897365.v2"
}
```

RXNFP has been developed in a collaboration between IBM Research Europe and the [Reymond group](http://gdb.unibe.ch) at the University of Bern. The classification models are used on the [RXN for Chemistry](https://rxn.res.ibm.com) platform.
Binary file added data/fps_ft.npz
Binary file not shown.
Binary file added data/fps_ft_10k.npz
Binary file not shown.
Binary file added data/fps_pretrained.npz
Binary file not shown.
1 change: 1 addition & 0 deletions data/rxnclass2id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"1.2.1": 0, "1.2.4": 1, "1.2.5": 2, "1.3.6": 3, "1.3.7": 4, "1.3.8": 5, "1.6.2": 6, "1.6.4": 7, "1.6.8": 8, "1.7.4": 9, "1.7.6": 10, "1.7.7": 11, "1.7.9": 12, "1.8.5": 13, "10.1.1": 14, "10.1.2": 15, "10.1.5": 16, "10.2.1": 17, "10.4.2": 18, "2.1.1": 19, "2.1.2": 20, "2.1.7": 21, "2.2.3": 22, "2.3.1": 23, "2.6.1": 24, "2.6.3": 25, "2.7.2": 26, "3.1.1": 27, "3.1.5": 28, "3.1.6": 29, "3.3.1": 30, "3.4.1": 31, "5.1.1": 32, "6.1.1": 33, "6.1.3": 34, "6.1.5": 35, "6.2.1": 36, "6.2.2": 37, "6.2.3": 38, "6.3.1": 39, "6.3.7": 40, "7.1.1": 41, "7.2.1": 42, "7.3.1": 43, "7.9.2": 44, "8.1.4": 45, "8.1.5": 46, "8.2.1": 47, "9.1.6": 48, "9.3.1": 49}
1 change: 1 addition & 0 deletions data/rxnclass2name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"3.1.1": "Bromo Suzuki coupling", "6.1.5": "N-Bn deprotection", "3.1.6": "Chloro Suzuki-type coupling", "3.1.5": "Bromo Suzuki-type coupling", "6.1.1": "N-Boc deprotection", "9.1.6": "Hydroxy to chloro", "7.2": "Amide to amine reduction", "7.3": "Cyano or imine to amine", "7.1": "Nitro to amine reduction", "6.3": "ROH deprotections", "6.2": "RCO2H deprotections", "6.1": "NH deprotections", "7.9": "Other reductions", "6.1.3": "N-Cbz deprotection", "10.1": "Halogenation", "10.2": "Nitration", "10.4": "Other functional group addition", "1.6.2": "Bromo N-alkylation", "1.6.4": "Chloro N-alkylation", "8": "Oxidations", "1.6.8": "Iodo N-alkylation", "1.7.7": "Mitsunobu aryl ether synthesis", "1.8.5": "Thioether synthesis", "10.1.1": "Bromination", "10.1.2": "Chlorination", "10.1.5": "Wohl-Ziegler bromination", "9.3.1": "Carboxylic acid to acid chloride", "7.9.2": "Carboxylic acid to alcohol reduction", "3.4": "Stille reaction", "3.3": "Sonogashira reaction", "3.1": "Suzuki coupling", "2.3": "N-acylation to urea", "2.2": "N-sulfonylation", "2.1": "N-acylation to amide", "2.7": "O-sulfonylation", "2.6": "O-acylation to ester", "7.2.1": "Amide to amine reduction", "3": "C-C bond formation", "7": "Reductions", "10.4.2": "Methylation", "3.4.1": "Stille reaction", "6.2.1": "CO2H-Et deprotection", "6.2.3": "CO2H-tBu deprotection", "6.2.2": "CO2H-Me deprotection", "2.2.3": "Sulfonamide Schotten-Baumann", "8.1": "Alcohols to aldehydes", "8.2": "Oxidations at sulfur", "10.2.1": "Nitration", "2": "Acylation and related processes", "6": "Deprotections", "9.1": "Alcohol to halide", "9.3": "Acid to acid chloride", "1.3.7": "Chloro N-arylation", "1.3.6": "Bromo N-arylation", "1.3.8": "Fluoro N-arylation", "8.2.1": "Sulfanyl to sulfinyl", "10": "Functional group addition (FGA)", "2.6.1": "Ester Schotten-Baumann", "2.6.3": "Fischer-Speier esterification", "3.3.1": "Sonogashira coupling", "6.3.7": "Methoxy to hydroxy", "6.3.1": "O-Bn deprotection", "1.6": "Heteroaryl N-alkylation", "1.7": "O-substitution", "1.2": "Reductive amination", "1.3": "N-arylation with Ar-X", "1.8": "S-substitution", "2.7.2": "Sulfonic ester Schotten-Baumann", "2.1.2": "Carboxylic acid + amine reaction", "2.1.1": "Amide Schotten-Baumann", "2.1.7": "N-acetylation", "5.1": "NH protections", "1": "Heteroatom alkylation and arylation", "5": "Protections", "1.7.9": "Williamson ether synthesis", "9": "Functional group interconversion (FGI)", "1.7.6": "Methyl esterification", "1.7.4": "Hydroxy to methoxy", "2.3.1": "Isocyanate + amine reaction", "1.2.4": "Eschweiler-Clarke methylation", "1.2.5": "Ketone reductive amination", "1.2.1": "Aldehyde reductive amination", "8.1.4": "Alcohol to aldehyde oxidation", "8.1.5": "Alcohol to ketone oxidation", "5.1.1": "N-Boc protection", "7.1.1": "Nitro to amino", "7.3.1": "Nitrile reduction"}
Loading

0 comments on commit 3827fdd

Please sign in to comment.