Skip to content

Commit

Permalink
Fix AttributeError NoneType has no attribute 'style' (#283)
Browse files Browse the repository at this point in the history
* fix AttributeError NoneType has no attribute 'style' when using INCAR tag 'kspacing' instead of KPOINTS file

* fix KeyError custodian/vasp/tests/test_handlers.py:229:          #

The next correction check ISYM and no CHGCAR
        h.correct()
        vi = VaspInput.from_directory(".")
>       assert vi["INCAR"]["ISYM"] == 0
E       KeyError: 'ISYM'

* simplify 'if vi["KPOINTS"] is not None' to 'if vi["KPOINTS"]'

* pytest GH action only run on PR/psuh to master and ignore docs changes
  • Loading branch information
janosh authored Aug 4, 2023
1 parent 1497cd4 commit 7695d4d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Testing

on: [push, pull_request]
on:
push:
branches: [master]
paths-ignore: [docs/**]
pull_request:
branches: [master]
paths-ignore: [docs/**]

jobs:
build:
Expand Down
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"]:
m = [i * args.static_kpoint for i in vinput["KPOINTS"].kpts[0]]
settings.extend(
[
Expand Down
38 changes: 21 additions & 17 deletions custodian/vasp/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ 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

elif (
self.error_count["brmix"] == 2
and vi["KPOINTS"] is not None
and vi["KPOINTS"]
and vi["KPOINTS"].style == Kpoints.supported_modes.Gamma
):
actions.append(
Expand All @@ -227,18 +227,17 @@ 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]
and vi["KPOINTS"]
and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst
):
actions.append({"dict": "KPOINTS", "action": {"_set": {"generation_style": "Gamma"}}})
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"] 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 All @@ -247,17 +246,20 @@ def correct(self):
}
)

elif self.error_count["brmix"] in [2, 3] and vi["INCAR"].get("KSPACING"):
actions.append({"dict": "INCAR", "action": {"_set": {"KGAMMA": True}}})

else:
if vi["INCAR"].get("ISYM", 2) > 0:
actions.append({"dict": "INCAR", "action": {"_set": {"ISYM": 0}}})
if vi["KPOINTS"] is not None and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst:
if vi["KPOINTS"] and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst:
actions.append(
{
"dict": "KPOINTS",
"action": {"_set": {"generation_style": "Gamma"}},
}
)
if vi["KPOINTS"] is not None and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst:
if vi["KPOINTS"] and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst:
actions.append(
{
"dict": "KPOINTS",
Expand Down Expand Up @@ -328,7 +330,7 @@ def correct(self):

if (
self.errors.intersection(["tetirr", "incorrect_shift"])
and vi["KPOINTS"] is not None
and vi["KPOINTS"]
and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst
):
actions.append(
Expand All @@ -339,7 +341,7 @@ def correct(self):
)

if "rot_matrix" in self.errors:
if vi["KPOINTS"] is not None and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst:
if vi["KPOINTS"] and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst:
actions.append(
{
"dict": "KPOINTS",
Expand Down Expand Up @@ -748,7 +750,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"] 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 +980,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"] and vi["KPOINTS"].style == Kpoints.supported_modes.Automatic
):
return False

try:
Expand All @@ -1000,7 +1004,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"] 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 7695d4d

Please sign in to comment.