Repository navigation
feat(scripts): mirror Geant4 G4NistManager constants for scintillators (#167) - #200
Merged
Merged
Conversation
#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
enabled auto-merge (squash)
May 6, 2026 22:01
6 tasks
5 tasks done
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
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scripts/enrich_from_geant4_nist.py— sibling toenrich_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'sG4NistMaterialBuilder.ccconstants (density, mean excitation energy). Composition is intentionally skipped — py-mat has no schema field for element fractions yet.G4_NISTdict (v11.2.0, line-number citations intoG4NistMaterialBuilder.cc). No runtime fetch: curation must be reproducible offline; minor versions are stable across these constants.Geant4-SL(Geant4 Software License, BSD-like with attribution). Touchesscripts/check_licenses.py,scripts/_curation.py,docs/data-policy.md,tests/test_check_licenses.py. The Geant4 SL is materially more permissive thanproprietary-reference-onlyimplies, 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 intoproprietary-reference-only(Option B in the issue brief), the revert is small.What it covers
pwomatchesG4_PbWO4for density but Geant4 carriespot=0.0(compute-from-composition sentinel) — the enricher recognizes that asmee_eV=Noneand skips the MEE writeback for it.Behavior
1.0%(NIST reference values should be exact).--write.--dry-runis 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 passeduv run pytest— 665 passed, 18 skippeduv run ruff check . && uv run ruff format --check .uv run python scripts/enrich_from_geant4_nist.py --key bgo --dry-run— clean comparison outputuv run python scripts/enrich_from_geant4_nist.py --dry-run— full report; 16 MISSING + 3 DIFF + 25 SKIP rows; no crashesCloses #167