Skip to content

Commit

Permalink
small fixes to propagate directory (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
zulissimeta committed Jul 2, 2024
1 parent 94b91d5 commit 48545f4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/custodian/cp2k/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
41 changes: 34 additions & 7 deletions src/custodian/cp2k/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="./"):
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/custodian/feff/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/custodian/vasp/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down

0 comments on commit 48545f4

Please sign in to comment.