utils#

irmsd.utils.read_extxyz(path_or_file: str | Path | TextIO) → Molecule | list[Molecule][source]#

Read an extended-XYZ file and return either:

  • a single Molecule (if only one structure is present)

  • a list[Molecule] if there are multiple structures

The extended-XYZ comment line may contain key=value pairs. Special handling: - ‘energy=’ → stored in Molecule.energy; if absent, the first bare numeric

token on the comment line is used as the energy (Hartree), matching the tag-less CREST ensemble convention

  • ‘cell=’ → stored in Molecule.cell

  • ‘pbc=’ → stored in Molecule.pbc

  • ‘Properties=’ → describes the atom-block column layout; a canonical_id:I:1 column (if present) is read into Molecule.ids

All other key=value pairs go into Molecule.info.

irmsd.utils.write_extxyz(path_or_file: str | Path | TextIO, molecules: Molecule | Sequence[Molecule], mode: str = 'w') → None[source]#

Write one or many Molecule objects to an extended-XYZ file.

Special behavior: - If Molecule.energy is not None, writes ‘energy=<value> energy_units=Hartree’

in the comment line (Molecule energies are stored in Hartree).

  • If Molecule.cell is not None, writes ‘cell=”<a11 … a33>”’.

  • If Molecule.pbc is not None, writes ‘pbc=”T T T”’ etc.

  • If Molecule.ids is not None, writes a per-atom canonical_id column and advertises it via ‘Properties=species:S:1:pos:R:3:canonical_id:I:1’.

  • All entries in Molecule.info are written as additional key=value pairs.

Parameters:
  • path_or_file (str | Path | TextIO) – Output path or already opened file object.

  • molecules (Molecule | Sequence[Molecule]) – One Molecule or a sequence of Molecule objects.

  • mode (str) – File open mode, default “w”. Use “a” to append.

Modules