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. Returns: 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 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, dos=ks_dos) plotter.add_ebands(bands_label + " + scissors", qp_bands, dos=qp_dos) return plotter.plot(**kwargs)
# 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) # Define the mapping reduced_coordinates -> name of the k-point. klabels = { (0.5, 0.0, 0.0): "L", (0.0, 0.0, 0.0): "$\Gamma$", (0.0, 0.5, 0.5): "X", } plotter.plot(title="Silicon band structure", klabels=klabels)
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) # Define the mapping reduced_coordinates -> name of the k-point. klabels = { (0.5, 0.0, 0.0): "L", (0.0, 0.0, 0.0): "$\Gamma$", (0.0, 0.5, 0.5): "X", } plotter.plot(title="Silicon band structure", klabels=klabels) except (IOError, OSError): print('no abinit output found')
def plot_qpbands(self, bands_filepath, bands_label=None, dos_filepath=None, dos_args=None, qp_marker=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. qp_marker: if int > 0, markers for the ab-initio QP energies are displayed. e.g qp_marker=50 kwargs: Options passed to the plotter. Returns: 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, dos=ks_dos) plotter.add_ebands(bands_label + " + scissors", qp_bands, dos=qp_dos) #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 == kpoint: #if qp.kpoint in kstar: 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.plot(**kwargs)
def band_plots(self, query=None, sort='system'): """ Plot the scissored bands for all the systems in the DB :param query: :param sort: :return: """ if query is None: query = {} for item in self.col.find(query).sort(sort): exclude = ['ZnO_mp-2133', 'K3Sb_mp-14017', 'NiP2_mp-486', 'OsS2_mp-20905', 'PbO_mp-1336', 'Rb3Sb_mp-16319', 'As2Os_mp-2455'] if item['system'] in exclude: continue if False: print('System : ', item['system'].split('_mp-')[0]) print('Ps : ', item['ps']) print('extra : ', item['extra_vars']) print('gwresults : ', item['gw_results']) try: data = self.gfs.get(item['results_file']).read() if len(data) > 1000: srf = MySigResFile(data) title = "QPState corrections of " + str(item['system']) + "\nusing " \ + str(item['ps'].split('/')[-2]) if item['extra_vars'] is not None: title += ' and ' + str(self.fix_extra(item['extra_vars'])) srf.plot_scissor(title=title) srf.print_gap_info() sc = srf.get_scissor() with self.gfs.get(item['ksbands_file']) as f: ksb = MyBandsFile(f.read()).ebands qpb = ksb.apply_scissors(sc) # Plot the LDA and the QPState band structure with matplotlib. plotter = ElectronBandsPlotter() plotter.add_ebands("KS", ksb) plotter.add_ebands("KS+scissors(e)", qpb) fig = plotter.plot(align='cbm', ylim=(-5, 10), title="%s Bandstructure" % item['system'].split('_mp-')[0]) try: if not item['tgwgap']: bands_data = self.gfs.get(item['ksbands_file']) ks_bands = MyBandsFile(bands_data) item['tkshomo'] = ks_bands.h**o item['tkslumo'] = ks_bands.lumo item['tksgap'] = ks_bands.lumo - ks_bands.h**o item['tgwhomo'] = ks_bands.h**o + sc.apply(ks_bands.h**o) item['tgwlumo'] = ks_bands.lumo + sc.apply(ks_bands.lumo) item['tgwgap'] = item['tgwlumo'] - item['tgwhomo'] self.col.save(item) except KeyError: pass except (KeyError, IOError, NoFile): print('No Sigres file in DataBase') try: return fig except UnboundLocalError: return None
def plot_qpbands(self, bands_filepath, bands_label=None, dos_filepath=None, dos_args=None, qp_marker=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. qp_marker: if int > 0, markers for the ab-initio QP energies are displayed. e.g qp_marker=50 kwargs: Options passed to the plotter. Returns: 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, dos=ks_dos) plotter.add_ebands(bands_label + " + scissors", qp_bands, dos=qp_dos) #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 == kpoint: #if qp.kpoint in kstar: 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.plot(**kwargs)
# 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) # Define the mapping reduced_coordinates -> name of the k-point. klabels = { (0.5, 0.0, 0.0): "L", (0.0, 0.0, 0.0): "$\Gamma$", (0.0, 0.5, 0.5): "X", } plotter.plot(title="Silicon band structure", klabels=klabels, align='cbm')