Skip to content

Commit 2ff2e6a

Browse files
add exception if user inputs single mpid to get cohesive energy function
1 parent 2b16e4e commit 2ff2e6a

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

mp_api/client/mprester.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,13 @@ def get_cohesive_energy(
13591359
(dict[str,float]) : The cohesive energies (in eV/atom or eV/formula unit) for
13601360
each material, indexed by MPID.
13611361
"""
1362+
# Prevent user error
1363+
if isinstance(material_ids, str | MPID):
1364+
raise MPRestError(
1365+
"Input material IDs (even a single ID) as a list: "
1366+
f"`[{material_ids}]`"
1367+
)
1368+
13621369
entry_preference = {
13631370
k: i for i, k in enumerate(["GGA", "GGA_U", "SCAN", "R2SCAN"])
13641371
}

tests/client/test_mprester.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ def test_get_cohesive_energy(self):
512512
v == pytest.approx(e_coh["noserial"][k]) for k, v in e_coh["serial"].items()
513513
)
514514

515+
with pytest.raises(MPRestError, match="Input material IDs"):
516+
with MPRester() as mpr:
517+
mpr.get_cohesive_energy("mp-1")
518+
515519
@pytest.mark.parametrize(
516520
"chemsys, thermo_type",
517521
[

0 commit comments

Comments
 (0)