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")
# 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()
def plot_qpbands(self, bands_filepath, bands_label=None, dos_filepath=None, dos_args=None, **kwargs): """ Correct the energies found in the netcdf file bands_filepath and plot the band energies (both the initial and the corrected ones) with matplotlib. The plot contains the KS and the QP DOS if dos_filepath is not None. Args: bands_filepath: Path to the netcdf file containing the initial KS energies to be corrected. bands_label String used to label the KS bands in the plot. dos_filepath: Optional path to a netcdf file with the initial KS energies on a homogeneous k-mesh (used to compute the KS and the QP dos) dos_args: Dictionary with the arguments passed to get_dos to compute the DOS Used if dos_filepath is not None. kwargs: Options passed to the plotter. Return: |matplotlib-Figure| """ from abipy.abilab import abiopen, ElectronBandsPlotter # Read the KS band energies from bands_filepath and apply the scissors operator. with abiopen(bands_filepath) as ncfile: ks_bands = ncfile.ebands #structure = ncfile.structure qp_bands = ks_bands.apply_scissors(self._scissors_spin) # Read the band energies computed on the Monkhorst-Pack (MP) mesh and compute the DOS. ks_dos, qp_dos = None, None if dos_filepath is not None: with abiopen(dos_filepath) as ncfile: ks_mpbands = ncfile.ebands dos_args = {} if not dos_args else dos_args ks_dos = ks_mpbands.get_edos(**dos_args) # Compute the DOS with the modified QPState energies. qp_mpbands = ks_mpbands.apply_scissors(self._scissors_spin) qp_dos = qp_mpbands.get_edos(**dos_args) # Plot the LDA and the QPState band structure with matplotlib. plotter = ElectronBandsPlotter() bands_label = bands_label if bands_label is not None else os.path.basename( bands_filepath) plotter.add_ebands(bands_label, ks_bands, edos=ks_dos) plotter.add_ebands(bands_label + " + scissors", qp_bands, edos=qp_dos) #qp_marker: if int > 0, markers for the ab-initio QP energies are displayed. e.g qp_marker=50 #qp_marker = 50 #if qp_marker is not None: # # Compute correspondence between the k-points in qp_list and the k-path in qp_bands. # # TODO # # WARNING: strictly speaking one should check if qp_kpoint is in the star of k-point. # # but compute_star is too slow if written in pure python. # x, y, s = [], [], [] # for ik_path, kpoint in enumerate(qp_bands.kpoints): # #kstar = kpoint.compute_star(structure.fm_symmops) # for spin in range(self.nsppol): # for ik_qp, qp in enumerate(self._qps_spin[spin]): # #if qp.kpoint in kstar: # if qp.kpoint == kpoint: # x.append(ik_path) # y.append(np.real(qp.qpe)) # s.append(qp_marker) # plotter.set_marker("ab-initio QP", [x, y, s]) return plotter.combiplot(**kwargs)
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()
# 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()
def plot_qpbands(self, bands_filepath, bands_label=None, dos_filepath=None, dos_args=None, **kwargs): """ Correct the energies found in the netcdf file bands_filepath and plot the band energies (both the initial and the corrected ones) with matplotlib. The plot contains the KS and the QP DOS if dos_filepath is not None. Args: bands_filepath: Path to the netcdf file containing the initial KS energies to be corrected. bands_label String used to label the KS bands in the plot. dos_filepath: Optional path to a netcdf file with the initial KS energies on a homogeneous k-mesh (used to compute the KS and the QP dos) dos_args: Dictionary with the arguments passed to get_dos to compute the DOS Used if dos_filepath is not None. kwargs: Options passed to the plotter. Return: |matplotlib-Figure| """ from abipy.abilab import abiopen, ElectronBandsPlotter # Read the KS band energies from bands_filepath and apply the scissors operator. with abiopen(bands_filepath) as ncfile: ks_bands = ncfile.ebands #structure = ncfile.structure qp_bands = ks_bands.apply_scissors(self._scissors_spin) # Read the band energies computed on the Monkhorst-Pack (MP) mesh and compute the DOS. ks_dos, qp_dos = None, None if dos_filepath is not None: with abiopen(dos_filepath) as ncfile: ks_mpbands = ncfile.ebands dos_args = {} if not dos_args else dos_args ks_dos = ks_mpbands.get_edos(**dos_args) # Compute the DOS with the modified QPState energies. qp_mpbands = ks_mpbands.apply_scissors(self._scissors_spin) qp_dos = qp_mpbands.get_edos(**dos_args) # Plot the LDA and the QPState band structure with matplotlib. plotter = ElectronBandsPlotter() bands_label = bands_label if bands_label is not None else os.path.basename(bands_filepath) plotter.add_ebands(bands_label, ks_bands, edos=ks_dos) plotter.add_ebands(bands_label + " + scissors", qp_bands, edos=qp_dos) #qp_marker: if int > 0, markers for the ab-initio QP energies are displayed. e.g qp_marker=50 #qp_marker = 50 #if qp_marker is not None: # # Compute correspondence between the k-points in qp_list and the k-path in qp_bands. # # TODO # # WARNING: strictly speaking one should check if qp_kpoint is in the star of k-point. # # but compute_star is too slow if written in pure python. # x, y, s = [], [], [] # for ik_path, kpoint in enumerate(qp_bands.kpoints): # #kstar = kpoint.compute_star(structure.fm_symmops) # for spin in range(self.nsppol): # for ik_qp, qp in enumerate(self._qps_spin[spin]): # #if qp.kpoint in kstar: # if qp.kpoint == kpoint: # x.append(ik_path) # y.append(np.real(qp.qpe)) # s.append(qp_marker) # plotter.set_marker("ab-initio QP", [x, y, s]) return plotter.combiplot(**kwargs)