2014-04-02 17:54:31 +02:00
|
|
|
from pytriqs.applications.dft.sumk_lda import *
|
|
|
|
from pytriqs.applications.dft.converters import Wien2kConverter
|
|
|
|
from pytriqs.gf.local.block_gf import BlockGf
|
|
|
|
from pytriqs.gf.local.gf_imfreq import GfImFreq
|
|
|
|
from pytriqs.archive import *
|
|
|
|
import pytriqs.utility.mpi as mpi
|
2014-11-15 15:30:10 +01:00
|
|
|
import numpy
|
|
|
|
import copy
|
2014-04-02 17:54:31 +02:00
|
|
|
|
|
|
|
class TransBasis:
|
2014-09-22 19:24:33 +02:00
|
|
|
'''Computates rotations into a new basis in order to make certain quantities diagonal.'''
|
2014-04-02 17:54:31 +02:00
|
|
|
|
|
|
|
def __init__(self, SK=None, hdf_datafile=None):
|
|
|
|
'''Inits the class by reading the input.'''
|
|
|
|
|
2014-11-10 10:49:27 +01:00
|
|
|
if SK is None:
|
2014-04-02 17:54:31 +02:00
|
|
|
# build our own SK instance
|
2014-11-10 10:49:27 +01:00
|
|
|
if hdf_datafile is None:
|
2014-11-15 15:30:10 +01:00
|
|
|
mpi.report("trans_basis: give SK instance or HDF filename!")
|
2014-04-02 17:54:31 +02:00
|
|
|
return 0
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-04-02 17:54:31 +02:00
|
|
|
Converter = Wien2kConverter(filename=hdf_datafile,repacking=False)
|
|
|
|
Converter.convert_dmft_input()
|
|
|
|
del Converter
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-04-02 17:54:31 +02:00
|
|
|
self.SK = SumkLDA(hdf_file=hdf_datafile+'.h5',use_lda_blocks=False)
|
|
|
|
else:
|
|
|
|
self.SK = SK
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-04-02 17:54:31 +02:00
|
|
|
self.T = copy.deepcopy(self.SK.T[0])
|
|
|
|
self.w = numpy.identity(SK.corr_shells[0][3])
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-04-02 17:54:31 +02:00
|
|
|
|
|
|
|
def __call__(self, prop_to_be_diagonal = 'eal'):
|
|
|
|
'''Calculates the diagonalisation.'''
|
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
if prop_to_be_diagonal == 'eal':
|
|
|
|
prop = self.SK.eff_atomic_levels()[0]
|
|
|
|
elif prop_to_be_diagonal == 'dm':
|
2014-11-16 18:02:04 +01:00
|
|
|
prop = self.SK.density_matrix(method = 'using_point_integration')[0]
|
2014-04-02 17:54:31 +02:00
|
|
|
else:
|
2014-11-15 15:30:10 +01:00
|
|
|
mpi.report("trans_basis: not a valid quantitiy to be diagonal. Choices are 'eal' or 'dm'.")
|
2014-04-02 17:54:31 +02:00
|
|
|
return 0
|
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
if self.SK.SO == 0:
|
|
|
|
self.eig,self.w = numpy.linalg.eigh(prop['up'])
|
|
|
|
# calculate new Transformation matrix
|
2014-04-02 17:54:31 +02:00
|
|
|
self.T = numpy.dot(self.T.transpose().conjugate(),self.w).conjugate().transpose()
|
|
|
|
else:
|
2014-11-15 15:30:10 +01:00
|
|
|
self.eig,self.w = numpy.linalg.eigh(prop['ud'])
|
|
|
|
# calculate new Transformation matrix
|
2014-04-02 17:54:31 +02:00
|
|
|
self.T = numpy.dot(self.T.transpose().conjugate(),self.w).conjugate().transpose()
|
|
|
|
|
|
|
|
# measure for the 'unity' of the transformation:
|
|
|
|
wsqr = sum(abs(self.w.diagonal())**2)/self.w.diagonal().size
|
|
|
|
return wsqr
|
|
|
|
|
|
|
|
|
|
|
|
def rotate_gf(self,gf_to_rot):
|
2014-09-22 19:24:33 +02:00
|
|
|
'''Rotates a given GF into the new basis.'''
|
2014-04-02 17:54:31 +02:00
|
|
|
|
|
|
|
# build a full GF
|
2014-11-14 11:21:58 +01:00
|
|
|
gfrotated = BlockGf( name_block_generator = [ (block,GfImFreq(indices = inner, mesh = gf_to_rot.mesh)) for block,inner in self.SK.gf_struct_sumk[0] ], make_copies = False)
|
2014-04-02 17:54:31 +02:00
|
|
|
|
|
|
|
# transform the CTQMC blocks to the full matrix:
|
2014-11-15 18:15:45 +01:00
|
|
|
ish = self.SK.corr_to_inequiv[0] # ish is the index of the inequivalent shell corresponding to icrsh
|
2014-11-15 15:30:10 +01:00
|
|
|
for block, inner in self.gf_struct_solver[ish].iteritems():
|
|
|
|
for ind1 in inner:
|
|
|
|
for ind2 in inner:
|
|
|
|
gfrotated[self.SK.solver_to_sumk_block[ish][block]][ind1,ind2] << gf_to_rot[block][ind1,ind2]
|
2014-04-02 17:54:31 +02:00
|
|
|
|
|
|
|
# Rotate using the matrix w
|
2014-11-14 09:43:28 +01:00
|
|
|
for bname,gf in gfrotated:
|
|
|
|
gfrotated[bname].from_L_G_R(self.w.transpose().conjugate(),gfrotated[bname],self.w)
|
2014-04-02 17:54:31 +02:00
|
|
|
|
|
|
|
gfreturn = gf_to_rot.copy()
|
|
|
|
# Put back into CTQMC basis:
|
2014-11-15 15:30:10 +01:00
|
|
|
for block, inner in self.gf_struct_solver[ish].iteritems():
|
|
|
|
for ind1 in inner:
|
|
|
|
for ind2 in inner:
|
2014-11-15 14:16:52 +01:00
|
|
|
gfreturn[block][ind1,ind2] << gfrotated[self.SK.solver_to_sumk_block[0][block]][ind1,ind2]
|
2014-04-02 17:54:31 +02:00
|
|
|
|
|
|
|
return gfreturn
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-04-02 17:54:31 +02:00
|
|
|
|
|
|
|
def write_trans_file(self, filename):
|
2014-09-22 19:24:33 +02:00
|
|
|
'''Writes the new transformation into a file readable by dmftproj.'''
|
2014-04-02 17:54:31 +02:00
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
f = open(filename,'w')
|
2014-04-02 17:54:31 +02:00
|
|
|
Tnew = self.T.conjugate()
|
2014-11-15 15:30:10 +01:00
|
|
|
dim = self.SK.corr_shells[0][3]
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
if self.SK.SO == 0:
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
for i in range(dim):
|
2014-04-02 17:54:31 +02:00
|
|
|
st = ''
|
2014-11-15 15:30:10 +01:00
|
|
|
for k in range(dim):
|
2014-04-02 17:54:31 +02:00
|
|
|
st += " %9.6f"%(Tnew[i,k].real)
|
|
|
|
st += " %9.6f"%(Tnew[i,k].imag)
|
2014-11-15 15:30:10 +01:00
|
|
|
for k in range(2*dim):
|
2014-04-02 17:54:31 +02:00
|
|
|
st += " 0.0"
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
if i < (dim-1):
|
2014-04-02 17:54:31 +02:00
|
|
|
f.write("%s\n"%(st))
|
|
|
|
else:
|
2014-11-15 15:30:10 +01:00
|
|
|
st1 = st.replace(' ','*',1)
|
2014-04-02 17:54:31 +02:00
|
|
|
f.write("%s\n"%(st1))
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
for i in range(dim):
|
2014-04-02 17:54:31 +02:00
|
|
|
st = ''
|
2014-11-15 15:30:10 +01:00
|
|
|
for k in range(2*dim):
|
2014-04-02 17:54:31 +02:00
|
|
|
st += " 0.0"
|
2014-11-15 15:30:10 +01:00
|
|
|
for k in range(dim):
|
2014-04-02 17:54:31 +02:00
|
|
|
st += " %9.6f"%(Tnew[i,k].real)
|
|
|
|
st += " %9.6f"%(Tnew[i,k].imag)
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
if i < (dim-1):
|
2014-04-02 17:54:31 +02:00
|
|
|
f.write("%s\n"%(st))
|
|
|
|
else:
|
2014-11-15 15:30:10 +01:00
|
|
|
st1 = st.replace(' ','*',1)
|
2014-04-02 17:54:31 +02:00
|
|
|
f.write("%s\n"%(st1))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
for i in range(dim):
|
2014-04-02 17:54:31 +02:00
|
|
|
st = ''
|
2014-11-15 15:30:10 +01:00
|
|
|
for k in range(dim):
|
2014-04-02 17:54:31 +02:00
|
|
|
st += " %9.6f"%(Tnew[i,k].real)
|
|
|
|
st += " %9.6f"%(Tnew[i,k].imag)
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-11-15 15:30:10 +01:00
|
|
|
if i < (dim-1):
|
2014-04-02 17:54:31 +02:00
|
|
|
f.write("%s\n"%(st))
|
|
|
|
else:
|
2014-11-15 15:30:10 +01:00
|
|
|
st1 = st.replace(' ','*',1)
|
2014-04-02 17:54:31 +02:00
|
|
|
f.write("%s\n"%(st1))
|
2014-09-22 19:24:33 +02:00
|
|
|
|
2014-04-02 17:54:31 +02:00
|
|
|
f.close()
|