3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-06 22:23:52 +01:00

Some changes in the usage of build_sigma_from_txt.

This commit is contained in:
Manuel Zingl 2015-08-24 14:47:08 +02:00
parent 61747745f4
commit cf7628065b
3 changed files with 55 additions and 85 deletions

View File

@ -47,15 +47,12 @@ You may also have your self energy stored in text files. For this case we provid
:meth:`constr_Sigma_real_axis`, which loads the data and puts it into a real frequency :class:`BlockGf <pytriqs.gf.local.BlockGf>` object:: :meth:`constr_Sigma_real_axis`, which loads the data and puts it into a real frequency :class:`BlockGf <pytriqs.gf.local.BlockGf>` object::
from pytriqs.applications.dft.build_sigma_from_txt import * from pytriqs.applications.dft.build_sigma_from_txt import *
SigmaReFreq = constr_Sigma_real_axis(SK, filename, hdf=False, hdf_dataset='SigmaReFreq',n_om=0, orb=0) SigmaReFreq = constr_Sigma_real_axis(filename=filename, gf_struct_orb=SK.gf_struct_solver[0])
where: where:
* `filename`: the name of the hdf5 archive file or the `fname` pattern in text files names as described above, * `filename`: the `fname` pattern in text files names as described below,
* `hdf`: if `True`, the real axis self energy will be read from the hdf5 file, otherwise from the text files, * `gf_struct_orb`: the Greens function structure for the regarding inequivalent shell.
* `hdf_dataset`: the name of dataset where the self energy is stored in the hdf5 file,
* `orb`: index of an inequivalent shell,
* `n_om`: the number of points in the real-axis mesh (used only if `hdf=False`).
It is important that you follow some rules concerning the structure of your data files: It is important that you follow some rules concerning the structure of your data files:
* Each data file should contain three columns: real frequency, real part and imaginary part of the self energy exactly in this order. * Each data file should contain three columns: real frequency, real part and imaginary part of the self energy exactly in this order.

View File

@ -3,101 +3,74 @@ import string
from pytriqs.gf.local import * from pytriqs.gf.local import *
def read_fortran_file (filename): def read_fortran_file (filename):
""" Returns a generator that yields all numbers in the Fortran file as float, one by one""" """Returns a generator that yields all numbers in the Fortran file as float, one by one"""
import os.path import os.path
if not(os.path.exists(filename)) : raise IOError, "File %s does not exist."%filename if not(os.path.exists(filename)) : raise IOError, "File %s does not exist."%filename
for line in open(filename,'r') : for line in open(filename,'r') :
for x in line.replace('D','E').split() : for x in line.replace('D','E').split() :
yield string.atof(x) yield string.atof(x)
def constr_Sigma_real_axis(self, filename, hdf=True, hdf_dataset='SigmaReFreq',n_om=0,orb=0, tol_mesh=1e-6): 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.""" """Uses Data from files to construct Sigma (or GF) on the real axis."""
if not hdf: # then read sigma from text files # first get the mesh out of any one of the files:
bl = gf_struct_orb.items()[0][0] # block name
# first get the mesh out of any one of the files: ol = gf_struct_orb.items()[0][1] # list of orbital indices
bl = self.gf_struct_solver[orb].items()[0][0] # block name if (len(ol)==1): # if blocks are of size one
ol = self.gf_struct_solver[orb].items()[0][1] # list of orbital indices Fname = filename+'_'+bl+'.dat'
if (len(ol)==1): # if blocks are of size one else:
Fname = filename+'_'+bl+'.dat' Fname = filename+'_'+bl+'/'+str(ol[0])+'_'+str(ol[0])+'.dat'
else:
print 'TEST'
Fname = filename+'_'+bl+'/'+str(ol[0])+'_'+str(ol[0])+'.dat'
try:
n_om = line_count(Fname)
R = read_fortran_file(Fname) R = read_fortran_file(Fname)
mesh = numpy.zeros([n_om],numpy.float_) mesh = numpy.zeros([n_om],numpy.float_)
try:
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 "SumkDFT.read_Sigma_ME : 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): for i in xrange(n_om):
assert abs(i*bin+mesh[0]-mesh[i]) < tol_mesh, 'constr_Sigma_ME: real-axis mesh is non-uniform!' mesh[i] = R.next()
sk = R.next()
sk = R.next()
# construct Sigma except StopIteration : # a more explicit error if the file is corrupted.
a_list = [a for a,al in self.gf_struct_solver[orb].iteritems()] raise "constr_Sigma_real_axis : reading mesh failed!"
glist = lambda : [ GfReFreq(indices = al, window=(mesh[0],mesh[n_om-1]),n_points=n_om) for a,al in self.gf_struct_solver[orb].iteritems()] R.close()
SigmaME = BlockGf(name_list = a_list, block_list = glist(),make_copies=False)
#read Sigma # check whether the mesh is uniform
for i,g in SigmaME: bin = (mesh[n_om-1]-mesh[0])/(n_om-1)
mesh=[w for w in g.mesh] for i in xrange(n_om):
for iL in g.indices: assert abs(i*bin+mesh[0]-mesh[i]) < tol_mesh, 'constr_Sigma_real_axis: real-axis mesh is non-uniform!'
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 "SumkDFT.read_Sigma_ME : reading Sigma from file failed!"
R.close()
# 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)
else: # read sigma from hdf #read Sigma
for i,g in SigmaME:
omega_min=0.0 mesh=[w for w in g.mesh]
omega_max=0.0 for iL in g.indices:
n_om=0 for iR in g.indices:
if (mpi.is_master_node()): if (len(g.indices) == 1):
ar = HDFArchive(filename) Fname = filename+'_%s'%(i)+'.dat'
SigmaME = ar[hdf_dataset] else:
del ar Fname = 'SigmaME_'+'%s'%(i)+'_%s'%(iL)+'_%s'%(iR)+'.dat'
R = read_fortran_file(Fname)
#OTHER SOLUTION FIXME try:
#else: for iom in xrange(n_om):
# SigmaME=0 sk = R.next()
#SigmaME = mpi.broadcast.. rsig = R.next()
isig = R.next()
# we need some parameters to construct Sigma on other nodes g.data[iom,iL,iR]=rsig+1j*isig
omega_min=SigmaME.mesh.omega_min except StopIteration : # a more explicit error if the file is corrupted.
omega_max=SigmaME.mesh.omega_max raise "constr_Sigma_real_axis : reading Sigma from file failed!"
n_om=len(SigmaME.mesh) R.close()
omega_min=mpi.bcast(omega_min)
omega_max=mpi.bcast(omega_max)
n_om=mpi.bcast(n_om)
mpi.barrier()
# construct Sigma on other nodes
if (not mpi.is_master_node()):
a_list = [a for a,al in self.gf_struct_solver[orb].iteritems()]
glist = lambda : [ GfReFreq(indices = al, window=(omega_min,omega_max),n_points=n_om) for a,al in self.gf_struct_solver[orb].iteritems()]
SigmaME = BlockGf(name_list = a_list, block_list = glist(),make_copies=False)
# pass SigmaME to other nodes
SigmaME = mpi.bcast(SigmaME)
mpi.barrier()
SigmaME.note='ReFreq' SigmaME.note='ReFreq'

View File

@ -19,7 +19,7 @@ for name, s in Sigma_hdf:
# Read self energy from txt files # Read self energy from txt files
SK = SumkDFTTools(hdf_file = 'SrVO3.h5', use_dft_blocks = True) SK = SumkDFTTools(hdf_file = 'SrVO3.h5', use_dft_blocks = True)
Sigma_txt = constr_Sigma_real_axis(SK, 'Sigma', hdf=False, n_om=101, orb=0) Sigma_txt = constr_Sigma_real_axis(filename='Sigma', gf_struct_orb=SK.gf_struct_solver[0])
SK.put_Sigma(Sigma_imp = [Sigma_txt]) SK.put_Sigma(Sigma_imp = [Sigma_txt])
SK.hdf_file = 'sigma_from_file.output.h5' SK.hdf_file = 'sigma_from_file.output.h5'