Exemplo n.º 1
0
# and saves the result to a new epsilon file.

# Felipe Homrich da Jornada <*****@*****.**> (2012)

from bgwtools.IO.epsmat import epsmatIO
import sys
from numpy import *

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

f_in = sys.argv[1]
f_out = sys.argv[2]

# Load the epsmat file into the epsmat object
epsmat = epsmatIO(f_in)

print
print 'Inverting epsilon matrices'
for iq in range(epsmat.nq):
	nmtx = epsmat.nmtx[iq]
	print ' - inverting a %d x %d matrix (%d/%d)'%(nmtx, nmtx, iq+1, epsmat.nq)
	mat = epsmat.epsmat[iq]
	epsmat.epsmat[iq] = linalg.inv(mat)

print
print 'Saving your the epsmat file to',f_out

epsmat.to_file(f_out)
Exemplo n.º 2
0
                      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)
        f.close()
Exemplo n.º 3
0
from numpy import *
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]
Exemplo n.º 4
0
        # "nmtx" = number of G vectors = rows = cols of epsinv
        nmtx = eps.nmtx[iq]
        # "qpt" is the vector for the current q-point
        qpt = eps.qpt[:, iq]
        # "mat" is the epsinv matrix
        mat = eps.epsmat[iq]
        # "gvec_q" is G + qpt, where "G" is the Gvector in the order
        # they appear in the row/columns of epsinv matrix ("mat")
        gidx = eps.isort[iq][:nmtx] - 1
        gvec_q = eps.gvec_k[:, gidx] + qpt[:, np.newaxis]

        # set the head to some value..
        mat[0, 0] = heads[iq]

        eps.epsmat[iq] = mat


if __name__ == '__main__':
    import sys

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

    f_in = sys.argv[1]
    f_out = sys.argv[2]

    eps = epsmatIO(f_in)
    eps_edit(eps)
    eps.to_file(f_out)
Exemplo n.º 5
0
fname_in = sys.argv[1]
fname_out = sys.argv[2]
grid = sys.argv[3].split(',')
if len(grid)!=3:
    print('Invalid q-grid entered: %s'%(sys.argv[3]))
    sys.exit(1)
grid = np.array(map(int, grid))

#copy the epsmat file, including q-points
import shutil
shutil.copyfile(fname_in, fname_out)

#open epsmat file, write fixed header to file fname_tmp1
from bgwtools.IO.epsmat import epsmatIO
fname_tmp = '_epsmat_tmp_'
epsmat = epsmatIO(fname_in, read_all=False)
print 'Original q-grid:', epsmat.grid
epsmat.grid = grid
print 'New q-grid:', epsmat.grid
epsmat.to_file(fname_tmp, write_all=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
os.unlink(fname_tmp)
Exemplo n.º 6
0
#!/usr/bin/env python

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

from bgwtools.IO.epsmat import epsmatIO
import sys
from numpy import amax

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

eps1 = epsmatIO(fname1)
eps2 = epsmatIO(fname2)

for iq in range(eps1.nq):
    print('iq = %d' % iq)
    diff = eps2.epsmat[iq] - eps1.epsmat[iq]
    max_diff = amax(abs(diff))
    print('||eps2 - eps1||_inf = %e' % max_diff)