Ejemplo n.º 1
0
Archivo: dos.py Proyecto: zx-sdu/pygra
def dos_kpm(h,
            scale=10.0,
            ewindow=4.0,
            ne=1000,
            delta=0.01,
            ntries=10,
            nk=100):
    """Calculate the KDOS bands using the KPM"""
    hkgen = h.get_hk_gen()  # get generator
    tr = timing.Testimator("DOS")  # generate object
    if h.dimensionality == 0: nk = 0  # single kpoint
    ytot = np.zeros(ne)  # initialize
    for ik in range(nk):  # loop over kpoints
        tr.remaining(ik, nk)
        hk = hkgen(np.random.random(3))  # get Hamiltonian
        npol = int(scale / delta)  # number of polynomials
        (x, y) = kpm.tdos(hk,
                          scale=scale,
                          npol=npol,
                          ne=ne,
                          ewindow=ewindow,
                          ntries=ntries)  # compute
        ytot += y  # add contribution
    ytot /= nk  # normalize
    np.savetxt("DOS.OUT", np.matrix([x, ytot]).T)  # save in file
Ejemplo n.º 2
0
def kdos_bands(h,
               use_kpm=True,
               kpath=None,
               scale=10.0,
               ewindow=4.0,
               ne=1000,
               delta=0.01,
               ntries=10):
    """Calculate the KDOS bands using the KPM"""
    if not use_kpm: raise  # nope
    hkgen = h.get_hk_gen()  # get generator
    if kpath is None: kpath = klist.default(h.geometry)  # default
    fo = open("KDOS_BANDS.OUT", "w")  # open file
    ik = 0
    tr = timing.Testimator("KDOS")  # generate object
    for k in kpath:  # loop over kpoints
        tr.remaining(ik, len(kpath))
        hk = hkgen(k)  # get Hamiltonian
        npol = int(scale / delta)  # number of polynomials
        (x, y) = kpm.tdos(hk,
                          scale=scale,
                          npol=npol,
                          ne=ne,
                          ewindow=ewindow,
                          ntries=ntries)  # compute
        for (ix, iy) in zip(x, y):  # loop
            fo.write(str(ik / len(kpath)) + "   ")
            fo.write(str(ix) + "   ")
            fo.write(str(iy) + "\n")
        fo.flush()
        ik += 1
    fo.close()
Ejemplo n.º 3
0
Archivo: dos.py Proyecto: zx-sdu/pygra
def dos1d(h,
          use_kpm=False,
          scale=10.,
          nk=100,
          npol=100,
          ntries=2,
          ndos=1000,
          delta=0.01,
          ewindow=None,
          frand=None):
    """ Calculate density of states of a 1d system"""
    if h.dimensionality != 1: raise  # only for 1d
    ks = np.linspace(0., 1., nk, endpoint=False)  # number of kpoints
    if not use_kpm:  # conventional method
        hkgen = h.get_hk_gen()  # get generator
        #    delta = 16./(nk*h.intra.shape[0]) # smoothing
        calculate_dos_hkgen(hkgen, ks, ndos=ndos,
                            delta=delta)  # conventiona algorithm
    else:
        h.turn_sparse()  # turn the hamiltonian sparse
        hkgen = h.get_hk_gen()  # get generator
        yt = np.zeros(ndos)  # number of dos
        import kpm
        ts = timing.Testimator("DOS")
        for i in range(nk):  # loop over kpoints
            k = np.random.random(3)  # random k-point
            hk = hkgen(k)  # hamiltonian
            (xs, yi) = kpm.tdos(hk,
                                scale=scale,
                                npol=npol,
                                frand=frand,
                                ewindow=ewindow,
                                ntries=ntries,
                                ne=ndos)
            yt += yi  # Add contribution
            ts.remaining(i, nk)
        yt /= nk  # normalize
        write_dos(xs, yt)  # write in file
        print()
        return xs, yt
Ejemplo n.º 4
0
###############################################
## this a test with a 1d tight binding model ##
###############################################
n = 100000 # dimension of the matrix
print("Dimension of the matrix",n)
ii = np.arange(0,n-2) # indexes from 0 to n-2
cols = np.concatenate([ii,ii+1]) # index for rows
rows = np.concatenate([ii+1,ii]) # index for cols
data = np.zeros(cols.shape[0]) + 1. # tight binding parameter

m = csc_matrix((data,(rows,cols)),shape=(n,n)) # create the sparse matrix

site = n//2 # the entry where you want the dos, n/2 is an atom in the middle
scale = 4.0 # this number has to be such that max(|eigenvalues|)/scale < 1
npol = 300 # number of polynomials, energy resolution goes as 1/npol
ne = 300 # number of energies to calculate (between -scale and scale)
ntries = 10 # number of random vectors used
# returns energies and dos

t0 = time.clock()
(x1,y1) = kpm.tdos(m,ntries=ntries,scale=scale,npol=npol,ne=ne) 
t1 = time.clock()

print("Time in computation",t1-t0)



plt.plot(x1,y1) # plot this dos

plt.show()