Source code for vibesketch.inputs.xyz
"""The XYZ writer: the geometry of one species, nothing else.
XYZ carries element symbols and Cartesian coordinates in angstrom. Charge and
multiplicity go into the comment line as ``key=value`` pairs, the extended
XYZ convention that ASE and vibe-view read; a plain XYZ reader ignores them.
Anything that describes a calculation is refused: an XYZ file cannot say
which method or basis to use.
"""
from __future__ import annotations
from collections.abc import Sequence
from typing import ClassVar
from vibesketch.document.model import JobSpec, Species, Task
from vibesketch.inputs.base import InputFile, InputWriter, first_conformer, needs_conformer
[docs]
class XyzWriter(InputWriter):
name: ClassVar[str] = "xyz"
description: ClassVar[str] = "Cartesian geometry in angstrom, charge and spin in the comment"
tasks: ClassVar[frozenset[Task]] = frozenset({"geometry"})
def _refusals(self, species: Species, spec: JobSpec) -> list[str]:
return needs_conformer(self.name, species)
def _render(self, species: Species, spec: JobSpec) -> Sequence[InputFile]:
from vibesketch import __version__
conformer = first_conformer(species)
comment = (
f"charge={species.charge} multiplicity={species.multiplicity} "
f"species={species.id} generator=vibe-sketch-{__version__}"
)
lines = [str(len(conformer.symbols)), comment]
for symbol, (x, y, z) in zip(conformer.symbols, conformer.xyz_angstrom, strict=True):
lines.append(f"{symbol:<2} {x:16.10f} {y:16.10f} {z:16.10f}")
return [InputFile(f"{species.id}.xyz", "\n".join(lines) + "\n", "chemical/x-xyz")]