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

Fix el_refs dict keys in PhaseDiagram objects #730

Merged
merged 3 commits into from
Jan 19, 2023
Merged
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
17 changes: 15 additions & 2 deletions mp_api/client/routes/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from mp_api.client.core.utils import validate_ids
from emmet.core.thermo import ThermoDoc, ThermoType
from pymatgen.analysis.phase_diagram import PhaseDiagram
from pymatgen.core import Element


class ThermoRester(BaseRester[ThermoDoc]):
Expand Down Expand Up @@ -173,6 +174,18 @@ def get_phase_diagram_from_chemsys(
use_document_model=False,
num_chunks=1,
chunk_size=1,
).get("data")
).get("data", [{}])

return response[0]["phase_diagram"] # type: ignore
pd = response[0].get("phase_diagram", None)

# Ensure el_ref keys are Element objects for PDPlotter.
# This should be fixed in pymatgen
if pd:
for key, entry in list(pd.el_refs.items()):
if not isinstance(key, str):
break

pd.el_refs[Element(str(key))] = entry
pd.el_refs.pop(key)

return pd # type: ignore