def mb_ph_ops(hlat, perturb, omega, nimp, nocc, pemb, pcore, pvirt): """ external ops for part-hole Green's function """ nimp_sp = nimp * 2 nsites_sp = hlat.shape[0] * 2 nocc_sp = nocc * 2 # transform h into imp+bath/ext(all) basis pall = N.hstack([pemb, pcore, pvirt]) hall = N.dot(pall.T, N.dot(hlat, pall)) hall_sp = _spinify(hall) # t1amp in (all) basis t1amp_ao = make_t1amp_ao(hlat, omega, perturb, nocc) t1amp_all = N.dot(pall.T, N.dot(t1amp_ao, pall)) t1amp_all_sp = _spinify(t1amp_all) # mb_ext_operators sites_imp = range(0, nimp_sp * 2) sites_ext = range(nimp_sp * 2, nsites_sp) cops = [] dops = [] project = False if project: li_t1amp_ext_imp = _linear_orthonormal_basis( t1amp_all_sp[sites_ext, :][:, sites_imp], orient='c') print "retained %i out of %i vectors" % (li_t1amp_ext_imp.shape[1], len(sites_imp)) li_t1amp_imp_ext = _linear_orthonormal_basis( t1amp_all_sp[sites_imp, :][:, sites_ext], orient='r') print "retained %i out of %i vectors" % (li_t1amp_imp_ext.shape[0], len(sites_imp)) for i in xrange(li_t1amp_ext_imp.shape[1]): cops.append(models.ContractedC(sites_ext, li_t1amp_ext_imp[:, i])) for i in xrange(li_t1amp_imp_ext.shape[0]): dops.append(models.ContractedD(sites_ext, li_t1amp_imp_ext[i, :])) else: for imp in sites_imp: coeff_c = t1amp_all_sp[sites_ext, imp] cops.append(models.ContractedC(sites_ext, coeff_c)) coeff_d = t1amp_all_sp[imp, sites_ext] dops.append(models.ContractedD(sites_ext, coeff_d)) cd_coeffs = {} for i in sites_ext: for j in sites_ext: if abs(t1amp_all_sp[i, j]) > 1.e-8: cd_coeffs[i, j] = t1amp_all_sp[i, j] cdop = models.ContractedCD(cd_coeffs) ops = {"1": models.Unit(), "c": cops, "d": dops, "cd": cdop} return ops
def hubbard_imp_ext_h(h0, u, nocc, nimp, nsites): nsites_sp = nsites * 2 sites_imp = range(0, 4 * nimp) sites_ext = range(4 * nimp, 2 * nsites) t_dict = {} for i in xrange(nsites_sp): for j in xrange(nsites_sp): if abs(h0[i, j]) > 1.e-12: t_dict[i, j] = h0[i, j] t_dict[0, 0] = 0 t_dict[1, 1] = 0 u_dict = {} u_dict[0, 1] = u # h in imp+ext space hop = models.GeneralHubbard(t_dict, u_dict) t_imp = {} for i in sites_imp: for j in sites_imp: if abs(h0[i, j]) > 1.e-12: t_imp[i, j] = h0[i, j] t_imp[0, 0] = 0 t_imp[1, 1] = 0 t_ext = {} for i in sites_ext: for j in sites_ext: if abs(h0[i, j]) > 1.e-12: t_ext[i, j] = h0[i, j] hext = models.ContractedCD(t_ext) himp = models.GeneralHubbard(t_imp, u_dict) hcs_imp = [] hds_imp = [] hcs_ext = [] hds_ext = [] for i in sites_imp: imp_coeffs = utils.zeros(len(sites_imp)) imp_coeffs[i] = 1. hcs_imp.append(models.ContractedC(sites_imp, imp_coeffs)) hds_imp.append(models.ContractedD(sites_imp, imp_coeffs)) hcs_ext.append(models.ContractedC(sites_ext, h0[sites_ext, i])) hds_ext.append(models.ContractedD(sites_ext, h0[i, sites_ext])) return hop, himp, hcs_imp, hds_imp, hcs_ext, hds_ext, hext
def mb_sp_ops(hlat, perturb, omega, nimp, nocc, pemb, pcore, pvirt): """ single particle external ops (for single particle Green's function) """ nimp_sp = nimp * 2 nsites_sp = hlat.shape[0] * 2 nocc_sp = nocc * 2 # transform h into imp+bath/ext(all) basis pall = N.hstack([pemb, pcore, pvirt]) hall = N.dot(pall.T, N.dot(hlat, pall)) hall_sp = _spinify(hall) # green's function amps in (all) basis damp_ao, camp_ao = make_greens_ao(hlat, omega, perturb, nocc) damp_all = N.dot(pall.T, damp_ao) camp_all = N.dot(pall.T, camp_ao) #print N.dot(damp_ao,pall) damp_all_sp = _spinify_vec(damp_all) camp_all_sp = _spinify_vec(camp_all) # mb_ext operators sites_imp = range(0, nimp_sp * 2) sites_ext = range(nimp_sp * 2, nsites_sp) coeff_c = camp_all_sp[sites_ext] cops = [models.ContractedC(sites_ext, coeff_c)] coeff_d = damp_all_sp[sites_ext] dops = [models.ContractedD(sites_ext, coeff_d)] ops = {"1": models.Unit(), "c": cops, "d": dops} return ops
def sp_greens(): # main loop for single-particle GF utils.dtype = N.complex128 nimp = 1 nimp_sp = 2 * nimp nocc = 20 nsites = 40 nsites_sp = nsites * 2 ndim = 2 sz = 0 # sites numbered in order as imp+bath ... ext sites_imp = range(0, 2 * nimp_sp) sites_ext = range(2 * nimp_sp, nsites_sp) ncore = 2 * nocc - 2 * nimp cocc = range(2 * nimp_sp, 2 * nimp_sp + ncore) vocc = range(2 * nimp_sp + ncore, nsites_sp) N.set_printoptions(precision=3) t = -1. # hopping delta = 0.2 # broadening # for u in [0.0,4.0,10.0]: for u in [1.0]: # Single impurity Anderson model mu = 0. hlat, hall, hlat_sp, hall_sp, e0 = models_embed.si_anderson_imp_ext_ni_h( t, nocc, nimp, nsites) hop, himp, hcs_imp, hds_imp, hcs_ext, hds_ext, hext = models_embed.si_anderson_imp_ext_h( hall_sp, u, nocc, nimp, nsites) # single site Hubbard in DMET basis # mu=u/2 # hlat,hall,hlat_sp,hall_sp,e0=models_embed.hubbard_imp_ext_ni_h(t,u,nocc,nimp,nsites) # hop,himp,hcs_imp,hds_imp,hcs_ext,hds_ext,hext=models_embed.hubbard_imp_ext_h(hall_sp,u,nocc,nimp,nsites) # g.s embedding basis pemb, pcore, pvirt = embed.embed(hlat, nimp, nocc) # perturbation operator perturb = utils.zeros([nsites]) perturb[0] = 1. p_coeffs = N.array([1]) perturb_dop = models.ContractedD(N.array([0]), p_coeffs) perturb_cop = models.ContractedC(N.array([0]), p_coeffs) fd = file("ph_siam.out." + str(u), "w") for omega in N.arange(-2, 2, 0.1): ops_dict = response_embed.mb_sp_ops(hlat, perturb, omega + 1j * delta, nimp, nocc, pemb, pcore, pvirt) configs_dict = response_embed.mb_configs(nsites, nimp, nimp_sp, 2 * nocc - nimp_sp, 0) neutral_ops_configs, plus_ops_configs, minus_ops_configs = response_embed.mb_sp_ops_configs( ops_dict, configs_dict) # basis is setup, now build matrix representations perturb_dop_mat = opbasis_ni.oimp_matrix_bra_ket_form( perturb_dop, minus_ops_configs, neutral_ops_configs, cocc, vocc) perturb_cop_mat = opbasis_ni.oimp_matrix_bra_ket_form( perturb_cop, plus_ops_configs, neutral_ops_configs, cocc, vocc) # h, N-1 configs himp_mat_minus = opbasis_ni.oimp_matrix_form( himp, minus_ops_configs, cocc, vocc) himp_ext_mat_minus = opbasis_ni.himp_ext_matrix_form( hcs_imp, hds_ext, hds_imp, hcs_ext, minus_ops_configs, cocc, vocc) hext_mat_minus = opbasis_ni.hext_matrix_form( hext, minus_ops_configs, cocc, vocc, e0) hmat_minus = himp_mat_minus + himp_ext_mat_minus + hext_mat_minus unit_mat_minus = opbasis_ni.oimp_matrix_form( models.Unit(), minus_ops_configs, cocc, vocc) # h, N+1 configs himp_mat_plus = opbasis_ni.oimp_matrix_form( himp, plus_ops_configs, cocc, vocc) himp_ext_mat_plus = opbasis_ni.himp_ext_matrix_form( hcs_imp, hds_ext, hds_imp, hcs_ext, plus_ops_configs, cocc, vocc) hext_mat_plus = opbasis_ni.hext_matrix_form( hext, plus_ops_configs, cocc, vocc, e0) hmat_plus = himp_mat_plus + himp_ext_mat_plus + hext_mat_plus unit_mat_plus = opbasis_ni.oimp_matrix_form( models.Unit(), plus_ops_configs, cocc, vocc) # h, neutral configs himp_mat = opbasis_ni.oimp_matrix_form(himp, neutral_ops_configs, cocc, vocc) himp_ext_mat = opbasis_ni.himp_ext_matrix_form( hcs_imp, hds_ext, hds_imp, hcs_ext, neutral_ops_configs, cocc, vocc) hext_mat = opbasis_ni.hext_matrix_form(hext, neutral_ops_configs, cocc, vocc, e0) hmat = himp_mat + himp_ext_mat + hext_mat unit_mat = opbasis_ni.oimp_matrix_form(models.Unit(), neutral_ops_configs, cocc, vocc) # get neutral ground-state energy es, cs = la.peigh(hmat, unit_mat) e0 = es[0] psi0 = cs[:, 0] print e0 print psi0 # all matrices setup, solve linear response (complex) psi1_minus = la.solve_perturb(omega + 1j * delta, unit_mat_minus, hmat_minus, e0, psi0, perturb_dop_mat, project=False, sign_ham=-1.) gfminus = N.dot(psi1_minus, N.dot(perturb_dop_mat, psi0)) psi1_plus = la.solve_perturb(omega + 1j * delta, unit_mat_plus, hmat_plus, e0, psi0, perturb_cop_mat, project=False) gfplus = N.dot(psi1_plus, N.dot(perturb_cop_mat, psi0)) d_gf, c_gf = _sp_gf(hlat, omega + 1j * delta, perturb, nocc) print omega, gfplus.imag, c_gf.imag, gfminus.imag, d_gf.imag print >> fd, omega - mu, gfplus.imag + gfminus.imag, c_gf.imag + d_gf.imag
def main(): # main loop for single-particle GF utils.dtype = N.complex128 nimp = 4 nimp_sp = 2 * nimp nsites = 8 nocc = nsites / 2 nsites_sp = nsites * 2 ndim = 2 sz = 0 # sites numbered in order as imp+bath ... ext sites_imp = range(0, 2 * nimp_sp) sites_ext = range(2 * nimp_sp, nsites_sp) ncore = 2 * nocc - 2 * nimp cocc = range(2 * nimp_sp, 2 * nimp_sp + ncore) vocc = range(2 * nimp_sp + ncore, nsites_sp) N.set_printoptions(precision=3) #t=1. # hopping gamma = 0.005 rho0 = (nsites - 2) / 2. t = 0.1 #N.sqrt(gamma/(rho0*N.pi)) #gamma = (t**2)*pi*0.1 delta = 0.005 # broadening #a=12.5 # for u in [0.0,4.0,10.0]: for u in [0., 2.5, 5., 7.5]: u *= t # Single impurity Anderson model mu = 0. hlat, hall, hlat_sp, hall_sp, e0 = models_embed.si_anderson_imp_ext_ni_h( t, u, nocc, nimp, nsites) hop, himp, hcs_imp, hds_imp, hcs_ext, hds_ext, hext = models_embed.si_anderson_imp_ext_h( hall_sp, u, nocc, nimp, nsites) #print hext # single site Hubbard in DMET basis #mu=u/2 #hlat,hall,hlat_sp,hall_sp,e0=models_embed.hubbard_imp_ext_ni_h(t,u,nocc,nimp,nsites) #hop,himp,hcs_imp,hds_imp,hcs_ext,hds_ext,hext=models_embed.hubbard_imp_ext_h(hall_sp,u,nocc,nimp,nsites) # g.s embedding basis pemb, pcore, pvirt = embed.embed(hlat, nimp, nocc) # perturbation operator perturb = utils.zeros([nsites]) perturb[0] = 1. p_coeffs = N.array([1]) perturb_dop = models.ContractedD(N.array([0]), p_coeffs) perturb_cop = models.ContractedC(N.array([0]), p_coeffs) fd = file( "siam_emb_dos_nsites" + str(nsites) + '_U' + str(u) + '_nimp' + str(nimp) + '_eta' + str(delta), "w") for omega in N.arange(-1., 1., 0.01): ops_dict = response_embed.mb_sp_ops(hlat, perturb, omega + 1j * delta, nimp, nocc, pemb, pcore, pvirt) configs_dict = response_embed.mb_configs(nsites, nimp, nimp_sp, 2 * nocc - nimp_sp, 0) neutral_ops_configs, plus_ops_configs, minus_ops_configs = response_embed.mb_sp_ops_configs( ops_dict, configs_dict) #print minus_ops_configs # basis is setup, now build matrix representations perturb_dop_mat = opbasis_ni.oimp_matrix_bra_ket_form( perturb_dop, minus_ops_configs, neutral_ops_configs, cocc, vocc) perturb_cop_mat = opbasis_ni.oimp_matrix_bra_ket_form( perturb_cop, plus_ops_configs, neutral_ops_configs, cocc, vocc) #print plus_ops_configs # h, N-1 configs #print minus_ops_configs himp_mat_minus = opbasis_ni.oimp_matrix_form( himp, minus_ops_configs, cocc, vocc) himp_ext_mat_minus = opbasis_ni.himp_ext_matrix_form( hcs_imp, hds_ext, hds_imp, hcs_ext, minus_ops_configs, cocc, vocc) #print himp_ext_mat_minus hext_mat_minus = opbasis_ni.hext_matrix_form( hext, minus_ops_configs, cocc, vocc, e0) hmat_minus = himp_mat_minus + himp_ext_mat_minus + hext_mat_minus unit_mat_minus = opbasis_ni.oimp_matrix_form( models.Unit(), minus_ops_configs, cocc, vocc) #print hext_mat_minus # h, N+1 configs himp_mat_plus = opbasis_ni.oimp_matrix_form( himp, plus_ops_configs, cocc, vocc) himp_ext_mat_plus = opbasis_ni.himp_ext_matrix_form( hcs_imp, hds_ext, hds_imp, hcs_ext, plus_ops_configs, cocc, vocc) hext_mat_plus = opbasis_ni.hext_matrix_form( hext, plus_ops_configs, cocc, vocc, e0) hmat_plus = himp_mat_plus + himp_ext_mat_plus + hext_mat_plus unit_mat_plus = opbasis_ni.oimp_matrix_form( models.Unit(), plus_ops_configs, cocc, vocc) # h, neutral configs himp_mat = opbasis_ni.oimp_matrix_form(himp, neutral_ops_configs, cocc, vocc) himp_ext_mat = opbasis_ni.himp_ext_matrix_form( hcs_imp, hds_ext, hds_imp, hcs_ext, neutral_ops_configs, cocc, vocc) hext_mat = opbasis_ni.hext_matrix_form(hext, neutral_ops_configs, cocc, vocc, e0) hmat = himp_mat + himp_ext_mat + hext_mat unit_mat = opbasis_ni.oimp_matrix_form(models.Unit(), neutral_ops_configs, cocc, vocc) # get neutral ground-state energy es, cs = la.peigh(hmat, unit_mat) e_gs = es[0] psi0 = cs[:, 0] #print e0 #print psi0 #print N.dot(perturb_dop_mat,psi0) # all matrices setup, solve linear response (complex) psi1_minus = la.solve_perturb(omega + 1j * delta, unit_mat_minus, hmat_minus, e_gs, psi0, perturb_dop_mat, project=False, sign_ham=-1.) gfminus = N.dot(psi1_minus, N.dot(perturb_dop_mat, psi0)) psi1_plus = la.solve_perturb(omega + 1j * delta, unit_mat_plus, hmat_plus, e_gs, psi0, perturb_cop_mat, project=False) #print N.dot(perturb_cop_mat,psi0) #print hmat gfplus = N.dot(psi1_plus, N.dot(perturb_cop_mat, psi0)) d_gf, c_gf = _sp_gf(hlat, omega + 1j * delta, perturb, nocc) #print omega, gfplus.imag,c_gf.imag, gfminus.imag,d_gf.imag #print >>fd, omega-mu, -1.*(gfplus.imag),-1.*(c_gf.imag+d_gf.imag) print >> fd, omega - mu, -(1 / N.pi) * (gfplus.imag + gfminus.imag)
def main(): # main loop for single-particle GF utils.dtype = N.complex128 nimp = 1 nimp_sp = 2 * nimp nsites = 300 nocc = nsites / 2 nsites_sp = nsites * 2 ndim = 2 sz = 0 # sites numbered in order as imp+bath ... ext sites_imp = range(0, 2 * nimp_sp) sites_ext = range(2 * nimp_sp, nsites_sp) ncore = 2 * nocc - 2 * nimp cocc = range(2 * nimp_sp, 2 * nimp_sp + ncore) vocc = range(2 * nimp_sp + ncore, nsites_sp) N.set_printoptions(precision=3) #t=1. # hopping gamma = 0.05 rho0 = (nsites - 2) / 2. t = N.sqrt(gamma / (rho0 * N.pi)) #t = 0.1 #gamma = (t**2)*pi*0.1 delta = 1e-12 # broadening #a=12.5 # for u in [0.0,4.0,10.0]: for u in [10.]: u *= gamma # Single impurity Anderson model mu = 0. hlat, hall, hlat_sp, hall_sp, e0 = models_embed.si_anderson_imp_ext_ni_h( t, u, nocc, nimp, nsites) hop, himp, hcs_imp, hds_imp, hcs_ext, hds_ext, hext = models_embed.si_anderson_imp_ext_h( hall_sp, u, nocc, nimp, nsites) #print hext # single site Hubbard in DMET basis #mu=u/2 #hlat,hall,hlat_sp,hall_sp,e0=models_embed.hubbard_imp_ext_ni_h(t,u,nocc,nimp,nsites) #hop,himp,hcs_imp,hds_imp,hcs_ext,hds_ext,hext=models_embed.hubbard_imp_ext_h(hall_sp,u,nocc,nimp,nsites) # g.s embedding basis pemb, pcore, pvirt = embed.embed(hlat, nimp, nocc) # perturbation operator perturb = utils.zeros([nsites]) perturb[0] = 1. p_coeffs = N.array([1]) perturb_dop = models.ContractedD(N.array([0]), p_coeffs) perturb_cop = models.ContractedC(N.array([0]), p_coeffs) #fd=file("siam_emb_dos_nsites"+str(nsites)+'_U'+str(u)+'_nimp'+str(nimp)+'_eta'+str(delta),"w") fdEnminus = file("En_minus", "w") fdCnminus = file("Cn_minus", "w") fdEnplus = file("En_plus", "w") fdCnplus = file("Cn_plus", "w") for omega in [1e-08]: #N.arange(-1.,1.,0.1): #print omega ops_dict = response_embed.mb_sp_ops(hlat, perturb, omega + 1j * delta, nimp, nocc, pemb, pcore, pvirt) configs_dict = response_embed.mb_configs(nsites, nimp, nimp_sp, 2 * nocc - nimp_sp, 0) neutral_ops_configs, plus_ops_configs, minus_ops_configs = response_embed.mb_sp_ops_configs( ops_dict, configs_dict) #print _ops_configs # basis is setup, now build matrix representations perturb_dop_mat = opbasis_ni.oimp_matrix_bra_ket_form( perturb_dop, minus_ops_configs, neutral_ops_configs, cocc, vocc) perturb_cop_mat = opbasis_ni.oimp_matrix_bra_ket_form( perturb_cop, plus_ops_configs, neutral_ops_configs, cocc, vocc) # h, N-1 configs #print ops_dict['d'][0] himp_mat_minus = opbasis_ni.oimp_matrix_form( himp, minus_ops_configs, cocc, vocc) himp_ext_mat_minus = opbasis_ni.himp_ext_matrix_form( hcs_imp, hds_ext, hds_imp, hcs_ext, minus_ops_configs, cocc, vocc) #print himp_ext_mat_minus hext_mat_minus = opbasis_ni.hext_matrix_form( hext, minus_ops_configs, cocc, vocc, e0) hmat_minus = himp_mat_minus + himp_ext_mat_minus + hext_mat_minus unit_mat_minus = opbasis_ni.oimp_matrix_form( models.Unit(), minus_ops_configs, cocc, vocc) #print hext_mat_minus # h, N+1 configs himp_mat_plus = opbasis_ni.oimp_matrix_form( himp, plus_ops_configs, cocc, vocc) himp_ext_mat_plus = opbasis_ni.himp_ext_matrix_form( hcs_imp, hds_ext, hds_imp, hcs_ext, plus_ops_configs, cocc, vocc) hext_mat_plus = opbasis_ni.hext_matrix_form( hext, plus_ops_configs, cocc, vocc, e0) hmat_plus = himp_mat_plus + himp_ext_mat_plus + hext_mat_plus unit_mat_plus = opbasis_ni.oimp_matrix_form( models.Unit(), plus_ops_configs, cocc, vocc) # h, neutral configs himp_mat = opbasis_ni.oimp_matrix_form(himp, neutral_ops_configs, cocc, vocc) himp_ext_mat = opbasis_ni.himp_ext_matrix_form( hcs_imp, hds_ext, hds_imp, hcs_ext, neutral_ops_configs, cocc, vocc) hext_mat = opbasis_ni.hext_matrix_form(hext, neutral_ops_configs, cocc, vocc, e0) hmat = himp_mat + himp_ext_mat + hext_mat unit_mat = opbasis_ni.oimp_matrix_form(models.Unit(), neutral_ops_configs, cocc, vocc) #print hext_mat_minus # get neutral ground-state energy es, cs = la.peigh(hmat, unit_mat) e_gs = es[0] psi0 = cs[:, 0] es_minus, cs_minus = la.peigh(hmat_minus, unit_mat_minus) Enarray = es_minus - e_gs * N.ones(len(es_minus)) print >> fdEnminus, omega, str(list(Enarray))[1:-1].translate( None, ',') es_plus, cs_plus = la.peigh(hmat_plus, unit_mat_plus) Enarray = es_plus - e_gs * N.ones(len(es_minus)) print >> fdEnplus, omega, str(list(Enarray))[1:-1].translate( None, ',') gfminus = 0. mat_el_list_minus = [] for i in xrange(len(es_minus)): ket = N.dot(perturb_dop_mat, psi0) bra = N.transpose(cs_minus[:, i].conjugate()) mat_el = N.dot(bra, ket) mat_el *= mat_el.conjugate() mat_el_list_minus.append(mat_el.real) den = omega + 1j * delta - e_gs + es_minus[i] gfminus += (mat_el / den) print >> fdCnminus, omega, str(mat_el_list_minus)[1:-1].translate( None, ',') gfplus = 0. mat_el_list_plus = [] for i in xrange(len(es_plus)): ket = N.dot(perturb_cop_mat, psi0) bra = N.transpose(cs_plus[:, i].conjugate()) mat_el = N.dot(bra, ket) mat_el *= mat_el.conjugate() mat_el_list_plus.append(mat_el.real) den = omega + 1j * delta + e_gs - es_plus[i] gfplus += (mat_el / den) print >> fdCnplus, omega, str(mat_el_list_plus)[1:-1].translate( None, ',')