pyRADDOSE-3D
A Python port of RADDOSE-3D, which models radiation dose in macromolecular crystallography.
Documentation: https://garmangroup.github.io/pyRADDOSE-3D/, with the example notebooks run and their results shown.
NumPy by default, so it installs at about 110 MB. Install pyRADDOSE-3D[torch]
and the same code runs on PyTorch, making the deterministic dose calculation
differentiable -- so a data-collection strategy can be optimised by gradient
descent rather than by scanning -- and the Monte Carlo runs on a GPU.
Conformance with the Java is a tested property, not a claim: each module is checked against reference values generated from RADDOSE-3D itself, and the achieved agreement is recorded rather than merely asserted.
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, photoelectron and fluorescence 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, 25 MB, in a package of their own, pyraddose-3d-elsepa |
| 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 are of everything installed, dependencies included, Python not;
most of the core's is SciPy and NumPy. PyTorch is the rest of level 3, and on
Linux it brings NVIDIA's CUDA libraries. [torch] alone gives gradients
without the Monte Carlo, and [plot] adds matplotlib, 58 MB, to draw the dose
in 3D.
Then, 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") # RADDOSE-3D's input, or YAML
simulation = simulate(experiment, record_images=True)
print(summary_text(simulation))
write_outputs(simulation) # output-Summary.txt, output-DoseState.csv, ...
The run scripts, the example inputs and the notebooks are in the repository: to use them, install from a clone.
From a clone, with uv
git clone https://github.com/GarmanGroup/pyRADDOSE-3D.git
cd pyRADDOSE-3D
uv makes a virtual
environment in the clone, .venv, and installs into it, at the same levels:
uv sync --no-dev --extra montecarlo
--extra montecarlo adds ELSEPA's electron tables, from packages/elsepa;
add --extra torch for PyTorch, and --extra plot to draw the dose in 3D.
Plain uv sync installs the development tools as well (see
Development).
Then activate it, and run:
source .venv/bin/activate # .venv\Scripts\activate on Windows
python programs/dose/run_dose.py docs/examples/inputs/insulin.txt
uv run python ... works without activating, but syncs first and so adds the
development tools unless given --no-dev. To open the example notebooks:
uv run --no-dev --group notebooks --with jupyterlab jupyter lab docs/examples
From a clone, with conda
environment.yml makes a conda environment,
pyraddose-3d, with the dependencies from conda-forge, the package installed
from the clone (editable, so a git pull updates it), the ELSEPA tables, and
JupyterLab and Matplotlib for the example notebooks and the dose contours:
conda env create -f environment.yml
conda activate pyraddose-3d
python programs/dose/run_dose.py docs/examples/inputs/insulin.txt
For gradients, add PyTorch: conda install -n pyraddose-3d -c conda-forge pytorch.
Running a dose calculation
Existing RADDOSE-3D input files are read unchanged, and the output files are
written with RADDOSE-3D's names and formats, so the port can stand in for the
Java in an existing pipeline. Give
programs/dose/run_dose.py an input file, as you
would give one to RADDOSE-3D:
python programs/dose/run_dose.py MyInput.txt
It prints the summary RADDOSE-3D prints and writes its files,
output-Summary.txt, output-DoseState.csv and the rest, to the current
directory; its other settings are at the top of the script. Or from Python,
as under Installing.
To draw the dose as RADDOSE-3D's DoseState.R does, as surfaces where it
crosses 0.1, 20 and 30 MGy, but with matplotlib rather than R:
python programs/dose/plot_dose_contours.py output-DoseState.csv
It saves five views as PNG files and opens a window in which the contours can
be turned with the mouse; pyraddose_3d.plotting draws them from Python.
docs/examples/inputs holds example inputs, ready to
run: RADDOSE-3D's insulin and MicroED examples, each as a RADDOSE-3D input file
and as a YAML configuration. The notebooks beside them start by running one,
then walk through crystals and beams, composition, decay models, gradients,
choosing a beam energy and drawing the dose. They are committed without their
results; the documentation shows
them run.
Optimising a strategy
Hand solve a tensor for any tunable setting and the whole calculation runs
in torch, so the reported numbers come back differentiable:
import torch
from pyraddose_3d.models.experiment import Experiment
from pyraddose_3d.solve import solve
experiment = Experiment.from_yaml("beamline.yaml")
fwhm = torch.tensor([20.0, 20.0], dtype=torch.float64, requires_grad=True)
peak = solve(experiment, {"beam.fwhm": fwhm})[0].max_dose
peak.backward()
fwhm.grad # how the peak dose responds to widening the beam
With no overrides it stays on NumPy, which is what a torch-less install runs and what the conformance corpus checks.
Only settings that carry a real gradient are accepted. Crystal geometry is
refused with the reason: the voxel occupancy test is a boolean parity count,
so autograd sees only the attenuation path and misses voxels entering or
leaving the crystal -- it returns a confident number that is 20% wrong. The
end of a wedge is refused for a different reason: it sets the number of
images and nothing else, so its derivative is zero wherever it exists. See
TUNABLE and FIXED in pyraddose_3d.solve.
Photoelectron and fluorescence escape are the exception to all of this. They are Monte Carlo, with each electron's direction drawn at random, so they have no gradient and run on NumPy only. They do reproduce RADDOSE-3D exactly, given its seed.
Licence
AGPL-3.0-only. Not a preference: RADDOSE-3D is licensed AGPL-3.0, and this
is a derivative work of it, so it inherits that licence. Upstream grants no
"or any later version", so neither can this -- hence AGPL-3.0-only rather
than -or-later.
See NOTICE for what is derived from where.
Attribution
This is a derivative work of RADDOSE-3D, by the Garman Group at the University of Oxford and contributors. 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
The element data in src/pyraddose_3d/data/ comes from RADDOSE-3D's
constants/MuCalcConstants.txt, which holds Pathikrit Bandyopadhyay's
parameterisation of the McMaster tables of X-ray cross-sections. The values
are unmodified; the layout is not. That file is 87 rows of 80 unlabelled
tab-separated columns, so it is split here into named tables --
elements.tsv, absorption_edges.tsv, cross_section_coefficients.tsv,
fluorescence.tsv, edge_ratios.tsv, electron_ionisation.tsv and
elsepa_elastic.tsv -- each with a header and each narrow enough to read.
tests/backend/data/build_element_tables.py is the script that produced
them.
Numerical behaviour is deliberately reproduced as-is, including several known quirks, each marked in the source. Where the port and the Java disagree, the Java is the specification until a change is made to both.
Development
The easiest way to get started is to use the github cli and uv:
gh repo fork GarmanGroup/pyRADDOSE-3D --clone
# or just
# gh repo clone GarmanGroup/pyRADDOSE-3D
cd pyRADDOSE-3D
uv sync
The Monte Carlo and XFEL subprograms read ELSEPA's electron angular tables,
which come in a data package beside the core, packages/elsepa, committed:
uv sync installs it. tests/backend/data/build_elsepa_package.py rebuilds
its tables from a RADDOSE-3D checkout, and the tests check them against each
directory's MANIFEST.tsv.
Run tests:
uv run pytest
Run the example notebooks, which are tests too:
uv run --group notebooks pytest --nbmake docs/examples
Build and preview the documentation, executing the examples:
uv run --group docs mkdocs serve
Lint files:
uv run pre-commit run --all-files
Release the core by pushing a tag, v and its version: CI builds it, takes
the version from the tag, publishes it to PyPI and makes a GitHub release.
The ELSEPA tables are released apart, rarely, as their own package: raise its
version in packages/elsepa/pyproject.toml, then run the Release ELSEPA
tables workflow from the Actions tab.
Metadata
Release files for pyRADDOSE-3D 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyraddose_3d-0.1.0.tar.gz | 1.8 MB | With provenance | Details for pyraddose_3d-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyraddose_3d-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pyraddose_3d-0.1.0-py3-none-any.whl |
Total release size: 2.3 MB
Release files / pyraddose_3d-0.1.0.tar.gz
| Download URL | pyraddose_3d-0.1.0.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e5b0e42af80b5ccedb663bc18890271959ba853b70a99aaecd9f81f5c73ccb3
|
|
BLAKE2b-256 checksum How to use checksums |
ffb1abe4d56bc3d7f1f1569454702d7d8e2b908da56025c20a8608940bc57635
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / pyraddose_3d-0.1.0-py3-none-any.whl
| Download URL | pyraddose_3d-0.1.0-py3-none-any.whl |
|---|---|
| Size | 517.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ead524323ed5aff5329e2a437199f2226a74ddb8da8d5997142a3dbaf19da7d
|
|
BLAKE2b-256 checksum How to use checksums |
0bf266caa43bf2ec9db6132c0413aab85f25835cbb7d1ee62db0b49fd4b860ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logSecurity for pyRADDOSE-3D 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyraddose_3d-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.