mol_interface#

irmsd.interfaces.mol_interface.cregen(molecule_list: Sequence[Molecule], rthr: float = 0.125, ethr: float = 7.96800686e-05, bthr: float = 0.01, printlvl: int = 0, ewin: float | None = None) → List[Molecule][source]#

High-level wrapper around the Fortran-backed cregen_raw that operates directly on Molecule objects. Returns a pruned & energy-sorted list of structures.

Parameters:
  • molecule_list (Sequence[Molecule]) – Sequence of Molecule objects. All molecules must have the same number of atoms.

  • rthr (float) – Distance threshold for the sorter (passed through to the backend).

  • ethr (float) – Inter-conformer energy threshold (in Hartree)

  • bthr (float) – Inter-conformer rotational constant threshold (fractional)

  • iinversion (int, optional) – Inversion symmetry flag, passed through to the backend.

  • printlvl (int, optional) – Verbosity level, passed through to the backend.

  • ewin (float | None) – Optional energy window to limit ensembe size around lowest energy structure. In Hartree.

Returns:

new_molecule_list – New Molecule objects reconstructed from the sorted atomic numbers and positions returned by the backend. The list contains only n_structures defined as unique according to the selected thresholds.

Return type:

list[Molecule]

Raises:
  • TypeError – If molecule_list does not contain Molecule instances.

  • ValueError – If molecule_list is empty or if the Molecules do not all have the same number of atoms.

irmsd.interfaces.mol_interface.delta_irmsd_list_molecule(molecule_list: Sequence[Molecule], iinversion: int = 0, allcanon: bool = True, printlvl: int = 0, use_ids: bool = True) → Tuple[ndarray, List[Molecule]][source]#

High-level wrapper around the Fortran-backed delta_irmsd_list that operates directly on Molecule objects.

Parameters:
  • molecule_list (Sequence[Molecule]) – Sequence of Molecule objects. All molecules must have the same number of atoms.

  • iinversion (int, optional) – Inversion symmetry flag, passed through to the backend.

  • allcanon (bool, optional) – Canonicalization flag, passed through to the backend.

  • printlvl (int, optional) – Verbosity level, passed through to the backend.

Returns:

  • delta (np.ndarray) – Float array returned by the backend (see delta_irmsd_list for detailed semantics).

  • new_molecule_list (list[Molecule]) – New Molecule objects reconstructed from the atomic numbers and positions returned by the backend. The list has the same length and ordering as molecule_list.

Raises:
  • TypeError – If molecule_list does not contain Molecule instances.

  • ValueError – If molecule_list is empty or if the Molecules do not all have the same number of atoms.

irmsd.interfaces.mol_interface.get_energies_from_molecule_list(molecule_list: Sequence[Molecule]) → ndarray[source]#

Collect potential energies from a sequence of Molecule objects.

For each Molecule, this function calls get_potential_energy() and stores the result in a 1D NumPy array of dtype float. If the energy is not available (for example, if get_potential_energy() raises AttributeError or returns None), the corresponding entry is set to 0.0.

Parameters:

molecule_list (Sequence[Molecule]) – Sequence of Molecule instances.

Returns:

energies – Array of shape (n_structures,) containing one energy per Molecule.

Return type:

np.ndarray

irmsd.interfaces.mol_interface.get_irmsd_molecule(molecule1: Molecule, molecule2: Molecule, iinversion: int = 0, use_ids: bool = True) → Tuple[float, Molecule, Molecule][source]#

Compute the iRMSD between two Molecule objects using the iRMSD backend.

The backend may reorder atoms and/or change atomic numbers according to its canonicalization / matching logic. This wrapper returns copies of both input Molecules with the updated atomic numbers and positions.

Parameters:
  • molecule1 (Molecule) – First input structure.

  • molecule2 (Molecule) – Second input structure.

  • iinversion (int, optional) – Inversion flag passed directly to the Fortran backend. See the backend documentation for allowed values and meanings.

  • use_ids (bool, optional) – If True (default) and both molecules carry per-atom canonical IDs (Molecule.ids), those IDs are passed to the backend as externally supplied ranks. The backend uses them only if they are mutually consistent, otherwise it recomputes the canonical ranks.

Returns:

  • irmsd (float) – iRMSD value in Ångström.

  • new_molecule1 (Molecule) – Copy of molecule1 with updated atomic numbers and positions.

  • new_molecule2 (Molecule) – Copy of molecule2 with updated atomic numbers and positions.

Raises:

TypeError – If either input is not a Molecule.

irmsd.interfaces.mol_interface.get_rmsd_molecule(molecule1: Molecule, molecule2: Molecule, mask=None) → Tuple[float, Molecule, ndarray][source]#

Compute the RMSD between two Molecule objects using the quaternion-based RMSD backend, and return an aligned copy of the second Molecule.

Parameters:
  • molecule1 (Molecule) – Reference structure.

  • molecule2 (Molecule) – Structure to be rotated/translated onto molecule1.

  • mask (array-like of bool, optional) – Optional mask selecting which atoms of molecule1 participate in the RMSD. Must be broadcastable / compatible with the Fortran backend’s mask semantics.

Returns:

  • rmsd (float) – Root-mean-square deviation in Ångström.

  • new_molecule2 (Molecule) – Copy of molecule2 with its positions replaced by the aligned coordinates returned by the backend.

  • rotation_matrix (np.ndarray) – 3×3 rotation matrix applied to align molecule2 onto molecule1.

Raises:

TypeError – If either input is not a Molecule.

irmsd.interfaces.mol_interface.prune(molecule_list: Sequence[Molecule], rthr: float, iinversion: int = 0, allcanon: bool = True, printlvl: int = 0, ethr: float | None = None, ewin: float | None = None, use_ids: bool = True) → List[Molecule][source]#

High-level wrapper around the Fortran-backed sorter_irmsd that operates directly on Molecule objects. Returns a pruned list of structures.

Parameters:
  • molecule_list (Sequence[Molecule]) – Sequence of Molecule objects. All molecules must have the same number of atoms.

  • rthr (float) – Distance threshold for the sorter (passed through to the backend).

  • iinversion (int, optional) – Inversion symmetry flag, passed through to the backend.

  • allcanon (bool, optional) – Canonicalization flag, passed through to the backend.

  • printlvl (int, optional) – Verbosity level, passed through to the backend.

  • ethr (float | None) – Optional energy threshold to accelerate by pre-sorting

  • ewin (float | None) – Optional energy window to limit ensembe size around lowest energy structure. In Hartree.

Returns:

new_molecule_list – New Molecule objects reconstructed from the sorted atomic numbers and positions returned by the backend. The list contains only n_structures defined as unique according to the selected thresholds.

Return type:

list[Molecule]

Raises:
  • TypeError – If molecule_list does not contain Molecule instances.

  • ValueError – If molecule_list is empty or if the Molecules do not all have the same number of atoms.

irmsd.interfaces.mol_interface.prune_by_energy_window(molecule_list: Sequence[Molecule], energy_window: float | None) → List[Molecule][source]#

Prune a list of Molecule objects based on a relative energy window.

This function identifies the lowest-energy structure in molecule_list and retains only those molecules whose energies lie within energy_window Hartree above this minimum. Energies are obtained via get_energies_from_molecule_list and are assumed to be aligned with the order of molecule_list.

If energy_window is None, the input list is returned unchanged.

Parameters:
  • molecule_list (list of Molecule) – The structures to be filtered.

  • energy_window (float or None) – Allowed energy range above the minimum structure, in Hartree. If None, no pruning is performed.

Returns:

pruned – A new list containing only the structures within the specified energy window.

Return type:

list of Molecule

Notes

The reference energy is the minimum energy found in the provided list. No sorting of the returned molecules is performed; the original order (minus removed entries) is preserved.

irmsd.interfaces.mol_interface.sorter_irmsd_molecule(molecule_list: Sequence[Molecule], rthr: float = 0.125, iinversion: int = 0, allcanon: bool = True, printlvl: int = 0, ethr: float | None = None, ewin: float | None = None, use_ids: bool = True) → Tuple[ndarray, List[Molecule]][source]#

High-level wrapper around the Fortran-backed sorter_irmsd that operates directly on Molecule objects.

Parameters:
  • molecule_list (Sequence[Molecule]) – Sequence of Molecule objects. All molecules must have the same number of atoms.

  • rthr (float) – Distance threshold for the sorter (passed through to the backend).

  • iinversion (int, optional) – Inversion symmetry flag, passed through to the backend.

  • allcanon (bool, optional) – Canonicalization flag, passed through to the backend.

  • printlvl (int, optional) – Verbosity level, passed through to the backend.

  • ethr (float | None) – Optional energy threshold to accelerate by pre-sorting

  • ewin (float | None) – Optional energy window to limit ensembe size around lowest energy structure. In Hartree.

Returns:

  • groups (np.ndarray) – Integer array of shape (nat,) with group indices for the first nat atoms (as defined by the backend).

  • new_molecule_list (list[Molecule]) – New Molecule objects reconstructed from the sorted atomic numbers and positions returned by the backend. The list has the same length and ordering as molecule_list.

Raises:
  • TypeError – If molecule_list does not contain Molecule instances.

  • ValueError – If molecule_list is empty or if the Molecules do not all have the same number of atoms.