From d306155315e393e0be4e7d3f026b77b0832b2635 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Mon, 13 Mar 2023 17:48:52 +0100 Subject: [PATCH 1/3] Do not recreate `parser_name` input port to change default The `CalcJob` plugins were setting the default value for the `parser_name` metadata option by redefining the port. This is not desirable since this loses the `help` attribute. Instead, we simply change the default through the attribute on the existing port. --- aiida_lammps/calculations/lammps/base.py | 7 ++----- aiida_lammps/calculations/lammps/force.py | 6 +----- aiida_lammps/calculations/lammps/md.py | 6 +----- aiida_lammps/calculations/lammps/md_multi.py | 6 +----- aiida_lammps/calculations/lammps/optimize.py | 6 +----- 5 files changed, 6 insertions(+), 25 deletions(-) diff --git a/aiida_lammps/calculations/lammps/base.py b/aiida_lammps/calculations/lammps/base.py index 2311558..5974073 100644 --- a/aiida_lammps/calculations/lammps/base.py +++ b/aiida_lammps/calculations/lammps/base.py @@ -101,11 +101,8 @@ def define(cls, spec): valid_type=str, default=cls._DEFAULT_RESTART_FILENAME, ) - spec.input( - "metadata.options.parser_name", - valid_type=str, - default=cls._DEFAULT_PARSER, - ) + spec.inputs["metadata"]["options"]["parser_name"].default = cls._DEFAULT_PARSER + spec.output( "results", valid_type=orm.Dict, diff --git a/aiida_lammps/calculations/lammps/force.py b/aiida_lammps/calculations/lammps/force.py index 9a2b784..6d4885a 100644 --- a/aiida_lammps/calculations/lammps/force.py +++ b/aiida_lammps/calculations/lammps/force.py @@ -14,11 +14,7 @@ class ForceCalculation(BaseLammpsCalculation): def define(cls, spec): super().define(spec) - spec.input( - "metadata.options.parser_name", - valid_type=str, - default="lammps.force", - ) + spec.inputs["metadata"]["options"]["parser_name"].default = "lammps.force" spec.output( "arrays", diff --git a/aiida_lammps/calculations/lammps/md.py b/aiida_lammps/calculations/lammps/md.py index d58ef59..d599f9b 100644 --- a/aiida_lammps/calculations/lammps/md.py +++ b/aiida_lammps/calculations/lammps/md.py @@ -17,11 +17,7 @@ class MdCalculation(BaseLammpsCalculation): def define(cls, spec): super().define(spec) - spec.input( - "metadata.options.parser_name", - valid_type=str, - default="lammps.md", - ) + spec.inputs["metadata"]["options"]["parser_name"].default = "lammps.md" spec.default_output_port = "results" spec.output( diff --git a/aiida_lammps/calculations/lammps/md_multi.py b/aiida_lammps/calculations/lammps/md_multi.py index af93b4d..1224b4e 100644 --- a/aiida_lammps/calculations/lammps/md_multi.py +++ b/aiida_lammps/calculations/lammps/md_multi.py @@ -16,11 +16,7 @@ class MdMultiCalculation(BaseLammpsCalculation): def define(cls, spec): super().define(spec) - spec.input( - "metadata.options.parser_name", - valid_type=str, - default="lammps.md.multi", - ) + spec.inputs["metadata"]["options"]["parser_name"].default = "lammps.md.multi" spec.default_output_port = "results" spec.output_namespace( diff --git a/aiida_lammps/calculations/lammps/optimize.py b/aiida_lammps/calculations/lammps/optimize.py index 7544d2c..9edf68a 100644 --- a/aiida_lammps/calculations/lammps/optimize.py +++ b/aiida_lammps/calculations/lammps/optimize.py @@ -19,11 +19,7 @@ class OptimizeCalculation(BaseLammpsCalculation): def define(cls, spec): super().define(spec) - spec.input( - "metadata.options.parser_name", - valid_type=str, - default="lammps.optimize", - ) + spec.inputs["metadata"]["options"]["parser_name"].default = "lammps.optimize" spec.output( "structure", From 815fd34f0b8adad20e31bf6d7c7afcbda57c6ba2 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Mon, 13 Mar 2023 17:57:05 +0100 Subject: [PATCH 2/3] `BaseLammpsCalculation`: Do not set `CodeInfo.withmpi` The plugin was setting `CodeInfo.withmpi` based on the inputs from `metadata.options.withmpi`. This is not necessary as the metadata option is already handled by the `CalcJob` base class. The plugin implementation should only set `CodeInfo.withmpi` if it wants to _force_ the code to be run with MPI enabled or disabled. The `CalcJob` base implementation used to not distinguish between the two, but in https://github.com/aiidateam/aiida-core/pull/5922 the handling of MPI was improved. A `Code` can now define whether it should be run with MPI or not and so the `CalcJob` class now has to raise if the MPI setting of the code and the plugin clash. The `withmpi` option, if explicitly set by the user, is also checked. Since the plugin doesn't intend to enforce MPI or not, the setting on the `CodeInfo` is removed. --- aiida_lammps/calculations/lammps/__init__.py | 1 - aiida_lammps/calculations/lammps/base.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/aiida_lammps/calculations/lammps/__init__.py b/aiida_lammps/calculations/lammps/__init__.py index 81afa49..06818ef 100644 --- a/aiida_lammps/calculations/lammps/__init__.py +++ b/aiida_lammps/calculations/lammps/__init__.py @@ -372,7 +372,6 @@ def prepare_for_submission(self, tempfolder): # pylint: disable=arguments-diffe codeinfo = CodeInfo() codeinfo.cmdline_params = list(self._cmdline_params) codeinfo.code_uuid = self.inputs.code.uuid - codeinfo.withmpi = self.metadata.options.withmpi codeinfo.stdout_name = self._stdout_name calcinfo = CalcInfo() diff --git a/aiida_lammps/calculations/lammps/base.py b/aiida_lammps/calculations/lammps/base.py index 5974073..56f9e0f 100644 --- a/aiida_lammps/calculations/lammps/base.py +++ b/aiida_lammps/calculations/lammps/base.py @@ -255,8 +255,6 @@ def prepare_for_submission(self, folder): codeinfo.code_uuid = self.inputs.code.uuid # Set the name of the stdout codeinfo.stdout_name = _output_filename - # Set whether or not one is running with MPI - codeinfo.withmpi = self.inputs.metadata.options.withmpi # Generate the datastructure for the calculation information calcinfo = datastructures.CalcInfo() From 6debf5b169d7d9722f44281b273d10289e0f582f Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Mon, 13 Mar 2023 18:03:21 +0100 Subject: [PATCH 3/3] Remove unused code in `aiida_lammps.calculations.lammps.__init__.py` This code is not used and seems to have no relation with the `BaseLammpsCalculation`. --- aiida_lammps/calculations/lammps/__init__.py | 81 -------------------- 1 file changed, 81 deletions(-) diff --git a/aiida_lammps/calculations/lammps/__init__.py b/aiida_lammps/calculations/lammps/__init__.py index 06818ef..34d63f3 100644 --- a/aiida_lammps/calculations/lammps/__init__.py +++ b/aiida_lammps/calculations/lammps/__init__.py @@ -12,87 +12,6 @@ from aiida_lammps.data.potential import EmpiricalPotential -def get_supercell( - structure: orm.StructureData, - supercell_shape: orm.Dict, -) -> orm.StructureData: - """Generate a supercell from a given StructureData - - :param structure: original structure that will be used to generate the supercell - :type structure: orm.StructureData - :param supercell_shape: dictionary with the supercell information - :type supercell_shape: orm.Dict - :return: generated supercell - :rtype: orm.StructureData - """ - symbols = np.array([site.kind_name for site in structure.sites]) - positions = np.array([site.position for site in structure.sites]) - cell = np.array(structure.cell) - supercell_shape = np.array(supercell_shape.dict.shape) - - supercell_array = np.dot(cell, np.diag(supercell_shape)) - - supercell = orm.StructureData(cell=supercell_array) - for k in range(positions.shape[0]): - for entry in itertools.product(*[range(i) for i in supercell_shape[::-1]]): - position = positions[k, :] + np.dot(np.array(entry[::-1]), cell) - symbol = symbols[k] - supercell.append_atom(position=position, symbols=symbol) - - return supercell - - -def get_force_constants(force_constants: orm.ArrayData) -> str: - """Get the force constants in text format - - :param force_constants: Array with the information needed for the force constants - :type force_constants: orm.ArrayData - :return: force constants in text - :rtype: str - """ - force_constants = force_constants.get_array("force_constants") - - fc_shape = force_constants.shape - fc_txt = "%4d\n" % (fc_shape[0]) - for i in range(fc_shape[0]): - for j in range(fc_shape[1]): - fc_txt += "%4d%4d\n" % (i + 1, j + 1) - for vec in force_constants[i][j]: - fc_txt += ("%22.15f" * 3 + "\n") % tuple(vec) - - return fc_txt - - -def structure_to_poscar(structure: orm.StructureData) -> str: - """Write the structure into a POSCAR - - :param structure: structure used for the simulation - :type structure: orm.StructureData - :return: POSCAR format for the structure - :rtype: str - """ - atom_type_unique = np.unique( - [site.kind_name for site in structure.sites], - return_index=True, - )[1] - labels = np.diff(np.append(atom_type_unique, [len(structure.sites)])) - - poscar = " ".join(np.unique([site.kind_name for site in structure.sites])) - poscar += "\n1.0\n" - cell = structure.cell - for row in cell: - poscar += f"{row[0]: 22.16f} {row[1]: 22.16f} {row[2]: 22.16f}\n" - poscar += " ".join(np.unique([site.kind_name for site in structure.sites])) + "\n" - poscar += " ".join(np.array(labels, dtype=str)) + "\n" - poscar += "Cartesian\n" - for site in structure.sites: - poscar += f"{site.position[0]: 22.16f} " - poscar += f"{site.position[1]: 22.16f} " - poscar += f"{site.position[2]: 22.16f}\n" - - return poscar - - class BaseLammpsCalculation(CalcJob): """ A basic plugin for calculating force constants using Lammps.