Esempio n. 1
0
def showElectronDosFrame(parent, filepath):
    """
    Read the electron bands from file filepath and shows an `ElectronDosFrame`.
    """
    bands = ElectronBands.from_file(filepath)
    title = "File: %s" % os.path.relpath(filepath)
    ElectronDosFrame(parent, bands, title=title).Show()
Esempio n. 2
0
    def test_jdos(self):
        """Test JDOS methods."""
        bands = ElectronBands.from_file(get_reference_file("si_WFK-etsf.nc"))

        spin = 0
        conduction = [4,]
        for v in range(1,5):
            valence = range(0,v)
            jdos = bands.get_jdos(spin, valence, conduction)
            intg = jdos.integral()[-1][-1]
            self.assert_almost_equal(intg, len(conduction) * len(valence))

        # Need a homogeneous sampling.
        with self.assertRaises(ValueError):
            bands = ElectronBands.from_file(get_reference_file("si_nscf_WFK-etsf.nc"))
            bands.get_jdos(spin, 0, 4)
Esempio n. 3
0
def showElectronDosFrame(parent, filepath):
    """
    Read the electron bands from file filepath and shows an `ElectronDosFrame`.
    """
    bands = ElectronBands.from_file(filepath)
    title = "File: %s" % os.path.relpath(filepath)
    ElectronDosFrame(parent, bands, title=title).Show()
Esempio n. 4
0
def showElectronBandsPlot(parent, filepath):
    """
    Read the electron bands from file filepath and plot the bands.
    """
    ebands = ElectronBands.from_file(filepath)
    title = "File: %s" % os.path.relpath(filepath)
    ebands.plot(title=title)
Esempio n. 5
0
    def model_from_ebands(cls, ebands, tmesh=(0, 300, 600), poorman_polaron=False):
        ebands = ElectronBands.as_ebands(ebands)

        ntemp = len(tmesh)
        nwr = 1000
        wr_step = 0.01

        aw = np.empty((ebands.nsppol, ebands.nkpt, ebands.mband, ntemp, nwr))
        aw_meshes = np.empty((ebands.nsppol, ebands.nkpt, ebands.mband, nwr))
        #aw: [nwr, ntemp, max_nbcalc, nkcalc, nsppol] array
        #aw_meshes: [max_nbcalc, nkcalc, nsppol] array with energy mesh in eV
        from abipy.tools.numtools import lorentzian
        from scipy.integrate import cumtrapz
        for spin in ebands.spins:
            for ik, kpt in enumerate(ebands.kpoints):
                for band in range(ebands.nband_sk[spin, ik]):
                    e0 = ebands.eigens[spin, ik, band]
                    emin = e0 - wr_step * (nwr // 2)
                    emax = e0 + wr_step * (nwr // 2)
                    emesh = np.linspace(emin, emax, num=nwr)
                    aw_meshes[spin, ik, band] = emesh
                    # Naive model: lorentzian centered on KS energy with T-dep broadening
                    for itemp, temp in enumerate(tmesh):
                        width = 0.2 + (temp / 300) * 0.2
                        avals = lorentzian(emesh, width=width, center=e0, height=None)
                        if poorman_polaron:
                            if band in (1, 2, 3) and kpt.norm < 0.3:
                                avals += 1.1 * lorentzian(emesh, width=0.1 * width, center=e0 - 0.4, height=None)
                            avals /= cumtrapz(avals, x=emesh)[-1]
                        aw[spin, ik, band, itemp] = avals

        return cls(ebands, aw, aw_meshes, tmesh)
Esempio n. 6
0
    def model_from_ebands(cls, ebands, tmesh=(0, 300, 600), poorman_polaron=False):
        ebands = ElectronBands.as_ebands(ebands)

        ntemp = len(tmesh)
        nwr =  1000
        wr_step = 0.01

        aw = np.empty((ebands.nsppol, ebands.nkpt, ebands.mband, ntemp, nwr))
        aw_meshes = np.empty((ebands.nsppol, ebands.nkpt, ebands.mband, nwr))
        #aw: [nwr, ntemp, max_nbcalc, nkcalc, nsppol] array
        #aw_meshes: [max_nbcalc, nkcalc, nsppol] array with energy mesh in eV
        from abipy.tools.numtools import lorentzian
        from scipy.integrate import cumtrapz
        for spin in ebands.spins:
            for ik, kpt in enumerate(ebands.kpoints):
                for band in range(ebands.nband_sk[spin, ik]):
                    e0 = ebands.eigens[spin, ik, band]
                    emin = e0 - wr_step * (nwr // 2)
                    emax = e0 + wr_step * (nwr // 2)
                    emesh = np.linspace(emin, emax, num=nwr)
                    aw_meshes[spin, ik, band] = emesh
                    # Naive model: lorentzian centered on KS energy with T-dep broadening
                    for itemp, temp in enumerate(tmesh):
                        width = 0.2 + (temp / 300) * 0.2
                        avals = lorentzian(emesh, width=width, center=e0, height=None)
                        if poorman_polaron:
                            if band in (1, 2, 3) and kpt.norm < 0.3:
                                avals += 1.1 * lorentzian(emesh, width=0.1 * width, center=e0 - 0.4, height=None)
                            avals /= cumtrapz(avals, x=emesh)[-1]
                        aw[spin, ik, band, itemp] = avals

        return cls(ebands, aw, aw_meshes, tmesh)
Esempio n. 7
0
def showElectronBandsPlot(parent, filepath):
    """
    Read the electron bands from file filepath and plot the bands.
    """
    ebands = ElectronBands.from_file(filepath)
    title = "File: %s" % os.path.relpath(filepath)
    ebands.plot(title=title)
Esempio n. 8
0
    def __init__(self, filepath):
        """
        Initialized the object from a Netcdf file.
        """
        super(WFK_File, self).__init__(filepath)

        # Initialize the  structure from file.
        self.structure = Structure.from_file(filepath)

        # Initialize the band energies.
        self.bands = ElectronBands.from_file(filepath)

        self.kpoints = kpoints_factory(filepath)
        self.nkpt = len(self.kpoints)

        with WFK_Reader(filepath) as reader:
            assert reader.has_pwbasis_set
            assert reader.cplex_ug == 2
            self.npwarr = reader.npwarr
            self.nband_sk = reader.nband_sk

            self.nspinor = reader.nspinor
            self.nsppol = reader.nsppol
            self.nspden = reader.nspden

        # FFT mesh (augmented divisions reported in the WFK file)
        self.fft_mesh = Mesh3D(reader.fft_divs, self.structure.lattice_vectors())

        # Build G-spheres for each k-point
        gspheres = len(self.kpoints) * [None]
        ecut = reader.ecut
        for k, kpoint in enumerate(self.kpoints):
            gvec_k, istwfk = reader.read_gvec_istwfk(k)
            gspheres[k] = GSphere(ecut, self.structure.reciprocal_lattice, kpoint, gvec_k, istwfk=istwfk)

        self._gspheres = tuple(gspheres)

        # Save reference to the reader.
        self.reader = reader
Esempio n. 9
0
 def test_dos(self):
     """Test DOS methods."""
     gs_bands = ElectronBands.from_file(get_reference_file("si_WFK-etsf.nc"))
     dos = gs_bands.get_dos()
     mu = dos.find_mu(8, atol=1.e-4)
     self.assert_almost_equal(mu, 6.1443350264585996, decimal=4)
Esempio n. 10
0
 def test_ncread_ebands(self):
     """Read ElectronBands from WFK data files"""
     for filename in WFK_NCFILES:
         bands = ElectronBands.from_file(filename)
Esempio n. 11
0
 def read_bands(self, path):
     try:
         self.bands = ElectronBands.from_file(path)
         ewx.ElectronDosFrame(bands=self.bands, parent=self).Show()
     except Exception:
         awx.showErrorMessage(self)
Esempio n. 12
0
def showElectronJdosFrame(parent, filepath):
    bands = ElectronBands.from_file(filepath)
    ElectronJdosFrame(parent, bands).Show()
Esempio n. 13
0
def showElectronDosFrame(parent, filepath):
    bands = ElectronBands.from_file(filepath)
    title = "File: %s" % os.path.relpath(filepath)
    ElectronDosFrame(parent, bands, title=title).Show()
Esempio n. 14
0
def showElectronJdosFrame(parent, filepath):
    """
    Read the electron bands from file filepath and shows an `ElectronJdosFrame`.
    """
    ebands = ElectronBands.from_file(filepath)
    ElectronJdosFrame(parent, ebands).Show()
Esempio n. 15
0
def showElectronBandsPlot(parent, filepath):
    ebands = ElectronBands.from_file(filepath)
    title = "File: %s" % os.path.relpath(filepath)
    ebands.plot(title=title)
Esempio n. 16
0
def showElectronJdosFrame(parent, filepath):
    """
    Read the electron bands from file filepath and shows an `ElectronJdosFrame`.
    """
    ebands = ElectronBands.from_file(filepath)
    ElectronJdosFrame(parent, ebands).Show()
Esempio n. 17
0
def showElectronDosFrame(parent, filepath):
    bands = ElectronBands.from_file(filepath)
    ElectronDosFrame(parent, bands, title="File: %s" % filepath).Show()
Esempio n. 18
0
def showElectronBandsPlot(parent, filepath):
    bands = ElectronBands.from_file(filepath)
    bands.plot(title="File: %s" % filepath)
Esempio n. 19
0
def build_scissors(options, args):
    import matplotlib.pyplot as plt
    from matplotlib.gridspec import GridSpec
    #gw_fname = raw_input('Enter the name of the GW file: ').strip()
    #
    # Init the corrections from gw_fname
    try:
        gw_fname = options.gw_files[0]
    except:
        show_examples_and_exit(1, err_msg = "GW file name must be specified")

    qp_corrections = read_GWFile(gw_fname)
    #
    # Construct the scissors operator for each spin.
    nsppol = len(qp_corrections)
    scissor_spin = list()
    for spin in range(nsppol):

        qpc = qp_corrections[spin].sort_by_energy()

        e0mesh = qpc.get_e0mesh()
        e0_min = np.min(e0mesh)
        e0_max = np.max(e0mesh)
        #print e0_min, e0_max

        corr = qpc.get_qpcorr()

        vb_idx = raw_input('Enter the index of the valence band maximum: ')
        vb_idx = int(vb_idx)

        h**o = qpc.max_e0(vb_idx)
        lumo = qpc.min_e0(vb_idx + 1)
        #print h**o, lumo

        #qpc.plot()

        ndomains = raw_input('How many fitting intervals do you want? (default is 2: valence/conduction): ')

        if ndomains:
            ndomains = int(ndomains)
            s = raw_input('Enter the boundaries for domains: ')
            tokens = s.split(",")
            domains = list()
            for t in tokens:
                bound = [float(v) for v in t.split()]
                domains.append(bound)
            print("Domains are: ", bound)
        else:
            ndomains = 2
            pad_hl = 0.1 / Ha_eV
            #h**o += 0.00000001
            #lumo -= 0.00000001
            domains = [(e0_min - pad_hl, h**o), (lumo, e0_max + pad_hl)]

        sciss = qpc.make_scissor(domains)

        qpc.plot(scissor=sciss)

        scissor_spin.append(sciss)

    #return scissor_spin
    # Save the list of objects with cPickle.
    # fname = "SCISSOR.cpickle"
    # fh = file(fname, mode="wb")
    # pickle.dump(scissor_spin, fh)
    # fh.close()

    #bst_fname = raw_input('Enter the name of the band structure file: ').strip()

    bst_fname = options.bands_file

    ks_bands = ElectronBands.from_file(bst_fname)

    qp_bands = ks_bands.apply_scissors(scissor_spin)

    # Plot the KS and the QPState band structures.
    fig = plt.figure()

    ax = fig.add_subplot(1, 1, 1)

    ax.grid(True)
    #ax.legend(loc="upper left")
    #title = None
    #if title: ax.set_title(title)

    ax.set_xlabel('k-point')
    ax.set_ylabel('Energy [eV]')

    for spin in range(ks_bands.nsppol):
        for band in range(ks_bands.mband):
            ks_bands.plot_ax(ax, spin, band)
            qp_bands.plot_ax(ax, spin, band)

    plt.show()

    #qp_bands.raw_print(fh=None, units="eV")

    # Write the GW file with the updated band structure.
    gw_fname = raw_input('Enter the name of the GW file: ').strip()
    if gw_fname: qp_bands.write_GWfile(gw_fname, ks_bands)