Running an input file¶
The quickest way to run pyRADDOSE-3D is the way RADDOSE-3D is run: hand it
an input file, then read the summary it prints and the files it writes.
inputs/, beside this notebook, holds four, ready to run:
| file | experiment |
|---|---|
insulin.txt |
RADDOSE-3D's own example input, MyInput.txt, unchanged: an insulin crystal in an X-ray beam, two wedges |
insulin.yaml |
the same experiment as a YAML configuration |
microed.txt |
RADDOSE-3D's ED_input_cell.txt, unchanged: a protein microcrystal in a 300 keV electron beam |
microed.yaml |
the same, as YAML |
Any RADDOSE-3D input file is read the same way.
An input file¶
This is insulin.txt:
from pathlib import Path
INPUTS = Path("inputs")
print((INPUTS / "insulin.txt").read_text())
##############################################################################
# Crystal Block #
##############################################################################
Crystal
Type Cuboid # Cuboid
Dimensions 100 100 100 # Dimensions of the crystal in X,Y,Z in µm.
PixelsPerMicron 0.1 # The computational resolution
AbsCoefCalc RD3D # Tells RADDOSE-3D how to calculate the
# Absorption coefficients
# Example case for insulin:
UnitCell 78.02 78.02 78.02 # unit cell size: a, b, c
# alpha, beta and gamma angles default to 90°
NumMonomers 24 # number of monomers in unit cell
NumResidues 51 # number of residues per monomer
ProteinHeavyAtoms Zn 0.333 S 6 # heavy atoms added to protein part of the
# monomer, i.e. S, coordinated metals,
# Se in Se-Met
# Note: If a sequence file is used S does not
# need to be added
SolventHeavyConc P 425 # concentration of elements in the solvent
# in mmol/l. Oxygen and lighter elements
# should not be specified
SolventFraction 0.64 # fraction of the unit cell occupied by solvent
##############################################################################
# Beam Block #
##############################################################################
Beam
Type Gaussian # Gaussian profile beam
Flux 2e12 # in photons per second (2e12 = 2 * 10^12)
FWHM 20 70 # in µm, X and Y for a Gaussian beam
# X=vertical and Y = horizontal for a
# horizontal goniometer
# Opposite for a vertical goniometer
Energy 12.1 # in keV
Collimation Rectangular 100 100 # X/Y collimation of the beam in µm
# X = vertical and Y = horizontal for a
# horizontal goniometer
# Opposite for a vertical goniometer
##############################################################################
# Wedge Block #
##############################################################################
Wedge 0 90 # Start and End rotational angle of the crystal
# Start < End
ExposureTime 50 # Total time for entire angular range in seconds
# AngularResolution 2 # Only change from the defaults when using very
# small wedges, e.g 5°.
##############################################################################
# Wedge Block #
##############################################################################
Wedge 90 180 # Start and End rotational angle of the crystal
# Start < End
ExposureTime 10 # Total time for entire angular range in seconds
# AngularResolution 2 # Only change from the defaults when using very
# small wedges, e.g 5°.
Read it, run it, and print what RADDOSE-3D prints:
from pyraddose_3d.models.experiment import Experiment
from pyraddose_3d.outputs import summary_text
from pyraddose_3d.solve import simulate
experiment = Experiment.from_file(INPUTS / "insulin.txt")
simulation = simulate(experiment, record_images=True)
print(summary_text(simulation))
Cuboid (Polyhedron) crystal of size [100, 100, 100] um [x, y, z] at a resolution of 10.00 microns per voxel edge. Simple DDM. Gaussian beam, 100.0x100.0 um with 20.00 by 70.00 FWHM (x by y) and 2.0e+12 photons per second at 12.10 keV. Wedge 1: Collecting data for a total of 50.0s from phi = 0.0 to 90.0 deg. Crystal coefficients calculated with RADDOSE-3D. Photelectric Coefficient: 3.10e-04 /um. Inelastic Coefficient: 1.78e-05 /um. Elastic Coefficient: 2.01e-05 /um. Attenuation Coefficient: 3.48e-04 /um. Density: 1.09 g/ml. Average Diffraction Weighted Dose : 6.269605 MGy Last Diffraction Weighted Dose : 10.560162 MGy Elastic Yield : 2.18e+11 photons Diffraction Efficiency (Elastic Yield/DWD): 3.47e+10 photons/MGy Average Dose (Whole Crystal) : 5.951007 MGy Average Dose (Exposed Region) : 5.951007 MGy Max Dose : 37.477703 MGy Average Dose (95.0 % of total absorbed energy threshold (2.86 MGy)): 9.549758 MGy Dose Contrast (Max/Threshold Av.) : 3.92 Used Volume : 100.0% Absorbed Energy (this Wedge) : 6.64e-03 J. Dose Inefficiency (Max Dose/mJ Absorbed) : 5645770.7 1/g Dose Inefficiency PE (Max Dose/mJ Deposited): 5767122.3 1/g Final Dose Histogram: Bin 1, 0.0 to 0.1 MGy: 16.6 % Bin 2, 0.1 to 3.4 MGy: 25.9 % Bin 3, 3.4 to 6.7 MGy: 21.0 % Bin 4, 6.7 to 10.1 MGy: 16.2 % Bin 5, 10.1 to 13.4 MGy: 9.0 % Bin 6, 13.4 to 16.7 MGy: 5.0 % Bin 7, 16.7 to 20.0 MGy: 2.2 % Bin 8, 20.0 to 23.4 MGy: 1.4 % Bin 9, 23.4 to 26.7 MGy: 1.2 % Bin 10, 26.7 to 30.0 MGy: 1.2 % Bin 11, 30.0 MGy upwards: 0.3 % Wedge 2: Collecting data for a total of 10.0s from phi = 90.0 to 180.0 deg. Crystal coefficients calculated with RADDOSE-3D. Photelectric Coefficient: 3.10e-04 /um. Inelastic Coefficient: 1.78e-05 /um. Elastic Coefficient: 2.01e-05 /um. Attenuation Coefficient: 3.48e-04 /um. Density: 1.09 g/ml. Average Diffraction Weighted Dose : 8.872101 MGy Last Diffraction Weighted Dose : 12.867242 MGy Elastic Yield : 4.32e+10 photons Diffraction Efficiency (Elastic Yield/DWD): 4.87e+09 photons/MGy Average Dose (Whole Crystal) : 7.133724 MGy Average Dose (Exposed Region) : 7.133724 MGy Max Dose : 44.973244 MGy Average Dose (95.0 % of total absorbed energy threshold (2.30 MGy)): 9.072340 MGy Dose Contrast (Max/Threshold Av.) : 4.96 Used Volume : 100.0% Absorbed Energy (this Wedge) : 1.32e-03 J. Dose Inefficiency (Max Dose/mJ Absorbed) : 34088998.2 1/g Dose Inefficiency PE (Max Dose/mJ Deposited): 5773173.2 1/g Final Dose Histogram: Bin 1, 0.0 to 0.1 MGy: 0.0 % Bin 2, 0.1 to 3.4 MGy: 36.3 % Bin 3, 3.4 to 6.7 MGy: 22.4 % Bin 4, 6.7 to 10.1 MGy: 18.1 % Bin 5, 10.1 to 13.4 MGy: 10.1 % Bin 6, 13.4 to 16.7 MGy: 4.4 % Bin 7, 16.7 to 20.0 MGy: 3.8 % Bin 8, 20.0 to 23.4 MGy: 1.2 % Bin 9, 23.4 to 26.7 MGy: 1.2 % Bin 10, 26.7 to 30.0 MGy: 0.2 % Bin 11, 30.0 MGy upwards: 2.3 %
write_outputs writes RADDOSE-3D's files, under its names and in its
formats. Here they go to a temporary directory. prefix works as
RADDOSE-3D's --prefix does, so prefix="output-" would write
output-Summary.txt and the rest to the current directory.
import tempfile
from pyraddose_3d.outputs import write_outputs
directory = Path(tempfile.mkdtemp())
for path in write_outputs(simulation, prefix=str(directory / "output-")):
print(path.name)
output-Summary.csv output-Summary.txt output-DoseState.csv output-DoseState.R output-RDE.csv output-DWDs.csv output-VoxelDose.csv output-VoxelFluences.csv
The same experiment in YAML¶
A YAML configuration says the same thing with each setting named, and its
units and RADDOSE-3D keyword in a comment. from_file reads anything
ending in .yaml or .yml as one, and anything else as a RADDOSE-3D input
file:
print((INPUTS / "insulin.yaml").read_text())
##############################################
### Dose calculation configuration example ###
##############################################
# The insulin crystal from RADDOSE-3D's own example input, MyInput.txt --
# insulin.txt here is that file, and describes the same experiment. Load
# with `Experiment.from_file(path)`, which reads either.
#
# A setting left out takes RADDOSE-3D's default, so leaving it out of this
# file means what leaving it out of a .txt input means. The .txt keyword for
# each setting is given in brackets.
crystal:
type: cuboid # [Type] cuboid, spherical, cylinder or polyhedron
dimensions: [100.0, 100.0, 100.0] # [Dimensions] x, y, z in micrometres
pixels_per_micron: 0.1 # [PixelsPerMicron] default 10 voxels across x
# angle_p: 0.0 # [AngleP] rotation in the plane of the loop, degrees
# angle_l: 0.0 # [AngleL] bend of the loop, degrees
# decay_model: simple # [DDM] simple, linear, bfactor or leal
composition: # [AbsCoefCalc RD3D]
method: unit_cell
unit_cell: [78.02, 78.02, 78.02] # [UnitCell] a, b, c in Angstroms
num_monomers: 24 # [NumMonomers] per unit cell
num_residues: 51 # [NumResidues] amino acids per monomer
protein_heavy_atoms: # [ProteinHeavyAtoms] atoms per monomer
Zn: 0.333
S: 6.0
solvent_heavy_conc: # [SolventHeavyConc] mmol/l
P: 425.0
solvent_fraction: 0.64 # [SolventFraction] computed if left out
# escape: # Monte Carlo, so see seed below
# photoelectron: true # [CalculatePEEscape] electrons leaving the crystal
# fluorescence: true # [CalculateFLEscape] and fluorescence photons
beam:
type: gaussian # [Type] gaussian, tophat or experimental
flux: 2.0e+12 # [Flux] photons per second
energy: 12.1 # [Energy] keV
fwhm: [20.0, 70.0] # [FWHM] x, y in micrometres
collimation: # [Collimation] leave out for no aperture
shape: rectangular # rectangular or circular
x: 100.0 # micrometres
y: 100.0
wedges: # one per [Wedge] block, exposed in order
- start: 0.0 # [Wedge] start and end angles in degrees
end: 90.0
exposure_time: 50.0 # [ExposureTime] seconds for the whole wedge
# angular_resolution: 2.0 # [AngularResolution] degrees per image
- start: 90.0
end: 180.0
exposure_time: 10.0
# seed: 20260917 # [--seed] escape's random numbers; chosen if left out
Experiment.from_file(INPUTS / "insulin.yaml") == experiment
True
MicroED¶
Subprogram EMED in an input file (subprogram: microed in YAML) asks for
RADDOSE-3D's MicroED engine, which microed runs:
print((INPUTS / "microed.txt").read_text())
###############################################################################
#Crystal Block#
###############################################################################
Crystal
Type Cuboid
Dimensions 0.2 0.2 0.2
PixelsPerMicron 100 #the number of voxel per micron in the crystal
AbsCoefCalc RD3D # Tells RADDOSE-3D how to calculate the
# Absorption coefficients
# Example case for insulin:
UnitCell 78.02 78.02 78.02 # unit cell size: a, b, c
# alpha, beta and gamma angles default to 90°
NumMonomers 24 # number of monomers in unit cell
NumResidues 51 # number of residues per monomer
SolventFraction 0.50 # fraction of the unit cell occupied by solvent
SUBPROGRAM EMED
###############################################################################
#Beam Block#
###############################################################################
Beam
Type TopHat
Energy 300
Collimation Circular 2.0 2.0
Exposure 7.8e-4 # in e-/A^2
###############################################################################
#Wedge Block#
###############################################################################
Wedge 0 0
ExposureTime 1
from pyraddose_3d.outputs import microed_report
from pyraddose_3d.solve import microed
print(microed_report(microed(Experiment.from_file(INPUTS / "microed.txt"))))
The density is: 9.40e-01 Elastic Lambda: 607.452583113029 GOS Inelastic Lambda: 288.27626995928324 The Dose in the exposed area by stopping power: 2.8807e-03 MGy The CSDA range is: 924967.74 nm Number elastic events: 687.43 Number single elastic events: 580.46 Number Inelastic events: 1225.99 Number productive events: 290.05 Information Coefficient (productive/MGy): 100687.00 The optimal accelerating voltage is: 730 kV The optimal thickness is: 195 nm
From the command line¶
programs/dose/run_dose.py does all of this for any input -- MX, MicroED,
or the Monte Carlo and XFEL subprograms -- printing the summary and writing
the files to the current directory. From the top of the repository:
python programs/dose/run_dose.py docs/examples/inputs/insulin.txt
With no input named, it runs insulin.txt. Its other settings, the output
prefix and whether to write the per-image files, are at the top of the
script.