Repository navigation
Conversation
- Introduced `stopping_power` function to calculate stopping power in MeV*cm²/g. - Refactored existing mass stopping power functionality into `stopping_power.cpp` and `stopping_power.h`. - Updated stopping bindings to include new `stopping_power` function. - Enhanced error handling for particle and material processing. - Added support for both scalar and array inputs for energy, particle, and material.
…d-water-according-to-one-of-the-models_2
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Witold Nieć <witold.niec@gmail.com>
…d-water-according-to-one-of-the-models_2
Agent-Logs-Url: https://github.com/libamtrack/pyamtrack/sessions/822ea03a-8fdf-4b4f-82f0-927cb5daedbe Co-authored-by: witNie <180410451+witNie@users.noreply.github.com>
…d-water-according-to-one-of-the-models_2
…ding-to-one-of-the-models_2' of https://github.com/libamtrack/pyamtrack into 62-add-stopping-power-for-protons-in-liquid-water-according-to-one-of-the-models_2
…ve argument handling
Co-authored-by: Leszek Grzanka <leszek.grzanka@gmail.com> Signed-off-by: Witold Nieć <witold.niec@gmail.com>
…s with documentation
…ions with documentation
…artesian product option
…tesian product option
…ude particle argument and cartesian product option
…nd cartesian product option
…kflows, examples, and tests
…m-cc-to-python Signed-off-by: Piotr Pich <ppich@student.agh.edu.pl>
|
|
||
|
|
||
| const char* dose_from_fluence_doc = R"pbdoc( | ||
| Calculate absorbed dose from particle fluence. |
There was a problem hiding this comment.
| Calculate absorbed dose from particle fluence. | |
| Calculate absorbed dose in Gy from particle fluence. |
|
|
||
| Parameters | ||
| ---------- | ||
| momentum : float, int, list, or numpy.ndarray |
There was a problem hiding this comment.
Shouldn't we add units to momentum, like for energy, i.e. momentum_MeV_c_nucl ?
Check also whether we should use momentum per_u or per_nucl. I think in case of momentum per_u may be more natural.
|
|
||
|
|
||
| const char* energy_from_energy_per_amu_doc = R"pbdoc( | ||
| Calculate the total kinetic energy of a particle from its kinetic energy |
There was a problem hiding this comment.
if something has MeV/u unit then we cannot call it "energy per nucleon", its rather "energy per atomic mass unit"
Review of #230: "Port remaining converter functions"
Verdict: Request changes. CI is green, but the tests only compare each function with itself and only use protons, so they miss real physics bugs. Part of the diff also undoes the stopping-power work merged in #182. Blocking issues
Tests
DocstringsThe
Suggested wording: Other docstring fixes:
Code cleanup
Suggested order
🤖 Generated with Claude Code · model: Claude Opus 5.5 ( |
There was a problem hiding this comment.
🟡 Changes recommended
Several correctness defects (discarded Bethe-fallback result, wrong per-nucleon↔total energy conversion in three inverse converters, a mismatched docstring, and a broken example) need fixing before approval.
10 open issues
This example passes integer particle numbers (particle_proton = 1001,particle_carbon = 6012)… · New The keyword argument is namedenergy_MeV_u, but the docstring and the C++ implementation treat… · New These newly added converters (gamma_from_energy,energy_from_gamma,momentum_from_energy,… · Newfluence_from_doseis registered withdose_from_fluence_doc, so its docstring describes the… · NewAT_E_from_beta_singlealready returns energy per nucleon (MeV/u), butAT_E_MeV_u_from_E_MeV… · NewAT_E_from_gamma_singlereturns energy per nucleon (MeV/u), butAT_E_MeV_u_from_E_MeVdivides by… · NewAT_E_MeV_u_from_momentum_singlereturns energy per nucleon (MeV/u), butAT_E_MeV_u_from_E_MeV… · New The include-guard closing comment is misspelled asMOMEMTUM_FROM_ENERGYand is missing the_H… · New The Bethe fallback value is computed but never used. The previousresult = fallback_result;… · New This Doxygen description now says the particle may be a "Particle number (1000*Z + A)", but the… · New
What changed in this PR
This PR completes the port of the remaining libamtrack converter functions to the Python (nanobind) bindings, bringing them in line with the existing multi-argument/cartesian-product wrapper pattern. The converters now take a particle argument and total kinetic energy (energy_MeV), and the stopping-power wrappers are migrated from the deprecated AT_*_E_MeV_single single-value functions to the array-based AT_*_with_no functions, switching the public energy input to per-nucleon (energy_MeV_u). Supporting infrastructure, docs, examples, and CI smoke tests are updated accordingly.
Changes:
- Add 8 new converter bindings (gamma/momentum/energy-per-amu/dose/fluence conversions) and extend
beta_from_energy/energy_from_betato accept a particle and vectorized inputs. - Migrate stopping-power wrappers to
AT_*_with_noand change the energy input semantics to MeV/u, with matching validation/error-message updates. - Introduce
Ion::get_internal_particle_no()(replacingparticle_to_long.husage) and refresh tests, examples, docs, and CI invocations.
| File | Description |
|---|---|
| src/stopping/stopping_power.cpp | Switch to AT_*_with_no; MeV/u semantics — fallback result is no longer assigned back (bug) |
| src/stopping/stopping_power.h | Doc updates; particle description now inaccurately allows integer particle numbers |
| src/stopping/stopping_bindings.cpp | Rename kwarg to energy_MeV_u and update docstrings |
| src/converters/energy_from_beta.cpp | New particle-aware impl; uses wrong per-nucleon→total conversion |
| src/converters/energy_from_gamma.cpp | New converter; wrong per-nucleon→total conversion |
| src/converters/energy_from_momentum.cpp | New converter; wrong per-nucleon→total conversion |
| src/converters/beta_from_energy.cpp/.h | Particle-aware, vectorized rewrite |
| src/converters/gamma/momentum/*from_energy.*, energy(from|per)amu* | New forward/inverse converters |
| src/converters/converters_bindings.cpp | Register new converters; wrong docstring for fluence_from_dose; inconsistent momentum_from_energy kwarg |
| src/converters/momentum_from_energy.h | New header; misspelled include-guard comment |
| src/particles/{particles.h,ions/ion.h,particle_arguments.h} | Add get_internal_particle_no() and rewire validation |
| tests/test_{converters,function_behavior,multidim_input,stopping}.py | Adapt tests to new signatures; new converters remain untested |
| examples/*.ipynb | Update usage; new stopping.ipynb passes integer particles that the API rejects |
| docs/naming_convention.md, .github/workflows/* , scripts/build_linux.sh | Update signatures/invocations |
Review effort: Balanced
| "results_proton = stp.stopping_power(energies, particle=particle_proton, material=material)\n", | ||
| "results_carbon = stp.stopping_power(energies, particle=particle_carbon, material=material)" |
| m.def("dose_from_fluence", &dose_from_fluence, nb::arg("energy_MeV"), nb::arg("particle"), nb::arg("fluence_cm2"), | ||
| nb::arg("material") = 1, nb::arg("stopping_power_source") = 1, nb::arg("cartesian_product") = false, | ||
| dose_from_fluence_doc); | ||
|
|
||
| m.def("fluence_from_dose", &fluence_from_dose, nb::arg("energy_MeV"), nb::arg("particle"), nb::arg("dose"), | ||
| nb::arg("material") = 1, nb::arg("stopping_power_source") = 1, nb::arg("cartesian_product") = false, | ||
| dose_from_fluence_doc); |
| if (fallback_status != AT_Success || fallback_result < 0.0) { | ||
| throw std::invalid_argument("Stopping-power calculation failed for the selected source and material"); | ||
| } | ||
| result = fallback_result; | ||
| } |
| * internally for the stopping-power models. | ||
| * @param particle Particle object. | ||
| * @param energy_MeV_u Kinetic energy in MeV per nucleon. | ||
| * @param particle Particle number (1000*Z + A) or Ion object. |
Copilot review has found some mistakes like wrong naming scheme and wrong function names in few of them Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Piotr Pich <ppich@student.agh.edu.pl>

No description provided.