Ejemplo n.º 1
0
def compare_kpts(fname_full, fname_sub, tol=1e-8):
    wfn_full = wfnIO(fname_full)
    wfn_sub = wfnIO(fname_sub)
    kpts_full = (wfn_full.kpt + tol) % 1
    kpts_sub = (wfn_sub.kpt + tol) % 1
    tree = cKDTree(kpts_full.T)
    d, ind = tree.query(kpts_sub.T)
    return ind, kpts_full.shape[1]
Ejemplo n.º 2
0
def test_bse(fname_wfn, fname_evec):
    from bgwtools.IO.wfn import wfnIO
    from bgwtools.IO.bsemat import bsematIO

    wfn = wfnIO(fname_wfn)
    bsemat = bsematIO(fname_evec)
    syms = wfn.mtrx
    cond = syms[2,2,:] == 1
    syms = syms[:,:,cond]

    bsemat.kpt[np.fabs(bsemat.kpt)<1e-15] = 0
    kg = Kgrids(syms, bsemat.kpt)

    #print [ sum(kg.idx_sk[:,ik]==ik) for ik in xrange(kg.nk) ]
    for ik in xrange(kg.nk):
        print kg.idx_sk[:,ik]
    print kg
Ejemplo n.º 3
0
def read_eqp(fname_wfn, fname_eqp, nv, nc):
    wfn = wfnIO(fname_wfn)
    n_occ = wfn.ifmax[0,0]

    if fname_eqp is None:
        #nv, nk
        en_v = wfn.energies[n_occ-nv:n_occ,:,0][::-1]*ryd
        #nc, nk
        en_c = wfn.energies[n_occ:n_occ+nc,:,0]*ryd
    else:
        from bgwtools.converters.read_eqp import get_data_from_eqp
        bands,kx,ky,kz,e_lda,e_gw = get_data_from_eqp(fname_eqp)
        bands_range = np.arange(len(bands))
        val_bands = bands_range[(bands<=n_occ) & (bands>n_occ-nv)][::-1]
        cond_bands = bands_range[(bands>n_occ) & (bands<n_occ+nc+1)]
        en_v = e_gw[:,val_bands].T
        en_c = e_gw[:,cond_bands].T
    return en_v, en_c
Ejemplo n.º 4
0
def truncate(wfn_in, fname_out, ik_keep):
    print
    print 'Truncating', wfn_in.fname, '->', fname_out
    wfn_out = wfnIO()
    wfn_out.__dict__ = wfn_in.__dict__.copy()
    wfn_out.nk = len(ik_keep)
    wfn_out.ngk = wfn_out.ngk[ik_keep]
    wfn_out.ngkmax = amax(wfn_out.ngk)
    wfn_out.kw = wfn_out.kw[ik_keep]
    wfn_out.kw[:] = 1.0 / wfn_out.nk
    wfn_out.kpt = wfn_out.kpt[:, ik_keep]
    #HACK!
    #wfn_out.ifmin[:] = 1
    #wfn_out.ifmax[:] = 4
    wfn_out.ifmin = wfn_out.ifmin[ik_keep, :]
    wfn_out.ifmax = wfn_out.ifmax[ik_keep, :]
    wfn_out.energies = wfn_out.energies[:, ik_keep, :]
    wfn_out.occupations = wfn_out.occupations[:, ik_keep, :]
    wfn_out.f = None
    wfn_out.fname = fname_out
    wfn_out.write_header(full=True)

    ng_max = amax(wfn_in.ngk)
    gvec = empty((3, ng_max), dtype=int, order='F')
    data = empty((ng_max, wfn_in.ns),
                 dtype=get_numpy_flavor(wfn_in.flavor),
                 order='F')
    k_done = 0
    for ik in range(wfn_in.nk):
        if ik in ik_keep:
            k_done += 1
            print k_done, '/', wfn_out.nk
            wfn_in.read_gvectors(gvec)
            wfn_out.write_gvectors(gvec[:, :wfn_in.ngk[ik]])
            for ib in range(wfn_in.nbands):
                wfn_in.read_data(data)
                wfn_out.write_data(data[:wfn_in.ngk[ik], :])
            if k_done == wfn_out.nk:
                break
        else:
            wfn_in.read_gvectors()
            for ib in range(wfn_in.nbands):
                wfn_in.read_data()
    print wfn_out
Ejemplo n.º 5
0
    def decimate_to(self, fname_out, verbose=True):
        wfn_in = self.wfn_in
        keep_k = self.keep_k
        nk_out = np.sum(keep_k)

        wfn_out = wfnIO()
        wfn_out.__dict__ = wfn_in.__dict__.copy()
        wfn_out.nk = nk_out
        wfn_out.ngk = wfn_out.ngk[keep_k]
        wfn_out.ngkmax = np.amax(wfn_out.ngk)
        wfn_out.kw = wfn_out.kw[keep_k]
        wfn_out.kw[:] = 1.0 / wfn_out.nk
        wfn_out.kpt = wfn_out.kpt[:, keep_k]
        wfn_out.ifmin = wfn_out.ifmin[keep_k, :]
        wfn_out.ifmax = wfn_out.ifmax[keep_k, :]
        wfn_out.energies = wfn_out.energies[:, keep_k, :]
        wfn_out.occupations = wfn_out.occupations[:, keep_k, :]
        wfn_out.f = None
        wfn_out.fname = fname_out
        wfn_out.write_header(full=True)

        ng_max = np.amax(wfn_in.ngk)
        gvec = np.empty((3, ng_max), dtype=int, order='F')
        data = np.empty((ng_max, wfn_in.ns),
                        dtype=get_numpy_flavor(wfn_in.flavor),
                        order='F')
        k_done = 0
        for ik in range(wfn_in.nk):
            if keep_k[ik]:
                k_done += 1
                if verbose:
                    print k_done, '/', wfn_out.nk
                wfn_in.read_gvectors(gvec)
                wfn_out.write_gvectors(gvec[:, :wfn_in.ngk[ik]])
                for ib in range(wfn_in.nbands):
                    wfn_in.read_data(data)
                    wfn_out.write_data(data[:wfn_in.ngk[ik], :])
                if k_done == wfn_out.nk:
                    break
            else:
                wfn_in.read_gvectors()
                for ib in range(wfn_in.nbands):
                    wfn_in.read_data()
Ejemplo n.º 6
0
        sys.exit(1)

    # Reading arguments and input files
    qmax=float(sys.argv[1])
    k_center=array([float(sys.argv[2]),float(sys.argv[3]),float(sys.argv[4])])
    fname_in = sys.argv[5]
    if write_wfn:
        if not read_wfn:
            print "Error: cannot write decimated wave function without input wave function"
            sys.exit(1)
        fname_out = sys.argv[6]
    if read_wfn:
        from bgwtools.IO.wfn import wfnIO
        from bgwtools.common.common import get_numpy_flavor
        from bgwtools.IO.fullbz import fullbzIO
        wfn_in = wfnIO(fname_in, full=True)
        M = wfn_in.bvec
        # Convert to cartesian coordinates
        rk_cart=tensordot(wfn_in.bvec,wfn_in.kpt, axes=([1],[0]))
        fullbz=fullbzIO('fullbz.dat')
        print "Dimensions of input k-grid: %i %i %i"%(wfn_in.kgrid[0],wfn_in.kgrid[1],wfn_in.kgrid[2])
    else:
        from bgwtools.IO.kgrid_log import kgridlogIO
        fullbz = kgridlogIO(sys.argv[5])
        norm = sqrt(fullbz.bvec[0,0]**2 +fullbz.bvec[1,0]**2)
        fullbz.bvec =fullbz.bvec /norm
        M = fullbz.bvec
        print "Dimensions of input k-grid: %i %i %i"%(fullbz.kgrid[0],fullbz.kgrid[1],fullbz.kgrid[2])
    fk_cart=tensordot(M,fullbz.fk, axes=([1],[0]))
    nf = fullbz.nf
    nrk = fullbz.nrk
Ejemplo n.º 7
0
import numpy as np
import sys
if len(sys.argv) != 3:
    print('Usage: %s wfn_in wfn_out' % (sys.argv[0]))
    sys.exit(1)
fname_in = sys.argv[1]
fname_out = sys.argv[2]

#copy *all* wfn file
import shutil
shutil.copyfile(fname_in, fname_out)

#open wfn file, write fixed header to file fname_tmp
from bgwtools.IO.wfn import wfnIO
fname_tmp = '_wfn_tmp_'
wfn = wfnIO(fname_in, full=False)
print 'Original sum of weights:', np.sum(wfn.kw)
wfn.kw[:] = 1.0 / wfn.nk
print 'New sum of weights:', np.sum(wfn.kw)
wfn.ngkmax = np.amax(wfn.ngk)
wfn.to_file(fname_tmp, full=False)

#copy fixed header to fname_out
f_tmp = open(fname_tmp, 'rb')
f_out = open(fname_out, 'r+b')
f_out.write(f_tmp.read())
f_out.close()
f_tmp.close()

#clean-up
import os
Ejemplo n.º 8
0
#!/usr/bin/env python

# This utility compares two wfn files and prints the larger difference.
# Felipe H. da Jornada, Apr 2013

from bgwtools.IO.wfn import wfnIO
from bgwtools.common.common import get_numpy_flavor
import sys
from numpy import amax, empty, empty_like

fname1 = sys.argv[1]
print('File #1: %s'%(fname1))
fname2 = sys.argv[2]
print('File #2: %s'%(fname2))

wfn1 = wfnIO(fname1)
wfn2 = wfnIO(fname2)

ng_max = amax(wfn1.ngk) * wfn1.nspinor
gvec = empty((3, ng_max), dtype=int, order='F')
data1 = empty((ng_max, wfn1.ns), dtype=get_numpy_flavor(wfn1.flavor), order='F')
data2 = empty_like(data1)
for ik in range(wfn1.nk):
	print('ik = %d'%ik)
        wfn1.read_gvectors(gvec)
        wfn2.read_gvectors(gvec)
        ngk = wfn1.ngk[ik] * wfn1.nspinor
        for ib in range(wfn1.nbands):
            wfn1.read_data(data1)
            wfn2.read_data(data2)
	    diff = (data2 - data1)[:ngk]
Ejemplo n.º 9
0
def get_velocity_kp(wfn, same_order=True):
    if not isinstance(wfn, wfnIO):
        raise TypeError('Expected wfn type, got %s.'%(type(wfn)))
    nb = wfn.nbands
    ns = wfn.ns
    kpts = wfn.kpt
    nk = wfn.nk
    ns = wfn.ns
    #print en.flags['F_CONTIGUOUS']
    #print kpts.flags['F_CONTIGUOUS']

    for ik in xrange(len(kpts)):
        

    # Consistency check: dk == 1/kgrid
    for idim in range(3):
        delta_k = all_delta_k[idim]
        cond = delta_k>0
        if any(cond):
            dk[idim] = amin(delta_k[cond])
    if any(fabs(dk - 1./kgrid) > TOL_SMALL):
        print wfn.nk
        print wfn.kgrid
        print dk
        print 1./kgrid
        raise ValueError('kgrid not consistent.')
    #dk = 1./kgrid

    # It's easier to roll the axis and calculate the velocities if the 
    # energies are indexed like this:
    en = en.reshape(nb, kgrid[2], kgrid[1], kgrid[0], ns, order='F')

    # Calcualte band velocity
    vel = zeros((3, nb, kgrid[2], kgrid[1], kgrid[0], ns), dtype=float, order='F')
    for idim in range(3):
        if kgrid[2-idim]<2: continue
        # In principle we could calculate both the forward and 
        # backward derivatives...
        #vel[2-idim] = 0.5*(roll(en, -1, idim+1) - roll(en, 1, idim+1))
        vel[2-idim] = roll(en, -1, idim+1) - en

    if same_order:
        return vel.reshape(3, nb, nk, ns, order='F')
    else:
        return en, vel

if __name__=='__main__':
    # A simple test, great for graphene, but should work for
    # any system.

    import sys
    fname = sys.argv[1]
    ib = 4
    if len(sys.argv)>2:
        ib = int(sys.argv[2])
    plot_abs = True
    plot_vel = True
    plot_en = True

    wfn = wfnIO(fname)
    en, vel = get_velocity(wfn, same_order=False)

    import matplotlib.pyplot as plt
    import scipy.linalg

    dk = 1./wfn.kgrid
    shift = dk*wfn.kshift
    x = arange(shift[0], 1.0, dk[0])
    y = arange(shift[1], 1.0, dk[1])
    X, Y = meshgrid(x, y)
    Z = zeros_like(X)
    XYZ = row_stack((X[newaxis],Y[newaxis],Z[newaxis]))
    M = linalg.cholesky(wfn.bdot).T
    #M = eye(3)
    XYZ = tensordot(M, XYZ, (1,0))
    M = linalg.inv(M)
    vel = vel[:,ib,0,:,:,0]
    vel = tensordot(M, vel, (0,0))

    if plot_abs:
        v = vel * wfn.kgrid[:,newaxis,newaxis]
        v = sqrt(sum(v**2, axis=0))

        from matplotlib.mlab import griddata
        Ni = 1000
        xi = linspace(amin(XYZ[0]), amax(XYZ[0]), Ni)
        yi = linspace(amin(XYZ[1]), amax(XYZ[1]), Ni)
        X_ = XYZ[0].flatten(order='F')
        Y_ = XYZ[1].flatten(order='F')
        V_ = v.flatten(order='F')

        vi = griddata(X_,Y_,V_,xi,yi,interp='linear')
        plt.imshow(vi, origin='lower', \
            extent=(amin(xi), amax(xi), amin(yi), amax(yi)))
        
        #plt.imshow(v, origin='lower', extent=(0,1,0,1))
        plt.colorbar()
    if plot_vel:
        ds = 1
        v = vel[:,::ds,::ds]*ds
        scale = 2
        plt.quiver(XYZ[0][::ds,::ds], XYZ[1][::ds,::ds], \
            v[0], v[1], angles='xy', scale=scale, zorder=10,\
            headwidth=5, headlength=5, width=1e-3)
    if plot_en:
        e = en[ib,0,:,:,0]
        plt.contour(XYZ[0], XYZ[1], e, linewidths=2)
    
    plt.show()
Ejemplo n.º 10
0
from bgwtools.IO.epsmat import epsmatIO
from bgwtools.IO.wfn import wfnIO

if len(sys.argv) < 5:
    print "Usage: %s eps0mat epsmat WFN output" % (sys.argv[0])
    sys.exit(1)

f_eps0mat = sys.argv[1]
f_epsmat = sys.argv[2]
f_wfn = sys.argv[3]
f_out = open(sys.argv[4], 'w')
f_out.write("%10s %10s %10s %5s %15s %10s \n" %
            ('# qx', 'qy', '|q|', 'Gz', 'eps', 'ekin'))

eps0mat = epsmatIO(f_eps0mat)
wfn = wfnIO(f_wfn)

print "Reading eps0mat"
print "   Number of G-vectors: ", eps0mat.ng

for ig in range(eps0mat.ng):
    g_indx = eps0mat.isort[0][ig]
    g_indx_i = eps0mat.isort_i[0][g_indx - 1]
    if eps0mat.gvec_k[0, g_indx - 1] == 0 and eps0mat.gvec_k[1,
                                                             g_indx - 1] == 0:
        print "   Found head"
        print "   Gvec: ", eps0mat.gvec_k[:, g_indx - 1]
        print "   isort,isort_i: ", g_indx, g_indx_i
        print "   ig", ig
        Gz = eps0mat.gvec_k[2, g_indx - 1]
        qG = [eps0mat.qpt[0, 0], eps0mat.qpt[1, 0], Gz]
Ejemplo n.º 11
0
 def __init__(self, fname_in):
     self.wfn_in = wfnIO(fname_in)
     self.keep_k = np.ones(self.wfn_in.nk, dtype=bool)
Ejemplo n.º 12
0
# Felipe Homrich da Jornada (Feb 2013)

import numpy as np
from bgwtools.IO.wfn import wfnIO
import sys
from bgwtools.common.common import get_numpy_flavor

if len(sys.argv) != 3:
    print('Usage: %s wfn_in wfn_out' % (sys.argv[0]))
    sys.exit(1)

fname_in = sys.argv[1]
fname_out = sys.argv[2]

wfn_in = wfnIO(fname_in, full=True)
nb_out = np.amax(wfn_in.ifmax) + 1

wfn_out = wfnIO()
wfn_out.__dict__ = wfn_in.__dict__.copy()
wfn_out.energies = wfn_out.energies[:nb_out, :, :]
wfn_out.occupations = wfn_out.occupations[:nb_out, :, :]
wfn_out.f = None
wfn_out.fname = fname_out
wfn_out.nbands = nb_out
wfn_out.write_header(full=True)

ng_max = np.amax(wfn_in.ngk)
gvec = np.empty((3, ng_max), dtype=int, order='F')
data = np.empty((ng_max, wfn_in.ns),
                dtype=get_numpy_flavor(wfn_in.flavor),
Ejemplo n.º 13
0
import sys
from bgwtools.common.common import get_numpy_flavor

ryd = 13.60569253

if len(sys.argv) != 5:
    print('Usage: %s qshift wfn_in wfn_out wfnq_out' % (sys.argv[0]))
    sys.exit(1)

qshift = array(map(float, sys.argv[1].split(',')))
fname_in = sys.argv[2]
fname_out = sys.argv[3]
fnameq_out = sys.argv[4]

print 'WFN:', fname_in
wfn_in = wfnIO(fname_in)
print 'q-shift', qshift

#c -> k
#v -> k + q
tol = 1e-8
#kpts_qmq0 = (wfnq_in.kpt - qshift[:,newaxis] + 1) % 1
# calculate k + q
#kpts_pq = wfn_in.kpt + qshift[:,newaxis]
iks = []
ikqs = []
for ik in range(wfn_in.nk):
    ks_pq = wfn_in.kpt[:, ik] + qshift
    delta = (wfn_in.kpt - ks_pq[:, newaxis] + tol) % 1
    #delta = (kpts_qmq0 - wfn_in.kpt[:,ik][:,newaxis])
    #kk_q = wfn_in.kpt[:,ik] + qshift
Ejemplo n.º 14
0
from bgwtools.common.common import get_numpy_flavor

ryd = 13.60569253
TOL = 1e-6

if len(sys.argv) != 5:
    print('Usage: %s wfn_full wfn_reduced wfn_out qx,qy,qz' % (sys.argv[0]))
    sys.exit(1)

fname_in = sys.argv[1]
fname_red = sys.argv[2]
fname_out = sys.argv[3]
q_shift = array(map(float, sys.argv[4].split(',')))
print q_shift

wfn_in = wfnIO(fname_in)
kpts_full = wfn_in.kpt

wfn_red = wfnIO(fname_red)
kpts_red = wfn_red.kpt

kpts_q = kpts_red + q_shift[:, newaxis]

should_keep = []
for jk in range(wfn_in.nk):
    kpt = kpts_full[:, jk]
    if any(all(abs(kpt[:, newaxis] - kpts_q) < TOL, axis=0)):
        should_keep += [jk]

if raw_input('Writing data to %s. Are you sure? [y/N] ' % (fname_out)) != 'y':
    sys.exit(0)
Ejemplo n.º 15
0
# Felipe Homrich da Jornada (Jun 2013)

from numpy import *
from bgwtools.IO.wfn import wfnIO
import sys
from bgwtools.common.common import get_numpy_flavor

if len(sys.argv) != 3:
    print('Usage: %s wfn_in wfn_out' % (sys.argv[0]))
    sys.exit(1)

fname_in = sys.argv[1]
fname_out = sys.argv[2]

wfn_in = wfnIO(fname_in)


def get_delta(kpts, idim):
    delta = fabs(kpts[idim, :] - wfn_in.kpt[idim, 0])
    cond = delta > 1e-8
    return amin(delta[cond])


dx = get_delta(wfn_in.kpt, 0)
dy = get_delta(wfn_in.kpt, 1)
x0 = amin(wfn_in.kpt[0, :])
y0 = amin(wfn_in.kpt[1, :])

print x0, y0
print dx, dy
Ejemplo n.º 16
0
def write_decimated(wfn,keep,bz,use_symmetries):
    if use_symmetries:
        keep_reduced = keep
    else:
        keep_reduced = bz.indr[keep]-1
        keep = keep[argsort(keep_reduced)] # sort k's by reduced index
    wfn_out = wfnIO()
    wfn_out.__dict__ = wfn.__dict__.copy()
    wfn_out.nk = len(keep)
    if use_symmetries:
        wfn_out.ngk = wfn_out.ngk[keep]
        wfn_out.kw = wfn_out.kw[keep]
    else:
        wfn_out.ngk = wfn_out.ngk[bz.indr[keep]-1]
        wfn_out.kw = wfn_out.kw[bz.indr[keep]-1]
    wfn_out.ngkmax = amax(wfn_out.ngk)
    wfn_out.kw[:] = 1.0/wfn_out.nk
    if use_symmetries:
        wfn_out.kpt = wfn_out.kpt[:, keep]
        wfn_out.ifmin = wfn_out.ifmin[keep, :]
        wfn_out.ifmax = wfn_out.ifmax[keep, :]
        wfn_out.energies = wfn_out.energies[:, keep, :]
        wfn_out.occupations = wfn_out.occupations[:, keep, :]
    else:
        wfn_out.kpt = bz.fk[:, keep]
        wfn_out.ifmin = wfn_out.ifmin[bz.indr[keep]-1, :]
        wfn_out.ifmax = wfn_out.ifmax[bz.indr[keep]-1, :]
        wfn_out.energies = wfn_out.energies[:, bz.indr[keep]-1, :]
        wfn_out.occupations = wfn_out.occupations[:, bz.indr[keep]-1, :]
    wfn_out.f = None
    wfn_out.fname = fname_out
    wfn_out.write_header(full=True)

    ng_max = amax(wfn_in.ngk)
    gvec = empty((3, ng_max), dtype=int, order='F')
    if use_symmetries:
        data = empty((ng_max, wfn_in.ns), dtype=get_numpy_flavor(wfn_in.flavor), order='F')
    else:
        data = empty((wfn_in.nbands,ng_max, wfn_in.ns), dtype=get_numpy_flavor(wfn_in.flavor), order='F')
    k_done = 0

    for ik in range(wfn_in.nk):
        if ik in keep_reduced:
            k_done += 1
            print k_done,'/',wfn_out.nk
            wfn_in.read_gvectors(gvec)
            if use_symmetries:
                wfn_out.write_gvectors(gvec[:,:wfn_in.ngk[ik]])
                for ib in range(wfn_in.nbands):
                    wfn_in.read_data(data)
                    wfn_out.write_data(data[:wfn_in.ngk[ik],:])
                if k_done==wfn_out.nk:
                    break
            else:
                # ik is the reduced index
                # find places where ik occurs in indr
                idx_k = where(keep_reduced==ik)[0]
                for kk in range(len(idx_k)):
                    wfn_out.write_gvectors(gvec[:,:wfn_in.ngk[ik]])
                    for ib in range(wfn_in.nbands):
                        if kk==0:
                            wfn_in.read_data(data[ib,:,:])
                        wfn_out.write_data(data[ib,:wfn_in.ngk[ik],:])
            if k_done==wfn_out.nk:
                break                    
        else:
            wfn_in.read_gvectors()
            for ib in range(wfn_in.nbands):
                wfn_in.read_data()
    print wfn_out
Ejemplo n.º 17
0
    # any system.

    import sys

    if len(sys.argv) != 3:
        print('usage: %s WFN band')
        sys.exit(1)

    fname = sys.argv[1]
    ib = int(sys.argv[2])

    plot_vel = True
    plot_en = False
    use_cartesian = False

    wfn = wfnIO(fname)
    vel = get_velocity_kp(wfn, ib)
    kpts = wfn.kpt

    import matplotlib.pyplot as plt
    import scipy.linalg

    if use_cartesian:
        M = linalg.cholesky(wfn.bdot).T
        kpts = dot(M, kpts)
        M = linalg.inv(M)
        vel = tensordot(M, vel, (0, 0))

    if plot_vel:
        scale = 10
        head = 25
Ejemplo n.º 18
0
            g[abs(g) < 1e-10] = 1e-10

            #uninvert, do operations, invert back
            #print mat.diagonal()
            mat = linalg.inv(mat)
            for ig in xrange(nmtx):
                mat[ig, ig] -= 1.0
            mat[:, :] = mat[:, :] / g[:, np.newaxis]
            for ig in xrange(nmtx):
                mat[ig, ig] += 1.0
            mat = linalg.inv(mat)
            #print mat.diagonal()
            self.epsmat.epsmat[iq] = mat


if __name__ == '__main__':
    import sys

    if len(sys.argv) != 4:
        print 'Usage: %s wfn epsmat_in epsmat_out' % (sys.argv[0])
        exit(1)

    wfn = wfnIO(sys.argv[1])
    f_in = sys.argv[2]
    f_out = sys.argv[3]

    eps = epsmatIO(f_in)
    conv = epsilon_truncator(eps, wfn, slab_truncator)
    conv.truncate()
    eps.to_file(f_out)
Ejemplo n.º 19
0
#!/usr/bin/env python

# This script calculates the phase of the G=0 component of the WFNs
# for all kpts and bands. This is useful when analyzing results from
# BSE calculations.

from bgwtools.IO.wfn import wfnIO
import sys
import numpy as np

fname_wfn = sys.argv[1]
fname_out = sys.argv[2]
wfn = wfnIO(fname_wfn)

gvecs = wfn.get_gvectors_bufer()
data = wfn.get_data_buffer()
heads = np.empty((wfn.nk, wfn.nbands), dtype='complex128')

print wfn.gvec
#exit()

for ik in xrange(wfn.nk):
    wfn.read_gvectors(gvecs)
    cond = np.all(gvecs[:, :wfn.ngk[ik]] == 0, axis=0)
    idx = np.nonzero(cond)[0][0]
    print ik, idx, gvecs[:, idx]
    for ib in xrange(wfn.nbands):
        wfn.read_data(data)
        heads[ik, ib] = data[idx, 0]

np.save(fname_out, heads)
Ejemplo n.º 20
0
    print('Usage: %s WFN.h5 WFN_out flavor \n' % (sys.argv[0]))
    print(' Flavor: 1=real, 2=complex')
    sys.exit(1)

fname_in = sys.argv[1]
fname_out = sys.argv[2]
flavor = int(sys.argv[3])

# Read WFN.h5
import h5py
wfn = h5py.File(fname_in, 'r')

# Copying Header

# File info
wfn_out = wfnIO()
wfn_out.fname = fname_out
if flavor == 2:
    wfn_out.name = 'WFN-Complex'
else:
    wfn_out.name = 'WFN-Real'
wfn_out.ftype = get_ftype('WFN')
wfn_out.flavor = flavor
wfn_out.date = ''
wfn_out.time = ''

# crystal
wfn_out.nat = int(wfn['/mf_header/crystal/nat'][...])
wfn_out.adot = wfn['/mf_header/crystal/adot'][...].T
wfn_out.alat = np.float(wfn['/mf_header/crystal/alat'][...])
wfn_out.apos = wfn['/mf_header/crystal/apos'][...].T
Ejemplo n.º 21
0
                      "--model",
                      default=1,
                      type="int",
                      help="which model to use (0-2).")
    (options, args) = parser.parse_args()

    if len(args) < 1:
        parser.error('Insuficient number of arguments.')
    elif len(args) == 1:
        print "Reading model from file '%s'" % (args[0])
        f = open(args[0], 'rb')
        epsmat_modeler = cPickle.load(f)
        f.close()
    else:
        print "Parsing wfn file '%s'" % (args[0])
        wfn = wfnIO(args[0])
        epsmat_modeler = EpsmatModeler(wfn, options.Gz_max, options.avgcut_xy)
        for arg in args[1:]:
            print "Parsing epsmat file '%s'" % (arg)
            epsmat = epsmatIO(arg, read_all=False)
            epsmat_modeler.add_epsmat(epsmat)
        epsmat_modeler.commit_data()

    epsmat_modeler.model(model=options.model,
                         smooth=options.smooth,
                         degree=options.degree)
    epsmat_modeler.get_bgw_params()
    if len(args) > 1:
        print "Dumping model to file '%s'" % (options.dump)
        f = open(options.dump, 'wb')
        cPickle.dump(epsmat_modeler, f)
Ejemplo n.º 22
0
 def __init__(self, fname):
     self.wfn = wfnIO(fname)