Implementation of organic reactivity prediction with LocalTransform developed by Prof. Yousung Jung group at KAIST (now moved to SNU, contact: yousung.jung@snu.ac.kr).
We slightly modified the model architechture to decrease the model size from 59MB to 36.4MB so we can upload to GitHub repo by decrease to size of bond feature from 512 to 256 through bond_net (see scripts/model.py
for more detail). This modification also accelerate the training process.
Also we fix few part of code to enable smooth implementation on cpu.
- Developer
- OS Requirements
- Python Dependencies
- Installation Guide
- Reproduce the results
- Demo and human benchmark results
- Publication
- License
Shuan Chen (shuan.micc@gmail.com)
This repository has been tested on both Linux and Windows operating systems.
- Python (version >= 3.6)
- Numpy (version >= 1.16.4)
- PyTorch (version >= 1.0.0)
- RDKit (version >= 2019)
- DGL (version >= 0.5.2)
- DGLLife (version >= 0.2.6)
Create a virtual environment to run the code of LocalTransform.
Make sure to install pytorch with the cuda version that fits your device.
This process usually takes few munites to complete.
git clone https://github.com/kaist-amsg/LocalTransform.git
cd LocalTransform
conda create -c conda-forge -n rdenv python=3.6 -y
conda activate rdenv
conda install pytorch cudatoolkit=11.3 -c pytorch -y
conda install -c conda-forge rdkit -y
conda install -c dglteam dgl-cuda11.3
pip install dgllife
Download the data from https://github.com/wengong-jin/nips17-rexgen/blob/master/USPTO/ and move the data to ./data/USPTO_480k/
.
A two-step data preprocessing is needed to train the LocalTransform model.
First go to the data processing folder
cd preprocessing
and extract the reaction templates.
python Extract_from_train_data.py
This will give you four files, including
(1) real_templates.csv (reaction templates for real bonds)
(2) virtual_templates.csv (reaction templates for imaginary bonds)
(3) template_infos.csv (including the hydrogen change, charge change and action information)
By running
python Run_preprocessing.py
You can get four preprocessed files, including
(1) preprocessed_train.csv
(2) preprocessed_valid.csv
(3) preprocessed_test.csv
(4) labeled_data.csv
Go to the main scripts folder
cd ../scripts
and run the following to train the model with reagent seperated or not (default: False)
python Train.py -sep True
The trained model will be saved at LocalTransform/models/LocalTransform_sep.pth
To use the model to test on test set, simply run
python Test.py -sep True
to get the raw prediction file saved at LocalTransform/outputs/raw_prediction/LocalTransform_sep.txt
Finally you can get the reactants of each prediciton by decoding the raw prediction file
python Decode_predictions.py -sep True
The decoded reactants will be saved at
LocalTransform/outputs/decoded_prediction/LocalTransform_sep.txt
By using
python Calculate_topk_accuracy.py -m sep
the top-k accuracy will be calculated from the files generated at step [4]
See Synthesis.ipynb
for running instructions and expected output. Human benchmark results is also shown at the end of the notebook.
This project is covered under the Apache 2.0 License.