Skip to content

Commit d744040

Browse files
ensure find_structure works with doc model false
1 parent 4af3a61 commit d744040

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

mp_api/client/routes/materials/materials.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,13 @@ def find_structure(
242242
comparator=ElementComparator(),
243243
)
244244

245-
matches = []
245+
matches: list[str] = []
246246
for doc in mat_docs:
247-
if matcher.fit(s, doc.structure):
248-
matches.append(doc.material_id)
247+
if matcher.fit(
248+
s,
249+
doc.structure if self.use_document_model else Structure.from_dict(doc["structure"]), # type: ignore[union-attr]
250+
):
251+
matches.append(doc.material_id.string if self.use_document_model else doc["material_id"]) # type: ignore[union-attr]
249252
if len(matches) >= max_matches:
250253
break
251254

tests/client/test_mprester.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def test_get_structures(self, mpr):
102102
structs = mpr.get_structures("Mn-O", final=False)
103103
assert len(structs) > 0
104104

105-
def test_find_structure(self, mpr):
105+
def test_find_structure(
106+
self,
107+
):
106108
cif_str = """# mp-111
107109
data_Ne
108110
_symmetry_space_group_name_H-M 'P 1'
@@ -139,11 +141,12 @@ def test_find_structure(self, mpr):
139141
f.write(cif_str)
140142
f.seek(0)
141143

142-
for struct_or_path in (
143-
temp_file.name,
144-
struct_from_cif,
145-
):
146-
data = mpr.find_structure(struct_or_path)
144+
for struct_or_path, use_document_model in [
145+
(temp_file.name, True),
146+
(struct_from_cif, False),
147+
]:
148+
with MPRester(use_document_model=use_document_model) as mpr:
149+
data = mpr.find_structure(struct_or_path)
147150
assert isinstance(data, str) and data == "mp-111"
148151

149152
f.close()

0 commit comments

Comments
 (0)