Ejemplo n.º 1
0
def abicomp_ebands(options):
    """
    Plot electron bands on a grid.
    """
    paths, e0 = options.paths, options.e0
    plotter = abilab.ElectronBandsPlotter(key_ebands=[(os.path.relpath(p), p) for p in paths])

    if options.ipython:
        import IPython
        IPython.embed(header=str(plotter) + "\nType `plotter` in the terminal and use <TAB> to list its methods",
                      plotter=plotter)

    elif options.notebook:
        plotter.make_and_open_notebook(daemonize=not options.no_daemon)

    else:
        # Print pandas Dataframe.
        frame = plotter.get_ebands_frame()
        abilab.print_frame(frame)

        # Optionally, print info on gaps and their location
        if not options.verbose:
            print("\nUse --verbose for more information")
        else:
            for ebands in plotter.ebands_list:
                print(ebands)

        # Here I select the plot method to call.
        if options.plot_mode != "None":
            plotfunc = getattr(plotter, options.plot_mode, None)
            if plotfunc is None:
                raise ValueError("Don't know how to handle plot_mode: %s" % options.plot_mode)
            plotfunc(e0=e0)

    return 0
Ejemplo n.º 2
0
    def test_interpolator(self):
        """Test QP interpolation."""
        # Get quasiparticle results from the SIGRES.nc database.
        sigres = abilab.abiopen(
            abidata.ref_file("si_g0w0ppm_nband30_SIGRES.nc"))

        # Interpolate QP corrections and apply them on top of the KS band structures.
        # QP band energies are returned in r.qp_ebands_kpath and r.qp_ebands_kmesh.

        # Just to test call without ks_ebands.
        r = sigres.interpolate(lpratio=5,
                               ks_ebands_kpath=None,
                               ks_ebands_kmesh=None,
                               verbose=0,
                               filter_params=[1.0, 1.0],
                               line_density=10)

        r = sigres.interpolate(
            lpratio=5,
            ks_ebands_kpath=abidata.ref_file("si_nscf_GSR.nc"),
            ks_ebands_kmesh=abidata.ref_file("si_scf_GSR.nc"),
            verbose=0,
            filter_params=[1.0, 1.0],
            line_density=10)

        assert r.qp_ebands_kpath is not None
        assert r.qp_ebands_kpath.kpoints.is_path
        #print(r.qp_ebands_kpath.kpoints.ksampling, r.qp_ebands_kpath.kpoints.mpdivs_shifts)
        assert r.qp_ebands_kpath.kpoints.mpdivs_shifts == (None, None)

        assert r.qp_ebands_kmesh is not None
        assert r.qp_ebands_kmesh.kpoints.is_ibz
        assert r.qp_ebands_kmesh.kpoints.ksampling is not None
        assert r.qp_ebands_kmesh.kpoints.is_mpmesh
        qp_mpdivs, qp_shifts = r.qp_ebands_kmesh.kpoints.mpdivs_shifts
        assert qp_mpdivs is not None
        assert qp_shifts is not None
        ks_mpdivs, ks_shifts = r.ks_ebands_kmesh.kpoints.mpdivs_shifts
        self.assert_equal(qp_mpdivs, ks_mpdivs)
        self.assert_equal(qp_shifts, ks_shifts)

        # Get DOS from interpolated energies.
        ks_edos = r.ks_ebands_kmesh.get_edos()
        qp_edos = r.qp_ebands_kmesh.get_edos()

        r.qp_ebands_kmesh.to_bxsf(self.get_tmpname(text=True))

        # Plot the LDA and the QPState band structure with matplotlib.
        plotter = abilab.ElectronBandsPlotter()
        plotter.add_ebands("LDA", r.ks_ebands_kpath, dos=ks_edos)
        plotter.add_ebands("GW (interpolated)", r.qp_ebands_kpath, dos=qp_edos)

        if self.has_matplotlib():
            assert plotter.combiplot(title="Silicon band structure",
                                     show=False)
            assert plotter.gridplot(title="Silicon band structure", show=False)

        sigres.close()
Ejemplo n.º 3
0
    def test_scissors_polyfit(self):
        """Testing scissors from SIGRES file."""
        # Get the quasiparticle results from the SIGRES.nc database.
        with abilab.abiopen(abidata.ref_file(
                "si_g0w0ppm_nband30_SIGRES.nc")) as sigma_file:
            qplist_spin = sigma_file.qplist_spin

        # Construct the scissors operator
        domains = [[-10, 6.1], [6.1, 18]]
        scissors = qplist_spin[0].build_scissors(domains, bounds=None)
        #scissors = qplist_spin[0].build_scissors(domains, bounds=None, plot=True)

        # Read the KS band energies computed on the k-path
        with abilab.abiopen(abidata.ref_file("si_nscf_GSR.nc")) as nc:
            ks_bands = nc.ebands

        # Read the KS band energies computed on the Monkhorst-Pack (MP) mesh
        # and compute the DOS with the Gaussian method
        with abilab.abiopen(abidata.ref_file("si_scf_GSR.nc")) as nc:
            ks_mpbands = nc.ebands
        ks_dos = ks_mpbands.get_edos()

        # Apply the scissors operator first on the KS band structure
        # along the k-path then on the energies computed with the MP mesh.
        qp_bands = ks_bands.apply_scissors(scissors)
        qp_mpbands = ks_mpbands.apply_scissors(scissors)

        # Compute the DOS with the modified QPState energies.
        qp_dos = qp_mpbands.get_edos()

        # Plot the LDA and the QPState band structure with matplotlib.
        if self.has_matplotlib():
            plotter = abilab.ElectronBandsPlotter()
            plotter.add_ebands("LDA", ks_bands, edos=ks_dos)
            plotter.add_ebands("LDA+scissors(e)", qp_bands, edos=qp_dos)

            # By default, the two band energies are shifted wrt to *their* fermi level.
            # Use e=0 if you don't want to shift the eigenvalus
            # so that it's possible to visualize the QP corrections.
            plotter.combiplot(title="Silicon band structure", show=False)
            plotter.gridplot(title="Silicon band structure", show=False)
Ejemplo n.º 4
0
 def get_ebands_plotter(self):
     from abipy import abilab
     plotter = abilab.ElectronBandsPlotter()
     for label, gsr in self:
         plotter.add_ebands(label, gsr.ebands)
     return plotter
Ejemplo n.º 5
0
# Plot band energies on k-path
ni_ebands_kpath.plot(ylims=elims, title="Ni band structure")

# Compute DOS with Gaussian method.
ni_edos = ni_ebands_kmesh.get_edos()

# Plot energies on k-path + DOS
ni_ebands_kpath.plot_with_edos(ni_edos,
                               ylims=elims,
                               title="Ni band structure + DOS")

# Plot electronic DOS.
#ni_edos.plot_dos_idos(xlims=elims)
#ni_edos.plot(xlims=elims)
#ni_edos.plot_up_minus_down(xlims=elims)

# Boxplot for 10 > band >= 5
ni_ebands_kpath.boxplot(
    brange=[5, 10], title="Boxplot for up and down spin and 10 > band >= 5")

# Use ElectronBandsPlotter to analyze multiple ElectronBands object
plotter = abilab.ElectronBandsPlotter()
plotter.add_ebands("k-mesh", ni_ebands_kmesh)
plotter.add_ebands("k-path", ni_ebands_kpath)

ylims = [-10, 5]
#plotter.combiplot(ylims=ylims)
plotter.gridplot(ylims=ylims)
#plotter.boxplot(brange=[5, 10])
plotter.combiboxplot(brange=[5, 10])