From 48545f45e8c750f8e4baffb7cc02657437f89e25 Mon Sep 17 00:00:00 2001 From: zulissimeta <122578103+zulissimeta@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:18:31 -0700 Subject: [PATCH] small fixes to propagate directory (#341) --- src/custodian/cp2k/interpreter.py | 2 +- src/custodian/cp2k/jobs.py | 41 +++++++++++++++++++++++++------ src/custodian/feff/interpreter.py | 2 +- src/custodian/vasp/interpreter.py | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/custodian/cp2k/interpreter.py b/src/custodian/cp2k/interpreter.py index 7baa1ffd..d28252ca 100644 --- a/src/custodian/cp2k/interpreter.py +++ b/src/custodian/cp2k/interpreter.py @@ -42,7 +42,7 @@ def __init__(self, filename="cp2k.inp", actions=None, strict=True, ci=None, dire self.ci = ci or Cp2kInput.from_file(os.path.join(self.directory, filename)) self.filename = filename actions = actions or [FileActions, DictActions] - super().__init__(actions, strict) + super().__init__(actions, strict, directory=directory) def apply_actions(self, actions) -> None: """ diff --git a/src/custodian/cp2k/jobs.py b/src/custodian/cp2k/jobs.py index a1f7330a..11842b7a 100644 --- a/src/custodian/cp2k/jobs.py +++ b/src/custodian/cp2k/jobs.py @@ -101,11 +101,19 @@ def setup(self, directory="./") -> None: ) if self.settings_override or self.restart: - modder = Cp2kModder(filename=os.path.join(directory, self.input_file), actions=[], ci=self.ci) + modder = Cp2kModder( + filename=os.path.join(directory, self.input_file), + actions=[], + ci=self.ci, + directory=directory, + ) modder.apply_actions(self.settings_override) if self.backup: - shutil.copy(os.path.join(directory, self.input_file), os.path.join(directory, f"{self.input_file}.orig")) + shutil.copy( + os.path.join(directory, self.input_file), + os.path.join(directory, f"{self.input_file}.orig"), + ) def run(self, directory="./"): """ @@ -138,9 +146,15 @@ def postprocess(self, directory="./") -> None: continue if not os.path.isdir(os.path.join(directory, file)): if self.final: - shutil.move(os.path.join(directory, file), os.path.join(directory, f"run{self.suffix}/{file}")) + shutil.move( + os.path.join(directory, file), + os.path.join(directory, f"run{self.suffix}/{file}"), + ) else: - shutil.copy(os.path.join(directory, file), os.path.join(directory, f"run{self.suffix}/{file}")) + shutil.copy( + os.path.join(directory, file), + os.path.join(directory, f"run{self.suffix}/{file}"), + ) # Remove continuation so if a subsequent job is run in # the same directory, will not restart this job. @@ -200,7 +214,12 @@ def gga_static_to_hybrid( ci = Cp2kInput.from_file(zpath(os.path.join(directory, input_file))) 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 + if run_type in { + "ENERGY", + "WAVEFUNCTION_OPTIMIZATION", + "WFN_OPT", + "ENERGY_FORCE", + }: # no need for double job return [job1] job2_settings_override = [ @@ -270,7 +289,10 @@ def double_job( 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"}}}} + { + "dict": input_file, + "action": {"_set": {"GLOBAL": {"RUN_TYPE": "ENERGY_FORCE"}}}, + } ] job2 = Cp2kJob( @@ -337,7 +359,12 @@ def pre_screen_hybrid( ci = Cp2kInput.from_file(zpath(os.path.join(directory, 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 = [ diff --git a/src/custodian/feff/interpreter.py b/src/custodian/feff/interpreter.py index df44cdbd..f5e897fc 100644 --- a/src/custodian/feff/interpreter.py +++ b/src/custodian/feff/interpreter.py @@ -32,7 +32,7 @@ def __init__(self, actions=None, strict=True, feffinp=None, directory="./") -> N self.feffinp = feffinp or FEFFDictSet.from_directory(self.directory) self.feffinp = self.feffinp.all_input() actions = actions or [FileActions, DictActions] - super().__init__(actions, strict) + super().__init__(actions, strict, directory=directory) def apply_actions(self, actions) -> None: """ diff --git a/src/custodian/vasp/interpreter.py b/src/custodian/vasp/interpreter.py index 80795d27..aba48d2e 100644 --- a/src/custodian/vasp/interpreter.py +++ b/src/custodian/vasp/interpreter.py @@ -30,7 +30,7 @@ def __init__(self, actions=None, strict=True, vi=None, directory="./") -> None: self.vi = vi or VaspInput.from_directory(directory) self.directory = directory actions = actions or [FileActions, DictActions] - super().__init__(actions, strict) + super().__init__(actions, strict, directory=directory) def apply_actions(self, actions) -> None: """