Пример #1
0
def get_system_details(work, prefix):
    wannier_dir = os.path.join(work, prefix, "wannier")
    scf_path = os.path.join(wannier_dir, "scf.out")
    E_F = fermi_from_scf(scf_path)
    latVecs = _Angstrom_per_bohr * latVecs_from_scf(scf_path)
    D = latVecs.T
    R = 2.0 * np.pi * np.linalg.inv(D)

    K_lat = np.array([1 / 3, 1 / 3, 0.0])
    K_Cart = np.dot(K_lat, R)

    Hr = get_Hr(work, prefix)
    Hk = Hk_Cart(K_Cart, Hr, latVecs)

    Es, U = np.linalg.eigh(Hk)

    return latVecs, K_Cart, Hr, Es, U, E_F
Пример #2
0
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("--DFT_only",
                        action='store_true',
                        help="Use DFT bands only (no Wannier)")
    parser.add_argument("--fermi_shift",
                        action='store_true',
                        help="Shift plotted energies so that E_F = 0")
    parser.add_argument("--band_extrema",
                        action='store_true',
                        help="Add lines at VBM/CBM")
    parser.add_argument("--minE",
                        type=float,
                        default=None,
                        help="Minimum energy to plot")
    parser.add_argument("--maxE",
                        type=float,
                        default=None,
                        help="Maximum energy to plot")
    parser.add_argument("--plot_evecs",
                        action='store_true',
                        help="Plot eigenvector decomposition")
    parser.add_argument(
        "--num_layers",
        type=int,
        default=3,
        help="Number of layers (required if group_layer_* options given)")
    parser.add_argument(
        "--group_layer_evecs_soc",
        action='store_true',
        help="Group eigenvectors weights by layer, assuming SOC")
    parser.add_argument(
        "--group_layer_evecs_no_soc",
        action='store_true',
        help="Group eigenvectors weights by layer, assuming no SOC")
    parser.add_argument("--show",
                        action='store_true',
                        help="Show band plot instead of outputting file")
    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")

    E_F = fermi_from_scf(scf_path)
    if args.minE is not None and args.maxE is not None:
        if args.fermi_shift:
            minE_plot = E_F + args.minE
            maxE_plot = E_F + args.maxE
        else:
            minE_plot = args.minE
            maxE_plot = args.maxE
    else:
        minE_plot, maxE_plot = None, None

    alat = alat_from_scf(scf_path)
    latVecs = latVecs_from_scf(scf_path)

    if args.DFT_only:
        Hr = None
    else:
        Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(args.prefix))
        Hr = extractHr(Hr_path)

    bands_dir = os.path.join(work, "bands")
    bands_path = os.path.join(bands_dir, "{}_bands.dat".format(args.prefix))

    num_bands, num_ks, qe_bands = extractQEBands(bands_path)
    outpath = args.prefix

    if args.group_layer_evecs_soc:
        orbitals_per_X = 6
        orbitals_per_M = 10
        comp_groups = make_comp_groups(orbitals_per_X, orbitals_per_M,
                                       args.num_layers)
    elif args.group_layer_evecs_no_soc:
        orbitals_per_X = 3
        orbitals_per_M = 5
        comp_groups = make_comp_groups(orbitals_per_X, orbitals_per_M,
                                       args.num_layers)
    else:
        comp_groups = None

    plotBands(qe_bands,
              Hr,
              alat,
              latVecs,
              minE_plot,
              maxE_plot,
              outpath,
              show=args.show,
              symList=band_path_labels(),
              fermi_energy=E_F,
              plot_evecs=args.plot_evecs,
              comp_groups=comp_groups,
              fermi_shift=args.fermi_shift,
              plot_band_extrema=args.band_extrema)
Пример #3
0
                        default=None)
    parser.add_argument('--scf_path',
                        type=str,
                        help="Path to QE scf output file.",
                        default=None)
    parser.add_argument('--minE',
                        type=float,
                        help="Minimal energy to plot.",
                        default=None)
    parser.add_argument('--maxE',
                        type=float,
                        help="Maximum energy to plot.",
                        default=None)
    parser.add_argument('--show',
                        help="Show plot before writing file.",
                        action='store_true')
    args = parser.parse_args()

    if args.Hr_path is not None:
        nbnd, nks, evalsQE = extractQEBands(args.QE_path)
        print("QE eigenvalues loaded.")
        Hr = extractHr(args.Hr_path)
        print("Wannier Hamiltonian loaded.")
        alat = alat_from_scf(args.scf_path)
        latVecs = latVecs_from_scf(args.scf_path)
        plotBands(evalsQE, Hr, alat, latVecs, args.minE, args.maxE,
                  args.outPath, args.show)
    else:
        plotDFTBands(args.QE_path, args.outPath, args.minE, args.maxE,
                     args.show)
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
Пример #5
0
def _main():
    np.set_printoptions(threshold=np.inf)

    parser = argparse.ArgumentParser(
        "TMD multilayer response to electric field",
        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")
    parser.add_argument("--holes",
                        type=float,
                        default=8e12,
                        help="Hole concentration [cm^{-2}]")
    parser.add_argument("--screened",
                        action='store_true',
                        help="Include screening by holes")
    parser.add_argument(
        "--initial_mass",
        action='store_true',
        help=
        "Use effective mass at E_perp = 0, p = 0 instead of recalculating for each phi"
    )
    parser.add_argument(
        "--plot_initial",
        action='store_true',
        help=
        "Plot initial band structure with max applied field, before charge convergence"
    )
    args = parser.parse_args()

    if args.num_layers != 3:
        assert ("num_layers != 3 not implemented")

    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_base = fermi_from_scf(scf_path)
    latVecs = latVecs_from_scf(scf_path)
    R = 2 * np.pi * np.linalg.inv(latVecs.T)

    Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(args.prefix))
    Hr = extractHr(Hr_path)

    d_A = 6.488  # Angstrom
    d_bohr = _bohr_per_Angstrom * d_A

    hole_density_cm2 = args.holes
    hole_density_bohr2 = hole_density_cm2 / (10**8 * _bohr_per_Angstrom)**2

    #print("hole_density_bohr2")
    #print(hole_density_bohr2)

    # Choose initial potential assuming holes are distributed uniformally.
    sigma_layer_initial = (1 / 3) * _e_C * hole_density_bohr2

    sigmas_initial = sigma_layer_initial * np.array([1.0, 1.0, 1.0])
    #print("sigmas_initial [C/bohr^2]")
    #print(sigmas_initial)

    # Dielectric constant of WSe2:
    # Kim et al., ACS Nano 9, 4527 (2015).
    # http://pubs.acs.org/doi/abs/10.1021/acsnano.5b01114
    #epsilon_r = 7.2

    # Effective dielectric constant from DFT (LDA).
    # avg(K^high_{top - bottom}, Gamma_{top - bottom})
    epsilon_r = 7.87

    Pzs = get_layer_projections(wout_path, args.num_layers)

    E_V_nms = np.linspace(0.0, 1.2, 84)

    if args.plot_initial:
        E_V_bohr = E_V_nms[-1] / (10 * _bohr_per_Angstrom)
        phis_initial_max = get_phis(sigmas_initial, d_bohr, E_V_bohr,
                                    epsilon_r, args.screened)
        plot_H_k0_phis(H_k0s, phis_initial, Pzs, band_indices, E_F_base)
        return

    if hole_density_cm2 > 0.0:
        tol_abs = 1e-6 * sum(sigmas_initial)
    else:
        tol_abs = 1e-12 * _e_C

    tol_rel = 1e-6

    distr_args = []
    for E_V_nm in E_V_nms:
        distr_args.append([
            E_V_nm, R, Hr, latVecs, E_F_base, sigmas_initial, Pzs,
            hole_density_bohr2, d_bohr, epsilon_r, tol_abs, tol_rel,
            args.initial_mass, args.screened
        ])

    with Pool() as p:
        nh_Es = p.starmap(hole_distribution, distr_args)

    plot_results(nh_Es, hole_density_bohr2, hole_density_cm2, epsilon_r,
                 args.screened, E_V_nms)
def _main():
    parser = argparse.ArgumentParser(
        "Plot band structure for multiple electric field values",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("prefix_E_0",
                        type=str,
                        help="Prefix for E = 0 calculation")
    parser.add_argument("prefix_E_mid",
                        type=str,
                        help="Prefix for E != 0 calculation, middle value")
    parser.add_argument("prefix_E_high",
                        type=str,
                        help="Prefix for E != 0 calculation, high value")
    parser.add_argument(
        "--subdir",
        type=str,
        default=None,
        help="Subdirectory under work_base where calculation was run")
    parser.add_argument(
        "--minE",
        type=float,
        default=1.85,
        help="Minimum energy to plot (using original energy zero)")
    parser.add_argument(
        "--maxE",
        type=float,
        default=5.75,
        help="Maximum energy to plot (using original energy zero)")
    parser.add_argument("--load",
                        action='store_true',
                        help="Load stored band data instead of recalculating")
    args = parser.parse_args()

    E_mid_val = args.prefix_E_mid.split('_')[-1]
    E_high_val = args.prefix_E_high.split('_')[-1]

    Gamma_lat = np.array([0.0, 0.0, 0.0])
    M_lat = np.array([1 / 2, 0.0, 0.0])
    K_lat = np.array([1 / 3, 1 / 3, 0.0])
    band_path_lat = [Gamma_lat, M_lat, K_lat, Gamma_lat]
    band_path_labels = ["$\\Gamma$", "$M$", "$K$", "$\\Gamma$"]
    Nk_per_panel = 400

    prefixes = [args.prefix_E_0, args.prefix_E_mid, args.prefix_E_high]
    labels = [
        "$E = 0$", "$E = {}$ V/nm".format(E_mid_val),
        "$E = {}$ V/nm".format(E_high_val)
    ]
    styles = ['r-', 'b-.', 'k--']

    xs, special_xs, Emks = [], [], []
    if args.load:
        with open("Efield_bands.json", 'r') as fp:
            in_data = json.load(fp)

        xs, special_xs, Emks = list(
            map(lambda k: [d[k] for d in in_data],
                ["xs", "special_xs", "Emks"]))

        E_Gamma_Eperp_0 = in_data[0]["E_Gamma_Eperp_0"]
    else:
        out_data = []

        for prefix_index, prefix in enumerate(prefixes):
            work = _get_work(args.subdir, prefix)
            wannier_dir = os.path.join(work, "wannier")
            scf_path = os.path.join(wannier_dir, "scf.out")

            latVecs = latVecs_from_scf(scf_path)

            Hr_path = os.path.join(wannier_dir, "{}_hr.dat".format(prefix))
            Hr = extractHr(Hr_path)

            if prefix_index == 0:
                E_F = fermi_from_scf(scf_path)
                E_Gamma_Eperp_0 = get_E_Gamma(Hr, E_F)

            this_xs, this_special_xs, this_Emks = calculate_bands(
                Hr, latVecs, band_path_lat, Nk_per_panel)

            this_Emks = shift_Emks(this_Emks, E_Gamma_Eperp_0)

            xs.append(this_xs)
            special_xs.append(this_special_xs)
            Emks.append(this_Emks)

            out_data.append({
                "prefix": prefix,
                "xs": this_xs,
                "special_xs": this_special_xs,
                "band_path_labels": band_path_labels,
                "Emks": this_Emks,
                "E_Gamma_Eperp_0": E_Gamma_Eperp_0
            })

        with open("Efield_bands.json", 'w') as fp:
            json.dump(out_data, fp)

    full_min_x, full_max_x = 0.0, 1.0
    full_minE, full_maxE = args.minE - E_Gamma_Eperp_0, args.maxE - E_Gamma_Eperp_0

    print("full_minE = ", full_minE)
    print("full_maxE = ", full_maxE)

    for this_xs, this_Emks, path_suffix in zip(xs, Emks,
                                               ["0.0", "0.5", "1.0"]):
        out_path = "Efield_bands_E_{}.csv".format(path_suffix)
        write_bands_csv(this_xs, this_Emks, out_path)

    write_bands_aux(special_xs[0], band_path_labels, "Efield_bands_aux.csv")

    plot_bands([xs[0], xs[-1]], special_xs[0], band_path_labels,
               [Emks[0], Emks[-1]], [labels[0], labels[-1]],
               [styles[0], styles[-1]], [full_min_x, full_max_x],
               [full_minE, full_maxE], "full")

    x_K = special_xs[0][2]
    zoom_xlim = [x_K - 0.05, x_K + 0.05]
    zoom_special_xs = [zoom_xlim[0], x_K, zoom_xlim[-1]]
    zoom_band_path_labels = [
        "$\\leftarrow M$", "$K$", "$\\rightarrow \\Gamma$"
    ]
    zoom_ylim = [-0.3, 0.1]

    print("zoom_xlim = ", zoom_xlim)
    print("zoom_ylim = ", zoom_ylim)

    plot_bands(xs, zoom_special_xs, zoom_band_path_labels, Emks, labels,
               styles, zoom_xlim, zoom_ylim, "zoom")
Пример #7
0
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
Пример #8
0
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