lmparticle authoring skill

lmparticle is a seeded Monte Carlo photon transport host for LMScript with embedded NIST XCOM cross sections for radiation shielding, detector response, radiographic imaging, and collision kerma calculations.

Purpose

Use lmparticle to evaluate photon attenuation, half-value and tenth-value layers, scatter buildup factors, NaI(Tl) and semiconductor detector pulse-height spectra, radiographic contrast, and multi-layer energy deposition from 1 keV to 20 MeV.

When to use it

Choose lmparticle for photon transport problems (photoelectric absorption, Compton scattering, Rayleigh coherent scattering, and pair production with 511 keV annihilation at rest) where collision kerma and photon fluences or spectra are required. Do not use it when secondary electron or positron transport, bremsstrahlung, X-ray fluorescence, or radiotherapy charged-particle disequilibrium in thin layers dominates.

Install

Install the lmctl CLI globally, or declare cli="lmparticle" and install="github:lmctl-ai/lmparticle@latest" in an LMScript _lmcode_ block so the runtime downloads and verifies the self-contained 2.5 MB release binary (Linux glibc 2.35 or newer, macOS, or Windows).

npm install -g @lmctl-ai/lmctl
lmparticle --version
lmparticle --notices
lmparticle --lmcode-schema --json

Commands

lmparticle runs as an lmcode host controlled by LMScript via run_lmcode(p) or directly from the command line for schema inspection, signature verification, and bytecode execution.

lmparticle --version
lmparticle --notices
lmparticle --lmcode-schema
lmparticle --lmcode-schema --json
lmparticle --lmcode-signatures
lmparticle --lmcode invocation.json
lmctl autorun examples/depth_dose.lms

Inputs and outputs

Programs use context rad: Rad alongside the standard lmcode_std_v3 catalog. All energies are in MeV, lengths in cm, and densities in g/cm3. Tallies in Result are normalized per source photon and paired with _err methods returning the standard error of the mean.

Safety rules

Worked examples

Transmit a 662 keV Cs-137 pencil beam through a 1 cm lead slab and verify that the uncollided plane crossing matches the narrow-beam exponential attenuation law:

p = _lmcode_ cli="lmparticle" install="github:lmctl-ai/lmparticle@latest";
let pb = rad.builtin("lead");
let g = rad.geometry();
g.slab("shield", pb, 0.0, 1.0);
let s = rad.source();
s.point(0.0, 0.0, -1.0).beam(0.0, 0.0, 1.0).energy(0.662);
let r = rad.simulation(g, s).plane("exit", "z", 1.0).seed(1).run(200000);
rad.print("uncollided " + str(r.plane_uncollided("exit")) + " +- " + str(r.plane_uncollided_err("exit")));
rad.assert_close(r.plane_uncollided("exit"), pow(2.718281828459045, -pb.mu(0.662)), 0.005);
end _lmcode_
r = run_lmcode(p);
require(r.ok, json_stringify(r));

Simulate the pulse-height spectrum of a 3x3 inch NaI(Tl) crystal irradiated by a 662 keV point source and save the histogram for plotting:

p = _lmcode_ cli="lmparticle" install="github:lmctl-ai/lmparticle@latest";
let nai = rad.builtin("nai");
let g = rad.geometry().cylinder("crystal", nai, 0.0, 0.0, 3.81, 0.0, 7.62);
let s = rad.source().point(0.0, 0.0, -10.0).beam(0.0, 0.0, 1.0).energy(0.662);
let r = rad.simulation(g, s).spectrum(140, 0.7).pulse_height("crystal").seed(7).run(100000);
rad.assert_true(r.pulse_fraction("crystal", 0.65, 0.67) > 0.1);
r.save_pulse_height("crystal", "nai_spectrum.dat");
end _lmcode_
r = run_lmcode(p);
require(r.ok, json_stringify(r));

Errors and exit codes

Each invocation emits one terminal LMCODE_RETURN frame. Exit code 0 indicates success. Exit code 2 indicates CLI argument or invocation manifest validation errors. Exit code 3 indicates bytecode load failure, schema mismatch, runtime assertion failure (assert_close or assert_true), invalid physics configuration, or exceeding LMPARTICLE_MAX_MEMORY_MB. Exit code 4 indicates an application or output file write failure.

How to verify

Check schema and signature parity against the lmscript compiler and run a known-answer Beer-Lambert attenuation test:

lmparticle --version
lmparticle --lmcode-schema --json > /tmp/lmparticle.schema.json
lmparticle --lmcode-signatures > /tmp/lmparticle.sigs.txt
lmscript --lmcode-signatures /tmp/lmparticle.schema.json > /tmp/lmparticle.compiler.txt
diff -u /tmp/lmparticle.compiler.txt /tmp/lmparticle.sigs.txt