def test_interpolator(self): """Test QP interpolation.""" from abipy.abilab import abiopen, ElectronBandsPlotter # Get quasiparticle results from the SIGRES.nc database. sigres = 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. 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 not ((qp_mpdivs, qp_shifts) == (None, 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 = 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(): plotter.combiplot(title="Silicon band structure", show=False) plotter.gridplot(title="Silicon band structure", show=False) sigres.close()
def test_scissors_polyfit(self): """Testing scissors from SIGRES file.""" # Get the quasiparticle results from the SIGRES.nc database. sigma_file = abiopen(abidata.ref_file("si_g0w0ppm_nband30_SIGRES.nc")) qplist_spin = sigma_file.qplist_spin sigma_file.close() # Construct the scissors operator domains = [[-10, 6.1], [6.1, 18]] scissors = qplist_spin[0].build_scissors(domains, bounds=None) # Read the KS band energies computed on the k-path with 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 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 = ElectronBandsPlotter() plotter.add_ebands("LDA", ks_bands, dos=ks_dos) plotter.add_ebands("LDA+scissors(e)", qp_bands, dos=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") plotter.gridplot(title="Silicon band structure")
#!/usr/bin/env python """ This example shows how to plot several band structures on a grid We use two GSR files: si_scf_GSR.n: energies on a homogeneous sampling of the BZ (can be used to compute DOS) si_nscf_GSR.nc: energies on a k-path in the BZ (used to plot the band dispersion) """ from abipy.abilab import ElectronBandsPlotter from abipy.data import ref_file # To plot a grid with two band structures: plotter = ElectronBandsPlotter() plotter.add_ebands("BZ sampling", ref_file("si_scf_GSR.nc")) plotter.add_ebands("k-path", ref_file("si_nscf_GSR.nc")) frame = plotter.get_ebands_frame() print(frame) plotter.gridplot(e0=None) #plotter.animate() # To plot a grid with band structures + DOS, use the optional argument `edos_objects` # The first subplot will get the band dispersion from eb_objects[0] and the dos from edos_objects[0] # edos_kwargs is an optional dictionary with the arguments that will be passed to `get_dos` to compute the DOS. #eb_objects = 2 * [ref_file("si_nscf_GSR.nc")] #edos_objects = 2 * [ref_file("si_scf_GSR.nc")] #plotter = ElectronBandsPlotter() #plotter.add_ebands("Si", ref_file("si_nscf_GSR.nc"), dos=ref_file("si_scf_GSR.nc")) #plotter.add_ebands("Same data", ref_file("si_nscf_GSR.nc"), dos=ref_file("si_scf_GSR.nc")) #plotter.gridplot()
# Read the KS band energies computed on the k-path ks_bands = abiopen(abidata.ref_file("si_nscf_GSR.nc")).ebands # Read the KS band energies computed on the Monkhorst-Pack (MP) mesh # and compute the DOS with the Gaussian method ks_mpbands = abiopen(abidata.ref_file("si_scf_GSR.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. plotter = ElectronBandsPlotter() plotter.add_ebands("LDA", ks_bands, dos=ks_dos) plotter.add_ebands("LDA+scissors(e)", qp_bands, dos=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") plotter.gridplot(title="Silicon band structure") sigma_file.close()
r = sigres.interpolate(lpratio=5, ks_ebands_kpath=ks_ebands_kpath, ks_ebands_kmesh=ks_ebands_kmesh) qp_edos = r.qp_ebands_kmesh.get_edos() # Shortcut: pass the name of the GSR files directly. #r = sigres.interpolate(ks_ebands_kpath=abidata.ref_file("si_nscf_GSR.nc"), # ks_ebands_kmesh=abidata.ref_file("si_scf_GSR.nc")) #ks_edos = r.ks_ebands_kmesh.get_edos() #qp_edos = r.qp_ebands_kmesh.get_edos() # Use ElectronBandsPlotter to plot the KS and the QP band structure with matplotlib. plotter = ElectronBandsPlotter() plotter.add_ebands("LDA", ks_ebands_kpath, dos=ks_edos) plotter.add_ebands("GW (interpolated)", r.qp_ebands_kpath, dos=qp_edos) # Get pandas dataframe with band structure parameters. #df = plotter.get_ebands_frame() #print(df) # 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="Combiplot") plotter.boxplot(swarm=True, title="Boxplot") plotter.combiboxplot(swarm=True, title="Combiboxplot") # sphinx_gallery_thumbnail_number = 4 plotter.gridplot(title="Gridplot") sigres.close()
We use two GSR files: si_scf_GSR.n: energies on a homogeneous sampling of the BZ (can be used to compute DOS) si_nscf_GSR.nc: energies on a k-path in the BZ (used to plot the band dispersion) """ from abipy.abilab import ElectronBandsPlotter from abipy.data import ref_file # To plot a grid with two band structures: plotter = ElectronBandsPlotter() plotter.add_ebands("BZ sampling", ref_file("si_scf_GSR.nc")) plotter.add_ebands("k-path", ref_file("si_nscf_GSR.nc")) # Get pandas dataframe frame = plotter.get_ebands_frame() print(frame) plotter.gridplot() #plotter.animate() # To plot a grid with band structures + DOS, use the optional argument `edos_objects` # The first subplot will get the band dispersion from eb_objects[0] and the DOS from edos_objects[0] # edos_kwargs is an optional dictionary with the arguments that will be passed to `get_dos` to compute the DOS. eb_objects = 2 * [ref_file("si_nscf_GSR.nc")] edos_objects = 2 * [ref_file("si_scf_GSR.nc")] plotter = ElectronBandsPlotter() plotter.add_ebands("Si", ref_file("si_nscf_GSR.nc"), dos=ref_file("si_scf_GSR.nc")) plotter.add_ebands("Same data", ref_file("si_nscf_GSR.nc"), dos=ref_file("si_scf_GSR.nc")) plotter.gridplot()
# Read the KS band energies computed on the k-path ks_bands = abiopen(abidata.ref_file("si_nscf_GSR.nc")).ebands # Read the KS band energies computed on the Monkhorst-Pack (MP) mesh # and compute the DOS with the Gaussian method ks_mpbands = abiopen(abidata.ref_file("si_scf_GSR.nc")).ebands ks_edos = 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_edos = qp_mpbands.get_edos() # Plot the LDA and the QPState band structure with matplotlib. plotter = ElectronBandsPlotter() plotter.add_ebands("LDA", ks_bands, edos=ks_edos) plotter.add_ebands("LDA+scissors(e)", qp_bands, edos=qp_edos) # 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") plotter.gridplot(title="Silicon band structure") sigma_file.close()
# This part is optional points = sigres.get_points_from_ebands(r.qp_ebands_kpath, size=24) r.qp_ebands_kpath.plot(points=points, with_gaps=True) #raise ValueError() # Shortcut: pass the name of the GSR files directly. #r = sigres.interpolate(ks_ebands_kpath=abidata.ref_file("si_nscf_GSR.nc"), # ks_ebands_kmesh=abidata.ref_file("si_scf_GSR.nc")) #ks_edos = r.ks_ebands_kmesh.get_edos() #qp_edos = r.qp_ebands_kmesh.get_edos() # Use ElectronBandsPlotter to plot the KS and the QP band structure with matplotlib. plotter = ElectronBandsPlotter() plotter.add_ebands("LDA", ks_ebands_kpath, edos=ks_edos) plotter.add_ebands("GW (interpolated)", r.qp_ebands_kpath, edos=qp_edos) # Get pandas dataframe with band structure parameters. #df = plotter.get_ebands_frame() #print(df) # 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="Combiplot") plotter.boxplot(swarm=True, title="Boxplot") plotter.combiboxplot(swarm=True, title="Combiboxplot") # sphinx_gallery_thumbnail_number = 4 plotter.gridplot(title="Gridplot", with_gaps=True) sigres.close()
si_scf_GSR.n: energies on a homogeneous sampling of the BZ (can be used to compute DOS) si_nscf_GSR.nc: energies on a k-path in the BZ (used to plot the band dispersion) """ from abipy.abilab import ElectronBandsPlotter from abipy.data import ref_file # To plot a grid with two band structures: plotter = ElectronBandsPlotter() plotter.add_ebands("BZ sampling", ref_file("si_scf_GSR.nc")) plotter.add_ebands("k-path", ref_file("si_nscf_GSR.nc")) # Get pandas dataframe frame = plotter.get_ebands_frame() print(frame) plotter.gridplot(with_gaps=True) #plotter.animate() # To plot a grid with band structures + DOS, use the optional argument `edos_objects` # The first subplot gets the band dispersion from eb_objects[0] and the DOS from edos_objects[0] # edos_kwargs is an optional dictionary passed to `get_dos` to compute the DOS. eb_objects = 2 * [ref_file("si_nscf_GSR.nc")] edos_objects = 2 * [ref_file("si_scf_GSR.nc")] # sphinx_gallery_thumbnail_number = 2 plotter = ElectronBandsPlotter() plotter.add_ebands("Si", ref_file("si_nscf_GSR.nc"), edos=ref_file("si_scf_GSR.nc")) plotter.add_ebands("Same data", ref_file("si_nscf_GSR.nc"),
ks_ebands_kpath=ks_ebands_kpath, ks_ebands_kmesh=ks_ebands_kmesh ) qp_edos = r.qp_ebands_kmesh.get_edos() # Shortcut: pass the name of the GSR files directly. #r = sigres.interpolate(ks_ebands_kpath=abidata.ref_file("si_nscf_GSR.nc"), # ks_ebands_kmesh=abidata.ref_file("si_scf_GSR.nc")) #ks_edos = r.ks_ebands_kmesh.get_edos() #qp_edos = r.qp_ebands_kmesh.get_edos() # Use ElectronBandsPlotter to plot the KS and the QP band structure with matplotlib. plotter = ElectronBandsPlotter() plotter.add_ebands("LDA", ks_ebands_kpath, dos=ks_edos) plotter.add_ebands("GW (interpolated)", r.qp_ebands_kpath, dos=qp_edos) # Get pandas dataframe with band structure parameters. #df = plotter.get_ebands_frame() #print(df) # 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="Combiplot") plotter.boxplot(swarm=True, title="Boxplot") plotter.combiboxplot(swarm=True, title="Combiboxplot") # sphinx_gallery_thumbnail_number = 4 plotter.gridplot(title="Gridplot") sigres.close()
si_scf_GSR.n: energies on a homogeneous sampling of the BZ (can be used to compute DOS) si_nscf_GSR.nc: energies on a k-path in the BZ (used to plot the band dispersion) """ from abipy.abilab import ElectronBandsPlotter from abipy.data import ref_file # To plot a grid with two band structures: plotter = ElectronBandsPlotter() plotter.add_ebands("BZ sampling", ref_file("si_scf_GSR.nc")) plotter.add_ebands("k-path", ref_file("si_nscf_GSR.nc")) # Get pandas dataframe frame = plotter.get_ebands_frame() print(frame) plotter.gridplot() #plotter.animate() # To plot a grid with band structures + DOS, use the optional argument `edos_objects` # The first subplot gets the band dispersion from eb_objects[0] and the DOS from edos_objects[0] # edos_kwargs is an optional dictionary passed to `get_dos` to compute the DOS. eb_objects = 2 * [ref_file("si_nscf_GSR.nc")] edos_objects = 2 * [ref_file("si_scf_GSR.nc")] # sphinx_gallery_thumbnail_number = 2 plotter = ElectronBandsPlotter() plotter.add_ebands("Si", ref_file("si_nscf_GSR.nc"), dos=ref_file("si_scf_GSR.nc")) plotter.add_ebands("Same data", ref_file("si_nscf_GSR.nc"), dos=ref_file("si_scf_GSR.nc")) plotter.gridplot()