Skip to content

Serve the pre-built PD for property_data / conventional_unit_cell queries - #1126

Open
kavanase wants to merge 1 commit into
materialsproject:mainfrom
kavanase:enhance/serve-prebuilt-pd-with-property-data
Open

Serve the pre-built PD for property_data / conventional_unit_cell queries#1126
kavanase wants to merge 1 commit into
materialsproject:mainfrom
kavanase:enhance/serve-prebuilt-pd-with-property-data

Conversation

@kavanase

@kavanase kavanase commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1104 / #1121. get_entries_in_chemsys serves MP's pre-built (website) phase diagram for the default mixed GGA_GGA+U_R2SCAN thermo type, which guarantees every entry shares one energy scale. That was gated on not (property_data or conventional_unit_cell): requesting either flag instead fell through to re-applying MaterialsProjectDFTMixingScheme locally, which is slower (two downloads plus a local re-mix), drops entries the scheme cannot place, can anchor on a different hull than MP serves, and is nondeterministic across processes (materialsproject/pymatgen#3113) -- (I'll be suggesting a separate fix for that issue to pymatgen).

The result was that the same chemical system returned three different answers depending on which flags you passed. For Si-O:

call before after
get_entries_in_chemsys("Si-O") 422 entries 422
... property_data=["energy_above_hull"] 419 entries, different set + energy frame 422, identical
... conventional_unit_cell=True 405 entries, different set + energy frame 422, identical

Now the served phase diagram is used in all three cases and decorated afterwards:
property_data fields are fetched with a single materials.thermo.search and merged into entry.data, and conventional_unit_cell reshaping is applied to the returned entries.

Bug fix: conventional_unit_cell mis-scaled the r2SCAN mixing correction

Previously, get_entries reshaped entries by mutating the raw thermo doc dicts, scaling the energy, the composition, and any n_atoms-bearing energy adjustment. A ConstantEnergyAdjustment — how the GGA(+U)/r2SCAN mixing correction is stored — has no n_atoms, so it alone stayed at its primitive-cell (no conventional) value while everything around it scaled, silently shifting corrected energies.

On get_entries("H-O", additional_criteria={"thermo_types": ["GGA_GGA+U_R2SCAN"]}, conventional_unit_cell=True), 6 of the 11 reshaped entries came back wrong:

mp-24043-r2SCAN     -5.187195 -> -5.288040   delta -0.100845 eV/atom  (cell ratio 3)
mp-1212478-r2SCAN   -5.125967 -> -5.214010   delta -0.088043 eV/atom  (cell ratio 2)
mp-697111-r2SCAN    -5.192768 -> -5.268401   delta -0.075634 eV/atom  (cell ratio 2)
...

The magnitudes are exactly correction_per_atom x (ratio - 1) / ratio, i.e. entirely explained by the unscaled constant adjustment. Reshaping now goes through one helper, _get_conventional_cell_entry, which scales adjustments with pymatgen's own EnergyAdjustment.normalize — correct for constant, composition and temperature adjustments alike, which avoids these mismatches.

This affects get_entries, get_entry_by_material_id and get_entries_in_chemsys.

Changes

  • get_entries_in_chemsys: drop the property_data / conventional_unit_cell gate; attach property_data to the served entries post-hoc with one thermo.search call.
  • get_entries: build the ComputedStructureEntry first, then reshape the object via the shared helper.
  • Apply the reshaping once, after every branch, rather than forwarding the flag into the queries — so the mixing scheme still matches structures on the original cells, and every path gets the same (correct) scaling.

Tests

  • New test_get_entries_in_chemsys_decorated_served_pd: asserts the plain, property_data and conventional_unit_cell calls return the same served entry set on the same energy scale.
  • test_get_entries now also asserts the corrected energy per atom. The existing assertion used the uncorrected energy, which was scaled correctly (while corrected was now).

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy.
  • Tests added for new features/fixes.
  • If applicable, new classes/functions/modules have duecredit @due.dcite decorators to reference relevant papers by DOI (example)

…it_cell queries (with the additions/corrections applied afterwards); plus fixes and a test
@kavanase

Copy link
Copy Markdown
Contributor Author

Test failure seems unrelated to this PR?

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.

1 participant