From a9a66226dbc424c482d06ff3839eeddd44e78d8d Mon Sep 17 00:00:00 2001 From: esoteric-ephemera Date: Wed, 20 Mar 2024 14:39:09 -0700 Subject: [PATCH] fix materials docs / build --- emmet-builders/emmet/builders/vasp/materials.py | 6 ++++-- emmet-core/emmet/core/tasks.py | 12 +++++++++--- emmet-core/emmet/core/vasp/material.py | 10 +++++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/emmet-builders/emmet/builders/vasp/materials.py b/emmet-builders/emmet/builders/vasp/materials.py index d54ff32c1b..b7b82673d5 100644 --- a/emmet-builders/emmet/builders/vasp/materials.py +++ b/emmet-builders/emmet/builders/vasp/materials.py @@ -181,7 +181,7 @@ def get_items(self) -> Iterator[List[Dict]]: invalid_ids = set() projected_fields = [ - "last_updated", + # "last_updated", "completed_at", "task_id", "formula_pretty", @@ -195,9 +195,11 @@ def get_items(self) -> Iterator[List[Dict]]: "input.structure", # needed for entry from task_doc "output.energy", + "calcs_reversed.output.energy", "input.is_hubbard", "input.hubbards", - "input.potcar_spec", + "calcs_reversed.input.potcar_spec", + "calcs_reversed.output.structure", # needed for transform deformation structure back for grouping "transformations", # misc info for materials doc diff --git a/emmet-core/emmet/core/tasks.py b/emmet-core/emmet/core/tasks.py index 20c2b4f116..66bb650702 100644 --- a/emmet-core/emmet/core/tasks.py +++ b/emmet-core/emmet/core/tasks.py @@ -409,7 +409,7 @@ class TaskDoc(StructureMetadata, extra="allow"): ) last_updated: Optional[datetime] = Field( - None, + datetime.utcnow(), description="Timestamp for the most recent calculation for this task document", ) @@ -437,6 +437,9 @@ def model_post_init(self, __context: Any) -> None: if self.task_type is None: self.task_type = task_type(self.orig_inputs) + if self.structure is None: + self.structure = self.calcs_reversed[0].output.structure + # Make sure that the datetime field is properly formatted # (Unclear when this is not the case, please leave comment if observed) @field_validator("last_updated", mode="before") @@ -662,7 +665,10 @@ def get_entry( "energy": calcs_reversed[0].output.energy, "parameters": { # Cannot be PotcarSpec document, pymatgen expects a dict - "potcar_spec": [dict(d) for d in calcs_reversed[0].input.potcar_spec], + # Note that `potcar_spec` is optional + "potcar_spec": [dict(d) for d in calcs_reversed[0].input.potcar_spec] + if calcs_reversed[0].input.potcar_spec + else [], # Required to be compatible with MontyEncoder for the ComputedEntry "run_type": str(calcs_reversed[0].run_type), "is_hubbard": calcs_reversed[0].input.is_hubbard, @@ -716,7 +722,7 @@ def structure_entry(self) -> ComputedStructureEntry: The TaskDoc.entry with corresponding TaskDoc.structure added. """ self.private_structure_entry = ComputedStructureEntry( - structure=self.output.structure, + structure=self.structure, energy=self.entry.energy, correction=self.entry.correction, composition=self.entry.composition, diff --git a/emmet-core/emmet/core/vasp/material.py b/emmet-core/emmet/core/vasp/material.py index 171c117475..dc41f3595c 100644 --- a/emmet-core/emmet/core/vasp/material.py +++ b/emmet-core/emmet/core/vasp/material.py @@ -12,7 +12,7 @@ from emmet.core.settings import EmmetSettings from emmet.core.structure import StructureMetadata from emmet.core.vasp.calc_types import CalcType, RunType, TaskType -from emmet.core.vasp.task_valid import TaskDocument +from emmet.core.tasks import TaskDoc SETTINGS = EmmetSettings() @@ -51,7 +51,7 @@ class MaterialsDoc(CoreMaterialsDoc, StructureMetadata): @classmethod def from_tasks( cls, - task_group: List[TaskDocument], + task_group: List[TaskDoc], structure_quality_scores: Dict[ str, int ] = SETTINGS.VASP_STRUCTURE_QUALITY_SCORES, @@ -101,7 +101,7 @@ def from_tasks( # Always prefer a static over a structure opt structure_task_quality_scores = {"Structure Optimization": 1, "Static": 2} - def _structure_eval(task: TaskDocument): + def _structure_eval(task: TaskDoc): """ Helper function to order structures optimization and statics calcs by - Functional Type @@ -155,7 +155,7 @@ def _structure_eval(task: TaskDocument): # Always prefer a static over a structure opt entry_task_quality_scores = {"Structure Optimization": 1, "Static": 2} - def _entry_eval(task: TaskDocument): + def _entry_eval(task: TaskDoc): """ Helper function to order entries and statics calcs by - Spin polarization @@ -222,7 +222,7 @@ def _entry_eval(task: TaskDocument): @classmethod def construct_deprecated_material( cls, - task_group: List[TaskDocument], + task_group: List[TaskDoc], commercial_license: bool = True, ) -> "MaterialsDoc": """