Пример #1
0
def plot_enc_convergence(directory="../vasp/examples/SiOptb88/",
                         plot=False,
                         filename="."):
    """
    Plot convergence for plane-wave cut-off data
    Works only if jobs run through jarvis-tools framework
    
    Args:
       directory: parent directory for job run
    Returns:
           matplotlib object, converged cut-off value
    """

    x = []
    y = []
    for a in glob.glob(str(directory) + str("/*.json")):
        if "MAIN-RELAX" in a:
            main_inc = str(a.split(".json")[0]) + str("/") + str("INCAR")
            main_inc_obj = Incar.from_file(main_inc)
            convg_encut = float(main_inc_obj["ENCUT"])
        elif "ENCUT" in a:
            run = str(a.split(".json")[0]) + str("/") + str("vasprun.xml")
            contcar = Structure.from_file((a.split(".json")[0]) + str("/") +
                                          str("CONTCAR"))
            vrun = Vasprun(run)
            infile = str(a.split(".json")[0]) + str("/") + str("INCAR")
            inc = Incar.from_file(infile)
            encut = inc["ENCUT"]
            en = float(
                vrun.final_energy)  # /float(contcar.composition.num_atoms)
            x.append(encut)
            y.append(en)
    order = np.argsort(x)
    xs = np.array(x)[order]
    ys = np.array(y)[order]
    plt = get_publication_quality_plot(14, 10)
    plt.ylabel("Energy (eV)")
    plt.plot(xs, ys, "s-", linewidth=2, markersize=10)
    plt.xlabel("Increment in ENCUT ")
    ax = plt.gca()
    ax.get_yaxis().get_major_formatter().set_useOffset(False)
    plt.title(str("Converged at ") + str(int(convg_encut)) + str("eV"),
              fontsize=26)
    # filename=str('Encut.png')
    plt.tight_layout()
    if plot == True:
        plt.savefig(filename)
        plt.close()

    return plt, convg_encut
Пример #2
0
    def plot(self, ax=None):
        """Plots the simulated electron diffraction pattern with a logarithmic
        intensity scale.

        Run `.show()` on the result of this method to display the plot.

        Parameters
        ----------
        ax : :obj:`matplotlib.axes.Axes`, optional
            A `matplotlib` axes instance. Used if the plot needs to be in a
            figure that has been created elsewhere.

        """
        if ax is None:
            plt = get_publication_quality_plot(10, 10)
            ax = plt.gca()
        ax.scatter(self.coordinates[:, 0],
                   self.coordinates[:, 1],
                   s=np.log10(self.intensities))
        ax.set_xlabel("Reciprocal Dimension ($A^{-1}$)")
        ax.set_ylabel("Reciprocal Dimension ($A^{-1}$)")
        return ax
Пример #3
0
def bandstr(vrun="", kpfile="", filename=".", plot=False):
    """
    Plot electronic bandstructure
 
    Args:
        vrun: path to vasprun.xml
        kpfile:path to line mode KPOINTS file 
    Returns:
           matplotlib object
    """

    run = Vasprun(vrun, parse_projected_eigen=True)
    bands = run.get_band_structure(kpfile, line_mode=True, efermi=run.efermi)
    bsp = BSPlotter(bands)
    zero_to_efermi = True
    bandgap = str(round(bands.get_band_gap()["energy"], 3))
    # print "bg=",bandgap
    data = bsp.bs_plot_data(zero_to_efermi)
    plt = get_publication_quality_plot(12, 8)
    plt.close()
    plt.clf()
    band_linewidth = 3
    x_max = data["distances"][-1][-1]
    # print (x_max)
    for d in range(len(data["distances"])):
        for i in range(bsp._nb_bands):
            plt.plot(
                data["distances"][d],
                [
                    data["energy"][d]["1"][i][j]
                    for j in range(len(data["distances"][d]))
                ],
                "b-",
                linewidth=band_linewidth,
            )
            if bsp._bs.is_spin_polarized:
                plt.plot(
                    data["distances"][d],
                    [
                        data["energy"][d]["-1"][i][j]
                        for j in range(len(data["distances"][d]))
                    ],
                    "r--",
                    linewidth=band_linewidth,
                )
    bsp._maketicks(plt)
    if bsp._bs.is_metal():
        e_min = -10
        e_max = 10
        band_linewidth = 3

    for cbm in data["cbm"]:
        plt.scatter(cbm[0], cbm[1], color="r", marker="o", s=100)

        for vbm in data["vbm"]:
            plt.scatter(vbm[0], vbm[1], color="g", marker="o", s=100)

    plt.xlabel(r"$\mathrm{Wave\ Vector}$", fontsize=30)
    ylabel = (
        r"$\mathrm{E\ -\ E_f\ (eV)}$" if zero_to_efermi else r"$\mathrm{Energy\ (eV)}$"
    )
    plt.ylabel(ylabel, fontsize=30)
    plt.ylim(-4, 4)
    plt.xlim(0, x_max)
    plt.tight_layout()
    if plot == True:
        plt.savefig(filename, img_format="png")
        plt.close()

    return plt
Пример #4
0
def plot_kp_convergence(
    directory="../vasp/examples/SiOptb88/", plot=False, filename="."
):
    """
    Plot convergence for k-points data
    Works only if jobs run through jarvis-tools framework
    
    Args:
       directory: parent directory for job run
    Returns:
           matplotlib object, converged k-points value
    """

    x = []
    y = []
    for a in glob.glob(str(directory) + str("/*.json")):
        if "MAIN-RELAX" in a:
            main_kp = str(a.split(".json")[0]) + str("/") + str("KPOINTS")
            main_kp_obj = Kpoints.from_file(main_kp)
            [k1, k2, k3] = main_kp_obj.kpts[0]
        elif "KPOINT" in a:
            k = int(float(str(a.split("-")[-1]).split(".json")[0]))
            run = str(a.split(".json")[0]) + str("/") + str("vasprun.xml")
            vrun = Vasprun(run)

            kpfile = str(a.split(".json")[0]) + str("/") + str("KPOINTS")
            contcar = Structure.from_file(
                (a.split(".json")[0]) + str("/") + str("CONTCAR")
            )
            kpoints = Kpoints.from_file(kpfile)
            [xx, yy, zz] = kpoints.kpts[0]
            en = float(vrun.final_energy)  # /float(contcar.composition.num_atoms)
            # en =float(vrun.final_energy)/float(contcar.composition.num_atoms)
            # print "ENERGYYY,AT",en,float(contcar.composition.num_atoms)
            x.append(k)
            y.append(en)

    order = np.argsort(x)
    xs = np.array(x)[order]
    ys = np.array(y)[order]
    len_xs = len(xs)
    xs1 = []
    ys1 = []
    target_ys = ys[-1]
    # print "target=",target_ys
    for i, el in enumerate(ys):
        if el <= (float(target_ys) + 0.002):
            xs1.append(xs[i])
            ys1.append(ys[i])
    # print "xs,ys=",xs,ys
    # print "xs1,ys1=",xs1,ys1
    left, bottom, width, height = [0.5, 0.5, 0.35, 0.35]
    plt = get_publication_quality_plot(14, 10)
    fig, ax1 = plt.subplots()
    plt.xlabel("Increment in K point", fontsize=20)
    plt.ylabel("Energy (eV)", fontsize=20)
    plt.title(
        str("Converged at ")
        + str(k1)
        + str("x")
        + str(k2)
        + str("x")
        + str(k3)
        + str(" ")
        + str("Automatic Mesh ")
        + str(max(x) - 25),
        fontsize=14,
    )
    plt.xticks(fontsize=20)
    plt.yticks(fontsize=20)
    ax2 = fig.add_axes([left, bottom, width, height])
    # ax2.plot(xs1,ys1, '.-',linewidth=2,markersize=10)
    ax1.plot(xs, ys, "s-", linewidth=2, markersize=10)
    el_list = sorted(list(contcar.symbol_set))
    search = "-".join([item for item in el_list])
    # ax1.xlabel('Increment in K point')
    # print "xs,ys"
    # print xs
    # print ys
    plt.plot(xs1, ys1, ".-", linewidth=2, markersize=10)
    plt.ylim([float(target_ys) + 0.002, float(target_ys) - 0.002])
    ax = plt.gca()
    ax.get_yaxis().get_major_formatter().set_useOffset(False)
    filename = str("KDen.png")
    k_convg = str(xx) + str("x") + str(yy) + str("x") + str(zz)
    plt.tight_layout()
    if plot == True:
        plt.savefig(filename)
        plt.close()
    return plt, k_convg
Пример #5
0
def plot_dos(vrun="", low_lim=-5, up_lim=10, filename=".", extra="", plot=False):
    """
    Plot total density of states

    Args:
       vrun: vasprun.xml path
       low_lim: lower energy limit in eV
       up_lim: upper energy limit in eV
    Returns:
          matplotlib objects for
          total, orbital and element project density of states
    """

    run = Vasprun(vrun, occu_tol=1e-2)
    complete_dos = run.complete_dos
    totup = complete_dos.get_densities(spin=Spin.up)
    totdn = complete_dos.get_densities(spin=Spin.down)
    en = complete_dos.energies
    bandgap = str(run.eigenvalue_band_properties[0])
    ef = complete_dos.efermi
    en[:] = [x - ef for x in en]

    plt1 = get_publication_quality_plot(14, 10)
    # plt1.close()
    # plt1.clf()
    plt1.xlabel("Energies (eV)")
    plt1.ylabel("Tot. DOS (arb. unit.)")
    plt1.plot(en, totup, "b", linewidth=3)
    plt1.plot(en, -totdn, "r", linewidth=3)
    plt1.xlim(low_lim, up_lim)
    plt1.tight_layout()
    if plot == True:
        tmp = str(filename) + str("/TDos") + str(extra) + str(".png")
        plt1.savefig(tmp)

    spd_dos = complete_dos.get_spd_dos()
    sdosup = spd_dos[OrbitalType.s].densities[Spin.up]
    pdosup = spd_dos[OrbitalType.p].densities[Spin.up]
    ddosup = spd_dos[OrbitalType.d].densities[Spin.up]
    sdosdn = spd_dos[OrbitalType.s].densities[Spin.down]
    pdosdn = spd_dos[OrbitalType.p].densities[Spin.down]
    ddosdn = spd_dos[OrbitalType.d].densities[Spin.down]

    plt2 = get_publication_quality_plot(14, 10)
    # plt2.close()
    # plt2.clf()
    plt2.plot(en, sdosup, "r", linewidth=3, label="s")
    plt2.plot(en, -sdosdn, "r", linewidth=3)
    plt2.plot(en, pdosup, "g", linewidth=3, label="p")
    plt2.plot(en, -pdosdn, "g", linewidth=3)
    plt2.plot(en, ddosup, "b", linewidth=3, label="d")
    plt2.plot(en, -ddosdn, "b", linewidth=3)
    plt2.xlabel("Energies (eV)")
    plt2.ylabel("Orb. DOS (arb. unit.)")
    plt2.legend(prop={"size": 26})
    plt2.xlim(low_lim, up_lim)
    plt2.tight_layout()
    if plot == True:
        tmp = str(filename) + str("/Dos") + str(extra) + str(".png")
        plt2.savefig(tmp)

    plt3 = get_publication_quality_plot(14, 10)
    # plt3.close()
    # plt3.clf()
    elt_dos = complete_dos.get_element_dos()
    at_symbs = set(run.atomic_symbols)
    for i, sym in enumerate(at_symbs):
        elt = elt_dos[Element(sym)]
        # color = cmap(float(i)/len(at_symbs))
        if i == 0:
            color = "b"
        elif i == 1:
            color = "g"
        elif i == 2:
            color = "r"
        elif i == 3:
            color = "c"
        elif i == 4:
            color = "m"
        elif i == 5:
            color = "y"
        elif i == 6:
            color = "k"
        else:
            color = "k"
            print("Use different color scheme")

        plt3.plot(en, elt.densities[Spin.up], color=color, linewidth=3, label=sym)
        plt3.plot(en, -elt.densities[Spin.down], color=color, linewidth=3)
        plt3.xlabel("Energies (eV)")
        plt3.ylabel("Elm. DOS (arb. unit.)")
        plt3.legend(prop={"size": 26})
        plt3.xlim(low_lim, up_lim)
        plt3.tight_layout()
    if plot == True:
        tmp = str(filename) + str("/EDos") + str(extra) + str(".png")
        plt3.savefig(tmp)

    return plt1, plt2, plt3
Пример #6
0
def IP_optics(vrun="", filename=".", extra="", plot=False):
    """
    Optoelectronic properties derived from dielectric function 

    See http://www.wien2k.at/reg_user/textbooks/WIEN2k_lecture-notes_2013/optic_handout.pdf
    http://www.phys.ufl.edu/~tanner/Wooten-OpticalPropertiesOfSolids-2up.pdf

    Args:
       vrun: path to vasprun.xml
    Reurns:
          info: dictionary with optoelectronic information
          energy: energy bins generally 0 to 40 eV
          real_part: real part of dielectric function
          imag_part: imaginary part of dielectric function
          absorption: absorption coefficient in cm^-1
       
    TODO: shorten the code with multi-dimensional np array   
    """

    info = {}

    storedir = filename

    run = Vasprun(vrun, occu_tol=1e-2)
    erange = len(run.dielectric[0])
    en = []
    realx = []
    imagx = []
    absorpx = []
    refrx = []
    reflx = []
    eelsx = []
    extcx = []
    opt_conx = []
    realy = []
    imagy = []
    absorpy = []
    refry = []
    refly = []
    eelsy = []
    extcy = []
    opt_cony = []
    realz = []
    imagz = []
    absorpz = []
    refrz = []
    reflz = []
    eelsz = []
    extcz = []
    opt_conz = []
    H = 4.13566733 * (10**(-15))
    # c0=2.99792458
    c0 = 2.99792458 * (math.pow(10, 8))
    for i in range(0, erange - 1):
        en.append(run.dielectric[0][i])
        realx.append(run.dielectric[1][i][0])
        imagx.append(run.dielectric[2][i][0])
        ab_valx = 1.4142 * ((float(run.dielectric[0][i]) / float(H)) * (float(
            math.sqrt(-run.dielectric[1][i][0] + math.sqrt(
                (run.dielectric[2][i][0]) * (run.dielectric[2][i][0]) +
                (run.dielectric[1][i][0]) *
                (run.dielectric[1][i][0])))) / float(float(c0) * 100.0)))
        absorpx.append(ab_valx)
        refr_valx = float(
            math.sqrt((run.dielectric[1][i][0]) +
                      math.sqrt((run.dielectric[2][i][0]) *
                                (run.dielectric[2][i][0]) +
                                (run.dielectric[1][i][0]) *
                                (run.dielectric[1][i][0])))) / float(1.4142)
        refrx.append(refr_valx)
        eels_valx = float(
            run.dielectric[2][i][0]) / float((run.dielectric[2][i][0]) *
                                             (run.dielectric[2][i][0]) +
                                             (run.dielectric[1][i][0]) *
                                             (run.dielectric[1][i][0]))
        eelsx.append(eels_valx)
        extc_valx = float(
            math.sqrt(-(run.dielectric[1][i][0]) +
                      math.sqrt((run.dielectric[2][i][0]) *
                                (run.dielectric[2][i][0]) +
                                (run.dielectric[1][i][0]) *
                                (run.dielectric[1][i][0])))) / float(1.4142)
        extcx.append(extc_valx)
        refl_valx = ((refr_valx - 1) *
                     (refr_valx - 1) + extc_valx * extc_valx) / (
                         (refr_valx + 1) *
                         (refr_valx + 1) + extc_valx * extc_valx)
        reflx.append(refl_valx)
        opt_valx = (float(float(run.dielectric[0][i]) / float(H)) /
                    float(4 * math.pi) * (run.dielectric[2][i][0]))
        opt_conx.append(opt_valx)

        realy.append(run.dielectric[1][i][1])
        imagy.append(run.dielectric[2][i][1])

        ab_valy = 1.4142 * ((float(run.dielectric[0][i]) / float(H)) * (float(
            math.sqrt(-run.dielectric[1][i][1] + math.sqrt(
                (run.dielectric[2][i][1]) * (run.dielectric[2][i][1]) +
                (run.dielectric[1][i][1]) *
                (run.dielectric[1][i][1])))) / float(float(c0) * 100.0)))
        absorpy.append(ab_valy)
        refr_valy = float(
            math.sqrt((run.dielectric[1][i][1]) +
                      math.sqrt((run.dielectric[2][i][1]) *
                                (run.dielectric[2][i][1]) +
                                (run.dielectric[1][i][1]) *
                                (run.dielectric[1][i][1])))) / float(1.4142)
        refry.append(refr_valy)
        eels_valy = float(
            run.dielectric[2][i][1]) / float((run.dielectric[2][i][1]) *
                                             (run.dielectric[2][i][1]) +
                                             (run.dielectric[1][i][1]) *
                                             (run.dielectric[1][i][1]))
        eelsy.append(eels_valy)
        extc_valy = float(
            math.sqrt(-(run.dielectric[1][i][1]) +
                      math.sqrt((run.dielectric[2][i][1]) *
                                (run.dielectric[2][i][1]) +
                                (run.dielectric[1][i][1]) *
                                (run.dielectric[1][i][1])))) / float(1.4142)
        extcy.append(extc_valy)
        refl_valy = ((refr_valy - 1) *
                     (refr_valy - 1) + extc_valy * extc_valy) / (
                         (refr_valy + 1) *
                         (refr_valy + 1) + extc_valy * extc_valy)
        refly.append(refl_valy)
        opt_valy = (float(float(run.dielectric[0][i]) / float(H)) /
                    float(4 * math.pi) * (run.dielectric[2][i][1]))
        opt_cony.append(opt_valy)

        realz.append(run.dielectric[1][i][2])
        imagz.append(run.dielectric[2][i][2])

        ab_valz = 1.4142 * ((float(run.dielectric[0][i]) / float(H)) * (float(
            math.sqrt(-run.dielectric[1][i][2] + math.sqrt(
                (run.dielectric[2][i][2]) * (run.dielectric[2][i][2]) +
                (run.dielectric[1][i][2]) *
                (run.dielectric[1][i][2])))) / float(float(c0) * 100.0)))
        absorpz.append(ab_valz)
        refr_valz = float(
            math.sqrt((run.dielectric[1][i][2]) +
                      math.sqrt((run.dielectric[2][i][2]) *
                                (run.dielectric[2][i][2]) +
                                (run.dielectric[1][i][2]) *
                                (run.dielectric[1][i][2])))) / float(1.4142)
        refrz.append(refr_valz)
        eels_valz = float(
            run.dielectric[2][i][2]) / float((run.dielectric[2][i][2]) *
                                             (run.dielectric[2][i][2]) +
                                             (run.dielectric[1][i][2]) *
                                             (run.dielectric[1][i][2]))
        eelsz.append(eels_valz)
        extc_valz = float(
            math.sqrt(-(run.dielectric[1][i][2]) +
                      math.sqrt((run.dielectric[2][i][2]) *
                                (run.dielectric[2][i][2]) +
                                (run.dielectric[1][i][2]) *
                                (run.dielectric[1][i][2])))) / float(1.4142)
        extcz.append(extc_valz)
        refl_valz = ((refr_valz - 1) *
                     (refr_valz - 1) + extc_valz * extc_valz) / (
                         (refr_valz + 1) *
                         (refr_valz + 1) + extc_valz * extc_valz)
        reflz.append(refl_valz)
        opt_valz = (float(float(run.dielectric[0][i]) / float(H)) /
                    float(4 * math.pi) * (run.dielectric[2][i][2]))
        opt_conz.append(opt_valz)

    if plot == True:
        # plt.close()
        plt = get_publication_quality_plot(14, 10)
        plt.plot(en, realx, linewidth=2, label=r"$\epsilon_1x$")
        plt.plot(en, realy, linewidth=2, label=r"$\epsilon_1y$")
        plt.plot(en, realz, linewidth=2, label=r"$\epsilon_1z$")
        plt.legend(prop={"size": 26})
        plt.xlim([0, 30])
        plt.xlabel("Energy (eV)")
        plt.ylabel("Dielec. function (Real part)")
        filename = str(storedir) + str("/") + str("Real") + str(extra) + str(
            ".png")
        plt.tight_layout()
        plt.savefig(filename)
        plt.tight_layout()
        plt.close()

        plt.clf()
        plt = get_publication_quality_plot(14, 10)
        plt.plot(en, imagx, linewidth=2, label=r"$\epsilon_2x$")
        plt.plot(en, imagy, linewidth=2, label=r"$\epsilon_2y$")
        plt.plot(en, imagz, linewidth=2, label=r"$\epsilon_2z$")
        plt.xlabel("Energy (eV)")
        plt.xlim([0, 30])
        plt.ylabel("Dielec. function(Imag part)")
        filename = str(storedir) + str("/") + str("Imag") + str(extra) + str(
            ".png")
        plt.tight_layout()
        plt.legend(prop={"size": 26})
        plt.savefig(filename)
        plt.close()

        plt.clf()
        plt = get_publication_quality_plot(14, 10)
        plt.plot(en, refrx, linewidth=2, label=r"$n_x$")
        plt.plot(en, refry, linewidth=2, label=r"$n_y$")
        plt.plot(en, refrz, linewidth=2, label=r"$n_z$")
        plt.xlim([0, 30])
        plt.xlabel("Energy (eV)")
        plt.ylabel("Refractive index")
        filename = str(storedir) + str("/") + str("Refr") + str(extra) + str(
            ".png")
        plt.tight_layout()
        plt.legend(prop={"size": 26})
        plt.savefig(filename)
        plt.close()

        plt.clf()
        plt = get_publication_quality_plot(14, 10)
        plt.plot(en, extcx, linewidth=2, label=r"$k_x$")
        plt.plot(en, extcy, linewidth=2, label=r"$k_y$")
        plt.plot(en, extcz, linewidth=2, label=r"$k_z$")
        plt.xlim([0, 30])
        plt.xlabel("Energy (eV)")
        plt.ylabel("Extinction Coefficient")
        filename = str(storedir) + str("/") + str("Extc") + str(extra) + str(
            ".png")
        plt.tight_layout()
        plt.legend(prop={"size": 26})
        plt.savefig(filename)
        plt.tight_layout()
        plt.close()

        plt.clf()
        plt = get_publication_quality_plot(14, 10)
        plt.plot(en, absorpx, linewidth=2, label=r"$\alpha_x$")
        plt.plot(en, absorpy, linewidth=2, label=r"$\alpha_y$")
        plt.plot(en, absorpz, linewidth=2, label=r"$\alpha_z$")
        plt.xlim([0, 30])
        plt.xlabel("Energy (eV)")
        plt.ylabel("Absorption coefficient")
        filename = str(storedir) + str("/") + str("Absorp") + str(extra) + str(
            ".png")
        plt.tight_layout()
        plt.legend(prop={"size": 26})
        plt.savefig(filename)
        plt.tight_layout()
        plt.close()

        plt.clf()
        plt = get_publication_quality_plot(14, 10)
        plt.plot(en, eelsx, linewidth=2, label=r"$e_x$")
        plt.plot(en, eelsy, linewidth=2, label=r"$e_y$")
        plt.plot(en, eelsz, linewidth=2, label=r"$e_z$")
        plt.xlim([0, 30])
        plt.xlabel("Energy (eV)")
        plt.ylabel("Energy loss spectrum")
        filename = str(storedir) + str("/") + str("ELS") + str(extra) + str(
            ".png")
        plt.tight_layout()
        plt.legend(prop={"size": 26})
        plt.savefig(filename)
        plt.tight_layout()
        plt.close()

        plt.clf()
        plt = get_publication_quality_plot(14, 10)
        plt.plot(en, opt_conx, linewidth=2, label=r"$\sigma_x$")
        plt.plot(en, opt_cony, linewidth=2, label=r"$\sigma_y$")
        plt.plot(en, opt_conz, linewidth=2, label=r"$\sigma_z$")
        plt.xlim([0, 30])
        plt.xlabel("Energy (eV)")
        plt.ylabel("Optical conductivity (Real part)")
        filename = str(storedir) + str("/") + str("Opt_con") + str(
            extra) + str(".png")
        plt.tight_layout()
        plt.legend(prop={"size": 26})
        plt.savefig(filename)
        plt.tight_layout()
        plt.close()

    info["absorption"] = [absorpx, absorpy, absorpz]
    info["energy"] = en
    info["real_part"] = [realx, realy, realz]
    info["imag_part"] = [imagx, imagy, imagz]
    info["refr_index"] = [refrx, refry, refrz]
    info["extinc"] = [extcx, extcy, extcz]
    info["reflectance"] = [reflx, refly, reflz]
    info["EELS"] = [eelsx, eelsy, eelsz]
    info["opt_conduct"] = [opt_conx, opt_cony, opt_conz]
    print(info["real_part"][0][0])
    return info