Ejemplo n.º 1
0
    def __init__ (self, units, hopping, orbital_positions = [ (0, 0, 0) ], orbital_names = [""]):

        # the k are int32 which boost python does like to convert 
        def reg(k) : return tuple( int(x) for x in k) 
        self._hop = dict ( ( reg(k), np.array(v)) for k, v in hopping.items())
        orb = dict ( (str(i), orb) for (i, orb) in enumerate(orbital_positions ))
        self.bl = BravaisLattice(units, orbital_positions)
        self.bz = BrillouinZone(self.bl)
        self.tb = TightBinding(self.bl, self._hop) #, orbital_positions )
        self.dim = self.bl.dim
        self.NOrbitalsInUnitCell = self.bl.n_orbitals
        self.Units = units
        self.OrbitalPositions = orbital_positions 
        self.OrbitalNames = orbital_names
        self.MuPattern = np.identity(self.NOrbitalsInUnitCell)
Ejemplo n.º 2
0
def convert_from_ndarray_to_triqs(U_Q, Q, cell, kpts):

    from pytriqs.gf import Gf, MeshBrillouinZone
    from pytriqs.lattice.lattice_tools import BrillouinZone
    from pytriqs.lattice.lattice_tools import BravaisLattice

    bl = BravaisLattice(cell, [(0, 0, 0)])
    bz = BrillouinZone(bl)
    bzmesh = MeshBrillouinZone(bz, np.diag(np.array(kpts, dtype=np.int32)))

    u_q = Gf(mesh=bzmesh, target_shape=U_Q.shape[1:])

    tmp = np.array(Q * kpts[None, :], dtype=np.int)
    I = [tuple(tmp[i]) for i in xrange(Q.shape[0])]

    for qidx, i in enumerate(I):
        for k in bzmesh:

            # -- Generalize this transform absolute to relative k-points
            a = cell[0, 0]
            q = k * 0.5 * a / np.pi

            j = tuple(np.array(kpts * q, dtype=np.int))
            if i == j: u_q[k].data[:] = U_Q[qidx]

    return u_q
Ejemplo n.º 3
0
class TBLattice:
    def __init__(self,
                 units,
                 hopping,
                 orbital_positions=[(0, 0, 0)],
                 orbital_names=[""]):

        # the k are int32 which boost python does like to convert
        def reg(k):
            return tuple(int(x) for x in k)

        self._hop = dict((reg(k), np.array(v)) for k, v in hopping.items())
        orb = dict((str(i), orb) for (i, orb) in enumerate(orbital_positions))
        self.bl = BravaisLattice(units, orbital_positions)
        self.bz = BrillouinZone(self.bl)
        self.tb = TightBinding(self.bl, self._hop)  #, orbital_positions )
        self.dim = self.bl.dim
        self.NOrbitalsInUnitCell = self.bl.n_orbitals
        self.Units = units
        self.OrbitalPositions = orbital_positions
        self.OrbitalNames = orbital_names
        self.MuPattern = np.identity(self.NOrbitalsInUnitCell)

    def latt_to_real_x(self, p):
        return self.bl.lattice_to_real_coordinates(np.array(p, np.float64))

    def hopping_dict(self):
        return self._hop

    def hopping(self, k_stack):
        return hopping_stack(self.tb, k_stack)

    def periodization_matrix(self, n_k):
        n_k = np.array(n_k)
        assert (len(n_k) == 3)
        assert (n_k.dtype == np.int)
        periodization_matrix = np.diag(np.array(list(n_k), dtype=np.int32))
        return periodization_matrix

    def get_kmesh(self, n_k):
        return MeshBrillouinZone(self.bz, self.periodization_matrix(n_k))

    def get_rmesh(self, n_k):
        return MeshCyclicLattice(self.bl, self.periodization_matrix(n_k))

    def on_mesh_brillouin_zone(self, n_k):

        target_shape = [self.NOrbitalsInUnitCell] * 2

        kmesh = self.get_kmesh(n_k)

        e_k = Gf(mesh=kmesh, target_shape=target_shape)

        k_vec = np.array([k.value for k in kmesh])
        k_vec_rel = np.dot(np.linalg.inv(self.bz.units()).T, k_vec.T).T
        e_k.data[:] = self.hopping(k_vec_rel.T).transpose(2, 0, 1)

        return e_k
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
init_delta_ref = load['init_delta'].reshape(-1, nk**2)
next_delta_ref = load['next_delta'].reshape(-1, nk**2)
final_delta_ref = load['final_delta'].reshape(-1, nk**2)
lamb_ref = load['lambda']
negative_final_delta_ref = load['negative_final_delta'].reshape(-1, nk**2)
negative_lamb_ref = load['negative_lambda']

# ================== TPRF calculations ========================================

# -- Create dispersion relation Green's function object

norbs = e_k_ref.shape[-1]

units = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
orbital_positions = [(0, 0, 0)]
bl = BravaisLattice(units, orbital_positions)
bz = BrillouinZone(bl)
periodization_matrix = nk * np.eye(3, dtype=np.int32)
periodization_matrix[2, 2] = 1
kmesh = MeshBrillouinZone(bz, periodization_matrix)

e_k = Gf(mesh=kmesh, target_shape=[norbs, norbs])

e_k.data[:] = e_k_ref.reshape(nk**2, norbs, norbs)

# --  Calculate bare Green's function

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

# -- Calculate bare bubble
Ejemplo n.º 6
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=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
Ejemplo n.º 7
0
""" Dimension of bz mesh is reduced from 3 to 2 by
broadcasting it over mpi...

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

import numpy as np

from pytriqs.gf import MeshBrillouinZone
from pytriqs.lattice.lattice_tools import BrillouinZone
from pytriqs.lattice.lattice_tools import BravaisLattice

bl = BravaisLattice(np.eye(3), [(0, 0, 0)])
bz = BrillouinZone(bl)

mesh = MeshBrillouinZone(bz, 8 * np.eye(3, dtype=np.int32))

import pytriqs.utility.mpi as mpi

if mpi.is_master_node():
    m = MeshBrillouinZone(bz, 8 * np.eye(3, dtype=np.int32))
else:
    m = None

m = mpi.bcast(m)

print mesh
print m

assert (mesh.domain.lattice.dim == m.domain.lattice.dim)
Ejemplo n.º 8
0
class TBLattice(object):

    """ Class describing a tight binding lattice model.

    This class is based in the TRIQS tight binding class and has been extended with
    some extra convienience methods and documentation.

    Parameters
    ----------

    units : list of three-tuples of floats
        Basis vectors for the real space lattice.

    hopping : dict
        Dictionary with three tuple of integeers as keys, 
        describing real space hoppings in multiples of 
        the real space lattice basis vectors, and values being 
        numpy ndarray hopping matrices in the orbital indices.

    orbital_positions : list of three three-tuples of floats.
        Internal orbital positions in the unit-cell.

    orbital_names : list of strings
        Names for each orbital.

    """

    def __init__ (self, units, hopping, orbital_positions = [ (0, 0, 0) ], orbital_names = [""]):

        # the k are int32 which boost python does like to convert 
        def reg(k) : return tuple( int(x) for x in k) 
        self._hop = dict ( ( reg(k), np.array(v)) for k, v in hopping.items())
        orb = dict ( (str(i), orb) for (i, orb) in enumerate(orbital_positions ))
        self.bl = BravaisLattice(units, orbital_positions)
        self.bz = BrillouinZone(self.bl)
        self.tb = TightBinding(self.bl, self._hop) #, orbital_positions )
        self.dim = self.bl.dim
        self.NOrbitalsInUnitCell = self.bl.n_orbitals
        self.Units = units
        self.OrbitalPositions = orbital_positions 
        self.OrbitalNames = orbital_names
        self.MuPattern = np.identity(self.NOrbitalsInUnitCell)

    def latt_to_real_x(self, p) : 
        return self.bl.lattice_to_real_coordinates (np.array(p, np.float64))

    def hopping_dict(self) : return self._hop

    def hopping(self, k_stack) :
        return hopping_stack(self.tb, k_stack)

    def periodization_matrix(self, n_k):
        n_k = np.array(n_k)
        assert( len(n_k) == 3 )
        assert( n_k.dtype == np.int )
        periodization_matrix = np.diag(np.array(list(n_k), dtype=np.int32))
        return periodization_matrix
    
    def get_kmesh(self, n_k):
        return MeshBrillouinZone(self.bz, self.periodization_matrix(n_k))

    def get_rmesh(self, n_k):
        return MeshCyclicLattice(self.bl, self.periodization_matrix(n_k))
    
    def on_mesh_brillouin_zone(self, n_k):

        """ Construct a discretization of the tight binding model in
        reciprocal space with given number of k-points.

        Parameters
        ----------

        n_k : three-tuple of ints
            Number of k-points in every dimension.

        Returns
        -------

        e_k : TRIQS Greens function on a Brillioun zone mesh
            Reciprocal space tight binding dispersion.

        """
        
        target_shape = [self.NOrbitalsInUnitCell] * 2

        kmesh = self.get_kmesh(n_k)

        e_k = Gf(mesh=kmesh, target_shape=target_shape)

        k_vec = np.array([k.value for k in kmesh])
        k_vec_rel = np.dot(np.linalg.inv(self.bz.units()).T, k_vec.T).T   
        e_k.data[:] = self.hopping(k_vec_rel.T).transpose(2, 0, 1)

        return e_k