Skip to content

Commit

Permalink
switch to absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetretto committed Jul 20, 2023
1 parent 7fbf27e commit 856e650
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
10 changes: 10 additions & 0 deletions custodian/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,26 @@ class tracked_lru_cache:
cached_functions: set = set()

def __init__(self, func):
"""
Args:
func: function to be decorated
"""
self.func = functools.lru_cache(func)
functools.update_wrapper(self, func)

def __call__(self, *args, **kwargs):
"""
Call the decorated function
"""
result = self.func(*args, **kwargs)
self.cached_functions.add(self.func)
return result

@classmethod
def cache_clear(cls):
"""
Clear the cache of all the decorated functions.
"""
while cls.cached_functions:
f = cls.cached_functions.pop()
f.cache_clear()
20 changes: 10 additions & 10 deletions custodian/vasp/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def correct(self):
# resources, seems to be to just increase NCORE slightly. That's what I do here.
nprocs = multiprocessing.cpu_count()
try:
nelect = load_outcar("OUTCAR").nelect
nelect = load_outcar(os.path.join(os.getcwd(), "OUTCAR")).nelect
except Exception:
nelect = 1 # dummy value
if nelect < nprocs:
Expand Down Expand Up @@ -885,7 +885,7 @@ def check(self):
self.max_drift = incar["EDIFFG"] * -1

try:
outcar = load_outcar("OUTCAR")
outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR"))
except Exception:
# Can't perform check if Outcar not valid
return False
Expand All @@ -907,7 +907,7 @@ def correct(self):
vi = VaspInput.from_directory(".")

incar = vi["INCAR"]
outcar = load_outcar("OUTCAR")
outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR"))

# Move CONTCAR to POSCAR
actions.append({"file": "CONTCAR", "action": {"_file_copy": {"dest": "POSCAR"}}})
Expand Down Expand Up @@ -981,7 +981,7 @@ def check(self):
return False

try:
v = load_vasprun(self.output_vasprun)
v = load_vasprun(os.path.join(os.getcwd(), self.output_vasprun))
if v.converged:
return False
except Exception:
Expand Down Expand Up @@ -1030,7 +1030,7 @@ def check(self):
Check for error.
"""
try:
v = load_vasprun(self.output_filename)
v = load_vasprun(os.path.join(os.getcwd(), self.output_filename))
if not v.converged:
return True
except Exception:
Expand All @@ -1041,7 +1041,7 @@ def correct(self):
"""
Perform corrections.
"""
v = load_vasprun(self.output_filename)
v = load_vasprun(os.path.join(os.getcwd(), self.output_filename))
algo = v.incar.get("ALGO", "Normal").lower()
actions = []
if not v.converged_electronic:
Expand Down Expand Up @@ -1151,7 +1151,7 @@ def check(self):
Check for error.
"""
try:
v = load_vasprun(self.output_filename)
v = load_vasprun(os.path.join(os.getcwd(), self.output_filename))
# check whether bandgap is zero, tetrahedron smearing was used
# and relaxation is performed.
if v.eigenvalue_band_properties[0] == 0 and v.incar.get("ISMEAR", 1) < -3 and v.incar.get("NSW", 0) > 1:
Expand Down Expand Up @@ -1200,7 +1200,7 @@ def check(self):
Check for error.
"""
try:
v = load_vasprun(self.output_filename)
v = load_vasprun(os.path.join(os.getcwd(), self.output_filename))
# check whether bandgap is zero and tetrahedron smearing was used
if v.eigenvalue_band_properties[0] == 0 and v.incar.get("KSPACING", 1) > 0.22:
return True
Expand Down Expand Up @@ -1249,7 +1249,7 @@ def check(self):
"""
incar = Incar.from_file("INCAR")
try:
outcar = load_outcar("OUTCAR")
outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR"))
except Exception:
# Can't perform check if Outcar not valid
return False
Expand Down Expand Up @@ -1616,7 +1616,7 @@ def check(self):
if self.wall_time:
run_time = datetime.datetime.now() - self.start_time
total_secs = run_time.total_seconds()
outcar = load_outcar("OUTCAR")
outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR"))
if not self.electronic_step_stop:
# Determine max time per ionic step.
outcar.read_pattern({"timings": r"LOOP\+.+real time(.+)"}, postprocess=float)
Expand Down
4 changes: 4 additions & 0 deletions custodian/vasp/io.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Helper functions for dealing with vasp files.
"""

from pymatgen.io.vasp.outputs import Outcar, Vasprun

from custodian.utils import tracked_lru_cache
Expand Down
4 changes: 2 additions & 2 deletions custodian/vasp/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check(self):
Check for error.
"""
try:
load_vasprun("vasprun.xml")
load_vasprun(os.path.join(os.getcwd(), "vasprun.xml"))
except Exception:
exception_context = {}

Expand Down Expand Up @@ -106,7 +106,7 @@ def check(self):
if not is_npt:
return False

outcar = load_outcar("OUTCAR")
outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR"))
patterns = {"MDALGO": r"MDALGO\s+=\s+([\d]+)"}
outcar.read_pattern(patterns=patterns)
if outcar.data["MDALGO"] == [["3"]]:
Expand Down

0 comments on commit 856e650

Please sign in to comment.