Skip to content

Commit

Permalink
get_ion_reference_data_for_chemsys: fix bug in str chemsys (#756)
Browse files Browse the repository at this point in the history
* get_ion_reference_data_for_chemsys: fix bug in str chemsys

* Update test_mprester.py

* linting

---------

Co-authored-by: Jason Munro <jmunro@lbl.gov>
  • Loading branch information
rkingsbury and munrojm committed May 15, 2023
1 parent a7097c7 commit 3ffecd2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mp_api/client/mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ def get_ion_reference_data_for_chemsys(
"""
ion_data = self.get_ion_reference_data()

if isinstance(chemsys, str):
chemsys = chemsys.split("-")
return [d for d in ion_data if d["data"]["MajElements"] in chemsys]

def get_ion_entries(
Expand Down
6 changes: 5 additions & 1 deletion tests/test_mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ def test_get_ion_entries(self, mpr):
ion_entry_data = mpr.get_ion_reference_data_for_chemsys("Ti-O-H")
ion_entries = mpr.get_ion_entries(pd, ion_entry_data)
assert len(ion_entries) == 5
assert all(isinstance(i, IonEntry) for i in ion_entries)
assert all([isinstance(i, IonEntry) for i in ion_entries])
bi_v_entry_data = mpr.get_ion_reference_data_for_chemsys("Bi-V")
bi_data = mpr.get_ion_reference_data_for_chemsys("Bi")
v_data = mpr.get_ion_reference_data_for_chemsys("V")
assert len(bi_v_entry_data) == len(bi_data) + v_data

# test an incomplete phase diagram
entries = mpr.get_entries_in_chemsys("Ti-O")
Expand Down

0 comments on commit 3ffecd2

Please sign in to comment.