Skip to content

feat(scripts): mirror Geant4 G4NistManager constants for scintillators (#167) - #200

Merged
gerchowl merged 2 commits into
mainfrom
feature/167-geant4-nist-mirror
May 6, 2026
Merged

gerchowl merged 2 commits into
mainfrom
feature/167-geant4-nist-mirror

Conversation

@gerchowl

@gerchowl gerchowl commented May 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds scripts/enrich_from_geant4_nist.py — sibling to enrich_from_wikidata.py (feat(scripts): extend Wikidata enricher to compounds + new properties (#158) #198), built on the shared curation helpers from feat(scripts): shared curation helpers (Phase 4 prep) #197. Cross-checks scintillator + plastic entries against Geant4 v11.2.0's G4NistMaterialBuilder.cc constants (density, mean excitation energy). Composition is intentionally skipped — py-mat has no schema field for element fractions yet.
  • Mirrors the Geant4 NIST table by hand into a pinned G4_NIST dict (v11.2.0, line-number citations into G4NistMaterialBuilder.cc). No runtime fetch: curation must be reproducible offline; minor versions are stable across these constants.
  • CONTROVERSIAL — extends the license allow-list with Geant4-SL (Geant4 Software License, BSD-like with attribution). Touches scripts/check_licenses.py, scripts/_curation.py, docs/data-policy.md, tests/test_check_licenses.py. The Geant4 SL is materially more permissive than proprietary-reference-only implies, and distinguishing it sets the right precedent for the BSD-like sources we'll hit next (HEPData mirrors, third-party NIST compilations). If a reviewer prefers collapsing into proprietary-reference-only (Option B in the issue brief), the revert is small.

What it covers

Category Matched Skipped
scintillators bgo, nai, nai.Tl, csi, csi.Tl, csi.Na, plastic_scint(+BC400, EJ200), pwo (density only) lyso, lyso.Ce, labr3
plastics pmma (→ G4_LUCITE), pc, ptfe, pe, nylon, delrin, pctfe peek, ultem, esr, pla, abs, petg, tpu, vespel, torlon

pwo matches G4_PbWO4 for density but Geant4 carries pot=0.0 (compute-from-composition sentinel) — the enricher recognizes that as mee_eV=None and skips the MEE writeback for it.

Behavior

  • Tighter tolerance than the Wikidata enricher: 1.0% (NIST reference values should be exact).
  • NEVER overwrites; NEVER adds new materials. Add-only writeback gated by --write.
  • --dry-run is a no-op accepted for CLI parity (this enricher is offline-only).

Test plan

  • uv run pytest tests/test_geant4_enrichment.py tests/test_curation_helpers.py -v — 30 passed
  • uv run pytest — 665 passed, 18 skipped
  • uv run ruff check . && uv run ruff format --check .
  • uv run python scripts/enrich_from_geant4_nist.py --key bgo --dry-run — clean comparison output
  • uv run python scripts/enrich_from_geant4_nist.py --dry-run — full report; 16 MISSING + 3 DIFF + 25 SKIP rows; no crashes

Closes #167

#167)

Adds scripts/enrich_from_geant4_nist.py — a sibling to enrich_from_wikidata.py
(#198) that cross-checks scintillator and plastic entries against the constants
shipped in Geant4 v11.2.0's G4NistMaterialBuilder.cc. Uses the shared curation
helpers from #197 (load_material_keys, build_source_row, writeback, fmt_delta).

Coverage:
- density (g/cm³, comparison + add-only writeback)
- mean_excitation_energy_eV (Geant4's mean ionisation potential — schema field
  added in #157), written into [<material>.nuclear]
- composition: skipped — py-mat has no schema field for element-fraction
  arrays today; documented in the module docstring

The Geant4 numbers are mirrored by hand into a G4_NIST dict pinned to v11.2.0,
with line-number citations into G4NistMaterialBuilder.cc. We do NOT fetch the
source at runtime — minor versions are stable across these constants and
curation tooling must be reproducible offline.

CONTROVERSIAL: extends the license allow-list with `Geant4-SL` (Geant4
Software License — BSD-like with attribution). Touches:
- scripts/check_licenses.py:ALLOWED
- scripts/_curation.py:LICENSE_ALLOWLIST
- docs/data-policy.md (new row in Allowed-licenses + clarifying paragraph)
- tests/test_check_licenses.py (parametrized accept-list)

Rationale for picking "extend the allow-list" over "use proprietary-reference-
only": the Geant4 SL is materially more permissive than the proprietary-
reference label implies (full redistribution allowed with attribution), and
distinguishing it explicitly sets the right precedent for the BSD-like sources
we'll hit next (HEPData mirrors, third-party NIST compilations). If a reviewer
prefers Option B (collapse into proprietary-reference-only), the change is a
3-line revert in _curation/check_licenses + a paragraph deletion in data-
policy.md. Calling this out so the decision is reviewable rather than buried.

Materials matched (10): bgo, nai, nai.Tl, csi, csi.Tl, csi.Na, plastic_scint,
plastic_scint.BC400, plastic_scint.EJ200, pwo (density only — G4_PbWO4 carries
pot=0.0, the compute-from-composition sentinel).

Plastics matched (7): pmma (→ G4_LUCITE), pc, ptfe, pe, nylon, delrin, pctfe.

Skipped with logged reason: lyso, lyso.Ce, labr3, peek, ultem, esr, pla,
abs, petg, tpu, vespel, torlon (and their grade-level descendants).

Tests: 10 new in tests/test_geant4_enrichment.py covering --dry-run,
--write add-only, no-overwrite-existing, comment-preserving round-trip,
license-allowlist canary, source-row sanity, and the PWO-MEE-is-None edge
case. Existing curation/Wikidata/check-licenses tests: 44 pass unchanged.

Closes #167
@gerchowl
gerchowl enabled auto-merge (squash) May 6, 2026 22:01
@gerchowl
gerchowl merged commit 4895376 into main May 6, 2026
18 checks passed
@vig-os-release-app vig-os-release-app Bot mentioned this pull request May 6, 2026
6 tasks
gerchowl added a commit that referenced this pull request May 6, 2026
…) (#203)

Adds `scripts/enrich_from_nist_webbook.py`, a comparison + add-only
writeback enricher for the five fluids that overlap between
`src/pymat/data/{gases,liquids}.toml` and the NIST Chemistry WebBook:
water (liquid), nitrogen, argon, helium, co2 (gas).

NIST has no JSON API; the script hits the IsoBar TSV endpoint
(`fluid.cgi?Action=Data&Type=IsoBar`) at a fixed pressure of 1.01325
bar (1 atm) over a 5 K range straddling the target temperature, then
selects the row matching the target. Targets: T=293.15 K for water
(liquid phase), T=298.15 K for the gases (STP). The (T, P) point and
the `Lemmon REFPROP equation of state` provenance are pinned in every
`_sources.note`.

Properties enriched (only those already in the schema):
  * mechanical.density          (kg/m³ → g/cm³)
  * thermal.specific_heat       (J/(g·K) → J/(kg·K))
  * thermal.thermal_conductivity (W/(m·K), identity)

Viscosity is in the WebBook payload but the runtime schema has no
viscosity field today — skipped rather than invented. Temperature
curves are out of scope (separate Phase-4 follow-up).

Behaviour mirrors the other enrichers (#197/#198/#200/#201):
  * Default: comparison-only (DIFF threshold 2%).
  * --write: ADD-ONLY; existing values are NEVER overwritten.
  * --dry-run / --key / --report flags identical to the siblings.
  * Uses `cached_get_text` (30-day TTL) so NIST's polite-traffic
    expectations are respected; uses `build_source_row` and
    `writeback` from `scripts/_curation.py`.

`_sources` rows: license = "PD-USGov" (allow-listed since #184), kind
= "handbook", citation includes the species, ref pins
`webbook.nist.gov:fluid.cgi?ID=<CAS>`. The report footer carries the
NIST AS-IS notice. Attribution is not legally required for PD-USGov,
and `LICENSES-DATA.md` only enumerates CC-BY/CC-BY-SA sources, so no
edit there.

Live run against the 5 fluids: 0 MISSING (every field is already
curated), 1 DIFF (helium thermal_conductivity at 2.1% vs NIST
0.15531 W/(m·K)). The other 14 cells are within 2% of NIST. All
existing values are preserved.

Tests: `tests/test_nist_webbook_enrichment.py` (11 cases) covers TSV
parsing, fixture-based --dry-run (offline via monkeypatched
`cached_get_text`), --write add-only, no-overwrite semantics, comment
round-trip, --report file output, and the PD-USGov allow-list
canary. Fixture `tests/fixtures/nist_webbook_water.txt` holds a
trimmed real WebBook response (header + 2 rows) so the test suite
runs fully offline.

Closes #159
@vig-os-release-app vig-os-release-app Bot mentioned this pull request May 7, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mirror Geant4 G4NistManager constants (BSD-like) — composition baselines

1 participant