From 9ecbee649ea1de4a5fc1991998c6ccbc1cabf479 Mon Sep 17 00:00:00 2001 From: Jason Munro Date: Wed, 13 Jul 2022 14:32:34 -0700 Subject: [PATCH] Add option to pass potcar hash dict to validation --- .../emmet/builders/vasp/task_validator.py | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/emmet-builders/emmet/builders/vasp/task_validator.py b/emmet-builders/emmet/builders/vasp/task_validator.py index 0a358d030d..9aeca7ba18 100644 --- a/emmet-builders/emmet/builders/vasp/task_validator.py +++ b/emmet-builders/emmet/builders/vasp/task_validator.py @@ -6,6 +6,7 @@ from emmet.builders.settings import EmmetBuildSettings from emmet.core.vasp.task_valid import TaskDocument +from emmet.core.vasp.calc_types.enums import CalcType from emmet.core.vasp.validation import DeprecationMessage, ValidationDoc @@ -14,6 +15,7 @@ def __init__( self, tasks: Store, task_validation: Store, + potcar_hashes: Optional[Dict[CalcType, Dict[str, str]]] = None, settings: Optional[EmmetBuildSettings] = None, query: Optional[Dict] = None, **kwargs, @@ -24,29 +26,38 @@ def __init__( Args: tasks: Store of task documents task_validation: Store of task_types for tasks + potcar_hashes: Optional dictionary of potcar hash data. + Mapping is calculation type -> potcar symbol -> hash value. """ self.tasks = tasks self.task_validation = task_validation self.settings = EmmetBuildSettings.autoload(settings) self.query = query self.kwargs = kwargs - self._potcar_hashes = None + self.potcar_hashes = potcar_hashes # Set up potcar cache if appropriate if self.settings.VASP_VALIDATE_POTCAR_HASHES: - from pymatgen.io.vasp.inputs import PotcarSingle + if not self.potcar_hashes: - potcar_hashes = defaultdict(dict) # type: dict + from pymatgen.io.vasp.inputs import PotcarSingle - for (calc_type, input_set) in self.settings.VASP_DEFAULT_INPUT_SETS.items(): - functional = input_set.CONFIG["POTCAR_FUNCTIONAL"] - for potcar_symbol in input_set.CONFIG["POTCAR"].values(): - potcar = PotcarSingle.from_symbol_and_functional( - symbol=potcar_symbol, functional=functional - ) - potcar_hashes[calc_type][potcar_symbol] = potcar.get_potcar_hash() + hashes = defaultdict(dict) # type: dict - self._potcar_hashes = potcar_hashes + for ( + calc_type, + input_set, + ) in self.settings.VASP_DEFAULT_INPUT_SETS.items(): + functional = input_set.CONFIG["POTCAR_FUNCTIONAL"] + for potcar_symbol in input_set.CONFIG["POTCAR"].values(): + potcar = PotcarSingle.from_symbol_and_functional( + symbol=potcar_symbol, functional=functional + ) + hashes[calc_type][potcar_symbol] = potcar.get_potcar_hash() + + self.potcar_hashes = potcar_hashes + else: + self.potcar_hashes = None super().__init__( source=tasks, @@ -78,7 +89,7 @@ def unary_function(self, item): input_sets=self.settings.VASP_DEFAULT_INPUT_SETS, LDAU_fields=self.settings.VASP_CHECKED_LDAU_FIELDS, max_allowed_scf_gradient=self.settings.VASP_MAX_SCF_GRADIENT, - potcar_hashes=self._potcar_hashes, + potcar_hashes=self.potcar_hashes, ) bad_tags = list(set(task_doc.tags).intersection(self.settings.DEPRECATED_TAGS))