Giter Site home page Giter Site logo

kaist-amsg / localtransform Goto Github PK

View Code? Open in Web Editor NEW
34.0 2.0 6.0 143.76 MB

Predicting Organic Reactivity with LocalTransform

License: Apache License 2.0

Jupyter Notebook 94.86% Python 5.14%
artificial-intelligence reaction-prediction pytorch

localtransform's Introduction

LocalTransform

LicenseDOI
Implementation of organic reactivity prediction with LocalTransform developed by Prof. Yousung Jung group at KAIST (now moved to SNU, contact: [email protected]).

LocalTransform

Model size decrease announcement (2022.10.31)

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.

Contents

Developer

Shuan Chen ([email protected])

OS Requirements

This repository has been tested on both Linux and Windows operating systems.

Python Dependencies

  • 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)

Installation Guide

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

Reproduce the results

[1] Download the raw data of USPTO-480k dataset

Download the data from https://github.com/wengong-jin/nips17-rexgen/blob/master/USPTO/ and move the data to ./data/USPTO_480k/.

[2] Data preprocessing

A two-step data preprocessing is needed to train the LocalTransform model.

1) Local reaction template derivation

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)

2) Assign the derived templates to raw data

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

[3] Train LocalTransform model

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

[4] Test LocalTransform model

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

[5] Exact match accuracy calculation

By using

python Calculate_topk_accuracy.py -m sep

the top-k accuracy will be calculated from the files generated at step [4]

Demo and human benchmark results

See Synthesis.ipynb for running instructions and expected output. Human benchmark results is also shown at the end of the notebook.

Publication

A Generalized Template-Based Graph Neural Network for Accurate Organic Reactivity Prediction, Nat Mach Intell 2022

License

This project is covered under the Apache 2.0 License.

localtransform's People

Contributors

shuan4638 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

localtransform's Issues

May you please release the trained model?

Marvelous work! I love the idea in your paper of defining reaction templates without indicating the specific atom types. Furthermore, I wanna try this method on some other kinds of reactions, and there seems to be no related model file in this repository. Would you mind releasing the trained checkpoints? It will be most helpful for me, and I'd like to thank you in advance.

How to train the model with other data

Thank you very much for your outstanding work!

The model is well established. But when I am trying to train the model with my own data, I am having a big problem.

When I run the command "python extract_from_train_data.py", all my input data shows "template problem" (as shown in the picture below). It seems that all my inputs are not being converted into templates during the extraction process.
N9M6_ @ET1BC L}XZ)M8A)J

Is this a problem with the format of my input data (my input format is organized as "C1Cc2cccc3cccc1c23.O=O.[H+]>>OC1Cc2cccc3cccc1c23.O")?
NAI`_LR80IC99A0W4{VWJRG

If I want to train the model with my own data, do I have to convert the SMILES code to the format of "[cH:28][cH:29]4)[CH2:16][CH2:17]C:18[CH2:19][CH2:20]3)[cH:10][cH:11][c:12]2[O:13][CH3:14])[CH2:2][CH2:3][CH2:4][CH2:5]1 24-25;23-25" ?
4`N7MXFKS85HHU_SKSSQ5DC_tmb

If so, is there any way to convert my data into this format?

I would be very grateful if you could give me some guidance!

RuntimeError: The size of tensor a (52) must match the size of tensor b (90) at non-singleton dimension 2

Thank you very much for your outstanding work on open source. When I tried to reproduce the results according to the steps, I got this error "RuntimeError: The size of tensor a (52) must match the size of tensor b (90) at non-singleton dimension 2" when running "python Train.py -s True". Have you encountered the same error and is there any way to solve this error? Thank you very much for your help!

NameError: name 'products' is not defined

Thank you very much for your guidance few days ago, and very sorry to bother again. The model was trained successfully, but when I run the test file with "python Test.py -sep True", I get this error: "NameError: name 'products' is not defined ". I checked the function that reported the error and found that the parameter 'products' is not defined here. Should I change 'products' to 'reagents' or something else? Thank you so much for your help!
FQ)JP{(7H BY{U6B7GNF2
IR${VCGW}~YU1VM9R1D4D(A

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.