Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from materialsproject/xas
Move XAS Logic into document and clean up builder
- Loading branch information
Showing
6 changed files
with
335 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
""" Core definition of a VASP Task Document """ | ||
from functools import lru_cache | ||
from typing import Any, ClassVar, Dict, List | ||
|
||
from pydantic import Field | ||
from pymatgen.analysis.xas.spectrum import XAS, site_weighted_spectrum | ||
from pymatgen.core import Structure | ||
from pymatgen.core.periodic_table import Element | ||
|
||
from emmet.core.mpid import MPID | ||
from emmet.core.structure import StructureMetadata | ||
from emmet.core.task import TaskDocument as BaseTaskDocument | ||
from emmet.core.utils import ValueEnum | ||
|
||
|
||
class CalcType(ValueEnum): | ||
""" | ||
The type of FEFF Calculation | ||
XANES - Just the near-edge region | ||
EXAFS - Just the extended region | ||
XAFS - Fully stitchted XANES + EXAFS | ||
""" | ||
|
||
XANES = "XANES" | ||
EXAFS = "EXAFS" | ||
XAFS = "XAFS" | ||
|
||
|
||
class TaskDocument(BaseTaskDocument, StructureMetadata): | ||
"""Task Document for a FEFF XAS Calculation. Doesn't support EELS for now""" | ||
|
||
calc_code: ClassVar[str] = "FEFF" | ||
|
||
structure: Structure | ||
input_parameters: Dict[str, Any] = Field( | ||
{}, description="Input parameters for the FEFF calculation" | ||
) | ||
spectrum: List[List[float]] = Field( | ||
[[]], description="Raw spectrum data from FEFF xmu.dat or eels.dat" | ||
) | ||
|
||
absorbing_atom: int = Field( | ||
..., description="Index in the cluster or structure for the absorbing atom" | ||
) | ||
spectrum_type: CalcType = Field(..., title="XAS Spectrum Type") | ||
edge: str = Field( | ||
..., title="Absorption Edge", description="The interaction edge for XAS" | ||
) | ||
|
||
# TEMP Stub properties for compatability with atomate drone | ||
|
||
@property | ||
def absorbing_element(self) -> Element: | ||
if isinstance(self.structure[self.absorbing_atom].specie, Element): | ||
return self.structure[self.absorbing_atom].specie | ||
return self.structure[self.absorbing_atom].specie.element | ||
|
||
@property | ||
def xas_spectrum(self) -> XAS: | ||
|
||
if not hasattr(self, "_xas_spectrum"): | ||
|
||
if not all([len(p) == 6 for p in self.spectrum]): | ||
raise ValueError( | ||
"Spectrum data doesn't appear to be from xmu.dat which holds XAS data" | ||
) | ||
|
||
energy = [point[0] for point in self.spectrum] # (eV) | ||
intensity = [point[3] for point in self.spectrum] # (mu) | ||
structure = self.structure | ||
absorbing_index = self.absorbing_atom | ||
absorbing_element = self.absorbing_element | ||
edge = self.edge | ||
spectrum_type = str(self.spectrum_type) | ||
|
||
self._xas_spectrum = XAS( | ||
x=energy, | ||
y=intensity, | ||
structure=structure, | ||
absorbing_element=absorbing_element, | ||
absorbing_index=absorbing_index, | ||
edge=edge, | ||
spectrum_type=spectrum_type, | ||
) | ||
|
||
return self._xas_spectrum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" Core definition of a Task Document which represents a calculation from some program""" | ||
from datetime import datetime | ||
from typing import ClassVar, List | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from emmet.core.mpid import MPID | ||
|
||
|
||
class TaskDocument(BaseModel): | ||
""" | ||
Definition of Task Document | ||
""" | ||
|
||
calc_code: ClassVar[str] = Field( | ||
..., description="The calculation code used to compute this task" | ||
) | ||
version: str = Field(None, description="The version of the calculation code") | ||
dir_name: str = Field(None, description="The directory for this task") | ||
task_id: MPID = Field(None, description="the Task ID For this document") | ||
|
||
completed: bool = Field(False, description="Whether this calcuation completed") | ||
completed_at: datetime = Field( | ||
None, description="Timestamp for when this task was completed" | ||
) | ||
last_updated: datetime = Field( | ||
default_factory=datetime.utcnow, | ||
description="Timestamp for this task document was last updateed", | ||
) | ||
|
||
tags: List[str] = Field([], description="Metadata tags for this task document") | ||
|
||
warnings: List[str] = Field( | ||
None, description="Any warnings related to this property" | ||
) |
Oops, something went wrong.