def Compute_Energy(self, DFT, TB, ed): #"""This module compute totoal energy using DMFT""" self.ETOT = 0.0 self.ETOT2 = 0.0 self.EPOT = 0.0 self.EPOT2 = 0.0 self.EDC = 0.0 self.EKIN = 0.0 #self.EKIN0=0.0 DFT.Read_OSZICAR('OSZICAR') ETOT_imp = 0.0 TrDeltaG = 0.0 for i, ats in enumerate(self.cor_at): self.EPOT2 += len(ats) * self.TrSigG[i] #E_KIN2+=len(ats)*DMFT.Ekin[i] om, Delta = Fileio.Read_complex_multilines('imp.' + str(i) + '/Delta.inp') om, G_loc = Fileio.Read_complex_multilines('G_loc.out') #om2,Gf=Fileio.Read_complex_multilines('imp.'+str(i)+'/Gf.out',1) #nom_s=min(len(om),len(om2)) for j, orbs in enumerate(self.cor_orb[i]): TrDeltaG += 2 * len(ats) * len(orbs) * Compute_TrG1G2( om, Delta[j], G_loc[j], self.T) #TrDeltaG+=Compute_TrG1G2(om[:nom_s],Delta[j][:nom_s],Gf[j][:nom_s],self.T) ETOT_imp += len(ats) * (self.Ekin_imp[i] + self.Epot_imp[i] - self.mu_imp[i] * self.Nd_imp[i]) fiDMFT = open('INFO_KSUM', 'r') Eline = fiDMFT.readlines()[-1:] self.EKIN = float(Eline[0].split()[4]) fiDMFT.close() om, Sig_loc = Fileio.Read_complex_multilines('sig.inp', 5) om, G_loc = Fileio.Read_complex_multilines('G_loc.out') #print shape(Sig_loc) #print shape(G_loc) idx = -1 for i, ats in enumerate(self.cor_at): d_orb = TB.TB_orbs[ats[0]] for j, orbs in enumerate(self.cor_orb[i]): idx += 1 self.EPOT += len(ats) * len(orbs) * Compute_TrG1G2( om, Sig_loc[idx], G_loc[idx], self.T) for orb in orbs: # spin X2 self.EPOT += 0.5 * len( ats) * self.Sigoo[i][j] * self.N_latt[i, d_orb.index(orb)] VdcNd = 0.0 VdcNd2 = 0.0 VdcNd3 = 0.0 for i, ats in enumerate(self.cor_at): VdcNd2 += len(ats) * self.Vdc[i] * self.Nd_imp[ i] #*DMFT.Nd_imp[i]**2 VdcNd3 += len(ats) * self.Vdc[i] * self.Nd_latt[i] VdcNd += len(ats) * self.mu * self.Nd_latt[i] d_orb = TB.TB_orbs[ats[0]] for j, orbs in enumerate(self.cor_orb[i]): for orb in orbs: VdcNd -= len(ats) * ed[i][j] * self.N_latt[ i, d_orb.index(orb)]
# # if itt==0 and it==0: # fi=open('VASP_mu.out','w') # print >>fi, DMFT_mu # fi.close() main_out.write('--- DMFT Ksum is finished ' + now() + '---') main_out.write('\n') main_out.flush() #for i in range(len(cor_at)): # DMFT.sig_st[i][:]+=0.5*(DMFT.Nd_imp[i]-DMFT.Nd_latt[i]) #DMFT.Impurity_Solver #if itt%3==0: om_loc, Delta = Fileio.Read_complex_multilines('Delta.out') loc_idx = -1 for i, ats in enumerate(cor_at): Delta_loc = zeros((len(cor_orb[i]), len(om_loc)), dtype=complex) for j, orbs in enumerate(cor_orb[i]): loc_idx += 1 Delta_loc[j, :] = copy.deepcopy(Delta[loc_idx, :]) Fileio.Print_complex_multilines( Delta_loc, om_loc, 'Delta' + str(i + 1) + '.inp') # shutil.copy2('Delta.out','Delta1.inp') Ed = array([loadtxt('Ed.out')]) if TB.LHF == '.FALSE.': IMP_SOLVER.RUN_CTQMC(p, pC, pD, it, itt, para_com, DMFT.mu, Ed, DMFT.Vdc) main_out.write('--- Impurity solver is finished ' + now() + '---')
def Compute_Delta(self, T, nspin, cor_at, cor_orb, TB, nom, delta=0.0): ##### Store local Green function and local Self energy with equidistant mesh as a list type ########## ommesh, tot_GLOC = Fileio.Read_complex_multilines("G_loc.out") ommesh, tot_SIGLOC = Fileio.Read_complex_multilines("SigMoo.out") SIGMDC = loadtxt("SigMdc.out") if nspin == 2: ommesh, tot_GLOC_dn = Fileio.Read_complex_multilines("G_loc_dn.out") ommesh, tot_SIGLOC_dn = Fileio.Read_complex_multilines("SigMoo_dn.out") SIGMDC_dn = loadtxt("SigMdc_dn.out") DMFT_mu = loadtxt("DMFT_mu.out") tot_ed = loadtxt("Ed.out") # tot_sig_st=loadtxt('Sig_st.out') ed = [] GLOC = [] SIGLOC = [] for i, ats in enumerate(cor_at): GLOC.append([]) SIGLOC.append([]) ed.append([]) # sig_st.append([]) for j, orbs in enumerate(cor_orb[i]): Gf_avg = zeros(len(ommesh), dtype=complex) Sig_avg = zeros(len(ommesh), dtype=complex) ed_avg = 0.0 # sigst_avg=0.0 for at in ats: for orb in orbs: idx = TB.idx[at][orb] Gf_avg += tot_GLOC[idx] Sig_avg += tot_SIGLOC[idx] + SIGMDC[idx] ed_avg += tot_ed[idx] # sigst_avg+=DMFT.Sig_st[i][j]#tot_sig_st[idx] Gf_avg /= len(ats) * len(orbs) Sig_avg /= len(ats) * len(orbs) # ;Sig_avg-=sig_st[i] ed_avg /= len(ats) * len(orbs) # sigst_avg/=len(ats)*len(orbs) GLOC[i].append(list(Gf_avg)) SIGLOC[i].append(list(Sig_avg)) ed[i].append(ed_avg) # sig_st[i].append(sigst_avg) if nspin == 2: GLOC_dn = [] SIGLOC_dn = [] for i, ats in enumerate(cor_at): GLOC_dn.append([]) SIGLOC_dn.append([]) for j, orbs in enumerate(cor_orb[i]): Gf_avg = zeros(len(ommesh), dtype=complex) Sig_avg = zeros(len(ommesh), dtype=complex) for at in ats: for orb in orbs: idx = TB.idx[at][orb] Gf_avg += tot_GLOC_dn[idx] Sig_avg += tot_SIGLOC_dn[idx] + SIGMDC_dn[idx] Gf_avg /= len(ats) * len(orbs) Sig_avg /= len(ats) * len(orbs) # ;Sig_avg-=sig_st[i] GLOC_dn[i].append(list(Gf_avg)) SIGLOC_dn[i].append(list(Sig_avg)) for i in range(len(GLOC)): if len(GLOC[i]) > 0: Delta_s = zeros((nspin * len(GLOC[i]), len(ommesh)), dtype=complex) for j in range(len(GLOC[i])): Delta_s[j, :] = ( 1j * ommesh + DMFT_mu - ed[i][j] - array(SIGLOC[i][j]) + 1j * delta - 1.0 / array(GLOC[i][j]) ) if nspin == 2: for j in range(len(GLOC[i])): Delta_s[j + len(GLOC[i]), :] = ( 1j * ommesh + DMFT_mu - ed[i][j] - array(SIGLOC_dn[i][j]) + 1j * delta - 1.0 / array(GLOC_dn[i][j]) ) ###### Interpolate Delta #### ommesh_new = pi * T * (2 * arange(nom) + 1) Delta = Interpolate(ommesh, Delta_s, ommesh_new, 3) Fileio.Print_complex_multilines( Delta, ommesh_new, "Delta" + str(i + 1) + ".inp" ) return DMFT_mu, ed # ,sig_st
def Mix_Sig_and_Print_sig_inp(self, TB, Nd_qmc, mix_sig, sig_file, nspin): fi = open(sig_file, "r") self.nom, self.ncor_orb = map(int, fi.readline()[16:].split()) fi.readline() fi.readline() Sigoo_old = eval(fi.readline()[8:]) Vdc_old = eval(fi.readline()[7:]) fi.close() om, Sig_old = Fileio.Read_complex_multilines(sig_file, 5) sym_Sigoo = self.Symmetrize_orb(TB, self.Sigoo, nspin) sym_Sigoo_imp = self.Symmetrize_orb(TB, self.Sigoo_imp, nspin) sym_Vdc = [] sym_Vdc_imp = [] for i, ats in enumerate(self.cor_at): for j, orbs in enumerate(self.cor_orb[i]): sym_Vdc.append(self.Vdc[i]) sym_Vdc_imp.append(self.Vdc_imp[i]) if nspin == 2: for j, orbs in enumerate(self.cor_orb[i]): sym_Vdc.append(self.Vdc[i]) sym_Vdc_imp.append(self.Vdc_imp[i]) # print self.Sigoo_imp,sym_Sigoo_imp # print array(Sigoo_old),sym_Sigoo_imp if Nd_qmc == 1: new_Sigoo = array(Sigoo_old) + mix_sig * ( array(sym_Sigoo_imp) - array(Sigoo_old) ) new_Vdc = array(Vdc_old) + mix_sig * (array(sym_Vdc_imp) - array(Vdc_old)) else: new_Sigoo = array(Sigoo_old) + mix_sig * ( array(sym_Sigoo) - array(Sigoo_old) ) new_Vdc = array(Vdc_old) + mix_sig * (array(sym_Vdc) - array(Vdc_old)) # print new_Sigoo,new_Vdc self.SigMdc = new_Sigoo - new_Vdc # print self.SigMdc # print om, self.ommesh for i in range(len(self.Sig)): self.Sig[i, :] -= sym_Sigoo_imp[i] # print self.Sig if len(om) != len(self.ommesh): Sig_old = Interpolate(om, Sig_old, self.ommesh, 3) self.nom = len(self.ommesh) self.Sig = Sig_old + mix_sig * (self.Sig - Sig_old) # print self.Sig # print shape(self.Sig) header1 = "# nom,ncor_orb= " + str(self.nom) + " " + str(self.ncor_orb) header2 = "# T= %18.15f" % (self.T) # +str(self.T) header3 = "# s_oo-Vdc= " for i in range(self.ncor_orb): header3 += "%18.15f " % (self.SigMdc[i]) header4 = "# s_oo= " + str(new_Sigoo.tolist()) header5 = "# Vdc= " + str(new_Vdc.tolist()) # print header1 # print header2 # print header3 # print header4 # print header5 Fileio.Print_complex_multilines( self.Sig, self.ommesh, "sig.inp", [header1, header2, header3, header4, header5], )
def interpol(self, emin, emax, rom, broaden, dest_dir, sp=False): """ This performs the interpolation of points on the real axis. """ print("\nInterpolating points on real axis...") headerline = 2 om, Sig = Fileio.Read_complex_multilines("./ac/Sig.out", headerline) s_oo = None Vdc = None # The exec() function doesn't work properly on Python3 so I had to use a workaround: fi = open("./ac/Sig.out", "r") line1 = fi.readline() s_oo = re.findall(r"\s*([0-9.+-]*)", line1) while "" in s_oo: s_oo.remove("") line2 = fi.readline() Vdc = re.findall(r"\s*([0-9.+-]*)", line2) while "" in Vdc: Vdc.remove("") # exec(ar[0]) # m=re.search('#(.*)',line) # exec(m.group(1).strip()) # s_oo_Vdc=np.array(s_oo)-array(Vdc) fi.close() s_oo_Vdc = np.array((np.array(s_oo)).astype(np.float)) - np.array( (np.array(Vdc)).astype(np.float)) ommesh = np.linspace(emin, emax, rom) # non spin polarized case if sp == False: Sig_tot = np.zeros((len(Sig), rom), dtype=complex) for i in range(len(Sig)): SigSpline = interpolate.splrep(om, Sig[i].real, k=1, s=0) Sig_tot[i, :] += interpolate.splev(ommesh, SigSpline) SigSpline = interpolate.splrep(om, Sig[i].imag, k=1, s=0) Sig_tot[i, :] += 1j * interpolate.splev(ommesh, SigSpline) header1 = "# nom,ncor_orb= " + str(len(ommesh)) + " " + str( len(Sig_tot)) # header2='# T= %18.15f'%(1.0/pC['beta'][0])#+str(self.T) header2 = "# T= %18.15f" % (broaden) # +str(self.T) header3 = "# s_oo-Vdc= " for i in range(len(s_oo_Vdc)): header3 += "%18.15f " % (s_oo_Vdc[i]) header4 = "# s_oo= " + str(s_oo) header5 = "# Vdc= " + str(Vdc) if dest_dir == "dos": Fileio.Print_complex_multilines( Sig_tot, ommesh, "./dos/sig.inp_real", [header1, header2, header3, header4, header5], ) # create sig.inp_real if dest_dir == "bands": Fileio.Print_complex_multilines( Sig_tot, ommesh, "./bands/sig.inp_real", [header1, header2, header3, header4, header5], ) # Spin polarized calculation if sp: Sig_tot = np.zeros((int(len(Sig) / 2), rom), dtype=complex) Sig_tot_dn = np.zeros((int(len(Sig) / 2), rom), dtype=complex) for i in range(int(len(Sig) / 2)): # spin SigSpline = interpolate.splrep(om, Sig[i].real, k=1, s=0) Sig_tot[i, :] += interpolate.splev(ommesh, SigSpline) SigSpline = interpolate.splrep(om, Sig[i].imag, k=1, s=0) Sig_tot[i, :] += 1j * interpolate.splev(ommesh, SigSpline) # spin down SigSpline = interpolate.splrep(om, Sig[i + int(len(Sig) / 2)].real, k=1, s=0) Sig_tot_dn[i, :] += interpolate.splev(ommesh, SigSpline) SigSpline = interpolate.splrep(om, Sig[i + int(len(Sig) / 2)].imag, k=1, s=0) Sig_tot_dn[i, :] += 1j * interpolate.splev(ommesh, SigSpline) header1 = "# nom,ncor_orb= " + str(len(ommesh)) + " " + str( len(Sig_tot)) header2 = "# T= %18.15f" % (broaden) header3 = "# s_oo-Vdc= " header3_dn = "# s_oo-Vdc= " for i in range(int(len(s_oo_Vdc) / 2)): header3 += "%18.15f " % (s_oo_Vdc[i]) header3_dn += "%18.15f " % (s_oo_Vdc[i + int(len(s_oo_Vdc) / 2)]) header4 = "# s_oo= " + str(s_oo[0:int(len(s_oo) / 2)]) header4_dn = "# s_oo= " + str(s_oo[int(len(s_oo) / 2):]) header5 = "# Vdc= " + str(Vdc[0:int(len(Vdc) / 2)]) header5_dn = "# Vdc= " + str(Vdc[int(len(Vdc) / 2):]) if dest_dir == "dos": Fileio.Print_complex_multilines( Sig_tot, ommesh, "./dos/sig.inp_real", [header1, header2, header3, header4, header5], ) Fileio.Print_complex_multilines( Sig_tot_dn, ommesh, "./dos/sig.inp_real_dn", [header1, header2, header3_dn, header4_dn, header5_dn], ) # create sig.inp_real if dest_dir == "bands": Fileio.Print_complex_multilines( Sig_tot, ommesh, "./bands/sig.inp_real", [header1, header2, header3, header4, header5], ) Fileio.Print_complex_multilines( Sig_tot_dn, ommesh, "./bands/sig.inp_real_dn", [header1, header2, header3_dn, header4_dn, header5_dn], ) print("Interpolation complete.\n")
#!/usr/bin/env python from scipy import * import copy, Fileio, re from scipy import interpolate if __name__ == '__main__': emin = -7.0 emax = 3.0 rom = 3000 broaden = 0.03 headerline = 2 om, Sig = Fileio.Read_complex_multilines('Sig.out', headerline) s_oo = None Vdc = None fi = open('Sig.out', 'r') for i in range(headerline): line = fi.readline() m = re.search('#(.*)', line) exec(m.group(1).strip()) s_oo_Vdc = array(s_oo) - array(Vdc) ommesh = linspace(emin, emax, rom) Sig_tot = zeros((len(Sig), rom), dtype=complex) for i in range(len(Sig)): SigSpline = interpolate.splrep(om, Sig[i].real, k=1, s=0) Sig_tot[i, :] += interpolate.splev(ommesh, SigSpline) SigSpline = interpolate.splrep(om, Sig[i].imag, k=1, s=0) Sig_tot[i, :] += 1j * interpolate.splev(ommesh, SigSpline)
def Read_Sig(self,TB,nspin): self.Sigoo=[];SigMoo=[] self.Nd_imp=zeros(len(self.cor_at),dtype=float) self.N_imp=zeros((len(self.cor_at),TB.max_cor_orb),dtype=float) self.MOM_imp=zeros((len(self.cor_at),TB.max_cor_orb),dtype=float) self.Eimp=[] for i,ats in enumerate(self.cor_at): d_orb=TB.TB_orbs[ats[0]] fileSig='Sig'+str(i+1)+'.out' if (os.path.exists(fileSig)): # If output file exists, start from previous iteration (ommesh_long,Sig_file,TrS,Epot,nf_q,mom) = Fileio.Read_complex_Data(fileSig) if len(Sig_file)!=nspin*len(self.cor_orb[i]): print "The number of correated orbital is not same as Sig file column"; exit() if len(mom)!=nspin*len(self.cor_orb[i]): print "The number of correated orbital is not same as mom list in Sig file"; exit() if self.nom>len(ommesh_long): print "nom should be decreased!"; exit() self.Nd_imp[i]=nf_q for j,orbs in enumerate(self.cor_orb[i]): for orb in orbs: self.N_imp[i,d_orb.index(orb)]=mom[j]/len(orbs) #self.N_imp[TB.idx[at][orb]]=mom[j]/len(orbs) if nspin==2: self.N_imp[i,d_orb.index(orb)]+=mom[j+len(self.cor_orb[i])]/len(orbs) self.MOM_imp[i,d_orb.index(orb)]=(mom[j]-mom[j+len(self.cor_orb[i])])/len(orbs) #self.Eimp.append(TrS-0.5*sum([mom[j]*Sig_file[j][-1].real for j in range(len(mom))])); #nf_qmc.append(list(mom)) self.Eimp.append(TrS); #nf_qmc.append(list(mom)) self.Sigoo.append(array(Sig_file[:,-1].real)) for iom in range(len(ommesh_long)): Sig_file[:,iom]-=self.Sigoo[i] for ii in range(nspin*len(self.cor_orb[i])): if Sig_file[ii,iom].imag >0: Sig_file[ii,iom]=Sig_file[ii,iom].real+0.0j SigMoo.append(Interpolate(ommesh_long,Sig_file,self.ommesh,1)) else: self.Eimp.append(0.0) self.Sigoo.append([]) SigMoo.append([]) for j in range(nspin*len(self.cor_orb[i])): if j<len(self.cor_orb[i]): self.Sigoo[i].append(-0.1) else: self.Sigoo[i].append(0.1) #Break symmetry SigMoo[i].append(zeros(len(self.ommesh))) self.Sig=zeros((len(TB.cor_idx),len(self.ommesh)),dtype=complex) for i,ats in enumerate(self.cor_at): for at in ats: for j,orbs in enumerate(self.cor_orb[i]): for orb in orbs: idx=TB.idx[at][orb] self.Sig[idx,:] = copy.deepcopy(SigMoo[i][j]) if (os.path.exists('SigMoo.out')): omtemp,self.Sig_old=Fileio.Read_complex_multilines('SigMoo.out') else: self.Sig_old=copy.deepcopy(self.Sig) if nspin==2: self.Sig_dn=zeros((len(TB.cor_idx),len(self.ommesh)),dtype=complex) for i,ats in enumerate(self.cor_at): for at in ats: for j,orbs in enumerate(self.cor_orb[i]): for orb in orbs: idx=TB.idx[at][orb] self.Sig_dn[idx,:] = copy.deepcopy(SigMoo[i][j+len(self.cor_orb[i])]) if (os.path.exists('SigMoo_dn.out')): omtemp,self.Sig_dn_old=Fileio.Read_complex_multilines('SigMoo_dn.out') else: self.Sig_dn_old=copy.deepcopy(self.Sig_dn)
#!/usr/bin/env python from scipy import * import copy, Fileio, re from scipy import interpolate if __name__ == "__main__": emin = 0.0 emax = 300 rom = 3000 broaden = 0.03 headerline = 2 om, Sig = Fileio.Read_complex_multilines("sig.inp", headerline) s_oo = None Vdc = None fi = open("sig.inp", "r") for i in range(headerline): line = fi.readline() m = re.search("#(.*)", line) exec(m.group(1).strip()) s_oo_Vdc = array(s_oo) - array(Vdc) ommesh = linspace(emin, emax, rom) Sig_tot = zeros((len(Sig), rom), dtype=complex) for i in range(len(Sig)): SigSpline = interpolate.splrep(om, Sig[i].real, k=1, s=0) Sig_tot[i, :] += interpolate.splev(ommesh, SigSpline) SigSpline = interpolate.splrep(om, Sig[i].imag, k=1, s=0) Sig_tot[i, :] += 1j * interpolate.splev(ommesh, SigSpline)