Wannier#
Utility functions for reading Wannier90 files used by ModelAnalyzer.
- apply_ws_degeneracy(hr_dict, irvec, ndegen, wsvec=None)[source]#
Convert H(R) in “hr.dat” into real-space hoppings, using the Wigner-Seitz degeneracies.
- Parameters:
hr_dict (dict) – H(R) read by
read_hr(), dict[(n1,n2,n3,a,b), value].irvec (ndarray) – R vectors, [num_R][3].
ndegen (ndarray) – Wigner-Seitz degeneracy of each R, [num_R].
wsvec (dict, optional) – shortest image translations read by
read_wsvec().
- Returns:
(dict) – real-space hoppings, dict[(n1,n2,n3,a,b), value].
Note
Wannier90 gives H(k) = sum_R H(R) exp(ik.R) / ndegen(R), where H(R) of the equivalent images on the boundary of the Wigner-Seitz supercell is written with the full value. The hopping at each image is H(R)/ndegen(R).
with use_ws_distance (wsvec), H_ab(R) is further distributed over R+T with the weight 1/nT.
- build_ket_wannier(nnkp, site_dict, rtol=0.0001, atol=0.0001)[source]#
Construct the MultiPie ket basis from Wannier90 projection information.
- Parameters:
nnkp (dict) – Information returned by
read_nnkp().site_dict (dict) – MultiPie sites in the form
{(name, sublattice): fractional_position}.rtol (float, optional) – Relative tolerance for comparing fractional positions.
atol (float, optional) – Absolute tolerance for comparing fractional positions.
- Returns:
(list) – Wannier ket basis with one entry per Wannier function. Each entry has the form
[name, sublattice, l, orbital].
Notes
Fractional positions are compared modulo lattice translations, so coordinates differing by an integer lattice vector are treated as the same site.
- convert_hr_to_model(hr_dict, mapping)[source]#
Convert H(R) in “hr.dat” into the ket and lattice of a MultiPie model.
- Parameters:
hr_dict (dict) – H(R) in Wannier index, dict[(n1,n2,n3,a,b), value].
mapping (dict) – mapping information returned by
map_wannier_to_model().
- Returns:
(dict) – H(R) in MultiPie index and primitive lattice of the model, dict[(n1,n2,n3,m,n), (value, None)].
Note
H_ab(R) = <0,a|H|R,b> is re-indexed through the bond vector, (c_b + R - c_a) U = r_n + (R U + L_b - L_a) - r_m, where c and r are the projection centre and the position of MultiPie ket, and L is the lattice offset.
- convert_to_conventional_frac(A, atoms_frac, symprec=0.0001)[source]#
Convert atomic positions in “win” to fractional coordinates of the conventional cell.
- Parameters:
A (ndarray) – lattice vector in “win”, [a1,a2,a3].
atoms_frac (dict) – atoms_frac in “win”.
symprec (float, optional) – precision for spglib.
- Returns:
(int) – space group no.
(dict) – atoms_frac in conventional cell.
Note
for a centred lattice, the positions are transformed into the standard conventional cell of spglib, x’ = P x + p.
for a primitive lattice, the positions are returned as they are.
- create_ket_wannier_multipie(wannier_info, tol=0.0001)[source]#
Create wannier and MultiPie ket, and conversion index.
- Parameters:
wannier_info (dict) – wannier_info dict. A, atoms_frac, atomc_cart, nw2n, nw2l, nw2m, nw2r, nw2s, atom_pos_r.
tol (float, optional) – tolerance to match projection centres with atoms (fractional).
- Returns:
(list) – idx for converting from wannier to multipie. <m|w> = delta(m.w2m(w)).
(list) – idx for converting from multipie to wannier. <m|w> = delta(w,m2w(m)).
(list) – ket_multipie name. |m>.
(list) – projection centre in fractional coordinate (in multipie order). |m>(pos).
(list) – projection centre in cartesian coordinate (in multipie order). |m>(pos).
Note
each projection centre (nw2n is its index in “nnkp”) is matched with an atom in “win” modulo lattice translations. a centre which is not on an atom (e.g., bond centre) is named X1, X2, … in order of appearance. if atom_pos_r is not given, the n-th projection centre is the n-th atom in “win”.
the positions are those of the projection centres, to which R of H(R) refers.
- decompose_operator_by_SAMB(Or_dict, Zr_dict, digit=15)[source]#
Decompose arbitrary operator into linear combination of SAMBs.
- Parameters:
Or_dict (dict) – dictionary form of an arbitrary operator matrix in real-space/k-space representation.
Zr_dict (dict) – dictionary form of SAMBs.
digit (int, optional) – round digit for Zr_dict.
- Returns:
(dict) – parameter set, dict[zj, coeff].
- find_lattice_transformation(A_wannier, A_model, tol=0.1)[source]#
Find integer unimodular matrix U such that A_wannier = U A_model.
- Parameters:
A_wannier (ndarray) – primitive lattice vectors in “win”, [a1,a2,a3] (Cartesian).
A_model (ndarray) – primitive lattice vectors of the model, [a1,a2,a3] (Cartesian).
tol (float, optional) – tolerance for the deviation of U from integers.
- Returns:
(ndarray) – U (int), or None if not found.
(float) – maximum deviation of U from integers.
Note
both lattices must be given in the same Cartesian frame (no rotation).
fractional coordinates are converted as x_model = x_wannier U.
- find_sg(A, atoms_frac, symprec=0.0001)[source]#
Find space group via spglib.
- Parameters:
A (ndarray) – lattice vector, [a1,a2,a3]. (conventional, standard setting).
atoms_frac (dict) – atoms_frac in “win”.
symprec (float, optional) – precision for spglib.
- Returns:
(int) – space group no.
- find_vector_index(vector_list, vector, symprec=0.0001)[source]#
Find vector index.
- Parameters:
vector_list (list) – vector list.
vector (ndarray) – vector to find.
symprec (float, optional) – precision.
- Returns:
(int) – index (None if not found).
Note
vectors differing by a lattice translation are regarded as the same.
- get_or_add_vector(existing_list, target_vector, symprec=0.0001)[source]#
Get and add vector.
- Parameters:
existing_list (list) – vector list previously appeared.
target_vector (ndarray) – vector.
symprec (float, optional) – precision.
- Returns:
(int) – index.
- map_wannier_to_model(nnkp, A_wannier, model, ket_wannier=None, tol=0.0001, lattice_tol=0.1)[source]#
Map Wannier functions onto the kets of a MultiPie model.
- Parameters:
nnkp (dict) – information returned by
read_nnkp().A_wannier (ndarray) – lattice vectors in “win”, [a1,a2,a3] (Cartesian).
model (MaterialModel) – loaded MultiPie model.
ket_wannier (list, optional) – MultiPie ket for each Wannier function, [“orbital@site(sublattice)”] or [[site, sublattice, orbital]]. If empty, it is determined from the projection centres.
tol (float, optional) – tolerance for fractional positions.
lattice_tol (float, optional) – tolerance for the lattice transformation.
- Returns:
- (dict) – mapping information.
w2m: MultiPie ket index of each Wannier function (list).
U: lattice transformation, x_model = x_wannier U + t (ndarray).
t: origin shift (ndarray).
offset: lattice offset L of each Wannier function, c U + t = r + L, where c and r are the projection centre and the position of MultiPie ket (int ndarray).
Note
the lattice of “win” must be related to the primitive lattice of the model by an integer unimodular matrix in the same Cartesian frame. Otherwise, the lattice vectors of “win” are assumed to be those of the model (with warning).
the origin shift t is chosen so that all the projection centres coincide with the sites of the model. When several shifts are possible, the smallest one is used (with warning if the mapping depends on the choice).
- matrix_dict_r(Or, rpoints, diagonal=False)[source]#
dictionary form of an arbitrary operator matrix in real-space representation.
- Parameters:
Or (ndarray) – real-space representation of the given operator, O_{ab}(R) = <φ_{a}(0)|O|φ_{b}(R)>.
rpoints (ndarray) – lattice points (crystal coordinate, [[n1,n2,n3]], nj: integer).
diagonal (bool, optional) – diagonal matrix ?
- Returns:
(dict) – real-space representation of the given operator, {(n2,n2,n3,a,b) = O_{ab}(R)}.
- merge_wannier_info(win, nnkp, seedname)[source]#
Check duplicated entries in
winandnnkp, then merge them.- Parameters:
win (dict) – Information returned by
read_win().nnkp (dict) – Information returned by
read_nnkp().seedname (str) – Wannier90 seedname used in error messages.
- Returns:
(dict) – Merged Wannier90 information. Every key present in both input dictionaries is checked for consistency, and the value from
winis retained for the duplicated key. With the current readers, the duplicated entries areA,num_k,num_wann, andkpoints.
- model_primitive_vector(model)[source]#
Get primitive lattice vectors of a MultiPie model.
- Parameters:
model (MaterialModel) – loaded MultiPie model.
- Returns:
(ndarray) – primitive lattice vectors, [a1,a2,a3] (Cartesian), consistent with the primitive fractional coordinates of the model.
- read_hr(hr_file, topdir=None)[source]#
Read
seedname_hr.datgenerated by Wannier90.- Parameters:
hr_file (str) – Wannier90 Hamiltonian file.
topdir (str, optional) – directory containing
seedname_hr.dat.
- Returns:
- (dict) – info. dict.
- HH_RReal-space Hamiltonian matrices
H_mn(R)in eV, shape
[num_R][num_wann][num_wann](ndarray).
- HH_RReal-space Hamiltonian matrices
- irvecLattice vectors
R = n1*a1 + n2*a2 + n3*a3in crystal coordinates, shape
[num_R][3](ndarray).
- irvecLattice vectors
- ndegenWigner-Seitz degeneracy of each
Rvector, shape [num_R](ndarray).
- ndegenWigner-Seitz degeneracy of each
Notes
Wannier indices in the file are one-based and are converted to zero-based array indices.
ndegenis the denominator used in the Wannier90 Fourier interpolation overRvectors. The file is read sequentially to avoid storing the full text representation in memory.
- read_nnkp(seedname, topdir=None)[source]#
Read
seedname.nnkpgenerated by Wannier90.- Parameters:
seedname (str) – Wannier90 seedname.
topdir (str, optional) – directory containing
seedname.nnkp.
- Returns:
- (dict) – info. dict.
- AReal lattice vectors
[a1,a2,a3]in Cartesian coordinates, shape
[3][3](list).
- AReal lattice vectors
- BReciprocal lattice vectors
[b1,b2,b3]in Cartesian coordinates, shape
[3][3](list).
- BReciprocal lattice vectors
num_k : Number of k points (int).
num_wann : Number of Wannier projections (int).
num_atom : Number of distinct projection centers (int).
num_b : Number of b-vectors per k point (int).
- kpointsk points in crystal coordinates, reduced to
0 <= k_i < 1, shape[num_k][3](list).
- nnkptsNearest-neighbour table
[ik,ikb,G1,G2,G3], shape[num_k][num_b][5](list).
- nw2nZero-based projection-center index of each
Wannier function, shape
[num_wann](list).
- nw2l, nw2mAngular indices
landmof each projection, shape
[num_wann](list).
- nw2l, nw2mAngular indices
- nw2rRadial-function index of each projection,
shape
[num_wann](list).
- nw2sSpin component of each projection; zero for
non-spinor projections (list).
- nw2saxisSpin-quantization axis of each projection,
shape
[num_wann][3](list).
- atom_orbWannier-function indices grouped by orbital
projection (list).
- atom_posOrbital-projection indices grouped by
projection center (list).
- atom_pos_rProjection-center positions in fractional
coordinates, shape
[num_atom][3](list).
- bvec_cartb-vectors at Gamma in Cartesian reciprocal
coordinates, shape
[num_b][3](list).
- bvec_crysThe same b-vectors in crystal coordinates,
shape
[num_b][3](list).
- wbFinite-difference weights of
bvec_cart, shape
[num_b](list).
- wbFinite-difference weights of
- bveckCartesian b-vector for each
(k,b)pair, shape
[num_k][num_b][3](list).
- bveckCartesian b-vector for each
- wkFinite-difference weight for each
(k,b) pair, shape
[num_k][num_b](list).
- wkFinite-difference weight for each
- kb2kZero-based index of
k+bfor each pair, shape
[num_k][num_b](list).
- kb2kZero-based index of
Notes
num_atomandatom_pos_rdescribe Wannier projection centers, which need not coincide with the physical atoms inseedname.win.For
auto_projections, onlynum_wannis available; the detailed projection entries are returned asNone.
- read_umat(seedname, topdir=None)[source]#
Read
seedname_u.mat,seedname_u_dis.mat. Not implemented yet.
- read_win(seedname, topdir=None)[source]#
Read
seedname.win.- Parameters:
seedname (str) – Wannier90 seedname.
topdir (str, optional) – directory containing
seedname.win.
- Returns:
- (dict) – info. dict.
num_k : Number of k points inferred from
mp_grid(int).num_bands : Number of Bloch bands passed to Wannier90 (int).
num_wann : Number of Wannier functions (int).
spinors : Whether the Wannier functions are spinors (bool).
fermi_energy: Fermi energy in eV (float).
- AReal lattice vectors
[a1,a2,a3]in angstrom, shape
[3][3](list).
- AReal lattice vectors
- atoms_fracAtomic positions in fractional coordinates,
{(symbol, occurrence): [r1,r2,r3]}(dict).
- atoms_cartAtomic positions in Cartesian coordinates in
angstrom,
{(symbol, occurrence): [x,y,z]}(dict).
mp_grid : Monkhorst-Pack grid
[nk1,nk2,nk3](list).- kpointsExplicit k points in crystal coordinates, reduced
to
0 <= k_i < 1, shape[num_k][3](list).
Notes
If only one of
atoms_fracandatoms_cartis present, the other is calculated usingA.Cartesian lengths are returned in angstrom.
- read_wsvec(seedname, topdir=None)[source]#
Read
seedname_wsvec.datgenerated by Wannier90.- Parameters:
seedname (str) – seedname.
topdir (str, optional) – directory containing
seedname_wsvec.dat.
- Returns:
(dict) – lattice translations T of the shortest images of each element, dict[(n1,n2,n3,a,b), [(T1,T2,T3)]], or None if the file does not exist.
Notes
Wannier indices in the file are one-based and are converted to zero-based indices.
H_ab(R) contributes to H_ab(k) as sum_T H_ab(R) exp(ik.(R+T)) / (ndegen(R) nT).
- sort_ket_list(lst, ket1, ket2)[source]#
Sort ket to align with the MultiPie definition (ket2).
- Parameters:
lst (list) – arbitrary list that has the same dimensions as the ket.
ket1 (list) – ket basis list, [[atom name, sublattice, rank, orbital]]
ket2 (list) – ket basis list, orbital@site.
- Returns:
(list) – arbitrary list that has the same dimensions as the ket.
- sort_ket_matrix(Ok, ket1, ket2)[source]#
Sort ket to align with the MultiPie definition (ket2).
- Parameters:
Ok (ndarray) – arbitrary operator in k-space representation, O_{ab}(k) = <φ_{a}(k)|H|φ_{b}(k)>.
ket1 (list) – ket basis list, [[atom name, sublattice, rank, orbital]]
ket2 (list) – ket basis list, orbital@site.
- Returns:
(ndarray) – operator.
- sort_ket_matrix_dict(Or_dict, ket1, ket2)[source]#
Sort ket to align with the MultiPie definition (ket2).
- Parameters:
Or_dict (dict) – dictionary form of an arbitrary operator matrix in reak-space/k-space representation.
ket1 (list) – ket basis list, [[atom name, sublattice, rank, orbital]]
ket2 (list) – ket basis list, orbital@site.
- Returns:
(dict) – dictionary form of an arbitrary operator matrix.