Skip to content

Commit

Permalink
fix implementation of potcar summary_stats checks
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkuner committed Nov 2, 2023
1 parent c485d2f commit 1750c8d
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions pymatgen/io/validation/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pydantic import Field
from pydantic.types import ImportString # replacement for PyObject
from pathlib import Path
from monty.os.path import zpath
from monty.serialization import loadfn

from pymatgen.io.vasp.sets import VaspInputSet
Expand Down Expand Up @@ -111,12 +110,7 @@ def from_task_doc(
ionic_steps = calcs_reversed[0]["output"]["ionic_steps"]
nionic_steps = len(ionic_steps)

potcar_path = zpath("POTCAR")
# for potcar_spec in task_doc.calcs_reversed[0].input.potcar_spec:
if Path.is_file(Path(potcar_path)):
potcar = Potcar.from_file(potcar_path)
else:
potcar = None
potcars = calcs_reversed[0]["input"]["potcar_spec"]

calc_type = _get_calc_type(calcs_reversed, orig_inputs)
task_type = _get_task_type(calcs_reversed, orig_inputs)
Expand Down Expand Up @@ -173,7 +167,7 @@ def from_task_doc(
][titel_no_spc].copy()

if potcar_summary_stats:
_check_potcars(reasons, warnings, potcar, valid_potcar_summary_stats)
_check_potcars(reasons, warnings, potcars, valid_potcar_summary_stats)

# TODO: check for surface/slab calculations!!!!!!

Expand Down Expand Up @@ -217,7 +211,7 @@ def from_task_doc(
nionic_steps,
parameters,
incar,
potcar,
potcars,
vasp_major_version,
vasp_minor_version,
vasp_patch_version,
Expand Down Expand Up @@ -363,18 +357,18 @@ def _check_potcars(
try:
incorrect_potcars = []
for potcar in potcars:
reference_summary_stats = valid_potcar_summary_stats.get(potcar.TITEL.replace(" ", ""), [])
reference_summary_stats = valid_potcar_summary_stats.get(potcar["TITEL"].replace(" ", ""), [])

key_match = False
data_match = False
for ref_psp in reference_summary_stats:
key_match = all(
set(ref_psp["keywords"][key]) == set(potcar._summary_stats["keywords"][key]) # type: ignore
set(ref_psp["keywords"][key]) == set(potcar["_summary_stats"]["keywords"][key]) # type: ignore
for key in ["header", "data"]
)

data_diff = [
abs(ref_psp["stats"][key][stat] - potcar._summary_stats["stats"][key][stat]) # type: ignore
abs(ref_psp["stats"][key][stat] - potcar["_summary_stats"]["stats"][key][stat]) # type: ignore
for stat in ["MEAN", "ABSMEAN", "VAR", "MIN", "MAX"]
for key in ["header", "data"]
]
Expand All @@ -383,7 +377,7 @@ def _check_potcars(
break

if (not key_match) or (not data_match):
incorrect_potcars.append(potcar.symbol)
incorrect_potcars.append(potcar["symbol"])

if len(incorrect_potcars) > 0:
# format error string
Expand Down

0 comments on commit 1750c8d

Please sign in to comment.