Model Analyzer#

Utility for ModelAnalyzer class.

add_local_parameter(matrix_info, parameter, ket)[source]#

Add local parameter for given nonlocal parameter.

Parameters:
  • matrix_info (dict) – matrix info.

  • parameter (dict) – parameter dict without site cluster.

  • ket (list) – ket list.

Returns:

  • (dict) – parameter dict with adding local one.

add_local_parameter_sym(matrix_info, ket)[source]#

Add local parameter for given nonlocal parameter.

Parameters:
  • matrix_info (dict) – matrix info.

  • ket (list) – ket list.

Returns:

  • (dict) – parameter dict with adding local one.

check_same_orbital_block(ket)[source]#

Check same orbital block for all atoms.

Parameters:

ket (list) – ket list.

Returns:

  • (bool) – same block ?

  • (int) – block size.

convert_orbital_to_detail(tag)[source]#

Convert orbital name to (rank, comp).

Parameters:

tag (str) – “name” or “(name,u/d)”. name = wannier90 or multipie.

Returns:

  • (tuple) – orbital (rank, comp, tag).

convert_zj_atomic_var(matrix_info, combined_cluster, combined_id, IR, full_ket, basis_type)[source]#

Convert from zj to atomic variable.

Parameters:
  • matrix_info (dict) – matrix info.

  • combined_cluster (dict) – combined cluster.

  • combined_id (dict) – combined id.

  • IR (str) – identity irrep.

  • full_ket (list) – kets of the full matrix, [(atom, sublattice, rank, basis_idx, orbital)].

  • basis_type (str) – basis type, “lg/lgs/jml”.

Returns:

  • (dict) – zj to var for each cluster, dict[bond name, dict[“bond” or zj, (head site, tail site) or var] ].

Note

  • “bond” is (head site, tail site) of bond 1, e.g., (“C(2)”, “C(1)”).

  • the atomic variables are g_{head orbital,tail orbital} and h_{…}, H_{head,tail} = g + i h at bond 1, with the short orbital names (short_orbital_name).

create_all_local_operator()[source]#

Create local operators.

Returns:

  • (dict) – local operators, dict[rank, dict[name, matrix]].

Note

  • atomic basis is tesseral harmonics, s, px, py, pz, dv, dxy, dxz, dyz, du, fc, fs, fbz, f3, fx, fy, faz.

  • operator names are Lx, Ly, Lz, Qu, Qv, Qyz, Qxz, Qxy, and spin Sx, Sy, Sz (in d[“s”]).

  • they are not normalized as SAMB (Tr X^2 = 1), but are the physical operators: the normalized atomic SAMB is multiplied by the factor in op_factor.

  • Lx, Ly, Lz: orbital angular momentum (in units of hbar), [Lx, Ly] = i Lz, L^2 = l(l+1).

  • Qu, Qv, Qyz, Qxz, Qxy: matrix elements <l m|Q(r)|l m’> of the angular functions, Qu = (3z^2-r^2)/(2r^2), Qv = sqrt(3)(x^2-y^2)/(2r^2), Qyz = sqrt(3)yz/r^2, Qxz = sqrt(3)zx/r^2, Qxy = sqrt(3)xy/r^2, e.g., <pz|Qu|pz> = 2/5, <du|Qu|du> = 2/7, <faz|Qu|faz> = 4/15.

  • Sx, Sy, Sz: sigma/2 in the order of (u, d).

  • L and Q are zero for rank 0 (s orbital).

  • it is used for basis, lg and lgs, not for jml.

create_gnuplot_cmd(filename, k_dis_pos, kmax, emax, emin, ef, colormap=False, lwidth=2, lc='salmon')[source]#

Create gnuplot file.

Parameters:
  • filename (str) – file name.

  • k_dis_pos (dict) – info. of high-symmetry point in linear k, dict[disconnected position, label].

  • kmax (float) – maximum value in kpoints.

  • emax (float) – maximum value of eigen values.

  • emin (float) – minimum value of eigen values.

  • ef (float) – fermi energy.

  • colormap (bool, optional) – with colormap of first expectation value of operator.

  • lwidth (int, optional) – line width.

  • lc (str, optional) – line color.

Notes

  • values that cannot be computed are not written in data file, so that they are skipped in the plot.

create_gnuplot_dos(filename, emin, emax, dmax, ef, labels, lwidth=2)[source]#

Create gnuplot file for DOS.

Parameters:
  • filename (str) – file name of data, columns (E, total, N(E), partial, …).

  • emin (float) – minimum of energy grid (not shifted).

  • emax (float) – maximum of energy grid (not shifted).

  • dmax (float) – maximum of total DOS.

  • ef (float) – fermi energy.

  • labels (list) – label of partial DOS.

  • lwidth (int, optional) – line width.

create_gnuplot_weight(filename, k_dis_pos, kmax, emax, emin, ef, labels, lwidth=2)[source]#

Create gnuplot file for band dispersion colored by orbital weight (fat band), one page for each weight.

Parameters:
  • filename (str) – file name of data, columns (k, E, weight1, weight2, …).

  • k_dis_pos (dict) – info. of high-symmetry point in linear k, dict[disconnected position, label].

  • kmax (float) – maximum value in kpoints.

  • emax (float) – maximum value of eigen values.

  • emin (float) – minimum value of eigen values.

  • ef (float) – fermi energy.

  • labels (list) – label of weights (without spaces).

  • lwidth (int, optional) – line width.

create_k_matrix(matrix, cluster_dict, vector_dict)[source]#

Create momentum matrix.

Parameters:
  • matrix (dict) – O(R) matrix dict.

  • cluster_dict (dict) – cluster dict.

  • vector_dict (dict) – vector dict.

Returns:

  • (dict) – momentum matrix, dict[tag, dict[(m,n), value] ].

Notes

  • only tight-binding gauge is supported.

create_k_multipole(cluster_samb, cluster_vector)[source]#

Create momentum multipole.

Parameters:
  • cluster_samb (dict) – cluster SAMB.

  • cluster_vector (dict) – cluster vector.

Returns:

  • (dict) – momentum multipole in terms of k.b_n, dict[wyckoff, dict[idx, (k_multipole, symmetry)] ].

  • (dict) – cluster vector, dict[site/bond name, dict[kb, expression] ].

create_local_operator(ket, op_name, op_dict, spinful)[source]#

Create local operator.

Parameters:
  • ket (list) – ket set.

  • op_name (str) – operator name.

  • op_dict (dict) – operator dict.

  • spinful (bool) – lgs basis ?

Returns:

  • (ndarray) – matrix for given operator.

create_operator_index(ket, mode=None)[source]#

Create operator index.

Parameters:
  • ket (list) – ket list.

  • mode (str, optional) – “orbital” or “spin”.

Returns:

  • (list) – index pair list.

Note

  • atom, sublattice, rank is the same in pair.

  • spin is the same for “orbital” mode.

  • orbital is the same for “spin” mode.

density_matrix_r(Uk, occupation, atom, kv, R, s=True)[source]#

Sum over k points of the density matrix, as the counterpart of a real-space matrix O(R).

Parameters:
  • Uk (ndarray) – eigen vectors, Uk[k,:,n].

  • occupation (ndarray) – occupation of each eigen state, [k,n].

  • atom (ndarray) – atomic positions.

  • kv (ndarray) – k points (fractional).

  • R (ndarray) – lattice vectors, [number of R, 3].

  • s (bool, optional) – include phase of atomic position ?

Returns:

  • (ndarray) – A[R,m,n] = sum_k P(k)_nm exp(2pi i k*R) (with the phase of atomic position, as fourier_r_to_k).

Notes

  • P(k) = U(k) f U(k)^dagger, and sum_k Tr[P(k) O(k)] = sum_(R,m,n) O(R)_mn A[R,m,n] for O(k) by fourier_r_to_k.

fermi_dirac(x, T=0.0, unit='Kelvin')[source]#

Fermi-Dirac distribution function, f(x) = 1 / (1 + exp(x/T)).

Parameters:
  • x (ndarray) – energy relative to the chemical potential (E - mu), in eV.

  • T (float, optional) – temperature (Kelvin or eV, see unit).

  • unit (str, optional) – unit of T, “Kelvin” or “eV”.

Returns:

  • (ndarray) – Fermi-Dirac occupation, 0 <= f(x) <= 1.

fermi_dirac_deriv(x, T=0.01, unit='Kelvin')[source]#

Minus the derivative of the Fermi-Dirac distribution w.r.t. x, -df/dx = f(x)*f(-x)/T. A positive, bell-shaped function peaked at x=0 (used e.g. for smearing/DOS broadening).

Parameters:
  • x (ndarray) – energy relative to the chemical potential (E - mu), in eV.

  • T (float, optional) – temperature (Kelvin or eV, see unit). Must be nonzero.

  • unit (str, optional) – unit of T, “Kelvin” or “eV”.

Returns:

  • (ndarray) – -df/dx.

fermi_dirac_deriv2(x, T=0.01, unit='Kelvin')[source]#

Second derivative of the Fermi-Dirac distribution w.r.t. x, -d^2f/dx^2 (i.e. the derivative of fermi_dirac_deriv).

Parameters:
  • x (ndarray) – energy relative to the chemical potential (E - mu), in eV.

  • T (float, optional) – temperature (Kelvin or eV, see unit). Must be nonzero.

  • unit (str, optional) – unit of T, “Kelvin” or “eV”.

Returns:

  • (ndarray) – -d^2f/dx^2.

fourier_k_to_r(Ok, atom, kv, irvec, s=True)[source]#

Fourier transformation from k to R (inverse of fourier_r_to_k).

Parameters:
  • Ok (ndarray) – O(k) matrix, shape (Nk, d, d).

  • atom (ndarray) – atomic positions.

  • kv (ndarray) – list of k vector.

  • irvec (iterable) – list/array of R = (n1, n2, n3) lattice vectors to evaluate O_R at.

  • s (bool, optional) – include phase of atomic position ? (must match the value used to generate Ok).

Returns:

dict[(n1,n2,n3,m,n): value], O_R = (1/Nk) sum_k O(k) exp(-2pi i k*Rs), Rs = (n1,n2,n3)-s(R[m]-R[n]), i.e. the inverse of fourier_r_to_k.

Return type:

dict

fourier_r_to_k(OR, atom, kv, s=True)[source]#

Fourier transformation from R to k.

Parameters:
  • OR (dict) – matrix dict, dict[(n1,n2,n3,m,n): value].

  • atom (ndarray) – atomic positions.

  • kv (ndarray) – list of k vector.

  • s (bool, optional) – include phase of atomic position ?

Returns:

  • (ndarray) – O(k) = sum_s Omn exp( 2pi i k*Rs ), Rs = (n1,n2,n3)-s(R[m]-R[n]).

grid_all(N1, N2, N3)[source]#

Create N1 x N2 x N3 grid points.

Parameters:
  • N1 (int) – number of divisions for a1.

  • N2 (int) – number of divisions for a2.

  • N3 (int) – number of divisions for a3.

Returns:

  • (ndarray) – grid points.

grid_path(pts, gpath, N1=100, A=None)[source]#

Create grid points along path.

Parameters:
  • pts (dict) – definitions of points, e.g., {“A”:[1,2,3],”B”:[3,4,5]}.

  • gpath (str) – path, e.g., “A-B|C-D-E”.

  • N1 (int, optional) – number of divisions.

  • A (ndarray, optional) – conversion matrix.

Returns:

  • (ndarray) – grid points.

  • (ndarray) – linear positions.

  • (dict) – dict[disconnected linear position, label].

is_almost_zero(x)[source]#

Check if x is numerically zero (within a tolerance).

k_label(label, style='latex')[source]#

Convert k-point label for plot.

Parameters:
  • label (str) – k-point label, e.g., “Γ”, “GAMMA”, “G”, “X|M”.

  • style (str, optional) – “latex” (matplotlib) or “gnuplot” (enhanced text).

Returns:

  • (str) – converted label.

kelvin_to_ev(T_kelvin)[source]#

Convert temperature from Kelvin to eV (k_B * T).

local_expectation(Uk, op)[source]#

Expectation value of local operator for each eigen state.

Parameters:
  • Uk (ndarray) – eigen vectors, Uk[k,:,n].

  • op (ndarray) – operator matrix (dim x dim).

Returns:

  • (ndarray) – expectation values, [k,n].

operator_expectation(Uk, Ok)[source]#

Expectation value of k-dependent operator for each eigen state.

Parameters:
  • Uk (ndarray) – eigen vectors, Uk[k,:,n].

  • Ok (ndarray) – operator matrix at each k, Ok[k,:,:].

Returns:

  • (ndarray) – expectation values (real part), [k,n].

output_dispersion(filename, k, ef, e, o=None, olist=None)[source]#

Output band dispersion along high-symmetry lines.

Parameters:
  • filename (str) – file name.

  • k (ndarray) – k points along high-symmetry lines.

  • ef (float) – fermi energy.

  • e (ndarray) – eigen values.

  • o (list, optional) – expectation value of any operator for each band, [[num_k, num_band]].

  • olist (list, optional) – list of local operator.

output_dos(filename, energy, ef, dos, labels, comment)[source]#

Output DOS.

Parameters:
  • filename (str) – file name.

  • energy (ndarray) – energy grid (not shifted).

  • ef (float) – fermi energy.

  • dos (ndarray) – DOS, [energy, column], columns (total, integrated total, partial, …).

  • labels (list) – label of partial DOS.

  • comment (list) – comment lines (without “#”).

parse_orbital(orbital_str)[source]#

Parse orbital string.

Parameters:

orbital_str (str) – orbital string, (orbital, spin).

Returns:

  • (tuple or str) – orbital, spin or orbital.

plot_save_dispersion(filename, k_dis_pos, ef=None, colormap=False, lwidth=1, lc='salmon')[source]#

Generate plot window for band dispersion (matplotlib).

Parameters:
  • filename (str) – file name.

  • k_dis_pos (dict) – info. of high-symmetry point in linear k, dict[disconnected position, label].

  • ef (float, optional) – not used, kept for compatibility.

  • colormap (bool, optional) – with colormap of first expectation value of operator.

  • lwidth (int, optional) – line width.

  • lc (str, optional) – line color.

Notes

  • energies in data file are already shifted by fermi energy.

plot_save_dos(filename, labels, lwidth=1)[source]#

Plot DOS (matplotlib).

Parameters:
  • filename (str) – file name of data, columns (E, total, N(E), partial, …).

  • labels (list) – label of partial DOS.

  • lwidth (float, optional) – line width.

Notes

  • energies in data file are already shifted by fermi energy.

plot_save_weight(filename, k_dis_pos, labels, lwidth=1.5)[source]#

Plot band dispersion colored by orbital weight (fat band), one page for each weight (matplotlib).

Parameters:
  • filename (str) – file name of data, columns (k, E, weight1, weight2, …).

  • k_dis_pos (dict) – info. of high-symmetry point in linear k, dict[disconnected position, label].

  • labels (list) – label of weights.

  • lwidth (float, optional) – line width.

Notes

  • energies in data file are already shifted by fermi energy.

  • the plots are saved in one PDF file (filename with .pdf).

power_energy(Ek, power)[source]#

Raise energy to the power.

Parameters:
  • Ek (ndarray) – energy eigen values.

  • power (float) – power (positive).

Returns:

  • (ndarray) – Ek^power, or -|Ek|^power where Ek^power is not a real number (negative Ek with non-integer power).

read_text_data(filename)[source]#

Read text data.

Parameters:

filename (str) – file name.

Returns:

  • (list) – block of data (ndarray) separated by empty line, [block][x, y].

samb_matrix_value(matrix)[source]#

SAMB matrix (real-space) with numerical values.

Parameters:

matrix (dict) – SAMB matrix, dict[(n1,n2,n3,m,n), (value, bond_no)] (value may be sympy).

Returns:

  • (dict) – dict[((n1,n2,n3),m,n), complex value], the form of fourier_r_to_k.

short_orbital_name(orbital, rank, basis_type)[source]#

Short orbital name for the atomic variables (ASCII).

Parameters:
  • orbital (str) – orbital of the ket, e.g., “pz”, “(px,u)”, “(3/2,1/2)”.

  • rank (int) – orbital rank.

  • basis_type (str) – basis type, “lg/lgs/jml”.

Returns:

  • (str) – short name, e.g., “pz”, “pxu” (lgs), “p(3/2,1/2)” (jml).

solve_z(Z_dict, names, simplify=True)[source]#

Solve z parameter in terms of atomic parameters on bond 1.

Parameters:
  • Z_dict (dict) – bond-1 basis, dict[(m,n), val].

  • names (list) – name of each ket, used for the atomic variables g_{m,n} and h_{m,n}.

  • simplify (bool, optional) – simplify result ?

Returns:

  • (dict) – z parameter.