Skip to content

Commit

Permalink
Merge pull request #54 from sphuber/fix/spec-parser-default
Browse files Browse the repository at this point in the history
Do not recreate `parser_name` input port to change default
  • Loading branch information
JPchico authored Mar 16, 2023
2 parents 9838b47 + 6debf5b commit d679df5
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 109 deletions.
82 changes: 0 additions & 82 deletions aiida_lammps/calculations/lammps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -372,7 +291,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()
Expand Down
9 changes: 2 additions & 7 deletions aiida_lammps/calculations/lammps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -258,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()
Expand Down
6 changes: 1 addition & 5 deletions aiida_lammps/calculations/lammps/force.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions aiida_lammps/calculations/lammps/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 1 addition & 5 deletions aiida_lammps/calculations/lammps/md_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 1 addition & 5 deletions aiida_lammps/calculations/lammps/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d679df5

Please sign in to comment.