Example #1
0
def create_random_gamma_wnn(p):
    wmesh_gamma = MeshImFreq(beta=p.beta, S="Boson", n_max=p.nw_gamma)
    nmesh_gamma = MeshImFreq(beta=p.beta, S="Fermion", n_max=p.nwf)

    gamma_wnn = Gf(
        mesh=MeshProduct(wmesh_gamma, nmesh_gamma, nmesh_gamma),
        target_shape=2 * g0_wk.target_shape,
    )

    np.random.seed(p.seed)
    gamma_wnn.data[:] = np.random.rand(*gamma_wnn.data.shape)

    return gamma_wnn
Example #2
0
File: bse.py Project: TRIQS/tprf
def fixed_fermionic_window_python_wnk(chi_wnk, nwf):
    r""" Helper routine to reduce the number of fermionic Matsubara 
    frequencies :math:`\nu` in a two frequency and one momenta dependent
    generalized susceptibility :math:`\chi_{abcd}(\omega, \nu, \mathbf{k})`.

    Parameters
    ----------

    chi_wnk : two frequency and one momenta dependent generalized 
              susceptibility :math:`\chi_{abcd}(\omega, \nu, \mathbf{k})`.
    nwf : number of fermionic frequencies to keep.

    Returns
    -------

    chi_wnk_out : Susceptibility with reduced number of fermionic Matsubara
                  frequencies.
    """

    g2 = chi_wnk
    wmesh, nmesh, kmesh = g2.mesh.components

    beta = g2.mesh.components[0].beta
    nmesh_small = MeshImFreq(beta=beta, S='Fermion', n_max=nwf)

    chi_wnk_out = Gf(mesh=MeshProduct(wmesh, nmesh_small, kmesh),
                     target_shape=g2.target_shape)

    n = g2.data.shape[1]
    s = n // 2 - nwf
    e = n // 2 + nwf

    chi_wnk_out.data[:] = g2.data[:, s:e, :]

    return chi_wnk_out
Example #3
0
def setup_dmft_calculation(p):

    p = copy.deepcopy(p)
    p.iter = 0

    # -- Local Hubbard interaction
    from triqs.operators import n
    p.solve.h_int = p.U * n('up', 0) * n(
        'do', 0) - 0.5 * p.U * (n('up', 0) + n('do', 0))

    # -- 2D square lattice w. nearest neighbour hopping t
    from triqs_tprf.tight_binding import TBLattice
    T = -p.t * np.eye(2)
    H = TBLattice(units=[(1, 0, 0), (0, 1, 0)],
                  orbital_positions=[(0, 0, 0)] * 2,
                  orbital_names=['up', 'do'],
                  hopping={
                      (0, +1): T,
                      (0, -1): T,
                      (+1, 0): T,
                      (-1, 0): T
                  })

    kmesh = H.get_kmesh(n_k=(p.n_k, p.n_k, 1))
    p.e_k = H.fourier(kmesh)

    # -- Initial zero guess for the self-energy
    p.sigma_w = Gf(mesh=MeshImFreq(p.init.beta, 'Fermion', p.init.n_iw),
                   target_shape=[2, 2])
    p.sigma_w.zero()

    return p
Example #4
0
def test_add_fake_bosonic_mesh_with_gf_nk(bzmesh):
    nmesh = MeshImFreq(beta=1, S="Fermion", n_max=1)

    gf_nk = Gf(mesh=MeshProduct(nmesh, bzmesh), target_shape=(2, 2))
    gf_wnk = add_fake_bosonic_mesh(gf_nk)

    np.testing.assert_allclose(gf_nk.data, gf_wnk[Idx(0), :, :].data)
Example #5
0
def create_eliashberg_ingredients(p):
    H = create_model_for_tests(**p)
    kmesh = H.get_kmesh(n_k=[p.nk] * p.dim + [1] * (3 - p.dim))
    e_k = H.fourier(kmesh)

    wmesh = MeshImFreq(beta=p.beta, S="Fermion", n_max=p.nw)
    g0_wk = lattice_dyson_g0_wk(mu=p.mu, e_k=e_k, mesh=wmesh)

    chi0_wk = imtime_bubble_chi0_wk(g0_wk, nw=p.nw)

    U_d, U_m = kanamori_charge_and_spin_quartic_interaction_tensors(
        p.norb, p.U, p.Up, p.J, p.Jp)

    chi_d = solve_rpa_PH(chi0_wk, U_d)
    chi_m = solve_rpa_PH(chi0_wk,
                         -U_m)  # Minus for correct charge rpa equation

    phi_d_wk = construct_phi_wk(chi_d, U_d)
    phi_m_wk = construct_phi_wk(chi_m, U_m)

    gamma = construct_gamma_singlet_rpa(U_d, U_m, phi_d_wk, phi_m_wk)

    eliashberg_ingredients = ParameterCollection(
        g0_wk=g0_wk,
        gamma=gamma,
        U_m=U_m,
        U_d=U_d,
        chi_m=chi_m,
        chi_d=chi_d,
    )
    return eliashberg_ingredients
Example #6
0
def w2dyn_ndarray_to_triqs_BlockGF_iw_beta_niw(giw, n_iw, beta, gf_struct):
    """ Convert a W2Dynamics ndarray format with indices [wosos] or [wff]
    where t is time, o is orbital, s is spin index, f is flavour
    to a block Triqs Matsubara response function 

    Takes: 
    giw  : Green function as numpy array
    beta : inverse temperature
    niw : number of Matsubaras
    gf_struct: desired block structure of triqs GF

    Returns: 
    BlockGF : triqs block Green function the response function data

    Author: Hugo U. R. Strand (2019) """

    ### check number of Matsubaras is correct and as last dimension
    ### the variable n_iw has only positive Matsubaras, the objects
    ### have both negative and positive
    n_iw_check = giw.shape[-1] / 2
    assert n_iw_check == n_iw

    ### check if giw is 3 or 5 dimensional, and make it 3 dimensional
    if len(giw.shape) == 5:
        norbs = giw.shape[0]
        nspin = giw.shape[1]
        nflavour = norbs * nspin
        giw = giw.reshape(nflavour, nflavour, 2 * n_iw)
    elif len(giw.shape) == 3:
        nflavour = giw.shape[0]
    else:
        raise Exception(
            "giw array must be 3 or 5 dimensional with iw as last dimension!")

    ### generate triqs Green function with same dimension than
    ### the input; this may not be a good idea if worm is used
    ### since then the output can have another structure...
    from triqs.gf import MeshImFreq, BlockGf
    iw_mesh = MeshImFreq(beta, 'Fermion', n_iw)
    G_iw = BlockGf(mesh=iw_mesh, gf_struct=gf_struct)

    ### read out blocks from full w2dyn matrices
    offset = 0
    for name, g_iw in G_iw:

        size1 = G_iw[name].data.shape[-1]
        size2 = G_iw[name].data.shape[-2]
        assert (size1 == size2)
        size_block = size1
        giw_block = giw[offset:offset + size_block,
                        offset:offset + size_block, :]
        g_iw.data[:] = giw_block.transpose(2, 0, 1)

        offset += size_block

    return G_iw
Example #7
0
def solve_lattice_bse(parm, momsus=False):

    print('--> solve_lattice_bse')

    print('nw =', parm.nw)
    print('nwf =', parm.nwf)
    
    # ------------------------------------------------------------------
    # -- Setup lattice

    bl = BravaisLattice([(1,0,0), (0,1,0)])

    bz = BrillouinZone(bl)    
    bzmesh = MeshBrZone(bz, n_k=1) # only one k-point
    
    e_k = Gf(mesh=bzmesh, target_shape=[1, 1])
    e_k *= 0.
          
    # ------------------------------------------------------------------
    # -- Lattice single-particle Green's function

    mesh = MeshImFreq(beta=parm.beta, S='Fermion', n_max=parm.nwf_gf)

    parm.Sigma_iw = parm.G_iw.copy()
    G0_iw = parm.G_iw.copy()

    G0_iw << inverse(iOmega_n + 0.5*parm.U)
    parm.Sigma_iw << inverse(G0_iw) - inverse(parm.G_iw)
    
    parm.mu = 0.5*parm.U
    g_wk = lattice_dyson_g_wk(mu=parm.mu, e_k=e_k, sigma_w=parm.Sigma_iw)
    g_wr = fourier_wk_to_wr(g_wk)

    # ------------------------------------------------------------------
    # -- Non-interacting generalized lattice susceptibility

    chi0_wr = chi0r_from_gr_PH(nw=parm.nw, nnu=parm.nwf, gr=g_wr) 
    chi0_wk = chi0q_from_chi0r(chi0_wr)

    # ------------------------------------------------------------------
    # -- Solve lattice BSE

    parm.chi_wk = chiq_from_chi0q_and_gamma_PH(chi0_wk, parm.gamma_m)

    # ------------------------------------------------------------------
    # -- Store results and static results
    
    num = np.squeeze(parm.chi_wk.data.real)
    ref = np.squeeze(parm.chi_m.data.real)
    
    diff = np.max(np.abs(num - ref))
    print('diff =', diff)
    
    parm.chi_w = chiq_sum_nu_q(parm.chi_wk) # static suscept
    
    return parm
Example #8
0
def create_g0_wk_for_test_model(p):
    H = create_model_for_tests(**p)

    kmesh = H.get_kmesh(n_k=[p.nk] * p.dim + [1] * (3 - p.dim))
    e_k = H.fourier(kmesh)

    wmesh = MeshImFreq(beta=p.beta, S="Fermion", n_max=p.nw)
    g0_wk = lattice_dyson_g0_wk(mu=p.mu, e_k=e_k, mesh=wmesh)

    return g0_wk
Example #9
0
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 triqs.plot.mpl_interface import oplot, plt
        oplot(p.Sigmalatt_iw)
        oplot(sigma, 'x')
        plt.show()
        exit()

    return sigma
Example #10
0
def G2_loc_fixed_fermionic_window_python(g2, nwf):
    """ Limit the last two fermionic freqiencies of a three
    frequency Green's function object :math:`G(\omega, \nu, \nu')`
    to ``nwf``. """

    nw = (g2.data.shape[0] + 1) // 2
    n = g2.data.shape[1]
    beta = g2.mesh.components[0].beta

    assert (n // 2 >= nwf)

    mesh_iw = MeshImFreq(beta=beta, S='Boson', n_max=nw)
    mesh_inu = MeshImFreq(beta=beta, S='Fermion', n_max=nwf)
    mesh_prod = MeshProduct(mesh_iw, mesh_inu, mesh_inu)

    g2_out = Gf(mesh=mesh_prod, target_shape=g2.target_shape)

    s = n // 2 - nwf
    e = n // 2 + nwf

    g2_out.data[:] = g2.data[:, s:e, s:e]
    return g2_out
Example #11
0
def bubble_setup(beta, mu, tb_lattice, nk, nw, sigma_w=None):

    print((tprf_banner(), "\n"))

    print(('beta  =', beta))
    print(('mu    =', mu))
    print(('sigma =', (not (sigma == None))))

    norb = tb_lattice.NOrbitalsInUnitCell
    print(('nk    =', nk))
    print(('nw    =', nw))
    print(('norb  =', norb))
    print()

    ntau = 4 * nw
    ntot = np.prod(nk) * norb**4 + np.prod(nk) * (nw + ntau) * norb**2
    nbytes = ntot * np.complex128().nbytes
    ngb = nbytes / 1024.**3
    print(('Approx. Memory Utilization: %2.2f GB\n' % ngb))

    periodization_matrix = np.diag(np.array(list(nk), dtype=int))
    #print 'periodization_matrix =\n', periodization_matrix

    bz = BrillouinZone(tb_lattice.bl)
    bzmesh = MeshBrZone(bz, periodization_matrix)

    print('--> ek')
    e_k = ek_tb_dispersion_on_bzmesh(tb_lattice, bzmesh, bz)

    if sigma is None:
        print('--> g0k')
        wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw)
        g_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh)
    else:
        print('--> gk')
        sigma_w = strip_sigma(nw, beta, sigma)
        g_wk = lattice_dyson_g_wk(mu=mu, e_k=e_k, sigma_w=sigma_w)

    print('--> gr_from_gk (k->r)')
    g_wr = fourier_wk_to_wr(g_wk)
    del g_wk

    print('--> grt_from_grw (w->tau)')
    g_tr = fourier_wr_to_tr(g_wr)
    del g_wr

    if sigma is None:
        return g_tr
    else:
        return g_tr, sigma_w
Example #12
0
def delta_inv(beta, nw, nk=100):

    mesh = MeshImFreq(beta, 'Fermion', n_max=nw)

    Sigma0, Sigma1 = 1.337, 3.5235
    ek = 2.*np.random.random(nk) - 1.

    G = Gf(mesh=mesh, target_shape=[1, 1])
    Sig = G.copy()
    for w in Sig.mesh:
        Sig[w][:] = Sigma0 + Sigma1 /w
 
    for e in ek: G << G + inverse(iOmega_n - e - Sig)

    G /= nk

    Delta = G.copy()
    Delta << inverse(G) - iOmega_n + Sig

    sum_ek = - np.sum(ek) / nk

    Roo = np.abs(Sigma0) + 1.

    w = [ w for w in mesh ]
    wmax = np.abs(w[-1].value)

    tail, err = Delta.fit_tail()

    order = len(tail)

    trunc_err_anal = (Roo / (0.8 * wmax))**order

    ratio = tail[0] / sum_ek
    diff = np.abs(1 - ratio)

    print('-' * 72)
    print('beta =', beta)
    print('nw =', nw)
    print('wmax =', wmax)
    print('tail_fit order =', len(tail))
    print('tail_fit err =', err)
    print(tail[:3])
    #print sum_ek
    print('trunc_err_anal =', trunc_err_anal)
    print('ratio =', ratio)
    print('diff =', diff)

    return diff[0, 0]
Example #13
0
    def test_sumk_discrete(self):
        tbl_w90 = TB_from_wannier90(seed='wannier_TB_test',
                                    path='./',
                                    extend_to_spin=False)

        SK = SumkDiscreteFromLattice(lattice=tbl_w90, n_points=10)
        Sigma_proto = GfImFreq(
            mesh=MeshImFreq(beta=40, S='Fermion', n_max=1025),
            target_shape=[tbl_w90.n_orbitals, tbl_w90.n_orbitals])
        Sigma_iw = BlockGf(name_list=['up', 'down'],
                           block_list=[Sigma_proto, Sigma_proto],
                           make_copies=True)

        # Sumk only accepts Sigma of MeshImFreq
        Gloc = SK(Sigma=Sigma_iw, mu=12.3461)
        # check if density is close to 1, not to strict since nkpts is relatively small
        assert abs(Gloc.total_density().real - 1.0) < 1e-2
Example #14
0
    def __init__(self,
                 beta,
                 gf_struct,
                 n_iw=1025,
                 n_tau=10001,
                 n_l=30,
                 delta_interface=False,
                 complex=False):
        """Constructor setting up response function parameters

        Arguments:
        beta : inverse temperature
        gf_struct : Triqs Green's function block structure
        n_iw : number of Matsubara frequencies
        n_tau : number of imaginary time points
        """

        self.constr_params = {
            "beta": beta,
            "gf_struct": gf_struct,
            "n_iw": n_iw,
            "n_tau": n_tau,
            "n_l": n_l,
            "delta_interface": delta_interface
        }

        self.beta = beta
        self.gf_struct = gf_struct
        self.n_iw = n_iw
        self.n_tau = n_tau
        self.n_l = n_l
        self.delta_interface = delta_interface
        self.complex = complex

        self.tau_mesh = MeshImTime(beta, 'Fermion', n_tau)
        self.iw_mesh = MeshImFreq(beta, 'Fermion', n_iw)

        if self.delta_interface:
            self.Delta_tau = BlockGf(mesh=self.tau_mesh,
                                     gf_struct=self.gf_struct)
        else:
            self.G0_iw = BlockGf(mesh=self.iw_mesh, gf_struct=gf_struct)
Example #15
0
def add_fake_bosonic_mesh(gf, beta=None):
    """ Put a one value bosonic mesh as the first mesh argument of a 
    Green's function object.

    Parameters
    ----------
    gf : Gf,
         Green's function on some arbitrary mesh. If 'beta' is not given
         one mesh needs to be a 'MeshImFreq' to obtain a beta'
    beta : float, optional
           The inverse temperature used for the fake bosonic mesh.

    Returns
    -------
    gf_w : Gf,
           Green's function with an additional one value bosonic mesh
           on its first position.
    """
    mesh = gf.mesh
    if isinstance(mesh, MeshProduct):
        meshes = mesh.components
    else:
        meshes = (mesh, )

    # If beta is not given access it from a 'MeshImFreq' of the 'Gf'
    if not beta:
        betas = [mesh.beta for mesh in meshes if hasattr(mesh, "beta")]
        if len(betas) == 0:
            raise ValueError(
                "No 'beta' was given and the Green's function does not contain"
                " a 'MeshImFreq'")
        beta = betas[0]

    wmesh = MeshImFreq(beta, 'Boson', 1)
    mesh = (wmesh, ) + meshes
    mesh = MeshProduct(*mesh)

    gf_w = Gf(mesh=mesh, target_shape=gf.target_shape)
    gf_w.data[0, ...] = gf.data

    return gf_w
Example #16
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You may obtain a copy of the License at
#     https:#www.gnu.org/licenses/gpl-3.0.txt
#
# Authors: Alexander Hampel, Nils Wentzell

import numpy as np
from triqs.gf import MeshImFreq, MeshImTime
from triqs.gf.tools import discretize_bath, make_delta
from triqs.utility.comparison_tests import assert_gfs_are_close

# build delta from discretized values
mesh = MeshImFreq(beta=40, S='Fermion', n_max=200)

hoppings = np.array([[0.2, 0.6]])
energies = np.array([0.0, 0.5])

delta_iw = make_delta(V=hoppings, eps=energies, mesh=mesh)

# run bath fitter on this input
V_opt, e_opt, delta_disc_iw = discretize_bath(delta_in=delta_iw, Nb=2, eps0=2.5, V0=None, tol=1e-10)
# compare to given values , resulting V can be correct up to a global sign
assert np.max(np.abs(hoppings) - np.abs(V_opt)) < 1e-6, 'did not achieved requiered accuracy for bath fit \n'+str(V_opt)+' vs \n'+str(hoppings)
assert np.max(np.abs(energies - e_opt)) < 1e-6, 'did not achieved requiered accuracy for bath fit \n'+str(e_opt)+' vs \n'+str(energies)
assert_gfs_are_close(delta_disc_iw, delta_iw)

#try with Nb % n_orb != 0
V_opt, e_opt, delta_disc_iw = discretize_bath(delta_in=delta_iw, Nb=3, eps0=2.5, V0=None, tol=1e-10)
Example #17
0
    p.diag = 0.5 + p.delta
    p.odiag = 0.5 - p.delta
    p.solve.alpha = [[[p.diag, p.odiag] for i in indices]
                     for bl, indices in p.gf_struct]

    # -- Total impurity hamiltonian and interaction part

    p.H_0 = -p.mu * (n('up', 0) + n('dn', 0)) - p.h * (n('up', 0) - n('dn', 0))
    p.H_int = p.U * n('up', 0) * n('dn', 0)
    p.H = p.H_0 + p.H_int
    p.solve.h_int = p.H_int

    # -- Non-Interacting Impurity Green function

    iw_mesh = MeshImFreq(p.beta, 'Fermion', p.n_iw)
    p.G0_iw = Gf_from_struct(mesh=iw_mesh, struct=p.gf_struct)

    h_field_dict = dict(up=p.h, dn=-p.h)
    for name, g0_iw in p.G0_iw:
        h_field = h_field_dict[name]
        g0_iw << inverse(iOmega_n + p.mu + h_field)

    # -- CTINT

    S = SolverCore(**p.solver_core.dict())
    S.G0_iw << p.G0_iw
    S.solve(**p.solve.dict())

    # -- Store to hdf5 archive
Example #18
0
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=int))
    kmesh = MeshBrZone(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
        -t_intra * np.eye(n_orb_spin) - t_inter * inter_orbital_hopping,
    },
    orbital_positions=[(0, 0, 0)] * n_orb_spin,
)

kmesh = H.get_kmesh(n_k=(16, 16, 1))
e_k = H.fourier(kmesh)
print(e_k)

# ----------------------------------------------------------------------
# -- Bare susceptibility from Green's function bubble

from triqs.gf import MeshImFreq
from triqs_tprf.lattice import lattice_dyson_g0_wk

wmesh = MeshImFreq(beta=5.0, S='Fermion', n_max=30)
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)

# ----------------------------------------------------------------------
# -- Kanamori interaction

from triqs.operators.util import U_matrix_kanamori, h_int_kanamori
from triqs_tprf.OperatorUtils import fundamental_operators_from_gf_struct
from triqs_tprf.rpa_tensor import get_rpa_tensor

U = 1.0
J = 0.1
Example #20
0
def mesh_product_iterator_numpy(mesh):
    return [
        list(map(np.array, list(zip(*list(x)))))
        for x in mesh_product_iterator(chi4_tau.mesh)
    ]


# ----------------------------------------------------------------------
if __name__ == '__main__':

    nw = 20
    nt = 45
    beta = 2.0

    imtime = MeshImTime(beta, 'Fermion', nt)
    imfreq = MeshImFreq(beta, 'Fermion', nw)

    imtime3 = MeshProduct(imtime, imtime, imtime)
    imfreq3 = MeshProduct(imfreq, imfreq, imfreq)

    chi4_tau = Gf(name=r'$g(\tau)$', mesh=imtime3, target_shape=[1, 1, 1, 1])

    print(dir(chi4_tau.indices))
    for i in chi4_tau.indices:
        print(i)
    exit()

    # -- Smooth anti-periodic function
    w = 0.5
    e1, e2, e3 = w, w, w
    E = np.array([e1, e2, e3])
Example #21
0
    print('E_kin_ref =', E_kin_ref)

    E_tot_ref = get_total_energy_mf_ref(t, beta, U, mu, n, m)
    print('E_tot_ref =', E_tot_ref)

    print('--> tight binding model')
    t_r = get_tb_model(t, U, n, m, mu=0.)

    print('--> dispersion e_k')
    kmesh = t_r.get_kmesh(n_k)
    e_k = t_r.fourier(kmesh)

    #print e_k.data

    print('--> lattice g0_wk')
    wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw)
    g0_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh)

    E_kin = get_kinetic_energy(e_k, g0_wk)
    print('E_kin =', E_kin)

    np.testing.assert_almost_equal(E_kin_ref, E_kin, decimal=6)

    rho = get_density_matrix(g0_wk)
    print('rho =\n', rho)

    n = rho[0, 0] + rho[1, 1]
    m = 0.5 * (rho[0, 0] - rho[1, 1])

    print('n, m =', n, m)
Example #22
0
nnu = 100

# -- BZ-sampling

bz = BrillouinZone(BravaisLattice([[1, 0], [0, 1]]))
bzmesh = MeshBrZone(bz, n_k=n_k)
q_list = [q for q in bzmesh]

# -- Dispersion

ek = Gf(mesh=bzmesh, target_shape=[1, 1])
for idx, k in enumerate(bzmesh):
    #ek[k] = -2*t*(np.cos(k[0]) + np.cos(k[1])) # does not work...
    ek.data[idx] = -2 * (np.cos(k[0]) + np.cos(k[1]))

mesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw_g)
bmesh = MeshImFreq(beta=beta, S='Boson', n_max=nw)

iw_list = np.array([iw for iw in bmesh])
iw_zero_idx = np.where(iw_list == 0)[0][0]

# -- Lattice single-particle Green's function

g0k = g0k_from_ek(mu=mu, ek=ek, mesh=mesh)
g0r = gr_from_gk(g0k)

# -- Non-interacting generalized lattice susceptibility

chi0r = chi0r_from_gr_PH(nw=nw, nnu=nnu, gr=g0r)
chi0q = chi0q_from_chi0r(chi0r, bz)
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 = MeshBrZone(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
Example #24
0
from triqs.gf import Gf, MeshImFreq, MeshBrZone, MeshProduct
from triqs.lattice import BrillouinZone, BravaisLattice
from triqs_tprf.ParameterCollection import *

# ----------------------------------------------------------------------

from triqs_tprf.symmetries import enforce_symmetry, check_symmetry, _invert_momentum

# ----------------------------------------------------------------------

p = ParameterCollection(beta = 10,
                        nw = 10,
                        nk = 4,
                        norb = 2,)

wmesh = MeshImFreq(beta=p.beta, S='Fermion', n_max=p.nw)

cell = np.eye(3)
bl = BravaisLattice(cell)
bz = BrillouinZone(bl)
kmesh = MeshBrZone(bz, p.nk * np.eye(3, dtype=int))

gf = Gf(mesh=MeshProduct(wmesh, kmesh), target_shape=2*(p.norb,))
gf.data[:] = np.random.rand(*gf.data.shape)

# -- Eexception handling
try:
    enforce_symmetry(gf, "something", "odd")
except ValueError as error:
    if not str(error) == "No symmetrize function for this variable exists.":
        raise Exception("Wrong exception was raised: \n %s"%error)
Example #25
0
def test_square_lattice_chi00():

    # ------------------------------------------------------------------
    # -- Discretizations

    n_k = (2, 2, 1)
    nw_g = 500
    nn = 400
    nw = 1

    # ------------------------------------------------------------------
    # -- tight binding parameters

    beta = 20.0
    mu = 0.0
    t = 1.0

    h_loc = np.array([
        [-0.3, -0.5],
        [-0.5, .4],
    ])

    T = -t * np.array([
        [1., 0.23],
        [0.23, 0.5],
    ])

    # ------------------------------------------------------------------
    # -- tight binding

    print('--> tight binding model')
    t_r = TBLattice(
        units=[(1, 0, 0), (0, 1, 0)],
        hopping={
            # nearest neighbour hopping -t
            (0, 0): h_loc,
            (0, +1): T,
            (0, -1): T,
            (+1, 0): T,
            (-1, 0): T,
        },
        orbital_positions=[(0, 0, 0)] * 2,
        orbital_names=['up_0', 'do_0'],
    )

    kmesh = t_r.get_kmesh(n_k)
    e_k = t_r.fourier(kmesh)

    wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw_g)

    print('--> g0_wk')
    g0_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh)

    print('--> g0_wr')
    g0_wr = fourier_wk_to_wr(g0_wk)

    print('--> g0_tr')
    g0_tr = fourier_wr_to_tr(g0_wr)

    # ------------------------------------------------------------------
    # -- anaytic chi00

    print('--> chi00_wk analytic')
    chi00_wk_analytic = lindhard_chi00_wk(e_k=e_k, nw=nw, beta=beta, mu=mu)

    print('--> chi00_wr analytic')
    chi00_wr_analytic = chi_wr_from_chi_wk(chi00_wk_analytic)

    # ------------------------------------------------------------------
    # -- imtime chi00

    print('--> chi0_tr_from_grt_PH')
    chi00_tr = chi0_tr_from_grt_PH(g0_tr)

    print('--> chi_wr_from_chi_tr')
    chi00_wr = chi_wr_from_chi_tr(chi00_tr, nw=1)

    print('--> chi_w0r_from_chi_tr')
    chi00_wr_ref = chi_w0r_from_chi_tr(chi00_tr)

    print('--> chi0_w0r_from_grt_PH')
    chi00_wr_opt = chi0_w0r_from_grt_PH(g0_tr)

    print('dchi00_wr     =',
          np.max(np.abs(chi00_wr_analytic.data - chi00_wr.data)))
    print('dchi00_wr_ref =',
          np.max(np.abs(chi00_wr_analytic.data - chi00_wr_ref.data)))
    print('dchi00_wr_opt =',
          np.max(np.abs(chi00_wr_analytic.data - chi00_wr_opt.data)))

    np.testing.assert_array_almost_equal(chi00_wr_analytic.data,
                                         chi00_wr.data,
                                         decimal=8)

    np.testing.assert_array_almost_equal(chi00_wr_analytic.data,
                                         chi00_wr_ref.data,
                                         decimal=4)

    np.testing.assert_array_almost_equal(chi00_wr_analytic.data,
                                         chi00_wr_opt.data,
                                         decimal=4)

    print('--> chi_wk_from_chi_wr')
    chi00_wk_imtime = chi_wk_from_chi_wr(chi00_wr)

    # ------------------------------------------------------------------
    # -- imtime chi00 helper function

    chi00_wk_imtime_2 = imtime_bubble_chi0_wk(g0_wk, nw=1)

    # ------------------------------------------------------------------
    # -- imfreq chi00

    print('--> chi00_wnr')
    chi00_wnr = chi0r_from_gr_PH(nw=1, nn=nn, g_nr=g0_wr)

    print('--> chi00_wnk')
    chi00_wnk = chi0q_from_chi0r(chi00_wnr)

    # -- Test per k and w calculator for chi0_wnk
    print('--> chi00_wnk_ref')
    from triqs_tprf.lattice import chi0q_from_g_wk_PH
    chi00_wnk_ref = chi0q_from_g_wk_PH(nw=1, nn=nn, g_wk=g0_wk)

    diff = np.max(np.abs(chi00_wnk.data - chi00_wnk_ref.data))
    print('chi00_wnk diff =', diff)
    np.testing.assert_array_almost_equal(chi00_wnk.data, chi00_wnk_ref.data)

    print('--> chi00_wk_imfreq')
    chi00_wk_imfreq = chi0q_sum_nu(chi00_wnk)

    print('--> chi00_wk_imfreq_tail_corr')
    chi00_wk_imfreq_tail_corr = chi0q_sum_nu_tail_corr_PH(chi00_wnk)

    # ------------------------------------------------------------------
    # -- Compare results

    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)

    print('--> Cf analytic with imtime')
    cf_chi_w0(chi00_wk_analytic, chi00_wk_imtime, decimal=7)

    print('--> Cf analytic with imtime 2')
    cf_chi_w0(chi00_wk_analytic, chi00_wk_imtime_2, decimal=4)

    print('--> Cf analytic with imfreq')
    cf_chi_w0(chi00_wk_analytic, chi00_wk_imfreq, decimal=2)

    print('--> Cf analytic with imfreq (tail corr)')
    cf_chi_w0(chi00_wk_analytic, chi00_wk_imfreq_tail_corr, decimal=5)
Example #26
0
File: gw.py Project: TRIQS/tprf
t_r = TBLattice(
    units=[(1, 0, 0)],
    hopping={
        (+1, ): t,
        (-1, ): t,
    },
    orbital_positions=[(0, 0, 0)] * norb,
)

kmesh = t_r.get_kmesh(n_k=(8, 1, 1))
e_k = t_r.fourier(kmesh)

print(e_k.data)

kmesh = e_k.mesh
wmesh = MeshImFreq(beta, 'Fermion', nw)
g_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh)

V_k = Gf(mesh=kmesh, target_shape=[norb] * 4)
V_k.data[:] = V

print('--> pi_bubble')
PI_wk = bubble_PI_wk(g_wk)

print('--> screened_interaction_W')
Wr_wk = retarded_screened_interaction_Wr_wk(PI_wk, V_k)

print('--> gw_self_energy')
sigma_wk = gw_sigma_wk(Wr_wk, g_wk, fft_flag=True)
sigma_wk_ref = gw_sigma_wk(Wr_wk, g_wk, fft_flag=False)
np.testing.assert_array_almost_equal(sigma_wk.data, sigma_wk_ref.data)
h_bath = sum(c_dag_bath_vec[s] * h_bath_mat * c_bath_vec[s]
             for s in spin_names)[0, 0]
h_coup = sum(c_dag_vec[s] * V_mat * c_bath_vec[s] +
             c_dag_bath_vec[s] * V_mat.transpose() * c_vec[s]
             for s in spin_names)[0, 0]  # FIXME Adjoint

# ==== Total impurity hamiltonian ====
h_imp = h_loc + h_coup + h_bath

# ==== Green function structure ====
gf_struct = [[s, orb_names] for s in spin_names]

# ==== Hybridization Function ====
n_iw = int(10 * beta)
iw_mesh = MeshImFreq(beta, 'Fermion', n_iw)
Delta = BlockGf(mesh=iw_mesh, gf_struct=gf_struct)
# FIXME Delta['up'] << V_mat.transpose() * inverse(iOmega_n - h_bath_mat) * V_mat
for bl, iw in product(spin_names, iw_mesh):
    Delta[bl][iw] = V_mat * inv(iw.value * eye(len(orb_bath_names)) -
                                h_bath_mat) * V_mat.transpose()

# ==== Non-Interacting Impurity Green function  ====
G0_iw = Delta.copy()
G0_iw['up'] << inverse(
    iOmega_n - h_0_mat - Delta['up'])  # FIXME Should work for BlockGf
G0_iw['dn'] << inverse(iOmega_n - h_0_mat - Delta['dn'])

# ==== Construct the CTHYB solver using the G0_iw Interface ====
constr_params = {
    'beta': beta,
Example #28
0
import triqs.utility.mpi as mpi

from triqs.gf import Gf, MeshImFreq, MeshProduct
from triqs.gf import MeshBrZone, MeshCycLat
from triqs.lattice import BrillouinZone, BravaisLattice

from triqs_tprf.lattice import lattice_dyson_g0_wk
from triqs_tprf.lattice import fourier_wk_to_wr
from triqs_tprf.lattice import fourier_wr_to_wk

bz = BrillouinZone(BravaisLattice([[1, 0], [0, 1]]))

periodization_matrix = np.diag(np.array([10, 10, 1], dtype=int))

bzmesh = MeshBrZone(bz, periodization_matrix)
lmesh = MeshCycLat(bz.lattice, periodization_matrix)

e_k = Gf(mesh=bzmesh, target_shape=[1, 1])

for k in bzmesh:
    e_k[k] = -2 * (np.cos(k[0]) + np.cos(k[1]))  # does not work...

mesh = MeshImFreq(beta=1.0, S='Fermion', n_max=1024)
g0_wk = lattice_dyson_g0_wk(mu=1.0, e_k=e_k, mesh=mesh)

g0_wr = fourier_wk_to_wr(g0_wk)
g0_wk_ref = fourier_wr_to_wk(g0_wr)

np.testing.assert_array_almost_equal(g0_wk.data, g0_wk_ref.data)