Skip to content

Commit 31d0ec1

Browse files
fix mypy errors and add docstr
1 parent 5db5334 commit 31d0ec1

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

.pre-commit-config.yaml

+8-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ repos:
3737
- --expand-star-imports
3838
- --ignore-init-module-imports
3939

40-
# - repo: https://github.com/pre-commit/mirrors-mypy
41-
# rev: v1.5.1
42-
# hooks:
43-
# - id: mypy
40+
- repo: https://github.com/pre-commit/mirrors-mypy
41+
rev: v1.8.0
42+
hooks:
43+
- id: mypy
44+
files: ^pymatgen/
45+
args:
46+
- --namespace-packages
47+
- --explicit-package-bases

pymatgen/io/validation/check_incar.py

+17-25
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ def _check_incar(
6565
task_type : TaskType
6666
Task type of the calculation.
6767
fft_grid_tolerance: float
68-
Directly calculating the FFT grid defaults from VASP is actually impossible
69-
without information on how VASP was compiled. This is because the FFT
70-
params generated depend on whatever fft library used. So instead, we do our
71-
best to calculate the FFT grid defaults and then lower it artificially by
72-
`fft_grid_tolerance`. So if the users FFT grid parameters are greater than
73-
(fft_grid_tolerance x slightly-off defaults), the FFT params are marked
68+
Directly calculating the FFT grid defaults from VASP is actually impossible
69+
without information on how VASP was compiled. This is because the FFT
70+
params generated depend on whatever fft library used. So instead, we do our
71+
best to calculate the FFT grid defaults and then lower it artificially by
72+
`fft_grid_tolerance`. So if the user's FFT grid parameters are greater than
73+
(fft_grid_tolerance x slightly-off defaults), the FFT params are marked
7474
as valid.
7575
"""
7676

@@ -140,9 +140,6 @@ class UpdateParameterValues:
140140
sensible default values.
141141
"""
142142

143-
# MK: unclear, expand
144-
# AK: review
145-
146143
_default_schema: dict[str, Any] = {
147144
"value": None,
148145
"tag": None,
@@ -183,7 +180,9 @@ def __init__(
183180
task_type : TaskType
184181
Task type of the calculation.
185182
fft_grid_tolerance: float
186-
TODO MK : what was the purpose of this originally?
183+
See docstr for `_check_incar`. The FFT grid generation has been udpated frequently
184+
in VASP, and determining the grid density with absolute certainty is not possible.
185+
This tolerance allows for "reasonable" discrepancies from the ideal FFT grid density.
187186
"""
188187

189188
self.parameters = copy.deepcopy(parameters)
@@ -414,22 +413,18 @@ def update_hybrid_params(self) -> None:
414413
self.valid_values["LHFCALC"] = self.input_set.incar.get("LHFCALC", self.defaults["LHFCALC"]["value"])
415414

416415
if self.valid_values["LHFCALC"]:
417-
self.defaults["AEXX"] = 0.25
418-
self.parameters["AEXX"] = self.parameters.get("AEXX", self.defaults["AEXX"])
419-
self.defaults["AGGAC"] = 0.0
416+
self.defaults["AEXX"]["value"] = 0.25
417+
self.parameters["AEXX"] = self.parameters.get("AEXX", self.defaults["AEXX"]["value"])
418+
self.defaults["AGGAC"]["value"] = 0.0
420419
for key in ("AGGAX", "ALDAX", "AMGGAX"):
421-
self.defaults[key] = 1.0 - self.parameters["AEXX"]
420+
self.defaults[key]["value"] = 1.0 - self.parameters["AEXX"]
422421

423-
if self.parameters.get("AEXX", self.defaults["AEXX"]) == 1.0:
424-
self.defaults["ALDAC"] = 0.0
425-
self.defaults["AMGGAC"] = 0.0
422+
if self.parameters.get("AEXX", self.defaults["AEXX"]["value"]) == 1.0:
423+
self.defaults["ALDAC"]["value"] = 0.0
424+
self.defaults["AMGGAC"]["value"] = 0.0
426425

427426
for key in self.categories["hybrid"]:
428-
self.defaults[key].update(
429-
{
430-
"operation": "==" if isinstance(self.defaults[key]["value"], bool) else "approx",
431-
}
432-
)
427+
self.defaults[key]["operation"] = "==" if isinstance(self.defaults[key]["value"], bool) else "approx"
433428

434429
def update_fft_params(self) -> None:
435430
"""Update parameters related to the FFT grid."""
@@ -756,9 +751,6 @@ class BasicValidator:
756751
check if a Sequence contains an element
757752
"""
758753

759-
# MK: unclear. Is the above docstring accurate? It seems like all checks use this, right?
760-
# AK: review
761-
762754
# avoiding dunder methods because these raise too many NotImplemented's
763755
operations: set[str | None] = {"==", ">", ">=", "<", "<=", "in", "approx", "auto fail", None}
764756

0 commit comments

Comments
 (0)