Calculate#

diatomic.calculate.electric_moment(mol, eigstates)#

Calculates the electric moments of each eigenstate.

Parameters:
  • eigstates (np.ndarray) – array of eigenstates from diagonalisation

  • mol – The molecule used to generate the eigenstates

Returns:

An array corresponding to the electric moments of the eigenstates.

Return type:

ndarray

diatomic.calculate.label_states(mol, eigstates, labels, index_repeats=False)#

Labels the eigenstates of a molecule with quantum numbers corresponding to specified labels. The returned numbers will only be good if the state is well-represented in the desired basis.

This function processes a list of labels that specify which quantum numbers to calculate for the given eigenstates of a molecule. It uses the angular momentum operators for the molecule and the eigenstates to calculate these quantum numbers.

The function supports labels for the total angular momentum vectors (N, F, I, I1, I2) for the z-component of them respectively (M<>). It also has an option to return the indices of repeated labels.

Parameters:
  • mol – An object representing the molecule, which contains the maximum angular momentum (Nmax) and intrinsic angular momenta (Ii).

  • eigstates (ndarray) – An array of eigenstates for which the labels are to be calculated.

  • labels (list of str) – A list of strings indicating which quantum numbers to calculate. Valid labels are “MN”, “MF”, “MI”, “MI1”, “MI2” for M-components and “N”, “F”, “I”, “I1”, “I2” for squared total angular momentum vectors.

  • index_repeats (bool, optional) – If True, includes the label indices of repeated labels in the output. Defaults to False.

Returns:

A two-dimensional array where each row corresponds to the desired

quantum numbers for each eigenstate, and each column corresponds to a label.

Return type:

ndarray

diatomic.calculate.magnetic_moment(mol, eigstates)#

Calculates the magnetic moments of each eigenstate.

Parameters:
  • eigstates (np.ndarray) – array of eigenstates from diagonalisation

  • mol – The molecule used to generate the eigenstates

Returns:

An array corresponding to the magnetic moments of the eigenstates.

Return type:

ndarray

diatomic.calculate.solve_system(hamiltonians, num_diagonals=None)#

Solves for the eigenenergies and eigenstates of given Hamiltonian(s over 1 parameter).

This function diagonalizes the input Hamiltonian(s) to find the corresponding eigenenergies and eigenstates. It supports both single Hamiltonian and a set of Hamiltonians (e.g., varying with time or another parameter).

It takes care to make sure the eigenenergies and eigenstates vary smoothly with respect to the varying parameter, unlike np.eigh.

Parameters:
  • hamiltonians (np.ndarray) – A single Hamiltonian matrix or an array of Hamiltonian matrices.

  • num_diagonals (int | None, optional) – The number of local swaps above and below to consider when smoothing eigenfunctions. Changing this to a number can speed up smoothing calculations for large numbers of eigenstates. If None, compare all eigenstates to all other eigenstates when smoothing (safest).

Returns:

(eigenenergies, eigenstates).

Return type:

tuple

Raises:

ValueError – If the input Hamiltonian has more than three dimensions.

diatomic.calculate.sort_by_labels(eigenlabels, eigenenergies, eigenstates)#

Sorts eigenstates and eigenenergies according to the provided labels lexicographically.

This function sorts the eigenstates and eigenenergies in ascending order based on the eigenlabels, which can be quantum numbers or any other identifiers for the states. They are sorted with the first label value taking preference, and then the second if the first drew, as with a language dictionary.

Parameters:
  • eigenlabels (np.ndarray) – Array of labels corresponding to eigenstates.

  • eigenenergies (np.ndarray) – Array of eigenenergies to be sorted.

  • eigenstates (np.ndarray) – Array of eigenstates to be sorted.

Returns:

The sorted eigenlabels, eigenenergies, and eigenstates.

Return type:

tuple

diatomic.calculate.sort_smooth(eigvals, eigvecs, num_diagonals=None)#

Smooths the eigenvalue trajectories as a function of an external parameter, rather than by energy order, as is the case with np.eigh.

This function sorts the eigenvalues and eigenvectors to maintain continuity as the external parameter changes, preventing sudden jumps in the eigenvalue ordering.

Parameters:
  • eigvals (np.ndarray) – Eigenvalues array with shape (steps, eigstate).

  • eigvecs (np.ndarray) – Eigenvectors array with shape (steps, basis, eigstate).

  • num_diagonals (int | None, optional) – The number of local swaps above and below to consider when smoothing eigenfunctions. Changing this to a number can speed up smoothing calculations for large numbers of eigenstates. If None, compare all eigenstates to all other eigenstates when smoothing (safest).

Returns:

The smoothed eigenvalues and eigenvectors.

Return type:

tuple

Raises:

ValueError – If eigvecs does not have three dimensions.

diatomic.calculate.transition_electric_moments(mol, eigenstates, h=0, from_states=slice(None, None, None))#

Calculates the electric dipole transition coupling strengths between molecular eigenstates.

Parameters:
  • eigenstates (ndarray) – An array containing the eigenstates of the molecule.

  • mol – An object representing the molecule.

  • h (int, optional) – The helicity of the transition, +1 for sigma+, 0 for pi, -1 for sigma-.

  • from_states (int, slice, or list, optional) – The indices of the initial states from which transitions are considered. If an integer is passed, it is internallyconverted to a list. By default, all states are considered (slice(None)).

Returns:

An array containing the absolute values of the transition electric

moments for the specified transitions between eigenstates.

Return type:

ndarray