ase_io#

irmsd.interfaces.ase_io._ENERGY_UNITS_KEY = 'energy_units'#

Info key (case-insensitive) carrying an explicit energy-unit declaration.

irmsd.interfaces.ase_io._HARTREE_UNIT_ALIASES = frozenset({'a.u.', 'atomic', 'au', 'e_h', 'eh', 'ha', 'hartree', 'hartrees'})#

Values (case-insensitive) marking an energy as already in Hartree.

irmsd.interfaces.ase_io._ase_energy_to_hartree(atoms) → float | None[source]#

Energy of atoms in Hartree; eV unless an energy_units=Hartree marker says otherwise.

irmsd.interfaces.ase_io._declared_hartree(info) → bool[source]#

True if info carries energy_units=Hartree (as our extxyz writers emit).

irmsd.interfaces.ase_io._hartree_to_ev(energy: float | None) → float | None[source]#

Hartree to eV, passing None through.

irmsd.interfaces.ase_io._strip_energy_units(info: dict) → dict[source]#

Copy of info without energy_units; avoids double conversion on round-trip.

irmsd.interfaces.ase_io.ase_to_molecule(atoms: ase.Atoms) → Molecule[source]#
irmsd.interfaces.ase_io.ase_to_molecule(atoms: Sequence['ase.Atoms']) → list[Molecule]

Convert ASE Atoms (single or sequence) to irmsd.core.Molecule.

Triggers no calculator evaluation and does not modify the input. Energies are converted from eV to Hartree unless info declares energy_units=Hartree; the marker is dropped from the result’s info. A per-atom canonical_id array is carried over as Molecule.ids.

Parameters:

atoms (ase.Atoms or Sequence[ase.Atoms])

Returns:

A list, in input order, if atoms is a sequence.

Return type:

Molecule or list[Molecule]

Raises:
  • RuntimeError – If ASE is not installed.

  • TypeError – If the input is neither an ASE Atoms instance nor a sequence of them.

irmsd.interfaces.ase_io.cregen_ase(atoms_list: Sequence['ase.Atoms'], rthr: float = 0.125, ethr: float = 8e-05, bthr: float = 0.01, printlvl: int = 0, ewin: float | None = None) → List['ase.Atoms'][source]#

ASE wrapper for cregen().

Parameters:
  • atoms_list (Sequence[ase.Atoms]) – List or tuple; all structures must have the same atom count.

  • rthr (float) – Distance threshold in Angstrom.

  • ethr (float) – Energy threshold for pre-sorting, in Hartree.

  • bthr (float) – Relative threshold for comparing rotational constants.

  • printlvl (int, optional) – Verbosity level.

  • ewin (float or None) – Energy window above the lowest structure, in Hartree.

Returns:

Rebuilt from the sorted Molecules.

Return type:

list[ase.Atoms]

irmsd.interfaces.ase_io.delta_irmsd_list_ase(atoms_list: Sequence['ase.Atoms'], iinversion: int = 0, allcanon: bool = True, printlvl: int = 0) → Tuple[np.ndarray, List['ase.Atoms']][source]#

ASE wrapper for delta_irmsd_list_molecule.

Parameters:
  • atoms_list (Sequence[ase.Atoms]) – List or tuple; all structures must have the same atom count.

  • iinversion (int, optional) – 0 = ‘auto’, 1 = ‘on’, 2 = ‘off’.

  • allcanon (bool, optional) – Canonicalization flag.

  • printlvl (int, optional) – Verbosity level.

Returns:

  • delta (np.ndarray) – Float array from the backend; see delta_irmsd_list.

  • new_atoms_list (list[ase.Atoms]) – Rebuilt from the transformed Molecules.

irmsd.interfaces.ase_io.get_axis_ase(atoms) → tuple[ndarray, ndarray, ndarray][source]#

Principal-axis data via Molecule.get_axis().

Parameters:

atoms (ase.Atoms)

Returns:

rot_constants_MHz, avg_momentum_au, rotation_matrix

Return type:

tuple[np.ndarray, np.ndarray, np.ndarray]

irmsd.interfaces.ase_io.get_canonical_ase(atoms, wbo: ndarray | None = None, invtype: str = 'apsp+', heavy: bool = False) → ndarray[source]#

Canonical ranks / invariants via Molecule.get_canonical().

Parameters:
  • atoms (ase.Atoms)

  • wbo (np.ndarray or None, optional) – Wiberg bond order matrix or similar, forwarded to the Fortran backend.

  • invtype (str, optional) – Invariant type selector forwarded to the backend.

  • heavy (bool, optional) – Restrict invariants to heavy atoms.

Return type:

np.ndarray

Raises:
irmsd.interfaces.ase_io.get_cn_ase(atoms) → ndarray[source]#

Coordination numbers via Molecule.get_cn(), shape (N,).

Parameters:

atoms (ase.Atoms)

irmsd.interfaces.ase_io.get_energies_from_atoms_list(atoms_list: Sequence['ase.Atoms']) → np.ndarray[source]#

Energies of atoms_list in Hartree, shape (N,); 0.0 where none is available.

Units follow _ase_energy_to_hartree().

irmsd.interfaces.ase_io.get_energy_ase(atoms)[source]#

Return the energy already stored on an ASE Atoms object, or None.

Looks in atoms.info["energy"], then the calculator’s results (“energy”, “free_energy”, “enthalpy”), then get_potential_energy() only if that needs no new calculation. The value is in ASE units (eV).

Parameters:

atoms (ase.Atoms)

Return type:

float or None

Raises:
irmsd.interfaces.ase_io.get_irmsd_ase(atoms1, atoms2, iinversion: int = 0) → Tuple[float, 'ase.Atoms', 'ase.Atoms'][source]#

ASE wrapper for get_irmsd_molecule.

Parameters:
  • atoms1 (ase.Atoms)

  • atoms2 (ase.Atoms)

  • iinversion (int, optional) – 0 = ‘auto’, 1 = ‘on’, 2 = ‘off’.

Returns:

  • irmsd (float) – In Angstrom.

  • new_atoms1, new_atoms2 (ase.Atoms) – New objects for the transformed structures.

Raises:
irmsd.interfaces.ase_io.get_point_group_ase(atoms, **settings) → str | None[source]#

Schoenflies point group via Molecule.get_point_group().

Parameters:
  • atoms (ase.Atoms)

  • **settings – Analyzer settings (threshold, primary_threshold, max_axis_order, max_opt_cycles, max_atoms), see irmsd.get_point_group().

Returns:

None if the analysis was skipped.

Return type:

str or None

irmsd.interfaces.ase_io.get_rmsd_ase(atoms1, atoms2, mask=None) → Tuple[float, 'ase.Atoms', np.ndarray][source]#

ASE wrapper for get_rmsd_molecule.

Parameters:
  • atoms1 (ase.Atoms) – Reference structure.

  • atoms2 (ase.Atoms) – Structure aligned onto atoms1.

  • mask (array-like of bool, optional) – Atoms of the first structure that enter the RMSD.

Returns:

  • rmsd (float) – In Angstrom.

  • new_atoms2 (ase.Atoms) – New object with coordinates aligned to atoms1.

  • rotation_matrix (np.ndarray) – 3x3 rotation used for the alignment.

Raises:
irmsd.interfaces.ase_io.molecule_to_ase(molecules: Molecule) → ase.Atoms[source]#
irmsd.interfaces.ase_io.molecule_to_ase(molecules: Sequence[Molecule]) → list['ase.Atoms']

Convert Molecule(s) to ASE Atoms without attaching a calculator.

The Hartree energy is written to info["energy"] in eV unless info already has an energy entry; any energy_units marker is dropped. Molecule.ids becomes a per-atom canonical_id array. The returned objects do not share state with the input.

Parameters:

molecules (Molecule or Sequence[Molecule])

Returns:

A list, in input order, if molecules is a sequence.

Return type:

ase.Atoms or list[ase.Atoms]

Raises:
  • RuntimeError – If ASE is not installed.

  • TypeError – If the input is neither a Molecule nor a sequence of Molecules.

irmsd.interfaces.ase_io.prune_ase(atoms_list: Sequence['ase.Atoms'], rthr: float, iinversion: int = 0, allcanon: bool = True, printlvl: int = 0, ethr: float | None = None, ewin: float | None = None) → List['ase.Atoms'][source]#

ASE wrapper for prune().

Parameters:
  • atoms_list (Sequence[ase.Atoms]) – List or tuple; all structures must have the same atom count.

  • rthr (float) – Distance threshold for the sorter.

  • iinversion (int, optional) – 0 = ‘auto’, 1 = ‘on’, 2 = ‘off’.

  • allcanon (bool, optional) – Canonicalization flag.

  • printlvl (int, optional) – Verbosity level.

  • ethr (float or None) – Energy threshold for pre-sorting, in Hartree.

  • ewin (float or None) – Energy window above the lowest structure, in Hartree.

Returns:

Rebuilt from the sorted Molecules.

Return type:

list[ase.Atoms]

irmsd.interfaces.ase_io.sorter_irmsd_ase(atoms_list: Sequence['ase.Atoms'], rthr: float = 0.125, iinversion: int = 0, allcanon: bool = True, printlvl: int = 0, ethr: float | None = None, ewin: float | None = None) → Tuple[np.ndarray, List['ase.Atoms']][source]#

ASE wrapper for sorter_irmsd_molecule.

Parameters:
  • atoms_list (Sequence[ase.Atoms]) – List or tuple; all structures must have the same atom count.

  • rthr (float) – Distance threshold for the sorter.

  • iinversion (int, optional) – 0 = ‘auto’, 1 = ‘on’, 2 = ‘off’.

  • allcanon (bool, optional) – Canonicalization flag.

  • printlvl (int, optional) – Verbosity level.

  • ethr (float or None) – Energy threshold for pre-sorting, in Hartree.

  • ewin (float or None) – Energy window above the lowest structure, in Hartree.

Returns:

  • groups (np.ndarray) – Integer group index per structure.

  • new_atoms_list (list[ase.Atoms]) – Rebuilt from the sorted Molecules.