xnn.common.data.ase_io.atoms_to_structure#

xnn.common.data.ase_io.atoms_to_structure(atoms, energy_key='energy', forces_key='forces', stress_key='stress')[source]#

Convert one ASE Atoms object to an xnn structure dict.

Geometry (positions, atomic numbers, cell, pbc) is always extracted; positions are taken as-is (the neighbor-list builder handles unwrapped coordinates). Targets are added when available: with the default key names, first from the attached calculator (get_potential_energy / get_forces / get_stress), then from atoms.info["energy"] / atoms.arrays["forces"] / atoms.info["stress"]. A non-default key selects that entry of info / arrays instead (e.g. MACE-convention REF_energy / REF_forces / REF_stress). Stress is converted to a full (3, 3) matrix.

Parameters:
  • atoms (ase.Atoms) – The structure to convert.

  • energy_key (str, optional) – Name of the reference energy in atoms.info.

  • forces_key (str, optional) – Name of the reference forces in atoms.arrays.

  • stress_key (str, optional) – Name of the reference stress in atoms.info.

Returns:

Structure dict with keys "pos", "atomic_numbers", "cell" (None for non-periodic frames), "pbc", and optionally "energy", "forces", "stress" and "total_charge" (from atoms.info["total_charge"] or atoms.info["charge"]).

Return type:

dict