TSItransRL is a Python codebase for goal-directed molecular generation with a staged workflow:
1_train.py)2_distill.py)3_generate.py, eval_script.py, 1_1_gen.py)The repository is currently configured mainly for the JNK3 + GSK3 multi-objective task (with QED/SA constraints), while parts of the code still include commented alternatives for DRD2.
1_train.py — trains/continues a custom conditional Transformer decoder (In model.py).1_1_gen.py — generates molecules from checkpoints and computes MOSES/property metrics.2_distill.py — fine-tunes/distills a GPT-2 LM (GPT2LMHeadModel) on selected generated molecules.3_generate.py — samples from the distilled GPT model and evaluates outputs.eval_script.py — shared evaluation logic (valid_metric) for validity/novelty/diversity/success metrics.model.py — custom autoregressive decoder implementation + scheduler.data.py — dataset and CSV parsing utilities.utils.py — property predictors (DRD2/JNK3/GSK3), SA/QED helpers, utility scoring logic.properties.py — additional property scoring helpers (older/parallel utility module).At a high level, the code uses molecular SMILES generation conditioned by task labels and iteratively improves generation quality:
positive/negative using task constraints.Current success criterion in active code path (JNK3/GSK3):
jnk3 >= 0.5gsk3 >= 0.5qed >= 0.6sa <= 4.0The project requires Python + PyTorch + RDKit + Hugging Face Transformers + MOSES.
CUDA is assumed by many scripts (.cuda()is used directly).
Recommended:
Example setup (conda):
conda create -n tsitransrl python=3.10 -y
conda activate tsitransrl
# Install PyTorch matching your CUDA version (example command may vary):
# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
pip install transformers pandas numpy tqdm seaborn matplotlib scikit-learn
# RDKit (recommended via conda-forge)
conda install -c conda-forge rdkit -y
# MOSES metrics package
pip install molsets
If molsets does not expose the moses namespace in your environment, install a compatible MOSES package used by your platform.
The scripts assume multiple local assets already exist. Important examples from hardcoded paths:
./liuyingv3./jnk_gsk_res/liuyingdistill*./jnk_gsk_res/YingGPTModel./drd2data/drd2.pkl./drd2data/jnk_gsk/jnk3.pkl./drd2data/jnk_gsk/gsk3.pkl./jnk_gsk_res/jnk_gsk_train_new7.csv./jnk_gsk_res/jnk_gsk_test_new7.csv./drd2data/jnk_gsk/jnk_gsk_activity.csvCSV schema expected in training data (see data.py):
SMILESjnk3, gsk3, qed, saMoleGPT)python 1_train.py
Notes:
if __name__ == "__main__":../jnk_gsk_res/molegpt_jnk_gsk6.ckpt./jnk_gsk_res/molegpt_jnk_gsk7.ckptpython 1_1_gen.py
This script:
MoleGPT checkpoint"<s>positive[SEP]"python 2_distill.py
This script:
liuyingdistill6)for_gpt_7.csv)Trainer./jnk_gsk_res/liuyingdistill7/)python 3_generate.py
This script:
./jnk_gsk_res/YingGPTModel)model.generate(...)valid_metric(...) from eval_script.pyThe evaluation scripts compute (depending on call path):
fraction_valid)IntDiv, IntDiv2)logP, SA, QED, weightOutputs are written to CSV/TXT paths configured in each script.
Hardcoded paths
__main__ block before running.GPU assumptions
.cuda() is called directly in several places.Potential bug in eval_script.py main call
valid_metric signature is:
valid_metric(gen_csv, n_jobs, ref_path, gen_smiles_csv, res_path)eval_script.py main block calls:
valid_metric(n_jobs, ref_path, gen_smiles_csv, res_path)gen_csv) and has shifted positions.External/local dependencies not included in repo
.pkl predictors are required but not stored here.pytorchtools.EarlyStopping
1_train.py imports EarlyStopping from pytorchtools, but that file/module is not present in this repository snapshot..pkl predictors, CSVs).1_train.py1_1_gen.py2_distill.py3_generate.pypytorchtools.py is available in Python path (or replace with your own early stopping implementation).python 1_train.py
python 1_1_gen.py
python 2_distill.py
python 3_generate.py
This repository is a fork of:
If you use this code in research, please cite the corresponding original work/repository as appropriate.
TSItransRL is a Python codebase for goal-directed molecular generation with a staged workflow:
1_train.py)2_distill.py)3_generate.py, eval_script.py, 1_1_gen.py)The repository is currently configured mainly for the JNK3 + GSK3 multi-objective task (with QED/SA constraints), while parts of the code still include commented alternatives for DRD2.
1_train.py — trains/continues a custom conditional Transformer decoder (In model.py).1_1_gen.py — generates molecules from checkpoints and computes MOSES/property metrics.2_distill.py — fine-tunes/distills a GPT-2 LM (GPT2LMHeadModel) on selected generated molecules.3_generate.py — samples from the distilled GPT model and evaluates outputs.eval_script.py — shared evaluation logic (valid_metric) for validity/novelty/diversity/success metrics.model.py — custom autoregressive decoder implementation + scheduler.data.py — dataset and CSV parsing utilities.utils.py — property predictors (DRD2/JNK3/GSK3), SA/QED helpers, utility scoring logic.properties.py — additional property scoring helpers (older/parallel utility module).At a high level, the code uses molecular SMILES generation conditioned by task labels and iteratively improves generation quality:
positive/negative using task constraints.Current success criterion in active code path (JNK3/GSK3):
jnk3 >= 0.5gsk3 >= 0.5qed >= 0.6sa <= 4.0The project requires Python + PyTorch + RDKit + Hugging Face Transformers + MOSES.
CUDA is assumed by many scripts (.cuda()is used directly).
Recommended:
Example setup (conda):
conda create -n tsitransrl python=3.10 -y
conda activate tsitransrl
# Install PyTorch matching your CUDA version (example command may vary):
# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
pip install transformers pandas numpy tqdm seaborn matplotlib scikit-learn
# RDKit (recommended via conda-forge)
conda install -c conda-forge rdkit -y
# MOSES metrics package
pip install molsets
If molsets does not expose the moses namespace in your environment, install a compatible MOSES package used by your platform.
The scripts assume multiple local assets already exist. Important examples from hardcoded paths:
./liuyingv3./jnk_gsk_res/liuyingdistill*./jnk_gsk_res/YingGPTModel./drd2data/drd2.pkl./drd2data/jnk_gsk/jnk3.pkl./drd2data/jnk_gsk/gsk3.pkl./jnk_gsk_res/jnk_gsk_train_new7.csv./jnk_gsk_res/jnk_gsk_test_new7.csv./drd2data/jnk_gsk/jnk_gsk_activity.csvCSV schema expected in training data (see data.py):
SMILESjnk3, gsk3, qed, saMoleGPT)python 1_train.py
Notes:
if __name__ == "__main__":../jnk_gsk_res/molegpt_jnk_gsk6.ckpt./jnk_gsk_res/molegpt_jnk_gsk7.ckptpython 1_1_gen.py
This script:
MoleGPT checkpoint"<s>positive[SEP]"python 2_distill.py
This script:
liuyingdistill6)for_gpt_7.csv)Trainer./jnk_gsk_res/liuyingdistill7/)python 3_generate.py
This script:
./jnk_gsk_res/YingGPTModel)model.generate(...)valid_metric(...) from eval_script.pyThe evaluation scripts compute (depending on call path):
fraction_valid)IntDiv, IntDiv2)logP, SA, QED, weightOutputs are written to CSV/TXT paths configured in each script.
Hardcoded paths
__main__ block before running.GPU assumptions
.cuda() is called directly in several places.Potential bug in eval_script.py main call
valid_metric signature is:
valid_metric(gen_csv, n_jobs, ref_path, gen_smiles_csv, res_path)eval_script.py main block calls:
valid_metric(n_jobs, ref_path, gen_smiles_csv, res_path)gen_csv) and has shifted positions.External/local dependencies not included in repo
.pkl predictors are required but not stored here.pytorchtools.EarlyStopping
1_train.py imports EarlyStopping from pytorchtools, but that file/module is not present in this repository snapshot..pkl predictors, CSVs).1_train.py1_1_gen.py2_distill.py3_generate.pypytorchtools.py is available in Python path (or replace with your own early stopping implementation).python 1_train.py
python 1_1_gen.py
python 2_distill.py
python 3_generate.py
This repository is a fork of:
If you use this code in research, please cite the corresponding original work/repository as appropriate.