def print_orbital_weights_dm_K(subdir, prefix): num_layers = 3 assert (num_layers == 3) # != 3 unimplemented work = _get_work(subdir, prefix) wannier_dir = os.path.join(work, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") wout_path = os.path.join(wannier_dir, "{}.wout".format(prefix)) E_F = fermi_from_scf(scf_path) layer_orbitals = get_layer_orbitals(wout_path, num_layers) Pzs = get_layer_projections(wout_path, num_layers) Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(prefix)) Hr = extractHr(Hr_path) K_lat = np.array([1 / 3, 1 / 3, 0.0]) H_TB_K = Hk_recip(K_lat, Hr) Es, U = np.linalg.eigh(H_TB_K) top = top_valence_indices(E_F, 2 * num_layers, Es) layer_weights, layer_basis = get_layer_basis_from_dm_K(U, top, Pzs) dm_basis_weights = [ get_state_weights(layer_orbitals, s) for s in layer_basis ] print("dm basis weights") print(dm_basis_weights)
def print_orbital_weights_eigenstates_Gamma(subdir, prefix): num_layers = 3 assert (num_layers == 3) # != 3 unimplemented work = _get_work(subdir, prefix) wannier_dir = os.path.join(work, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") wout_path = os.path.join(wannier_dir, "{}.wout".format(prefix)) E_F = fermi_from_scf(scf_path) layer_orbitals = get_layer_orbitals(wout_path, num_layers) Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(prefix)) Hr = extractHr(Hr_path) Gamma_lat = np.array([0.0, 0.0, 0.0]) H_TB_Gamma = Hk_recip(Gamma_lat, Hr) Es, U = np.linalg.eigh(H_TB_Gamma) top = top_valence_indices(E_F, 2 * num_layers, Es) eigenstate_weights = [ get_state_weights(layer_orbitals, U[:, [t]]) for t in top ] print("eigenstate weights") print(eigenstate_weights)
def get_E_Gamma(Hr, E_F): Gamma_lat = np.array([0.0, 0.0, 0.0]) this_Hk = Hk_recip(Gamma_lat, Hr) Es = np.linalg.eigvalsh(this_Hk) top_Gamma_index = top_valence_indices(E_F, 1, Es)[0] return Es[top_Gamma_index]
def plot_orbital_weights_K(subdir, prefix): num_layers = 3 assert (num_layers == 3) # != 3 unimplemented work = _get_work(subdir, prefix) wannier_dir = os.path.join(work, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") wout_path = os.path.join(wannier_dir, "{}.wout".format(prefix)) E_F = fermi_from_scf(scf_path) layer_orbitals = get_layer_orbitals(wout_path, num_layers) Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(prefix)) Hr = extractHr(Hr_path) K_lat = np.array([1 / 3, 1 / 3, 0.0]) H_TB_K = Hk_recip(K_lat, Hr) Es, U = np.linalg.eigh(H_TB_K) top = top_valence_indices(E_F, 2 * num_layers, Es) eigenstate_weights = [ get_state_weights(layer_orbitals, U[:, [t]]) for t in top ] state_indices = [0, 0, 1, 1, 2, 2] labels = [ r"$s_1$; $(+, \uparrow)$", r"$s_1$; $(-, \downarrow)$", r"$s_2$; $(+, \uparrow)$", r"$s_2$; $(-, \downarrow)$", r"$s_3$; $(+, \uparrow)$", r"$s_3$; $(-, \downarrow)$" ] weight_keys = [ "(+, up)", "(-, down)", "(+, up)", "(-, down)", "(+, up)", "(-, down)" ] syms = ["D", "D", "o", "o", "s", "s"] colors = ["black", "red", "black", "red", "black", "red"] vals = [] for state_index, label, key, sym, color in zip(state_indices, labels, weight_keys, syms, colors): vals.append([]) for layer_index in range(num_layers): vals[-1].append(eigenstate_weights[state_index][key][layer_index]) plt.plot(range(num_layers), vals[-1], "k{}".format(sym), markerfacecolor=(1, 1, 1, 0.0), markeredgecolor=color, label=label, markersize=10) plt.xlim(0 - 0.1, num_layers - 1 + 0.1) plt.ylim(0, 1) plt.legend(loc=0) plt.savefig("{}_state_components.png".format(prefix), bbox_inches='tight', dpi=500)
def get_H_k0s(R, Hr, latVecs, E_F_base): Gamma_cart = np.array([0.0, 0.0, 0.0]) K_lat = np.array([1 / 3, 1 / 3, 0.0]) K_cart = np.dot(K_lat, R) Kprime_cart = -K_cart k0s = [Gamma_cart, K_cart, Kprime_cart] H_k0s, band_indices = [], [] def Hfn(k0, q): return Hk(q + k0, Hr, latVecs) k0_num_orbitals = [2, 3, 3] for k0, num_orbitals in zip(k0s, k0_num_orbitals): H_k0s.append(partial(Hfn, k0)) Es, U = np.linalg.eigh(H_k0s[-1](np.array([0.0, 0.0, 0.0]))) top = top_valence_indices(E_F_base, num_orbitals, Es) band_indices.append(top) return k0s, H_k0s, band_indices
def _main(): np.set_printoptions(threshold=np.inf) parser = argparse.ArgumentParser( "Plot band structure", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("prefix", type=str, help="Prefix for calculation") parser.add_argument( "--subdir", type=str, default=None, help="Subdirectory under work_base where calculation was run") parser.add_argument("--num_layers", type=int, default=3, help="Number of layers") args = parser.parse_args() work = _get_work(args.subdir, args.prefix) wannier_dir = os.path.join(work, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") wout_path = os.path.join(wannier_dir, "{}.wout".format(args.prefix)) E_F = fermi_from_scf(scf_path) Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(args.prefix)) Hr = extractHr(Hr_path) K = np.array([1 / 3, 1 / 3, 0.0]) reduction_factor = 0.7 num_ks = 100 ks = vec_linspace(K, reduction_factor * K, num_ks) xs = np.linspace(1, reduction_factor, num_ks) assert (Hr[(0, 0, 0)][0].shape[0] == get_total_orbitals(args.num_layers)) Pzs = get_layer_projections(wout_path, args.num_layers) spin_operators = Pauli_over_full_basis(get_total_orbitals(args.num_layers)) num_top_bands = 2 * args.num_layers deviations, proj_overlaps, spins = [], [], [] spins_non_layer_renormalized = [] for z in range(len(Pzs)): deviations.append([]) proj_overlaps.append([]) spins.append([]) spins_non_layer_renormalized.append([]) for k in ks: print("k = {}".format(k)) for z, Pz in enumerate(Pzs): Hk = Hk_recip(k, Hr) Es, U = np.linalg.eigh(Hk) top = top_valence_indices(E_F, num_top_bands, Es) print("top orbitals = ", top, "energies = ", [Es[t] for t in top]) proj_dms = [] # "dm" == density matrix kz_spins = [] kz_spins_non_layer_renormalized = [] for restricted_index_n, band_n in enumerate(top): state_n = U[:, [band_n]] print("orbital", band_n) for i, v in enumerate(state_n[:, 0]): print(i, v) dm_n = density_matrix([state_n], [1]) proj_dm = np.dot(Pz, np.dot(dm_n, Pz)) proj_dms.append(proj_dm) kz_spins.append(expectation_normalized(proj_dm, spin_operators)) kz_spins_non_layer_renormalized.append([ np.trace(np.dot(proj_dm, sigma)) for sigma in spin_operators ]) spins[z].append(kz_spins) spins_non_layer_renormalized[z].append( kz_spins_non_layer_renormalized) proj_overlap = np.zeros([num_top_bands, num_top_bands], dtype=np.complex128) for restricted_index_np in range(len(top)): for restricted_index_n in range(len(top)): dm_np, dm_n = proj_dms[restricted_index_np], proj_dms[ restricted_index_n] dm_np_norm = dm_np / np.trace(dm_np) dm_n_norm = dm_n / np.trace(dm_n) print( "np, n, Tr rho_np^z, Tr rho_n^z, Tr rho_np^z rho_n^z", restricted_index_np, restricted_index_n, np.trace(dm_np), np.trace(dm_n), np.trace(np.dot(dm_np, dm_n))) proj_overlap[restricted_index_np, restricted_index_n] = np.trace( np.dot(dm_np_norm, dm_n_norm)) print("z = {}".format(z)) print("overlap = ") print(proj_overlap) # proj_overlap should be real. eps_abs = 1e-12 assert (all([x.imag < eps_abs for x in np.nditer(proj_overlap)])) # Compute deviation from desired 'all ones' value of proj_overlap. deviation = sum([abs(1 - x) for x in np.nditer(proj_overlap)]) print("sum of abs(deviation) = {}".format(deviation)) proj_overlaps[z].append(proj_overlap) deviations[z].append(deviation) # Plot deviation from 1-band-per-layer representability. for z in range(len(Pzs)): plt.plot(xs, deviations[z], label="deviations for layer {}".format(z)) plt.legend(loc=0) plt.savefig("{}_deviation_separability_K.png".format(args.prefix), bbox_inches='tight', dpi=500) plt.clf() # Plot layer-projected band overlaps. for z in range(len(Pzs)): for ip, i in [(0, 1), (1, 2), (0, 2)]: ys = [v[ip, i].real for v in proj_overlaps[z]] plt.plot(xs, ys, label="({}, {}) overlap".format(ip, i)) plt.legend(loc=0) plt.savefig("{}_overlap_z_{}_separability_K.png".format( args.prefix, z), bbox_inches='tight', dpi=500) plt.clf() # Plot layer-projected spin expectation values. for z in range(len(Pzs)): colors = ['k', 'g', 'b'] styles = ['-', '--', '.'] for band_n, style in zip([0, 1, 2], styles): for (spin_index, spin_dir), color in zip(enumerate(['x', 'y', 'z']), colors): ys = [ spins[z][k][band_n][spin_index].real for k in range(num_ks) ] plt.plot(xs, ys, '{}{}'.format(color, style), label="Band {} spin {}".format(band_n, spin_dir)) plt.legend(loc=0) plt.savefig("{}_z_{}_spin_real.png".format(args.prefix, z), bbox_inches='tight', dpi=500) plt.clf() for band_n, style in zip([0, 1, 2], styles): for (spin_index, spin_dir), color in zip(enumerate(['x', 'y', 'z']), colors): ys = [ spins[z][k][band_n][spin_index].imag for k in range(num_ks) ] plt.plot(xs, ys, '{}{}'.format(color, style), label="Band {} spin {}".format(band_n, spin_dir)) plt.legend(loc=0) plt.savefig("{}_z_{}_spin_imag.png".format(args.prefix, z), bbox_inches='tight', dpi=500) plt.clf() # Plot sum of spin expectation values over layers. colors = ['k', 'g', 'b'] styles = ['-', '--', '.'] for (spin_index, spin_dir), color in zip(enumerate(['x', 'y', 'z']), colors): for band_n, style in zip([0, 1, 2], styles): ys = np.zeros([num_ks], dtype=np.float64) for z in range(len(Pzs)): ys += np.array([ spins_non_layer_renormalized[z][k][band_n][spin_index].real for k in range(num_ks) ]) plt.plot(xs, ys, '{}{}'.format(color, style), label="Band {} spin {}".format(band_n, spin_dir)) plt.legend(loc=0) plt.savefig("{}_z_total_spin_real.png".format(args.prefix), bbox_inches='tight', dpi=500) plt.clf()
def make_effective_Hamiltonian_Gamma(subdir, prefix, top_two_only, verbose=False): num_layers = 3 work = _get_work(subdir, prefix) wannier_dir = os.path.join(work, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") wout_path = os.path.join(wannier_dir, "{}.wout".format(prefix)) E_F = fermi_from_scf(scf_path) latVecs = latVecs_from_scf(scf_path) alat_Bohr = 1.0 R = 2 * np.pi * np.linalg.inv(latVecs.T) Gamma_cart = np.array([0.0, 0.0, 0.0]) K_lat = np.array([1 / 3, 1 / 3, 0.0]) K_cart = np.dot(K_lat, R) if verbose: print(K_cart) print(latVecs) upto_factor = 0.3 num_ks = 100 ks = vec_linspace(Gamma_cart, upto_factor * K_cart, num_ks) xs = np.linspace(0.0, upto_factor, num_ks) Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(prefix)) Hr = extractHr(Hr_path) if top_two_only: Pzs = [np.eye(get_total_orbitals(num_layers))] else: Pzs = get_layer_projections(wout_path, num_layers) H_TB_Gamma = Hk(Gamma_cart, Hr, latVecs) Es, U = np.linalg.eigh(H_TB_Gamma) if top_two_only: top = top_valence_indices(E_F, 2, Es) else: top = top_valence_indices(E_F, 2 * num_layers, Es) layer_weights, layer_basis = get_layer_basis_Gamma(U, top, Pzs, verbose) complement_basis_mat = nullspace(array_with_rows(layer_basis).conjugate()) complement_basis = [] for i in range(complement_basis_mat.shape[1]): v = complement_basis_mat[:, [i]] complement_basis.append(v / np.linalg.norm(v)) assert (len(layer_basis) + len(complement_basis) == 22 * num_layers) for vl in [v.conjugate().T for v in layer_basis]: for vc in complement_basis: assert (abs(np.dot(vl, vc)[0, 0]) < 1e-12) # 0th order effective Hamiltonian: H(Gamma) in layer basis. H_layer_Gamma = layer_Hamiltonian_0th_order(H_TB_Gamma, layer_basis) #E_repr = sum([Es[t] for t in top]) / len(top) E_repr = Es[top[0]] H_correction = correction_Hamiltonian_0th_order(Gamma_cart, Hr, latVecs, E_repr, complement_basis, layer_basis) H0_tot = H_layer_Gamma + H_correction H_PQ = correction_Hamiltonian_PQ(K_cart, Hr, latVecs, complement_basis, layer_basis) # Momentum expectation values <z_{lp}| dH/dk_{c}|_Gamma |z_l> ps = layer_Hamiltonian_ps(Gamma_cart, Hr, latVecs, layer_basis) ps_correction = correction_Hamiltonian_ps(Gamma_cart, Hr, latVecs, E_repr, complement_basis, layer_basis) ps_tot = deepcopy(ps) for i, v in enumerate(ps_correction): ps_tot[i] += v # Inverse effective masses <z_{lp}| d^2H/dk_{cp}dk_{c}|_Gamma |z_l> mstar_invs = layer_Hamiltonian_mstar_inverses(Gamma_cart, Hr, latVecs, layer_basis) mstar_invs_correction_base, mstar_invs_correction_other = correction_Hamiltonian_mstar_inverses( Gamma_cart, Hr, latVecs, E_repr, complement_basis, layer_basis) mstar_inv_tot = deepcopy(mstar_invs) for mstar_contrib in [ mstar_invs_correction_base, mstar_invs_correction_other ]: for k, v in mstar_contrib.items(): mstar_inv_tot[k] += v if verbose: print("H0") print(H_layer_Gamma) print("H_correction") print(H_correction) print("H_correction max") print(abs(H_correction).max()) print("H_PQ max") print(abs(H_PQ).max()) print("p") print(ps) print("ps max") print(max([abs(x).max() for x in ps])) print("ps correction") print(ps_correction) print("ps_correction max") print(max([abs(x).max() for x in ps_correction])) print("mstar_inv") print(mstar_invs) print("mstar_inv max") print(max([abs(v).max() for k, v in mstar_invs.items()])) print("mstar_inv_correction_base") print(mstar_invs_correction_base) print("mstar_inv_correction_base max") print( max([abs(v).max() for k, v in mstar_invs_correction_base.items()])) print("mstar_inv_correction_other") print(mstar_invs_correction_other) print("mstar_inv_correction_other max") print( max([abs(v).max() for k, v in mstar_invs_correction_other.items()])) # Fit quality plots. H_layers = [] for k in ks: q = k - Gamma_cart H_layers.append( H_kdotp(q, H_layer_Gamma, H_correction, ps, ps_correction, mstar_invs, mstar_invs_correction_base, mstar_invs_correction_other)) Emks, Umks = [], [] for band_index in range(len(layer_basis)): Emks.append([]) Umks.append([]) for k_index, Hk_layers in enumerate(H_layers): Es_layers, U_layers = np.linalg.eigh(Hk_layers) #print(k_index) #print("U", U) for band_index in range(len(layer_basis)): Emks[band_index].append(Es_layers) Umks[band_index].append(U_layers) for band_index in range(len(layer_basis)): plt.plot(xs, Emks[band_index]) TB_Emks = [] for m in range(len(top)): TB_Emks.append([]) for k in ks: this_H_TB_k = Hk(k, Hr, latVecs) this_Es, this_U = np.linalg.eigh(this_H_TB_k) for m, i in enumerate(top): TB_Emks[m].append(this_Es[i]) for TB_Em in TB_Emks: plt.plot(xs, TB_Em, 'k.') plt.show() # Effective masses. print("effective mass, top valence band, TB model: m^*_{xx; yy; xy}") print( effective_mass_band(lambda k: Hk(k, Hr, latVecs), Gamma_cart, top[0], alat_Bohr)) print( "effective mass, top valence band, k dot p model: m^*_{xx; yy; xy}" ) print( effective_mass_band( lambda k: H_kdotp(k - Gamma_cart, H_layer_Gamma, H_correction, ps, ps_correction, mstar_invs, mstar_invs_correction_base, mstar_invs_correction_other), Gamma_cart, len(layer_basis) - 1, alat_Bohr)) # Elements contributing to crossover scale. t_Gamma_a = H0_tot[0, 2] t_Gamma_b = H0_tot[0, 3] print("t_Gamma_a, t_Gamma_b") print(t_Gamma_a, t_Gamma_b) print("norm(t_Gamma_a)") print(abs(t_Gamma_a)) print("[t_Gamma]_{2, 4}, [t_Gamma]_{2, 5}") print(H0_tot[2, 4], H0_tot[2, 5]) t_Gamma_direct = H0_tot[0, 4] print("t_Gamma_direct, norm(t_Gamma_direct)") print(t_Gamma_direct, abs(t_Gamma_direct)) print("E_SL_Gamma") print([H0_tot[i, i] for i in range(6)]) print("H0_tot") print(H0_tot) Gamma_valence_max = Es[top[0]] print("H0") print_H0_LaTeX(H_layer_Gamma, Gamma_valence_max) print("H0_tot") print_H0_LaTeX(H0_tot, Gamma_valence_max) dump_model_np("{}_model_Gamma".format(prefix), H0_tot, ps_tot, mstar_inv_tot) return H0_tot, ps_tot, mstar_inv_tot
def _main(): parser = argparse.ArgumentParser( "Plot band structure", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("prefix", type=str, help="Prefix for calculation") parser.add_argument( "--subdir", type=str, default=None, help="Subdirectory under work_base where calculation was run") parser.add_argument( "--num_layers", type=int, default=3, help="Number of layers (required if group_layer_* options given)") args = parser.parse_args() if args.num_layers != 3: raise ValueError("mirror check not implemented for num_layers != 3") work = _get_work(args.subdir, args.prefix) wannier_dir = os.path.join(work, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") E_F = fermi_from_scf(scf_path) Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(args.prefix)) Hr = extractHr(Hr_path) Gamma = np.array([0.0, 0.0, 0.0]) K = np.array([1 / 3, 1 / 3, 0.0]) max_K_factor = 0.3 num_ks = 2 ks = vec_linspace(Gamma, max_K_factor * K, num_ks) xs = np.linspace(0.0, max_K_factor, num_ks) basis = basis_state_labels(args.num_layers) M = mirror_op() # Assume SOC present and that model has 2*3 X(p) orbitals per layer # and 2*5 M(d) in canonical Wannier90 order. # Assumes atoms are ordered with all Xs first, then all Ms, and within # M/X groups the atoms are in layer order. orbitals_per_X = 6 orbitals_per_M = 10 # Base index for orbitals of each layer: X_base_orbitals = [ z * orbitals_per_X for z in range(1, 2 * args.num_layers - 1) ] M_base_orbitals = [ args.num_layers * 2 * orbitals_per_X + z * orbitals_per_M for z in range(args.num_layers) ] pz_up = [n for n in X_base_orbitals] pz_dn = [n + 1 for n in X_base_orbitals] dz2_up = [n for n in M_base_orbitals] dz2_dn = [n + 1 for n in M_base_orbitals] #print(pz_up) #print(pz_dn) #print(dz2_up) #print(dz2_dn) orbital_group = list(itertools.chain(pz_up, pz_dn, dz2_up, dz2_dn)) num_top_bands = 2 * args.num_layers weights = [] for i in range(num_top_bands): weights.append([]) for k in ks: print("k = ", k) Hk = Hk_recip(k, Hr) Es, U = np.linalg.eigh(Hk) top = top_valence_indices(E_F, num_top_bands, Es) print("top valence", top, [Es[t] for t in top]) mirror_signs = [1, 1, -1, -1, 1, 1] for i, band in enumerate(top): state = U[:, band] mirror_eval = np.dot(state.conjugate().T, np.dot(M, state))[0, 0] print("band {}; mirror <v|M|v> = {}".format(band, mirror_eval)) print("mirror deviation elements") Mdev = np.dot(M, state) - mirror_signs[i] * state for n, v in enumerate(Mdev): if abs(v)**2 > 1e-3: print(n, basis[n], v, abs(v)**2) print("band, orb, orb_label, weight, evec comp") #for n, v in enumerate(state): # if abs(v)**2 > 1e-2: # print(band, n, basis[n], abs(v)**2, v) for n, v in enumerate(state): print(band, n, basis[n], abs(v)**2, v) total = 0 for n in orbital_group: evec_comp = U[n, band].conjugate() total += abs(evec_comp)**2 #print(total) weights[i].append(1 - total) #for i, band_weights in enumerate(weights): # plt.plot(xs, band_weights, label="Band {}".format(i)) plt.plot(xs, weights[0], 'b.', label="Band 0") plt.plot(xs, weights[1], 'g--', label="Band 1") plt.legend(loc=0) plt.xlabel("k / K", fontsize='large') plt.ylabel("Weight outside inner p_z, dz^2") plt.savefig("model_weights_Gamma.png", bbox_inches='tight', dpi=500)
def _main(): np.set_printoptions(threshold=np.inf) parser = argparse.ArgumentParser( "Plot band structure", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("prefix", type=str, help="Prefix for calculation") parser.add_argument( "--subdir", type=str, default=None, help="Subdirectory under work_base where calculation was run") parser.add_argument("--num_layers", type=int, default=3, help="Number of layers") args = parser.parse_args() work = _get_work(args.subdir, args.prefix) wannier_dir = os.path.join(work, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") wout_path = os.path.join(wannier_dir, "{}.wout".format(args.prefix)) E_F = fermi_from_scf(scf_path) Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(args.prefix)) Hr = extractHr(Hr_path) Gamma = np.array([0.0, 0.0, 0.0]) K = np.array([1 / 3, 1 / 3, 0.0]) upto_factor = 0.3 num_ks = 100 ks = vec_linspace(Gamma, upto_factor * K, num_ks) xs = np.linspace(0.0, upto_factor, num_ks) assert (Hr[(0, 0, 0)][0].shape[0] == get_total_orbitals(args.num_layers)) Pzs = get_layer_projections(wout_path, args.num_layers) num_top_bands = 2 * args.num_layers for k in ks: print("k = {}".format(k)) Hk = Hk_recip(k, Hr) Es, U = np.linalg.eigh(Hk) top = top_valence_indices(E_F, num_top_bands, Es) print("top orbitals = ", top, "energies = ", [Es[t] for t in top]) tb_states = [] for restricted_index_n, band_n in enumerate(top): state_n = U[:, [band_n]] print("orbital", band_n) for i, v in enumerate(state_n[:, 0]): print(i, v) tb_states.append(state_n) dm = density_matrix(tb_states, [1] * len(tb_states)) for z, Pz in enumerate(Pzs): print("z = {}".format(z)) proj_dm = np.dot(Pz, np.dot(dm, Pz)) proj_dm_evals, proj_dm_evecs = np.linalg.eigh(proj_dm) print("proj_dm_evals") print(proj_dm_evals) print("proj_dm_evecs") for i in range(proj_dm_evecs.shape[1]): for j in range(proj_dm_evecs.shape[0]): print(j, proj_dm_evecs[j, i])
def get_occupations(prefix, subdir, screened, d_bohr, hole_density_bohr2, sigmas_initial, epsilon_r): work = _get_work(subdir, prefix) wannier_dir = os.path.join(work, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") wout_path = os.path.join(wannier_dir, "{}.wout".format(prefix)) E_F = fermi_from_scf(scf_path) latVecs = latVecs_from_scf(scf_path) alat_Bohr = 1.0 R = 2 * np.pi * np.linalg.inv(latVecs.T) Gamma_cart = np.array([0.0, 0.0, 0.0]) K_lat = np.array([1 / 3, 1 / 3, 0.0]) K_cart = np.dot(K_lat, R) Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(prefix)) Hr = extractHr(Hr_path) H_TB_Gamma = Hk(Gamma_cart, Hr, latVecs) Es_Gamma, U_Gamma = np.linalg.eigh(H_TB_Gamma) H_TB_K = Hk(K_cart, Hr, latVecs) Es_K, U_K = np.linalg.eigh(H_TB_K) top_Gamma = top_valence_indices(E_F, 2, Es_Gamma) top_K = top_valence_indices(E_F, 3, Es_Gamma) assert (top_Gamma == [41, 40]) assert (top_K == [41, 40, 39]) E_top_Gamma, E_top_K = Es_Gamma[top_Gamma[0]], Es_K[top_K[0]] Ediff = E_top_Gamma - E_top_K def Hfn(k): return Hk(k, Hr, latVecs) mstar_top_Gamma = effective_mass_band(Hfn, Gamma_cart, top_Gamma[0], alat_Bohr) mstar_top_K = effective_mass_band(Hfn, K_cart, top_K[0], alat_Bohr) mstar_Gamma = mstar_top_Gamma[0] mstar_K = mstar_top_K[0] num_layers = 3 Pzs = get_layer_projections(wout_path, num_layers) if hole_density_bohr2 > 0.0: tol_abs = 1e-6 * sum(sigmas_initial) else: tol_abs = 1e-12 * _e_C tol_rel = 1e-6 nh_Gamma, nh_K, E_Gamma, E_K = hole_distribution(0.0, R, Hr, latVecs, E_F, sigmas_initial, Pzs, hole_density_bohr2, d_bohr, epsilon_r, tol_abs, tol_rel, screened=screened) if hole_density_bohr2 > 0.0: nh_Gamma_frac = nh_Gamma / hole_density_bohr2 nh_K_frac = nh_K / hole_density_bohr2 else: nh_Gamma_frac = 0.0 nh_K_frac = 0.0 return Ediff, mstar_Gamma, mstar_K, nh_Gamma_frac, nh_K_frac, E_Gamma, E_K
def make_effective_Hamiltonian_K(k0_lat, subdir, prefix, get_layer_basis, verbose=False): num_layers = 3 work = _get_work(subdir, prefix) wannier_dir = os.path.join(work, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") wout_path = os.path.join(wannier_dir, "{}.wout".format(prefix)) E_F = fermi_from_scf(scf_path) latVecs = latVecs_from_scf(scf_path) alat_Bohr = 1.0 R = 2 * np.pi * np.linalg.inv(latVecs.T) K_cart = np.dot(k0_lat, R) if verbose: print(K_cart) print(latVecs) reduction_factor = 0.7 num_ks = 100 ks = vec_linspace(K_cart, reduction_factor * K_cart, num_ks) xs = np.linspace(1, reduction_factor, num_ks) Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(prefix)) Hr = extractHr(Hr_path) Pzs = get_layer_projections(wout_path, num_layers) H_TB_K = Hk(K_cart, Hr, latVecs) Es, U = np.linalg.eigh(H_TB_K) top = top_valence_indices(E_F, 2 * num_layers, Es) layer_weights, layer_basis = get_layer_basis(U, top, Pzs, verbose) complement_basis_mat = nullspace(array_with_rows(layer_basis).conjugate()) complement_basis = [] for i in range(complement_basis_mat.shape[1]): v = complement_basis_mat[:, [i]] complement_basis.append(v / np.linalg.norm(v)) assert (len(layer_basis) + len(complement_basis) == 22 * num_layers) for vl in [v.conjugate().T for v in layer_basis]: for vc in complement_basis: assert (abs(np.dot(vl, vc)[0, 0]) < 1e-12) # 0th order effective Hamiltonian: H(K) in layer basis. H_layer_K = layer_Hamiltonian_0th_order(H_TB_K, layer_basis) #E_repr = sum([Es[t] for t in top]) / len(top) E_repr = Es[top[0]] H_correction = correction_Hamiltonian_0th_order(K_cart, Hr, latVecs, E_repr, complement_basis, layer_basis) H0_tot = H_layer_K + H_correction H_PQ = correction_Hamiltonian_PQ(K_cart, Hr, latVecs, complement_basis, layer_basis) # Momentum expectation values <z_{lp}| dH/dk_{c}|_K |z_l> ps = layer_Hamiltonian_ps(K_cart, Hr, latVecs, layer_basis) ps_correction = correction_Hamiltonian_ps(K_cart, Hr, latVecs, E_repr, complement_basis, layer_basis) ps_tot = deepcopy(ps) for i, v in enumerate(ps_correction): ps_tot[i] += v # Inverse effective masses <z_{lp}| d^2H/dk_{cp}dk_{c}|_K |z_l> mstar_invs = layer_Hamiltonian_mstar_inverses(K_cart, Hr, latVecs, layer_basis) mstar_invs_correction_base, mstar_invs_correction_other = correction_Hamiltonian_mstar_inverses( K_cart, Hr, latVecs, E_repr, complement_basis, layer_basis) mstar_inv_tot = deepcopy(mstar_invs) for mstar_contrib in [ mstar_invs_correction_base, mstar_invs_correction_other ]: for k, v in mstar_contrib.items(): mstar_inv_tot[k] += v if verbose: print("H0") print(H_layer_K) print("H_correction") print(H_correction) print("H_correction max") print(abs(H_correction).max()) print("H_PQ max") print(abs(H_PQ).max()) print("ps") print(ps) print("ps max") print(max([abs(x).max() for x in ps])) print("ps correction") print(ps_correction) print("ps_correction max") print(max([abs(x).max() for x in ps_correction])) print("mstar_inv") print(mstar_invs) print("mstar_inv max") print(max([abs(v).max() for k, v in mstar_invs.items()])) print("mstar_inv_correction_base") print(mstar_invs_correction_base) print("mstar_inv_correction_base max") print( max([abs(v).max() for k, v in mstar_invs_correction_base.items()])) print("mstar_inv_correction_other") print(mstar_invs_correction_other) print("mstar_inv_correction_other max") print( max([abs(v).max() for k, v in mstar_invs_correction_other.items()])) # Fit quality plots. H_layers = [] for k in ks: q = k - K_cart H_layers.append( H_kdotp(q, H_layer_K, H_correction, ps, ps_correction, mstar_invs, mstar_invs_correction_base, mstar_invs_correction_other)) Emks, Umks = [], [] for band_index in range(len(layer_basis)): Emks.append([]) Umks.append([]) for k_index, Hk_layers in enumerate(H_layers): Es, U = np.linalg.eigh(Hk_layers) #print(k_index) #print("U", U) for band_index in range(len(layer_basis)): Emks[band_index].append(Es) Umks[band_index].append(U) for band_index in range(len(layer_basis)): plt.plot(xs, Emks[band_index]) TB_Emks = [] for m in range(len(top)): TB_Emks.append([]) for k in ks: this_H_TB_k = Hk(k, Hr, latVecs) this_Es, this_U = np.linalg.eigh(this_H_TB_k) for m, i in enumerate(top): TB_Emks[m].append(this_Es[i]) for TB_Em in TB_Emks: plt.plot(xs, TB_Em, 'k.') plt.show() plt.clf() # Effective masses. print( "effective mass, top valence band, TB model: m^*_{xx; yy; xy} / m_e" ) mstar_TB = effective_mass_band(lambda k: Hk(k, Hr, latVecs), K_cart, top[0], alat_Bohr) print(mstar_TB) print( "effective mass, top valence band, k dot p model: m^*_{xx; yy; xy} / m_e" ) mstar_kdotp = effective_mass_band( lambda k: H_kdotp(k - K_cart, H_layer_K, H_correction, ps, ps_correction, mstar_invs, mstar_invs_correction_base, mstar_invs_correction_other), K_cart, len(layer_basis) - 1, alat_Bohr) print(mstar_kdotp) # Elements contributing to crossover scale. t_K = H0_tot[1, 2] t_K_25 = H0_tot[2, 5] Delta_K = H0_tot[1, 1] - H0_tot[2, 2] lambda_SO = H0_tot[1, 1] - H0_tot[0, 0] t_K_direct = H0_tot[1, 5] print("t_K, Delta_K, lambda_SO") print(t_K, Delta_K, lambda_SO) print("t_K_25") print(t_K_25) print("norm(t_K), norm(t_K_25)") print(abs(t_K), abs(t_K_25)) print("t_K_direct, norm(t_K_direct)") print(t_K_direct, abs(t_K_direct)) print("E_SL_K top") print([H0_tot[i, i] for i in [1, 3, 5]]) print("E_SL_K bottom") print([H0_tot[i, i] for i in [0, 2, 4]]) # Elements contributing to effective dielectric constant. print("Layer on-site energy differences:") print( "Top group of bands: middle layer - bottom layer; top layer - middle layer" ) print(H0_tot[3, 3] - H0_tot[1, 1], H0_tot[5, 5] - H0_tot[3, 3]) print( "Bottom group of bands: middle layer - bottom layer; top layer - middle layer" ) print(H0_tot[2, 2] - H0_tot[0, 0], H0_tot[4, 4] - H0_tot[2, 2]) H_TB_Gamma = Hk_recip(np.array([0.0, 0.0, 0.0]), Hr) Es_Gamma, U_Gamma = np.linalg.eigh(H_TB_Gamma) Gamma_valence_max = Es_Gamma[top[0]] print("H0") print_H0_LaTeX(H_layer_K, Gamma_valence_max) print("H0_tot") print_H0_LaTeX(H0_tot, Gamma_valence_max) dump_model_np("{}_model_K".format(prefix), H0_tot, ps_tot, mstar_inv_tot) phases = {(i, j): cmath.phase(H0_tot[i, j]) for i, j in [(0, 3), (1, 2), (2, 5), (3, 4)]} phase_factors = list( map(lambda x: np.exp(-1j * x), [ -phases[(0, 3)], -phases[(1, 2)], 0.0, 0.0, phases[(3, 4)], phases[(2, 5)] ])) phase_U = np.diag(phase_factors) H0_tot_real_hop = np.dot(phase_U.conjugate().T, np.dot(H0_tot, phase_U)) print("H0_tot_real_hop") print_H0_LaTeX(H0_tot_real_hop, Gamma_valence_max) return H0_tot, ps_tot, mstar_inv_tot