pyRADDOSE-3D
A Python port of RADDOSE-3D, which models the radiation dose a crystal absorbs during an X-ray diffraction experiment -- voxel by voxel, image by image.
It reads RADDOSE-3D's input files unchanged and writes its output files in the same formats, so it can stand in for the Java in an existing pipeline. It also reads a YAML configuration, and it runs on NumPy by default or on PyTorch, where the calculation becomes differentiable: a data-collection strategy can be optimised by gradient descent rather than by scanning.
Citing this work
pyRADDOSE-3D is a derivative of RADDOSE-3D. If you use it, cite the original:
Zeldin, O. B., Gerstel, M. and Garman, E. F. (2013). RADDOSE-3D: time- and space-resolved modelling of dose in macromolecular crystallography. J. Appl. Cryst. 46, 1225-1230. doi:10.1107/S0021889813011461
Installing
From PyPI, at one of three levels, each adding to the one before:
| install | size | for | |
|---|---|---|---|
| 1. Core | pip install pyRADDOSE-3D |
110 MB | RADDOSE-3D's dose calculation: every MX input it accepts, escape, MicroED, and its input and output files |
| 2. Monte Carlo | pip install "pyRADDOSE-3D[montecarlo]" |
135 MB | adds the Monte Carlo, GOS and XFEL subprograms, with ELSEPA's electron tables (pyraddose-3d-elsepa, 25 MB) |
| 3. PyTorch | pip install "pyRADDOSE-3D[montecarlo,torch]" |
0.75 GB on macOS; 5.5 GB on Linux | adds gradients, to optimise a strategy, and the Monte Carlo on a GPU |
The sizes include every dependency; on Linux PyTorch brings NVIDIA's CUDA
libraries. [plot] adds matplotlib, 58 MB, to draw the dose.
The run scripts, the example inputs and these notebooks are in the repository. To use them, install from a clone, with uv, at the same levels:
git clone https://github.com/GarmanGroup/pyRADDOSE-3D.git
cd pyRADDOSE-3D
uv sync --no-dev --extra montecarlo # add --extra torch --extra plot
source .venv/bin/activate # .venv\Scripts\activate on Windows
or with conda, from the clone's environment.yml, which includes the ELSEPA
tables and matplotlib:
conda env create -f environment.yml
conda activate pyraddose-3d
A first run
Give programs/dose/run_dose.py an input file, as you
would give one to RADDOSE-3D:
python programs/dose/run_dose.py docs/examples/inputs/insulin.txt
It prints the summary RADDOSE-3D prints and writes its files to the current directory. Or, from Python:
from pyraddose_3d.models.experiment import Experiment
from pyraddose_3d.outputs import summary_text, write_outputs
from pyraddose_3d.solve import simulate
experiment = Experiment.from_file("MyInput.txt") # or a .yaml configuration
simulation = simulate(experiment, record_images=True)
print(summary_text(simulation))
write_outputs(simulation) # output-Summary.txt, output-DoseState.csv, ...
Running an input file shows the example inputs and runs them; the other examples walk through the rest.
Agreement with RADDOSE-3D
Every number is checked against RADDOSE-3D itself, on a corpus of 95 experiments, with each tolerance measured and justified rather than chosen; the output files are compared with the Java's line by line. The 22 Monte Carlo, GOS and XFEL experiments, which are random, are compared statistically, over 20 runs on each side. See Agreement with RADDOSE-3D.
The whole MX calculation is ported, photoelectron and fluorescence escape
included: escape is Monte Carlo, and the port draws its random numbers in
the Java's order, so given RADDOSE-3D's seed it gives RADDOSE-3D's answer.
So is the MicroED engine (Subprogram EMED), RADDOSE-3D's dose to a thin
crystal in an electron beam, and its Monte Carlo and XFEL subprograms
(Subprogram MonteCarlo, GOS and XFEL), which follow every electron;
those are random, and agree with RADDOSE-3D statistically. Not ported:
AbsCoefCalc RDV2/RDV3, which run the original Fortran RADDOSE as an
external program. Asking for them is an error, not a silently different
answer.
Licence
AGPL-3.0-only, as RADDOSE-3D is.