From 999e6c9ce5358ba8bc242e7dde8122e59a26ebfb Mon Sep 17 00:00:00 2001 From: PythonFZ Date: Tue, 15 Nov 2022 14:56:24 +0100 Subject: [PATCH 1/2] update CP2K Node --- znlib/atomistic/cp2k.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/znlib/atomistic/cp2k.py b/znlib/atomistic/cp2k.py index a8c5f60..82a8b15 100644 --- a/znlib/atomistic/cp2k.py +++ b/znlib/atomistic/cp2k.py @@ -44,6 +44,7 @@ class CP2KNode(Node): input_file: str = dvc.params() # e.g. "env OMP_NUM_THREADS=2 mpiexec -np 4 cp2k_shell.psmp" cp2k_shell: str = meta.Text("cp2k_shell.psmp") + label: str = meta.Text("cp2k") outputs: AtomsList = ZnAtoms() @@ -84,34 +85,32 @@ def get_calculator(self, script) -> ase.calculators.cp2k.CP2K: stress_tensor=self.stress_tensor, xc=None, print_level=None, - label="cp2k", + label=self.label, ) def _move_cp2k_outs(self): """The CP2K command is executed in the cwd. Output files will be moved to NWD afterward.""" - for file in pathlib.Path(".").glob("cp2k-RESTART.wfn*"): + for file in pathlib.Path(".").glob(f"{self.label}*"): file.rename(self.cp2k_output_dir / file) - cp2k_inp = pathlib.Path("cp2k.inp") - cp2k_inp.rename(self.cp2k_output_dir / cp2k_inp) - - cp2k_out = pathlib.Path("cp2k.out") - cp2k_out.rename(self.cp2k_output_dir / cp2k_out) - @property def wfn_restart_file(self) -> pathlib.Path: # TODO if the file does not work return path to one of the backup files - return self.cp2k_output_dir / "cp2k-RESTART.wfn" + return self.cp2k_output_dir / f"{self.label}-RESTART.wfn" def run(self): - if self.cp2k_output_dir.exists(): - shutil.rmtree(self.cp2k_output_dir) + # ! assert there are no files starting with cp2k_... + # ! run cp2k + # ! Do checkpoints?!? + # ! move outputs + # if self.cp2k_output_dir.exists(): + # shutil.rmtree(self.cp2k_output_dir) self.cp2k_output_dir.mkdir() if self.wfn_restart is not None: # TODO maybe rename the file otherwise? - assert pathlib.Path(self.wfn_restart).name == "cp2k-RESTART.wfn" + assert pathlib.Path(self.wfn_restart).name == f"{self.label}-RESTART.wfn" shutil.copy(self.wfn_restart, ".") with open(self.input_file, "r") as file: @@ -121,11 +120,13 @@ def run(self): cp2k_input_script = "\n".join(CP2KInputGenerator().line_iter(cp2k_input_dict)) + calc = self.get_calculator(cp2k_input_script) + self.outputs = [] for atom in self.atoms: assert isinstance(atom, ase.Atoms) atom = atom.copy() - atom.calc = self.get_calculator(cp2k_input_script) + atom.calc = calc atom.get_potential_energy() self.outputs.append(atom) From 4aee77f1e0a2dd8453baa94746daf111c480a334 Mon Sep 17 00:00:00 2001 From: PythonFZ Date: Tue, 15 Nov 2022 14:57:44 +0100 Subject: [PATCH 2/2] update CP2K Node --- znlib/atomistic/cp2k.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/znlib/atomistic/cp2k.py b/znlib/atomistic/cp2k.py index 82a8b15..c7cb3d7 100644 --- a/znlib/atomistic/cp2k.py +++ b/znlib/atomistic/cp2k.py @@ -44,7 +44,7 @@ class CP2KNode(Node): input_file: str = dvc.params() # e.g. "env OMP_NUM_THREADS=2 mpiexec -np 4 cp2k_shell.psmp" cp2k_shell: str = meta.Text("cp2k_shell.psmp") - label: str = meta.Text("cp2k") + label: str = meta.Text("ase_cp2k") outputs: AtomsList = ZnAtoms()