Utils

MagInt.utils.Kanamori_hamiltonian(U_int, J_hund, orbital, dft_exec)

Constructs the Kanamori Hamiltonian in the Wien2k format or returns the double counting for the Kanamori convention.

Parameters:
  • U_int (float) – The screened Coulomb interaction value.

  • J_hund (float) – The Hund’s exchange coupling value.

  • orbital (int) – Defines the orbital angular momentum quantum number (l). For instance, for d orbitals, this would be 2.

  • dft_exec (str) – The DFT executable being used. Currently, only ‘Wien2k’ is supported.

Returns:

  • U_full (ndarray) – The full Kanamori Hamiltonian matrix in the given DFT executable’s format.

  • U_dc (float) – The double counting term for the Coulomb interaction.

  • J_dc (float) – The double counting term for Hund’s exchange interaction.

MagInt.utils.compare_dicts(dict1, dict2, rtol=1e-05, atol=1e-08)

Compare two dictionaries for equality, with support for numpy arrays.

Parameters:
  • dict1 (dict) – The first dictionary to compare.

  • dict2 (dict) – The second dictionary to compare.

  • rtol (float, optional) – The relative tolerance parameter for numpy array comparison (default is 1e-5).

  • atol (float, optional) – The absolute tolerance parameter for numpy array comparison (default is 1e-8).

Returns:

Returns True if both dictionaries are the same; otherwise, False.

Return type:

bool

MagInt.utils.compare_lists_arrays(list1, list2, rtol=1e-05, atol=1e-08)

Compare two lists of NumPy arrays.

Parameters:
  • list1 (list) – First list of NumPy arrays.

  • list2 (list) – Second list of NumPy arrays.

  • rtol (float) – Relative tolerance.

  • atol (float) – Absolute tolerance.

Return type:

True if all corresponding arrays in the lists are equal within the given tolerance, False otherwise.

MagInt.utils.cub_eal(dim)

Extracts the transformation matrix from the ‘real_d_harms’ file.

Reads the ‘real_d_harms’ file and constructs the transformation matrix.

Parameters:

dim (int) – The dimension of the square transformation matrix to be constructed.

Returns:

The transformation matrix of shape (dim, dim) populated with complex values.

Return type:

ndarray

MagInt.utils.gener_L_mat(l)

Generate the total angular momentum matrices Jx, Jy, Jz, J+, and J-.

This function constructs the total angular momentum matrices (Jx, Jy, Jz, J+, and J-) for a given quantum number j. The matrices are based on the quantum mechanics definitions for angular momentum.

Parameters:

j (float) – The total angular momentum quantum number.

Returns:

A dictionary containing the angular momentum matrices ‘x’, ‘y’, ‘z’, ‘p’ (which corresponds to J+), and ‘m’ (which corresponds to J-), where each key maps to its respective matrix.

Return type:

dict

MagInt.utils.gener_M_mat(L, S, gamma)

Generate magnetic moment operator matrices.

Constructs the magnetic moment operators (Mx, My, and Mz) from the given orbital (L) and spin (S) angular momentum matrices using the Landé g-factor.

Parameters:
  • L (dict) – Dictionary containing the orbital angular momentum matrices ‘x’, ‘y’, and ‘z’.

  • S (dict) – Dictionary containing the spin angular momentum matrices ‘x’, ‘y’, and ‘z’.

  • gamma (float) – Landé g-factor used to weight the contribution from orbital angular momentum.

Returns:

A dictionary containing the magnetic moment matrices ‘x’, ‘y’, and ‘z’.

Return type:

dict

MagInt.utils.gener_S_mat(nlm)

Generate the spin matrices Sx, Sy, Sz, Sp and Sm, where Sp/Sm are the S+/- ladder operators respectively.

This function creates the three spin matrices for a given dimension. The matrices are constructed in a larger 2D space, where the original dimension is multiplied by 2 to account for spin up and spin down states. Each spin matrix is represented in the Pauli matrix form.

Parameters:

nlm (int) – Dimension for which the spin matrices are to be constructed.

Returns:

A dictionary containing the spin matrices ‘x’, ‘y’, ‘z’, ‘p’, ‘m’ , where each key maps to its respective spin matrix.

Return type:

dict

MagInt.utils.my_get_vec(n, iv, vec)

Extracts a specific vector from the ‘STATES’ file.

Reads the ‘STATES’ file and retrieves the vector number iv. The structure of each line in ‘STATES’ is expected to have the format of a complex number in parenthesis, e.g., (real,imag).

Parameters:
  • n (int) – The total number of vectors in the ‘STATES’ file.

  • iv (int) – The index of the vector to be extracted (0-based index).

  • vec (list or ndarray) – An initialized list or array to store the extracted vector values.

Returns:

The updated list or array containing the values of the extracted vector.

Return type:

list or ndarray

MagInt.utils.print_arr(arr, log='arr', fname=None, decd=4, prn_zero_imag=False)

Print the real and/or imaginary parts of an array with customizable format.

This function is designed to print either the real part, imaginary part, or both of an array, depending on the presence of non-zero values in these parts and the parameters provided.

Parameters:
  • arr (numpy.ndarray) – The array to be printed. Should be a two-dimensional array.

  • log (str, optional) – Label for the output. Defaults to ‘arr’.

  • fname (str, optional) – If provided, the output will be written to a file with this name. Otherwise, it will be printed to the standard output. Defaults to None.

  • decd (int, optional) – Number of decimal places for the printed values. Defaults to 4.

  • prn_zero_imag (bool, optional) – If True, the imaginary part of the array will always be printed, even if it’s zero. Defaults to False.

MagInt.utils.print_mat(mat)

Print the real and imaginary parts of a matrix in a formatted manner.

This function is designed to display each element of the matrix with its real and imaginary components. The output is formatted to show up to 5 decimal places for both the real and imaginary parts.

Parameters:

mat (numpy.ndarray) – The matrix to be printed. Should be a square matrix with both real and imaginary parts.

Notes

The output format for each element is: “real_part imaginary_part”, with each part displayed with up to 5 decimal places.

MagInt.utils.read_eal(eal_fname, nlms)

Read the Effective Atomic Levels (EAL) from a file and store it in a dictionary format.

This function reads the EAL data from the specified file. The EAL data is expected to contain real and imaginary parts, which are combined into a complex number. The processed data is then stored in a dictionary with a key ‘ud’.

Parameters:
  • eal_fname (str) – Path to the file containing the EAL data.

  • nlms (int) – Dimension of the EAL square matrix. It indicates the number of rows and columns of the matrix.

Returns:

Dictionary containing the EAL data as a complex matrix under the ‘ud’ key.

Return type:

dict

MagInt.utils.read_mat(mat_fname)

Read a matrix from a file and convert it to a complex format.

This function reads data from the specified file where the data is expected to have real and imaginary parts presented in separate columns. The function combines these parts into complex numbers and arranges them into a complex matrix of appropriate dimensions.

Parameters:

mat_fname (str) – Path to the file containing the matrix data.

Returns:

A complex matrix constructed from the real and imaginary parts read from the file.

Return type:

np.ndarray