def put_gf_on_mesh(g_in, wmesh): assert (len(wmesh) <= len(g_in.mesh)) g_out = Gf(mesh=wmesh, target_shape=g_in.target_shape) for w in wmesh: index = w.linear_index + wmesh.first_index() # absolute index g_out[w] = g_in[Idx(index)] return g_out
def plot_g2(G2, cplx=None, idx_labels=None, w=Idx(0), opt={}, title=None): data = G2[w, :, :].data if cplx == 're': data = data.real elif cplx == 'im': data = data.imag n = data.shape[-1] N = n**2 subp = [N, N, 1] colorbar_flag = True import itertools for idxs in itertools.product(xrange(n), repeat=4): i1, i2, i3, i4 = idxs d = data[:, :, i1, i2, i3, i4] ax = plt.subplot(*subp) subp[-1] += 1 if idx_labels is not None: labels = [idx_labels[idx] for idx in idxs] sub_title = r'$c^\dagger_{%s} c_{%s} c^\dagger_{%s} c_{%s}$' % tuple( labels) else: sub_title = str(idxs) plt.title(sub_title, fontsize=8) #plt.pcolormesh(d, **opt) if np.max(np.abs(d)) > 1e-10: plt.imshow(d, **opt) if colorbar_flag: if title is not None: plt.title(title) plt.colorbar() colorbar_flag = False ax.set_xticks([]) ax.set_yticks([]) plt.axis('equal') plt.tight_layout()
def strip_sigma(nw, beta, sigma_in, debug=False): np.testing.assert_almost_equal(beta, sigma_in.mesh.beta) wmesh = MeshImFreq(beta, 'Fermion', n_max=nw) sigma = Gf(mesh=wmesh, target_shape=sigma_in.target_shape) for w in wmesh: index = w.linear_index + wmesh.first_index() # absolute index sigma[w] = sigma_in[Idx(index)] if debug: from pytriqs.plot.mpl_interface import oplot, plt oplot(p.Sigmalatt_iw) oplot(sigma, 'x') plt.show() exit() return sigma
def cf_chi_w0(chi1, chi2, decimal=9): chi1, chi2 = chi1[Idx(0), :].data, chi2[Idx(0), :].data diff = np.linalg.norm(chi1 - chi2) print '|dchi| =', diff np.testing.assert_array_almost_equal(chi1, chi2, decimal=decimal)
def make_calc(): # ------------------------------------------------------------------ # -- Read precomputed ED data filename = "data_pomerol.tar.gz" p = read_TarGZ_HDFArchive(filename) # ------------------------------------------------------------------ # -- RPA tensor from triqs_tprf.rpa_tensor import get_rpa_tensor from triqs_tprf.rpa_tensor import fundamental_operators_from_gf_struct fundamental_operators = fundamental_operators_from_gf_struct(p.gf_struct) p.U_abcd = get_rpa_tensor(p.H_int, fundamental_operators) # ------------------------------------------------------------------ # -- Generalized PH susceptibility loc_bse = ParameterCollection() loc_bse.chi_wnn = chi_from_gg2_PH(p.G_iw, p.G2_iw_ph) loc_bse.chi0_wnn = chi0_from_gg2_PH(p.G_iw, p.G2_iw_ph) loc_bse.gamma_wnn = inverse_PH(loc_bse.chi0_wnn) - inverse_PH( loc_bse.chi_wnn) loc_bse.chi_wnn_ref = inverse_PH( inverse_PH(loc_bse.chi0_wnn) - loc_bse.gamma_wnn) np.testing.assert_array_almost_equal(loc_bse.chi_wnn.data, loc_bse.chi_wnn_ref.data) loc_bse.chi0_w = trace_nn(loc_bse.chi0_wnn) loc_bse.chi_w = trace_nn(loc_bse.chi_wnn) # ------------------------------------------------------------------ # -- RPA, using BSE inverses and constant Gamma loc_rpa = ParameterCollection() loc_rpa.U_abcd = p.U_abcd # -- Build constant gamma loc_rpa.gamma_wnn = loc_bse.gamma_wnn.copy() loc_rpa.gamma_wnn.data[:] = loc_rpa.U_abcd[None, None, None, ...] # Nb! In the three frequency form $\Gamma \propto U/\beta^2$ loc_rpa.gamma_wnn.data[:] /= p.beta**2 loc_rpa.chi0_wnn = loc_bse.chi0_wnn loc_rpa.chi0_w = loc_bse.chi0_w # -- Solve RPA loc_rpa.chi_wnn = inverse_PH( inverse_PH(loc_rpa.chi0_wnn) - loc_rpa.gamma_wnn) loc_rpa.chi_w = trace_nn(loc_rpa.chi_wnn) # ------------------------------------------------------------------ # -- Bubble RPA on lattice lat_rpa = ParameterCollection() # -- Setup dummy lattice Green's function equal to local Green's function bz = BrillouinZone( BravaisLattice(units=np.eye(3), orbital_positions=[(0, 0, 0)])) periodization_matrix = np.diag(np.array(list([1] * 3), dtype=np.int32)) kmesh = MeshBrillouinZone(bz, periodization_matrix) wmesh = MeshImFreq(beta=p.beta, S='Fermion', n_max=p.nwf_gf) lat_rpa.g_wk = Gf(mesh=MeshProduct(wmesh, kmesh), target_shape=p.G_iw.target_shape) lat_rpa.g_wk[:, Idx(0, 0, 0)] = p.G_iw # -- chi0_wk bubble and chi_wk_rpa bubble RPA from triqs_tprf.lattice_utils import imtime_bubble_chi0_wk lat_rpa.chi0_wk = imtime_bubble_chi0_wk(lat_rpa.g_wk, nw=1) from triqs_tprf.lattice import solve_rpa_PH lat_rpa.chi_wk = solve_rpa_PH(lat_rpa.chi0_wk, p.U_abcd) lat_rpa.chi0_w = lat_rpa.chi0_wk[:, Idx(0, 0, 0)] lat_rpa.chi_w = lat_rpa.chi_wk[:, Idx(0, 0, 0)] print '--> cf Tr[chi0] and chi0_wk' print loc_rpa.chi0_w.data.reshape((4, 4)).real print lat_rpa.chi0_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi0_w.data, lat_rpa.chi0_w.data, decimal=2) print 'ok!' print '--> cf Tr[chi_rpa] and chi_wk_rpa' print loc_rpa.chi_w.data.reshape((4, 4)).real print lat_rpa.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi_w.data, lat_rpa.chi_w.data, decimal=2) print 'ok!' # ------------------------------------------------------------------ # -- Lattice BSE lat_bse = ParameterCollection() lat_bse.g_wk = lat_rpa.g_wk from triqs_tprf.lattice import fourier_wk_to_wr lat_bse.g_wr = fourier_wk_to_wr(lat_bse.g_wk) from triqs_tprf.lattice import chi0r_from_gr_PH lat_bse.chi0_wnr = chi0r_from_gr_PH(nw=1, nnu=p.nwf, gr=lat_bse.g_wr) from triqs_tprf.lattice import chi0q_from_chi0r lat_bse.chi0_wnk = chi0q_from_chi0r(lat_bse.chi0_wnr) # -- Lattice BSE calc from triqs_tprf.lattice import chiq_from_chi0q_and_gamma_PH lat_bse.chi_kwnn = chiq_from_chi0q_and_gamma_PH(lat_bse.chi0_wnk, loc_bse.gamma_wnn) # -- Trace results from triqs_tprf.lattice import chi0q_sum_nu_tail_corr_PH from triqs_tprf.lattice import chi0q_sum_nu lat_bse.chi0_wk_tail_corr = chi0q_sum_nu_tail_corr_PH(lat_bse.chi0_wnk) lat_bse.chi0_wk = chi0q_sum_nu(lat_bse.chi0_wnk) from triqs_tprf.lattice import chiq_sum_nu, chiq_sum_nu_q lat_bse.chi_kw = chiq_sum_nu(lat_bse.chi_kwnn) lat_bse.chi0_w_tail_corr = lat_bse.chi0_wk_tail_corr[:, Idx(0, 0, 0)] lat_bse.chi0_w = lat_bse.chi0_wk[:, Idx(0, 0, 0)] lat_bse.chi_w = lat_bse.chi_kw[Idx(0, 0, 0), :] print '--> cf Tr[chi0_wnk] and chi0_wk' print lat_bse.chi0_w_tail_corr.data.reshape((4, 4)).real print lat_bse.chi0_w.data.reshape((4, 4)).real print lat_rpa.chi0_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi0_w_tail_corr.data, lat_rpa.chi0_w.data) np.testing.assert_array_almost_equal(lat_bse.chi0_w.data, lat_rpa.chi0_w.data, decimal=2) print 'ok!' print '--> cf Tr[chi_kwnn] and chi_wk' print lat_bse.chi_w.data.reshape((4, 4)).real print loc_bse.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi_w.data, loc_bse.chi_w.data) print 'ok!' # ------------------------------------------------------------------ # -- Store to hdf5 filename = 'data_bse_rpa.h5' with HDFArchive(filename, 'w') as res: res['p'] = p
def get_chi0_wnk(g_wk, nw=1, nwf=None): fmesh = g_wk.mesh.components[0] kmesh = g_wk.mesh.components[1] if nwf is None: nwf = len(fmesh) / 2 mpi.barrier() mpi.report('g_wk ' + str(g_wk[Idx(2), Idx(0, 1, 2)][0, 0])) n = np.sum(g_wk.data) / len(kmesh) mpi.report('n ' + str(n)) mpi.barrier() mpi.report('--> g_wr from g_wk') g_wr = fourier_wk_to_wr(g_wk) mpi.barrier() mpi.report('g_wr ' + str(g_wr[Idx(2), Idx(0, 1, 2)][0, 0])) n_r = np.sum(g_wr.data, axis=0)[0] mpi.report('n_r=0 ' + str(n_r[0, 0])) mpi.barrier() mpi.report('--> chi0_wnr from g_wr') chi0_wnr = chi0r_from_gr_PH(nw=nw, nnu=nwf, gr=g_wr) #mpi.report('--> chi0_wnr from g_wr (nompi)') #chi0_wnr_nompi = chi0r_from_gr_PH_nompi(nw=nw, nnu=nwf, gr=g_wr) del g_wr #abs_diff = np.abs(chi0_wnr.data - chi0_wnr_nompi.data) #mpi.report('shape = ' + str(abs_diff.shape)) #idx = np.argmax(abs_diff) #mpi.report('argmax = ' + str(idx)) #diff = np.max(abs_diff) #mpi.report('diff = %6.6f' % diff) #del chi0_wnr #chi0_wnr = chi0_wnr_nompi #exit() mpi.barrier() mpi.report('chi0_wnr ' + str(chi0_wnr[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) chi0_r0 = np.sum(chi0_wnr[:, :, Idx(0, 0, 0)].data) mpi.report('chi0_r0 ' + str(chi0_r0)) mpi.barrier() mpi.report('--> chi0_wnk from chi0_wnr') chi0_wnk = chi0q_from_chi0r(chi0_wnr) del chi0_wnr mpi.barrier() mpi.report('chi0_wnk ' + str(chi0_wnk[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) chi0 = np.sum(chi0_wnk.data) / len(kmesh) mpi.report('chi0 = ' + str(chi0)) mpi.barrier() #if mpi.is_master_node(): if False: from triqs_tprf.ParameterCollection import ParameterCollection p = ParameterCollection() p.g_wk = g_wk p.g_wr = g_wr p.chi0_wnr = chi0_wnr p.chi0_wnk = chi0_wnk print '--> Writing debug info for BSE' with HDFArchive('data_debug_bse.h5', 'w') as arch: arch['p'] = p mpi.barrier() return chi0_wnk
def solve_lattice_bse(g_wk, gamma_wnn, tail_corr_nwf=None): fmesh_g = g_wk.mesh.components[0] kmesh = g_wk.mesh.components[1] bmesh = gamma_wnn.mesh.components[0] fmesh = gamma_wnn.mesh.components[1] nk = len(kmesh) nw = (len(bmesh) + 1) / 2 nwf = len(fmesh) / 2 nwf_g = len(fmesh_g) / 2 if mpi.is_master_node(): print tprf_banner(), "\n" print 'Lattcie BSE with local vertex approximation.\n' print 'nk =', nk print 'nw =', nw print 'nwf =', nwf print 'nwf_g =', nwf_g print 'tail_corr_nwf =', tail_corr_nwf print if tail_corr_nwf is None: tail_corr_nwf = nwf mpi.report('--> chi0_wnk_tail_corr') chi0_wnk_tail_corr = get_chi0_wnk(g_wk, nw=nw, nwf=tail_corr_nwf) mpi.report('--> trace chi0_wnk_tail_corr (WARNING! NO TAIL FIT. FIXME!)') chi0_wk_tail_corr = chi0q_sum_nu_tail_corr_PH(chi0_wnk_tail_corr) #chi0_wk_tail_corr = chi0q_sum_nu(chi0_wnk_tail_corr) mpi.barrier() mpi.report('B1 ' + str(chi0_wk_tail_corr[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() mpi.report('--> chi0_wnk_tail_corr to chi0_wnk') if tail_corr_nwf != nwf: mpi.report('--> fixed_fermionic_window_python_wnk') chi0_wnk = fixed_fermionic_window_python_wnk(chi0_wnk_tail_corr, nwf=nwf) else: chi0_wnk = chi0_wnk_tail_corr.copy() del chi0_wnk_tail_corr mpi.barrier() mpi.report('C ' + str(chi0_wnk[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() mpi.report('--> trace chi0_wnk') chi0_wk = chi0q_sum_nu(chi0_wnk) mpi.barrier() mpi.report('D ' + str(chi0_wk[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() dchi_wk = chi0_wk_tail_corr - chi0_wk chi0_kw = Gf(mesh=MeshProduct(kmesh, bmesh), target_shape=chi0_wk_tail_corr.target_shape) chi0_kw.data[:] = chi0_wk_tail_corr.data.swapaxes(0, 1) del chi0_wk del chi0_wk_tail_corr assert (chi0_wnk.mesh.components[0] == bmesh) assert (chi0_wnk.mesh.components[1] == fmesh) assert (chi0_wnk.mesh.components[2] == kmesh) # -- Lattice BSE calc with built in trace mpi.report('--> chi_kw from BSE') #mpi.report('DEBUG BSE INACTIVE'*72) chi_kw = chiq_sum_nu_from_chi0q_and_gamma_PH(chi0_wnk, gamma_wnn) #chi_kw = chi0_kw.copy() mpi.barrier() mpi.report('--> chi_kw from BSE (done)') del chi0_wnk mpi.report('--> chi_kw tail corrected (using chi0_wnk)') for k in kmesh: chi_kw[ k, :] += dchi_wk[:, k] # -- account for high freq of chi_0 (better than nothing) del dchi_wk mpi.report('--> solve_lattice_bse, done.') return chi_kw, chi0_kw
def solve_lattice_bse(g_wk, gamma_wnn, tail_corr_nwf=None): r""" Compute the generalized lattice susceptibility :math:`\chi_{abcd}(\omega, \mathbf{k})` using the Bethe-Salpeter equation (BSE). Parameters ---------- g_wk : Single-particle Green's function :math:`G_{ab}(\omega, \mathbf{k})`. gamma_wnn : Local particle-hole vertex function :math:`\Gamma_{abcd}(\omega, \nu, \nu')` tail_corr_nwf : Number of fermionic freqiencies to use in the tail correction of the sum over fermionic frequencies. Returns ------- chi0_wk : Generalized lattice susceptibility :math:`\chi_{abcd}(\omega, \mathbf{k})` """ fmesh_g = g_wk.mesh.components[0] kmesh = g_wk.mesh.components[1] bmesh = gamma_wnn.mesh.components[0] fmesh = gamma_wnn.mesh.components[1] nk = len(kmesh) nw = (len(bmesh) + 1) / 2 nwf = len(fmesh) / 2 nwf_g = len(fmesh_g) / 2 if mpi.is_master_node(): print tprf_banner(), "\n" print 'Lattcie BSE with local vertex approximation.\n' print 'nk =', nk print 'nw =', nw print 'nwf =', nwf print 'nwf_g =', nwf_g print 'tail_corr_nwf =', tail_corr_nwf print if tail_corr_nwf is None: tail_corr_nwf = nwf mpi.report('--> chi0_wnk_tail_corr') chi0_wnk_tail_corr = get_chi0_wnk(g_wk, nw=nw, nwf=tail_corr_nwf) mpi.report('--> trace chi0_wnk_tail_corr (WARNING! NO TAIL FIT. FIXME!)') chi0_wk_tail_corr = chi0q_sum_nu_tail_corr_PH(chi0_wnk_tail_corr) #chi0_wk_tail_corr = chi0q_sum_nu(chi0_wnk_tail_corr) mpi.barrier() mpi.report('B1 ' + str(chi0_wk_tail_corr[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() mpi.report('--> chi0_wnk_tail_corr to chi0_wnk') if tail_corr_nwf != nwf: mpi.report('--> fixed_fermionic_window_python_wnk') chi0_wnk = fixed_fermionic_window_python_wnk(chi0_wnk_tail_corr, nwf=nwf) else: chi0_wnk = chi0_wnk_tail_corr.copy() del chi0_wnk_tail_corr mpi.barrier() mpi.report('C ' + str(chi0_wnk[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() mpi.report('--> trace chi0_wnk') chi0_wk = chi0q_sum_nu(chi0_wnk) mpi.barrier() mpi.report('D ' + str(chi0_wk[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() dchi_wk = chi0_wk_tail_corr - chi0_wk chi0_kw = Gf(mesh=MeshProduct(kmesh, bmesh), target_shape=chi0_wk_tail_corr.target_shape) chi0_kw.data[:] = chi0_wk_tail_corr.data.swapaxes(0, 1) del chi0_wk del chi0_wk_tail_corr assert (chi0_wnk.mesh.components[0] == bmesh) assert (chi0_wnk.mesh.components[1] == fmesh) assert (chi0_wnk.mesh.components[2] == kmesh) # -- Lattice BSE calc with built in trace mpi.report('--> chi_kw from BSE') #mpi.report('DEBUG BSE INACTIVE'*72) chi_kw = chiq_sum_nu_from_chi0q_and_gamma_PH(chi0_wnk, gamma_wnn) #chi_kw = chi0_kw.copy() mpi.barrier() mpi.report('--> chi_kw from BSE (done)') del chi0_wnk mpi.report('--> chi_kw tail corrected (using chi0_wnk)') for k in kmesh: chi_kw[ k, :] += dchi_wk[:, k] # -- account for high freq of chi_0 (better than nothing) del dchi_wk mpi.report('--> solve_lattice_bse, done.') return chi_kw, chi0_kw
def get_chi0_wnk(g_wk, nw=1, nwf=None): r""" Compute the generalized lattice bubble susceptibility :math:`\chi^{(0)}_{abcd}(\omega, \nu, \mathbf{k})` from the single-particle Green's function :math:`G_{ab}(\omega, \mathbf{k})`. Parameters ---------- g_wk : Single-particle Green's function :math:`G_{ab}(\omega, \mathbf{k})`. nw : Number of bosonic freqiencies in :math:`\chi`. nwf : Number of fermionic freqiencies in :math:`\chi`. Returns ------- chi0_wnk : Generalized lattice bubble susceptibility :math:`\chi^{(0)}_{abcd}(\omega, \nu, \mathbf{k})` """ fmesh = g_wk.mesh.components[0] kmesh = g_wk.mesh.components[1] if nwf is None: nwf = len(fmesh) / 2 mpi.barrier() mpi.report('g_wk ' + str(g_wk[Idx(2), Idx(0, 0, 0)][0, 0])) n = np.sum(g_wk.data) / len(kmesh) mpi.report('n ' + str(n)) mpi.barrier() mpi.report('--> g_wr from g_wk') g_wr = fourier_wk_to_wr(g_wk) mpi.barrier() mpi.report('g_wr ' + str(g_wr[Idx(2), Idx(0, 0, 0)][0, 0])) n_r = np.sum(g_wr.data, axis=0)[0] mpi.report('n_r=0 ' + str(n_r[0, 0])) mpi.barrier() mpi.report('--> chi0_wnr from g_wr') chi0_wnr = chi0r_from_gr_PH(nw=nw, nn=nwf, g_nr=g_wr) #mpi.report('--> chi0_wnr from g_wr (nompi)') #chi0_wnr_nompi = chi0r_from_gr_PH_nompi(nw=nw, nn=nwf, g_wr=g_wr) del g_wr #abs_diff = np.abs(chi0_wnr.data - chi0_wnr_nompi.data) #mpi.report('shape = ' + str(abs_diff.shape)) #idx = np.argmax(abs_diff) #mpi.report('argmax = ' + str(idx)) #diff = np.max(abs_diff) #mpi.report('diff = %6.6f' % diff) #del chi0_wnr #chi0_wnr = chi0_wnr_nompi #exit() mpi.barrier() mpi.report('chi0_wnr ' + str(chi0_wnr[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) chi0_r0 = np.sum(chi0_wnr[:, :, Idx(0, 0, 0)].data) mpi.report('chi0_r0 ' + str(chi0_r0)) mpi.barrier() mpi.report('--> chi0_wnk from chi0_wnr') chi0_wnk = chi0q_from_chi0r(chi0_wnr) del chi0_wnr mpi.barrier() mpi.report('chi0_wnk ' + str(chi0_wnk[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) chi0 = np.sum(chi0_wnk.data) / len(kmesh) mpi.report('chi0 = ' + str(chi0)) mpi.barrier() #if mpi.is_master_node(): if False: from triqs_tprf.ParameterCollection import ParameterCollection p = ParameterCollection() p.g_wk = g_wk p.g_wr = g_wr p.chi0_wnr = chi0_wnr p.chi0_wnk = chi0_wnk print '--> Writing debug info for BSE' with HDFArchive('data_debug_bse.h5', 'w') as arch: arch['p'] = p mpi.barrier() return chi0_wnk
nw = 20 beta = 0.544 from pytriqs.gf import MeshImFreq, Idx wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw) from triqs_tprf.lattice import lattice_dyson_g0_wk g0_wk = lattice_dyson_g0_wk(mu=0., e_k=e_k, mesh=wmesh) from triqs_tprf.lattice_utils import imtime_bubble_chi0_wk chi00_wk = imtime_bubble_chi0_wk(g0_wk, nw=1) print print 'chi0_q0 =\n', chi00_wk[Idx(0), Idx(0, 0, 0)].real.reshape((16, 16)) #print #import itertools #for idxs in itertools.product(range(2), repeat=4): # print idxs, chi00_wk[Idx(0), Idx(0, 0, 0)].real[idxs] chi0_q0_ref = chi0_q0_integral(t, beta) print print 'chi0_q0 =', chi00_wk[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0].real print 'chi0_q0_ref =', chi0_q0_ref print # ---------------------------------------------------------------------- # -- Kanamori interaction
hfr.chi0_SzSz = hfr.bare_response(Sz, Sz) hfr.chi_SzSz = hfr.response(Sz, Sz) #hfr.chi0_k = hfr.compute_chi0_k() np.testing.assert_almost_equal(hr.chi0_SzSz, hfr.chi0_SzSz) np.testing.assert_almost_equal(hr.chi_SzSz, hfr.chi_SzSz) # ------------------------------------------------------------------ # -- Call TPRF chi0_wk bubble calc wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=n_w) g0_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh) chi0_wk = imtime_bubble_chi0_wk(g0_wk, nw=1) chi0_abcd = chi0_wk[Idx(0), Idx(0, 0, 0)].copy() chi0_ab = hr.extract_dens_dens(chi0_abcd) chi0_SzSz = np.einsum('ab,abcd,cd->', Sz, chi0_abcd, Sz) print 'chi0_abcd diff =', np.max(np.abs(chi0_abcd - hfr.chi0_abcd)) np.testing.assert_almost_equal(chi0_abcd, hfr.chi0_abcd, decimal=6) print 'chi0_ab diff =', np.max(np.abs(chi0_ab - hr.chi0_ab)) np.testing.assert_almost_equal(chi0_ab, hr.chi0_ab) np.testing.assert_almost_equal(chi0_SzSz, hr.chi0_SzSz) if False: chi0_k = chi0_wk[Idx(0), :] np.set_printoptions(precision=3,
e_k_interp = e_k_interp(kx, ky, kz) plt.figure() plt.plot(k_plot, e_k_interp, '-') plt.axes().set_xticks(K_plot) plt.axes().set_xticklabels([r'$\Gamma$',r'$X$',r'$M$',r'$\Gamma$']) plt.ylabel(r'$\epsilon(\mathbf{k})$') plt.grid() plt.tight_layout() plt.savefig('figure_e_k_bandpath.pdf') # ------------------------------------------------------------------ chi_k = chi00_wk[Idx(0), :][0, 0, 0, 0] # zero frequency, and scalar chi_k_interp = np.vectorize(lambda kx, ky, kz : chi_k([kx, ky, kz]).real) chi_k_interp = chi_k_interp(kx, ky, kz) plt.figure() plt.plot(k_plot, chi_k_interp, '-') plt.axes().set_xticks(K_plot) plt.axes().set_xticklabels([r'$\Gamma$',r'$X$',r'$M$',r'$\Gamma$']) plt.ylabel(r'$\chi_0(\mathbf{k}, i\omega_n = 0)$') plt.grid() plt.tight_layout() plt.savefig('figure_chi00_k_bandpath.pdf')
# -- Two site super lattice P = np.array([[ 2 ]]) Units_prim = np.array(t_r_prim.Units) print 'Units_prim =\n', Units_prim Units = np.dot(P, Units_prim) print 'Units =\n', Units t_r = TBSuperLattice(t_r_prim, P) t_r.bz = BrillouinZone(t_r.bl) e_k = t_r.on_mesh_brillouin_zone(n_k) print e_k.target_shape print 'eps(k=0) =\n', e_k[Idx(0, 0, 0)] # -- Local double occ and spin operators gf_struct = [[0, [0, 1, 2, 3]]] docc = n(0, 0) * n(0, 2) + n(0, 1) * n(0, 3) print 'docc =', docc sigma_x = 0.5 * np.rot90(np.diag([1., 1.])) sigma_y = 0.5 * np.rot90(np.diag([1.j, -1.j])) sigma_z = 0.5 * np.diag([1., -1.]) print 'sigma_x =\n', sigma_x print 'sigma_y =\n', sigma_y
def make_calc(): # ------------------------------------------------------------------ # -- Read precomputed ED data filename = "bse_and_rpa_loc_vs_latt.tar.gz" p = read_TarGZ_HDFArchive(filename)['p'] # ------------------------------------------------------------------ # -- RPA tensor from triqs_tprf.rpa_tensor import get_rpa_tensor from triqs_tprf.rpa_tensor import fundamental_operators_from_gf_struct fundamental_operators = fundamental_operators_from_gf_struct(p.gf_struct) p.U_abcd = get_rpa_tensor(p.H_int, fundamental_operators) # ------------------------------------------------------------------ # -- Generalized PH susceptibility loc_bse = ParameterCollection() loc_bse.chi_wnn = chi_from_gg2_PH(p.G_iw, p.G2_iw_ph) loc_bse.chi0_wnn = chi0_from_gg2_PH(p.G_iw, p.G2_iw_ph) loc_bse.gamma_wnn = inverse_PH(loc_bse.chi0_wnn) - inverse_PH( loc_bse.chi_wnn) loc_bse.chi_wnn_ref = inverse_PH( inverse_PH(loc_bse.chi0_wnn) - loc_bse.gamma_wnn) np.testing.assert_array_almost_equal(loc_bse.chi_wnn.data, loc_bse.chi_wnn_ref.data) from triqs_tprf.bse import solve_local_bse loc_bse.gamma_wnn_ref = solve_local_bse(loc_bse.chi0_wnn, loc_bse.chi_wnn) np.testing.assert_array_almost_equal(loc_bse.gamma_wnn.data, loc_bse.gamma_wnn_ref.data) loc_bse.chi0_w = trace_nn(loc_bse.chi0_wnn) loc_bse.chi_w = trace_nn(loc_bse.chi_wnn) # ------------------------------------------------------------------ # -- RPA, using BSE inverses and constant Gamma loc_rpa = ParameterCollection() loc_rpa.chi0_wnn = loc_bse.chi0_wnn loc_rpa.chi0_w = loc_bse.chi0_w loc_rpa.U_abcd = p.U_abcd # -- Build constant gamma from triqs_tprf.rpa_tensor import get_gamma_rpa loc_rpa.gamma_wnn = get_gamma_rpa(loc_rpa.chi0_wnn, loc_rpa.U_abcd) # -- Solve RPA loc_rpa.chi_wnn = inverse_PH( inverse_PH(loc_rpa.chi0_wnn) - loc_rpa.gamma_wnn) loc_rpa.chi_w = trace_nn(loc_rpa.chi_wnn) # ------------------------------------------------------------------ # -- Bubble RPA on lattice lat_rpa = ParameterCollection() # -- Setup dummy lattice Green's function equal to local Green's function bz = BrillouinZone( BravaisLattice(units=np.eye(3), orbital_positions=[(0, 0, 0)])) periodization_matrix = np.diag(np.array(list([1] * 3), dtype=np.int32)) kmesh = MeshBrillouinZone(bz, periodization_matrix) wmesh = MeshImFreq(beta=p.beta, S='Fermion', n_max=p.nwf_gf) lat_rpa.g_wk = Gf(mesh=MeshProduct(wmesh, kmesh), target_shape=p.G_iw.target_shape) lat_rpa.g_wk[:, Idx(0, 0, 0)] = p.G_iw # -- chi0_wk bubble and chi_wk_rpa bubble RPA from triqs_tprf.lattice_utils import imtime_bubble_chi0_wk lat_rpa.chi0_wk = imtime_bubble_chi0_wk(lat_rpa.g_wk, nw=1) from triqs_tprf.lattice import solve_rpa_PH lat_rpa.chi_wk = solve_rpa_PH(lat_rpa.chi0_wk, p.U_abcd) lat_rpa.chi0_w = lat_rpa.chi0_wk[:, Idx(0, 0, 0)] lat_rpa.chi_w = lat_rpa.chi_wk[:, Idx(0, 0, 0)] print '--> cf Tr[chi0] and chi0_wk' print loc_rpa.chi0_w.data.reshape((4, 4)).real print lat_rpa.chi0_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi0_w.data, lat_rpa.chi0_w.data, decimal=2) print 'ok!' print '--> cf Tr[chi_rpa] and chi_wk_rpa' print loc_rpa.chi_w.data.reshape((4, 4)).real print lat_rpa.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi_w.data, lat_rpa.chi_w.data, decimal=2) print 'ok!' # ------------------------------------------------------------------ # -- Lattice BSE lat_bse = ParameterCollection() lat_bse.g_wk = lat_rpa.g_wk lat_bse.mu = p.mu lat_bse.e_k = Gf(mesh=kmesh, target_shape=p.G_iw.target_shape) lat_bse.e_k[Idx(0, 0, 0)] = np.eye(2) lat_bse.sigma_w = p.G_iw.copy() lat_bse.sigma_w << iOmega_n + lat_bse.mu * np.eye(2) - lat_bse.e_k[Idx( 0, 0, 0)] - inverse(p.G_iw) lat_bse.g_wk_ref = lat_bse.g_wk.copy() lat_bse.g_wk_ref[:, Idx(0, 0, 0)] << inverse(iOmega_n + lat_bse.mu * np.eye(2) - lat_bse.e_k[Idx(0, 0, 0)] - lat_bse.sigma_w) np.testing.assert_array_almost_equal(lat_bse.g_wk.data, lat_bse.g_wk_ref.data) #for w in lat_bse.g_wk.mesh.components[0]: # print w, lat_bse.g_wk[w, Idx(0,0,0)][0, 0] from triqs_tprf.lattice import fourier_wk_to_wr lat_bse.g_wr = fourier_wk_to_wr(lat_bse.g_wk) from triqs_tprf.lattice import chi0r_from_gr_PH lat_bse.chi0_wnr = chi0r_from_gr_PH(nw=1, nn=p.nwf, g_nr=lat_bse.g_wr) from triqs_tprf.lattice import chi0q_from_chi0r lat_bse.chi0_wnk = chi0q_from_chi0r(lat_bse.chi0_wnr) #for n in lat_bse.chi0_wnk.mesh.components[1]: # print n.value, lat_bse.chi0_wnk[Idx(0), n, Idx(0,0,0)][0,0,0,0] # -- Lattice BSE calc from triqs_tprf.lattice import chiq_from_chi0q_and_gamma_PH lat_bse.chi_kwnn = chiq_from_chi0q_and_gamma_PH(lat_bse.chi0_wnk, loc_bse.gamma_wnn) # -- Lattice BSE calc with built in trace from triqs_tprf.lattice import chiq_sum_nu_from_chi0q_and_gamma_PH lat_bse.chi_kw_ref = chiq_sum_nu_from_chi0q_and_gamma_PH( lat_bse.chi0_wnk, loc_bse.gamma_wnn) # -- Lattice BSE calc with built in trace using g_wk from triqs_tprf.lattice import chiq_sum_nu_from_g_wk_and_gamma_PH lat_bse.chi_kw_tail_corr_ref = chiq_sum_nu_from_g_wk_and_gamma_PH( lat_bse.g_wk, loc_bse.gamma_wnn) # -- Trace results from triqs_tprf.lattice import chi0q_sum_nu_tail_corr_PH from triqs_tprf.lattice import chi0q_sum_nu lat_bse.chi0_wk_tail_corr = chi0q_sum_nu_tail_corr_PH(lat_bse.chi0_wnk) lat_bse.chi0_wk = chi0q_sum_nu(lat_bse.chi0_wnk) from triqs_tprf.lattice import chiq_sum_nu, chiq_sum_nu_q lat_bse.chi_kw = chiq_sum_nu(lat_bse.chi_kwnn) np.testing.assert_array_almost_equal(lat_bse.chi_kw.data, lat_bse.chi_kw_ref.data) from triqs_tprf.bse import solve_lattice_bse lat_bse.chi_kw_tail_corr, tmp = solve_lattice_bse(lat_bse.g_wk, loc_bse.gamma_wnn) from triqs_tprf.bse import solve_lattice_bse_e_k_sigma_w lat_bse.chi_kw_tail_corr_new = solve_lattice_bse_e_k_sigma_w( lat_bse.mu, lat_bse.e_k, lat_bse.sigma_w, loc_bse.gamma_wnn) np.testing.assert_array_almost_equal(lat_bse.chi_kw_tail_corr.data, lat_bse.chi_kw_tail_corr_ref.data) np.testing.assert_array_almost_equal(lat_bse.chi_kw_tail_corr.data, lat_bse.chi_kw_tail_corr_new.data) np.testing.assert_array_almost_equal(lat_bse.chi_kw_tail_corr_ref.data, lat_bse.chi_kw_tail_corr_new.data) lat_bse.chi0_w_tail_corr = lat_bse.chi0_wk_tail_corr[:, Idx(0, 0, 0)] lat_bse.chi0_w = lat_bse.chi0_wk[:, Idx(0, 0, 0)] lat_bse.chi_w_tail_corr = lat_bse.chi_kw_tail_corr[Idx(0, 0, 0), :] lat_bse.chi_w = lat_bse.chi_kw[Idx(0, 0, 0), :] print '--> cf Tr[chi0_wnk] and chi0_wk' print lat_bse.chi0_w_tail_corr.data.reshape((4, 4)).real print lat_bse.chi0_w.data.reshape((4, 4)).real print lat_rpa.chi0_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi0_w_tail_corr.data, lat_rpa.chi0_w.data) np.testing.assert_array_almost_equal(lat_bse.chi0_w.data, lat_rpa.chi0_w.data, decimal=2) print 'ok!' print '--> cf Tr[chi_kwnn] and chi_wk (without chi0 tail corr)' print lat_bse.chi_w.data.reshape((4, 4)).real print loc_bse.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi_w.data, loc_bse.chi_w.data) print 'ok!' # ------------------------------------------------------------------ # -- Use chi0 tail corrected trace to correct chi_rpa cf bubble dchi_wk = lat_bse.chi0_wk_tail_corr - lat_bse.chi0_wk dchi_w = dchi_wk[:, Idx(0, 0, 0)] loc_rpa.chi_w_tail_corr = loc_rpa.chi_w + dchi_w # -- this will be the same, but it will be close to the real physical value lat_bse.chi_w_tail_corr_ref = lat_bse.chi_w + dchi_w loc_bse.chi_w_tail_corr_ref = loc_bse.chi_w + dchi_w print '--> cf Tr[chi_rpa] and chi_wk_rpa' print loc_rpa.chi_w.data.reshape((4, 4)).real print loc_rpa.chi_w_tail_corr.data.reshape((4, 4)).real print lat_rpa.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi_w_tail_corr.data, lat_rpa.chi_w.data, decimal=3) print '--> cf Tr[chi_kwnn] with tail corr (from chi0_wnk)' print lat_bse.chi_w_tail_corr.data.reshape((4, 4)).real print lat_bse.chi_w_tail_corr_ref.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi_w_tail_corr.data, lat_bse.chi_w_tail_corr_ref.data) print 'ok!' # ------------------------------------------------------------------ # -- Store to hdf5 filename = 'data_bse_rpa.h5' with HDFArchive(filename, 'w') as res: res['p'] = p
n = rho[0, 0] + rho[1, 1] m = 0.5 * (rho[0, 0] - rho[1, 1]) print 'n, m =', n, m E_tot = E_kin - U * (n**2 / 4 - m**2) print 'E_tot =', E_tot np.testing.assert_almost_equal(E_tot_ref, E_tot, decimal=6) # ------------------------------------------------------------------ # -- Lattice chi0 print '--> chi00_wk' chi00_wk = imtime_bubble_chi0_wk(g0_wk, nw=1) print 'chi0_q0 =\n', chi00_wk[Idx(0), Idx(0, 0, 0)].real.reshape((4, 4)) print '--> lindhard_chi00_wk' chi00_wk_analytic = lindhard_chi00_wk(e_k=e_k, nw=1, beta=beta, mu=mu) print 'chi0_q0_analytic =\n', chi00_wk_analytic[Idx(0), Idx(0, 0, 0)].real.reshape( (4, 4)) np.testing.assert_almost_equal(chi00_wk.data, chi00_wk_analytic.data, decimal=5) chi0_q0_ref = chi0_q0_integral(t, beta) print 'chi0_q0 =', chi00_wk[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0].real print 'chi0_q0_ref =', chi0_q0_ref
def Idxs(integer_index_list): from pytriqs.gf import Idx return tuple(Idx(i) for i in integer_index_list)