From edb0d49c7d63797a05bd3aaf2ab9182e78d7509a Mon Sep 17 00:00:00 2001 From: superstar54 Date: Mon, 13 May 2024 14:01:33 +0200 Subject: [PATCH] update docstring, and write the file directly --- aiida_cp2k/calculations/__init__.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/aiida_cp2k/calculations/__init__.py b/aiida_cp2k/calculations/__init__.py index ca1d574..7a0b718 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,16 @@ 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. + The label of the structure is written as the comment line of the xyz file.""" + 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" + xyz += structure.label + 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)