Skip to content

Commit 0428266

Browse files
munrojmesoteric-ephemera
authored andcommitted
Initial commit of blessed tasks method
1 parent a796979 commit 0428266

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

mp_api/client/routes/materials/materials.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from emmet.core.settings import EmmetSettings
44
from emmet.core.symmetry import CrystalSystem
5+
from emmet.core.vasp.calc_types import RunType
56
from emmet.core.vasp.material import MaterialsDoc
67
from pymatgen.core.structure import Structure
78

@@ -318,3 +319,51 @@ def find_structure(
318319
return material_ids # type: ignore
319320

320321
return material_ids[0]
322+
323+
def get_blessed_calcs(
324+
self,
325+
run_type: RunType = RunType.R2SCAN,
326+
material_ids: Optional[list[str]] = None,
327+
uncorrected_energy: Optional[
328+
tuple[Optional[float], Optional[float]] | float
329+
] = None,
330+
num_chunks: int | None = None,
331+
chunk_size: int = 1000,
332+
):
333+
"""Get blessed calculation entries for a given material and run type.
334+
335+
Args:
336+
run_type (RunType): Calculation run type (e.g. GGA, GGA+U, R2SCAN, PBESol)
337+
material_ids (list[str]): List of material ID values
338+
uncorrected_energy (tuple[Optional[float], Optional[float]] | float): Tuple of minimum and maximum uncorrected DFT energy in eV/atom.
339+
Note that if a single value is passed, it will be used as the minimum and maximum.
340+
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
341+
chunk_size (int): Number of data entries per chunk.
342+
"""
343+
query_params: dict = {"run_type": str(run_type)}
344+
if material_ids:
345+
if isinstance(material_ids, str):
346+
material_ids = [material_ids]
347+
348+
query_params.update({"material_ids": ",".join(validate_ids(material_ids))})
349+
350+
if uncorrected_energy:
351+
if isinstance(uncorrected_energy, float):
352+
uncorrected_energy = (uncorrected_energy, uncorrected_energy)
353+
354+
query_params.update(
355+
{
356+
"uncorrected_energy_min": uncorrected_energy[0], # type: ignore
357+
"uncorrected_energy_max": uncorrected_energy[1], # type: ignore
358+
}
359+
)
360+
361+
results = self._query_resource(
362+
query_params,
363+
# fields=["material_ids", "entries"],
364+
suburl="blessed_tasks",
365+
parallel_param="material_ids" if material_ids else None,
366+
chunk_size=chunk_size,
367+
num_chunks=num_chunks,
368+
)
369+
return results.get("data")

0 commit comments

Comments
 (0)