Skip to content

Commit

Permalink
Adding that one can specify other files to be retrieved via the setti…
Browse files Browse the repository at this point in the history
…ng (#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 <mail@sphuber.net>

* Update docs/source/topics/calculations/raw.md

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>

* Update docs/source/topics/calculations/base.md

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>

* Update docs/source/topics/workflows/relax.md

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>

* Update docs/source/topics/workflows/base.md

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>

---------

Co-authored-by: Jonathan Chico <jonathan.chico@sandvik.com>
Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
3 people authored Nov 28, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0affc72 commit 47b1a4d
Showing 7 changed files with 51 additions and 11 deletions.
11 changes: 10 additions & 1 deletion aiida_lammps/calculations/base.py
Original file line number Diff line number Diff line change
@@ -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,13 +258,22 @@ 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
):
return (
"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]

32 changes: 31 additions & 1 deletion aiida_lammps/calculations/raw.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions docs/source/topics/calculations/base.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion docs/source/topics/calculations/raw.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions docs/source/topics/workflows/base.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions docs/source/topics/workflows/md.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions docs/source/topics/workflows/relax.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 47b1a4d

Please sign in to comment.