3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-13 17:43:48 +01:00
dft_tools/python/sumk_dft_tools.py

560 lines
24 KiB
Python
Raw Normal View History

2013-07-23 19:49:42 +02:00
################################################################################
#
# TRIQS: a Toolbox for Research in Interacting Quantum Systems
#
# Copyright (C) 2011 by M. Aichhorn, L. Pourovskii, V. Vildosola
#
# TRIQS is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# TRIQS. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
from types import *
import numpy
import pytriqs.utility.dichotomy as dichotomy
from pytriqs.gf.local import *
import pytriqs.utility.mpi as mpi
from symmetry import *
2014-11-18 11:30:26 +01:00
from sumk_dft import SumkDFT
2013-07-23 19:49:42 +02:00
2014-11-18 11:30:26 +01:00
class SumkDFTTools(SumkDFT):
"""Extends the SumkDFT class with some tools for analysing the data."""
2013-07-23 19:49:42 +02:00
2014-11-18 11:30:26 +01:00
def __init__(self, hdf_file, mu = 0.0, h_field = 0.0, use_dft_blocks = False, dft_data = 'dft_input', symmcorr_data = 'dft_symmcorr_input',
parproj_data = 'dft_parproj_input', symmpar_data = 'dft_symmpar_input', bands_data = 'dft_bands_input'):
2013-07-23 19:49:42 +02:00
self.G_upfold_refreq = None
2014-11-18 11:30:26 +01:00
SumkDFT.__init__(self, hdf_file=hdf_file, mu=mu, h_field=h_field, use_dft_blocks=use_dft_blocks,
dft_data=dft_data, symmcorr_data=symmcorr_data, parproj_data=parproj_data,
symmpar_data=symmpar_data, bands_data=bands_data)
2013-07-23 19:49:42 +02:00
def downfold_pc(self,ik,ir,ish,bname,gf_to_downfold,gf_inp):
2013-07-23 19:49:42 +02:00
"""Downfolding a block of the Greens function"""
2013-07-23 19:49:42 +02:00
gf_downfolded = gf_inp.copy()
isp = self.spin_names_to_ind[self.SO][bname] # get spin index for proj. matrices
2013-07-23 19:49:42 +02:00
dim = self.shells[ish][3]
n_orb = self.n_orbitals[ik,isp]
L=self.proj_mat_pc[ik,isp,ish,ir,0:dim,0:n_orb]
R=self.proj_mat_pc[ik,isp,ish,ir,0:dim,0:n_orb].conjugate().transpose()
gf_downfolded.from_L_G_R(L,gf_to_downfold,R)
return gf_downfolded
def rotloc_all(self,ish,gf_to_rotate,direction):
"""Local <-> Global rotation of a GF block.
direction: 'toLocal' / 'toGlobal' """
2014-11-15 20:04:54 +01:00
assert (direction == 'toLocal' or direction == 'toGlobal'),"Give direction 'toLocal' or 'toGlobal' in rotloc!"
2013-07-23 19:49:42 +02:00
gf_rotated = gf_to_rotate.copy()
2014-11-15 20:04:54 +01:00
if direction == 'toGlobal':
if (self.rot_mat_all_time_inv[ish] == 1) and self.SO:
gf_rotated << gf_rotated.transpose()
2013-07-23 19:49:42 +02:00
gf_rotated.from_L_G_R(self.rot_mat_all[ish].conjugate(),gf_rotated,self.rot_mat_all[ish].transpose())
else:
gf_rotated.from_L_G_R(self.rot_mat_all[ish],gf_rotated,self.rot_mat_all[ish].conjugate().transpose())
2014-11-15 20:04:54 +01:00
elif direction == 'toLocal':
if (self.rot_mat_all_time_inv[ish] == 1) and self.SO:
gf_rotated << gf_rotated.transpose()
2013-07-23 19:49:42 +02:00
gf_rotated.from_L_G_R(self.rot_mat_all[ish].transpose(),gf_rotated,self.rot_mat_all[ish].conjugate())
else:
gf_rotated.from_L_G_R(self.rot_mat_all[ish].conjugate().transpose(),gf_rotated,self.rot_mat_all[ish])
2013-07-23 19:49:42 +02:00
return gf_rotated
def lattice_gf_realfreq(self, ik, mu, broadening, mesh=None, with_Sigma=True):
2013-07-23 19:49:42 +02:00
"""Calculates the lattice Green function on the real frequency axis. If self energy is
present and with_Sigma=True, the mesh is taken from Sigma. Otherwise, the mesh has to be given."""
ntoi = self.spin_names_to_ind[self.SO]
2014-11-17 10:48:04 +01:00
spn = self.spin_block_names[self.SO]
2013-07-23 19:49:42 +02:00
2014-11-15 20:04:54 +01:00
if not hasattr(self,"Sigma_imp"): with_Sigma=False
if with_Sigma:
assert all(type(gf) == GfReFreq for bname,gf in self.Sigma_imp[0]), "Real frequency Sigma needed for lattice_gf_realfreq!"
2013-07-23 19:49:42 +02:00
stmp = self.add_dc()
else:
2014-11-17 10:48:04 +01:00
assert (not mesh is None),"Without Sigma, give the mesh=(om_min,om_max,n_points) for lattice_gf_realfreq!"
2013-07-23 19:49:42 +02:00
2014-11-15 20:04:54 +01:00
if self.G_upfold_refreq is None:
# first setting up of G_upfold_refreq
2014-11-17 10:48:04 +01:00
block_structure = [ range(self.n_orbitals[ik,ntoi[sp]]) for sp in spn ]
gf_struct = [ (spn[isp], block_structure[isp]) for isp in range(self.n_spin_blocks[self.SO]) ]
block_ind_list = [block for block,inner in gf_struct]
2014-11-15 20:04:54 +01:00
if with_Sigma:
glist = lambda : [ GfReFreq(indices = inner, mesh=self.Sigma_imp[0].mesh) for block,inner in gf_struct]
2013-07-23 19:49:42 +02:00
else:
2014-11-15 20:04:54 +01:00
glist = lambda : [ GfReFreq(indices = inner, window=(mesh[0],mesh[1]), n_points=mesh[2]) for block,inner in gf_struct]
self.G_upfold_refreq = BlockGf(name_list = block_ind_list, block_list = glist(),make_copies=False)
self.G_upfold_refreq.zero()
2013-07-23 19:49:42 +02:00
GFsize = [ gf.N1 for bname,gf in self.G_upfold_refreq]
2014-11-17 10:48:04 +01:00
unchangedsize = all( [ self.n_orbitals[ik,ntoi[spn[isp]]] == GFsize[isp]
for isp in range(self.n_spin_blocks[self.SO]) ] )
2013-07-23 19:49:42 +02:00
2014-11-15 20:04:54 +01:00
if not unchangedsize:
2014-11-17 10:48:04 +01:00
block_structure = [ range(self.n_orbitals[ik,ntoi[sp]]) for sp in spn ]
gf_struct = [ (spn[isp], block_structure[isp]) for isp in range(self.n_spin_blocks[self.SO]) ]
block_ind_list = [block for block,inner in gf_struct]
2014-11-15 20:04:54 +01:00
if with_Sigma:
glist = lambda : [ GfReFreq(indices = inner, mesh =self.Sigma_imp[0].mesh) for block,inner in gf_struct]
2013-07-23 19:49:42 +02:00
else:
2014-11-15 20:04:54 +01:00
glist = lambda : [ GfReFreq(indices = inner, window=(mesh[0],mesh[1]), n_points=mesh[2]) for block,inner in gf_struct]
self.G_upfold_refreq = BlockGf(name_list = block_ind_list, block_list = glist(),make_copies=False)
self.G_upfold_refreq.zero()
2014-11-17 10:48:04 +01:00
idmat = [numpy.identity(self.n_orbitals[ik,ntoi[sp]],numpy.complex_) for sp in spn]
2013-07-23 19:49:42 +02:00
self.G_upfold_refreq << Omega + 1j*broadening
2013-07-23 19:49:42 +02:00
M = copy.deepcopy(idmat)
2014-11-17 10:48:04 +01:00
for isp in range(self.n_spin_blocks[self.SO]):
ind = ntoi[spn[isp]]
2013-07-23 19:49:42 +02:00
n_orb = self.n_orbitals[ik,ind]
2014-11-17 10:48:04 +01:00
M[isp] = self.hopping[ik,ind,0:n_orb,0:n_orb] - (idmat[isp]*mu) - (idmat[isp] * self.h_field * (1-2*isp))
self.G_upfold_refreq -= M
2013-07-23 19:49:42 +02:00
2014-11-15 20:04:54 +01:00
if with_Sigma:
tmp = self.G_upfold_refreq.copy() # init temporary storage
2014-11-15 20:04:54 +01:00
for icrsh in range(self.n_corr_shells):
for bname,gf in tmp: tmp[bname] << self.upfold(ik,icrsh,bname,stmp[icrsh][bname],gf)
self.G_upfold_refreq -= tmp # adding to the upfolded GF
2013-07-23 19:49:42 +02:00
self.G_upfold_refreq.invert()
2013-07-23 19:49:42 +02:00
return self.G_upfold_refreq
2013-07-23 19:49:42 +02:00
def check_input_dos(self, om_min, om_max, n_om, beta=10, broadening=0.01):
2013-07-23 19:49:42 +02:00
delta_om = (om_max-om_min)/(n_om-1)
om_mesh = numpy.zeros([n_om],numpy.float_)
for i in range(n_om): om_mesh[i] = om_min + delta_om * i
2013-07-23 19:49:42 +02:00
DOS = {}
for bn in self.spin_block_names[self.SO]:
2013-07-23 19:49:42 +02:00
DOS[bn] = numpy.zeros([n_om],numpy.float_)
2014-11-15 20:04:54 +01:00
DOSproj = [ {} for ish in range(self.n_inequiv_shells) ]
DOSproj_orb = [ {} for ish in range(self.n_inequiv_shells) ]
for ish in range(self.n_inequiv_shells):
for bn in self.spin_block_names[self.corr_shells[self.inequiv_to_corr[ish]][4]]:
dim = self.corr_shells[self.inequiv_to_corr[ish]][3]
DOSproj[ish][bn] = numpy.zeros([n_om],numpy.float_)
DOSproj_orb[ish][bn] = numpy.zeros([n_om,dim,dim],numpy.float_)
2013-07-23 19:49:42 +02:00
# init:
Gloc = []
for icrsh in range(self.n_corr_shells):
2014-11-17 10:48:04 +01:00
spn = self.spin_block_names[self.corr_shells[icrsh][4]]
glist = lambda : [ GfReFreq(indices = inner, window = (om_min,om_max), n_points = n_om) for block,inner in self.gf_struct_sumk[icrsh]]
2014-11-17 10:48:04 +01:00
Gloc.append(BlockGf(name_list = spn, block_list = glist(),make_copies=False))
2014-11-15 20:04:54 +01:00
for icrsh in range(self.n_corr_shells): Gloc[icrsh].zero() # initialize to zero
2014-11-15 20:04:54 +01:00
for ik in range(self.n_k):
2013-07-23 19:49:42 +02:00
G_upfold=self.lattice_gf_realfreq(ik=ik,mu=self.chemical_potential,broadening=broadening,mesh=(om_min,om_max,n_om),with_Sigma=False)
G_upfold *= self.bz_weights[ik]
2013-07-23 19:49:42 +02:00
# non-projected DOS
for iom in range(n_om):
for bname,gf in G_upfold:
2013-07-23 19:49:42 +02:00
asd = gf.data[iom,:,:].imag.trace()/(-3.1415926535)
DOS[bname][iom] += asd
2014-11-15 20:04:54 +01:00
for icrsh in range(self.n_corr_shells):
2013-07-23 19:49:42 +02:00
tmp = Gloc[icrsh].copy()
for bname,gf in tmp: tmp[bname] << self.downfold(ik,icrsh,bname,G_upfold[bname],gf) # downfolding G
2013-07-23 19:49:42 +02:00
Gloc[icrsh] += tmp
2014-11-15 20:04:54 +01:00
if self.symm_op != 0: Gloc = self.symmcorr.symmetrize(Gloc)
2013-07-23 19:49:42 +02:00
2014-11-15 20:04:54 +01:00
if self.use_rotations:
for icrsh in range(self.n_corr_shells):
for bname,gf in Gloc[icrsh]: Gloc[icrsh][bname] << self.rotloc(icrsh,gf,direction='toLocal')
2013-07-23 19:49:42 +02:00
# Gloc can now also be used to look at orbitally resolved quantities
for ish in range(self.n_inequiv_shells):
for bname,gf in Gloc[self.inequiv_to_corr[ish]]: # loop over spins
for iom in range(n_om): DOSproj[ish][bname][iom] += gf.data[iom,:,:].imag.trace()/(-3.1415926535)
2013-07-23 19:49:42 +02:00
DOSproj_orb[ish][bname][:,:,:] += gf.data[:,:,:].imag/(-3.1415926535)
2013-07-23 19:49:42 +02:00
# output:
2014-11-15 20:04:54 +01:00
if mpi.is_master_node():
for bn in self.spin_block_names[self.SO]:
2013-07-23 19:49:42 +02:00
f=open('DOS%s.dat'%bn, 'w')
for i in range(n_om): f.write("%s %s\n"%(om_mesh[i],DOS[bn][i]))
f.close()
2013-07-23 19:49:42 +02:00
for ish in range(self.n_inequiv_shells):
2013-07-23 19:49:42 +02:00
f=open('DOS%s_proj%s.dat'%(bn,ish),'w')
for i in range(n_om): f.write("%s %s\n"%(om_mesh[i],DOSproj[ish][bn][i]))
f.close()
for i in range(self.corr_shells[self.inequiv_to_corr[ish]][3]):
for j in range(i,self.corr_shells[self.inequiv_to_corr[ish]][3]):
2013-07-23 19:49:42 +02:00
Fname = 'DOS'+bn+'_proj'+str(ish)+'_'+str(i)+'_'+str(j)+'.dat'
f=open(Fname,'w')
for iom in range(n_om): f.write("%s %s\n"%(om_mesh[iom],DOSproj_orb[ish][bn][iom,i,j]))
2013-07-23 19:49:42 +02:00
f.close()
2013-07-23 19:49:42 +02:00
def read_parproj_input_from_hdf(self):
2013-07-23 19:49:42 +02:00
"""
Reads the data for the partial projectors from the HDF file
"""
2014-10-31 18:52:32 +01:00
things_to_read = ['dens_mat_below','n_parproj','proj_mat_pc','rot_mat_all','rot_mat_all_time_inv']
value_read = self.read_input_from_hdf(subgrp=self.parproj_data,things_to_read = things_to_read)
return value_read
2013-07-23 19:49:42 +02:00
def dos_partial(self,broadening=0.01):
"""calculates the orbitally-resolved DOS"""
assert hasattr(self,"Sigma_imp"), "Set Sigma First!!"
value_read = self.read_parproj_input_from_hdf()
if not value_read: return value_read
if self.symm_op: self.symmpar = Symmetry(self.hdf_file,subgroup=self.symmpar_data)
2013-07-23 19:49:42 +02:00
mu = self.chemical_potential
2014-11-17 10:48:04 +01:00
gf_struct_proj = [ [ (sp, range(self.shells[i][3])) for sp in self.spin_block_names[self.SO] ] for i in range(self.n_shells) ]
Gproj = [BlockGf(name_block_generator = [ (block,GfReFreq(indices = inner, mesh = self.Sigma_imp[0].mesh)) for block,inner in gf_struct_proj[ish] ], make_copies = False )
2014-11-15 20:04:54 +01:00
for ish in range(self.n_shells)]
2013-07-23 19:49:42 +02:00
for ish in range(self.n_shells): Gproj[ish].zero()
Msh = [x.real for x in self.Sigma_imp[0].mesh]
2013-07-23 19:49:42 +02:00
n_om = len(Msh)
DOS = {}
for bn in self.spin_block_names[self.SO]:
2013-07-23 19:49:42 +02:00
DOS[bn] = numpy.zeros([n_om],numpy.float_)
DOSproj = [ {} for ish in range(self.n_shells) ]
DOSproj_orb = [ {} for ish in range(self.n_shells) ]
for ish in range(self.n_shells):
for bn in self.spin_block_names[self.SO]:
2014-11-15 20:04:54 +01:00
dim = self.shells[ish][3]
2013-07-23 19:49:42 +02:00
DOSproj[ish][bn] = numpy.zeros([n_om],numpy.float_)
2014-11-15 20:04:54 +01:00
DOSproj_orb[ish][bn] = numpy.zeros([n_om,dim,dim],numpy.float_)
2013-07-23 19:49:42 +02:00
ikarray=numpy.array(range(self.n_k))
for ik in mpi.slice_array(ikarray):
S = self.lattice_gf_realfreq(ik=ik,mu=mu,broadening=broadening)
S *= self.bz_weights[ik]
# non-projected DOS
for iom in range(n_om):
for bname,gf in S: DOS[bname][iom] += gf.data[iom,:,:].imag.trace()/(-3.1415926535)
2013-07-23 19:49:42 +02:00
#projected DOS:
2014-11-15 20:04:54 +01:00
for ish in range(self.n_shells):
2013-07-23 19:49:42 +02:00
tmp = Gproj[ish].copy()
2014-11-15 20:04:54 +01:00
for ir in range(self.n_parproj[ish]):
for bname,gf in tmp: tmp[bname] << self.downfold_pc(ik,ir,ish,bname,S[bname],gf)
2013-07-23 19:49:42 +02:00
Gproj[ish] += tmp
2013-07-23 19:49:42 +02:00
# collect data from mpi:
for bname in DOS:
2014-11-15 20:04:54 +01:00
DOS[bname] = mpi.all_reduce(mpi.world, DOS[bname], lambda x,y : x+y)
for ish in range(self.n_shells):
Gproj[ish] << mpi.all_reduce(mpi.world, Gproj[ish], lambda x,y : x+y)
mpi.barrier()
2014-11-15 20:04:54 +01:00
if self.symm_op != 0: Gproj = self.symmpar.symmetrize(Gproj)
2013-07-23 19:49:42 +02:00
# rotation to local coord. system:
2014-11-15 20:04:54 +01:00
if self.use_rotations:
for ish in range(self.n_shells):
for bname,gf in Gproj[ish]: Gproj[ish][bname] << self.rotloc_all(ish,gf,direction='toLocal')
2013-07-23 19:49:42 +02:00
for ish in range(self.n_shells):
for bname,gf in Gproj[ish]:
for iom in range(n_om): DOSproj[ish][bname][iom] += gf.data[iom,:,:].imag.trace()/(-3.1415926535)
DOSproj_orb[ish][bname][:,:,:] += gf.data[:,:,:].imag / (-3.1415926535)
2013-07-23 19:49:42 +02:00
2014-11-15 20:04:54 +01:00
if mpi.is_master_node():
2013-07-23 19:49:42 +02:00
# output to files
for bn in self.spin_block_names[self.SO]:
2013-07-23 19:49:42 +02:00
f=open('./DOScorr%s.dat'%bn, 'w')
for i in range(n_om): f.write("%s %s\n"%(Msh[i],DOS[bn][i]))
f.close()
2013-07-23 19:49:42 +02:00
# partial
for ish in range(self.n_shells):
f=open('DOScorr%s_proj%s.dat'%(bn,ish),'w')
for i in range(n_om): f.write("%s %s\n"%(Msh[i],DOSproj[ish][bn][i]))
f.close()
2013-07-23 19:49:42 +02:00
for i in range(self.shells[ish][3]):
for j in range(i,self.shells[ish][3]):
Fname = './DOScorr'+bn+'_proj'+str(ish)+'_'+str(i)+'_'+str(j)+'.dat'
f=open(Fname,'w')
for iom in range(n_om): f.write("%s %s\n"%(Msh[iom],DOSproj_orb[ish][bn][iom,i,j]))
2013-07-23 19:49:42 +02:00
f.close()
def spaghettis(self,broadening,shift=0.0,plot_range=None, ishell=None, invert_Akw=False, fermi_surface=False):
""" Calculates the correlated band structure with a real-frequency self energy.
2013-07-23 19:49:42 +02:00
ATTENTION: Many things from the original input file are are overwritten!!!"""
assert hasattr(self,"Sigma_imp"), "Set Sigma First!!"
2014-10-31 18:52:32 +01:00
things_to_read = ['n_k','n_orbitals','proj_mat','hopping','n_parproj','proj_mat_pc']
value_read = self.read_input_from_hdf(subgrp=self.bands_data,things_to_read=things_to_read)
if not value_read: return value_read
2013-07-23 19:49:42 +02:00
if fermi_surface: ishell=None
2014-10-31 18:52:32 +01:00
# FIXME CAN REMOVE?
2013-07-23 19:49:42 +02:00
# print hamiltonian for checks:
2014-11-15 20:04:54 +01:00
if self.SP == 1 and self.SO == 0:
2013-07-23 19:49:42 +02:00
f1=open('hamup.dat','w')
f2=open('hamdn.dat','w')
2014-11-15 20:04:54 +01:00
for ik in range(self.n_k):
for i in range(self.n_orbitals[ik,0]):
2013-07-23 19:49:42 +02:00
f1.write('%s %s\n'%(ik,self.hopping[ik,0,i,i].real))
2014-11-15 20:04:54 +01:00
for i in range(self.n_orbitals[ik,1]):
2013-07-23 19:49:42 +02:00
f2.write('%s %s\n'%(ik,self.hopping[ik,1,i,i].real))
f1.write('\n')
f2.write('\n')
f1.close()
f2.close()
else:
f=open('ham.dat','w')
2014-11-15 20:04:54 +01:00
for ik in range(self.n_k):
for i in range(self.n_orbitals[ik,0]):
2013-07-23 19:49:42 +02:00
f.write('%s %s\n'%(ik,self.hopping[ik,0,i,i].real))
f.write('\n')
f.close()
2013-07-23 19:49:42 +02:00
#=========================================
# calculate A(k,w):
mu = self.chemical_potential
2014-11-17 10:48:04 +01:00
spn = self.spin_block_names[self.SO]
2013-07-23 19:49:42 +02:00
# init DOS:
2014-01-22 22:57:18 +01:00
M = [x.real for x in self.Sigma_imp[0].mesh]
2013-07-23 19:49:42 +02:00
n_om = len(M)
if plot_range is None:
om_minplot = M[0]-0.001
om_maxplot = M[n_om-1] + 0.001
else:
om_minplot = plot_range[0]
om_maxplot = plot_range[1]
2014-11-15 20:04:54 +01:00
if ishell is None:
2013-07-23 19:49:42 +02:00
Akw = {}
2014-11-17 10:48:04 +01:00
for sp in spn: Akw[sp] = numpy.zeros([self.n_k, n_om ],numpy.float_)
2013-07-23 19:49:42 +02:00
else:
Akw = {}
2014-11-17 10:48:04 +01:00
for sp in spn: Akw[sp] = numpy.zeros([self.shells[ishell][3],self.n_k, n_om ],numpy.float_)
2013-07-23 19:49:42 +02:00
if fermi_surface:
om_minplot = -2.0*broadening
om_maxplot = 2.0*broadening
Akw = {}
2014-11-17 10:48:04 +01:00
for sp in spn: Akw[sp] = numpy.zeros([self.n_k,1],numpy.float_)
2013-07-23 19:49:42 +02:00
2014-11-17 10:48:04 +01:00
if not ishell is None:
GFStruct_proj = [ (sp, range(self.shells[ishell][3])) for sp in spn ]
Gproj = BlockGf(name_block_generator = [ (block,GfReFreq(indices = inner, mesh = self.Sigma_imp[0].mesh)) for block,inner in GFStruct_proj ], make_copies = False)
2013-07-23 19:49:42 +02:00
Gproj.zero()
2014-11-15 20:04:54 +01:00
for ik in range(self.n_k):
2013-07-23 19:49:42 +02:00
S = self.lattice_gf_realfreq(ik=ik,mu=mu,broadening=broadening)
2014-11-15 20:04:54 +01:00
if ishell is None:
2013-07-23 19:49:42 +02:00
# non-projected A(k,w)
for iom in range(n_om):
2014-11-15 20:04:54 +01:00
if (M[iom] > om_minplot) and (M[iom] < om_maxplot):
2013-07-23 19:49:42 +02:00
if fermi_surface:
for bname,gf in S: Akw[bname][ik,0] += gf.data[iom,:,:].imag.trace()/(-3.1415926535) * (M[1]-M[0])
2013-07-23 19:49:42 +02:00
else:
for bname,gf in S: Akw[bname][ik,iom] += gf.data[iom,:,:].imag.trace()/(-3.1415926535)
Akw[bname][ik,iom] += ik*shift # shift Akw for plotting in xmgrace -- REMOVE
2013-07-23 19:49:42 +02:00
else:
# projected A(k,w):
Gproj.zero()
tmp = Gproj.copy()
2014-11-15 20:04:54 +01:00
for ir in range(self.n_parproj[ishell]):
for bname,gf in tmp: tmp[bname] << self.downfold_pc(ik,ir,ishell,bname,S[bname],gf)
2013-07-23 19:49:42 +02:00
Gproj += tmp
2014-10-31 18:52:32 +01:00
# FIXME NEED TO READ IN ROTMAT_ALL FROM PARPROJ SUBGROUP, REPLACE ROTLOC WITH ROTLOC_ALL
2013-07-23 19:49:42 +02:00
# TO BE FIXED:
# rotate to local frame
#if (self.use_rotations):
# for bname,gf in Gproj: Gproj[bname] << self.rotloc(0,gf,direction='toLocal')
2013-07-23 19:49:42 +02:00
for iom in range(n_om):
2014-11-15 20:04:54 +01:00
if (M[iom] > om_minplot) and (M[iom] < om_maxplot):
2013-07-23 19:49:42 +02:00
for ish in range(self.shells[ishell][3]):
2014-11-17 10:48:04 +01:00
for ibn in spn:
2013-07-23 19:49:42 +02:00
Akw[ibn][ish,ik,iom] = Gproj[ibn].data[iom,ish,ish].imag/(-3.1415926535)
2013-07-23 19:49:42 +02:00
# END k-LOOP
2014-11-15 20:04:54 +01:00
if mpi.is_master_node():
if ishell is None:
2014-11-17 10:48:04 +01:00
for ibn in spn:
2013-07-23 19:49:42 +02:00
# loop over GF blocs:
2014-11-15 20:04:54 +01:00
if invert_Akw:
2013-07-23 19:49:42 +02:00
maxAkw=Akw[ibn].max()
minAkw=Akw[ibn].min()
# open file for storage:
if fermi_surface:
f=open('FS_'+ibn+'.dat','w')
else:
f=open('Akw_'+ibn+'.dat','w')
for ik in range(self.n_k):
if fermi_surface:
2014-11-15 20:04:54 +01:00
if invert_Akw:
Akw[ibn][ik,0] = 1.0/(minAkw-maxAkw)*(Akw[ibn][ik,0] - maxAkw)
2013-07-23 19:49:42 +02:00
f.write('%s %s\n'%(ik,Akw[ibn][ik,0]))
else:
for iom in range(n_om):
2014-11-15 20:04:54 +01:00
if (M[iom] > om_minplot) and (M[iom] < om_maxplot):
if invert_Akw:
2013-07-23 19:49:42 +02:00
Akw[ibn][ik,iom] = 1.0/(minAkw-maxAkw)*(Akw[ibn][ik,iom] - maxAkw)
2014-11-15 20:04:54 +01:00
if shift > 0.0001:
2013-07-23 19:49:42 +02:00
f.write('%s %s\n'%(M[iom],Akw[ibn][ik,iom]))
else:
f.write('%s %s %s\n'%(ik,M[iom],Akw[ibn][ik,iom]))
f.write('\n')
2013-07-23 19:49:42 +02:00
f.close()
else:
2014-11-17 10:48:04 +01:00
for ibn in spn:
2013-07-23 19:49:42 +02:00
for ish in range(self.shells[ishell][3]):
2014-11-15 20:04:54 +01:00
if invert_Akw:
2013-07-23 19:49:42 +02:00
maxAkw=Akw[ibn][ish,:,:].max()
minAkw=Akw[ibn][ish,:,:].min()
f=open('Akw_'+ibn+'_proj'+str(ish)+'.dat','w')
2013-07-23 19:49:42 +02:00
for ik in range(self.n_k):
for iom in range(n_om):
2014-11-15 20:04:54 +01:00
if (M[iom] > om_minplot) and (M[iom] < om_maxplot):
if invert_Akw:
2013-07-23 19:49:42 +02:00
Akw[ibn][ish,ik,iom] = 1.0/(minAkw-maxAkw)*(Akw[ibn][ish,ik,iom] - maxAkw)
2014-11-15 20:04:54 +01:00
if shift > 0.0001:
2013-07-23 19:49:42 +02:00
f.write('%s %s\n'%(M[iom],Akw[ibn][ish,ik,iom]))
else:
f.write('%s %s %s\n'%(ik,M[iom],Akw[ibn][ish,ik,iom]))
f.write('\n')
2013-07-23 19:49:42 +02:00
f.close()
def partial_charges(self,beta=40):
"""Calculates the orbitally-resolved density matrix for all the orbitals considered in the input.
The theta-projectors are used, hence case.parproj data is necessary"""
value_read = self.read_parproj_input_from_hdf()
if not value_read: return value_read
if self.symm_op: self.symmpar = Symmetry(self.hdf_file,subgroup=self.symmpar_data)
2013-07-23 19:49:42 +02:00
# Density matrix in the window
2014-11-17 10:48:04 +01:00
spn = self.spin_block_names[self.SO]
ntoi = self.spin_names_to_ind[self.SO]
self.dens_mat_window = [ [numpy.zeros([self.shells[ish][3],self.shells[ish][3]],numpy.complex_) for ish in range(self.n_shells)]
2014-11-17 10:48:04 +01:00
for isp in range(len(spn)) ] # init the density matrix
2013-07-23 19:49:42 +02:00
mu = self.chemical_potential
2014-11-17 10:48:04 +01:00
GFStruct_proj = [ [ (sp, range(self.shells[i][3])) for sp in spn ] for i in range(self.n_shells) ]
2013-07-23 19:49:42 +02:00
if hasattr(self,"Sigma_imp"):
Gproj = [BlockGf(name_block_generator = [ (block,GfImFreq(indices = inner, mesh = self.Sigma_imp[0].mesh)) for block,inner in GFStruct_proj[ish] ], make_copies = False)
2014-11-15 20:04:54 +01:00
for ish in range(self.n_shells)]
2013-07-23 19:49:42 +02:00
beta = self.Sigma_imp[0].mesh.beta
else:
Gproj = [BlockGf(name_block_generator = [ (block,GfImFreq(indices = inner, beta = beta)) for block,inner in GFStruct_proj[ish] ], make_copies = False)
2014-11-15 20:04:54 +01:00
for ish in range(self.n_shells)]
2013-07-23 19:49:42 +02:00
2014-11-15 20:04:54 +01:00
for ish in range(self.n_shells): Gproj[ish].zero()
2013-07-23 19:49:42 +02:00
ikarray=numpy.array(range(self.n_k))
2013-07-23 19:49:42 +02:00
for ik in mpi.slice_array(ikarray):
S = self.lattice_gf_matsubara(ik=ik,mu=mu,beta=beta)
S *= self.bz_weights[ik]
2014-11-15 20:04:54 +01:00
for ish in range(self.n_shells):
2013-07-23 19:49:42 +02:00
tmp = Gproj[ish].copy()
2014-11-15 20:04:54 +01:00
for ir in range(self.n_parproj[ish]):
for bname,gf in tmp: tmp[bname] << self.downfold_pc(ik,ir,ish,bname,S[bname],gf)
2013-07-23 19:49:42 +02:00
Gproj[ish] += tmp
2013-07-23 19:49:42 +02:00
#collect data from mpi:
2014-11-15 20:04:54 +01:00
for ish in range(self.n_shells):
Gproj[ish] << mpi.all_reduce(mpi.world, Gproj[ish], lambda x,y : x+y)
2013-07-23 19:49:42 +02:00
mpi.barrier()
# Symmetrisation:
2014-11-15 20:04:54 +01:00
if self.symm_op != 0: Gproj = self.symmpar.symmetrize(Gproj)
2014-11-15 20:04:54 +01:00
for ish in range(self.n_shells):
2013-07-23 19:49:42 +02:00
# Rotation to local:
2014-11-15 20:04:54 +01:00
if self.use_rotations:
for bname,gf in Gproj[ish]: Gproj[ish][bname] << self.rotloc_all(ish,gf,direction='toLocal')
2013-07-23 19:49:42 +02:00
isp = 0
for bname,gf in Gproj[ish]: #dmg.append(Gproj[ish].density()[bname])
self.dens_mat_window[isp][ish] = Gproj[ish].density()[bname]
2013-07-23 19:49:42 +02:00
isp+=1
2013-07-23 19:49:42 +02:00
# add Density matrices to get the total:
2014-11-17 10:48:04 +01:00
dens_mat = [ [ self.dens_mat_below[ntoi[spn[isp]]][ish]+self.dens_mat_window[isp][ish] for ish in range(self.n_shells)]
for isp in range(len(spn)) ]
2013-07-23 19:49:42 +02:00
return dens_mat