From bcec6ee40443b17d2800fd27db9b96e20f01a716 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Mon, 13 May 2024 13:34:31 +0200 Subject: [PATCH 1/3] use kind_name as atom symbol --- aiida_cp2k/calculations/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aiida_cp2k/calculations/__init__.py b/aiida_cp2k/calculations/__init__.py index f6f928c..ca1d574 100644 --- a/aiida_cp2k/calculations/__init__.py +++ b/aiida_cp2k/calculations/__init__.py @@ -13,6 +13,7 @@ from aiida.engine import CalcJob from aiida.orm import Dict, RemoteData, SinglefileData from aiida.plugins import DataFactory +from ase import Atom, Atoms from ..utils import Cp2kInput from ..utils.datatype_helpers import ( @@ -409,7 +410,10 @@ def prepare_for_submission(self, folder): def _write_structure(structure, folder, name): """Function that writes a structure and takes care of element tags.""" - xyz = _atoms_to_xyz(structure.get_ase()) + atoms = Atoms(cell=structure.cell, pbc=structure.pbc) + for site in structure.sites: + atoms.append(Atom(site.kind_name, site.position)) + xyz = _atoms_to_xyz(atoms) with open(folder.get_abs_path(name), mode="w", encoding="utf-8") as fobj: fobj.write(xyz) From 684235ce1b82dde177fb610ae3ca6af5d0e05520 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Mon, 13 May 2024 14:01:33 +0200 Subject: [PATCH 2/3] update docstring, and write the file directly --- aiida_cp2k/calculations/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/aiida_cp2k/calculations/__init__.py b/aiida_cp2k/calculations/__init__.py index ca1d574..dc9e22f 100644 --- a/aiida_cp2k/calculations/__init__.py +++ b/aiida_cp2k/calculations/__init__.py @@ -13,7 +13,6 @@ from aiida.engine import CalcJob from aiida.orm import Dict, RemoteData, SinglefileData from aiida.plugins import DataFactory -from ase import Atom, Atoms from ..utils import Cp2kInput from ..utils.datatype_helpers import ( @@ -408,12 +407,15 @@ def prepare_for_submission(self, folder): @staticmethod def _write_structure(structure, folder, name): - """Function that writes a structure and takes care of element tags.""" - - atoms = Atoms(cell=structure.cell, pbc=structure.pbc) - for site in structure.sites: - atoms.append(Atom(site.kind_name, site.position)) - xyz = _atoms_to_xyz(atoms) + """Function that writes a structure to a xyz file. + The element tags being the names of the kind. + """ + elem_coords = [ + f"{site.position[0]:25.16f} {site.position[1]:25.16f} {site.position[2]:25.16f}" + for site in structure.sites + ] + xyz = f"{len(elem_coords)}\n\n" + xyz += "\n".join(map(add, structure.get_site_kindnames(), elem_coords)) with open(folder.get_abs_path(name), mode="w", encoding="utf-8") as fobj: fobj.write(xyz) From d4901e6df243d85e5deb0a53baf336ee2295625e Mon Sep 17 00:00:00 2001 From: superstar54 Date: Mon, 13 May 2024 16:56:47 +0200 Subject: [PATCH 3/3] fix pre-commit --- aiida_cp2k/calculations/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiida_cp2k/calculations/__init__.py b/aiida_cp2k/calculations/__init__.py index dc9e22f..cab76c8 100644 --- a/aiida_cp2k/calculations/__init__.py +++ b/aiida_cp2k/calculations/__init__.py @@ -481,7 +481,7 @@ def _trajectory_to_xyz_and_cell(trajectory): if "cells" in trajectory.get_arraynames(): cell = "# Step Time [fs] Ax [Angstrom] Ay [Angstrom] Az [Angstrom] Bx [Angstrom] By [Angstrom] Bz [Angstrom] Cx [Angstrom] Cy [Angstrom] Cz [Angstrom] Volume [Angstrom^3]\n" cell_vecs = [ - f"{stepid+1} {(stepid+1)*0.5:6.3f} {cellvec[0][0]:25.16f} {cellvec[0][1]:25.16f} {cellvec[0][2]:25.16f} {cellvec[1][0]:25.16f} {cellvec[1][1]:25.16f} {cellvec[1][2]:25.16f} {cellvec[2][0]:25.16f} {cellvec[2][1]:25.16f} {cellvec[2][2]:25.16f} {np.dot(cellvec[0],np.cross(cellvec[1],cellvec[2]))}" + f"{stepid+1} {(stepid+1)*0.5:6.3f} {cellvec[0][0]:25.16f} {cellvec[0][1]:25.16f} {cellvec[0][2]:25.16f} {cellvec[1][0]:25.16f} {cellvec[1][1]:25.16f} {cellvec[1][2]:25.16f} {cellvec[2][0]:25.16f} {cellvec[2][1]:25.16f} {cellvec[2][2]:25.16f} {np.dot(cellvec[0], np.cross(cellvec[1], cellvec[2]))}" for (stepid, cellvec) in zip(stepids, trajectory.get_array("cells")) ] cell += "\n".join(cell_vecs)