コード例 #1
0
def surface(h1,
            energies=np.linspace(-1., 1., 100),
            operator=None,
            delta=0.01,
            kpath=None,
            hs=None):
    """Get the surface DOS of an interface"""
    from scipy.sparse import csc_matrix, bmat
    if kpath is None:
        if h1.dimensionality == 3:
            g2d = h1.geometry.copy()  # copy Hamiltonian
            import sculpt
            g2d = sculpt.set_xy_plane(g2d)
            kpath = klist.default(g2d, nk=100)
        elif h1.dimensionality == 2:
            kpath = [[k, 0., 0.] for k in np.linspace(0., 1., 40)]
        else:
            raise
    fo = open("KDOS.OUT", "w")
    fo.write("# k, E, Surface, Bulk\n")
    tr = timing.Testimator("KDOS")  # generate object
    ik = 0
    h1 = h1.get_multicell()  # multicell Hamiltonian
    for k in kpath:
        tr.remaining(ik, len(kpath))  # generate object
        ik += 1
        outs = green.surface_multienergy(h1,
                                         k=k,
                                         energies=energies,
                                         delta=delta,
                                         hs=hs)
        for (energy, out) in zip(energies, outs):
            # write everything
            fo.write(str(ik) + "   " + str(energy) + "   ")
            for g in out:  # loop
                if operator is None:
                    d = -g.trace()[0, 0].imag  # only the trace
                elif callable(operator):
                    d = operator(g, k=k)  # call the operator
                else:
                    d = -(g *
                          operator).trace()[0, 0].imag  # assume it is a matrix
                fo.write(str(d) + "   ")  # write in a file
            fo.write("\n")  # next line
            fo.flush()  # flush
    fo.close()
コード例 #2
0
ファイル: dos.py プロジェクト: zx-sdu/pygra
def bulkandsurface(h1,
                   energies=np.linspace(-1., 1., 100),
                   operator=None,
                   delta=0.01,
                   hs=None,
                   nk=30):
    """Compute the DOS of the bulk and the surface"""
    tr = timing.Testimator("KDOS")  # generate object
    ik = 0
    h1 = h1.get_multicell()  # multicell Hamiltonian
    kpath = [np.random.random(3) for i in range(nk)]  # loop
    dosout = np.zeros((2, len(energies)))  # output DOS
    for k in kpath:
        tr.remaining(ik, len(kpath))  # generate object
        ik += 1
        outs = green.surface_multienergy(h1,
                                         k=k,
                                         energies=energies,
                                         delta=delta,
                                         hs=hs)
        ie = 0
        for (energy, out) in zip(energies, outs):  # loop over energies
            # compute dos
            ig = 0
            for g in out:  # loop
                if operator is None:
                    d = -g.trace()[0, 0].imag  # only the trace
                elif callable(operator):
                    d = operator(g, k=k)  # call the operator
                else:
                    d = -(g *
                          operator).trace()[0, 0].imag  # assume it is a matrix
                dosout[ig, ie] += d  # store
                ig += 1  # increase site
            ie += 1  # increase energy
    # write in file
    dosout /= nk  # normalize
    np.savetxt("DOS_BULK_SURFACE.OUT",
               np.matrix([energies, dosout[0], dosout[1]]).T)