Repository navigation
Description
Context
Three tests in `tests/test_enrichers.py` were silently broken for an unknown amount of time:
- `TestPeriodictableEnrichment::test_enrich_simple_formula` (`Al2O3`)
- `TestPeriodictableEnrichment::test_enrich_complex_formula` (`Lu1.8Y0.2SiO5`)
- `TestEnrichAll::test_enrich_all_with_periodictable` (`SiO2`)
They were hidden by the `uv.lock` mismatch (CI was failing at `uv sync --frozen` long before any test ran). Once CI was unblocked in #8, they surfaced and have been marked `@pytest.mark.xfail(strict=True)` as a placeholder so CI stays green while this is tracked here.
Root cause
`enrich_from_periodictable` in `src/pymat/enrichers.py` does:
```python
if not material.properties.mechanical.density and formula.density:
material.properties.mechanical.density = formula.density
```
`periodictable.formula(...).density` only returns a value for pure elements. For compounds it is always `None`:
```
$ python -c "import periodictable as pt; print([(f, pt.formula(f).density) for f in ['Al2O3','SiO2','Lu1.8Y0.2SiO5','Fe','Au']])"
[('Al2O3', None), ('SiO2', None), ('Lu1.8Y0.2SiO5', None), ('Fe', 7.874), ('Au', 19.3)]
```
So for any compound, the enricher silently does nothing on the density front. The tests assume the opposite.
Proposed fix
Add a density-from-composition calculator to `enrich_from_periodictable`. Two plausible approaches:
- Mass-fraction weighted density — iterate `formula.atoms`, weight each element's elemental density by its mass fraction. Rough but nonzero for most compounds.
- Look up a compound-density database (not from periodictable). Materials Project / Matminer have compound densities; we already integrate Materials Project via `enrich_from_matproj`, so this would be a natural extension there, not in the periodictable path.
Option 1 is the honest fix for this function's current promise. Option 2 sidesteps periodictable entirely.
Whichever path: once done, remove the `xfail` markers from `tests/test_enrichers.py` lines 16–41, 57–69, and 86–105.
Acceptance criteria
- `enrich_from_periodictable(Material(formula="Al2O3"))` sets a non-zero density
- `enrich_from_periodictable(Material(formula="Lu1.8Y0.2SiO5"))` sets density in the 6.5–7.5 g/cm³ range (matches LYSO target in existing test)
- `enrich_all(..., use_periodictable=True)` for `SiO2` sets a density
- `xfail(strict=True)` markers removed
- No regression in the other periodictable-dependent tests
Activity
fix(enricher): Material.molar_mass computed property + correct enrich…
gerchowl commentedon Apr 15, 2026
Fixed in #14 (merged to dev: e212891).
enrich_from_periodictabledocstring now explicitly says compound density is not derivable from periodictable (crystal packing required) and points atenrich_from_matprojfor that path.Material.molar_mass+molar_mass_qtyadded as@propertyaccessors parsingself.formulavia newpymat/elements.py(mirror ofmat-rs/src/elements.rs).docs/decisions/0001-derived-chemistry-properties-live-on-material.md) for why this lives onMaterialrather than in a newChemicalPropertiesgroup, and the upgrade trigger for revisiting that decision.Merge pull request #17 from MorePET/dev
docs: refresh README for 2.1.0 (molar_mass, PyPI install, fixed URLs)
feat!: 3.0 vis cutover — `properties.pbr` removed, `.vis` canonical, …