Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to copy specific files/directories when parent_folder in inputs #773

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions aiida_quantumespresso/calculations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import copy
import numbers
from pathlib import Path
import warnings
from functools import partial
from types import MappingProxyType
Expand Down Expand Up @@ -211,6 +212,7 @@ def prepare_for_submission(self, folder):

# operations for restart
symlink = settings.pop('PARENT_FOLDER_SYMLINK', self._default_symlink_usage) # a boolean
restart_copy_files = settings.pop('RESTART_COPY_FILES', None) # a list of strings
if symlink:
if 'parent_folder' in self.inputs:
# I put the symlink to the old parent ./out folder
Expand All @@ -220,8 +222,32 @@ def prepare_for_submission(self, folder):
self._restart_copy_from), self._restart_copy_to
))
else:
# copy remote output dir, if specified
if 'parent_folder' in self.inputs:
# copy specific file(s) or all from remote output dir, if specified
if 'parent_folder' in self.inputs and restart_copy_files:
restart_copy_from = []
# if the `restart_copy_files`` field is specified, I put the path joined
# to './out' in the `remote_copy_list`. If the file is in a subfolder of
# './out', then I create as many subdirs as needed for the new calculation.
for file in restart_copy_files:
path = Path(file)
restart_copy_from.append(os.path.join(self._OUTPUT_SUBFOLDER, path))
# here I create eventual subdir(s) in path
subdir = self._OUTPUT_SUBFOLDER
for part in path.parts:
subdir = os.path.join(subdir, part)
if subdir != restart_copy_from[-1]:
folder.get_subfolder(subdir, create=True)

for copy_from in restart_copy_from:
if Path(copy_from).parts[-1] == '*':
restart_copy_to = Path(copy_from).parent.name
else:
restart_copy_to = copy_from
remote_copy_list.append((
self.inputs.parent_folder.computer.uuid,
os.path.join(self.inputs.parent_folder.get_remote_path(), copy_from), restart_copy_to
))
elif 'parent_folder' in self.inputs:
remote_copy_list.append((
self.inputs.parent_folder.computer.uuid,
os.path.join(self.inputs.parent_folder.get_remote_path(),
Expand Down