TOPAS & GATE Proton & Hadrontherapy Monte Carlo (.topas, .mac)
@modelscript/topas (languages/topas) provides native WebAssembly GLR parsing, Geant4 geometry hierarchy and parent-child bounding-box containment verification, Bortfeld (1997) analytical Bragg peak depth-dose and Spread-Out Bragg Peak (SOBP) evaluation, DAEBuilder lowering, and OpenSCAD / Modelica projections for TOPAS (Tool for Particle Simulation) and GATE proton, carbon-ion, and flash radiotherapy beamline configurations.
Supported Extensions & Standards
| Extension | Format | Description |
|---|---|---|
.topas, .txt | TOPAS Parameter File | Typed Geant4 parameter system (s: string, d: double with units, i: integer, b: boolean, dv:/sv: vectors) for Ge/, So/, Sc/, and Ph/ |
.mac | GATE / Geant4 Macro | Command-stream macro (/gate/world/daughters/..., /gate/source/..., /gate/actor/...) for medical physics Monte Carlo |
Key Capabilities
1. Typed Geometry (Ge/), Beam Sources (So/) & Dose Scorers (Sc/)
- Parses hierarchical CSG beamline components (
TsBox,TsCylinder,TsSphere,TsRangeModulator,TsPropeller,TsMultiLeafCollimator, water phantoms, and patient CT volumes), particle sources (Proton,Carbon12,Electron,Photon), andDoseToMedium/LETdscorers.
2. Analytical Bortfeld Bragg Peak & Range Calculation
- Computes the continuous-slowing-down range
in water ( , for protons), distal dose falloff ( ), peak-to-plateau ratio, and full depth-dose curves ( computeBraggPeakDepthDose).
3. 3D Nozzle CSG & Modelica Projections
- Projects TOPAS/GATE treatment nozzles and water phantoms into OpenSCAD 3D CSG geometry (
topasToScad) and Modelica beamline dosimetry models (topasToModelica).
Pre-Flight Diagnostics
10 rules9 error1 warning
| Code | Rule | Severity | Message |
|---|---|---|---|
M9601 | topas-type-prefix-mismatch | error | Parameter '<fullPath>' value '<rawVal>' does not match declared TOPAS type prefix '<typePrefix>:'. |
M9602 | topas-unresolved-parent-component | error | Geometry component '<compName>' references undeclared parent volume '<parentName>'. |
M9603 | topas-non-positive-geometry-dimension | error | Geometry component '<compName>' has invalid dimension: <detail>. |
M9604 | topas-child-exceeds-parent-bounds | error | Child geometry '<childName>' protrudes outside parent '<parentName>' along <axis>-axis ('<childExtent> mm' > '<parentHalfExtent> mm'). |
M9605 | topas-undefined-material | error | Component '<compName>' references unknown material '<materialName>' not found in Geant4/NIST materials or custom 'Ma/' definitions. |
M9606 | topas-invalid-beam-energy | error | Particle source '<sourceName>' has invalid beam energy specification: <detail>. |
M9607 | topas-circular-include-file | error | Circular or self-referential includeFile chain detected: '<cycleChain>'. |
M9608 | topas-scorer-missing-component | error | Scorer '<scorerName>' has invalid configuration: <detail>. |
M9609 | topas-vector-length-mismatch | error | Vector parameter '<fullPath>' declares length '<declaredCount>' but provides '<actualCount>' elements. |
M9610 | topas-duplicate-parameter-assignment | warning | Parameter '<fullPath>' is assigned multiple times in the same file without 'change' override prefix. |
Generated from languages/topas/src/lints/rules.ts. All languages →
CLI Usage
bash
# Inspect TOPAS/GATE geometry components, beam sources, and scorers
msx topas inspect ProtonNozzle.topas
# Validate parent-child bounding box containment, materials, and beam energy
msx topas validate ProtonNozzle.topas
# Compute analytical Bortfeld Bragg peak range (R0, R80) and depth-dose curve
msx topas bragg-peak ProtonNozzle.topas
# Project treatment nozzle and phantom geometry to OpenSCAD or Modelica
msx topas to-scad ProtonNozzle.topas > ProtonNozzle.scad
msx topas to-modelica ProtonNozzle.topas > ProtonNozzle.mo
