From bd4c1e40847b20b4676000af21a962fab534691c Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Sun, 8 Oct 2023 06:27:02 -0700 Subject: [PATCH] ruff . --select FURB --preview --fix --- .pre-commit-config.yaml | 2 +- custodian/qchem/handlers.py | 9 ++---- custodian/vasp/handlers.py | 51 +++++++++++++++---------------- custodian/vasp/tests/test_jobs.py | 2 +- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 83a69edf..5dca34d7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/custodian/qchem/handlers.py b/custodian/qchem/handlers.py index 5fe8860c..28e0e510 100644 --- a/custodian/qchem/handlers.py +++ b/custodian/qchem/handlers.py @@ -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") @@ -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 diff --git a/custodian/vasp/handlers.py b/custodian/vasp/handlers.py index 6780e6af..854ccd36 100644 --- a/custodian/vasp/handlers.py +++ b/custodian/vasp/handlers.py @@ -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" @@ -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: @@ -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: @@ -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( @@ -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(".") @@ -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} diff --git a/custodian/vasp/tests/test_jobs.py b/custodian/vasp/tests/test_jobs.py index 13a96462..2cc97aa0 100644 --- a/custodian/vasp/tests/test_jobs.py +++ b/custodian/vasp/tests/test_jobs.py @@ -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):