Skip to content

Commit

Permalink
enable instantiating partial task doc
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed Oct 17, 2020
1 parent c7f9a2e commit 4945ac7
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions 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
Expand All @@ -17,15 +17,15 @@
run_type,
task_type,
)
from emmet.stubs import ComputedEntry, Matrix3D, Structure
from emmet.stubs import ComputedEntry, Matrix3D, Vector3D, Structure


class Status(Enum):
"""
VASP Calculation State
"""

SUCESS = "sucess"
SUCESS = "successful"
FAILED = "failed"


Expand All @@ -34,75 +34,76 @@ 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):
"""
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):
"""
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(
Expand All @@ -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")
Expand All @@ -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 = {
Expand Down

0 comments on commit 4945ac7

Please sign in to comment.