From 00c32b08a47f5f8406c92c2add641148384590f1 Mon Sep 17 00:00:00 2001 From: munrojm Date: Mon, 8 Jan 2024 14:40:55 -0800 Subject: [PATCH 1/3] Initial commit of blessed tasks method --- mp_api/client/routes/materials/materials.py | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/mp_api/client/routes/materials/materials.py b/mp_api/client/routes/materials/materials.py index bf5d20e3b..41a3f84b4 100644 --- a/mp_api/client/routes/materials/materials.py +++ b/mp_api/client/routes/materials/materials.py @@ -1,9 +1,11 @@ from __future__ import annotations import warnings +from typing import Optional from emmet.core.settings import EmmetSettings from emmet.core.symmetry import CrystalSystem +from emmet.core.vasp.calc_types import RunType from emmet.core.vasp.material import MaterialsDoc from pymatgen.core.structure import Structure @@ -321,3 +323,51 @@ def find_structure( return results[0]["material_id"] else: return [] + + def get_blessed_calcs( + self, + run_type: RunType = RunType.R2SCAN, + material_ids: Optional[list[str]] = None, + uncorrected_energy: Optional[ + tuple[Optional[float], Optional[float]] | float + ] = None, + num_chunks: int | None = None, + chunk_size: int = 1000, + ): + """Get blessed calculation entries for a given material and run type. + + Args: + run_type (RunType): Calculation run type (e.g. GGA, GGA+U, R2SCAN, PBESol) + material_ids (list[str]): List of material ID values + uncorrected_energy (tuple[Optional[float], Optional[float]] | float): Tuple of minimum and maximum uncorrected DFT energy in eV/atom. + Note that if a single value is passed, it will be used as the minimum and maximum. + num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible. + chunk_size (int): Number of data entries per chunk. + """ + query_params: dict = {"run_type": str(run_type)} + if material_ids: + if isinstance(material_ids, str): + material_ids = [material_ids] + + query_params.update({"material_ids": ",".join(validate_ids(material_ids))}) + + if uncorrected_energy: + if isinstance(uncorrected_energy, float): + uncorrected_energy = (uncorrected_energy, uncorrected_energy) + + query_params.update( + { + "uncorrected_energy_min": uncorrected_energy[0], # type: ignore + "uncorrected_energy_max": uncorrected_energy[1], # type: ignore + } + ) + + results = self._query_resource( + query_params, + # fields=["material_ids", "entries"], + suburl="blessed_tasks", + parallel_param="material_ids" if material_ids else None, + chunk_size=chunk_size, + num_chunks=num_chunks, + ) + return results.get("data") From 02e91e5f0e6e56410868cce6d7f958ea1657ca5c Mon Sep 17 00:00:00 2001 From: munrojm Date: Wed, 10 Jan 2024 07:45:16 -0800 Subject: [PATCH 2/3] Function name change --- mp_api/client/routes/materials/materials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mp_api/client/routes/materials/materials.py b/mp_api/client/routes/materials/materials.py index 41a3f84b4..59b82331d 100644 --- a/mp_api/client/routes/materials/materials.py +++ b/mp_api/client/routes/materials/materials.py @@ -324,7 +324,7 @@ def find_structure( else: return [] - def get_blessed_calcs( + def get_blessed_entries( self, run_type: RunType = RunType.R2SCAN, material_ids: Optional[list[str]] = None, From de7e2e62a4db21d11706f6fa9ab04f14b4d0f28a Mon Sep 17 00:00:00 2001 From: Jason Munro Date: Thu, 29 Feb 2024 10:07:59 -0800 Subject: [PATCH 3/3] Linting --- mp_api/client/routes/materials/materials.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mp_api/client/routes/materials/materials.py b/mp_api/client/routes/materials/materials.py index c27434267..e280d27e8 100644 --- a/mp_api/client/routes/materials/materials.py +++ b/mp_api/client/routes/materials/materials.py @@ -1,7 +1,5 @@ from __future__ import annotations -from typing import Optional - from emmet.core.settings import EmmetSettings from emmet.core.symmetry import CrystalSystem from emmet.core.vasp.calc_types import RunType @@ -313,10 +311,8 @@ def find_structure( def get_blessed_entries( self, run_type: RunType = RunType.R2SCAN, - material_ids: Optional[list[str]] = None, - uncorrected_energy: Optional[ - tuple[Optional[float], Optional[float]] | float - ] = None, + material_ids: list[str] | None = None, + uncorrected_energy: tuple[float | None, float | None] | float | None = None, num_chunks: int | None = None, chunk_size: int = 1000, ):