This repository holds the code used to train, sample, transfer learn and reinforcement learn models described in Memory-assisted reinforcement learning for diverse molecular de novo design. This code is based on our updated REINVENT code used in "Molecular De Novo Design through Deep Reinforcement Learning".
The scripts and folders are the following:
- Python files in the main folder are all scripts. Run them with
-h
for usage information. ./priors
folder: Contains the trained priors used in the manuscript../scaffold
folder: Contains the code of the memory units../results
folder: Contains all the used datasets and generated molecules form the manuscript
The repository includes a Conda environment.yml
file with the required libraries to run all the scripts. It should work fine with Linux setups and a mid-high range GPU.
A Conda environment.yml
is supplied with all the required libraries.
git clone https://github.com/tblaschke/reinvent-memory
cd reinvent-memory
conda env create -f environment.yml
conda activate reinvent
From here the general usage applies.
- Create Model (
create_model.py
): Creates a blank model file. - Train Model (
train_model.py
): Trains the model with the specified parameters. - Transfer Learn Model (
transfer_learn_model.py
): Performs transfer learning of an already trained model with the specified parameters. - Sample Model (
sample_from_model.py
): Samples an already trained model for a given number of SMILES. - Reinforcement Learn Model (
reinforce_model.py
): Performs reinforcement learning of an already trained model with the specified parameters.
This code contains the memory unit aka scaffold filter. It's a hash table which dynamically changes the reward function during the reinforcement learning such the model gets penalized when it generates too similar compounds.
The basic principle goes as follows. Highly scored compounds get added to the memory. Inside the memory the compounds are assigned into different buckets. Each bucket is represented by an index compound. If a bucket is "full" we alter the value of the scoring function to be 0. To find out into which bucket a compound belongs, it's compared to all index compounds.
There are multiple modes to assign compounds into buckets.
- CompoundSimilarity: Calculates the ECFP Tanimoto similarity to all index compounds.
- MurckoScaffold: Checks for exact matches of Bemis-Murcko Scaffold
- TopologicalScaffold: Checks for exact matches of Topological Scaffold / Carbon Skeleton (replace all heavy atoms in a BM scaffold with carbons, and connect them only via single bonds)
- ScaffoldSimilarity: Checks for Tanimoto similarity between topological scaffolds. Uses the Atom Pair fingerprint.
- NoFilter: Only saves the generated molecules. Does nothing on it's own. This mode is equivalent to a normal RL.
The results used for the publication can be found in the results
folder. It contains all saved memories for all the different runs and the result of our MMP analysis.
If you want to reproduce all the numbers for yourself please checkout the other code repositories for the data extraction and SVM training and the MMP analysis. To make it as easy as possible to run all of the code copy all three code repositories into your ~/projects folder (if it does not exists, create it)
mkdir -f ~/projects
git clone https://github.com/tblaschke/reinvent-memory ~/projects/reinvent-memory
git clone https://github.com/tblaschke/reinvent-classifiers ~/projects/reinvent-classifiers
git clone https://github.com/tblaschke/reinvent-mmp-analysis ~/projects/reinvent-mmp-analysis
This command will download ExCAPE, filter the activity data, create the datasets and train the SVM models.
cd ~/projects/reinvent-classifiers
conda activate reinvent
bash run_extraction_and_svm_training.sh
After the datasets are constructed and SVMs are trained, this command will run all RL experiments. (Use a GPU for this)
cd ~/projects/reinvent-classifiers
conda activate reinvent
bash run_all_reinvent_experiments.sh
After the RL experiments. This will collect all the data and perform the MMP analysis.
cd ~/projects/reinvent-mmp-analysis
conda activate reinvent
bash run_mmpa.sh
If you have any questions please feel free to open an issue on GitHub or write an mail to thomas.blaschke@uni-bonn.de