Skip to content

Commit

Permalink
Disable nested monty decode for some data (#784)
Browse files Browse the repository at this point in the history
* Disable nested monty decode for some data

* Linting

* Test fixes

* Linting

* Update get_entries test

* More linting
  • Loading branch information
munrojm committed Apr 27, 2023
1 parent 6316599 commit d5190ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions mp_api/client/mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ def __init__(
endpoint=endpoint,
include_user_agent=include_user_agent,
session=self.session,
monty_decode=monty_decode,
monty_decode=monty_decode
if cls not in [TaskRester, ProvenanceRester] # type: ignore
else False, # Disable monty decode on nested data which may give errors
use_document_model=use_document_model,
headers=self.headers,
) # type: BaseRester
Expand Down Expand Up @@ -594,7 +596,8 @@ def get_entries(
entry_dict["composition"][element] *= site_ratio

for correction in entry_dict["energy_adjustments"]:
correction["n_atoms"] *= site_ratio
if "n_atoms" in correction:
correction["n_atoms"] *= site_ratio

entry = (
ComputedStructureEntry.from_dict(entry_dict)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def test_get_entries(self, mpr):

s = prim.structure
assert pytest.approx(s.lattice.a) == s.lattice.b
assert pytest.approx(s.lattice.a) != s.lattice.c
assert pytest.approx(s.lattice.a) == s.lattice.c
assert pytest.approx(s.lattice.alpha) == s.lattice.beta
assert pytest.approx(s.lattice.alpha) != s.lattice.gamma
assert pytest.approx(s.lattice.alpha) == s.lattice.gamma

# Additional criteria
entry = mpr.get_entries(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@ def test_get_phase_diagram_from_chemsys():
# Test that a phase diagram is returned

assert isinstance(
ThermoRester().get_phase_diagram_from_chemsys("Hf-Pm"), PhaseDiagram
ThermoRester().get_phase_diagram_from_chemsys("Hf-Pm", thermo_type="GGA_GGA+U"),
PhaseDiagram,
)

0 comments on commit d5190ff

Please sign in to comment.