Skip to main content
. Author manuscript; available in PMC: 2026 Aug 8.
Published in final edited form as: Phys Med Biol. 2026 Jan 14;71(1):10.1088/1361-6560/ae237c. doi: 10.1088/1361-6560/ae237c

Source code 1:

Example simulation script

1 import opengate as gate
2 sim = gate.Simulation()
3 mm = gate.g4_units.mm
4 MeV = gate.g4_units.MeV
5 patient = sim.add_volume(“Image”, name=“patient”)
6 patient.image = “patient-4mm.mhd”
7 patient.mother = “world”
8 patient.voxel_materials = [
9  [−2000, −900, “G4_AIR”],
10  [−900, −100, “Lung”],
11  [−100, 0, “G4_ADIPOSE_TISSUE_ICRP”],
12  [0, 300, “G4_TISSUE_SOFT_ICRP”],
13  [300, 800, “G4_B-100_BONE”],
14  [800, 6000, “G4_BONE_COMPACT_ICRU”]]
15 patient.set_production_cut(
16  particle_name=“electron”,
17  value=3 * mm)
18 src = sim.add_source(“GenericSource”, name=“p_src”)
19 src.particle = “proton”
20 src.position.type = “sphere”
21 src.position.radius = 10 * mm
22 src.position.translation = [0, 0, −140 * mm]
23 src.n = 1e4 # number of primary particles
24 src.direction.type = “momentum”
25 src.direction.momentum = [0, 0, 1]
26 dose_actor = sim.add_actor(“DoseActor”, “dose”)
27 dose_actor.attached_to = “patient”
28 dose_actor.size = [99, 99, 99]
29 dose_actor.spacing = [2 * mm, 2 * mm, 2 * mm]
30 dose_actor.output_coordinate_system = ‘attached_to_image’
31 dose_actor.translation = [2 * mm, 3 * mm, −2 * mm]
32 for en in [130, 140, 150, 160]:
33  src.energy.mono = en * MeV
34  dose.output_filename = f”patient_energy_{en}.mhd”
35  sim.run(start_new_process=True)