Skip to content

Commit e45342f

Browse files
add warning to nomad lookup + test against regression
1 parent 418cba1 commit e45342f

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

mp_api/client/mprester.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,21 +1258,41 @@ def get_charge_density_from_material_id(
12581258
task_id = latest_doc["task_id"]
12591259
return self.get_charge_density_from_task_id(task_id, inc_task_doc)
12601260

1261-
def get_download_info(self, material_ids, calc_types=None, file_patterns=None):
1261+
def get_download_info(
1262+
self,
1263+
material_ids: str | MPID | list[str | MPID],
1264+
calc_types: list[str | CalcType] | None = None,
1265+
file_patterns: list[str] | None = None,
1266+
):
12621267
"""Get a list of URLs to retrieve raw VASP output files from the NoMaD repository
12631268
Args:
1264-
material_ids (list): list of material identifiers (mp-id's)
1265-
task_types (list): list of task types to include in download (see CalcType Enum class)
1269+
material_ids (str or MPID, or list thereof): list of material identifiers (mp-id's)
1270+
calc_types (list of str or CalcType): list of calc types to include in download (see CalcType Enum class)
12661271
file_patterns (list): list of wildcard file names to include for each task
12671272
Returns:
12681273
a tuple of 1) a dictionary mapping material_ids to task_ids and
12691274
calc_types, and 2) a list of URLs to download zip archives from
12701275
NoMaD repository. Each zip archive will contain a manifest.json with
12711276
metadata info, e.g. the task/external_ids that belong to a directory.
12721277
"""
1278+
warnings.warn(
1279+
"Full downloads of raw data are being transitioned to "
1280+
"Materials Project's AWS S3 OpenData buckets. "
1281+
"These features for accessing legacy raw data via NOMAD "
1282+
"are maintained but may not be supported in the future.",
1283+
category=MPRestWarning,
1284+
stacklevel=2,
1285+
)
1286+
12731287
# task_id's correspond to NoMaD external_id's
1288+
if isinstance(material_ids, str | MPID):
1289+
material_ids = [material_ids]
1290+
12741291
calc_types = (
1275-
[t.value for t in calc_types if isinstance(t, CalcType)]
1292+
[
1293+
t.value if isinstance(t, CalcType) else CalcType(t).value
1294+
for t in calc_types
1295+
]
12761296
if calc_types
12771297
else []
12781298
)

tests/client/test_mprester.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,43 @@ def test_oxygen_evolution_bad_input(self, mpr):
649649
with pytest.raises(ValueError, match="No available insertion electrode data"):
650650
_ = mpr.get_oxygen_evolution("mp-2207", "Al")
651651

652+
def test_nomad_integration(self, mpr):
653+
# No particular reason for this MPID other than that it exists in NOMAD.
654+
target_mpid = "mp-10018"
655+
with pytest.warns(
656+
MPRestWarning, match="Full downloads of raw data are being transitioned"
657+
), pytest.warns(
658+
MPRestWarning, match="the following ids are not found on NOMAD"
659+
):
660+
calc_type_map, nomad_urls = mpr.get_download_info(
661+
target_mpid, file_patterns=["some_pattern"]
662+
)
663+
assert all(
664+
isinstance(entry["task_id"], MPID)
665+
and isinstance(entry["calc_type"], CalcType)
666+
for entry in calc_type_map[target_mpid]
667+
)
668+
assert all(
669+
url.startswith("https://nomad-lab.eu/prod/rae/api/raw/query")
670+
and "file_pattern=some_pattern" in url
671+
for url in nomad_urls
672+
)
673+
674+
calc_type_map, nomad_urls = mpr.get_download_info(
675+
[MPID(target_mpid)], calc_types=["GGA Deformation"]
676+
)
677+
assert all(
678+
isinstance(entry["task_id"], MPID)
679+
and entry["calc_type"].value == "GGA Deformation"
680+
for entry in calc_type_map[target_mpid]
681+
)
682+
assert all(
683+
url.startswith(
684+
"https://nomad-lab.eu/prod/rae/api/raw/query?external_id="
685+
)
686+
for url in nomad_urls
687+
)
688+
652689
def test_warnings_exceptions(self, monkeypatch: pytest.MonkeyPatch):
653690
from mp_api.client.core.settings import MAPI_CLIENT_SETTINGS
654691

0 commit comments

Comments
 (0)