Пример #1
0
def writeBands(ispin, what, bands):
    # Write output
    if HS.nspin > 1:
        sspin = ['.up', '.down'][ispin]
    else:
        sspin = ''

    Graphs = []
    for jj, elem in enumerate(what):
        f = open(general.DestDir + '/' + elem[0] + sspin + '.dat', 'w')
        xx = N.array(range(elem[3]), N.float) / (elem[3] - 1.0)
        iColor, Datasets = 1, []
        for ii in range(len(bands[jj][0, :])):
            # Choose bands within +-5 eV from Ef
            if N.sum((bands[jj][:, ii] < general.eMax)*\
                     (bands[jj][:, ii] > general.eMin)) > 1e-5:
                f.write("\n# Band %i \n" % (ii))
                for kk, data in enumerate(bands[jj][:, ii]):
                    f.write("%i %e\n" % (kk, data))
                Datasets += [XMGR.XYset(xx, bands[jj][:, ii], Lcolor=iColor)]
                iColor += 1
        f.close()

        g = XMGR.Graph()
        for data in Datasets:
            g.AddDatasets(data)
        g.SetSubtitle(what[jj][0])

        g.SetXaxis(label='', majorUnit=0.5, minorUnit=0.1, vmax=1, vmin=0)
        if jj == 0:
            g.SetYaxis(label='eV',
                       majorUnit=1,
                       minorUnit=0.2,
                       vmax=general.eMax,
                       vmin=general.eMin)
        else:
            g.SetYaxis(label='',
                       majorUnit=1e10,
                       minorUnit=0.2,
                       vmax=general.eMax,
                       vmin=general.eMin)
        Graphs += [g]

    p = XMGR.Plot(general.DestDir + '/BandStruct.agr', Graphs[0])

    for ii in range(1, len(Graphs)):
        p.AddGraphs(Graphs[ii])
    p.ArrangeGraphs(nx=len(Graphs), ny=1, hspace=0.0, vspace=0.0)

    # Finally, write the plot file
    p.ShowTimestamp()
    p.WriteFile()
    p.Print2File(general.DestDir + '/BandStruct.eps')
Пример #2
0
def PlotElectronBands(filename, dk, elist, ticks):
    # Make xmgrace plots
    if len(dk) > 1:
        x = N.array([dk])
    else:
        x = N.array([[0.0]])
    e = N.concatenate((x, elist.T)).T
    es = XMGR.Array2XYsets(e, Lwidth=2, Lcolor=1)
    ge = XMGR.Graph(es)
    ge.SetXaxisSpecialTicks(ticks)
    ge.SetXaxis(vmax=dk[-1], majorGridlines=True)
    ge.SetYaxis(vmin=-20, vmax=20, label=r'E-E\sF\N (eV)', majorUnit=5.0)
    pe = XMGR.Plot(filename, ge)
    pe.WriteFile()
Пример #3
0
def WriteDOS(outfile, bands, emin, emax, pts, smear):
    egrid = N.linspace(emin, emax, pts)
    id1 = N.ones(bands.shape, N.float)
    id2 = N.ones(egrid.shape, N.float)
    dE = N.outer(egrid, id1) - N.outer(id2, bands)  # [e,kn]
    w = N.exp(-dE**2 / (2 * smear**2)) / (smear * (2 * N.pi)**.5)  # [e,b]
    dos = N.sum(w, axis=1) / len(bands)  # sum over bands
    # Write plot
    ps = XMGR.XYset(egrid, dos, Lwidth=2, Lcolor=1)
    gp = XMGR.Graph(ps)
    gp.SetXaxis(label='E (eV)', vmin=emin, vmax=emax, majorUnit=emax / 5)
    ymax = N.max(dos)
    gp.SetYaxis(label='DOS (states/eV)', vmin=0, vmax=ymax, majorUnit=ymax / 5)
    #gp.SetSubtitle(ncfile)
    pp = XMGR.Plot(outfile, gp)
    pp.PutText('smear = %.3f meV' % (1e3 * smear), 0.20, 0.75)
    pp.PutText('kpts = %i' % len(bands), 0.20, 0.70)
    pp.WriteFile()
Пример #4
0
def WriteMPSH(fn, options, DevGF, DOS, ev0):
    """
    Projected density of states onto MPSH eigenstates (at Gamma)
    """

    import xml.dom.minidom as xml
    import gzip

    doc = xml.Document()
    mpsh = doc.createElement('mpsh')
    doc.appendChild(mpsh)
    xmladd(doc, mpsh, 'nspin', '%i' % DevGF.HS.nspin)
    xmladd(doc, mpsh, 'norbitals', '%i' % (DevGF.nuo))
    xmladd(doc, mpsh, 'energy_values', myprint(options.Elist + DevGF.HS.ef))
    xmladd(doc, mpsh, 'E_Fermi', '%.8f' % DevGF.HS.ef)
    for ii in range(DevGF.nuo):
        orb = doc.createElement('orbital')
        mpsh.appendChild(orb)
        orb.setAttribute('index', '%i' % ii)
        xmladd(doc, orb, 'data', myprint(DOS[:, :, ii]))
    doc.writexml(gzip.GzipFile(fn, 'w'))

    # Make plot
    g = XMGR.Graph()
    for ii in range(DevGF.nuo):
        for iS in range(DevGF.HS.nspin):
            g.AddDatasets(
                XMGR.XYset(options.Elist, (-1)**iS * DOS[iS, :, ii],
                           legend='',
                           Lwidth=2))

    # Set axes and write XMGR plot to file
    g.SetXaxis(label='E-E\sF\N (eV)', autoscale=True)
    g.SetYaxis(label='DOS (1/eV)', autoscale=True)
    # Add MPSH eigenvalues to plot after axis scaling
    g.AddDatasets(XMGR.XYset(ev0, 0 * ev0 + 1, Ltype=0, Stype=3))
    g.SetTitle(fn, size=1.3)
    g.ShowLegend()
    p = XMGR.Plot(fn + '.xmgr', g)
    p.WriteFile()
Пример #5
0
def WritePDOS(fn, options, DevGF, DOS, basis):
    """
    PDOS from the surface Green's function from electrode calculations

    NOTE! The DOS is a sum over the atoms of the unitcell.
    NOTE! The outfile contains the DOS divided into s,p,d,f shells.
    This decomposition is not perfect since polarized basis orbitals
    will end up in L+1 part, i.e., 6s polarized orbital = 6p
    """

    import xml.dom.minidom as xml
    import gzip

    # First, last orbital in full space and pyTBT folded space.
    devOrbSt = DevGF.HS.lasto[options.DeviceAtoms[0] - 1]
    pyTBTdevOrbSt = devOrbSt - DevGF.HS.lasto[options.DeviceAtoms[0] - 1]
    devOrbEnd = DevGF.HS.lasto[options.DeviceAtoms[1]] - 1

    doc = xml.Document()
    pdos = doc.createElement('pdos')
    doc.appendChild(pdos)
    xmladd(doc, pdos, 'nspin', '%i' % DevGF.HS.nspin)
    xmladd(doc, pdos, 'norbitals', '%i' % (DevGF.nuo))
    xmladd(doc, pdos, 'energy_values', myprint(options.Elist + DevGF.HS.ef))
    xmladd(doc, pdos, 'E_Fermi', '%.8f' % DevGF.HS.ef)
    for ii in range(DevGF.nuo):
        orb = doc.createElement('orbital')
        pdos.appendChild(orb)
        io = devOrbSt + ii
        orb.setAttribute('index', '%i' % (io + 1))
        orb.setAttribute('atom_index', '%i' % basis.ii[io])
        orb.setAttribute('species', basis.label[io])
        orb.setAttribute(
            'position', '%f %f %f' %
            (basis.xyz[io, 0], basis.xyz[io, 1], basis.xyz[io, 2]))
        orb.setAttribute('n', '%i' % basis.N[io])
        orb.setAttribute('l', '%i' % basis.L[io])
        orb.setAttribute('m', '%i' % basis.M[io])
        xmladd(doc, orb, 'data', myprint(DOS[:, :, ii]))
    doc.writexml(gzip.GzipFile(fn, 'w'))

    # Make plot
    atoms = list(set(basis.label))
    lVals = list(set(basis.L))
    plots = [[atoms, lVals, 'Tot']]
    plots += [[atoms, [lVal], 'Tot L=%i' % lVal] for lVal in lVals]
    plots += [[[atom], lVals, atom + ' Tot'] for atom in atoms]
    plots += [[[atom], [lVal], atom + ' L=%i' % lVal] for lVal in lVals
              for atom in atoms]

    g = XMGR.Graph()
    for atom, lVal, name in plots:
        nspin, ee, PDOS = SIO.ExtractPDOS(fn,
                                          None,
                                          FermiRef=False,
                                          llist=lVal,
                                          species=atom,
                                          Normalize=True)
        for iS in range(nspin):
            g.AddDatasets(
                XMGR.XYset(ee - DevGF.HS.ef, (-1)**iS * PDOS[iS],
                           legend=name,
                           Lwidth=2))

    # Set axes and write XMGR plot to file
    g.SetXaxis(label='E-E\sF\N (eV)', autoscale=True)
    g.SetYaxis(label='DOS (1/eV/atom)', autoscale=True)
    g.SetTitle(fn, size=1.3)
    g.ShowLegend()
    p = XMGR.Plot(fn + '.xmgr', g)
    p.WriteFile()
Пример #6
0
x = N.linspace(-x0, x0, 1e5)
gauss = -1j * N.pi**-0.5 * N.exp(-x**2)

# Output from our Hilbert function:
Hg, ker = mm.Hilbert(gauss)

# We can compare with this:
# Hilbert transform of a Gaussian function is related to Faddeva/w(z) functions:
# https://en.wikipedia.org/wiki/Dawson_function
ex = -1j * N.pi**0.5 * ss.wofz(x)

# Collect data in a plot
data1 = XMGR.XYset(x, gauss.imag, legend='Gauss', Lwidth=2)
data2 = XMGR.XYset(x, ex.real, legend='Faddeva', Lwidth=2)
data3 = XMGR.XYset(x, N.pi * Hg.imag, legend='Inelastica', Lwidth=1)
graph1 = XMGR.Graph(data1, data2, data3)
graph1.SetXaxis(autoscale=True)
graph1.SetYaxis(autoscale=True)
graph1.ShowLegend()

# Compute error/difference between the two methods:
err = ex.real - N.pi * Hg.imag
data4 = XMGR.XYset(x, err, legend='Difference', Lwidth=2)
graph2 = XMGR.Graph(data4)
graph2.SetXaxis(autoscale=True)
graph2.SetYaxis(autoscale=True)
graph2.ShowLegend()

plot = XMGR.Plot('test.agr', graph1)
plot.AddGraphs(graph2)
plot.ArrangeGraphs(nx=2, ny=1)