From 4945ac78e0dd2bc6a1671afb39af3186275b2ad3 Mon Sep 17 00:00:00 2001 From: Shyam D Date: Fri, 16 Oct 2020 20:32:51 -0700 Subject: [PATCH] enable instantiating partial task doc --- emmet-core/emmet/core/vasp/task.py | 69 +++++++++++++++--------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/emmet-core/emmet/core/vasp/task.py b/emmet-core/emmet/core/vasp/task.py index 9bc867d2e3..27a78c8ade 100644 --- a/emmet-core/emmet/core/vasp/task.py +++ b/emmet-core/emmet/core/vasp/task.py @@ -1,7 +1,7 @@ """ Core definition of a VASP Task Document """ from datetime import datetime from enum import Enum -from functools import cached_property, partial +from functools import lru_cache, partial from typing import ClassVar, Dict, List, Optional, Union from pydantic import BaseModel, Field, create_model @@ -17,7 +17,7 @@ run_type, task_type, ) -from emmet.stubs import ComputedEntry, Matrix3D, Structure +from emmet.stubs import ComputedEntry, Matrix3D, Vector3D, Structure class Status(Enum): @@ -25,7 +25,7 @@ class Status(Enum): VASP Calculation State """ - SUCESS = "sucess" + SUCESS = "successful" FAILED = "failed" @@ -34,18 +34,19 @@ class InputSummary(BaseModel): Summary of inputs for a VASP calculation """ - structure: Structure = Field(..., description="The input structure object") + structure: Structure = Field(None, description="The input structure object") parameters: Dict = Field( - ..., + None, description="Input parameters from VASPRUN for the last calculation in the series", ) pseudo_potentials: Dict = Field( - ..., description="Summary of the pseudopotentials used in this calculation" + None, description="Summary of the pseudopotentials used in this calculation" ) potcar_spec: List[Dict] = Field( - ..., description="Potcar specification as a title and hash" + None, description="Potcar specification as a title and hash" ) + parameters: Dict = Field(None, description="parameters for this VASP calculation") class OutputSummary(BaseModel): @@ -53,21 +54,21 @@ class OutputSummary(BaseModel): Summary of the outputs for a VASP calculation """ - structure: Structure = Field(..., description="The output structure object") + structure: Structure = Field(None, description="The output structure object") energy: float = Field( - ..., description="The final total DFT energy for the last calculation" + None, description="The final total DFT energy for the last calculation" ) energy_per_atom: float = Field( - ..., description="The final DFT energy per atom for the last calculation" + None, description="The final DFT energy per atom for the last calculation" ) - bandgap: float = Field(..., description="The DFT bandgap for the last calculation") - forces: List[Matrix3D] = Field( - ..., description="Forces on atoms from the last calculation" + bandgap: float = Field(None, description="The DFT bandgap for the last calculation") + forces: List[Vector3D] = Field( + None, description="Forces on atoms from the last calculation" ) stress: Matrix3D = Field( - ..., description="Stress on the unitcell from the last calculation" + None, description="Stress on the unitcell from the last calculation" ) - parameters: Dict = Field(..., description="parameters for this VASP calculation") + class RunStatistics(BaseModel): @@ -75,34 +76,34 @@ class RunStatistics(BaseModel): Summary of the Run statistics for a VASP calculation """ - average_memory: float = Field(..., description="The average memory used in kb") - max_memory: float = Field(..., description="The maximum memory used in kb") - elapsed_time: float = Field(..., description="The real time elapsed in seconds") - system_time: float = Field(..., description="The system CPU time in seconds") + average_memory: float = Field(None, description="The average memory used in kb") + max_memory: float = Field(None, description="The maximum memory used in kb") + elapsed_time: float = Field(None, description="The real time elapsed in seconds") + system_time: float = Field(None, description="The system CPU time in seconds") user_time: float = Field( - ..., description="The user CPU time spent by VASP in seconds" + None, description="The user CPU time spent by VASP in seconds" ) total_time: float = Field( - ..., description="The total CPU time for this calculation" + None, description="The total CPU time for this calculation" ) - cores: int = Field(..., description="The number of cores used by VASP") + cores: int = Field(None, description="The number of cores used by VASP") -class TaskDocument(StructureMetadata): +class TaskDocument(BaseModel): """ Definition of VASP Task Document """ - dir_name: str = Field(..., description="The directory for this VASP task") + dir_name: str = Field(None, description="The directory for this VASP task") run_stats: Dict[str, RunStatistics] = Field( - ..., + None, description="Summary of runtime statisitics for each calcualtion in this task", ) completed_at: datetime = Field( - ..., description="Timestamp for when this task was completed" + None, description="Timestamp for when this task was completed" ) last_updated: datetime = Field( - ..., description="Timestamp for this task document was last updateed" + None, description="Timestamp for this task document was last updateed" ) is_valid: bool = Field( @@ -115,7 +116,7 @@ class TaskDocument(StructureMetadata): state: Status orig_inputs: Dict[str, Dict] = Field( - ..., description="Summary of the original VASP inputs" + None, description="Summary of the original VASP inputs" ) task_id: str = Field(None, description="the Task ID For this document") tags: List[str] = Field(None, description="Metadata tags for this task document") @@ -124,19 +125,19 @@ class TaskDocument(StructureMetadata): ["core"], description="List of sandboxes this task document is allowed in" ) - @cached_property + @property def run_type(self) -> RunType: - return run_type(self.output.parameters) + return run_type(self.input.parameters) - @cached_property + @property def task_type(self): return task_type(self.orig_inputs) - @cached_property + @property def calc_type(self): - return calc_type(self.orig_inputs, self.parameters) + return calc_type(self.orig_inputs, self.input.parameters) - @cached_property + @property def entry(self): """ Turns a Task Doc into a ComputedEntry""" entry_dict = {