Ejemplo n.º 1
0
def dos2d(h,use_kpm=True,scale=10.,nk=20,npol=100,ntries=100,delta=None,
          ndos=100):
  """ Calculate density of states of a 1d system"""
  if h.dimensionality!=2: raise # only for 2d
  ks = []
  for ik in np.linspace(0.,1.,nk,endpoint=False):
    for jk in np.linspace(0.,1.,nk,endpoint=False):
      ks.append(np.array([ik,jk])) # add point
  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: # use the kpm
    h.turn_sparse() # turn the hamiltonian sparse
    hkgen = h.get_hk_gen() # get generator
    mus = np.array([0.0j for i in range(2*npol)]) # initialize polynomials
    import kpm
    for k in ks: # loop over kpoints
      hk = hkgen(k) # hamiltonian
      mus += kpm.random_trace(hk/scale,ntries=ntries,n=npol)
    mus /= len(ks) # normalize by the number of kpoints
    xs = np.linspace(-0.9,0.9,npol) # x points
    ys = kpm.generate_profile(mus,xs) # generate the profile
    write_dos(xs*scale,ys) # write in file
    return
Ejemplo n.º 2
0
def kdos1d_sites(h,
                 sites=[0],
                 scale=10.,
                 nk=100,
                 npol=100,
                 kshift=0.,
                 ewindow=None,
                 info=False):
    """ Calculate kresolved density of states of
  a 1d system for a certain orbitals"""
    if h.dimensionality != 1: raise  # only for 1d
    ks = np.linspace(0., 1., nk)  # number of kpoints
    h.turn_sparse()  # turn the hamiltonian sparse
    hkgen = h.get_hk_gen()  # get generator
    if ewindow is None: xs = np.linspace(-0.9, 0.9, nk)  # x points
    else: xs = np.linspace(-ewindow / scale, ewindow / scale, nk)  # x points
    import kpm
    write_kdos()  # initialize file
    for k in ks:  # loop over kpoints
        mus = np.array([0.0j
                        for i in range(2 * npol)])  # initialize polynomials
        hk = hkgen(k + kshift)  # hamiltonian
        for isite in sites:
            mus += kpm.local_dos(hk / scale, i=isite, n=npol)
        ys = kpm.generate_profile(mus, xs)  # generate the profile
        write_kdos(k, xs * scale, ys, new=False)  # write in file (append)
        if info: print("Done", k)
Ejemplo n.º 3
0
def dos0d_kpm(h, use_kpm=True, scale=10, npol=100, ntries=100):
    """ Calculate density of states of a 1d system"""
    if h.dimensionality != 0: raise  # only for 0d
    if not use_kpm: raise  # only using KPM
    h.turn_sparse()  # turn the hamiltonian sparse
    mus = np.array([0.0j for i in range(2 * npol)])  # initialize polynomials
    import kpm
    mus = kpm.random_trace(h.intra / scale, ntries=ntries, n=npol)
    xs = np.linspace(-0.9, 0.9, 4 * npol)  # x points
    ys = kpm.generate_profile(mus, xs)  # generate the profile
    write_dos(xs * scale, ys)  # write in file
Ejemplo n.º 4
0
def dos0d_kpm(h,use_kpm=True,scale=10,npol=100,ntries=100,fun=None):
  """ Calculate density of states of a 1d system"""
  if h.dimensionality!=0: raise # only for 0d
  if not use_kpm: raise # only using KPM
  h.turn_sparse() # turn the hamiltonian sparse
  mus = np.array([0.0j for i in range(2*npol)]) # initialize polynomials
  import kpm
  mus = kpm.random_trace(h.intra/scale,ntries=ntries,n=npol,fun=fun)
  xs = np.linspace(-0.9,0.9,4*npol) # x points
  ys = kpm.generate_profile(mus,xs) # generate the profile
  write_dos(xs*scale,ys) # write in file
Ejemplo n.º 5
0
Archivo: dos.py Proyecto: zx-sdu/pygra
def dos2d(h,
          use_kpm=False,
          scale=10.,
          nk=100,
          ntries=1,
          delta=None,
          ndos=500,
          numw=20,
          random=True,
          kpm_window=1.0):
    """ Calculate density of states of a 2d system"""
    if h.dimensionality != 2: raise  # only for 2d
    ks = []
    from klist import kmesh
    ks = kmesh(h.dimensionality, nk=nk)
    if random:
        ks = [np.random.random(2) for ik in ks]
        print("Random k-mesh")
    if not use_kpm:  # conventional method
        hkgen = h.get_hk_gen()  # get generator
        if delta is None: delta = 6. / nk
        # conventiona algorithm
        calculate_dos_hkgen(hkgen,
                            ks,
                            ndos=ndos,
                            delta=delta,
                            is_sparse=h.is_sparse,
                            numw=numw)
    else:  # use the kpm
        npol = ndos // 10
        h.turn_sparse()  # turn the hamiltonian sparse
        hkgen = h.get_hk_gen()  # get generator
        mus = np.array([0.0j
                        for i in range(2 * npol)])  # initialize polynomials
        import kpm
        tr = timing.Testimator("DOS")
        ik = 0
        for k in ks:  # loop over kpoints
            #      print("KPM DOS at k-point",k)
            ik += 1
            tr.remaining(ik, len(ks))
            if random:
                kr = np.random.random(2)
                print("Random sampling in DOS")
                hk = hkgen(kr)  # hamiltonian
            else:
                hk = hkgen(k)  # hamiltonian
            mus += kpm.random_trace(hk / scale, ntries=ntries, n=npol)
        mus /= len(ks)  # normalize by the number of kpoints
        xs = np.linspace(-0.9, 0.9, ndos) * kpm_window  # x points
        ys = kpm.generate_profile(mus, xs)  # generate the profile
        write_dos(xs * scale, ys)  # write in file
        return (xs, ys)
Ejemplo n.º 6
0
def dos0d_sites(h,sites=[0],scale=10.,npol=500,ewindow=None,refine_e=1.0):
  """ Calculate density of states of a 1d system for a certain orbitals"""
  if h.dimensionality!=0: raise # only for 1d
  h.turn_sparse() # turn the hamiltonian sparse
  mus = np.array([0.0j for i in range(2*npol)]) # initialize polynomials
  import kpm
  hk = h.intra # hamiltonian
  for isite in sites:
    mus += kpm.local_dos(hk/scale,i=isite,n=npol)
  if ewindow is None:  xs = np.linspace(-0.9,0.9,int(npol*refine_e)) # x points
  else:  xs = np.linspace(-ewindow/scale,ewindow/scale,npol) # x points
  ys = kpm.generate_profile(mus,xs) # generate the profile
  write_dos(xs*scale,ys) # write in file
Ejemplo n.º 7
0
def dos1d(h,use_kpm=True,scale=10.,nk=100,npol=100,ntries=100):
  """ Calculate density of states of a 1d system"""
  if h.dimensionality!=1: raise # only for 1d
  if not use_kpm: raise # only using KPM
  ks = np.linspace(0.,1.,nk,endpoint=False) # number of kpoints
  h.turn_sparse() # turn the hamiltonian sparse
  hkgen = h.get_hk_gen() # get generator
  mus = np.array([0.0j for i in range(2*npol)]) # initialize polynomials
  import kpm
  for k in ks: # loop over kpoints
    hk = hkgen(k) # hamiltonian
    mus += kpm.random_trace(hk/scale,ntries=ntries,n=npol)
  mus /= nk # normalize by the number of kpoints
  xs = np.linspace(-0.9,0.9,4*npol) # x points
  ys = kpm.generate_profile(mus,xs) # generate the profile
  write_dos(xs*scale,ys) # write in file
Ejemplo n.º 8
0
def dos1d(h, use_kpm=True, scale=10., nk=100, npol=100, ntries=100):
    """ Calculate density of states of a 1d system"""
    if h.dimensionality != 1: raise  # only for 1d
    if not use_kpm: raise  # only using KPM
    ks = np.linspace(0., 1., nk, endpoint=False)  # number of kpoints
    h.turn_sparse()  # turn the hamiltonian sparse
    hkgen = h.get_hk_gen()  # get generator
    mus = np.array([0.0j for i in range(2 * npol)])  # initialize polynomials
    import kpm
    for k in ks:  # loop over kpoints
        hk = hkgen(k)  # hamiltonian
        mus += kpm.random_trace(hk / scale, ntries=ntries, n=npol)
    mus /= nk  # normalize by the number of kpoints
    xs = np.linspace(-0.9, 0.9, 4 * npol)  # x points
    ys = kpm.generate_profile(mus, xs)  # generate the profile
    write_dos(xs * scale, ys)  # write in file
Ejemplo n.º 9
0
def dos1d_sites(h,sites=[0],scale=10.,nk=100,npol=100,info=False,ewindow=None):
  """ Calculate density of states of a 1d system for a certain orbitals"""
  if h.dimensionality!=1: raise # only for 1d
  ks = np.linspace(0.,1.,nk,endpoint=False) # number of kpoints
  h.turn_sparse() # turn the hamiltonian sparse
  hkgen = h.get_hk_gen() # get generator
  mus = np.array([0.0j for i in range(2*npol)]) # initialize polynomials
  import kpm
  for k in ks: # loop over kpoints
    hk = hkgen(k) # hamiltonian
    for isite in sites:
      mus += kpm.local_dos(hk/scale,i=isite,n=npol)
    if info: print("Done",k)
  mus /= nk # normalize by the number of kpoints
  if ewindow is None:  xs = np.linspace(-0.9,0.9,npol) # x points
  else:  xs = np.linspace(-ewindow/scale,ewindow/scale,npol) # x points
  ys = kpm.generate_profile(mus,xs) # generate the profile
  write_dos(xs*scale,ys) # write in file
Ejemplo n.º 10
0
def kdos1d_sites(h,sites=[0],scale=10.,nk=100,npol=100,kshift=0.,
                  ewindow=None,info=False):
  """ Calculate kresolved density of states of
  a 1d system for a certain orbitals"""
  if h.dimensionality!=1: raise # only for 1d
  ks = np.linspace(0.,1.,nk) # number of kpoints
  h.turn_sparse() # turn the hamiltonian sparse
  hkgen = h.get_hk_gen() # get generator
  if ewindow is None:  xs = np.linspace(-0.9,0.9,nk) # x points
  else:  xs = np.linspace(-ewindow/scale,ewindow/scale,nk) # x points
  import kpm
  write_kdos() # initialize file
  for k in ks: # loop over kpoints
    mus = np.array([0.0j for i in range(2*npol)]) # initialize polynomials
    hk = hkgen(k+kshift) # hamiltonian
    for isite in sites:
      mus += kpm.local_dos(hk/scale,i=isite,n=npol)
    ys = kpm.generate_profile(mus,xs) # generate the profile
    write_kdos(k,xs*scale,ys,new=False) # write in file (append)
    if info: print "Done",k
Ejemplo n.º 11
0
Archivo: dos.py Proyecto: woal777/pygra
def dos1d_sites(h,
                sites=[0],
                scale=10.,
                nk=100,
                npol=100,
                info=False,
                ewindow=None):
    """ Calculate density of states of a 1d system for a certain orbitals"""
    if h.dimensionality != 1: raise  # only for 1d
    ks = np.linspace(0., 1., nk, endpoint=False)  # number of kpoints
    h.turn_sparse()  # turn the hamiltonian sparse
    hkgen = h.get_hk_gen()  # get generator
    mus = np.array([0.0j for i in range(2 * npol)])  # initialize polynomials
    import kpm
    for k in ks:  # loop over kpoints
        hk = hkgen(k)  # hamiltonian
        for isite in sites:
            mus += kpm.local_dos(hk / scale, i=isite, n=npol)
        if info: print "Done", k
    mus /= nk  # normalize by the number of kpoints
    if ewindow is None: xs = np.linspace(-0.9, 0.9, npol)  # x points
    else: xs = np.linspace(-ewindow / scale, ewindow / scale, npol)  # x points
    ys = kpm.generate_profile(mus, xs)  # generate the profile
    write_dos(xs * scale, ys)  # write in file
Ejemplo n.º 12
0
def write_surface_kpm(h,
                      ne=400,
                      klist=None,
                      scale=4.,
                      npol=200,
                      w=20,
                      ntries=20):
    """Write the surface DOS using the KPM"""
    if klist is None: klist = np.linspace(-.5, .5, 50)
    import kpm
    fo = open("KDOS.OUT", "w")  # open file
    for k in klist:
        print("Doing kpoint", k)
        if h.dimensionality == 2:
            (intra, inter) = h.kchain(k)  # k hamiltonian
            (es, ds, dsb) = kpm.edge_dos(intra,
                                         inter,
                                         scale=scale,
                                         w=w,
                                         npol=npol,
                                         ne=ne,
                                         bulk=True)
        # if the Hamiltonian is 1d from the beginning
        elif h.dimensionality == 1:
            intra, inter = h.intra, h.inter  # 1d hamiltonian
            dd = h.intra.shape[0]  # dimension
            inde = np.zeros(dd)  # array with zeros
            indb = np.zeros(dd)  # array with zeros
            for i in range(dd // 10):  # one tenth
                inde[i] = 1.  # use this one
                indb[4 * dd // 10 + i] = 1.  # use this one

            def gedge():
                return (np.random.random(len(inde)) - 0.5) * inde

            def gbulk():
                return (np.random.random(len(indb)) - 0.5) * (indb)

            # hamiltonian
            h0 = intra + inter * np.exp(1j * np.pi * 2. * k) + (
                inter * np.exp(1j * np.pi * 2. * k)).H
            xs = np.linspace(-0.9, 0.9, 4 * npol)  # x points
            es = xs * scale
            # calculate the bulk
            mus = kpm.random_trace(h0 / scale,
                                   ntries=ntries,
                                   n=npol,
                                   fun=gbulk)
            dsb = kpm.generate_profile(mus, xs)  # generate the profile
            # calculate the edge
            mus = kpm.random_trace(h0 / scale,
                                   ntries=ntries,
                                   n=npol,
                                   fun=gedge)
            ds = kpm.generate_profile(mus, xs)  # generate the profile
        else:
            raise
        for (e, d1, d2) in zip(es, ds, dsb):
            fo.write(
                str(k) + "   " + str(e) + "   " + str(d1) + "    " + str(d2) +
                "\n")
    fo.close()
Ejemplo n.º 13
0
import numpy as np
import pylab as py
import time
from numpy.random import random

import geometry

g = geometry.chain()
nrep = 40
g = g.supercell(nrep)
h = g.get_hamiltonian()

m = h.intra
m = m/6.
points = 200 # number of polynomials
t1 = time.clock()
musp = kpm.full_trace(m,use_fortran=False) # full trace
t2 = time.clock()
musf = kpm.full_trace(m,use_fortran=True) # full trace
t3 = time.clock()
print "FORTRAN ",t3-t2
print "Python  ",t2-t1

x = np.linspace(-.9,.9,points*10)
yp = kpm.generate_profile(musp,x) # python
yf = kpm.generate_profile(musf,x) # fortran
py.scatter(x,yp,label="Python",c="blue")
py.plot(x,yf,label="FORTRAN",c="green")
py.legend()
py.show()
Ejemplo n.º 14
0
import kpm  # kernel polynomial method
import numpy as np
import pylab as py

m = np.matrix([[0., 1.], [1., 0.]])  # default matrix
m = m / 2
mus = kpm.full_trace(m)  # full trace
points = 200  # number of polynomials
x = np.linspace(-.9, .9, points * 10)
y = kpm.generate_profile(mus, x)
py.plot(x, y)
py.show()
Ejemplo n.º 15
0
###############################################
## this a test with a 1d tight binding model ##
###############################################
n = 1000 # 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)
# returns energies and dos

# this function computes the different moments using the KPM
mus = kpm.get_moments_ldos(m,i=site,n=npol,scale=scale)

# once you have the moments, you can reconstruct the DOS
# using the Chebyshev relations
x = np.linspace(-0.9,0.9,400)
y = kpm.generate_profile(mus.real,x,kernel="jackson").real


# plot the result
plt.plot(x*scale,y/scale) # plot this dos
plt.show()
Ejemplo n.º 16
0
import kpm  # kernel polynomial method
import numpy as np
import pylab as py
import time
from numpy.random import random

m = np.matrix([[0., 1.], [1., 0.]])  # default matrix
ndim = 30
m = np.matrix(random((ndim, ndim))) - 1.
m += m.H
m = m / (2 * ndim)
points = 200  # number of polynomials
t1 = time.clock()
musp = kpm.full_trace(m, use_fortran=False)  # full trace
t2 = time.clock()
musf = kpm.full_trace(m, use_fortran=True)  # full trace
t3 = time.clock()
print "FORTRAN ", t3 - t2
print "Python  ", t2 - t1

x = np.linspace(-.9, .9, points * 10)
yp = kpm.generate_profile(musp, x)  # python
yf = kpm.generate_profile(musf, x)  # fortran
py.plot(x, yp, label="Python")
py.plot(x, yp, label="FORTRAN")
py.legend()
py.show()
Ejemplo n.º 17
0
import geometry

g = geometry.honeycomb_lattice()
nrep = 2
g = g.supercell(nrep)
h = g.get_hamiltonian()

m = h.intra
m = m / 6.
points = 10000  # number of polynomials
t1 = time.clock()
musp = kpm.full_trace(m, use_fortran=False)  # full trace
t2 = time.clock()
musf = kpm.full_trace(m, use_fortran=True)  # full trace
t3 = time.clock()
print "FORTRAN ", t3 - t2
print "Python  ", t2 - t1

x = np.linspace(-.9, .9, points * 10)
t1 = time.clock()
yp = kpm.generate_profile(musp, x, use_fortran=False)  # python
t2 = time.clock()
yf = kpm.generate_profile(musf, x, use_fortran=True)  # fortran
t3 = time.clock()
print "FORTRAN ", t3 - t2
print "Python  ", t2 - t1
py.scatter(x, yp, label="Python", c="blue")
py.plot(x, yf, label="FORTRAN", c="green")
py.legend()
py.show()
Ejemplo n.º 18
0
import kpm # kernel polynomial method
import numpy as np
import pylab as py

m = np.matrix([[0.,1.],[1.,0.]]) # default matrix
m = m/2
mus = kpm.full_trace(m) # full trace
points = 200 # number of polynomials
x = np.linspace(-.9,.9,points*10)
y = kpm.generate_profile(mus,x)
py.plot(x,y)
py.show()
Ejemplo n.º 19
0
import geometry

g = geometry.honeycomb_lattice()
nrep = 2
g = g.supercell(nrep)
h = g.get_hamiltonian()

m = h.intra
m = m/6.
points = 10000 # number of polynomials
t1 = time.clock()
musp = kpm.full_trace(m,use_fortran=False) # full trace
t2 = time.clock()
musf = kpm.full_trace(m,use_fortran=True) # full trace
t3 = time.clock()
print "FORTRAN ",t3-t2
print "Python  ",t2-t1

x = np.linspace(-.9,.9,points*10)
t1 = time.clock()
yp = kpm.generate_profile(musp,x,use_fortran=False) # python
t2 = time.clock()
yf = kpm.generate_profile(musf,x,use_fortran=True) # fortran
t3 = time.clock()
print "FORTRAN ",t3-t2
print "Python  ",t2-t1
py.scatter(x,yp,label="Python",c="blue")
py.plot(x,yf,label="FORTRAN",c="green")
py.legend()
py.show()