Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retrieve prebuild phase diagrams from OpenData #961

Merged
merged 3 commits into from
Jan 8, 2025
Merged
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
2 changes: 1 addition & 1 deletion mp_api/client/mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def get_material_id_references(self, material_id: str) -> list[str]:
Returns:
List of BibTeX references ([str])
"""
docs = self.provenance.search(material_ids=material_id)
docs = self.materials.provenance.search(material_ids=material_id)

if not docs:
return []
Expand Down
21 changes: 9 additions & 12 deletions mp_api/client/routes/materials/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
from emmet.core.thermo import ThermoDoc, ThermoType
from monty.json import MontyDecoder
from pymatgen.analysis.phase_diagram import PhaseDiagram
from pymatgen.core import Element

Expand Down Expand Up @@ -163,18 +164,14 @@ def get_phase_diagram_from_chemsys(
)

sorted_chemsys = "-".join(sorted(chemsys.split("-")))
phase_diagram_id = f"{sorted_chemsys}_{t_type}"

response = self._query_resource(
criteria={"phase_diagram_ids": phase_diagram_id},
fields=["phase_diagram"],
suburl="phase_diagram/",
use_document_model=False,
num_chunks=1,
chunk_size=1,
).get("data", [{}])

pd = response[0].get("phase_diagram", None)
phdiag_id = f"thermo_type={t_type}/chemsys={sorted_chemsys}"
version = self.db_version.replace(".", "-")
obj_key = f"objects/{version}/phase-diagrams/{phdiag_id}.jsonl.gz"
pd = self._query_open_data(
bucket="materialsproject-build",
key=obj_key,
decoder=MontyDecoder().decode,
)[0][0].get("phase_diagram")

# Ensure el_ref keys are Element objects for PDPlotter.
# Ensure qhull_data is a numpy array
Expand Down
1 change: 1 addition & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"materials_electronic_structure_dos",
"materials_substrates",
"materials_synthesis",
"materials_similarity",
]

special_resters = ["materials_charge_density", "doi"]
Expand Down
11 changes: 3 additions & 8 deletions tests/test_mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ def test_get_entries(self, mpr):
assert e.data.get("energy_above_hull", None) is not None

# Conventional structure
formula = "BiFeO3"
entry = mpr.get_entry_by_material_id(
"mp-22526", inc_structure=True, conventional_unit_cell=True
)[0]
entry = mpr.get_entry_by_material_id("mp-22526", conventional_unit_cell=True)[1]

s = entry.structure
assert pytest.approx(s.lattice.a) == s.lattice.b
Expand All @@ -152,9 +149,7 @@ def test_get_entries(self, mpr):
assert pytest.approx(s.lattice.gamma) == 120

# Ensure energy per atom is same
prim = mpr.get_entry_by_material_id(
"mp-22526", inc_structure=True, conventional_unit_cell=False
)[0]
prim = mpr.get_entry_by_material_id("mp-22526", conventional_unit_cell=False)[1]

s = prim.structure
assert pytest.approx(s.lattice.a) == s.lattice.b
Expand Down Expand Up @@ -327,7 +322,7 @@ def test_large_list(self, mpr):
chunk_size=1000, num_chunks=10, fields=["material_id"]
)
]
docs = mpr.summary.search(material_ids=mpids, fields=["material_ids"])
docs = mpr.summary.search(material_ids=mpids, fields=["material_id"])
assert len(docs) == 10000

def test_get_api_key_endpoint_from_env_var(self, monkeypatch: pytest.MonkeyPatch):
Expand Down
Loading