def get_interpolated_ebands_plotter(self, vertices_names=None, knames=None, line_density=20, ngkpt=None, shiftk=(0, 0, 0), kpoints=None, **kwargs): """ Args: vertices_names: Used to specify the k-path for the interpolated QP band structure It's a list of tuple, each tuple is of the form (kfrac_coords, kname) where kfrac_coords are the reduced coordinates of the k-point and kname is a string with the name of the k-point. Each point represents a vertex of the k-path. ``line_density`` defines the density of the sampling. If None, the k-path is automatically generated according to the point group of the system. knames: List of strings with the k-point labels defining the k-path. It has precedence over `vertices_names`. line_density: Number of points in the smallest segment of the k-path. Used with ``vertices_names``. ngkpt: Mesh divisions. Used if bands should be interpolated in the IBZ. shiftk: Shifts for k-meshs. Used with ngkpt. kpoints: |KpointList| object taken e.g from a previous ElectronBands. Has precedence over vertices_names and line_density. Return: |ElectronBandsPlotter| object. """ diff_str = self.has_different_structures() if diff_str: cprint(diff_str, "yellow") # Need KpointList object (assume same structures in Robot) nc0 = self.abifiles[0] if kpoints is None: if ngkpt is not None: # IBZ sampling kpoints = IrredZone.from_ngkpt(nc0.structure, ngkpt, shiftk, kptopt=1, verbose=0) else: # K-Path if knames is not None: kpoints = Kpath.from_names(nc0.structure, knames, line_density=line_density) else: if vertices_names is None: vertices_names = [(k.frac_coords, k.name) for k in nc0.structure.hsym_kpoints] kpoints = Kpath.from_vertices_and_names( nc0.structure, vertices_names, line_density=line_density) plotter = ElectronBandsPlotter() for label, abiwan in self.items(): plotter.add_ebands(label, abiwan.interpolate_ebands(kpoints=kpoints)) return plotter
def get_plotter_from_ebands(self, ebands): """ Interpolate energies using the k-points given in input |ElectronBands| ebands. Return: |ElectronBandsPlotter| object. """ ebands = ElectronBands.as_ebands(ebands) wan_ebands = self.interpolate_ebands(kpoints=ebands.kpoints) return ElectronBandsPlotter(key_ebands=[("Ab-initio", ebands), ("Interpolated", wan_ebands)])
def get_interpolated_ebands_plotter(self, vertices_names=None, knames=None, line_density=20, ngkpt=None, shiftk=(0, 0, 0), kpoints=None, **kwargs): """ Args: vertices_names: Used to specify the k-path for the interpolated QP band structure It's a list of tuple, each tuple is of the form (kfrac_coords, kname) where kfrac_coords are the reduced coordinates of the k-point and kname is a string with the name of the k-point. Each point represents a vertex of the k-path. ``line_density`` defines the density of the sampling. If None, the k-path is automatically generated according to the point group of the system. knames: List of strings with the k-point labels defining the k-path. It has precedence over `vertices_names`. line_density: Number of points in the smallest segment of the k-path. Used with ``vertices_names``. ngkpt: Mesh divisions. Used if bands should be interpolated in the IBZ. shiftk: Shifts for k-meshs. Used with ngkpt. kpoints: |KpointList| object taken e.g from a previous ElectronBands. Has precedence over vertices_names and line_density. Return: |ElectronBandsPlotter| object. """ diff_str = self.has_different_structures() if diff_str: cprint(diff_str, "yellow") # Need KpointList object (assume same structures in Robot) nc0 = self.abifiles[0] if kpoints is None: if ngkpt is not None: # IBZ sampling kpoints = IrredZone.from_ngkpt(nc0.structure, ngkpt, shiftk, kptopt=1, verbose=0) else: # K-Path if knames is not None: kpoints = Kpath.from_names(nc0.structure, knames, line_density=line_density) else: if vertices_names is None: vertices_names = [(k.frac_coords, k.name) for k in nc0.structure.hsym_kpoints] kpoints = Kpath.from_vertices_and_names(nc0.structure, vertices_names, line_density=line_density) plotter = ElectronBandsPlotter() for label, abiwan in self.items(): plotter.add_ebands(label, abiwan.interpolate_ebands(kpoints=kpoints)) return plotter
def OnCompareEbands(self, event): """Plot multiple electron bands""" plotter = ElectronBandsPlotter() for path, ebands in zip(self.ebands_filepaths, self.ebands_list): label = os.path.relpath(path) plotter.add_ebands(label, ebands) try: print(plotter.bands_statdiff()) except: pass plotter.plot()
def test_ebands_plotter(self): """Testing ElelectronBandsPlotter.""" plotter = ElectronBandsPlotter(key_ebands=[("Si1", abidata.ref_file("si_scf_GSR.nc"))]) plotter.add_ebands("Si2", abidata.ref_file("si_scf_GSR.nc")) repr(plotter); str(plotter) assert len(plotter.ebands_list) == 2 assert len(plotter.edoses_list) == 0 with self.assertRaises(ValueError): plotter.add_ebands("Si2", abidata.ref_file("si_scf_GSR.nc")) # __add__ should merge plotters p2 = plotter.add_plotter(plotter) assert len(p2.ebands_list) == 2 assert len(p2.edoses_list) == 0 assert hasattr(p2, "combiplot") print(plotter.bands_statdiff()) df = plotter.get_ebands_frame() assert df is not None if self.has_matplotlib(): assert plotter.combiplot(title="Silicon band structure", show=False) # Alias for combiplot assert plotter.plot(e0=2, width_ratios=(3, 1), fontsize=12, show=False) if self.has_seaborn(): plotter.combiboxplot(title="Silicon band structure", swarm=True, show=False) assert plotter.gridplot(title="Silicon band structure", with_gaps=True, show=False) assert plotter.boxplot(title="Silicon band structure", swarm=True, show=False) assert plotter.animate(show=False) if self.has_ipywidgets(): assert plotter.ipw_select_plot() is not None if self.has_nbformat(): assert plotter.write_notebook(nbpath=self.get_tmpname(text=True)) pickle_path = self.get_tmpname(text=True) plotter.pickle_dump(pickle_path) same = ElectronBandsPlotter.pickle_load(pickle_path) assert len(same.ebands_dict) == len(plotter.ebands_dict) assert list(same.ebands_dict.keys()) == list(plotter.ebands_dict.keys())
def test_ebands_plotter(self): """Testing ElelectronBandsPlotter.""" plotter = ElectronBandsPlotter( key_ebands=[("Si1", abidata.ref_file("si_scf_GSR.nc"))]) plotter.add_ebands("Si2", abidata.ref_file("si_scf_GSR.nc")) repr(plotter) str(plotter) assert len(plotter.ebands_list) == 2 assert len(plotter.edoses_list) == 0 with self.assertRaises(ValueError): plotter.add_ebands("Si2", abidata.ref_file("si_scf_GSR.nc")) # __add__ should merge plotters p2 = plotter.add_plotter(plotter) assert len(p2.ebands_list) == 2 assert len(p2.edoses_list) == 0 assert hasattr(p2, "combiplot") print(plotter.bands_statdiff()) df = plotter.get_ebands_frame() assert df is not None if self.has_matplotlib(): assert plotter.combiplot(title="Silicon band structure", show=False) # Alias for combiplot assert plotter.plot(e0=2, width_ratios=(3, 1), fontsize=12, show=False) if self.has_seaborn(): plotter.combiboxplot(title="Silicon band structure", swarm=True, show=False) assert plotter.gridplot(title="Silicon band structure", show=False) assert plotter.boxplot(title="Silicon band structure", swarm=True, show=False) assert plotter.animate(show=False) if self.has_ipywidgets(): assert plotter.ipw_select_plot() is not None if self.has_nbformat(): assert plotter.write_notebook(nbpath=self.get_tmpname(text=True)) pickle_path = self.get_tmpname(text=True) plotter.pickle_dump(pickle_path) same = ElectronBandsPlotter.pickle_load(pickle_path) assert len(same.ebands_dict) == len(plotter.ebands_dict) assert list(same.ebands_dict.keys()) == list( plotter.ebands_dict.keys())
def test_api(self): """Test ElelectronBandsPlotter API.""" plotter = ElectronBandsPlotter( key_ebands=[("Si1", abidata.ref_file("si_scf_GSR.nc"))]) plotter.add_ebands("Si2", abidata.ref_file("si_scf_GSR.nc")) print(repr(plotter)) assert len(plotter.ebands_list) == 2 assert len(plotter.edoses_list) == 0 with self.assertRaises(ValueError): plotter.add_ebands("Si2", abidata.ref_file("si_scf_GSR.nc")) print(plotter.bands_statdiff()) df = plotter.get_ebands_frame() assert df is not None if self.has_matplotlib(): plotter.combiplot(title="Silicon band structure", show=False) if self.has_seaborn(): plotter.combiboxplot(title="Silicon band structure", show=False) plotter.gridplot(title="Silicon band structure", show=False) plotter.boxplot(title="Silicon band structure", swarm=True, show=False) plotter.animate(show=False) if self.has_nbformat(): plotter.write_notebook(nbpath=self.get_tmpname(text=True))