Skip to content

Commit d363a1e

Browse files
precommit
1 parent e8c69da commit d363a1e

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

pymatgen/io/validation/check_incar.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def check(self) -> None:
125125
severity=working_params.defaults[key]["severity"],
126126
)
127127

128+
128129
class UpdateParameterValues:
129130
"""
130131
Update a set of parameters according to supplied rules and defaults.
@@ -184,7 +185,7 @@ def __init__(
184185
"""
185186

186187
self.parameters = copy.deepcopy(parameters)
187-
self.defaults = copy.deepcopy(defaults)
188+
self.defaults: dict = copy.deepcopy(defaults)
188189
self.input_set = input_set
189190
self.vasp_version = vasp_version
190191
self.structure = structure
@@ -220,8 +221,8 @@ def update_parameters_and_defaults(self) -> None:
220221
self.add_defaults_to_parameters()
221222

222223
for key, v in self.defaults.items():
223-
if isinstance(v,dict):
224-
self.defaults[key] = VaspParam(**{"name":key,**v})
224+
if isinstance(v, dict):
225+
self.defaults[key] = VaspParam(**{"name": key, **v})
225226

226227
def add_defaults_to_parameters(self, valid_values_source: dict | None = None) -> None:
227228
"""
@@ -333,10 +334,10 @@ def update_precision_params(self) -> None:
333334
}
334335
self.parameters["ROPT"] = [abs(value) for value in self.parameters.get("ROPT", [ropt_default[cur_prec]])]
335336
self.defaults["ROPT"] = VaspParam(
336-
name = "ROPT",
337-
value = [abs(ropt_default[cur_prec]) for _ in self.parameters["ROPT"]],
338-
tag = "startup",
339-
operation = ["<=" for _ in self.parameters["ROPT"]],
337+
name="ROPT",
338+
value=[abs(ropt_default[cur_prec]) for _ in self.parameters["ROPT"]],
339+
tag="startup",
340+
operation=["<=" for _ in self.parameters["ROPT"]],
340341
)
341342

342343
def update_misc_special_params(self) -> None:
@@ -449,10 +450,10 @@ def update_fft_params(self) -> None:
449450
self.valid_values[key] = int(self.valid_values[key] * self._fft_grid_tolerance)
450451

451452
self.defaults[key] = VaspParam(
452-
name = key,
453-
value = self.valid_values[key],
454-
tag = "fft",
455-
operation = ">=",
453+
name=key,
454+
value=self.valid_values[key],
455+
tag="fft",
456+
operation=">=",
456457
comment=(
457458
"This likely means the number FFT grid points was modified by the user. "
458459
"If not, please create a GitHub issue."
@@ -566,15 +567,15 @@ def update_smearing_params(self, bandgap_tol=1.0e-4) -> None:
566567
self.valid_values["ELECTRONIC ENTROPY"] = 0.001 * convert_eV_to_meV
567568

568569
self.defaults["ELECTRONIC ENTROPY"] = VaspParam(
569-
name = "ELECTRONIC ENTROPY",
570-
value = 0.0,
571-
tag = "smearing",
570+
name="ELECTRONIC ENTROPY",
571+
value=0.0,
572+
tag="smearing",
572573
comment=(
573574
"The entropy term (T*S) in the energy is suggested to be less than "
574575
f"{round(self.valid_values['ELECTRONIC ENTROPY'], 1)} meV/atom "
575576
f"in the VASP wiki. Thus, SIGMA should be decreased."
576577
),
577-
operation = "<=",
578+
operation="<=",
578579
)
579580

580581
def _get_default_nbands(self):
@@ -654,15 +655,15 @@ def update_electronic_params(self):
654655
# NBANDS.
655656
min_nbands = int(np.ceil(self._NELECT / 2) + 1)
656657
self.defaults["NBANDS"] = VaspParam(
657-
name = "NBANDS",
658-
value = self._get_default_nbands(),
659-
tag = "electronic",
660-
operation = [">=", "<="],
661-
comment = (
658+
name="NBANDS",
659+
value=self._get_default_nbands(),
660+
tag="electronic",
661+
operation=[">=", "<="],
662+
comment=(
662663
"Too many or too few bands can lead to unphysical electronic structure "
663664
"(see https://github.com/materialsproject/custodian/issues/224 "
664665
"for more context.)"
665-
)
666+
),
666667
)
667668
self.valid_values["NBANDS"] = [min_nbands, 4 * self.defaults["NBANDS"]["value"]]
668669
self.parameters["NBANDS"] = [self.parameters["NBANDS"] for _ in range(2)]
@@ -715,7 +716,7 @@ def update_ionic_params(self):
715716
# every MP-compliant input set, but often have comparable or even better results) will also be accepted
716717
# I am **NOT** confident that this should be the final check. Perhaps I need convincing (or perhaps it does indeed need to be changed...)
717718
# TODO: -somehow identify if a material is a vdW structure, in which case force-convergence should maybe be more strict?
718-
self.defaults["EDIFFG"] = VaspParam(name = "EDIFFG", value = 10 * self.valid_values["EDIFF"], tag = "ionic")
719+
self.defaults["EDIFFG"] = VaspParam(name="EDIFFG", value=10 * self.valid_values["EDIFF"], tag="ionic")
719720

720721
self.valid_values["EDIFFG"] = self.input_set.incar.get("EDIFFG", self.defaults["EDIFFG"]["value"])
721722
self.defaults["EDIFFG"][

pymatgen/io/validation/vasp_defaults.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,21 @@ def __init__(
8383
tag: InputCategory | str,
8484
operation: str | Sequence[str] | None = None,
8585
alias: str | None = None,
86-
tolerance: float = 1.e-4,
86+
tolerance: float = 1.0e-4,
8787
comment: str | None = None,
88-
warning : str | None = None,
89-
severity : Literal["reason", "warning"] = "reason"
88+
warning: str | None = None,
89+
severity: Literal["reason", "warning"] = "reason",
9090
) -> None:
9191

9292
self.name = name
9393
self.value = value
94-
if (
95-
(isinstance(operation,str) and operation not in VALID_OPERATIONS)
96-
or (isinstance(operation,list | tuple) and any(op not in VALID_OPERATIONS for op in operation))
94+
if (isinstance(operation, str) and operation not in VALID_OPERATIONS) or (
95+
isinstance(operation, list | tuple) and any(op not in VALID_OPERATIONS for op in operation)
9796
):
97+
if isinstance(operation, list | tuple):
98+
operation = f"[{', '.join(operation)}]"
9899
raise InvalidOperation(operation)
99-
100+
100101
self.operation = operation
101102
self.alias = alias or name
102103
if isinstance(tag, str):
@@ -109,7 +110,7 @@ def __init__(
109110
self.comment = comment
110111
self.warning = warning
111112

112-
if severity not in {"reason","warning"}:
113+
if severity not in {"reason", "warning"}:
113114
raise ValueError(f"`severity` must either be 'reason' or 'warning', not {severity}")
114115
self.severity = severity
115116

@@ -126,9 +127,10 @@ def update(self, dct: dict[str, Any]) -> None:
126127
for k, v in dct.items():
127128
self[k] = v
128129

129-
def as_dict(self) -> dict[str,Any]:
130+
def as_dict(self) -> dict[str, Any]:
130131
"""Convert to a dict."""
131-
return {k: getattr(self,k) for k in self.__slots__}
132+
return {k: getattr(self, k) for k in self.__slots__}
133+
132134

133135
VASP_DEFAULTS_LIST = [
134136
VaspParam("ADDGRID", False, "fft", operation="=="),

0 commit comments

Comments
 (0)