def extract_Hk_vals(work, dps, soc): orbital_pairs = [("X2_X1p_z_z_uu_K", (1/3, 1/3, 0), ["X2", "pz", "up", "X1p", "pz", "up"]), ("X2_X1p_z_z_ud_K", (1/3, 1/3, 0), ["X2", "pz", "up", "X1p", "pz", "down"]), ("M_X1p_z2_z_uu_K", (1/3, 1/3, 0), ["M", "dz2", "up", "X1p", "pz", "up"]), ("M_X1p_z2_z_ud_K", (1/3, 1/3, 0), ["M", "dz2", "up", "X1p", "pz", "down"]), ("X2_Mp_z_z2_uu_K", (1/3, 1/3, 0), ["X2", "pz", "up", "Mp", "dz2", "up"]), ("X2_Mp_z_z2_ud_K", (1/3, 1/3, 0), ["X2", "pz", "up", "Mp", "dz2", "down"]), ("X2_X1p_z_z_uu_Kp", (-1/3, -1/3, 0), ["X2", "pz", "up", "X1p", "pz", "up"]), ("X2_X1p_z_z_ud_Kp", (-1/3, -1/3, 0), ["X2", "pz", "up", "X1p", "pz", "down"]), ("M_X1p_z2_z_uu_Kp", (-1/3, -1/3, 0), ["M", "dz2", "up", "X1p", "pz", "up"]), ("M_X1p_z2_z_ud_Kp", (-1/3, -1/3, 0), ["M", "dz2", "up", "X1p", "pz", "down"]), ("X2_Mp_z_z2_uu_Kp", (-1/3, -1/3, 0), ["X2", "pz", "up", "Mp", "dz2", "up"]), ("X2_Mp_z_z2_ud_Kp", (-1/3, -1/3, 0), ["X2", "pz", "up", "Mp", "dz2", "down"]), ("X2_X1p_z_z_uu_G", (0, 0, 0), ["X2", "pz", "up", "X1p", "pz", "up"]), ("X2_X1p_z_z_ud_G", (0, 0, 0), ["X2", "pz", "up", "X1p", "pz", "down"]), ("M_X1p_z2_z_uu_G", (0, 0, 0), ["M", "dz2", "up", "X1p", "pz", "up"]), ("M_X1p_z2_z_ud_G", (0, 0, 0), ["M", "dz2", "up", "X1p", "pz", "down"]), ("X2_Mp_z_z2_uu_G", (0, 0, 0), ["X2", "pz", "up", "Mp", "dz2", "up"]), ("X2_Mp_z_z2_ud_G", (0, 0, 0), ["X2", "pz", "up", "Mp", "dz2", "down"]), ("X2_X1p_z_z_uu_M", (1/2, 0, 0), ["X2", "pz", "up", "X1p", "pz", "up"]), ("X2_X1p_z_z_ud_M", (1/2, 0, 0), ["X2", "pz", "up", "X1p", "pz", "down"]), ("M_X1p_z2_z_uu_M", (1/2, 0, 0), ["M", "dz2", "up", "X1p", "pz", "up"]), ("M_X1p_z2_z_ud_M", (1/2, 0, 0), ["M", "dz2", "up", "X1p", "pz", "down"]), ("X2_Mp_z_z2_uu_M", (1/2, 0, 0), ["X2", "pz", "up", "Mp", "dz2", "up"]), ("X2_Mp_z_z2_ud_M", (1/2, 0, 0), ["X2", "pz", "up", "Mp", "dz2", "down"]), ("X2_X1p_z_z_uu_Mp", (-1/2, 0, 0), ["X2", "pz", "up", "X1p", "pz", "up"]), ("X2_X1p_z_z_ud_Mp", (-1/2, 0, 0), ["X2", "pz", "up", "X1p", "pz", "down"]), ("M_X1p_z2_z_uu_Mp", (-1/2, 0, 0), ["M", "dz2", "up", "X1p", "pz", "up"]), ("M_X1p_z2_z_ud_Mp", (-1/2, 0, 0), ["M", "dz2", "up", "X1p", "pz", "down"]), ("X2_Mp_z_z2_uu_Mp", (-1/2, 0, 0), ["X2", "pz", "up", "Mp", "dz2", "up"]), ("X2_Mp_z_z2_ud_Mp", (-1/2, 0, 0), ["X2", "pz", "up", "Mp", "dz2", "down"])] # has the structure {"val_label_1": [val1(d1), val1(d2), ...], # "val_label_2": [val2(d1), val2(d2), ...], ...} Hk_vals = {} for d, prefix in dps: Hr = get_Hr(work, prefix) atom_Hr_order = get_atom_order(work, prefix) for label, klat, orb_types in orbital_pairs: i_sym, i_orbital, i_spin = orb_types[0], orb_types[1], orb_types[2] j_sym, j_orbital, j_spin = orb_types[3], orb_types[4], orb_types[5] i_index = orbital_index(atom_Hr_order, i_sym, i_orbital, i_spin, soc) j_index = orbital_index(atom_Hr_order, j_sym, j_orbital, j_spin, soc) Hk = Hk_recip(klat, Hr) val = Hk[i_index, j_index] re_label, im_label = "{}_re".format(label), "{}_im".format(label) if re_label not in Hk_vals: Hk_vals[re_label] = [] if im_label not in Hk_vals: Hk_vals[im_label] = [] Hk_vals[re_label].append(val.real) Hk_vals[im_label].append(val.imag) return Hk_vals
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_extrema(work, prefix, k, k_prefix, num_layers, num_valence_bands, num_conduction_bands): wannier_dir = os.path.join(work, prefix, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") E_F = fermi_from_scf(scf_path) Hr = get_Hr(work, prefix) Hk = Hk_recip(k, Hr) Es, U = np.linalg.eigh(Hk) below_fermi, above_fermi = bracket_indices(Es, E_F) if num_layers != 2: raise ValueError( "get_layer_indices() unimplemented for num_layers != 2") layer_indices_up = get_layer_indices(work, prefix, 'up') layer_indices_down = get_layer_indices(work, prefix, 'down') layer_contribs_up = get_layer_contribs(layer_indices_up, U) layer_contribs_down = get_layer_contribs(layer_indices_down, U) extrema = {} def add_extrema_entries(i, band_index, vc_label): extrema["energy_{}_{}".format(vc_label, i)] = Es[band_index] for l in range(num_layers): layer_contrib = select_layer_contrib(layer_contribs_up, layer_contribs_down, None, l, band_index) extrema["contrib_layer_{}_{}_{}".format(l, vc_label, i)] = layer_contrib for spin in ['up', 'down']: spin_contrib = sum([ select_layer_contrib(layer_contribs_up, layer_contribs_down, spin, l, band_index) for l in range(num_layers) ]) extrema["contrib_spin_{}_{}_{}".format(spin, vc_label, i)] = spin_contrib for i, band_index in enumerate( range(below_fermi, below_fermi - num_valence_bands, -1)): add_extrema_entries(i, band_index, 'valence') for i, band_index in enumerate( range(above_fermi, above_fermi + num_conduction_bands)): add_extrema_entries(i, band_index, 'conduction') return extrema
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) 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) 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: base_orbitals = [ args.num_layers * 2 * orbitals_per_X + z * orbitals_per_M for z in range(args.num_layers) ] # Orbitals contributing to j = +5/2 state: x2y2_up = [base + 6 for base in base_orbitals] xy_up = [base + 8 for base in base_orbitals] x2y2_dn = [base + 7 for base in base_orbitals] xy_dn = [base + 9 for base in base_orbitals] num_top_bands = 2 * args.num_layers weights = [] for i in range(num_top_bands): weights.append([]) for k in ks: Hk = Hk_recip(k, Hr) Es, U = np.linalg.eigh(Hk) top = top_valence_indices(E_F, num_top_bands, Es) for i, band in enumerate(top): total = 0 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) for z, (n1_up, n2_up, n1_dn, n2_dn) in enumerate(zip(x2y2_up, xy_up, x2y2_dn, xy_dn)): # Appropriate arrangement for K. # TODO - swap for -K. # U[n, i] = <n|i> --> <i|n> = U[n, i].conjugate() if z % 2 == 0: evec_comp = ( 1 / np.sqrt(2)) * (U[n1_dn, band].conjugate() - 1j * U[n2_dn, band].conjugate()) else: evec_comp = ( 1 / np.sqrt(2)) * (U[n1_up, band].conjugate() + 1j * U[n2_up, band].conjugate()) total += abs(evec_comp)**2 weights[i].append(1 - total) for i, band_weights in enumerate(weights): plt.plot(xs, band_weights, label="Band {}".format(i)) plt.legend(loc=0) plt.xlabel("k / K", fontsize='large') plt.ylabel("Weight outside l_z = +/- 2, up/down group") plt.savefig("model_weights_K.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) 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 _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 get_gaps(work, prefix, layer_threshold, k, spin_valence=None, spin_conduction=None, use_curvature=True): wannier_dir = os.path.join(work, prefix, "wannier") scf_path = os.path.join(wannier_dir, "scf.out") E_F = fermi_from_scf(scf_path) alat_Bohr = alat_from_scf(scf_path) D = D_from_scf(scf_path) R = 2*np.pi*np.linalg.inv(D) k_Cart = np.dot(np.array(k), R) layer_indices_up = get_layer_indices(work, prefix, 'up') layer_indices_down = get_layer_indices(work, prefix, 'down') Hr = get_Hr(work, prefix) # note: # rotated K 2pi/3: K_R2 = (-2/3, 1/3, 0.0) # rotated K 4pi/3: K_R4 = (1/3, -2/3, 0.0) Hk = Hk_recip(k, Hr) w, U = np.linalg.eigh(Hk) conduction, valence = layer_band_extrema(w, U, E_F, layer_indices_up, layer_indices_down, layer_threshold, spin_valence, spin_conduction) conduction_curvature = [None, None] valence_curvature = [None, None] for l in [0, 1]: valence_curvature[l] = get_curvature(D, Hr, k_Cart, valence[l]) conduction_curvature[l] = get_curvature(D, Hr, k_Cart, conduction[l]) gaps = {} layer_labels = ["0", "1"] # Generate gap for each layer pair. Keys have the form: "(0, 1)/(0, 1)". for cond_layer_index, cond_layer_label in enumerate(layer_labels): for valence_layer_index, valence_layer_label in enumerate(layer_labels): k = "{}/{}".format(cond_layer_label, valence_layer_label) gaps[k] = float(w[conduction[cond_layer_index]] - w[valence[valence_layer_index]]) # Generate band extremum energy for each choice of layer and valence or conduction. vc_labels = ["valence", "conduction"] all_vc_data = [valence, conduction] for vc_label, vc_data in zip(vc_labels, all_vc_data): for layer_index, layer_label in enumerate(layer_labels): k = "{}_{}".format(layer_label, vc_label) gaps[k] = float(w[vc_data[layer_index]]) # Minimum of the spin-orbit split partner of the lowest conduction band. # If layer gap is smaller than SO splitting, need to skip a band to find partner. conduction_min = min(conduction[0], conduction[1]) if abs(conduction[0] - conduction[1]) == 1: conduction_min_partner = conduction_min + 2 else: conduction_min_partner = conduction_min + 1 gaps["conduction_min_partner"] = float(w[conduction_min_partner]) if use_curvature: add_curvature(gaps, valence_curvature, conduction_curvature, alat_Bohr) return gaps
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 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