Skip to content

Commit

Permalink
fix AttributeError NoneType has no attribute 'style' when using INCAR…
Browse files Browse the repository at this point in the history
… tag 'kspacing' instead of KPOINTS file
  • Loading branch information
janosh committed Aug 4, 2023
1 parent 1497cd4 commit 20af8b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion custodian/cli/run_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_jobs(args):
]
)
auto_npar = False
elif job_type.startswith("static"):
elif job_type.startswith("static") and vinput["KPOINTS"] is not None:
m = [i * args.static_kpoint for i in vinput["KPOINTS"].kpts[0]]
settings.extend(
[
Expand Down
29 changes: 17 additions & 12 deletions custodian/vasp/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def correct(self):
self.error_count["brmix"] += 1

elif self.error_count["brmix"] == 1 and vi["INCAR"].get("IMIX", 4) != 1:
# Use Kerker mixing w/default values for other parameters
# Use Kerker mixing w/ default values for other parameters
actions.append({"dict": "INCAR", "action": {"_set": {"IMIX": 1}}})
self.error_count["brmix"] += 1

Expand All @@ -227,18 +227,21 @@ def correct(self):
actions.append({"dict": "INCAR", "action": {"_unset": {"IMIX": 1}}})
self.error_count["brmix"] += 1

elif self.error_count["brmix"] in [2, 3] and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst:
actions.append(
{
"dict": "KPOINTS",
"action": {"_set": {"generation_style": "Gamma"}},
}
)
elif self.error_count["brmix"] in [2, 3]:
if vi["KPOINTS"] is not None and vi["KPOINTS"].style == Kpoints.supported_modes.Gamma:
actions.append({"dict": "KPOINTS", "action": {"_set": {"generation_style": "Gamma"}}})
elif vi["INCAR"].get("KSPACING"):
actions.append({"dict": "INCAR", "action": {"_set": {"KGAMMA": True}}})

if "IMIX" in vi["INCAR"]:
actions.append({"dict": "INCAR", "action": {"_unset": {"IMIX": 1}}})
self.error_count["brmix"] += 1

if vi["KPOINTS"].num_kpts < 1 and all(n % 2 == 0 for n in vi["KPOINTS"].kpts[0]):
if (
vi["KPOINTS"] is not None
and vi["KPOINTS"].num_kpts < 1
and all(n % 2 == 0 for n in vi["KPOINTS"].kpts[0])
):
new_kpts = (tuple(n + 1 for n in vi["KPOINTS"].kpts[0]),)
actions.append(
{
Expand Down Expand Up @@ -748,7 +751,7 @@ def correct(self):
if "kpoints_trans" in self.errors and self.error_count["kpoints_trans"] == 0:
m = reduce(operator.mul, vi["KPOINTS"].kpts[0])
m = max(int(round(m ** (1 / 3))), 1)
if vi["KPOINTS"].style.name.lower().startswith("m"):
if vi["KPOINTS"] is not None and vi["KPOINTS"].style.name.lower().startswith("m"):
m += m % 2
actions.append({"dict": "KPOINTS", "action": {"_set": {"kpoints": [[m] * 3]}}})
self.error_count["kpoints_trans"] += 1
Expand Down Expand Up @@ -978,7 +981,9 @@ def check(self):
# According to VASP admins, you can disregard this error
# if symmetry is off
# Also disregard if automatic KPOINT generation is used
if (not vi["INCAR"].get("ISYM", True)) or vi["KPOINTS"].style == Kpoints.supported_modes.Automatic:
if (not vi["INCAR"].get("ISYM", True)) or (
vi["KPOINTS"] is not None and vi["KPOINTS"].style == Kpoints.supported_modes.Automatic
):
return False

try:
Expand All @@ -1000,7 +1005,7 @@ def correct(self):
vi = VaspInput.from_directory(".")
m = reduce(operator.mul, vi["KPOINTS"].kpts[0])
m = max(int(round(m ** (1 / 3))), 1)
if vi["KPOINTS"].style.name.lower().startswith("m"):
if vi["KPOINTS"] is not None and vi["KPOINTS"].style.name.lower().startswith("m"):
m += m % 2
actions = [{"dict": "KPOINTS", "action": {"_set": {"kpoints": [[m] * 3]}}}]
VaspModder(vi=vi).apply_actions(actions)
Expand Down

0 comments on commit 20af8b2

Please sign in to comment.