This repository contains the code for RetroSynformer [1].
The RetroSynFormer express the retrosynthesis task, iteratively breaking down a compound into building blocks, as a sequence-modeling problem and train a model based on the Decision Transformer. The synthesis routes are generated by iteratively predicting chemical reactions from a set of reaction templates that encode known transformations, and routes are scored during construction using a novel reward function. RetroSynFormer was trained on routes extracted from the PaRoutes dataset of patented experimental routes.
Start by cloning this repo. Then, create and activate the conda environment by executing the following commands at the root of the repository:
conda create -n retrosynformer-env python=3.11
conda activate myenv
Then install PyTorch with the appropriate CUDA version. For CUDA=11.7 run:
pip install torch==1.13 --index-url https://download.pytorch.org/whl/cu117
Finally, use pip to intall the requirements:
pip install -r requirements.txt
- Download and preprocess the dataset (2 steps, see Data)
- Update the config file located in:
/retrosynformer/results/config.yaml - Train the data using:
retrosynformer/train.py - Use the trained model and
retrosynformer/predict.pyto predict retrosynthesis routes for the test targets.
Downlowad the PaRoutes dataset [2] from https://zenodo.org/records/17177425 and place in a data folder.
retrosynformer/train.py: Run to train the Decicion Transformer. Seeresults/config.yamlfor an example config file.
retrosynformer/predict.py: Run to predict routes for the testset and the N1 and N5 sets.
-
retrosynformer/utils/evaluation.py: Run to evaluate the results and calculate an average for multiple runs. -
retrosynformer/utils/evalutaion_compare_aizy.py: Run to evaluate the results and compare predictions to routes generated by baseline (AiZynthFinder [3]).
The software is licensed under the Apache 2.0 license (see LICENSE file), and is free and provided as-is.
[1] Granqvist, et al. "RetroSynFormer: Planning multi-step chemical synthesis routes via a Decision Transformer" chemRxiv preprint DOI:https://doi.org/10.26434/chemrxiv-2025-kd6gb (2025).
[2] Genheden, S., and Bjerrum, E. "PaRoutes: towards a framework for benchmarking retrosynthesis route predictions." Digital Discovery 1.4 (2022).
[3] Genheden, Samuel, et al. "AiZynthFinder: a fast, robust and flexible open-source software for retrosynthetic planning." Journal of cheminformatics 12.1 (2020).