Skip to content

Commit

Permalink
use sets for membership checks
Browse files Browse the repository at this point in the history
fix typos
  • Loading branch information
janosh committed Nov 14, 2023
1 parent 141209b commit d200876
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 97 deletions.
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
exclude: ^(docs|test_files|tests)
exclude: ^(docs|test_files)

ci:
autoupdate_schedule: monthly
skip: [mypy]
autofix_commit_msg: pre-commit auto-fixes
autoupdate_commit_msg: pre-commit autoupdate

Expand All @@ -23,7 +22,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.7.0
hooks:
- id: mypy
additional_dependencies: [types-requests]
Expand Down
17 changes: 12 additions & 5 deletions custodian/cli/run_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,18 @@ def get_jobs(args):
from pymatgen.io.vasp.sets import MPStaticDielectricDFPTVaspInputSet, MPStaticSet

# vis = MPStaticSet.from_prev_calc(
# ".", user_incar_settings={"EDIFF": 1e-6, "IBRION": 8,
# "LEPSILON": True, 'LREAL':False,
# "LPEAD": True, "ISMEAR": 0,
# "SIGMA": 0.01},
# ediff_per_atom=False)
# ".",
# user_incar_settings={
# "EDIFF": 1e-6,
# "IBRION": 8,
# "LEPSILON": True,
# "LREAL": False,
# "LPEAD": True,
# "ISMEAR": 0,
# "SIGMA": 0.01,
# },
# ediff_per_atom=False,
# )
vis = MPStaticDielectricDFPTVaspInputSet()
incar = vis.get_incar(vinput["POSCAR"].structure)
unset = {}
Expand Down
4 changes: 2 additions & 2 deletions custodian/cp2k/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class UnconvergedScfErrorHandler(ErrorHandler):
can also use Iterative Refinement of the approximate congruency
transformation.
(iv) Once can enable rotations of the occupied subspace which allows
fractional occupations with OT. As of October 2021, this option cannot
be used with 3 point CG, FULL_ALL, or FULL_SINGLE_INVERSE.
fractional occupations with OT. As of October 2021, this option cannot
be used with 3 point CG, FULL_ALL, or FULL_SINGLE_INVERSE.
(2) Traditional Diagonalization:
Expand Down
14 changes: 7 additions & 7 deletions custodian/cp2k/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def gga_static_to_hybrid(
)

ci = Cp2kInput.from_file(zpath(input_file))
r = ci["global"].get("run_type", Keyword("RUN_TYPE", "ENERGY_FORCE")).values[0]
if r in ["ENERGY", "WAVEFUNCTION_OPTIMIZATION", "WFN_OPT", "ENERGY_FORCE"]: # no need for double job
run_type = ci["global"].get("run_type", Keyword("RUN_TYPE", "ENERGY_FORCE")).values[0]
if run_type in {"ENERGY", "WAVEFUNCTION_OPTIMIZATION", "WFN_OPT", "ENERGY_FORCE"}: # no need for double job
return [job1]

job2_settings_override = [
Expand All @@ -217,7 +217,7 @@ def gga_static_to_hybrid(
"WFN_RESTART_FILE_NAME": "GGA-RESTART.wfn",
}
},
"GLOBAL": {"RUN_TYPE": r},
"GLOBAL": {"RUN_TYPE": run_type},
},
},
}
Expand Down Expand Up @@ -257,8 +257,8 @@ def double_job(
settings_override={},
)
ci = Cp2kInput.from_file(zpath(input_file))
r = ci["global"].get("run_type", Keyword("RUN_TYPE", "ENERGY_FORCE")).values[0]
if r not in ["ENERGY", "WAVEFUNCTION_OPTIMIZATION", "WFN_OPT"]:
run_type = ci["global"].get("run_type", Keyword("RUN_TYPE", "ENERGY_FORCE")).values[0]
if run_type not in {"ENERGY", "WAVEFUNCTION_OPTIMIZATION", "WFN_OPT"}:
job1.settings_override = [
{"dict": input_file, "action": {"_set": {"GLOBAL": {"RUN_TYPE": "ENERGY_FORCE"}}}}
]
Expand All @@ -273,7 +273,7 @@ def double_job(
suffix="2",
restart=True,
)
job2.settings_override = [{"dict": input_file, "action": {"_set": {"GLOBAL": {"RUN_TYPE": r}}}}]
job2.settings_override = [{"dict": input_file, "action": {"_set": {"GLOBAL": {"RUN_TYPE": run_type}}}}]

return [job1, job2]

Expand Down Expand Up @@ -321,7 +321,7 @@ def pre_screen_hybrid(

ci = Cp2kInput.from_file(zpath(input_file))
r = ci["global"].get("run_type", Keyword("RUN_TYPE", "ENERGY_FORCE")).values[0]
if r in ["ENERGY", "WAVEFUNCTION_OPTIMIZATION", "WFN_OPT", "ENERGY_FORCE"]: # no need for double job
if r in {"ENERGY", "WAVEFUNCTION_OPTIMIZATION", "WFN_OPT", "ENERGY_FORCE"}: # no need for double job
return [job1]

job2_settings_override = [
Expand Down
4 changes: 2 additions & 2 deletions custodian/qchem/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def opt_with_frequency_flattener(
opt_geom_opt = copy.deepcopy(opt_indata.geom_opt)
opt_geom_opt["initial_hessian"] = "read"
for key in opt_indata.rem:
if key not in ["job_type", "geom_opt2", "scf_guess_always"]:
if key not in {"job_type", "geom_opt2", "scf_guess_always"}:
if freq_rem.get(key, None) != opt_indata.rem[key] and "geom_opt" not in key:
freq_rem[key] = opt_indata.rem[key]
if opt_rem.get(key, None) != opt_indata.rem[key]:
Expand Down Expand Up @@ -365,7 +365,7 @@ def opt_with_frequency_flattener(
freq_outdata = QCOutput(output_file + ".freq_" + str(ii)).data
freq_indata = QCInput.from_file(input_file + ".freq_" + str(ii))
for key in freq_indata.rem:
if key not in ["job_type", "geom_opt2", "scf_guess_always"]:
if key not in {"job_type", "geom_opt2", "scf_guess_always"}:
if freq_rem.get(key, None) != freq_indata.rem[key]:
freq_rem[key] = freq_indata.rem[key]
if opt_rem.get(key, None) != freq_indata.rem[key] and key != "cpscf_nseg":
Expand Down
14 changes: 7 additions & 7 deletions custodian/vasp/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def correct(self):
self.error_count["brmix"] += 1

elif (
self.error_count["brmix"] in [2, 3]
self.error_count["brmix"] in {2, 3}
and vi["KPOINTS"]
and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst
):
Expand All @@ -264,7 +264,7 @@ def correct(self):
}
)

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

else:
Expand Down Expand Up @@ -476,7 +476,7 @@ def correct(self):
is_contcar = False
if is_contcar:
actions.append({"file": "CONTCAR", "action": {"_file_copy": {"dest": "POSCAR"}}})
if vi["INCAR"].get("ALGO", "Normal").lower() in ["fast", "veryfast"]:
if vi["INCAR"].get("ALGO", "Normal").lower() in {"fast", "veryfast"}:
actions.append({"dict": "INCAR", "action": {"_set": {"ALGO": "Normal"}}})
else:
potim = round(vi["INCAR"].get("POTIM", 0.5) / 2.0, 2)
Expand Down Expand Up @@ -525,7 +525,7 @@ def correct(self):
# are often used with ALGO = All (and hybrids are incompatible with ALGO = VeryFast/Fast and slow with
# ALGO = Normal), we do not adjust ALGO in these cases.
if vi["INCAR"].get("METAGGA", "none") == "none" and not vi["INCAR"].get("LHFCALC", False):
if vi["INCAR"].get("ALGO", "Normal").lower() in ["all", "damped"]:
if vi["INCAR"].get("ALGO", "Normal").lower() in {"all", "damped"}:
actions.append({"dict": "INCAR", "action": {"_set": {"ALGO": "Fast"}}})
elif 53 <= vi["INCAR"].get("IALGO", 38) <= 58:
actions.append({"dict": "INCAR", "action": {"_set": {"ALGO": "Fast"}, "_unset": {"IALGO": 38}}})
Expand Down Expand Up @@ -636,7 +636,7 @@ def correct(self):
# 2) Use ALGO = Damped but only *after* an ISMEAR = 0 run where the wavefunction
# has been stored and read in for the subsequent run.
if (
(algo in ["all", "damped"] or (50 <= vi["INCAR"].get("IALGO", 38) <= 59))
(algo in {"all", "damped"} or (50 <= vi["INCAR"].get("IALGO", 38) <= 59))
and vi["INCAR"].get("ISMEAR", 1) < 0
and self.error_count["algo_tet"] == 0
):
Expand Down Expand Up @@ -1445,7 +1445,7 @@ def correct(self):

# NOTE: This is the algo_tet handler response.
if (
incar.get("ALGO", "Normal").lower() in ["all", "damped"] or (50 <= incar.get("IALGO", 38) <= 59)
incar.get("ALGO", "Normal").lower() in {"all", "damped"} or (50 <= incar.get("IALGO", 38) <= 59)
) and incar.get("ISMEAR", 1) < 0:
# ALGO=All/Damped / IALGO=5X often fails with ISMEAR < 0. There are two options VASP
# suggests: 1) Use ISMEAR = 0 (and a small sigma) to get the SCF to converge.
Expand Down Expand Up @@ -1773,7 +1773,7 @@ def correct(self):
# change ALGO = Fast to Normal if ALGO is !Normal
vi = VaspInput.from_directory(".")
algo = vi["INCAR"].get("ALGO", "Normal").lower()
if algo not in ["normal", "n"]:
if algo not in {"normal", "n"}:
backup(VASP_BACKUP_FILES)
actions = [{"dict": "INCAR", "action": {"_set": {"ALGO": "Normal"}}}]
VaspModder(vi=vi).apply_actions(actions)
Expand Down
8 changes: 4 additions & 4 deletions custodian/vasp/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def setup(self):
incar = Incar.from_file("INCAR")
# Only optimized NPAR for non-HF and non-RPA calculations.
if not (incar.get("LHFCALC") or incar.get("LRPA") or incar.get("LEPSILON")):
if incar.get("IBRION") in [5, 6, 7, 8]:
if incar.get("IBRION") in {5, 6, 7, 8}:
# NPAR should not be set for Hessian matrix
# calculations, whether in DFPT or otherwise.
del incar["NPAR"]
Expand Down Expand Up @@ -361,7 +361,7 @@ def metagga_opt_run(
auto_continue=False,
):
"""
Returns a list of thres jobs to perform an optimization for any
Returns a list of three jobs to perform an optimization for any
metaGGA functional. There is an initial calculation of the
GGA wavefunction which is fed into the initial metaGGA optimization
to precondition the electronic structure optimizer. The metaGGA
Expand All @@ -372,7 +372,7 @@ def metagga_opt_run(
metaGGA = incar.get("METAGGA", "SCAN")

# Pre optimize WAVECAR and structure using regular GGA
pre_opt_setings = [
pre_opt_settings = [
{
"dict": "INCAR",
"action": {"_set": {"METAGGA": None, "LWAVE": True, "NSW": 0}},
Expand All @@ -384,7 +384,7 @@ def metagga_opt_run(
auto_npar=auto_npar,
final=False,
suffix=".precondition",
settings_override=pre_opt_setings,
settings_override=pre_opt_settings,
)
]

Expand Down
2 changes: 1 addition & 1 deletion custodian/vasp/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def check_broken_chgcar(chgcar, diff_thresh=None):
Args:
chgcar (Chgcar): Chgcar-like object.
diff_thresh (Float): Threshold for diagonal difference.
None means we won't check for this.
None means we won't check for this.
"""
chgcar_data = chgcar.data["total"]
if (chgcar_data < 0).sum() > 100:
Expand Down
Loading

0 comments on commit d200876

Please sign in to comment.