Skip to content

Commit 44eca78

Browse files
Ensure MPIDs are returned by find_structure (#1026)
1 parent 5ecebec commit 44eca78

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

mp_api/client/routes/materials/materials.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,17 @@ def find_structure(
304304
use_document_model=False,
305305
).get("data")
306306

307-
if len(results) > 1: # type: ignore
307+
if not results:
308+
return []
309+
310+
material_ids = validate_ids([doc["material_id"] for doc in results])
311+
312+
if len(material_ids) > 1: # type: ignore
308313
if not allow_multiple_results:
309314
raise ValueError(
310315
"Multiple matches found for this combination of tolerances, but "
311316
"`allow_multiple_results` set to False."
312317
)
313-
return results # type: ignore
318+
return material_ids # type: ignore
314319

315-
return results[0]["material_id"] if (results and results[0]) else []
320+
return material_ids[0]

tests/test_mprester.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,14 @@ def test_get_structures(self, mpr):
9696
structs = mpr.get_structures("Mn-O", final=False)
9797
assert len(structs) > 0
9898

99-
@pytest.mark.skip(reason="Endpoint issues")
10099
def test_find_structure(self, mpr):
101100
path = os.path.join(MAPIClientSettings().TEST_FILES, "Si_mp_149.cif")
102-
with open(path) as file:
103-
data = mpr.find_structure(path)
104-
assert len(data) > 0
101+
data = mpr.find_structure(path)
102+
assert isinstance(data, str) and data == "mp-149"
105103

106-
s = CifParser(file).get_structures()[0]
107-
data = mpr.find_structure(s)
108-
assert len(data) > 0
104+
s = CifParser(path).get_structures()[0]
105+
data = mpr.find_structure(s)
106+
assert isinstance(data, str) and data == "mp-149"
109107

110108
def test_get_bandstructure_by_material_id(self, mpr):
111109
bs = mpr.get_bandstructure_by_material_id("mp-149")

0 commit comments

Comments
 (0)