IO utilities

IO utilities#

pasted._io#

XYZ format serialisation helpers.

pasted._io.format_xyz(atoms: list[str], positions: list[Vec3], charge: int, mult: int, metrics: dict[str, float], prefix: str = '') str[source]#

Serialise a structure to the extended XYZ format.

The second line (comment line) encodes prefix, charge, multiplicity, composition, and all metric values.

Parameters:
  • atoms – Element symbols.

  • positions – Cartesian coordinates (Å), one per atom.

  • charge – Total system charge.

  • mult – Spin multiplicity 2S+1.

  • metrics – Dict of computed disorder metrics.

  • prefix – Prepended to the comment line (e.g. "sample=1 mode=gas").

Return type:

A multi-line string (no trailing newline).

pasted._io.parse_xyz(text: str) list[tuple[list[str], list[Vec3], int, int, dict[str, float]]][source]#

Parse a (possibly multi-frame) XYZ string — standard or extended format.

Supports both:

  • Standard XYZ — atom count line, comment line, then coordinate lines. charge defaults to 0, mult to 1, metrics is empty.

  • Extended XYZ (as written by PASTED) — the comment line may contain charge=+0, mult=1, and KEY=VALUE metric tokens.

Parameters:

text – Full contents of one or more XYZ frames (concatenated).

Return type:

list of (atoms, positions, charge, mult, metrics) tuples, one per frame.

Raises:

ValueError – When the atom-count line or a coordinate line cannot be parsed.