#!/usr/bin/env python

import sys, os
sys.path.append(os.getcwd() + "/..")
sys.path.append(os.getcwd() + "/../../common")
from model import *
import util

from pytriqs.archive import HDFArchive
from pytriqs.utility import mpi
from pyed.TriqsExactDiagonalization import TriqsExactDiagonalization

# --------- Construct the ED solver ----------
fundamental_operators = util.get_fundamental_operators(h_imp)
ed = TriqsExactDiagonalization(h_imp, fundamental_operators, beta)

# --------- Calculate the single-particle Green function ----------
G_iw = G0_iw.copy()

for bl, idx_lst in gf_struct:
    for i, j in product(idx_lst, idx_lst):
        ed.set_g2_iwn(G_iw[bl][i,j], c(bl,i), c_dag(bl,j))

# -------- Save in archive ---------
with HDFArchive("../results/pyed.h5",'w') as res:
    res["G"] = G_iw
