Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion mp_api/client/mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,8 +1376,19 @@ def get_entries_in_chemsys(
str(doc["material_id"]): {p: doc[p] for p in property_data}
for doc in docs
}
no_doc = dict.fromkeys(property_data)
missing = []
for entry in entries: # served entries carry `material_id`
entry.data |= props[str(entry.data["material_id"])]
material_id = str(entry.data["material_id"])
if material_id not in props:
missing.append(material_id)
entry.data |= props.get(material_id, no_doc)
if missing: # e.g. materials removed since an older `db_version`
logger.warning(
f"No thermo document was found for {', '.join(missing)} in "
f"database version {self.current_db_version} (used for REST "
"queries), so their `property_data` fields are None."
)

if entries is None:
# MP has no pre-built diagram for this system, so redo the mixing here as MP does when
Expand Down
21 changes: 21 additions & 0 deletions tests/client/test_mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,27 @@ def test_get_entries_in_chemsys_decorated_served_pd(self, mpr):
assert entry.energy_per_atom == pytest.approx(energy, abs=1e-8)
assert entry.composition.reduced_formula == formula

def test_get_entries_in_chemsys_decorated_served_pd_missing_docs(self, caplog):
"""
With an older ``db_version``, the phase diagram is read from that version but
``property_data`` from the REST API (current version), which lacks some of its
materials, e.g. ``mp-1275385`` in the v2026.04.13 Co-O phase diagram. These get
None rather than raising a ``KeyError``.
"""
with MPRester(db_version="2026.04.13") as mpr:
with caplog.at_level(logging.WARNING, logger="mp_api.client"):
entries = mpr.get_entries_in_chemsys(
"Co-O", property_data=["energy_above_hull"]
)
missing = {
str(e.data["material_id"])
for e in entries
if e.data["energy_above_hull"] is None
}
assert "mp-1275385" in missing
assert len(missing) < len(entries)
assert "No thermo document was found for mp-1275385" in caplog.text

@pytest.mark.skipif(
contribs_client is None,
reason="`pip install 'mp-api[contribs]'` to use pourbaix functionality.",
Expand Down
Loading