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)]
def Print_Gloc(self, print_at, TB): for at in print_at: Fileio.Print_complex_multilines( array([ self.Gloc[i] for i in range(TB.idx[at][TB.TB_orbs[at][0]], TB.idx[at][TB.TB_orbs[at][-1]] + 1) ]), self.ommesh, 'G_loc_' + at + '.out')
def Read_Sig(self, TB, nspin): self.Sig = [] 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.Epot_imp = [] self.Ekin_imp = [] self.mu_imp = [] self.TrSigG = [] for i, ats in enumerate(self.cor_at): d_orb = TB.TB_orbs[ats[0]] fileSig = "imp." + str(i) + "/Sig.out" if os.path.exists(fileSig): ( self.ommesh, Sig_file, TrS, Epot, nf_q, mom, Ekin, imp_mu, ) = 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) for j in range(nspin * len(self.cor_orb[i])): for iom in range(len(self.ommesh)): if Sig_file[j, iom].imag > 0: Sig_file[j, iom] = Sig_file[j, iom].real + 0.0j self.Sig.append(Sig_file[j]) self.TrSigG.append(TrS) self.Epot_imp.append(Epot) self.Ekin_imp.append(Ekin) self.mu_imp.append(imp_mu) self.Sig = array(self.Sig)
rank = comm.Get_rank() name = MPI.Get_processor_name() print "Hello, World! I am process %d of %d on %s." % (rank, size, name) HF_iter = open('ITERINFO', 'a') DM_iter = open('DMINFO', 'a') if os.path.exists("DMFT_mu.out"): fi = open('DMFT_mu.out', 'r') else: fi = open('DFT_mu.out', 'r') mu = float(fi.readline().split()[0]) fi.close() if (os.path.exists('SigMdc.out')): SigMdc = Fileio.Read_float('SigMdc.out') else: print "SigMdc.out is missing" exit() if (os.path.exists('SigMdc_dn.out')): SigMdc_dn = Fileio.Read_float('SigMdc_dn.out') else: print "SigMdc_dn.out is missing" exit() if (os.path.exists('ksum.input')): fi = open('ksum.input', 'r') nspin = int(fi.readline().strip()) ncor_orb = int(fi.readline().strip()) norb = int(fi.readline().strip()) n_tot = float(fi.readline().strip())
emin = -5.0 emax = 5.0 #rom=1000 rom = int(sys.argv[1]) execfile('INPUT.py') TB = Struct.TBstructure('POSCAR', p['atomnames'], p['orbs']) cor_at = p['cor_at'] cor_orb = p['cor_orb'] TB.Compute_cor_idx(cor_at, cor_orb) ommesh = linspace(emin, emax, rom) Sig_tot = zeros((TB.ncor_orb, rom), dtype=complex) for i, ats in enumerate(cor_at): (om, Sig, TrSigmaG, Epot, nf_q, mom) = Fileio.Read_complex_Data('Sig' + str(i + 1) + '.out') newSig = zeros((len(Sig), rom), dtype=complex) for ii in range(len(Sig)): SigSpline = interpolate.splrep(om, Sig[ii].real, k=1, s=0) newSig[ii, :] += interpolate.splev(ommesh, SigSpline) SigSpline = interpolate.splrep(om, Sig[ii].imag, k=1, s=0) newSig[ii, :] += 1j * interpolate.splev(ommesh, SigSpline) for at in ats: for ii, orbs in enumerate(cor_orb[i]): for orb in orbs: idx = TB.idx[at][orb] Sig_tot[idx, :] = copy.deepcopy( newSig[ii, :]) # non spin polarized #Sig_tot[idx,:]=copy.deepcopy(newSig[ii+len(cor_orb[i]),:]) Fileio.Print_complex_multilines(Sig_tot, ommesh, 'SigMoo_real.out')
ETOT2_old = 0.0 ETOT = 0.0 ETOT2 = 0.0 CHGDIFF = 0. CHGDIFF2 = 0. shutil.copy2('sig.inp', 'sig.inp.0') for itt in range(p['Niter']): main_out.write('--- Starting Charge loop ' + str(itt + 1) + now() + '---') main_out.write('\n') main_out.flush() #if itt<p['Niter']-p['Nforce']: Fileio.Create_INPUT(p,pC,TB,T,noms,'.FALSE.') #else: Fileio.Create_INPUT(p,pC,TB,T,noms,'.TRUE.') Fileio.Create_dmft_params(p, pC, N_atoms, atm_idx, sym_idx) for it in range(p['Nit']): main_out.write('--- Starting DMFT loop ' + str(it + 1) + now() + '---') main_out.write('\n') main_out.flush() if itt == 0 and it == 0: for i, ats in enumerate(cor_at): if p['nspin'] == 2: pD['para='] = 0 else: pD['para='] = 1 if p['orbs'][0] == 'f': pD['l='] = 3 elif p['orbs'][0] == 'd': pD['l='] = 2 pD['J='] = float(J[i]) pD['Eimp='] = zeros(
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], )
ETOT2_old = 0.0 ETOT = 0.0 ETOT2 = 0.0 CHGDIFF = 0.0 CHGDIFF2 = 0.0 shutil.copy2("sig.inp", "sig.inp.0") # ----------------------- Starting DFT+DMFT loop ----------------------------- for itt in range(p["Niter"]): main_out.write("--- Starting charge loop " + str(itt + 1) + now() + "---") main_out.write("\n") main_out.flush() Fileio.Create_dmft_params(p, pC, N_atoms, atm_idx, sym_idx) for it in range(p["Nit"]): main_out.write("--- Starting DMFT loop " + str(it + 1) + now() + "---") print("\n----- Starting DMFT loop : %s -----\n" % (str(it + 1))) main_out.write("\n") main_out.flush() if itt == 0 and it == 0: for i, ats in enumerate(cor_at): if p["nspin"] == 2: pD["para="] = 0 else: pD["para="] = 1 if p["orbs"][0] == "f":
DFT = VASP.VASP_class() ETOT_old = 0.0 ETOT2_old = 0.0 ETOT = 0.0 ETOT2 = 0.0 CHGDIFF = 0. CHGDIFF2 = 0. for itt in range(p['Niter']): main_out.write('--- Starting Charge loop ' + str(itt + 1) + now() + '---') main_out.write('\n') main_out.flush() if itt < p['Niter'] - p['Nforce']: Fileio.Creat_INPUT(p, pC, TB, T_high, noms_high, '.FALSE.') else: Fileio.Creat_INPUT(p, pC, TB, T_high, noms_high, '.TRUE.') if p['Nrelax'] > p['Nforce']: print "Nrelax should not be larger than Nforce" exit() if itt >= p['Niter'] - p['Nrelax']: TB.Update_POSCAR('POSCAR') pV['NSW= '] = [3, '# NSW'] pV['POTIM= '] = [0.1, '# NSW'] pV['IBRION= '] = [1, '# IBRION'] pV['ISIF= '] = [2, '# ISIF'] pV['EDIFFG= '] = [-0.01, '# EDIFFG'] CreateINCAR(pV) if os.path.exists('CHGCAR') and itt == 0:
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)
def Compute_HF(self,Nd_qmc,p,TB): """Compute Energy and Sigma""" nspin=p['nspin'];U=p['U'];J=p['J'];dc_type=p['dc_type'];Uprime=p['Uprime'] self.VHF=zeros((len(self.cor_at),2*TB.max_cor_orb),dtype=float) self.VHF_latt=zeros((len(self.cor_at),2*TB.max_cor_orb),dtype=float) self.VHF_imp=zeros((len(self.cor_at),2*TB.max_cor_orb),dtype=float) self.VDC=zeros(len(self.cor_at),dtype=float) self.sig_st=[]#zeros(len(cor_at),dtype=float) self.EHF=0.0#zeros(len(self.cor_at),dtype=float) self.EHF_latt=0.0#zeros(len(self.cor_at),dtype=float) self.EHF_imp=0.0#zeros(len(self.cor_at),dtype=float) self.EDC=0.0;self.EDC_imp=0.0 #self.EHF_cor=zeros(len(self.cor_at),dtype=float) self.SigMdc=zeros(TB.ncor_orb,dtype=float) if nspin==2: self.SigMdc_dn=zeros(TB.ncor_orb,dtype=float) for i,ats in enumerate(self.cor_at): d_orb=TB.TB_orbs[ats[0]] fi=open('UC'+str(i+1)+'.dat','r') UC=[] for line in fi.readlines(): UC.append(map(float,line.split())) if len(UC)!=2*len(d_orb): print "The size of UC is not consistent with orb"; exit() UC=array(UC)+U[i]-diag(ones(2*len(d_orb))*U[i]) if Nd_qmc==0: OCC=array(list((self.N_latt[i][:len(d_orb)]+self.MOM[i][:len(d_orb)])/2)+list((self.N_latt[i][:len(d_orb)]-self.MOM[i][:len(d_orb)])/2)) else: OCC=array(list((self.N_imp[i][:len(d_orb)]+self.MOM_imp[i][:len(d_orb)])/2)+list((self.N_imp[i][:len(d_orb)]-self.MOM_imp[i][:len(d_orb)])/2)) OCC_latt=array(list((self.N_latt[i][:len(d_orb)]+self.MOM[i][:len(d_orb)])/2)+list((self.N_latt[i][:len(d_orb)]-self.MOM[i][:len(d_orb)])/2)) OCC_imp=array(list((self.N_imp[i][:len(d_orb)]+self.MOM_imp[i][:len(d_orb)])/2)+list((self.N_imp[i][:len(d_orb)]-self.MOM_imp[i][:len(d_orb)])/2)) self.VHF[i,:2*len(d_orb)]=dot(UC,OCC) self.VHF_latt[i,:2*len(d_orb)]=dot(UC,OCC_latt) self.VHF_imp[i,:2*len(d_orb)]=dot(UC,OCC_imp) ###### Compute VDC ####### if dc_type==1: if Nd_qmc==0: self.VDC[i]=Uprime[i]*(self.Nd_latt[i]-0.5)-J[i]/2*(self.Nd_latt[i]-1) else: self.VDC[i]=Uprime[i]*(self.Nd_imp[i]-0.5)-J[i]/2*(self.Nd_imp[i]-1) elif dc_type==2: if Nd_qmc==0: self.VDC[i]=(Uprime[i]-2*J[i])*(0.9*self.Nd_latt[i])-J[i]/2*(2*self.Nd_latt[i]/5) else: self.VDC[i]=(Uprime[i]-2*J[i])*(0.9*self.Nd_imp[i])-J[i]/2*(2*self.Nd_imp[i]/5) else: print "dc type is wrong!"; exit() self.sig_st.append([]) for j,orbs in enumerate(self.cor_orb[i]): self.sig_st[i].append(0.0) for orb in orbs: idx=d_orb.index(orb) #for orb2 in orbs: # idx2=d_orb.index(orb2) # ########### This only works for one cor_orb ############# # self.EHF_cor[i]+=0.5*(OCC[idx]*UC[idx,idx2]*OCC[idx2]+OCC[idx]*UC[idx,idx2+5]*OCC[idx2+5]+OCC[idx+5]*UC[idx+5,idx2]*OCC[idx2]+OCC[idx+5]*UC[idx+5,idx2+5]*OCC[idx2+5]) for orb2 in TB.TB_orbs[ats[0]]: if TB.cor_idx[TB.idx[ats[0]][orb2]]==1: idx2=d_orb.index(orb2) self.sig_st[i][j]+=UC[idx,idx2]*OCC[idx2]+UC[idx,idx2+len(d_orb)]*OCC[idx2+len(d_orb)] self.sig_st[i][j]/=len(orbs) for orb in orbs: idx=d_orb.index(orb) if nspin==1 and Nd_qmc>1: self.VHF[i,idx]=self.Sigoo[i][j]; self.VHF[i,idx+len(d_orb)]=self.Sigoo[i][j] if nspin==2 and Nd_qmc>1: self.VHF[i,idx]=self.Sigoo[i][j]; self.VHF[i,idx+len(d_orb)]=self.Sigoo[i][j+len(self.cor_orb[i])] self.sig_st[i][j]-=self.VDC[i] self.EHF+=len(ats)*0.5*dot(OCC,self.VHF[i][:2*len(d_orb)]) self.EHF_imp+=len(ats)*0.5*dot(OCC_imp,self.VHF_imp[i][:2*len(d_orb)]) self.EHF_latt+=len(ats)*0.5*dot(OCC_latt,self.VHF_latt[i][:2*len(d_orb)]) if dc_type==1: self.EDC+=len(ats)*(Uprime[i]*self.Nd_latt[i]*(self.Nd_latt[i]-1)/2.0-J[i]*self.Nd_latt[i]*(self.Nd_latt[i]-2)/4.0) self.EDC_imp+=len(ats)*(Uprime[i]*self.Nd_imp[i]*(self.Nd_imp[i]-1)/2.0-J[i]*self.Nd_imp[i]*(self.Nd_imp[i]-2)/4.0) elif dc_type==2: self.EDC+=self.Natom[i]*(Uprime[i]*self.Nd_latt[i]*(0.9*self.Nd_latt[i])/2-5*J[i]*self.Nd_latt[i]/2*(2*self.Nd_latt[i]/5)) self.EDC_imp+=self.Natom[i]*(Uprime[i]*self.Nd_imp[i]*(0.9*self.Nd_imp[i])/2-5*J[i]*self.Nd_imp[i]/2*(2*self.Nd_imp[i]/5)) else: print "This dc type is not supported!"; exit() for at in ats: for orb in TB.TB_orbs[at]: idx=TB.idx[at][orb] self.SigMdc[idx] = self.VHF[i,d_orb.index(orb)]-self.VDC[i] if nspin==2: for at in ats: for orb in TB.TB_orbs[at]: idx=TB.idx[at][orb] self.SigMdc_dn[idx] = self.VHF[i,d_orb.index(orb)+len(d_orb)]-self.VDC[i] if (os.path.exists('SigMdc.out')): self.SigMdc_old=Fileio.Read_float('SigMdc.out') else: self.SigMdc_old=copy.deepcopy(self.SigMdc) if nspin==2: if (os.path.exists('SigMdc_dn.out')): self.SigMdc_dn_old=Fileio.Read_float('SigMdc_dn.out') else: self.SigMdc_dn_old=copy.deepcopy(self.SigMdc_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)