Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Aborted] Feat: Add run types for GW calculations #1099

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions emmet-core/emmet/core/vasp/calc_types/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class RunType(ValueEnum):
vdW_DF2_U = "vdW-DF2+U"
LDA = "LDA"
LDA_U = "LDA+U"
G0W0_PBE = "G0W0-PBE"
G0W0_GGA = "G0W0-GGA"

@classmethod
def _missing_(cls, value):
Expand All @@ -98,6 +100,7 @@ class TaskType(ValueEnum):
Deformation = "Deformation"
Optic = "Optic"
Molecular_Dynamics = "Molecular Dynamics"
GW_Band_Structure = "GW Band Structure"
Unrecognized = "Unrecognized"


Expand Down Expand Up @@ -954,3 +957,5 @@ class CalcType(ValueEnum):
LDA_U_Optic = "LDA+U Optic"
LDA_U_Molecular_Dynamics = "LDA+U Molecular Dynamics"
LDA_U_Unrecognized = "LDA+U Unrecognized"
G0W0_GGA_Band_Structure = "G0W0-GGA GW Band Structure"
G0W0_PBE_Band_Structure = "G0W0-PBE GW Band Structure"
9 changes: 9 additions & 0 deletions emmet-core/emmet/core/vasp/calc_types/run_types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,12 @@ VDW:
LASPH: true
LUSE_VDW: true
Zab_vdW: -1.8867
GW:
G0W0-GGA:
ALGO: Gw0
NELM: 1
GGA: --
G0W0-PBE:
ALGO: Gw0
NELM: 1
GGA: PE
18 changes: 15 additions & 3 deletions emmet-core/emmet/core/vasp/calc_types/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
__all__ = ["run_type", "task_type", "calc_type"]


def run_type(parameters: Dict) -> RunType:
def run_type(
parameters: Dict,
inputs: Dict[Literal["incar", "poscar", "kpoints", "potcar"], Dict] = None,
) -> RunType:
"""
Determine run type from the VASP parameters dict.

This is adapted from pymatgen to be far less unstable

Args:
parameters: Dictionary of VASP parameters from vasprun.xml.
inputs: inputs dict with an incar, kpoints, potcar, and poscar dictionaries.

Returns:
The run type.
Expand All @@ -29,6 +33,10 @@ def run_type(parameters: Dict) -> RunType:
TaskDocument.run_type, copy over LDAU* fields from the incar rather than trust
parameters.
"""
incar = {}
if inputs is not None:
incar = inputs.get("incar", {})

is_hubbard = "+U" if parameters.get("LDAU", False) else ""

def _variant_equal(v1, v2) -> bool:
Expand All @@ -38,10 +46,11 @@ def _variant_equal(v1, v2) -> bool:
return v1 == v2

# This is to force an order of evaluation
for functional_class in ["HF", "VDW", "METAGGA", "GGA"]:
for functional_class in ["GW", "HF", "VDW", "METAGGA", "GGA"]:
for special_type, params in _RUN_TYPE_DATA[functional_class].items():
if all(
_variant_equal(parameters.get(param, None), value)
or (param in incar and _variant_equal(incar.get(param, None), value))
for param, value in params.items()
):
return RunType(f"{special_type}{is_hubbard}")
Expand Down Expand Up @@ -116,6 +125,9 @@ def task_type(
elif incar.get("IBRION", 1) == 0:
calc_type.append("Molecular Dynamics")

elif incar.get("ALGO").upper() == "GW0":
calc_type.append("GW Band Structure")

if len(calc_type) == 0:
return TaskType("Unrecognized")

Expand All @@ -136,6 +148,6 @@ def calc_type(
Returns:
The calc type.
"""
rt = run_type(parameters).value
rt = run_type(parameters, inputs).value
tt = task_type(inputs).value
return CalcType(f"{rt} {tt}")
7 changes: 5 additions & 2 deletions emmet-core/emmet/core/vasp/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,10 @@ def from_vasp_files(
volumetric_files = [] if volumetric_files is None else volumetric_files
vasprun = Vasprun(vasprun_file, **vasprun_kwargs)
outcar = Outcar(outcar_file)
contcar = Poscar.from_file(contcar_file)
try:
contcar = Poscar.from_file(contcar_file)
except ValueError:
contcar = Poscar(vasprun.final_structure)
completed_at = str(datetime.fromtimestamp(vasprun_file.stat().st_mtime))

output_file_paths = _get_output_file_paths(volumetric_files)
Expand Down Expand Up @@ -852,7 +855,7 @@ def from_vasp_files(
},
bader=bader,
ddec6=ddec6,
run_type=run_type(input_doc.parameters),
run_type=run_type(input_doc.parameters, input_doc.model_dump()),
task_type=task_type(input_doc.model_dump()),
calc_type=calc_type(input_doc.model_dump(), input_doc.parameters),
),
Expand Down