def test_read_ebands_from_WFK(self): """Read ElectronBands from WFK files.""" for filename in data.WFK_NCFILES: ebands = ElectronBands.from_file(filename) ebands.to_pymatgen() ebands.to_pdframe() assert ElectronBands.as_ebands(ebands) is ebands
def test_jdos(self): """Test JDOS methods.""" bands = ElectronBands.from_file(data.ref_file("si_scf_GSR.nc")) spin = 0 conduction = [4,] for v in range(1,5): valence = range(0,v) jdos = bands.get_ejdos(spin, valence, conduction) intg = jdos.integral()[-1][-1] self.assert_almost_equal(intg, len(conduction) * len(valence)) self.serialize_with_pickle(jdos, protocols=[-1]) nscf_bands = ElectronBands.from_file(data.ref_file("si_nscf_GSR.nc")) # Test the detection of denerate states. degs = nscf_bands.degeneracies(spin=0, kpoint=[0,0,0], bands_range=range(8)) ref_degbands = [[0], [1,2,3], [4,5,6], [7]] for i, (e, deg_bands) in enumerate(degs): self.assertEqual(deg_bands, ref_degbands[i]) # JDOS a homogeneous sampling. with self.assertRaises(ValueError): nscf_bands.get_ejdos(spin, 0, 4)
def test_jdos(self): """Test JDOS methods.""" bands = ElectronBands.from_file(data.ref_file("si_scf_GSR.nc")) spin = 0 conduction = [ 4, ] for v in range(1, 5): valence = range(0, v) jdos = bands.get_ejdos(spin, valence, conduction) intg = jdos.integral()[-1][-1] self.assert_almost_equal(intg, len(conduction) * len(valence)) self.serialize_with_pickle(jdos, protocols=[-1]) nscf_bands = ElectronBands.from_file(data.ref_file("si_nscf_GSR.nc")) # Test the detection of denerate states. degs = nscf_bands.degeneracies(spin=0, kpoint=[0, 0, 0], bands_range=range(8)) ref_degbands = [[0], [1, 2, 3], [4, 5, 6], [7]] for i, (e, deg_bands) in enumerate(degs): self.assertEqual(deg_bands, ref_degbands[i]) # JDOS a homogeneous sampling. with self.assertRaises(ValueError): nscf_bands.get_ejdos(spin, 0, 4)
def test_read_ebands_from_GSR(self): """Read ElectronBands from GSR files.""" for filename in abidata.GSR_NCFILES: ebands = ElectronBands.from_file(filename) ebands.to_pymatgen() ebands.to_pdframe() self.serialize_with_pickle(ebands, test_eq=False) ElectronBands.from_dict(ebands.as_dict()) self.assertMSONable(ebands, test_if_subclass=False)
def test_read_ebands_from_WFK(self): """Read ElectronBands from WFK files.""" for ii, filename in enumerate(abidata.WFK_NCFILES): ebands = ElectronBands.from_file(filename) ebands.to_pymatgen() ebands.to_pdframe() assert ElectronBands.as_ebands(ebands) is ebands self.serialize_with_pickle(ebands, test_eq=False) ElectronBands.from_dict(ebands.as_dict()) self.assertMSONable(ebands, test_if_subclass=False) if ii == 0: if self.has_matplotlib(): ebands.plot(show=False) ebands.to_xmgrace(self.get_tmpname(text=True))
def test_ebands_skw_interpolation(self): """Testing SKW interpolation.""" si_ebands_kmesh = ElectronBands.from_file(abidata.ref_file("si_scf_GSR.nc")) # Test interpolation. vertices_names = [((0.0, 0.0, 0.0), "G"), ((0.5, 0.5, 0.0), "M")] r = si_ebands_kmesh.interpolate(lpratio=10, vertices_names=vertices_names, kmesh=[8, 8, 8], verbose=1) assert r.ebands_kpath is not None assert r.ebands_kpath.kpoints.is_path assert not r.ebands_kpath.kpoints.is_ibz mpdivs, shifts = r.ebands_kpath.kpoints.mpdivs_shifts assert mpdivs is None and shifts is None assert r.ebands_kmesh is not None assert r.ebands_kmesh.kpoints.is_ibz assert not r.ebands_kmesh.kpoints.is_path assert r.ebands_kmesh.kpoints.ksampling is not None assert r.ebands_kmesh.kpoints.is_mpmesh mpdivs, shifts = r.ebands_kmesh.kpoints.mpdivs_shifts self.assert_equal(mpdivs, [8, 8, 8]) self.assert_equal(shifts.flatten(), [0, 0, 0]) # Export it in BXSF format. r.ebands_kmesh.to_bxsf(self.get_tmpname(text=True))
def test_ebands_skw_interpolation(self): if sys.version[0:3] >= '3.4': raise unittest.SkipTest( "SKW interpolation is not tested if Python version >= 3.4 (linalg.solve portability issue)" ) bands = ElectronBands.from_file(abidata.ref_file("si_scf_GSR.nc")) # Test interpolate. vertices_names = [((0.0, 0.0, 0.0), "G"), ((0.5, 0.5, 0.0), "M")] r = bands.interpolate(lpratio=10, vertices_names=vertices_names, kmesh=[8, 8, 8], verbose=1) assert r.ebands_kpath is not None assert r.ebands_kpath.kpoints.is_path assert not r.ebands_kpath.kpoints.is_ibz mpdivs, shifts = r.ebands_kpath.kpoints.mpdivs_shifts assert mpdivs is None and shifts is None assert r.ebands_kmesh is not None assert r.ebands_kmesh.kpoints.is_ibz assert not r.ebands_kmesh.kpoints.is_path assert r.ebands_kmesh.kpoints.ksampling is not None assert r.ebands_kmesh.kpoints.is_mpmesh mpdivs, shifts = r.ebands_kmesh.kpoints.mpdivs_shifts self.assert_equal(mpdivs, [8, 8, 8]) self.assert_equal(shifts.flatten(), [0, 0, 0]) # Export it in BXSF format. r.ebands_kmesh.to_bxsf(self.get_tmpname(text=True))
def test_ebands_skw_interpolation(self): """Testing SKW interpolation.""" si_ebands_kmesh = ElectronBands.from_file( abidata.ref_file("si_scf_GSR.nc")) # Test interpolation. vertices_names = [((0.0, 0.0, 0.0), "G"), ((0.5, 0.5, 0.0), "M")] r = si_ebands_kmesh.interpolate(lpratio=10, vertices_names=vertices_names, kmesh=[8, 8, 8], verbose=1) assert r.ebands_kpath is not None assert r.ebands_kpath.kpoints.is_path assert not r.ebands_kpath.kpoints.is_ibz mpdivs, shifts = r.ebands_kpath.kpoints.mpdivs_shifts assert mpdivs is None and shifts is None assert r.ebands_kmesh is not None assert r.ebands_kmesh.kpoints.is_ibz assert not r.ebands_kmesh.kpoints.is_path assert r.ebands_kmesh.kpoints.ksampling is not None assert r.ebands_kmesh.kpoints.is_mpmesh mpdivs, shifts = r.ebands_kmesh.kpoints.mpdivs_shifts self.assert_equal(mpdivs, [8, 8, 8]) self.assert_equal(shifts.flatten(), [0, 0, 0]) # Export it in BXSF format. r.ebands_kmesh.to_bxsf(self.get_tmpname(text=True))
def test_derivatives(self): """Testing computation of effective masses.""" ebands = ElectronBands.from_file(abidata.ref_file("si_nscf_GSR.nc")) # Hack eigens to simulate free-electron bands. # This should produce all(effective masses == 1) new_eigens = np.empty(ebands.shape) branch = 0.5 * units.Ha_to_eV * np.array( [(k.norm * units.bohr_to_ang)**2 for k in ebands.kpoints]) for spin in ebands.spins: for band in range(ebands.mband): new_eigens[spin, :, band] = branch ebands._eigens = new_eigens effm_lines = ebands.effective_masses(spin=0, band=0, acc=2) # Flatten structure (.flatten does not work in this case) values = [] for arr in effm_lines: values.extend(arr) self.assert_almost_equal(np.array(values), 1.0) em = ebands.effmass_line(spin=0, kpoint=(0, 0, 0), band=0) repr(em) str(em)
def test_api(self): """Testing ElelectronDosPlotter API.""" gsr_path = abidata.ref_file("si_scf_GSR.nc") gs_bands = ElectronBands.from_file(gsr_path) si_edos = gs_bands.get_edos() plotter = ElectronDosPlotter() plotter.add_edos("edos1", si_edos) with self.assertRaises(ValueError): plotter.add_edos("edos1", si_edos) plotter.add_edos("edos2", gsr_path, edos_kwargs=dict(method="gaussian", step=0.2, width=0.4)) assert len(plotter.edos_list) == 2 assert not plotter._can_use_basenames_as_labels() if self.has_matplotlib(): assert plotter.combiplot(show=False) assert plotter.gridplot(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))
def __init__(self, ebands_kpath, phbst_file, phdos_file, ebands_kmesh=None): self.eb_kpath = ElectronBands.as_ebands(ebands_kpath) self.eb_kmesh = ElectronBands.as_ebands( ebands_kmesh) if ebands_kmesh is not None else None self.phbst_file = phbst_file if duck.is_string(self.phbst_file): self.phbst_file = PhbstFile(self.phbst_file) self.phb_qpath = self.phbst_file.phbands self.phdos_file = phdos_file if duck.is_string(self.phdos_file): self.phdos_file = PhdosFile(phdos_file)
def interpolate_ebands(self, vertices_names=None, line_density=20, ngkpt=None, shiftk=(0, 0, 0), kpoints=None): """ Build new |ElectronBands| object by interpolating the KS Hamiltonian with Wannier functions. Supports k-path via (vertices_names, line_density), IBZ mesh defined by ngkpt and shiftk or input list of kpoints. Args: vertices_names: Used to specify the k-path for the interpolated QP band structure 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. 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. Returns: |ElectronBands| object with Wannier-interpolated energies. """ # Need KpointList object. if kpoints is None: if ngkpt is not None: # IBZ sampling kpoints = IrredZone.from_ngkpt(self.structure, ngkpt, shiftk, kptopt=1, verbose=0) else: # K-Path if vertices_names is None: vertices_names = [(k.frac_coords, k.name) for k in self.structure.hsym_kpoints] kpoints = Kpath.from_vertices_and_names(self.structure, vertices_names, line_density=line_density) nk = len(kpoints) eigens = np.zeros((self.nsppol, nk, self.mwan)) # Interpolate Hamiltonian for each kpoint and spin. start = time.time() write_warning = True for spin in range(self.nsppol): num_wan = self.nwan_spin[spin] for ik, kpt in enumerate(kpoints): oeigs = self.hwan.eval_sk(spin, kpt.frac_coords) eigens[spin, ik, :num_wan] = oeigs if num_wan < self.mwan: # May have different number of wannier functions if nsppol == 2. # Here I use the last value to fill eigens matrix (not very clean but oh well). eigens[spin, ik, num_wan:self.mwan] = oeigs[-1] if write_warning: cprint("Different number of wannier functions for spin. Filling last bands with oeigs[-1]", "yellow") write_warning = False print("Interpolation completed in %.3f [s]" % (time.time() - start)) occfacts = np.zeros_like(eigens) return ElectronBands(self.structure, kpoints, eigens, self.ebands.fermie, occfacts, self.ebands.nelect, self.nspinor, self.nspden, smearing=self.ebands.smearing)
def test_dos(self): """Test DOS methods.""" gs_bands = ElectronBands.from_file(data.ref_file("si_scf_GSR.nc")) dos = gs_bands.get_edos() mu = dos.find_mu(8, atol=1.e-4) imu = dos.tot_idos.find_mesh_index(mu) self.assert_almost_equal(dos.tot_idos[imu][1], 8, decimal=2) self.serialize_with_pickle(dos, protocols=[-1], test_eq=False)
def ebands(self): """ |ElectronBands| object with the single-particle energies used to compute the screening. """ ebands = ElectronBands.from_file(self.filepath) # FIXME cprint("Setting Fermi energy to zero since `fermie_energy` is not initialized in Abinit v8.2", "yellow") ebands.fermie = 0 return ebands
def test_jdos(self): """Test JDOS methods.""" bands = ElectronBands.from_file(abidata.ref_file("si_scf_GSR.nc")) spin = 0 conduction = [ 4, ] for v in range(1, 5): valence = range(0, v) jdos = bands.get_ejdos(spin, valence, conduction) intg = jdos.integral()[-1][-1] self.assert_almost_equal(intg, len(conduction) * len(valence)) self.serialize_with_pickle(jdos, protocols=[-1]) nscf_bands = ElectronBands.from_file( abidata.ref_file("si_nscf_GSR.nc")) diffs = nscf_bands.statdiff(nscf_bands) print(diffs) # Test the detection of denerate states. degs = nscf_bands.degeneracies(spin=0, kpoint=[0, 0, 0], bands_range=range(8)) ref_degbands = [[0], [1, 2, 3], [4, 5, 6], [7]] for i, (e, deg_bands) in enumerate(degs): self.assertEqual(deg_bands, ref_degbands[i]) # Test Electron e1 = nscf_bands._electron_state(spin=0, kpoint=[0, 0, 0], band=0) str(e1) e1_copy = e1.copy() assert isinstance(e1.as_dict(), dict) assert isinstance(e1.to_strdict(), dict) assert e1.spin == 0 assert e1.skb[0] == 0 str(e1.tips) # JDOS requires a homogeneous sampling. with self.assertRaises(ValueError): nscf_bands.get_ejdos(spin, 0, 4)
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 test_frame_from_ebands(self): """Testing dataframe_from_ebands.""" gsr_kmesh = abidata.ref_file("si_scf_GSR.nc") si_ebands_kmesh = ElectronBands.as_ebands(gsr_kmesh) gsr_nscf_path = abidata.ref_file("si_nscf_GSR.nc") index = ["foo", "bar", "hello"] df = dataframe_from_ebands([gsr_kmesh, si_ebands_kmesh, gsr_nscf_path], index=index, with_spglib=True) #str(df) assert all(f == "Si2" for f in df["formula"]) assert all(num == 227 for num in df["abispg_num"]) assert all(df["spglib_num"] == df["abispg_num"])
def test_dos(self): """Test DOS methods.""" gs_bands = ElectronBands.from_file(data.ref_file("si_scf_GSR.nc")) dos = gs_bands.get_edos() print(dos) assert ElectronDos.as_edos(dos, {}) is dos edos_samevals = ElectronDos.as_edos(gs_bands, {}) assert ElectronDos.as_edos(gs_bands, {}) == dos assert ElectronDos.as_edos(data.ref_file("si_scf_GSR.nc"), {}) == dos mu = dos.find_mu(8) imu = dos.tot_idos.find_mesh_index(mu) self.assert_almost_equal(dos.tot_idos[imu][1], 8, decimal=2) self.serialize_with_pickle(dos, protocols=[-1], test_eq=False)
def test_derivatives(self): """Testing computation of effective masses.""" ebands = ElectronBands.from_file(data.ref_file("si_nscf_GSR.nc")) # Hack eigens to simulate free-electron bands. This will produce all(effective masses == 1) new_eigens = np.empty(ebands.shape) branch = 0.5 * units.Ha_to_eV * np.array([(k.norm * units.bohr_to_ang)**2 for k in ebands.kpoints]) for spin in ebands.spins: for band in range(ebands.mband): new_eigens[spin, :, band] = branch ebands._eigens = new_eigens effm_lines = ebands.effective_masses(spin=0, band=0, acc=2) # Flatten structure (.flatten does not work in this case) values = [] for arr in effm_lines: values.extend(arr) self.assertArrayAlmostEqual(np.array(values), 1.0)
def test_api(self): """Test ElelectronDosPlotter API.""" gsr_path = abidata.ref_file("si_scf_GSR.nc") gs_bands = ElectronBands.from_file(gsr_path) edos = gs_bands.get_edos() plotter = ElectronDosPlotter() plotter.add_edos("edos1", edos) plotter.add_edos("edos2", gsr_path, edos_kwargs=dict(method="gaussian", step=0.2, width=0.4)) assert len(plotter.edos_list) == 2 if self.has_matplotlib(): plotter.combiplot(show=False) plotter.gridplot(show=False) if self.has_nbformat(): plotter.write_notebook(nbpath=self.get_tmpname(text=True))
def test_dos(self): """Test DOS methods.""" gs_bands = ElectronBands.from_file(abidata.ref_file("si_scf_GSR.nc")) assert not gs_bands.has_metallic_scheme # Test get_e0 assert gs_bands.get_e0("fermie") == gs_bands.fermie assert gs_bands.get_e0(None) == 0.0 assert gs_bands.get_e0("None") == 0.0 assert gs_bands.get_e0(1.0) == 1.0 edos = gs_bands.get_edos() print(edos) assert ElectronDos.as_edos(edos, {}) is edos edos_samevals = ElectronDos.as_edos(gs_bands, {}) assert ElectronDos.as_edos(gs_bands, {}) == edos assert ElectronDos.as_edos(abidata.ref_file("si_scf_GSR.nc"), {}) == edos mu = edos.find_mu(8) imu = edos.tot_idos.find_mesh_index(mu) self.assert_almost_equal(edos.tot_idos[imu][1], 8, decimal=2) d, i = edos.dos_idos(spin=0) tot_d, tot_i = edos.dos_idos() self.assert_almost_equal(2 * d.values, tot_d.values) self.assert_almost_equal(2 * i.values, tot_i.values) self.serialize_with_pickle(edos, protocols=[-1], test_eq=False) # Test plot methods if self.has_matplotlib(): edos.plot(show=False) edos.plot_dos_idos(show=False) edos.plot_up_minus_down(show=False) gs_bands.plot_with_edos(dos=edos, show=False) if self.has_seaborn(): gs_bands.boxplot(show=False)
def test_nickel_ebands_spin(self): """Testing Nickel electron bands with nsppol == 2""" ref_nelect = 18 ni_ebands_kmesh = ElectronBands.from_file( abidata.ref_file("ni_666k_GSR.nc")) assert ElectronBands.as_ebands(ni_ebands_kmesh) is ni_ebands_kmesh with self.assertRaises(TypeError): ElectronBands.as_ebands(1) repr(ni_ebands_kmesh) str(ni_ebands_kmesh) assert ni_ebands_kmesh.nsppol == 2 and ni_ebands_kmesh.nspinor == 1 and ni_ebands_kmesh.nspden == 2 assert ni_ebands_kmesh.nelect == ref_nelect assert ni_ebands_kmesh.kpoints.is_ibz and ni_ebands_kmesh.has_bzmesh and not ni_ebands_kmesh.has_bzpath assert ni_ebands_kmesh.has_timrev assert ni_ebands_kmesh.has_metallic_scheme smearing = ni_ebands_kmesh.smearing assert smearing.has_metallic_scheme assert smearing.occopt == 7 self.assert_almost_equal(smearing.tsmear_ev.to("Ha"), 0.0075) assert smearing.scheme == "gaussian" ni_ebands_kmesh.copy() ni_ebands_kmesh.deepcopy() ni_edos = ni_ebands_kmesh.get_edos() repr(ni_edos) str(ni_edos) assert ni_edos.to_string(verbose=2) # Get ElectronDosPlotter with nsppol == 2 and test matplotlib methods. edos_plotter = ni_ebands_kmesh.compare_gauss_edos(widths=[0.2, 0.4], step=0.2) assert len(edos_plotter) == 2 if self.has_matplotlib(): # Combiplot. assert edos_plotter.combiplot(title="default values", show=False) assert edos_plotter.combiplot(what_list=("dos", "idos"), spin_mode="resolved", show=False) assert edos_plotter.combiplot(e0=0, what_list="dos", spin_mode="resolved", fontsize=12, show=False) # Gridplot assert edos_plotter.gridplot(title="default values", show=False) assert edos_plotter.gridplot(what="idos", spin_mode="resolved", xlims=(-10, 10), show=False) assert edos_plotter.gridplot(e0=0, what="dos", spin_mode="resolved", fontsize=12, show=False) ni_ebands_kpath = ElectronBands.from_file( abidata.ref_file("ni_kpath_GSR.nc")) assert not ni_ebands_kpath.has_linewidths ni_ebands_kpath.linewidths = np.ones(ni_ebands_kpath.shape) assert ni_ebands_kpath.has_linewidths repr(ni_ebands_kpath) str(ni_ebands_kpath) assert ni_ebands_kpath.nsppol == 2 and ni_ebands_kpath.nspinor == 1 and ni_ebands_kpath.nspden == 2 assert ni_ebands_kpath.nelect == ref_nelect assert ni_ebands_kpath.kpoints.is_path and not ni_ebands_kpath.has_bzmesh and ni_ebands_kpath.has_bzpath assert ni_ebands_kpath.has_timrev assert ni_ebands_kpath.fermie == ni_ebands_kmesh.fermie # Serialization self.serialize_with_pickle(ni_ebands_kpath, test_eq=False) self.assertMSONable(ni_ebands_kpath, test_if_subclass=False) assert len(ni_ebands_kpath.to_json()) od = ni_ebands_kmesh.get_dict4pandas(with_spglib=False) assert od["nsppol"] == 2 and od["nspinor"] == 1 and od["nspden"] == 2 df = ni_ebands_kpath.get_dataframe() ni_ebands_kpath.to_xmgrace(self.get_tmpname(text=True)) ni_ebands_kpath.to_xmgrace(sys.stdout) # BXSF cannot be produced because. #ngkpt 6 6 6 #nshiftk 4 #shiftk 1/2 1/2 1/2 1/2 0.0 0.0 0.0 1/2 0.0 0.0 0.0 1/2 with self.assertRaises(ValueError): ni_ebands_kmesh.to_bxsf(self.get_tmpname(text=True)) # Interpolation r = ni_ebands_kmesh.interpolate(lpratio=10, kmesh=[8, 8, 8], verbose=1) assert r.ebands_kpath is not None assert r.ebands_kpath.kpoints.is_path assert not r.ebands_kpath.kpoints.is_ibz mpdivs, shifts = r.ebands_kpath.kpoints.mpdivs_shifts assert mpdivs is None and shifts is None assert r.ebands_kmesh is not None assert r.ebands_kmesh.kpoints.is_ibz assert not r.ebands_kmesh.kpoints.is_path assert r.ebands_kmesh.kpoints.ksampling is not None assert r.ebands_kmesh.kpoints.is_mpmesh mpdivs, shifts = r.ebands_kmesh.kpoints.mpdivs_shifts self.assert_equal(mpdivs, [8, 8, 8]) self.assert_equal(shifts.flatten(), [0, 0, 0]) # Test __add__ and __radd__ (should return ElectronBandsPlotter) p = ni_ebands_kmesh + r.ebands_kmesh + r.ebands_kpath assert hasattr(p, "combiplot") # Test plot methods if self.has_matplotlib(): elims = [-10, 2] assert ni_ebands_kmesh.plot(show=False) assert ni_ebands_kmesh.plot_bz(show=False) assert ni_ebands_kpath.plot(ylims=elims, show=False) assert ni_ebands_kpath.plot_with_edos(ni_edos, ylims=elims, show=False) assert ni_ebands_kpath.plot_bz(show=False) assert ni_ebands_kpath.plot_transitions(4.4, qpt=(0, 0, 0), atol_ev=0.1, atol_kdiff=1e-4, show=False) assert ni_ebands_kpath.plot_transitions(4.4, qpt=(0.03, 0, 0), atol_ev=0.5, atol_kdiff=0.2, show=False) assert ni_ebands_kpath.plot_scatter3d(spin=0, band=8, show=False) assert ni_edos.plot(xlims=elims, show=False) assert ni_edos.plot_dos_idos(xlims=elims, show=False) assert ni_edos.plot_up_minus_down(xlims=elims, show=False) # Test linewidths assert ni_ebands_kmesh.plot_lws_vs_e0(show=False) is None assert ni_ebands_kpath.plot_lws_vs_e0(show=False) # TODO Generaliza jdos to metals. #vrange, crange = range(0, 4), range(4, 5) #assert ni_ebands_kmesh.plot_ejdosvc(vrange, crange, cumulative=False, show=False) #assert ni_ebands_kmesh.plot_ejdosvc(vrange, crange, cumulative=True, show=False) if self.has_seaborn(): assert ni_ebands_kmesh.boxplot( brange=[5, 10], show=False, title="Boxplot for up and down spin and 10 > band >= 5") # Test Abipy --> Pymatgen converter. pmg_bands_kpath = ni_ebands_kpath.to_pymatgen() assert hasattr(pmg_bands_kpath, "get_branch") # Should be BandStructureSymmLine assert pmg_bands_kpath.efermi == ni_ebands_kpath.fermie assert pmg_bands_kpath.is_spin_polarized assert pmg_bands_kpath.is_metal() # Test Pymatgen --> Abipy converter. same_ekpath = ElectronBands.from_pymatgen(pmg_bands_kpath, ni_ebands_kpath.nelect) repr(same_ekpath) str(same_ekpath) self.assert_equal(same_ekpath.eigens, ni_ebands_kpath.eigens) assert same_ekpath.fermie == ni_ebands_kpath.fermie pmg_bands_kmesh = ni_ebands_kmesh.to_pymatgen() #assert hasattr(pmg_bands_kmesh, "get_branch") # Should be BandStructure assert pmg_bands_kmesh.efermi == ni_ebands_kmesh.fermie assert pmg_bands_kmesh.is_spin_polarized assert pmg_bands_kmesh.is_metal() # Test Pymatgen --> Abipy converter. same_ekmesh = ElectronBands.from_pymatgen(pmg_bands_kmesh, ni_ebands_kmesh.nelect) self.assert_equal(same_ekmesh.eigens, ni_ebands_kmesh.eigens) assert same_ekmesh.fermie == ni_ebands_kmesh.fermie
def test_read_ebands_from_WFK(self): """Read ElectronBands from WFK files.""" for filename in data.WFK_NCFILES: ebands = ElectronBands.from_file(filename)
def test_silicon_ebands(self): """Testing electron bands with nsppol == 1""" si_ebands_kmesh = ElectronBands.from_file(abidata.ref_file("si_scf_GSR.nc")) assert not si_ebands_kmesh.has_metallic_scheme repr(si_ebands_kmesh); str(si_ebands_kmesh) assert si_ebands_kmesh.to_string(title="Title", with_structure=False, with_kpoints=True, verbose=1) for spin, ik, band in si_ebands_kmesh.skb_iter(): assert spin == 0 assert si_ebands_kmesh.nkpt >= ik >= 0 assert si_ebands_kmesh.nband_sk[spin, ik] >= band >= 0 # Test ElectronBands get_e0 assert si_ebands_kmesh.get_e0("fermie") == si_ebands_kmesh.fermie assert si_ebands_kmesh.get_e0(None) == 0.0 assert si_ebands_kmesh.get_e0("None") == 0.0 assert si_ebands_kmesh.get_e0(1.0) == 1.0 with self.assertRaises(ValueError): si_ebands_kmesh.get_e0("foo") r = si_ebands_kmesh.with_points_along_path(knames=["G", "X", "L", "G"]) assert r.ebands.kpoints.is_path assert r.ebands.kpoints[0].is_gamma assert r.ebands.kpoints[0] == r.ebands.kpoints[-1] assert si_ebands_kmesh.kpoints[r.ik_new2prev[0]].is_gamma # Serialization self.serialize_with_pickle(si_ebands_kmesh, test_eq=False) self.assertMSONable(si_ebands_kmesh, test_if_subclass=False) assert len(si_ebands_kmesh.to_json()) dless_states = si_ebands_kmesh.dispersionless_states() assert not dless_states estats = si_ebands_kmesh.spacing() self.assert_almost_equal(estats.mean, 2.3100587301616917) self.assert_almost_equal(estats.stdev, 2.164400652355628) self.assert_almost_equal(estats.min, 0) self.assert_almost_equal(estats.max, 11.855874158768694) repr(estats); str(estats) with self.assertRaises(NotImplementedError): si_ebands_kmesh.get_edos(method="tetrahedron") si_edos = si_ebands_kmesh.get_edos() repr(si_edos); str(si_edos) assert ElectronDos.as_edos(si_edos, {}) is si_edos assert si_edos == si_edos and not (si_edos != si_edos) edos_samevals = ElectronDos.as_edos(si_ebands_kmesh, {}) assert ElectronDos.as_edos(si_ebands_kmesh, {}) == si_edos assert ElectronDos.as_edos(abidata.ref_file("si_scf_GSR.nc"), {}) == si_edos with self.assertRaises(TypeError): ElectronDos.as_edos({}, {}) mu = si_edos.find_mu(8) imu = si_edos.tot_idos.find_mesh_index(mu) self.assert_almost_equal(si_edos.tot_idos[imu][1], 8, decimal=2) d, i = si_edos.dos_idos(spin=0) tot_d, tot_i = si_edos.dos_idos() self.assert_almost_equal(2 * d.values, tot_d.values) self.assert_almost_equal(2 * i.values, tot_i.values) self.assert_equal(si_edos.up_minus_down.mesh, si_edos.tot_dos.mesh) self.assert_equal(si_edos.up_minus_down.values, 0) # Test ElectronDos get_e0 assert si_edos.get_e0("fermie") == si_edos.fermie assert si_edos.get_e0(None) == 0.0 assert si_edos.get_e0("None") == 0.0 assert si_edos.get_e0(1.0) == 1.0 with self.assertRaises(TypeError): si_edos.get_e0("foo") self.serialize_with_pickle(si_edos, protocols=[-1], test_eq=False) # Test plot methods if self.has_matplotlib(): klabels = { (0,0,0): "$\Gamma$", (0.375, 0.375, 0.7500): "K", (0.5, 0.5, 1.0): "X", (0.5, 0.5, 0.5): "L", (0.5, 0.0, 0.5): "X", (0.5, 0.25, 0.75): "W", } assert si_edos.plot(show=False) assert si_edos.plot_dos_idos(show=False) assert si_edos.plot_up_minus_down(show=False) assert si_ebands_kmesh.plot_with_edos(edos=si_edos, klabels=klabels, with_gaps=True, show=False) assert si_ebands_kmesh.kpoints.plot(show=False) vrange, crange = range(0, 4), range(4, 5) assert si_ebands_kmesh.plot_ejdosvc(vrange, crange, cumulative=False, show=False) assert si_ebands_kmesh.plot_ejdosvc(vrange, crange, cumulative=True, show=False) assert si_ebands_kmesh.kpoints.plot(show=False) if self.has_seaborn(): assert si_ebands_kmesh.boxplot(swarm=True, show=False) if self.has_ipywidgets(): assert si_ebands_kmesh.ipw_edos_widget() # Test Abipy --> Pymatgen converter. pmg_bands_kmesh = si_ebands_kmesh.to_pymatgen() assert pmg_bands_kmesh.efermi == si_ebands_kmesh.fermie assert not pmg_bands_kmesh.is_spin_polarized #assert not pmg_bands_kmesh.is_metal() # Test Pymatgen --> Abipy converter. same_ekmesh = ElectronBands.from_pymatgen(pmg_bands_kmesh, si_ebands_kmesh.nelect) repr(same_ekmesh); str(same_ekmesh) self.assert_equal(same_ekmesh.eigens, si_ebands_kmesh.eigens) assert same_ekmesh.fermie == si_ebands_kmesh.fermie assert len(same_ekmesh.kpoints) == len(pmg_bands_kmesh.kpoints) # Test JDOS methods. spin = 0 conduction = [4,] for v in range(1, 5): valence = range(0, v) jdos = si_ebands_kmesh.get_ejdos(spin, valence, conduction) intg = jdos.integral()[-1][-1] self.assert_almost_equal(intg, len(conduction) * len(valence)) self.serialize_with_pickle(jdos, protocols=[-1]) si_ebands_kpath = ElectronBands.from_file(abidata.ref_file("si_nscf_GSR.nc")) diffs = si_ebands_kpath.statdiff(si_ebands_kpath) assert diffs is not None repr(diffs); str(diffs) h**o = si_ebands_kpath.homos[0] repr(h**o); str(h**o) assert h**o.spin == 0 and h**o.occ == 2.0 and h**o.band == 3 assert h**o.kpoint == [0, 0, 0] assert h**o == h**o assert si_ebands_kpath.kpoints[h**o.kidx] == h**o.kpoint self.assert_almost_equal(h**o.eig, 5.5983129712050665) assert "eig" in h**o.__class__.get_fields() lumo = si_ebands_kpath.lumos[0] assert h**o != lumo assert lumo.spin == 0 and lumo.occ == 0.0 and lumo.band == 4 self.assert_almost_equal(lumo.kpoint.frac_coords, [0., 0.4285714, 0.4285714]) assert si_ebands_kpath.kpoints[lumo.kidx] == lumo.kpoint self.assert_almost_equal(lumo.eig, 6.1226526474610843) dir_gap = si_ebands_kpath.direct_gaps[0] fun_gap = si_ebands_kpath.fundamental_gaps[0] assert fun_gap.energy <= dir_gap.energy assert dir_gap.qpoint == [0, 0, 0] assert dir_gap.is_direct assert dir_gap == dir_gap assert dir_gap != fun_gap assert si_ebands_kpath.get_gaps_string() #print("repr_fun_gap", repr(fun_gap), id(fun_gap), id(fun_gap.qpoint)) #print("repr_dir_gap", repr(dir_gap), id(dir_gap), id(dir_gap.qpoint)) self.assert_almost_equal(dir_gap.energy, 2.5318279814319133) self.assert_almost_equal(fun_gap.qpoint.frac_coords, [0., 0.4285714, 0.4285714]) self.assert_almost_equal(fun_gap.energy, 0.52433967625601774) assert not fun_gap.is_direct e1 = si_ebands_kpath.lomo_sk(spin=0, kpoint=0) e2 = si_ebands_kpath.lomo_sk(spin=0, kpoint=si_ebands_kpath.kpoints[0]) assert e1.eig == e2.eig # Test abipy-->pymatgen converter pmg_bands_kpath = si_ebands_kpath.to_pymatgen() assert hasattr(pmg_bands_kpath, "get_branch") # Should be BandStructureSymmLine assert pmg_bands_kpath.efermi == si_ebands_kpath.fermie assert not pmg_bands_kpath.is_spin_polarized assert not pmg_bands_kpath.is_metal() # Test the detection of denerate states. degs = si_ebands_kpath.degeneracies(spin=0, kpoint=[0, 0, 0], bands_range=range(8)) ref_degbands = [[0], [1, 2, 3], [4, 5, 6], [7]] for i, (e, deg_bands) in enumerate(degs): self.assertEqual(deg_bands, ref_degbands[i]) # Test Electron e1 = si_ebands_kpath._electron_state(spin=0, kpoint=[0, 0, 0], band=0) repr(e1); str(e1) e1_copy = e1.copy() assert isinstance(e1.as_dict(), dict) assert isinstance(e1.to_strdict(), dict) assert e1.spin == 0 assert e1.skb[0] == 0 str(e1.tips) # JDOS requires a homogeneous sampling. with self.assertRaises(ValueError): si_ebands_kpath.get_ejdos(spin, 0, 4) if self.has_matplotlib(): assert si_ebands_kpath.plot(spin=0, e0=0, with_gaps=True, max_phfreq=0.1, show=False)
def test_silicon_ebands(self): """Testing electron bands with nsppol == 1""" si_ebands_kmesh = ElectronBands.from_file( abidata.ref_file("si_scf_GSR.nc")) assert not si_ebands_kmesh.has_metallic_scheme repr(si_ebands_kmesh) str(si_ebands_kmesh) assert si_ebands_kmesh.to_string(title="Title", with_structure=False, with_kpoints=True, verbose=1) for spin, ik, band in si_ebands_kmesh.skb_iter(): assert spin == 0 assert si_ebands_kmesh.nkpt >= ik >= 0 assert si_ebands_kmesh.nband_sk[spin, ik] >= band >= 0 # Test ElectronBands get_e0 assert si_ebands_kmesh.get_e0("fermie") == si_ebands_kmesh.fermie assert si_ebands_kmesh.get_e0(None) == 0.0 assert si_ebands_kmesh.get_e0("None") == 0.0 assert si_ebands_kmesh.get_e0(1.0) == 1.0 with self.assertRaises(ValueError): si_ebands_kmesh.get_e0("foo") # Serialization self.serialize_with_pickle(si_ebands_kmesh, test_eq=False) self.assertMSONable(si_ebands_kmesh, test_if_subclass=False) assert len(si_ebands_kmesh.to_json()) dless_states = si_ebands_kmesh.dispersionless_states() assert not dless_states estats = si_ebands_kmesh.spacing() self.assert_almost_equal(estats.mean, 2.3100587301616917) self.assert_almost_equal(estats.stdev, 2.164400652355628) self.assert_almost_equal(estats.min, 0) self.assert_almost_equal(estats.max, 11.855874158768694) repr(estats) str(estats) with self.assertRaises(NotImplementedError): si_ebands_kmesh.get_edos(method="tetrahedron") si_edos = si_ebands_kmesh.get_edos() repr(si_edos) str(si_edos) assert ElectronDos.as_edos(si_edos, {}) is si_edos assert si_edos == si_edos and not (si_edos != si_edos) edos_samevals = ElectronDos.as_edos(si_ebands_kmesh, {}) assert ElectronDos.as_edos(si_ebands_kmesh, {}) == si_edos assert ElectronDos.as_edos(abidata.ref_file("si_scf_GSR.nc"), {}) == si_edos with self.assertRaises(TypeError): ElectronDos.as_edos({}, {}) mu = si_edos.find_mu(8) imu = si_edos.tot_idos.find_mesh_index(mu) self.assert_almost_equal(si_edos.tot_idos[imu][1], 8, decimal=2) d, i = si_edos.dos_idos(spin=0) tot_d, tot_i = si_edos.dos_idos() self.assert_almost_equal(2 * d.values, tot_d.values) self.assert_almost_equal(2 * i.values, tot_i.values) self.assert_equal(si_edos.up_minus_down.mesh, si_edos.tot_dos.mesh) self.assert_equal(si_edos.up_minus_down.values, 0) # Test ElectronDos get_e0 assert si_edos.get_e0("fermie") == si_edos.fermie assert si_edos.get_e0(None) == 0.0 assert si_edos.get_e0("None") == 0.0 assert si_edos.get_e0(1.0) == 1.0 with self.assertRaises(TypeError): si_edos.get_e0("foo") self.serialize_with_pickle(si_edos, protocols=[-1], test_eq=False) # Test plot methods if self.has_matplotlib(): klabels = { (0, 0, 0): "$\Gamma$", (0.375, 0.375, 0.7500): "K", (0.5, 0.5, 1.0): "X", (0.5, 0.5, 0.5): "L", (0.5, 0.0, 0.5): "X", (0.5, 0.25, 0.75): "W", } assert si_edos.plot(show=False) assert si_edos.plot_dos_idos(show=False) assert si_edos.plot_up_minus_down(show=False) assert si_ebands_kmesh.plot_with_edos(edos=si_edos, klabels=klabels, show=False) assert si_ebands_kmesh.kpoints.plot(show=False) vrange, crange = range(0, 4), range(4, 5) assert si_ebands_kmesh.plot_ejdosvc(vrange, crange, cumulative=False, show=False) assert si_ebands_kmesh.plot_ejdosvc(vrange, crange, cumulative=True, show=False) assert si_ebands_kmesh.kpoints.plot(show=False) if self.has_seaborn(): assert si_ebands_kmesh.boxplot(swarm=True, show=False) if self.has_ipywidgets(): assert si_ebands_kmesh.ipw_edos_widget() # Test Abipy --> Pymatgen converter. pmg_bands_kmesh = si_ebands_kmesh.to_pymatgen() assert pmg_bands_kmesh.efermi == si_ebands_kmesh.fermie assert not pmg_bands_kmesh.is_spin_polarized #assert not pmg_bands_kmesh.is_metal() # Test Pymatgen --> Abipy converter. same_ekmesh = ElectronBands.from_pymatgen(pmg_bands_kmesh, si_ebands_kmesh.nelect) repr(same_ekmesh) str(same_ekmesh) self.assert_equal(same_ekmesh.eigens, si_ebands_kmesh.eigens) assert same_ekmesh.fermie == si_ebands_kmesh.fermie assert len(same_ekmesh.kpoints) == len(pmg_bands_kmesh.kpoints) # Test JDOS methods. spin = 0 conduction = [ 4, ] for v in range(1, 5): valence = range(0, v) jdos = si_ebands_kmesh.get_ejdos(spin, valence, conduction) intg = jdos.integral()[-1][-1] self.assert_almost_equal(intg, len(conduction) * len(valence)) self.serialize_with_pickle(jdos, protocols=[-1]) si_ebands_kpath = ElectronBands.from_file( abidata.ref_file("si_nscf_GSR.nc")) diffs = si_ebands_kpath.statdiff(si_ebands_kpath) assert diffs is not None repr(diffs) str(diffs) h**o = si_ebands_kpath.homos[0] repr(h**o) str(h**o) assert h**o.spin == 0 and h**o.occ == 2.0 and h**o.band == 3 assert h**o.kpoint == [0, 0, 0] assert si_ebands_kpath.kpoints[h**o.kidx] == h**o.kpoint self.assert_almost_equal(h**o.eig, 5.5983129712050665) assert "eig" in h**o.__class__.get_fields() lumo = si_ebands_kpath.lumos[0] assert lumo.spin == 0 and lumo.occ == 0.0 and lumo.band == 4 self.assert_almost_equal(lumo.kpoint.frac_coords, [0., 0.4285714, 0.4285714]) assert si_ebands_kpath.kpoints[lumo.kidx] == lumo.kpoint self.assert_almost_equal(lumo.eig, 6.1226526474610843) dir_gap = si_ebands_kpath.direct_gaps[0] fun_gap = si_ebands_kpath.fundamental_gaps[0] assert fun_gap.energy <= dir_gap.energy assert dir_gap.qpoint == [0, 0, 0] assert dir_gap.is_direct #print("repr_fun_gap", repr(fun_gap), id(fun_gap), id(fun_gap.qpoint)) #print("repr_dir_gap", repr(dir_gap), id(dir_gap), id(dir_gap.qpoint)) self.assert_almost_equal(dir_gap.energy, 2.5318279814319133) self.assert_almost_equal(fun_gap.qpoint.frac_coords, [0., 0.4285714, 0.4285714]) self.assert_almost_equal(fun_gap.energy, 0.52433967625601774) assert not fun_gap.is_direct e1 = si_ebands_kpath.lomo_sk(spin=0, kpoint=0) e2 = si_ebands_kpath.lomo_sk(spin=0, kpoint=si_ebands_kpath.kpoints[0]) assert e1.eig == e2.eig # Test abipy-->pymatgen converter pmg_bands_kpath = si_ebands_kpath.to_pymatgen() assert hasattr(pmg_bands_kpath, "get_branch") # Should be BandStructureSymmLine assert pmg_bands_kpath.efermi == si_ebands_kpath.fermie assert not pmg_bands_kpath.is_spin_polarized assert not pmg_bands_kpath.is_metal() # Test the detection of denerate states. degs = si_ebands_kpath.degeneracies(spin=0, kpoint=[0, 0, 0], bands_range=range(8)) ref_degbands = [[0], [1, 2, 3], [4, 5, 6], [7]] for i, (e, deg_bands) in enumerate(degs): self.assertEqual(deg_bands, ref_degbands[i]) # Test Electron e1 = si_ebands_kpath._electron_state(spin=0, kpoint=[0, 0, 0], band=0) repr(e1) str(e1) e1_copy = e1.copy() assert isinstance(e1.as_dict(), dict) assert isinstance(e1.to_strdict(), dict) assert e1.spin == 0 assert e1.skb[0] == 0 str(e1.tips) # JDOS requires a homogeneous sampling. with self.assertRaises(ValueError): si_ebands_kpath.get_ejdos(spin, 0, 4)
def test_pymatgen_converter(self): """Test abipy-->pymatgen converter""" nscf_bands = ElectronBands.from_file(data.ref_file("si_nscf_GSR.nc")) pmg_bands = nscf_bands.to_pymatgen()
def __init__(self, path): self.ks_bands = ElectronBands.from_file(path) self.nsppol = self.ks_bands.nsppol super(SigresReader, self).__init__(path) try: self.nomega_r = self.read_dimvalue("nomega_r") except self.Error: self.nomega_r = 0 #self.nomega_i = self.read_dim("nomega_i") # Save important quantities needed to simplify the API. self.structure = self.read_structure() self.gwcalctyp = self.read_value("gwcalctyp") self.usepawu = self.read_value("usepawu") # 1) The K-points of the homogeneous mesh. self.ibz = self.ks_bands.kpoints # 2) The K-points where QPState corrections have been calculated. gwred_coords = self.read_redc_gwkpoints() self.gwkpoints = KpointList(self.structure.reciprocal_lattice, gwred_coords) # minbnd[nkptgw,nsppol] gives the minimum band index computed # Note conversion between Fortran and python convention. self.gwbstart_sk = self.read_value("minbnd") - 1 self.gwbstop_sk = self.read_value("maxbnd") # min and Max band index for GW corrections. self.min_gwbstart = np.min(self.gwbstart_sk) self.max_gwbstart = np.max(self.gwbstart_sk) self.min_gwbstop = np.min(self.gwbstop_sk) self.max_gwbstop = np.max(self.gwbstop_sk) self._egw = self.read_value("egw", cmode="c") # Read and save important matrix elements. # All these arrays are dimensioned # vxcme(b1gw:b2gw,nkibz,nsppol*nsig_ab)) self._vxcme = self.read_value("vxcme") self._sigxme = self.read_value("sigxme") self._hhartree = self.read_value("hhartree", cmode="c") self._vUme = self.read_value("vUme") #if self.usepawu == 0: self._vUme.fill(0.0) # Complex arrays self._sigcmee0 = self.read_value("sigcmee0", cmode="c") self._ze0 = self.read_value("ze0", cmode="c") # Frequencies for the spectral function. if self.has_spfunc: self._omega_r = self.read_value("omega_r") self._sigcme = self.read_value("sigcme", cmode="c") self._sigxcme = self.read_value("sigxcme", cmode="c") # Self-consistent case self._en_qp_diago = self.read_value("en_qp_diago") # <KS|QPState> self._eigvec_qp = self.read_value("eigvec_qp", cmode="c")
def test_read_ebands_from_GSR(self): """Read ElectronBands from GSR files.""" for filename in data.GSR_NCFILES: ebands = ElectronBands.from_file(filename) ebands.to_pymatgen()
def test_read_ebands_from_GSR(self): """Read ElectronBands from GSR files.""" for filename in data.GSR_NCFILES: ebands = ElectronBands.from_file(filename)
def __init__(self, path): self.ks_bands = ElectronBands.from_file(path) self.nsppol = self.ks_bands.nsppol super(SIGRES_Reader, self).__init__(path) try: self.nomega_r = self.read_dimvalue("nomega_r") except self.Error: self.nomega_r = 0 #self.nomega_i = self.read_dim("nomega_i") # Save important quantities needed to simplify the API. self.structure = self.read_structure() self.gwcalctyp = self.read_value("gwcalctyp") self.usepawu = self.read_value("usepawu") # 1) The K-points of the homogeneous mesh. self.kpoints = kpoints_factory(self) # 2) The K-points where QPState corrections have been calculated. gwred_coords = self.read_redc_gwkpoints() self.gwkpoints = askpoints(gwred_coords, self.structure.reciprocal_lattice) # minbnd[nkptgw,nsppol] gives the minimum band index computed # Note conversion between Fortran and python convention. self.gwbstart_sk = self.read_value("minbnd") - 1 self.gwbstop_sk = self.read_value("maxbnd") # min and Max band index for GW corrections. self.min_gwbstart = np.min(self.gwbstart_sk) self.max_gwbstop = np.max(self.gwbstop_sk) self._egw = self.read_value("egw", cmode="c") # Read and save important matrix elements. # All these arrays are dimensioned # vxcme(b1gw:b2gw,nkibz,nsppol*nsig_ab)) self._vxcme = self.read_value("vxcme") self._sigxme = self.read_value("sigxme") self._hhartree = self.read_value("hhartree", cmode="c") self._vUme = self.read_value("vUme") #if self.usepawu == 0: self._vUme.fill(0.0) # Complex arrays self._sigcmee0 = self.read_value("sigcmee0", cmode="c") self._ze0 = self.read_value("ze0", cmode="c") # Frequencies for the spectral function. if self.has_spfunc: self._omega_r = self.read_value("omega_r") self._sigcme = self.read_value("sigcme", cmode="c") self._sigxcme = self.read_value("sigxcme", cmode="c") # Self-consistent case self._en_qp_diago = self.read_value("en_qp_diago") # <KS|QPState> self._eigvec_qp = self.read_value("eigvec_qp", cmode="c")
def test_nickel_ebands_spin(self): """Testing Nickel electron bands with nsppol == 2""" ref_nelect = 18 ni_ebands_kmesh = ElectronBands.from_file(abidata.ref_file("ni_666k_GSR.nc")) assert ElectronBands.as_ebands(ni_ebands_kmesh) is ni_ebands_kmesh with self.assertRaises(TypeError): ElectronBands.as_ebands(1) repr(ni_ebands_kmesh); str(ni_ebands_kmesh) assert ni_ebands_kmesh.nsppol == 2 and ni_ebands_kmesh.nspinor == 1 and ni_ebands_kmesh.nspden == 2 assert ni_ebands_kmesh.nelect == ref_nelect assert ni_ebands_kmesh.kpoints.is_ibz and ni_ebands_kmesh.has_bzmesh and not ni_ebands_kmesh.has_bzpath assert ni_ebands_kmesh.has_timrev assert ni_ebands_kmesh.has_metallic_scheme smearing = ni_ebands_kmesh.smearing assert smearing.has_metallic_scheme assert smearing.occopt == 7 self.assert_almost_equal(smearing.tsmear_ev.to("Ha"), 0.0075) assert smearing.scheme == "gaussian" assert not ni_ebands_kmesh.get_gaps_string() #ni_ebands_kmesh.copy() #ni_ebands_kmesh.deepcopy() ni_edos = ni_ebands_kmesh.get_edos() repr(ni_edos); str(ni_edos) assert ni_edos.to_string(verbose=2) # Get ElectronDosPlotter with nsppol == 2 and test matplotlib methods. edos_plotter = ni_ebands_kmesh.compare_gauss_edos(widths=[0.2, 0.4], step=0.2) assert len(edos_plotter) == 2 if self.has_matplotlib(): # Combiplot. assert edos_plotter.combiplot(title="default values", show=False) assert edos_plotter.combiplot(what_list=("dos", "idos"), spin_mode="resolved", show=False) assert edos_plotter.combiplot(e0=0, what_list="dos", spin_mode="automatic", fontsize=12, show=False) # Gridplot assert edos_plotter.gridplot(title="default values", show=False) assert edos_plotter.gridplot(what="idos", spin_mode="resolved", xlims=(-10, 10), show=False) assert edos_plotter.gridplot(e0=0, what="dos", spin_mode="resolved", fontsize=12, show=False) ni_ebands_kpath = ElectronBands.from_file(abidata.ref_file("ni_kpath_GSR.nc")) assert not ni_ebands_kpath.has_linewidths ni_ebands_kpath.linewidths = np.ones(ni_ebands_kpath.shape) assert ni_ebands_kpath.has_linewidths repr(ni_ebands_kpath); str(ni_ebands_kpath) assert ni_ebands_kpath.nsppol == 2 and ni_ebands_kpath.nspinor == 1 and ni_ebands_kpath.nspden == 2 assert ni_ebands_kpath.nelect == ref_nelect assert ni_ebands_kpath.kpoints.is_path and not ni_ebands_kpath.has_bzmesh and ni_ebands_kpath.has_bzpath assert ni_ebands_kpath.has_timrev assert ni_ebands_kpath.fermie == ni_ebands_kmesh.fermie # Serialization self.serialize_with_pickle(ni_ebands_kpath, test_eq=False) self.assertMSONable(ni_ebands_kpath, test_if_subclass=False) assert len(ni_ebands_kpath.to_json()) od = ni_ebands_kmesh.get_dict4pandas(with_spglib=False) assert od["nsppol"] == 2 and od["nspinor"] == 1 and od["nspden"] == 2 df = ni_ebands_kpath.get_dataframe() ni_ebands_kpath.to_xmgrace(self.get_tmpname(text=True)) ni_ebands_kpath.to_xmgrace(sys.stdout) # BXSF cannot be produced because. #ngkpt 6 6 6 #nshiftk 4 #shiftk 1/2 1/2 1/2 1/2 0.0 0.0 0.0 1/2 0.0 0.0 0.0 1/2 with self.assertRaises(ValueError): ni_ebands_kmesh.to_bxsf(self.get_tmpname(text=True)) # Interpolation r = ni_ebands_kmesh.interpolate(lpratio=10, kmesh=[8, 8, 8], verbose=1) assert r.ebands_kpath is not None assert r.ebands_kpath.kpoints.is_path assert not r.ebands_kpath.kpoints.is_ibz mpdivs, shifts = r.ebands_kpath.kpoints.mpdivs_shifts assert mpdivs is None and shifts is None assert r.ebands_kmesh is not None assert r.ebands_kmesh.kpoints.is_ibz assert not r.ebands_kmesh.kpoints.is_path assert r.ebands_kmesh.kpoints.ksampling is not None assert r.ebands_kmesh.kpoints.is_mpmesh mpdivs, shifts = r.ebands_kmesh.kpoints.mpdivs_shifts self.assert_equal(mpdivs, [8, 8, 8]) self.assert_equal(shifts.flatten(), [0, 0, 0]) # Test __add__ and __radd__ (should return ElectronBandsPlotter) p = ni_ebands_kmesh + r.ebands_kmesh + r.ebands_kpath assert hasattr(p, "combiplot") # Test plot methods if self.has_matplotlib(): elims = [-10, 2] assert ni_ebands_kmesh.plot(show=False) assert ni_ebands_kmesh.plot_bz(show=False) assert ni_ebands_kpath.plot(ylims=elims, with_gaps=True, show=False) assert ni_ebands_kpath.plot_with_edos(ni_edos, ylims=elims, show=False) assert ni_ebands_kpath.plot_bz(show=False) assert ni_ebands_kpath.plot_transitions(4.4, qpt=(0, 0, 0), atol_ev=0.1, atol_kdiff=1e-4, show=False) assert ni_ebands_kpath.plot_transitions(4.4, qpt=(0.03, 0, 0), atol_ev=0.5, atol_kdiff=0.2, show=False) assert ni_ebands_kpath.plot_scatter3d(spin=0, band=8, show=False) assert ni_edos.plot(xlims=elims, show=False) assert ni_edos.plot_dos_idos(xlims=elims, show=False) assert ni_edos.plot_up_minus_down(xlims=elims, show=False) # Test linewidths assert ni_ebands_kmesh.plot_lws_vs_e0(show=False) is None assert ni_ebands_kpath.plot_lws_vs_e0(show=False) # TODO Generaliza jdos to metals. #vrange, crange = range(0, 4), range(4, 5) #assert ni_ebands_kmesh.plot_ejdosvc(vrange, crange, cumulative=False, show=False) #assert ni_ebands_kmesh.plot_ejdosvc(vrange, crange, cumulative=True, show=False) if self.has_seaborn(): assert ni_ebands_kmesh.boxplot(brange=[5, 10], show=False, title="Boxplot for up and down spin and 10 > band >= 5") # Test Abipy --> Pymatgen converter. pmg_bands_kpath = ni_ebands_kpath.to_pymatgen() assert hasattr(pmg_bands_kpath, "get_branch") # Should be BandStructureSymmLine assert pmg_bands_kpath.efermi == ni_ebands_kpath.fermie assert pmg_bands_kpath.is_spin_polarized assert pmg_bands_kpath.is_metal() # Test Pymatgen --> Abipy converter. same_ekpath = ElectronBands.from_pymatgen(pmg_bands_kpath, ni_ebands_kpath.nelect) repr(same_ekpath); str(same_ekpath) self.assert_equal(same_ekpath.eigens, ni_ebands_kpath.eigens) assert same_ekpath.fermie == ni_ebands_kpath.fermie pmg_bands_kmesh = ni_ebands_kmesh.to_pymatgen() #assert hasattr(pmg_bands_kmesh, "get_branch") # Should be BandStructure assert pmg_bands_kmesh.efermi == ni_ebands_kmesh.fermie assert pmg_bands_kmesh.is_spin_polarized assert pmg_bands_kmesh.is_metal() # Test Pymatgen --> Abipy converter. same_ekmesh = ElectronBands.from_pymatgen(pmg_bands_kmesh, ni_ebands_kmesh.nelect) self.assert_equal(same_ekmesh.eigens, ni_ebands_kmesh.eigens) assert same_ekmesh.fermie == ni_ebands_kmesh.fermie