Skip to content

Commit 00c32b0

Browse files
author
munrojm
committed
Initial commit of blessed tasks method
1 parent 8a84e76 commit 00c32b0

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

mp_api/client/routes/materials/materials.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import annotations
22

33
import warnings
4+
from typing import Optional
45

56
from emmet.core.settings import EmmetSettings
67
from emmet.core.symmetry import CrystalSystem
8+
from emmet.core.vasp.calc_types import RunType
79
from emmet.core.vasp.material import MaterialsDoc
810
from pymatgen.core.structure import Structure
911

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

0 commit comments

Comments
 (0)