def solver_input_data(parms, L, hyb_data_all, AvgDispersion, VCoulomb, nf): # prepare hybtau file for CTQMC N_LAYERS = int(parms["N_LAYERS"]) FLAVORS = int(parms["FLAVORS"]) SPINS = int(parms["SPINS"]) corr_id = system.getCorrIndex(parms) dmft_id = system.getDMFTCorrIndex(parms) dmft_FLAVORS = 2 * len(dmft_id) / N_LAYERS # 2 for SPINS hyb_data = [] for n, d in enumerate(hyb_data_all): data = hyb_data_all[n][:, :, dmft_id[L::N_LAYERS]] data_out = zeros((size(data, 1), dmft_FLAVORS), dtype=data.dtype) data_out[:, ::2] = data[0] data_out[:, 1::2] = data[0] if SPINS == 1 else data[1] hyb_data.append(data_out) Eav = AvgDispersion[:, 0, dmft_id[L::N_LAYERS]] inertHFSelfEnergy = get_inert_band_HF(parms, nf[:, L::N_LAYERS]) MU = array([float(parms["MU"]) - VCoulomb[L] - Eav[s] - inertHFSelfEnergy[s] for s in range(SPINS)]) MU_out = zeros(dmft_FLAVORS) MU_out[::2] = MU[0] MU_out[1::2] = MU[0] if SPINS == 1 else MU[1] parms_copy = parms.copy() parms_copy["FLAVORS"] = dmft_FLAVORS print "Inert HF Self Energy: ", inertHFSelfEnergy return {"hybtau": hyb_data[0], "hybmat": hyb_data[1], "hybtail": hyb_data[2], "MU": MU_out, "parms": parms_copy}
def get_asymp_selfenergy(parms, nf_in, nn_in = None): dmft_id = system.getDMFTCorrIndex(parms, all = False); FLAVORS = int(parms['FLAVORS']); SPINS = 2; U = generate_Umatrix(float(parms['U']), float(parms['J']), int(parms['FLAVORS']), val_def(parms, 'INTERACTION_TYPE', 'SlaterKanamori')); if int(val_def(parms, 'TMP_HELD_DC' , 0)) > 0: for m in range(2*FLAVORS): for n in range(2*FLAVORS): f1 = m/2 f2 = n/2 if (f1 not in dmft_id) or (f2 not in dmft_id): U[m, n] = 0. nf = zeros(SPINS*FLAVORS); nf[::2] = nf[1::2] = nf_in[0]; if int(parms['SPINS']) == 2: nf[1::2] = nf_in[1]; nn = zeros((FLAVORS*SPINS, FLAVORS*SPINS)); pos = 0; for i in range(FLAVORS*SPINS): for j in range(i+1): f1 = i/SPINS; f2 = j/SPINS; if f1 in dmft_id and f2 in dmft_id and nn_in is not None: nn[i,j] = nn[j,i] = nn_in[pos]; pos += 1; if f1 in dmft_id: nn[i,i] = nf[i]; S = zeros((2, SPINS*FLAVORS)); # 2: expansion orders: (iwn)^0, (iwn)^{-1} for f in range(SPINS*FLAVORS): # zeroth order is easy: \Sigma^0_f = U_{f, f'} * <n_f'> S[0, f] = sum(U[f, :]*nf); # first order is harder: \Sigma^1_f = U_{f,f1}*U_{f,f2}*<n_f1 n_f2> - (\Sigma^0_f)^2 for f1 in range(SPINS*FLAVORS): for f2 in range(SPINS*FLAVORS): S[1, f] += U[f, f1]*U[f,f2]*nn[f1,f2]; S[1,f] -= S[0,f]**2; ret = array([S[:,::2], S[:,1::2]]); # for mean field, there is only \Sigma^0, other terms vanish # so I set \Sigma^1 to be zero for f in range(FLAVORS): if f not in dmft_id: ret[:, 1, f] = 0; if int(val_def(parms, 'TMP_HELD_DC' , 0)) > 0: uu = float(parms['U']) jj = float(parms['J']) ntot = sum(nf_in[0][dmft_id] + nf_in[1][dmft_id]) ret[:, 0, f] = ((uu-2*jj) + jj*(2 - (3-1)) / (2*3.-1.))*(ntot-0.5) if int(parms['SPINS']) == 1: ret = array([ret[0]]); return ret;
def getDensity(h5, it = None): if it is None: it = h5['iter'][0]; parms = load_parms(h5, it); N_LAYERS = int(parms['N_LAYERS']); SPINS = int(parms['SPINS']); NCOR = int(parms['NCOR']); U = float(parms['U']); n_f = h5['log_density'][0 if it == 0 else it-1, 4:].reshape(SPINS, -1)[:, :NCOR]; if U != 0 and it > 0: if int(val_def(parms, 'FIXED_HARTREE', 0)) > 0: n_f = h5['log_density'][0, 4:].reshape(SPINS, -1)[:, :NCOR]; dmft_id = system.getDMFTCorrIndex(parms); gtau = h5['SolverData/Gtau/'+str(it)][:] n_f[:, dmft_id] = -gtau[:, -1, dmft_id]; return n_f;
def get_inert_band_HF(parms, nf): FLAVORS = int(parms["FLAVORS"]) SPINS = 2 ret = zeros(SPINS) if int(val_def(parms, "TMP_HELD_DC", 0)) > 0: return ret assert size(nf, 1) == FLAVORS dmft_id = system.getDMFTCorrIndex(parms, all=False) inert_id = array([s for s in range(FLAVORS) if s not in dmft_id]) U = float(parms["U"]) J = float(parms["J"]) if len(nf) == 1: nf = r_[nf, nf] for s in range(SPINS): for f in inert_id: ret[s] += (U - 2 * J) * nf[not s, f] + (U - 3 * J) * nf[s, f] if int(val_def(parms, "MEAN_FIELD_UNPOLARIZED", 0)) > 0: ret = ones(SPINS) * mean(ret) return ret
def getSpectraFromSelfEnergy(h5, se_filename, rham, rotmat, numk = None, setail_filename = None, it = 0): # prepare data w, se_refreq = ProcessSelfEnergy(se_filename, emin = -5, emax = 5, NFreq = 500); it = h5['iter'][0] - it; parms = load_parms(h5, it); print 'work on iteration ', it; if rham is not None: print 'new path for rham file is: ', rham; parms['RHAM'] = rham; if rotmat is not None: print 'new path for rot_mat file is ', rotmat; parms['ROT_MAT'] = rotmat; BETA = float(parms['BETA']); N_LAYERS = int(parms['N_LAYERS']); FLAVORS = int(parms['FLAVORS']); SPINS = int(parms['SPINS']); NORB = int(parms['NORB']); dmft_id = system.getDMFTCorrIndex(parms, all = False); dmft_id_len = len(dmft_id); # get the se tails tmp = h5['SolverData/selfenergy_asymp_coeffs'][:]; se_tail = tmp[tmp[:,0] == it, 1:].reshape(SPINS, 2, -1)[:, :, ::N_LAYERS]; if setail_filename is not None: print 'use the tail from external source: ', setail_filename; tmp = genfromtxt(setail_filename); se_tail[:, :, dmft_id] = array([tmp[:, s::SPINS] for s in range(SPINS)]); print se_tail; # restore SelfEnergy se = zeros((SPINS, len(se_refreq), N_LAYERS*FLAVORS), dtype = complex); for s in range(SPINS): for f in range(N_LAYERS*FLAVORS): if f/N_LAYERS not in dmft_id: se[s,:,f] = se_tail[s, 0, f/N_LAYERS]; else: f1 = nonzero(f/N_LAYERS == dmft_id)[0][0]; se[s, :, f] = se_refreq[:, SPINS*f1+s]*se_tail[s, 1, f/N_LAYERS] + se_tail[s, 0, f/N_LAYERS]; # tight binding Hamiltonian if 'RHAM' in parms: HR, R = getHamiltonian(parms['RHAM'], 4); if parms['DTYPE'] == '3bands': FLAVORS = 3; extra = { 'HR' : HR, 'R': R }; # rotation matrix if int(val_def(parms, 'FORCE_DIAGONAL', 0)) > 0: print 'FORCE_DIAGONAL is used'; ind = nonzero(sum(R**2, 1)==0)[0][0]; H0 = HR[ind]; else: H0 = None; rot_mat = getRotationMatrix(N_LAYERS, FLAVORS, val_def(parms, 'ROT_MAT', None), H0); # prepare for k-integrate parms['NUMK'] = 16 if numk is None else numk; bp, wf = grule(int(parms['NUMK'])); broadening = 0.01; extra.update({ 'GaussianData' : [bp, wf], 'rot_mat' : rot_mat }); delta = float(parms['DELTA']); mu = float(parms['MU']); # running print 'generating interacting DOS with parameters' for k, v in parms.iteritems(): print '%s = %s'%(k, v); Gr = averageGreen(delta, mu, w+1j*broadening, se, parms, float(parms['ND']), float(parms['DENSITY']), 0, extra)[1]; if SPINS == 1: savetxt(parms['ID']+'.idos', c_[w, -1/pi*Gr[0].imag], fmt = '%g'); elif SPINS == 2: savetxt(parms['ID']+'_up.idos', c_[w, -1/pi*Gr[0].imag], fmt = '%g'); savetxt(parms['ID']+'_dn.idos', c_[w, -1/pi*Gr[1].imag], fmt = '%g'); # calculate original G(iwn), only consider one "LAYERS" Giwn_orig = h5['ImpurityGreen/%d'%it][:,:,::N_LAYERS]; NMatsubara = size(Giwn_orig, 1); wn = (2*arange(NMatsubara) + 1)*pi/BETA; Giwn = zeros((NMatsubara, 2*FLAVORS*SPINS), dtype = float); # 2 for real and imag for f in range(FLAVORS): for s in range(SPINS): Giwn[:, 2*(SPINS*f+s)] = Giwn_orig[s, :, f].real; Giwn[:, 2*(SPINS*f+s)+1] = Giwn_orig[s, :, f].imag; savetxt(parms['ID']+'.gmat', c_[wn, Giwn]); # calculate G(iwn) for reference, only consider one "LAYERS" NMatsubara = 200; wn = (2*arange(NMatsubara) + 1)*pi/BETA; Giwn = zeros((NMatsubara, 2*FLAVORS*SPINS), dtype = float); # 2 for real and imag for f in range(FLAVORS): for s in range(SPINS): A = -1/pi * Gr[s, :, f*N_LAYERS].imag; for n in range(NMatsubara): tck_re = splrep(w, real(A / (1j*wn[n] - w))); tck_im = splrep(w, imag(A / (1j*wn[n] - w))); Giwn[n, 2*(SPINS*f+s)] = splint(w[0], w[-1], tck_re); Giwn[n, 2*(SPINS*f+s)+1] = splint(w[0], w[-1], tck_im); savetxt(parms['ID']+'.gmat.ref', c_[wn, Giwn]);
def run_solver(AvgDispersion, nf, w, it, parms, aWeiss, np=1, VCoulomb=None): ID = parms["ID"] N_LAYERS = int(parms["N_LAYERS"]) FLAVORS = int(parms["FLAVORS"]) SPINS = int(parms["SPINS"]) DATA_FILE = parms["DATA_FILE"] TMPH5FILE = "." + DATA_FILE + ".id" + str(ID) + ".i" + str(it) + ".solver_out.h5" if VCoulomb is None: VCoulomb = zeros(N_LAYERS) solver = solver_types.init_solver(parms, np) corr_id = system.getCorrIndex(parms) NCOR = int(parms["NCOR"]) NDMFT = 2 * len(system.getDMFTCorrIndex(parms)) # 2 for SPINS # check save point and initialize for new iteration try: tmph5 = h5py.File(TMPH5FILE, "r+") hyb_tau = tmph5["Hybtau"][:] hyb_mat = tmph5["Hybmat"][:] hyb_coefs = tmph5["hyb_asym_coeffs"][:].reshape(SPINS, -1, NCOR) except: try: tmph5.close() except: pass tmph5 = h5py.File(TMPH5FILE, "w") tmph5.create_dataset("L", (2,), dtype=int, data=array([it, 0])) # asymptotic coefficients, upto 3rd order for hyb hyb_coefs = zeros((SPINS, 3, NCOR), dtype=float) # electric chemical potential eMU = float(parms["MU"]) - VCoulomb for L in range(N_LAYERS): hyb_coefs[:, :, L::N_LAYERS] = get_asymp_hybmat( parms, nf[:, L::N_LAYERS], eMU[L], AvgDispersion[:, :, corr_id[L:NCOR:N_LAYERS]] ) # get practical hybmat, and hybtau Eav = AvgDispersion[:, 0, corr_id] hyb_mat = zeros((SPINS, int(parms["N_MAX_FREQ"]), NCOR), dtype=complex) hyb_tau = zeros((SPINS, int(parms["N_TAU"]) + 1, NCOR), dtype=float) for s in range(SPINS): for f in range(NCOR): hyb_mat[s, :, f] = w + eMU[f % N_LAYERS] - Eav[s, f] - aWeiss[s, :, f] tmp = cppext.IFT_mat2tau( hyb_mat[s, :, f].copy(), int(parms["N_TAU"]) + 1, float(parms["BETA"]), float(hyb_coefs[s, 0, f]), float(hyb_coefs[s, 1, f]), ) # set value >= 0 to be smaller than 0, the mean of left and right neighbors ind = nonzero(tmp >= 0)[0] for i in ind: lefti = righti = i while tmp[lefti] >= 0 and lefti > 0: lefti -= 1 while tmp[righti] >= 0 and righti < len(tmp) - 1: righti += 1 leftval = tmp[lefti] if tmp[lefti] < 0 else 0 rightval = tmp[righti] if tmp[righti] < 0 else 0 tmp[i] = (leftval + rightval) / 2.0 hyb_tau[s, :, f] = tmp tmph5.create_dataset("Hybmat", hyb_mat.shape, dtype=complex, data=hyb_mat) tmph5.create_dataset("Hybtau", hyb_tau.shape, dtype=float, data=hyb_tau) # initialize output dataset Gtau_shape = (int(parms["N_TAU"]) + 1, NDMFT) tmph5.create_dataset("Gtau", Gtau_shape, dtype=float, data=zeros(Gtau_shape, dtype=float)) tmph5.create_group("Observables") tmph5.create_dataset("hyb_asym_coeffs", hyb_coefs.flatten().shape, dtype=float, data=hyb_coefs.flatten()) # run hyb_data = [hyb_tau, hyb_mat, hyb_coefs] MEASURE_freq = True if "Gw" in tmph5 else False startL = tmph5["L"][1] sym_layers = getSymmetricLayers(tmph5, parms) for L in range(startL, N_LAYERS): print "Processing task ", ID, ": iteration ", it, ", layer ", L tmph5["L"][1] = L TMPFILE = "." + DATA_FILE + ".id" + str(ID) + ".i" + str(it) + ".L" + str(L) if float(parms["U"]) == 0: break if (sym_layers is None) or (L not in sym_layers[:, 1]): solver.prepare(TMPFILE, solver_input_data(parms, L, hyb_data, AvgDispersion, VCoulomb, nf)) tmph5.close() ret_val = solver.run() tmph5 = h5py.File(TMPH5FILE, "r+") if ret_val > 0: print "Not finish running impurity solver or problem occurs while running the solver." os.system("rm " + TMPFILE + ".*") tmph5.close() return None solver_out = solver.collect() if solver_out is None: tmph5.close() return None Gtau = solver_out[0] obs = solver_out[1] if len(solver_out) > 2: MEASURE_freq = True Giwn = solver_out[2] Siwn = solver_out[3] os.system("rm " + TMPFILE + ".*") elif L in sym_layers[:, 1]: # symmetric layer, no need to calculate sym_index = nonzero(sym_layers[:, 1] == L)[0] sym_L = sym_layers[sym_index, 0][0] print "L=%d is the symmetric layer of layer L=%d" % (L, sym_L) Gtau = tmph5["Gtau"][:, sym_L::N_LAYERS] obs = None if tmph5["Observables"].keys() != []: obs = dict() for k, v in tmph5["Observables/L" + str(sym_L)].iteritems(): obs[k] = v if MEASURE_freq: Giwn = tmph5["Gw"][:, sym_L::N_LAYERS] Siwn = tmph5["Sw"][:, sym_L::N_LAYERS] # this is the only place for AFM # only works for the 4-cell unitcell (GdFeO3 distortion) # G-type AFM: 0-3 are the same, 0-1 and 0-2 are opposite in spin # here I just swap values of opposite spins if int(val_def(parms, "AFM", 0) > 0) and (L in [1, 2]): print "AFM processing on this L" Ntmp = NDMFT / N_LAYERS # correlated bands per site mapid = zeros(Ntmp, dtype=int) mapid[0::2] = arange(1, Ntmp, 2) mapid[1::2] = arange(0, Ntmp, 2) Gtau = Gtau[:, mapid] if MEASURE_freq: Giwn = Giwn[:, mapid] Siwn = Siwn[:, mapid] if "nn" in obs: tmp = obs["nn"][:] nn = zeros((Ntmp, Ntmp), dtype=float) pos = 0 for i in range(Ntmp): for j in range(i + 1): nn[i, j] = nn[j, i] = tmp[pos] pos += 1 nn = nn[mapid] nn = nn[:, mapid] tmp = array([]) for i in range(Ntmp): for j in range(i + 1): tmp = r_[tmp, nn[i, j]] obs["nn"] = tmp tmph5["Gtau"][:, L::N_LAYERS] = Gtau if MEASURE_freq: if "Gw" not in tmph5: matsubara_shape = (len(Giwn), NDMFT) tmph5.create_dataset("Gw", matsubara_shape, dtype=complex, data=zeros(matsubara_shape, dtype=complex)) tmph5.create_dataset("Sw", matsubara_shape, dtype=complex, data=zeros(matsubara_shape, dtype=complex)) tmph5["Gw"][:, L::N_LAYERS] = Giwn tmph5["Sw"][:, L::N_LAYERS] = Siwn if obs is not None: new_group_str = "Observables/L" + str(L) tmph5.create_group(new_group_str) for k, v in obs.iteritems(): tmph5.create_dataset(new_group_str + "/" + k, v.shape, dtype=v.dtype, data=v) print "Finish iteration ", it, ", layer ", L, "\n" print "DONE: iteration %d\n" % it tmph5["L"][1] = N_LAYERS tmph5.close() return TMPH5FILE
def solver_post_process(parms, aWeiss, h5, tmph5filename): N_LAYERS = int(parms["N_LAYERS"]) FLAVORS = int(parms["FLAVORS"]) NCOR = int(parms["NCOR"]) SPINS = 2 # NOTE: for collecting all spins, symmetrize them later if neccessary if len(aWeiss) == 1: aWeiss = r_[aWeiss, aWeiss] # SPINS = 1 case dmft_id = system.getDMFTCorrIndex(parms) if not os.path.isfile(tmph5filename): print >> sys.stderr, "File %s not found" % tmph5filename return None tmph5 = h5py.File(tmph5filename, "r") if tmph5["L"][1] < N_LAYERS: print >> sys.stderr, "Unfinish solving the impurity model" return None # save data from temporary file h5solver = h5["SolverData"] it = tmph5["L"][0] MEASURE_freq = True if "Gw" in tmph5 else False for s in tmph5["Observables"]: new_group_str = "Observables/%d/%s" % (it, s) for k in tmph5["Observables/%s" % s]: v = tmph5["Observables/%s/%s" % (s, k)] try: h5solver.create_dataset(new_group_str + "/" + k, v.shape, dtype=v.dtype, data=v) except: h5solver[new_group_str + "/" + k][:] = v Gmat = zeros((SPINS, int(parms["N_MAX_FREQ"]), NCOR), dtype=complex) Smat = zeros((SPINS, int(parms["N_MAX_FREQ"]), NCOR), dtype=complex) Ntau = max(int(parms["N_TAU"]) / 20, 400) + 1 Htau = tmph5["Hybtau"][:, ::20, :] # the updated density: for DMFT bands, get from Gtau, for inert bands, get from Gavg of previous iteration nf = h5["log_density"][0 if int(val_def(parms, "FIXED_HARTREE", 0)) > 0 else it - 1, 4:].reshape(-1, NCOR + 1) if len(nf) == 1: nf = r_[nf, nf] nf = nf[:, :NCOR] nf[:, dmft_id] = -assign(tmph5["Gtau"][-1, :], N_LAYERS) # get raw Gmat and Smat for f in range(size(tmph5["Gtau"], 1)): g = cppext.FT_tau2mat(tmph5["Gtau"][:, f].copy(), float(parms["BETA"]), int(parms["N_MAX_FREQ"])) try: tmp = c_[tmp, g] except: tmp = g.copy() Gmat[:, :, dmft_id] = assign(tmp, N_LAYERS) Smat[:, :, dmft_id] = aWeiss[:, :, dmft_id] - 1 / Gmat[:, :, dmft_id] if MEASURE_freq: nfreq = size(tmph5["Gw"][:], 0) Gmat[:, :nfreq, dmft_id] = assign(tmph5["Gw"], N_LAYERS) Stmp = assign(tmph5["Sw"], N_LAYERS) # adjust self energy measured using improved estimator # with contribution from inertial d-bands for L in range(N_LAYERS): SE_inert = get_inert_band_HF(parms, nf[:, L::N_LAYERS]) Stmp[0, :, L::N_LAYERS] += SE_inert[0] Stmp[1, :, L::N_LAYERS] += SE_inert[1] Smat[:, :nfreq, dmft_id] = Stmp # symmetrize orbital and spin if necessary paraorb = [int(s) for s in val_def(parms, "PARAORBITAL", "").split()] if len(paraorb) == 1: if paraorb[0] > 0: if parms["DTYPE"] == "3bands": paraorb = [[0, 1, 2]] # t2g only HARD CODE else: paraorb = [[0, 3], [1, 2, 4]] # t2g and eg HARD CODE else: paraorb = [] if len(paraorb) > 0: if type(paraorb[0]) != list: paraorb = [paraorb] print "Symmetrize over orbital ", paraorb for L in range(N_LAYERS): for s in range(SPINS): for sym_bands in paraorb: gm = zeros(size(Gmat, 1), dtype=complex) sm = zeros(size(Smat, 1), dtype=complex) nf_tmp = 0.0 for f in sym_bands: gm += Gmat[s, :, L + f * N_LAYERS] sm += Smat[s, :, L + f * N_LAYERS] nf_tmp += nf[s, L + f * N_LAYERS] for f in sym_bands: Gmat[s, :, L + f * N_LAYERS] = gm / float(len(sym_bands)) Smat[s, :, L + f * N_LAYERS] = sm / float(len(sym_bands)) nf[s, L + f * N_LAYERS] = nf_tmp / float(len(sym_bands)) if int(parms["SPINS"]) == 1: print "Symmetrize over spins" Gmat = array([mean(Gmat, 0)]) Smat = array([mean(Smat, 0)]) nf = array([mean(nf, 0)]) # smooth Gmat and Smat SPINS = int(parms["SPINS"]) Smat = smooth_selfenergy(it, h5, Smat, nf) NCutoff = int(parms["N_CUTOFF"]) Gmat[:, NCutoff:, :] = 1.0 / (aWeiss[:SPINS, NCutoff:, :] - Smat[:, NCutoff:, :]) # calculate Gtau from Gmat (after symmtrization) Gtau = zeros((SPINS, Ntau, NCOR), dtype=float) S0 = zeros((SPINS, NCOR)) for L in range(N_LAYERS): S0[:, L::N_LAYERS] = get_asymp_selfenergy(parms, nf[:, L::N_LAYERS])[:, 0, :] for s in range(SPINS): for f in range(NCOR): if f not in dmft_id: Smat[s, :, f] = S0[s, f] Gmat[s, :, f] = 1.0 / (aWeiss[s, :, f] - Smat[s, :, f]) Gtau[s, :, f] = cppext.IFT_mat2tau(Gmat[s, :, f].copy(), Ntau, float(parms["BETA"]), 1.0, 0.0) Gtau[:, 0, :] = -(1.0 - nf) Gtau[:, -1, :] = -nf # saving data dT = 5 Nb2 = size(tmph5["Gtau"], 0) / 2 Gb2 = array([mean(tmph5["Gtau"][Nb2 - dT : Nb2 + dT, f], 0) for f in range(size(tmph5["Gtau"], 1))]) log_data(h5solver, "log_Gbeta2", it, Gb2.flatten(), data_type=float) log_data(h5solver, "log_nsolve", it, -tmph5["Gtau"][-1, :].flatten(), data_type=float) log_data(h5solver, "hyb_asym_coeffs", it, tmph5["hyb_asym_coeffs"][:].flatten(), data_type=float) save_data(h5solver, it, ("Gtau", "Hybtau", "Hybmat"), (Gtau, Htau, tmph5["Hybmat"][:])) tmph5.close() del tmph5 os.system("rm %s" % tmph5filename) return Gmat, Smat
def HartreeRun(parms, extra): print "Initialization using Hartree approximation\n" N_LAYERS = int(parms['N_LAYERS']); FLAVORS = int(parms['FLAVORS']); SPINS = 1; p = dict({ 'MU' : float(val_def(parms, 'MU', 0)), 'N_LAYERS': N_LAYERS, 'NORB' : int(parms['NORB']), 'U' : float(parms['U']), 'J' : float(parms['J']), 'DELTA': float(val_def(parms, 'DELTA', 0)), 'ND' : N_LAYERS*float(val_def(parms, 'ND', -1)), 'DENSITY' : N_LAYERS*float(parms['DENSITY']), 'FLAVORS' : FLAVORS, 'SPINS' : 1, 'OUTPUT' : '.' + parms['DATA_FILE'] + '_HartreeInit', 'NN' : None, 'N_MAX_FREQ' : 30, 'BETA' : float(parms['BETA']), 'NUMK' : int(val_def(parms, 'INIT_NUMK', 8)), 'TUNEUP' : int(val_def(parms, 'NO_TUNEUP', 0)) == 0, 'MAX_ITER' : 15, 'ALPHA' : 0.5, # pay attention at this parm sometimes 'DTYPE' : parms['DTYPE'], 'INTEGRATE_MOD' : val_def(parms, 'INTEGRATE_MOD', 'integrate'), 'np' : parms['np'] }); for k, v in p.iteritems(): print k + ': ', v; bp, wf = grule(p['NUMK']); X, W = generateGaussPoints(p['N_MAX_FREQ']); wn = 1/sqrt(X)/p['BETA']; p.update({ 'X' : X, 'W' : W, 'w' : wn }); if p['NN'] is None and os.path.isfile(p['OUTPUT']+'.nn'): p['NN'] = p['OUTPUT']; # running TOL = 1e-2; if p['NN'] is None: nn = ones(N_LAYERS*FLAVORS, dtype = 'f8') * p['DENSITY']/p['NORB']/2; # 2 for spin mu = p['MU']; delta = p['DELTA']; else: print 'Continue from '+p['NN']; nn = genfromtxt(p['NN']+'.nn')[2:]; mu = genfromtxt(p['NN']+'.nn')[1]; delta = genfromtxt(p['NN']+'.nn')[0]; Gavg = zeros((p['N_MAX_FREQ'], p['NORB']), dtype = 'c16'); se = zeros((SPINS, p['N_MAX_FREQ'], N_LAYERS*FLAVORS), dtype = 'c16'); stop = False; count = 0; ALPHA = p['ALPHA']; corr1 = system.getDMFTCorrIndex(parms, all = False); corr2 = array([i for i in range(FLAVORS) if i not in corr1]); # index for eg bands old_GaussianData = extra['GaussianData']; extra['GaussianData'] = [bp, wf]; while not stop: count += 1; nn_old = nn.copy(); p['MU'] = mu; p['DELTA'] = delta; Gavg_old = Gavg.copy(); for L in range(N_LAYERS): se_coef = functions.get_asymp_selfenergy(p, array([nn[L:N_LAYERS*FLAVORS:N_LAYERS]]))[0, 0, :]; for s in range(SPINS): for f in range(len(se_coef)): se[s, :, f*N_LAYERS+L] = se_coef[f]; Gavg, delta, mu, Vc = averageGreen(delta, mu, 1j*wn, se, p, p['ND'], p['DENSITY'], p['TUNEUP'], extra); Gavg = mean(Gavg, 0); nn = getDensity(Gavg, p); # no spin/orbital polarization, no charge order for L in range(N_LAYERS): nf1 = nn[0:N_LAYERS*FLAVORS:N_LAYERS]; for id in range(FLAVORS): if id in corr1: nf1[id] = mean(nf1[corr1]); else: nf1[id] = mean(nf1[corr2]); nn[L:N_LAYERS*FLAVORS:N_LAYERS] = nf1; err = linalg.norm(r_[delta, mu, nn] - r_[p['DELTA'], p['MU'], nn_old]); savetxt(p['OUTPUT']+'.nn', r_[delta, mu, nn]); print 'Step %d: %.5f'%(count, err); if (err < TOL): stop = True; print 'converged'; if count > p['MAX_ITER']: break; mu = ALPHA*mu + (1-ALPHA)*p['MU']; delta = ALPHA*delta + (1-ALPHA)*p['DELTA']; nn = ALPHA*nn + (1-ALPHA)*nn_old; # DOS NFREQ = 500; BROADENING = 0.03; extra['GaussianData'] = old_GaussianData; parms_tmp = parms.copy(); parms_tmp['DELTA'] = delta; Eav = system.getAvgDispersion(parms_tmp, 3, extra)[0,0,:]; Ed = mean(Eav[:N_LAYERS*FLAVORS][corr1]); Ep = mean(Eav[N_LAYERS*FLAVORS:]) if N_LAYERS*FLAVORS < p['NORB'] else Ed; emax = min(4, p['U']); emin = -(Ed - Ep + max(se_coef) + min(4, p['U'])); print "Energy range for HF DOS: ", emin, emax w = linspace(emin, emax, NFREQ) + 1j*BROADENING; se = zeros((SPINS, NFREQ, N_LAYERS*FLAVORS), dtype = 'c16'); for L in range(N_LAYERS): se_coef = functions.get_asymp_selfenergy(p, array([nn[L:N_LAYERS*FLAVORS:N_LAYERS]]))[0, 0, :]; for s in range(SPINS): for f in range(len(se_coef)): se[s, :, f*N_LAYERS+L] = se_coef[f]; Gr = average_green.averageGreen(delta, mu, w, se, p,p['ND'], p['DENSITY'], 0, extra)[1][0]; savetxt(parms['ID']+'.dos', c_[w.real, -1/pi*Gr.imag], fmt = '%.6f'); print ('End Hartree approx.:%d Ntot=%.2f Nd=%.2f Delta=%.4f ' 'Delta_eff=%.4f')%(count, 2*sum(nn)/N_LAYERS, 2*sum(nn[:N_LAYERS*FLAVORS]/N_LAYERS), delta, delta-mean(se_coef[corr1])), ': \n', \ nn[:N_LAYERS*FLAVORS].reshape(-1, N_LAYERS),\ '\n\n' # os.system('rm ' + p['OUTPUT']+'.nn'); return delta, mu, array([nn for s in range(int(parms['SPINS']))]), Vc;
def gget(data, st, iter = None, L = None, f = None): if iter == None: iter = str(data['iter'][0]); iter = str(iter); parms = load_parms(data, int(iter)); N_LAYERS = int(parms['N_LAYERS']); FLAVORS = int(parms['FLAVORS']); SPINS = int(parms['SPINS']); NORB = int(parms['NORB']); NCOR = int(parms['NCOR']); corr_id = system.getCorrIndex(parms); dmft_id = system.getDMFTCorrIndex(parms); dmft_site_id = system.getDMFTCorrIndex(parms, all = False); if st == 'wn': NMaxFreq = int(parms['N_MAX_FREQ']); BETA = float(parms['BETA']); return (2*arange(0, NMaxFreq)+1)*pi/BETA; if st == 'parms': return parms; if st == 'log': log = data['log_density'][:]; num_iter = len(log); nraw = log[:,4:]; orbital = zeros((num_iter, FLAVORS, N_LAYERS)); orbital_abs = zeros((num_iter, FLAVORS, N_LAYERS)); spinup = zeros((num_iter, N_LAYERS)); spindn = zeros((num_iter, N_LAYERS)); density = zeros((num_iter, N_LAYERS)); magnetization = zeros((num_iter, N_LAYERS)); for n in range(num_iter): nf = nraw[n].reshape(SPINS, -1)[:, :NCOR]; noxy = nraw[n].reshape(SPINS, -1)[:, -1]/N_LAYERS; # if n > 0: # nf_gtau = -data['SolverData/Gtau/'+str(n)][:, -1, :]; # nf[:, dmft_id] = nf_gtau[:, dmft_id]; nf = nf.reshape(SPINS, FLAVORS, N_LAYERS); if SPINS == 1: nf = r_[nf, nf]; noxy = r_[noxy, noxy]; density[n] = array([sum(nf[:,:,i]) for i in range(N_LAYERS)]); orbital[n] = (nf[0] + nf[1])/density[n]; orbital_abs[n] = (nf[0] + nf[1]); spinup[n] = sum(nf[0], 0)/density[n] - 1./2; spindn[n] = sum(nf[1], 0)/density[n] - 1./2; # magnetization[n] = sum(nf[0, dmft_site_id, :] - nf[1, dmft_site_id], 0); magnetization[n] = sum(nf[0] - nf[1], 0) + noxy[0] - noxy[1]; # magnetization[n] = sum(nf[0] - nf[1], 0); out = (log[:,:4], density, spinup, spindn, orbital, magnetization, orbital_abs); return out; if L == None: L = arange(N_LAYERS); if f == None: f = arange(FLAVORS); L = array([L]).flatten(); f = asarray([f]).flatten(); idx = array([], dtype = 'i4'); for i in range(0,len(f)): idx = r_[idx, L + f[i]*N_LAYERS]; idx = sort(idx); if st == 'idx': return idx; if st == 'Gimp': return data['ImpurityGreen/' + iter][:,:,idx]; if st == 'se': return data['SelfEnergy/' + iter][:,:,idx]; if st == 'as': return data['WeissField/' + iter][:,:,idx]; if st == 'Gavg': return data['avgGreen/' + iter][:,:, corr_id][:,:,idx]; if st == 'hybmat': return data['SolverData/Hybmat/' + iter][:,:,idx]; if st == 'hybtau': return data['SolverData/Hybtau/' + iter][:,:,idx]; if st == 'Gtau': return data['SolverData/Gtau/' + iter][:,:,idx]; if st == 'G0': return 1. / data['WeissField/' + iter][:,:,idx]; if st == 'bG': return getFermiDOS(data, iter); if st == 'Gtot': return getTotalGtau(data, iter); if st == 'Z' : return getRenormFactor(data, npoint = 2, it = iter);