Beispiel #1
0
    def get_gauges(self, bands, verbose=True):
        wfn = self.wfn

        nbands = len(bands)
        ng_max = np.amax(wfn.ngk)
        gvec = np.empty((3, ng_max), dtype=int, order='F')
        data = np.empty((ng_max, wfn.ns),
                        dtype=get_numpy_flavor(wfn.flavor),
                        order='F')
        gauges = np.empty((nbands, wfn.nk), dtype=get_numpy_flavor(wfn.flavor))
        k_done = 0
        for ik in range(wfn.nk):
            k_done += 1
            if verbose:
                print k_done, '/', wfn.nk
            #wfn.read_gvectors(gvec)
            #Assume G-vectors are order by kinetic energy
            wfn.read_gvectors()
            ib_ = 0
            for ib in range(wfn.nbands):
                if ib in bands:
                    wfn.read_data(data)
                    gauges[ib_, ik] = data[0]
                    ib_ += 1
                else:
                    wfn.read_data()
        return gauges
Beispiel #2
0
    def get_data_buffer(self):
        '''Results an ndarray that serves as buffer for calls to read_data'''

        if self.flavor == common.flavor.NONE:
            raise Exception('Flavor is unknown.')

        dtype = common.get_numpy_flavor(self.flavor)
        return empty((self.ngkmax, self.ns), dtype=dtype, order='F')
Beispiel #3
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
Beispiel #4
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()
Beispiel #5
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
Beispiel #6
0
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]
            max_diff = amax(abs(diff))
            print('  band %d:'%(ib))
            print('    ||cg2 - cg1||_inf = %e'%max_diff)
Beispiel #7
0
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),
                order='F')
k_done = 0
for ik in range(wfn_in.nk):
    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(nb_out):
        wfn_in.read_data(data)
        wfn_out.write_data(data[:wfn_in.ngk[ik], :])
    for ib in range(nb_out, wfn_in.nbands):
        wfn_in.read_data()

print wfn_out
Beispiel #8
0
wfn_out.ngk = wfn_out.ngk[should_keep]
wfn_out.ngkmax = amax(wfn_out.ngk)
wfn_out.kw = wfn_out.kw[should_keep]
wfn_out.kw[:] = 1.0/wfn_out.nk
wfn_out.kpt = wfn_out.kpt[:, should_keep]
wfn_out.ifmin = wfn_out.ifmin[should_keep, :]
wfn_out.ifmax = wfn_out.ifmax[should_keep, :]
wfn_out.energies = wfn_out.energies[:, should_keep, :]
wfn_out.occupations = wfn_out.occupations[:, should_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 should_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):