From 47b1a4d4e66f16c0ad37f2416ca7b6ddd6543a3d Mon Sep 17 00:00:00 2001 From: Jonathan Chico <37243453+JPchico@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:38:32 +0100 Subject: [PATCH] Adding that one can specify other files to be retrieved via the setting (#89) * Adding that one can specify other files to be retrieved via the settings. Addresses #88 * Moving the explanation of the additional_retrieve_list to the settings. Adding that the settings can take a list of strings or a list of tuples. * Update docs/source/topics/workflows/md.md Co-authored-by: Sebastiaan Huber * Update docs/source/topics/calculations/raw.md Co-authored-by: Sebastiaan Huber * Update docs/source/topics/calculations/base.md Co-authored-by: Sebastiaan Huber * Update docs/source/topics/workflows/relax.md Co-authored-by: Sebastiaan Huber * Update docs/source/topics/workflows/base.md Co-authored-by: Sebastiaan Huber --------- Co-authored-by: Jonathan Chico Co-authored-by: Sebastiaan Huber --- aiida_lammps/calculations/base.py | 11 ++++++++- aiida_lammps/calculations/raw.py | 32 ++++++++++++++++++++++++- docs/source/topics/calculations/base.md | 4 ++-- docs/source/topics/calculations/raw.md | 3 ++- docs/source/topics/workflows/base.md | 4 ++-- docs/source/topics/workflows/md.md | 4 ++-- docs/source/topics/workflows/relax.md | 4 ++-- 7 files changed, 51 insertions(+), 11 deletions(-) diff --git a/aiida_lammps/calculations/base.py b/aiida_lammps/calculations/base.py index 25f520e..3a1dad3 100644 --- a/aiida_lammps/calculations/base.py +++ b/aiida_lammps/calculations/base.py @@ -231,7 +231,6 @@ def _validate_inputs(cls, value, ctx) -> Union[str, None]: # pylint: disable=unused-argument, inconsistent-return-statements """Validate the top-level inputs namespace.""" if "parameters" in value: - _restart = any( value["parameters"].get_dict().get("restart", {}).get(key, False) for key in ["print_final", "print_intermediate"] @@ -259,6 +258,8 @@ def _validate_settings(cls, value, ctx) -> Union[str, None]: settings = value.get_dict() additional_cmdline_params = settings.get("additional_cmdline_params", []) + additional_retrieve_list = settings.get("additional_retrieve_list", []) + if not isinstance(additional_cmdline_params, list) or any( not isinstance(e, str) for e in additional_cmdline_params ): @@ -266,6 +267,13 @@ def _validate_settings(cls, value, ctx) -> Union[str, None]: "Invalid value for `additional_cmdline_params`, should be " f"list of strings but got: {additional_cmdline_params}" ) + if not isinstance(additional_retrieve_list, list) or any( + not isinstance(e, (str, tuple)) for e in additional_retrieve_list + ): + return ( + "Invalid value for `additional_retrieve_list`, should be " + f"list of strings or of tuples but got: {additional_retrieve_list}" + ) @classmethod def _validate_parameters(cls, value, ctx) -> Union[str, None]: @@ -405,6 +413,7 @@ def prepare_for_submission(self, folder): calcinfo.retrieve_temporary_list = retrieve_temporary_list # Set the files that must be retrieved calcinfo.retrieve_list = retrieve_list + calcinfo.retrieve_list += settings.get("additional_retrieve_list", []) # Set the information of the code into the calculation datastructure calcinfo.codes_info = [codeinfo] diff --git a/aiida_lammps/calculations/raw.py b/aiida_lammps/calculations/raw.py index 73bb430..d015541 100644 --- a/aiida_lammps/calculations/raw.py +++ b/aiida_lammps/calculations/raw.py @@ -1,5 +1,6 @@ """Plugin with minimal interface to run LAMMPS.""" import shutil +from typing import Union from aiida import orm from aiida.common.datastructures import CalcInfo, CodeInfo @@ -34,6 +35,13 @@ def define(cls, spec): required=False, help="Optional namespace to specify with which filenames the files of ``files`` input should be written.", ) + spec.input( + "settings", + valid_type=orm.Dict, + required=False, + validator=cls._validate_settings, + help="Additional settings that control the ``LAMMPS`` calculation", + ) spec.inputs["metadata"]["options"][ "input_filename" ].default = cls.FILENAME_INPUT @@ -83,6 +91,25 @@ def validate_inputs(cls, value, ctx): "namespace to explicitly define unique filenames for each file." ) + @classmethod + def _validate_settings(cls, value, ctx) -> Union[str, None]: + # pylint: disable=unused-argument, inconsistent-return-statements + """Validate the ``settings`` input.""" + if not value: + return + + settings = value.get_dict() + + additional_retrieve_list = settings.get("additional_retrieve_list", []) + + if not isinstance(additional_retrieve_list, list) or any( + not isinstance(e, (str, tuple)) for e in additional_retrieve_list + ): + return ( + "Invalid value for `additional_retrieve_list`, should be " + f"list of strings or of tuples but got: {additional_retrieve_list}" + ) + def prepare_for_submission(self, folder: Folder) -> CalcInfo: """Prepare the calculation for submission. @@ -100,7 +127,6 @@ def prepare_for_submission(self, folder: Folder) -> CalcInfo: handle.write(self.inputs.script.get_content()) for key, node in self.inputs.get("files", {}).items(): - # The filename with which the file is written to the working directory is defined by the ``filenames`` input # namespace, falling back to the filename of the ``SinglefileData`` node if not defined. filename = filenames.get(key, node.filename) @@ -119,6 +145,10 @@ def prepare_for_submission(self, folder: Folder) -> CalcInfo: calcinfo = CalcInfo() calcinfo.provenance_exclude_list = provenance_exclude_list calcinfo.retrieve_list = [filename_output] + if "settings" in self.inputs: + calcinfo.retrieve_list += self.inputs.settings.get_dict().get( + "additional_retrieve_list", [] + ) calcinfo.codes_info = [codeinfo] return calcinfo diff --git a/docs/source/topics/calculations/base.md b/docs/source/topics/calculations/base.md index eb11e13..3c9a849 100644 --- a/docs/source/topics/calculations/base.md +++ b/docs/source/topics/calculations/base.md @@ -7,7 +7,7 @@ The {class}`~aiida_lammps.calculations.base.LammpsBaseCalculation` performs a si - **structure**, ({class}`~aiida.orm.nodes.data.structure.StructureData`) - Structure used in the ``LAMMPS`` calculation. - **potential**, ({class}`~aiida_lammps.data.potential.LammpsPotentialData`) - Potential used in the ``LAMMPS`` calculation. See [](#topics-data-potential). - **parameters**, ({class}`~aiida.orm.nodes.data.dict.Dict`) - Parameters that control the input script generated for the ``LAMMPS`` calculation. See [](#topics-data-parameters). -- **settings**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Additional settings that control the ``LAMMPS`` calculation. +- **settings**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Additional settings that control the ``LAMMPS`` calculation. One can control if extra files will be copied to the repository by specifying `settings["additional_retrieve_list"] = ["foo", "bar"]`. It is also possible to do pattern matching via [globs patterns](https://en.wikipedia.org/wiki/Glob_%28programming%29) by `settings["additional_retrieve_list"] = [('path/sub/*c.txt', '.', None)]`, for more information see the [pattern matching](https://aiida.readthedocs.io/projects/aiida-core/en/latest/topics/calculations/usage.html#pattern-matching) in the `aiida-core` documentation. - **input_restartfile** ({class}`~aiida.orm.nodes.data.singlefile.SinglefileData`), *optional* - Input restart file to continue from a previous ``LAMMPS`` calculation. - **parent_folder**, ({class}`~aiida.orm.nodes.data.remote.base.RemoteData`), *optional* - An optional working directory of a previously completed calculation to restart from. - **metadata.options.input_filename**, (`str`), *optional* - Name of the input file for the calculation. Defaults to `input.in`. @@ -34,4 +34,4 @@ LAMMPS can produce binary restart files which contain all the atomic positions, - **structure**, ({class}`~aiida.orm.nodes.data.structure.StructureData`), *optional* - The output structure of the calculation. - **remote_folder**, ({class}`~aiida.orm.nodes.data.remote.base.RemoteData`) - Folder in the remote machine where the calculation was performed. - **remote_stash**, ({class}`~aiida.orm.nodes.data.remote.stash.base.RemoteStashData`), *optional* – Contents of the stash.source_list option are stored in this remote folder after job completion. -- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added, but one can add more by specifying them in `CalcInfo.retrieve_list`. +- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added. diff --git a/docs/source/topics/calculations/raw.md b/docs/source/topics/calculations/raw.md index dc93c09..838b5da 100644 --- a/docs/source/topics/calculations/raw.md +++ b/docs/source/topics/calculations/raw.md @@ -7,6 +7,7 @@ The {class}`~aiida_lammps.calculations.raw.LammpsRawCalculation` performs a LAMM - **script**, ({class}`~aiida.orm.nodes.data.singlefile.SinglefileData`) - Complete input script to use. If specified, `structure`, `potential` and `parameters` are ignored. - **files**, (Namespace of {class}`~aiida.orm.nodes.data.singlefile.SinglefileData`), *optional* - Optional files that should be written to the working directory. This is an - **filenames**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Optional namespace to specify with which filenames the files of ``files`` input should be written. +- **settings**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Additional settings that control the ``LAMMPS`` calculation. One can control if extra files will be copied to the repository by specifying `settings["additional_retrieve_list"] = ["foo", "bar"]`. It is also possible to do pattern matching via [globs patterns](https://en.wikipedia.org/wiki/Glob_%28programming%29) by `settings["additional_retrieve_list"] = [('path/sub/*c.txt', '.', None)]`, for more information see the [pattern matching](https://aiida.readthedocs.io/projects/aiida-core/en/latest/topics/calculations/usage.html#pattern-matching) in the `aiida-core` documentation. - **metadata.options.input_filename**, (`str`), *optional* - Name of the input file for the calculation. Defaults to `input.in`. - **metadata.options.output_filename**, (`str`). *optional* - Name of the main output file for LAMMPS. Defaults to `lammps.out`. - **metadata.options.parser_name**, (`str`), *optional* - Name of the parser to be used for this calculation. Defaults to `lammps.raw`. @@ -16,4 +17,4 @@ The {class}`~aiida_lammps.calculations.raw.LammpsRawCalculation` performs a LAMM - **results**, ({class}`~aiida.orm.nodes.data.dict.Dict`) - The parsed data extracted from the lammps output file. - **remote_folder**, ({class}`~aiida.orm.nodes.data.remote.base.RemoteData`) - Folder in the remote machine where the calculation was performed. - **remote_stash**, ({class}`~aiida.orm.nodes.data.remote.stash.base.RemoteStashData`), *optional* – Contents of the stash.source_list option are stored in this remote folder after job completion. -- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added, but one can add more by specifying them in `CalcInfo.retrieve_list`. +- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added. diff --git a/docs/source/topics/workflows/base.md b/docs/source/topics/workflows/base.md index 5c231f2..5776cde 100644 --- a/docs/source/topics/workflows/base.md +++ b/docs/source/topics/workflows/base.md @@ -12,7 +12,7 @@ The inputs for the {class}`~aiida_lammps.workflows.base.LammpsBaseWorkChain` are - **lammps.structure**, ({class}`~aiida.orm.nodes.data.structure.StructureData`) - Structure used in the ``LAMMPS`` calculation. - **lammps.potential**, ({class}`~aiida_lammps.data.potential.LammpsPotentialData`) - Potential used in the ``LAMMPS`` calculation. See [](#topics-data-potential). - **lammps.parameters**, ({class}`~aiida.orm.nodes.data.dict.Dict`) - Parameters that control the input script generated for the ``LAMMPS`` calculation. See [](#topics-data-parameters). -- **lammps.settings**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Additional settings that control the ``LAMMPS`` calculation. +- **lammps.settings**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Additional settings that control the ``LAMMPS`` calculation. One can control if extra files will be copied to the repository by specifying `settings["additional_retrieve_list"] = ["foo", "bar"]`. It is also possible to do pattern matching via [globs patterns](https://en.wikipedia.org/wiki/Glob_%28programming%29) by `settings["additional_retrieve_list"] = [('path/sub/*c.txt', '.', None)]`, for more information see the [pattern matching](https://aiida.readthedocs.io/projects/aiida-core/en/latest/topics/calculations/usage.html#pattern-matching) in the `aiida-core` documentation. - **lammps.input_restartfile** ({class}`~aiida.orm.nodes.data.singlefile.SinglefileData`), *optional* - Input restart file to continue from a previous ``LAMMPS`` calculation. - **lammps.parent_folder**, ({class}`~aiida.orm.nodes.data.remote.base.RemoteData`), *optional* - An optional working directory of a previously completed calculation to restart from. - **store_restart**, ({class}`~aiida.orm.nodes.data.bool.Bool`), *optional* - Whether to store the restart file in the repository. Defaults to `False`. @@ -33,4 +33,4 @@ LAMMPS can produce binary restart files which contain all the atomic positions, - **structure**, ({class}`~aiida.orm.nodes.data.structure.StructureData`), *optional* - The output structure of the calculation. - **remote_folder**, ({class}`~aiida.orm.nodes.data.remote.base.RemoteData`) - Folder in the remote machine where the calculation was performed. - **remote_stash**, ({class}`~aiida.orm.nodes.data.remote.stash.base.RemoteStashData`), *optional* – Contents of the stash.source_list option are stored in this remote folder after job completion. -- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added, but one can add more by specifying them in `CalcInfo.retrieve_list`. +- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added. diff --git a/docs/source/topics/workflows/md.md b/docs/source/topics/workflows/md.md index 568c7ea..5f3c1fd 100644 --- a/docs/source/topics/workflows/md.md +++ b/docs/source/topics/workflows/md.md @@ -22,7 +22,7 @@ This is a subclass of the {class}`~aiida_lammps.workflows.base.LammpsBaseWorkCha - **lammps.structure**, ({class}`~aiida.orm.nodes.data.structure.StructureData`) - Structure used in the ``LAMMPS`` calculation. - **lammps.potential**, ({class}`~aiida_lammps.data.potential.LammpsPotentialData`) - Potential used in the ``LAMMPS`` calculation. See [](#topics-data-potential). - **lammps.parameters**, ({class}`~aiida.orm.nodes.data.dict.Dict`) - Parameters that control the input script generated for the ``LAMMPS`` calculation. See [](#topics-data-parameters). -- **lammps.settings**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Additional settings that control the ``LAMMPS`` calculation. +- **lammps.settings**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Additional settings that control the ``LAMMPS`` calculation. One can control if extra files will be copied to the repository by specifying `settings["additional_retrieve_list"] = ["foo", "bar"]`. It is also possible to do pattern matching via [globs patterns](https://en.wikipedia.org/wiki/Glob_%28programming%29) by `settings["additional_retrieve_list"] = [('path/sub/*c.txt', '.', None)]`, for more information see the [pattern matching](https://aiida.readthedocs.io/projects/aiida-core/en/latest/topics/calculations/usage.html#pattern-matching) in the `aiida-core` documentation. - **lammps.input_restartfile** ({class}`~aiida.orm.nodes.data.singlefile.SinglefileData`), *optional* - Input restart file to continue from a previous ``LAMMPS`` calculation. - **lammps.parent_folder**, ({class}`~aiida.orm.nodes.data.remote.base.RemoteData`), *optional* - An optional working directory of a previously completed calculation to restart from. - **store_restart**, ({class}`~aiida.orm.nodes.data.bool.Bool`), *optional* - Whether to store the restart file in the repository. Defaults to `False`. @@ -49,4 +49,4 @@ LAMMPS can produce binary restart files which contain all the atomic positions, - **structure**, ({class}`~aiida.orm.nodes.data.structure.StructureData`), *optional* - The output structure of the calculation. - **remote_folder**, ({class}`~aiida.orm.nodes.data.remote.base.RemoteData`) - Folder in the remote machine where the calculation was performed. - **remote_stash**, ({class}`~aiida.orm.nodes.data.remote.stash.base.RemoteStashData`), *optional* – Contents of the stash.source_list option are stored in this remote folder after job completion. -- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added, but one can add more by specifying them in `CalcInfo.retrieve_list`. +- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added. diff --git a/docs/source/topics/workflows/relax.md b/docs/source/topics/workflows/relax.md index 3bae3cd..0e1eee4 100644 --- a/docs/source/topics/workflows/relax.md +++ b/docs/source/topics/workflows/relax.md @@ -23,7 +23,7 @@ This is a subclass of the {class}`~aiida_lammps.workflows.base.LammpsBaseWorkCha - **lammps.structure**, ({class}`~aiida.orm.nodes.data.structure.StructureData`) - Structure used in the ``LAMMPS`` calculation. - **lammps.potential**, ({class}`~aiida_lammps.data.potential.LammpsPotentialData`) - Potential used in the ``LAMMPS`` calculation. See [](#topics-data-potential). - **lammps.parameters**, ({class}`~aiida.orm.nodes.data.dict.Dict`) - Parameters that control the input script generated for the ``LAMMPS`` calculation. See [](#topics-data-parameters). -- **lammps.settings**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Additional settings that control the ``LAMMPS`` calculation. +- **lammps.settings**, ({class}`~aiida.orm.nodes.data.dict.Dict`), *optional* - Additional settings that control the ``LAMMPS`` calculation. One can control if extra files will be copied to the repository by specifying `settings["additional_retrieve_list"] = ["foo", "bar"]`. It is also possible to do pattern matching via [globs patterns](https://en.wikipedia.org/wiki/Glob_%28programming%29) by `settings["additional_retrieve_list"] = [('path/sub/*c.txt', '.', None)]`, for more information see the [pattern matching](https://aiida.readthedocs.io/projects/aiida-core/en/latest/topics/calculations/usage.html#pattern-matching) in the `aiida-core` documentation. - **lammps.input_restartfile** ({class}`~aiida.orm.nodes.data.singlefile.SinglefileData`), *optional* - Input restart file to continue from a previous ``LAMMPS`` calculation. - **lammps.parent_folder**, ({class}`~aiida.orm.nodes.data.remote.base.RemoteData`), *optional* - An optional working directory of a previously completed calculation to restart from. - **store_restart**, ({{ Bool }}), *optional* - Whether to store the restart file in the repository. Defaults to `False`. @@ -58,4 +58,4 @@ LAMMPS can produce binary restart files which contain all the atomic positions, - **structure**, ({class}`~aiida.orm.nodes.data.structure.StructureData`), *optional* - The output structure of the calculation. - **remote_folder**, ({class}`~aiida.orm.nodes.data.remote.base.RemoteData`) - Folder in the remote machine where the calculation was performed. - **remote_stash**, ({class}`~aiida.orm.nodes.data.remote.stash.base.RemoteStashData`), *optional* – Contents of the stash.source_list option are stored in this remote folder after job completion. -- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added, but one can add more by specifying them in `CalcInfo.retrieve_list`. +- **retrieved**, ({class}`~aiida.orm.nodes.data.folder.FolderData`) - Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added.