Skip to content

Commit cb6670a

Browse files
precommit
1 parent 34d1704 commit cb6670a

File tree

8 files changed

+100
-93
lines changed

8 files changed

+100
-93
lines changed

pymatgen/io/validation/check_common_errors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import TYPE_CHECKING
77

88
from pymatgen.io.validation.common import SETTINGS, BaseValidator
9-
from pymatgen.io.validation.settings import IOValidationSettings
109

1110
if TYPE_CHECKING:
1211
from numpy.typing import ArrayLike

pymatgen/io/validation/check_incar.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# TODO: fix ISIF getting overwritten by MP input set.
1717

18+
1819
class CheckIncar(BaseValidator):
1920
"""
2021
Check calculation parameters related to INCAR input tags.
@@ -35,8 +36,7 @@ class CheckIncar(BaseValidator):
3536

3637
name: str = "Check INCAR tags"
3738
fft_grid_tolerance: float | None = Field(
38-
SETTINGS.VASP_FFT_GRID_TOLERANCE,
39-
description="Tolerance for determining sufficient density of FFT grid."
39+
SETTINGS.VASP_FFT_GRID_TOLERANCE, description="Tolerance for determining sufficient density of FFT grid."
4040
)
4141
bandgap_tol: float = Field(1.0e-4, description="Tolerance for assuming a material has no gap.")
4242

@@ -72,7 +72,7 @@ def check(self, vasp_files: VaspFiles, reasons: list[str], warnings: list[str])
7272
resp = vasp_param.check(user_incar_params[vasp_param.name], valid_incar_params[vasp_param.name])
7373
msgs[vasp_param.severity].extend(resp.get(vasp_param.severity, []))
7474

75-
def update_parameters_and_defaults(self, vasp_files: VaspFiles) -> tuple[dict[str,Any], dict[str,Any]]:
75+
def update_parameters_and_defaults(self, vasp_files: VaspFiles) -> tuple[dict[str, Any], dict[str, Any]]:
7676
"""Update a set of parameters according to supplied rules and defaults.
7777
7878
While many of the parameters in VASP need only a simple check to determine
@@ -298,10 +298,7 @@ def _update_fft_params(self, user_incar: dict, ref_incar: dict, vasp_files: Vasp
298298
"""Update ENCUT and parameters related to the FFT grid."""
299299

300300
# ensure that ENCUT is appropriately updated
301-
user_incar["ENMAX"] = user_incar.get(
302-
"ENCUT",
303-
getattr(vasp_files.vasprun,"parameters",{}).get("ENMAX")
304-
)
301+
user_incar["ENMAX"] = user_incar.get("ENCUT", getattr(vasp_files.vasprun, "parameters", {}).get("ENMAX"))
305302

306303
ref_incar["ENMAX"] = vasp_files.valid_input_set.incar.get("ENCUT", self.vasp_defaults["ENMAX"])
307304

@@ -513,17 +510,17 @@ def _update_electronic_params(self, user_incar: dict, ref_incar: dict, vasp_file
513510
)
514511
except Exception:
515512
self.vasp_defaults["NELECT"] = VaspParam(
516-
name = "NELECT",
517-
value = None,
518-
tag = "electronic",
519-
operation= "auto fail",
513+
name="NELECT",
514+
value=None,
515+
tag="electronic",
516+
operation="auto fail",
520517
severity="warning",
521-
alias = "NELECT / POTCAR",
518+
alias="NELECT / POTCAR",
522519
comment=(
523520
"Issue checking whether NELECT was changed to make "
524521
"the structure have a non-zero charge. This is likely due to the "
525522
"directory not having a POTCAR file."
526-
)
523+
),
527524
)
528525

529526
# NBANDS.
@@ -549,10 +546,9 @@ def _update_ionic_params(self, user_incar: dict, ref_incar: dict, vasp_files: Va
549546

550547
# IBRION.
551548
ref_incar["IBRION"] = [-1, 1, 2]
552-
if (
553-
(inp_set_ibrion := vasp_files.valid_input_set.incar.get("IBRION"))
554-
and inp_set_ibrion not in ref_incar["IBRION"]
555-
):
549+
if (inp_set_ibrion := vasp_files.valid_input_set.incar.get("IBRION")) and inp_set_ibrion not in ref_incar[
550+
"IBRION"
551+
]:
556552
ref_incar["IBRION"].append(inp_set_ibrion)
557553

558554
ionic_steps = []

pymatgen/io/validation/check_kpoints_kspacing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _check_user_shifted_mesh(self, vasp_files: VaspFiles, reasons: list[str], wa
7070
def _check_explicit_mesh_permitted(self, vasp_files: VaspFiles, reasons: list[str], warnings: list[str]) -> None:
7171
# Check for explicit kpoint meshes
7272

73-
if isinstance(self.allow_explicit_kpoint_mesh,bool):
73+
if isinstance(self.allow_explicit_kpoint_mesh, bool):
7474
allow_explicit = self.allow_explicit_kpoint_mesh
7575
elif self.allow_explicit_kpoint_mesh == "auto":
7676
allow_explicit = vasp_files.run_type == "nonscf"

pymatgen/io/validation/common.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from importlib import import_module
77
import os
88
from pathlib import Path
9-
from pydantic import BaseModel, Field, computed_field, model_serializer, PrivateAttr
9+
from pydantic import BaseModel, Field, model_serializer, PrivateAttr
1010
from typing import TYPE_CHECKING, Any
1111

1212
from pymatgen.core import Structure
@@ -21,6 +21,7 @@
2121

2222
SETTINGS = IOValidationSettings()
2323

24+
2425
class ValidationError(Exception):
2526
"""Define custom exception during validation."""
2627

@@ -35,11 +36,9 @@ class _PotcarSummaryStatsKeywords(BaseModel):
3536
data: set[str] = Field(description="The keywords in the POTCAR body.")
3637

3738
@model_serializer
38-
def set_to_list(self) -> dict[str,list[str]]:
39+
def set_to_list(self) -> dict[str, list[str]]:
3940
"""Ensure JSON compliance of set fields."""
40-
return {
41-
k : list(getattr(self,k)) for k in ("header","data")
42-
}
41+
return {k: list(getattr(self, k)) for k in ("header", "data")}
4342

4443
class _PotcarSummaryStatsStats(BaseModel):
4544
"""Schematize `PotcarSingle._summary_stats["stats"]` field."""
@@ -88,7 +87,10 @@ class LightVasprun(BaseModel):
8887
kpoints: Kpoints = Field(description="The actual k-points used in the calculation.")
8988
parameters: dict[str, Any] = Field(description="The default-padded input parameters interpreted by VASP.")
9089
bandgap: float = Field(description="The bandgap - note that this field is derived from the Vasprun object.")
91-
potcar_symbols : list[str] | None = Field(None, description="Optional: if a POTCAR is unavailable, this is used to determine the functional used in the calculation.")
90+
potcar_symbols: list[str] | None = Field(
91+
None,
92+
description="Optional: if a POTCAR is unavailable, this is used to determine the functional used in the calculation.",
93+
)
9294

9395
@classmethod
9496
def from_vasprun(cls, vasprun: Vasprun) -> Self:
@@ -105,7 +107,7 @@ class VaspInputSafe(BaseModel):
105107
structure: Structure = Field(description="The structure associated with the calculation.")
106108
kpoints: Kpoints | None = Field(None, description="The optional KPOINTS or IBZKPT file used in the calculation.")
107109
potcar: list[PotcarSummaryStats] | None = Field(None, description="The optional POTCAR used in the calculation.")
108-
_pmg_vis : VaspInputSet | None = PrivateAttr(None)
110+
_pmg_vis: VaspInputSet | None = PrivateAttr(None)
109111

110112
@model_serializer
111113
def deserialize_objects(self) -> dict[str, Any]:
@@ -136,7 +138,6 @@ def from_vasp_input_set(cls, vis: VaspInputSet) -> Self:
136138
new_vis._pmg_vis = vis
137139
return new_vis
138140

139-
140141
def _calculate_ng(self, **kwargs) -> tuple[list[int], list[int]] | None:
141142
"""Interface to pymatgen vasp input set as needed."""
142143
if self._pmg_vis:
@@ -147,7 +148,7 @@ def _calculate_ng(self, **kwargs) -> tuple[list[int], list[int]] | None:
147148
class VaspFiles(BaseModel):
148149
"""Define required and optional files for validation."""
149150

150-
user_input : VaspInputSafe = Field(description="The VASP input set used in the calculation.")
151+
user_input: VaspInputSafe = Field(description="The VASP input set used in the calculation.")
151152
outcar: LightOutcar | None = None
152153
vasprun: LightVasprun | None = None
153154

@@ -194,7 +195,7 @@ def from_paths(
194195
if (path := _vars.get(file_name)) and Path(path).exists():
195196
if file_name == "poscar":
196197
config["user_input"]["structure"] = file_cls.from_file(path).structure
197-
elif hasattr(file_cls,"from_file"):
198+
elif hasattr(file_cls, "from_file"):
198199
config["user_input"][file_name] = file_cls.from_file(path)
199200
else:
200201
config[file_name] = file_cls(path)
@@ -204,7 +205,8 @@ def from_paths(
204205

205206
if config.get("outcar"):
206207
config["outcar"] = LightOutcar(
207-
drift = config["outcar"].drift, magnetization=config["outcar"].magnetization,
208+
drift=config["outcar"].drift,
209+
magnetization=config["outcar"].magnetization,
208210
)
209211
if config.get("vasprun"):
210212
config["vasprun"] = LightVasprun.from_vasprun(config["vasprun"])

pymatgen/io/validation/emmet_validation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class ValidationDoc(EmmetBaseModel):
4242
warnings: list[str] = Field([], description="List of potential warnings about this calculation")
4343

4444
@staticmethod
45-
def task_doc_to_vasp_files(task_doc : TaskDoc | TaskDocument) -> VaspFiles:
45+
def task_doc_to_vasp_files(task_doc: TaskDoc | TaskDocument) -> VaspFiles:
4646
"""Convert an emmet.core TaskDoc or legacy TaskDocument to VaspFiles."""
47-
47+
4848
if isinstance(task_doc, TaskDocument):
4949
final_calc = Calculation(**task_doc.calcs_reversed[0])
5050
else:
@@ -66,12 +66,12 @@ def task_doc_to_vasp_files(task_doc : TaskDoc | TaskDocument) -> VaspFiles:
6666
return VaspFiles(
6767
user_input=VaspInputSafe(
6868
incar=Incar(final_calc.input.incar),
69-
kpoints = final_calc.input.kpoints,
69+
kpoints=final_calc.input.kpoints,
7070
structure=final_calc.input.structure,
7171
potcar=potcar_stats,
7272
),
73-
outcar = LightOutcar(**{k: final_calc.output.outcar.get(k) for k in ("drift", "magnetization")}),
74-
vasprun = LightVasprun(
73+
outcar=LightOutcar(**{k: final_calc.output.outcar.get(k) for k in ("drift", "magnetization")}),
74+
vasprun=LightVasprun(
7575
vasp_version=final_calc.vasp_version,
7676
ionic_steps=[ionic_step.model_dump() for ionic_step in final_calc.output.ionic_steps],
7777
final_energy=task_doc.output.energy,
@@ -91,6 +91,6 @@ def from_task_doc(cls, task_doc: TaskDoc | TaskDocument, **kwargs) -> Self:
9191
valid=validator.is_valid,
9292
reasons=validator.reasons,
9393
warnings=validator.warnings,
94-
task_id = task_doc.task_id,
94+
task_id=task_doc.task_id,
9595
**kwargs,
9696
)

pymatgen/io/validation/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def from_vasp_input(
3939
vasp_file_paths: dict[str, os.PathLike[str]] | None = None,
4040
vasp_files: VaspFiles | None = None,
4141
fast: bool = False,
42-
check_potcar : bool = True,
42+
check_potcar: bool = True,
4343
):
4444

4545
if not vasp_files and vasp_file_paths:

tests/conftest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
def test_dir():
1212
return _test_dir
1313

14-
vasp_calc_data : dict[str,VaspFiles] = {
15-
k : VaspFiles(**loadfn(_test_dir / "vasp" / f"{k}.json.gz"))
16-
for k in ("Si_uniform","Si_static","Si_old_double_relax")
14+
15+
vasp_calc_data: dict[str, VaspFiles] = {
16+
k: VaspFiles(**loadfn(_test_dir / "vasp" / f"{k}.json.gz"))
17+
for k in ("Si_uniform", "Si_static", "Si_old_double_relax")
1718
}
1819

20+
1921
def incar_check_list():
2022
"""Pre-defined list of pass/fail tests."""
21-
return loadfn(_test_dir / "vasp" / "scf_incar_check_list.yaml")
23+
return loadfn(_test_dir / "vasp" / "scf_incar_check_list.yaml")

0 commit comments

Comments
 (0)