diff --git a/python/build_sigma_from_txt.py b/python/build_sigma_from_txt.py deleted file mode 100644 index 6e64fc52..00000000 --- a/python/build_sigma_from_txt.py +++ /dev/null @@ -1,77 +0,0 @@ -import numpy -import string -from pytriqs.gf.local import * - -def read_fortran_file (filename): - """Returns a generator that yields all numbers in the Fortran file as float, one by one""" - import os.path - if not(os.path.exists(filename)) : raise IOError, "File %s does not exist."%filename - for line in open(filename,'r') : - for x in line.replace('D','E').split() : - yield string.atof(x) - -def line_count(fname): - """Counts the lines of a file""" - with open(fname) as f: - for i, l in enumerate(f): - pass - return i + 1 - -def constr_Sigma_real_axis(filename, gf_struct_orb, tol_mesh=1e-6): - """Uses Data from files to construct Sigma (or GF) on the real axis.""" - - # first get the mesh out of any one of the files: - bl = gf_struct_orb.items()[0][0] # block name - ol = gf_struct_orb.items()[0][1] # list of orbital indices - if (len(ol)==1): # if blocks are of size one - Fname = filename+'_'+bl+'.dat' - else: - Fname = filename+'_'+bl+'/'+str(ol[0])+'_'+str(ol[0])+'.dat' - - try: - n_om = line_count(Fname) - R = read_fortran_file(Fname) - mesh = numpy.zeros([n_om],numpy.float_) - - for i in xrange(n_om): - mesh[i] = R.next() - sk = R.next() - sk = R.next() - - except StopIteration : # a more explicit error if the file is corrupted. - raise "constr_Sigma_real_axis : reading mesh failed!" - R.close() - - # check whether the mesh is uniform - bin = (mesh[n_om-1]-mesh[0])/(n_om-1) - for i in xrange(n_om): - assert abs(i*bin+mesh[0]-mesh[i]) < tol_mesh, 'constr_Sigma_real_axis: real-axis mesh is non-uniform!' - - # construct Sigma - a_list = [a for a,al in gf_struct_orb.iteritems()] - glist = lambda : [ GfReFreq(indices = al, window=(mesh[0],mesh[n_om-1]),n_points=n_om) for a,al in gf_struct_orb.iteritems()] - SigmaME = BlockGf(name_list = a_list, block_list = glist(),make_copies=False) - - #read Sigma - for i,g in SigmaME: - mesh=[w for w in g.mesh] - for iL in g.indices: - for iR in g.indices: - if (len(g.indices) == 1): - Fname = filename+'_%s'%(i)+'.dat' - else: - Fname = 'SigmaME_'+'%s'%(i)+'_%s'%(iL)+'_%s'%(iR)+'.dat' - R = read_fortran_file(Fname) - try: - for iom in xrange(n_om): - sk = R.next() - rsig = R.next() - isig = R.next() - g.data[iom,iL,iR]=rsig+1j*isig - except StopIteration : # a more explicit error if the file is corrupted. - raise "constr_Sigma_real_axis : reading Sigma from file failed!" - R.close() - - SigmaME.note='ReFreq' - - return SigmaME diff --git a/test/sigma_from_file.output.h5 b/test/sigma_from_file.output.h5 index 47dee8e4..3381c321 100644 Binary files a/test/sigma_from_file.output.h5 and b/test/sigma_from_file.output.h5 differ diff --git a/test/sigma_from_file.py b/test/sigma_from_file.py index b033d9e9..fb5ffd82 100644 --- a/test/sigma_from_file.py +++ b/test/sigma_from_file.py @@ -1,7 +1,7 @@ from pytriqs.archive import * from pytriqs.gf.local import * +from pytriqs.gf.local.tools import * from pytriqs.applications.dft.sumk_dft_tools import * -from pytriqs.applications.dft.build_sigma_from_txt import * import numpy as np # Read self energy from hdf file @@ -19,12 +19,15 @@ for name, s in Sigma_hdf: # Read self energy from txt files SK = SumkDFTTools(hdf_file = 'SrVO3.h5', use_dft_blocks = True) -Sigma_txt = constr_Sigma_real_axis(filename='Sigma', gf_struct_orb=SK.gf_struct_solver[0]) + +a_list = [a for a,al in SK.gf_struct_solver[0].iteritems()] +g_list = [read_gf_from_txt([['Sigma_' + a + '.dat']], a) for a in a_list] +Sigma_txt = BlockGf(name_list = a_list, block_list = g_list, make_copies=False) + SK.put_Sigma(Sigma_imp = [Sigma_txt]) SK.hdf_file = 'sigma_from_file.output.h5' SK.save(['Sigma_imp_w']) - if ((Sigma_txt - Sigma_hdf).real < 1e-6) & ((Sigma_txt - Sigma_hdf).imag < 1e-6): print 'Conversion: HDF -> TRIQS -> TXT -> TRIQS successful!'