Repository navigation
feat(scripts): NIST WebBook (SRD 69) enricher for gases & liquids (#159) - #203
Merged
Merged
Conversation
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
gerchowl
enabled auto-merge (squash)
May 6, 2026 22:40
6 tasks
8 tasks done
gerchowl
added a commit
that referenced
this pull request
May 6, 2026
* feat(scripts): PubChem enricher for small-molecule scalars (#165) Adds `scripts/enrich_from_pubchem.py` — a cross-check enricher for pure compounds in the gases & liquids catalogs. PubChem (NCBI/NLM, PD-USGov) is the lane this fills: per-compound MW, melting point, boiling point, and (parseable-when-clean) density. NIST WebBook (#159, PR #203) stays the primary populator for fluid thermophysical properties; PubChem is only the sanity check + the source of MP for elements/gases that NIST WebBook doesn't cleanly surface. ## Properties enriched - `thermal.melting_point` (°C → degC) — primary writeback target. Clean for every CID we ship. - `mechanical.density` (g/cm³) — comparison only for gases; add-only writeback for liquids. ## Properties dropped (schema gap, documented) - `molecular_weight_g_mol` — not in `MechanicalProperties` today. - `thermal.boiling_point` — not in `ThermalProperties` today. Both are still surfaced in the report and folded into the `_sources` note (in K) so curators see what PubChem said. Adding the schema fields is out of scope for #165. ## Judgment calls - **Density string parser**: PubChem `Density` strings are a mix of clean values (`"0.9950 g/cu cm at 25 °C"`), wrong-unit values (`"1.251 g/L"`), table refs (`"[Table#8152]"`), and prose (`"VAPOR DENSITY @ NORMAL TEMP APPROX SAME AS AIR"`). Per the issue scope guard, the regex is conservative: only `<float> g/cu cm` and `<float> g/cm3` patterns match. Everything else returns None and surfaces as `(no value)` in the report. - **Gas density gating**: PubChem density entries for gases are mostly the cryogenic-liquid phase, not the STP gas density we store. Comparing always flags DIFF (e.g. nitrogen 0.001165 vs PubChem 0.311 — PubChem's critical density). `density_writeback=False` on every gas entry blocks the writeback path so we never overwrite an STP value with a cryo value. Comparison still runs and reports the DIFF. - **CID coverage**: water, glycerol (liquids); nitrogen, argon, helium, CO2, methane (gases). Ethanol is in the issue's suggested CID list but `liquids.ethanol` doesn't exist in the catalog yet, so it's excluded; air is a mixture and PubChem isn't a meaningful source. Oxygen/hydrogen/neon/xenon left out for the initial scope. - **Tolerance**: 5% relative diff for DIFF flag (looser than NIST WebBook's 2%) — PubChem aggregates many primary sources at varying reference temperatures. - **License tag**: `PD-USGov`. Per NCBI policies PubChem data is freely usable including commercially; PD-USGov is the closest fit in our allow-list. Verified via the existing `LICENSE_ALLOWLIST` canary test. ## Live results (full run, fresh fetch) - water: density OK (0.3%), MP OK - glycerol: density OK (0.0%), MP OK (0.6%) - nitrogen: density DIFF (expected — STP vs critical), MP missing → would-write - argon, helium, co2, methane: density (no value), MP missing → would-write Closes #165. * fix(scripts): pre-commit hooks on PubChem fixture (#165) Two CI failures on the captured PubChem PUG-View fixture (`tests/fixtures/pubchem_water.json`): * `end-of-file-fixer`: append trailing newline. * `typos`: rewrote PubChem's `"ANID"` (annotation node ID) to `"AND"` inside the JSON response. Add `ANID = "ANID"` to `.typos.toml` so the fixture stays byte-identical to what PubChem actually serves — rewriting it would silently diverge from real responses.
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_nist_webbook.py: a comparison + add-only enricher for the five fluids overlapping betweensrc/pymat/data/{gases,liquids}.tomland NIST Chemistry WebBook (SRD 69) —water,nitrogen,argon,helium,co2. New fluids and temperature curves are explicitly out of scope (Phase 5 / a follow-up).webbook.nist.gov/cgi/fluid.cgi?Action=Data&Type=IsoBarreturns a clean TSV; we straddle the target temperature with a 5 K range to dodge the WebBook's "Range Error" page, then select the matching row.(T, P)= (293.15 K, 1.01325 bar) for water (liquid phase) and (298.15 K, 1.01325 bar) for the gases — pinned in every_sources.notealong withLemmon REFPROP equation of state.mechanical.density,thermal.specific_heat,thermal.thermal_conductivity. Viscosity is dropped (no schema field). Behaviour mirrors PRs feat(scripts): shared curation helpers (Phase 4 prep) #197/feat(scripts): extend Wikidata enricher to compounds + new properties (#158) #198/feat(scripts): mirror Geant4 G4NistManager constants for scintillators (#167) #200/feat(scripts): refractiveindex.info enricher for n,k dispersion (#164) #201:cached_get_textfor fetches,build_source_row+writebackfor the comment-preserving TOML edit, ADD-ONLY semantics, identical CLI shape (--key/--write/--dry-run/--report)._sourcesrows:license = "PD-USGov",kind = "handbook", refwebbook.nist.gov:fluid.cgi?ID=<CAS>. Report footer carries the NIST AS-IS notice.LICENSES-DATA.mdonly enumerates CC-BY/CC-BY-SA sources, so no edit there (issue's "skip if PD-USGov isn't listed" branch).Live comparison run (5 fluids): 0 MISSING, 1 DIFF (helium thermal_conductivity at 2.1%, just over the 2% threshold). The remaining 14 cells are within 2% of NIST; existing curator values are preserved.
Closes #159
Test plan
pytest tests/test_nist_webbook_enrichment.py tests/test_curation_helpers.py— 31 passing (11 new + 20 helpers).pytest --ignore=tests/test_visual_compare.py— 648 passed, 35 skipped (visual_compare ignored: needs PIL, unrelated).ruff check .andruff format --check .— clean.python scripts/enrich_from_nist_webbook.py— 5 fluids fetched, comparison report rendered, no TOML mutation in default mode.scripts/check_licenses.py— passes.