Skip to content

Commit

Permalink
ruff . --select FURB --preview --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 8, 2023
1 parent b6142e2 commit bd4c1e4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
args: [--fix, --ignore, D]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
exclude: pymatgen/analysis/vesta_cutoffs.yaml
Expand Down
9 changes: 3 additions & 6 deletions custodian/qchem/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ def correct(self):
if not self.qcinp.rem.get("sym_ignore") or self.qcinp.rem.get("symmetry"):
self.qcinp.rem["sym_ignore"] = "true"
self.qcinp.rem["symmetry"] = "false"
actions.append({"sym_ignore": "true"})
actions.append({"symmetry": "false"})
actions.extend(({"sym_ignore": "true"}, {"symmetry": "false"}))
else:
print("Not sure how else to fix a failed coordinate transformation")

Expand All @@ -295,15 +294,13 @@ def correct(self):
# "run_nbo6" has to change to "nbo_external" in QChem 5.4.2 and later
del self.qcinp.rem["run_nbo6"]
self.qcinp.rem["nbo_external"] = "true"
actions.append({"run_nbo6": "deleted"})
actions.append({"nbo_external": "true"})
actions.extend(({"run_nbo6": "deleted"}, {"nbo_external": "true"}))

elif "bad_new_nbo_external_rem" in self.errors:
# Have to use "run_nbo6" instead of "nbo_external" for QChem 5.4.1 or earlier
del self.qcinp.rem["nbo_external"]
self.qcinp.rem["run_nbo6"] = "true"
actions.append({"nbo_external": "deleted"})
actions.append({"run_nbo6": "true"})
actions.extend(({"nbo_external": "deleted"}, {"run_nbo6": "true"}))

elif "esp_chg_fit_error" in self.errors:
# this error should only be possible if resp_charges or esp_charges is set
Expand Down
51 changes: 24 additions & 27 deletions custodian/vasp/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
from custodian.utils import backup
from custodian.vasp.interpreter import VaspModder

__author__ = "Shyue Ping Ong, William Davidson Richards, Anubhav Jain, Wei Chen, Stephen Dacek, Andrew Rosen"
__author__ = (
"Shyue Ping Ong, William Davidson Richards, Anubhav Jain, Wei Chen, "
"Stephen Dacek, Andrew Rosen, Janosh Riebesell"
)
__version__ = "0.1"
__maintainer__ = "Shyue Ping Ong"
__email__ = "ongsp@ucsd.edu"
Expand Down Expand Up @@ -281,18 +284,10 @@ def correct(self):
# CHGCAR and WAVECAR when dealing with this error.
# A.S.R.: Then why only delete them now?
if vi["INCAR"].get("ICHARG", 0) < 10:
actions.append(
{
"file": "CHGCAR",
"action": {"_file_delete": {"mode": "actual"}},
}
)
actions.append(
{
"file": "WAVECAR",
"action": {"_file_delete": {"mode": "actual"}},
}
)
actions += [
{"file": "CHGCAR", "action": {"_file_delete": {"mode": "actual"}}},
{"file": "WAVECAR", "action": {"_file_delete": {"mode": "actual"}}},
]
self.error_count["brmix"] += 1

if "zpotrf" in self.errors:
Expand Down Expand Up @@ -482,8 +477,10 @@ def correct(self):
potim = round(vi["INCAR"].get("POTIM", 0.5) / 2.0, 2)
actions.append({"dict": "INCAR", "action": {"_set": {"POTIM": potim}}})
if vi["INCAR"].get("ICHARG", 0) < 10:
actions.append({"file": "CHGCAR", "action": {"_file_delete": {"mode": "actual"}}})
actions.append({"file": "WAVECAR", "action": {"_file_delete": {"mode": "actual"}}})
actions += [
{"file": "CHGCAR", "action": {"_file_delete": {"mode": "actual"}}},
{"file": "WAVECAR", "action": {"_file_delete": {"mode": "actual"}}},
]
self.error_count["eddrmm"] += 1

if "edddav" in self.errors:
Expand Down Expand Up @@ -923,13 +920,10 @@ def correct(self):

# Set PREC to High so ENAUG can be used to control Augmentation Grid Size
if incar.get("PREC", "Accurate").lower() != "high":
actions.append({"dict": "INCAR", "action": {"_set": {"PREC": "High"}}})
actions.append(
{
"dict": "INCAR",
"action": {"_set": {"ENAUG": incar.get("ENCUT", 520) * 2}},
}
)
actions += [
{"dict": "INCAR", "action": {"_set": {"PREC": "High"}}},
{"dict": "INCAR", "action": {"_set": {"ENAUG": incar.get("ENCUT", 520) * 2}}},
]
# PREC is already high and ENAUG set so just increase it
else:
actions.append(
Expand Down Expand Up @@ -1103,8 +1097,10 @@ def correct(self):
elif not v.converged_ionic:
# Just continue optimizing and let other handlers fix ionic
# optimizer parameters
actions.append({"dict": "INCAR", "action": {"_set": {"IBRION": 1}}})
actions.append({"file": "CONTCAR", "action": {"_file_copy": {"dest": "POSCAR"}}})
actions += [
{"dict": "INCAR", "action": {"_set": {"IBRION": 1}}},
{"file": "CONTCAR", "action": {"_file_copy": {"dest": "POSCAR"}}},
]

if actions:
vi = VaspInput.from_directory(".")
Expand Down Expand Up @@ -1153,9 +1149,10 @@ def correct(self):
backup(VASP_BACKUP_FILES | {self.output_filename})
vi = VaspInput.from_directory(".")

actions = []
actions.append({"dict": "INCAR", "action": {"_set": {"ISMEAR": 2}}})
actions.append({"dict": "INCAR", "action": {"_set": {"SIGMA": 0.2}}})
actions = [
{"dict": "INCAR", "action": {"_set": {"ISMEAR": 2}}},
{"dict": "INCAR", "action": {"_set": {"SIGMA": 0.2}}},
]

VaspModder(vi=vi).apply_actions(actions)
return {"errors": ["IncorrectSmearing"], "actions": actions}
Expand Down
2 changes: 1 addition & 1 deletion custodian/vasp/tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from custodian.vasp.jobs import GenerateVaspInputJob, VaspJob, VaspNEBJob

test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "test_files")
pymatgen.core.SETTINGS["PMG_VASP_PSP_DIR"] = os.path.abspath(test_dir) # type: ignore
pymatgen.core.SETTINGS["PMG_VASP_PSP_DIR"] = os.path.abspath(test_dir)


class VaspJobTest(unittest.TestCase):
Expand Down

0 comments on commit bd4c1e4

Please sign in to comment.