This repository enables offline chemical reaction prediction using transformer models. The available tasks are RXN's most used prediction functionality: forward reaction, single-step retrosynthesis, and retrosynthesis tree generation. These tasks are performed locally via Jupyter notebook, via dedicated Python scripts, or via LLM (using OpenWeb UI and MCP). The transformer models were trained using 2025Q2 Pistachio data.
[!NOTE]
If using Podman, replace docker commands with podman throughout this guide.
This repository uses Git LFS for .ckpt model files. Install Git LFS, then run git lfs install once on your machine before cloning or pulling the repository.
Hardware:
8GB RAM (16GB recommended for retrosynthesis tree predictions)
10GB free disk space for container images and models
Supported platforms: macOS, Linux, Windows
Supported architectures: Intel/AMD (x86_64) and ARM64 (Apple Silicon)
NVIDIA GPU (optional) — required only when using compose-cuda.yaml
GPU-accelerated inference via NVIDIA CUDA (requires an NVIDIA GPU and the NVIDIA Container Toolkit)
Clone this repository, and from the root directory run the following commands. Replace compose.yaml with compose-cuda.yaml in each command to enable GPU acceleration.
Use the provided notebook.ipynb to explore examples and interact with the models.
Notebook
Initial Setup
Run the Celery setup and helper functions section first to:
Import required libraries
Configure the Celery application
Define helper functions for visualizing results
Product Prediction
Two examples are provided for product prediction (batch and single reaction). Customize the reactants list:
python
1# Set up a list of reactants to make predictions2reactants_list =["CCI.O=Cc1ccc([N+](=O)[O-])c(O)c1"]
Configure prediction parameters:
python
1# Setup task kwargs2kwargs ={3"topn":3,# Number of results per reactant4"num_beams":5,# Number of beams used for prediction. Must be >= topn5}
After running the prediction, the results will be displayed in a table:
Product Prediction Results
Retrosynthesis Prediction
Retrosynthesis predictions process one product at a time. Set the target product:
python
1# Choose product for retrosynthesis prediction2product ="C=CC(=C)C[Si](C)(C)C"
Configure retrosynthesis-specific parameters:
python
1# Setup task kwargs2kwargs ={3"topn":10,# Number of results per reactant4"num_beams":10,# Number of beams used for prediction. Must be >= topn5"fap":0.6,# Forward likelihood acceptance probability (not length averaged)6"fld":0.2,# Forward likelihood delta required between the top2 forward prediction results7}
Results are displayed in a similar table format:
Retrosynthesis Prediction Results
Retrosynthesis Tree Prediction
Start by selecting a target product SMILES:
python
1# Choose product for retrosynthesis tree prediction2product ="C1C(C[Si](C)(C)C)=CCC2C(=O)OC(=O)C12"
Configure prediction and tree-specific parameters:
python
1# Setup task kwargs2kwargs ={3"topn":15,# Number of results per reactant4"num_beams":15,# Number of beams used for prediction. Must be >= topn5"fap":0.6,# Forward likelihood acceptance probability (not length averaged)6"fld":0.2,# Forward likelihood delta required between the top2 forward prediction results7"max_depth":4,# Max depth of the retrosynthesis tree8"beam_width":6,# Max amount of nodes being expanded in each step9}10
⚠️ Performance Note: Retrosynthesis tree predictions are computationally intensive and may take significant time to complete.
Result Visualization
Two visualization options are available:
1. Text Representation - Complete textual view of predicted routes and steps:
Retrosynthesis Tree Text Representation
2. Graph Representation - Visual tree structure with molecule expansion paths. Use the selector to switch between different prediction results:
Retrosynthesis Tree Graph Representation
LLM (click to expand)
MCP Integration with OpenWebUI
Access OpenWeb UI at http://localhost:3000/ to interact with RXN models using natural language through AI assistants.
OpenWeb UI
Setup MCP Server Connection
Navigate to Settings → Integrations
Under Manage Tool Servers, click the + icon
Set URL to http://localhost:8000
Click Verify Connection and Save
OpenWeb UI New Integration
Configure External Models (Optional)
To use external AI models:
Go to Admin Settings → Connections
Add your API key for the desired model provider
OpenWeb UI Connections
Enable RXN Tools
Select your preferred AI model
Click the Integrations button below the prompt input
Select Tools and toggle on rxn-mcp-server
Note: You must re-enable the tool when switching models.
OpenWeb UI Activate Tool
Using Natural Language
Interact with RXN functions using conversational prompts:
OpenWeb UI Chat Prompt
Python Scripts (click to expand)
Running via Scripts
If you prefer a command-line workflow, you can run predictions directly from the provided Python scripts without using Jupyter or OpenWebUI. This method may be useful for
running analyses on remote machines (which often lack GUIs).
Open a Shell in the Worker Container
The scripts are executed inside the worker container, where the models and Celery configuration are already available:
docker exec -it rxn-worker-1 bash
Available Example Scripts
python scripts/predict_product.py — run forward reaction prediction examples
python scripts/predict_retrosynthesis.py — run single-step retrosynthesis examples
python scripts/predict_retrosynthesis_tree.py — run retrosynthesis tree examples
python scripts/run_notebook_examples.py — run the same examples shown in the notebook in sequence (this is effectively a combination of the three prior scripts)
Customize Inputs and Parameters
Each script is intended to be edited before execution. The scripts/ directory is mounted into the worker container, so local changes are immediately available without rebuilding the image. Update the input SMILES and prediction parameters directly in the file:
reactants_list for forward reaction prediction
product for retrosynthesis and retrosynthesis tree prediction
topn, num_beams, fap, fld, max_depth, and beam_width as needed
Then run the script you want:
python scripts/predict_product.py
Exit the Container
When you are finished, leave the container shell with:
exit
Container Management
Container Architecture
The system consists of six containers:
redis - Results backend for Celery tasks
broker - RabbitMQ message queue for task distribution
worker - Celery worker running the transformer models
jupyter - Interactive notebook environment
mcp - Model Context Protocol server for LLM integration
openwebui - Web interface for AI assistant interaction
[!TIP]
Replace -f compose.yaml with -f compose-cuda.yaml in any of the commands above to manage the GPU-accelerated stack instead.
Performance Notes
Forward Predictions: Fast (seconds)
Single-Step Retrosynthesis: Moderate (seconds to minutes)
Tree Retrosynthesis: Slow (minutes to hours depending on depth/width)
Optimization Tips:
Start with smaller topn and num_beams values
Limit max_depth to 3-4 for tree predictions
Use beam_width of 5-10 for reasonable performance
Allocate 16GB RAM for complex tree predictions
Benchmarking:
GPU acceleration provides significant speedup, especially for complex retrosynthesis tree predictions. These results are from the Python scripts in the scripts/ folder. Analysis
times can vary substantially depending on the query molecule(s) and parameters.