Exemple #1
0
def mb_ph_ops(hlat, perturb, omega, nimp, nocc, pemb, pcore, pvirt):
    """
    external ops for part-hole Green's function
    """
    nimp_sp = nimp * 2
    nsites_sp = hlat.shape[0] * 2
    nocc_sp = nocc * 2

    # transform h into imp+bath/ext(all) basis
    pall = N.hstack([pemb, pcore, pvirt])
    hall = N.dot(pall.T, N.dot(hlat, pall))
    hall_sp = _spinify(hall)

    # t1amp in (all) basis
    t1amp_ao = make_t1amp_ao(hlat, omega, perturb, nocc)
    t1amp_all = N.dot(pall.T, N.dot(t1amp_ao, pall))
    t1amp_all_sp = _spinify(t1amp_all)

    # mb_ext_operators
    sites_imp = range(0, nimp_sp * 2)
    sites_ext = range(nimp_sp * 2, nsites_sp)

    cops = []
    dops = []

    project = False

    if project:
        li_t1amp_ext_imp = _linear_orthonormal_basis(
            t1amp_all_sp[sites_ext, :][:, sites_imp], orient='c')
        print "retained %i out of %i vectors" % (li_t1amp_ext_imp.shape[1],
                                                 len(sites_imp))

        li_t1amp_imp_ext = _linear_orthonormal_basis(
            t1amp_all_sp[sites_imp, :][:, sites_ext], orient='r')
        print "retained %i out of %i vectors" % (li_t1amp_imp_ext.shape[0],
                                                 len(sites_imp))

        for i in xrange(li_t1amp_ext_imp.shape[1]):
            cops.append(models.ContractedC(sites_ext, li_t1amp_ext_imp[:, i]))

        for i in xrange(li_t1amp_imp_ext.shape[0]):
            dops.append(models.ContractedD(sites_ext, li_t1amp_imp_ext[i, :]))
    else:
        for imp in sites_imp:
            coeff_c = t1amp_all_sp[sites_ext, imp]
            cops.append(models.ContractedC(sites_ext, coeff_c))
            coeff_d = t1amp_all_sp[imp, sites_ext]
            dops.append(models.ContractedD(sites_ext, coeff_d))

    cd_coeffs = {}
    for i in sites_ext:
        for j in sites_ext:
            if abs(t1amp_all_sp[i, j]) > 1.e-8:
                cd_coeffs[i, j] = t1amp_all_sp[i, j]
    cdop = models.ContractedCD(cd_coeffs)

    ops = {"1": models.Unit(), "c": cops, "d": dops, "cd": cdop}

    return ops
Exemple #2
0
def mb_sp_ops(hlat, perturb, omega, nimp, nocc, pemb, pcore, pvirt):
    """
    single particle external ops 
    (for single particle Green's function)
    """
    nimp_sp = nimp * 2
    nsites_sp = hlat.shape[0] * 2
    nocc_sp = nocc * 2

    # transform h into imp+bath/ext(all) basis
    pall = N.hstack([pemb, pcore, pvirt])
    hall = N.dot(pall.T, N.dot(hlat, pall))
    hall_sp = _spinify(hall)

    # green's function amps in (all) basis
    damp_ao, camp_ao = make_greens_ao(hlat, omega, perturb, nocc)
    damp_all = N.dot(pall.T, damp_ao)
    camp_all = N.dot(pall.T, camp_ao)
    #print N.dot(damp_ao,pall)
    damp_all_sp = _spinify_vec(damp_all)
    camp_all_sp = _spinify_vec(camp_all)

    # mb_ext operators
    sites_imp = range(0, nimp_sp * 2)
    sites_ext = range(nimp_sp * 2, nsites_sp)

    coeff_c = camp_all_sp[sites_ext]
    cops = [models.ContractedC(sites_ext, coeff_c)]

    coeff_d = damp_all_sp[sites_ext]
    dops = [models.ContractedD(sites_ext, coeff_d)]

    ops = {"1": models.Unit(), "c": cops, "d": dops}

    return ops
Exemple #3
0
def ph_greens():
    # main loop for general density-density (ph) response functions
    utils.dtype = N.complex128

    nimp = 1
    nimp_sp = 2 * nimp
    nocc = 10
    nsites = 20
    nsites_sp = nsites * 2
    ndim = 2
    sz = 0
    # sites numbered in order as imp+bath ... ext
    sites_imp = range(0, 2 * nimp_sp)
    sites_ext = range(2 * nimp_sp, nsites_sp)
    ncore = 2 * nocc - 2 * nimp
    cocc = range(2 * nimp_sp, 2 * nimp_sp + ncore)
    vocc = range(2 * nimp_sp + ncore, nsites_sp)

    N.set_printoptions(precision=3)

    t = -1.  # hopping
    delta = 0.0  #25 # broadening

    #    for u in [0.0,4.0,10.0]:
    for u in [0.0, 0.5, 1.0, 2.0, 4.0, 8.0]:  #,1.0,4.0,8.0]:

        # Single impurity Anderson model
        mu = 0.
        hlat, hall, hlat_sp, hall_sp, e0 = models_embed.si_anderson_imp_ext_ni_h(
            t, nocc, nimp, nsites)
        hop, himp, hcs_imp, hds_imp, hcs_ext, hds_ext, hext = models_embed.si_anderson_imp_ext_h(
            hall_sp, u, nocc, nimp, nsites)

        #        single site Hubbard in DMET basis
        #        mu=u/2
        #        hlat,hall,hlat_sp,hall_sp,e0=models_embed.hubbard_imp_ext_ni_h(t,u,nocc,nimp,nsites)
        #        hop,himp,hcs_imp,hds_imp,hcs_ext,hds_ext,hext=models_embed.hubbard_imp_ext_h(hall_sp,u,nocc,nimp,nsites)

        # g.s embedding basis
        pemb, pcore, pvirt = embed.embed(hlat, nimp, nocc)

        # perturbation operator
        perturb = utils.zeros([nsites, nsites])
        perturb[0, 0] = 1.

        p_coeffs = {}
        p_coeffs[0, 0] = 1.
        p_coeffs[1, 1] = 1.
        perturbop = models.ContractedCD(p_coeffs)

        fd = file("ph_siam.out." + str(u), "w")
        for omega in N.arange(0, 4, 0.01):

            if abs(omega - 2.0) < 0.00001:
                continue

            ops_dict = response_embed.mb_ph_ops(hlat, perturb,
                                                omega + 1j * delta, nimp, nocc,
                                                pemb, pcore, pvirt)
            configs_dict = response_embed.mb_configs(nsites, nimp, nimp_sp,
                                                     2 * nocc - nimp_sp, 0)
            neutral_ops_configs = response_embed.mb_ph_ops_configs(
                ops_dict, configs_dict)

            # basis is setup, now build matrix representations
            perturb_mat = opbasis_ni.oimp_matrix_form(perturbop,
                                                      neutral_ops_configs,
                                                      cocc, vocc)

            # h, neutral configs
            himp_mat = opbasis_ni.oimp_matrix_form(himp, neutral_ops_configs,
                                                   cocc, vocc)
            himp_ext_mat = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, neutral_ops_configs, cocc,
                vocc)
            hext_mat = opbasis_ni.hext_matrix_form(hext, neutral_ops_configs,
                                                   cocc, vocc, e0)

            #print 'himp_mat size: ',himp_mat.shape
            #print 'himp_mat',himp_mat[:,0]
            #print 'hext_mat size: ',hext_mat.shape
            #print 'himp_ext_mat size: ',himp_ext_mat.shape

            hmat = himp_mat + himp_ext_mat + hext_mat

            #print 'total size hmat: ',hmat.shape

            unit_mat = opbasis_ni.oimp_matrix_form(models.Unit(),
                                                   neutral_ops_configs, cocc,
                                                   vocc)

            # get neutral ground-state energy
            es, cs = la.peigh(hmat, unit_mat)
            e0 = es[0]
            psi0 = cs[:, 0]
            # all matrices setup, solve linear response (complex)
            psi1 = la.solve_perturb(omega - 1j * delta,
                                    unit_mat,
                                    hmat,
                                    e0,
                                    psi0,
                                    perturb_mat,
                                    project=True)

            ph_gf = N.dot(N.conj(psi1), N.dot(perturb_mat, psi0))

            ph_gf0 = _second_order_energy(hlat, nocc, perturb,
                                          omega + 1j * delta)

            #print 'hlat size: ',hlat.shape
            #print 'hlat: '
            #print hlat

            #print omega, ph_gf.imag,ph_gf0.imag
            print omega, ph_gf, 2 * ph_gf0
            print >> fd, omega - mu, ph_gf.imag, ph_gf0.imag, ph_gf.real, 2 * ph_gf0.real
Exemple #4
0
def sp_greens():
    # main loop for single-particle GF
    utils.dtype = N.complex128

    nimp = 1
    nimp_sp = 2 * nimp
    nocc = 20
    nsites = 40
    nsites_sp = nsites * 2
    ndim = 2
    sz = 0
    # sites numbered in order as imp+bath ... ext
    sites_imp = range(0, 2 * nimp_sp)
    sites_ext = range(2 * nimp_sp, nsites_sp)
    ncore = 2 * nocc - 2 * nimp
    cocc = range(2 * nimp_sp, 2 * nimp_sp + ncore)
    vocc = range(2 * nimp_sp + ncore, nsites_sp)

    N.set_printoptions(precision=3)

    t = -1.  # hopping
    delta = 0.2  # broadening

    #    for u in [0.0,4.0,10.0]:
    for u in [1.0]:

        # Single impurity Anderson model
        mu = 0.
        hlat, hall, hlat_sp, hall_sp, e0 = models_embed.si_anderson_imp_ext_ni_h(
            t, nocc, nimp, nsites)
        hop, himp, hcs_imp, hds_imp, hcs_ext, hds_ext, hext = models_embed.si_anderson_imp_ext_h(
            hall_sp, u, nocc, nimp, nsites)

        #        single site Hubbard in DMET basis
        #        mu=u/2
        #        hlat,hall,hlat_sp,hall_sp,e0=models_embed.hubbard_imp_ext_ni_h(t,u,nocc,nimp,nsites)
        #        hop,himp,hcs_imp,hds_imp,hcs_ext,hds_ext,hext=models_embed.hubbard_imp_ext_h(hall_sp,u,nocc,nimp,nsites)

        # g.s embedding basis
        pemb, pcore, pvirt = embed.embed(hlat, nimp, nocc)

        # perturbation operator
        perturb = utils.zeros([nsites])
        perturb[0] = 1.
        p_coeffs = N.array([1])
        perturb_dop = models.ContractedD(N.array([0]), p_coeffs)
        perturb_cop = models.ContractedC(N.array([0]), p_coeffs)

        fd = file("ph_siam.out." + str(u), "w")
        for omega in N.arange(-2, 2, 0.1):

            ops_dict = response_embed.mb_sp_ops(hlat, perturb,
                                                omega + 1j * delta, nimp, nocc,
                                                pemb, pcore, pvirt)
            configs_dict = response_embed.mb_configs(nsites, nimp, nimp_sp,
                                                     2 * nocc - nimp_sp, 0)
            neutral_ops_configs, plus_ops_configs, minus_ops_configs = response_embed.mb_sp_ops_configs(
                ops_dict, configs_dict)

            # basis is setup, now build matrix representations
            perturb_dop_mat = opbasis_ni.oimp_matrix_bra_ket_form(
                perturb_dop, minus_ops_configs, neutral_ops_configs, cocc,
                vocc)
            perturb_cop_mat = opbasis_ni.oimp_matrix_bra_ket_form(
                perturb_cop, plus_ops_configs, neutral_ops_configs, cocc, vocc)

            # h, N-1 configs
            himp_mat_minus = opbasis_ni.oimp_matrix_form(
                himp, minus_ops_configs, cocc, vocc)
            himp_ext_mat_minus = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, minus_ops_configs, cocc,
                vocc)
            hext_mat_minus = opbasis_ni.hext_matrix_form(
                hext, minus_ops_configs, cocc, vocc, e0)
            hmat_minus = himp_mat_minus + himp_ext_mat_minus + hext_mat_minus
            unit_mat_minus = opbasis_ni.oimp_matrix_form(
                models.Unit(), minus_ops_configs, cocc, vocc)

            # h, N+1 configs
            himp_mat_plus = opbasis_ni.oimp_matrix_form(
                himp, plus_ops_configs, cocc, vocc)
            himp_ext_mat_plus = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, plus_ops_configs, cocc,
                vocc)
            hext_mat_plus = opbasis_ni.hext_matrix_form(
                hext, plus_ops_configs, cocc, vocc, e0)
            hmat_plus = himp_mat_plus + himp_ext_mat_plus + hext_mat_plus
            unit_mat_plus = opbasis_ni.oimp_matrix_form(
                models.Unit(), plus_ops_configs, cocc, vocc)

            # h, neutral configs
            himp_mat = opbasis_ni.oimp_matrix_form(himp, neutral_ops_configs,
                                                   cocc, vocc)
            himp_ext_mat = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, neutral_ops_configs, cocc,
                vocc)
            hext_mat = opbasis_ni.hext_matrix_form(hext, neutral_ops_configs,
                                                   cocc, vocc, e0)
            hmat = himp_mat + himp_ext_mat + hext_mat
            unit_mat = opbasis_ni.oimp_matrix_form(models.Unit(),
                                                   neutral_ops_configs, cocc,
                                                   vocc)

            # get neutral ground-state energy
            es, cs = la.peigh(hmat, unit_mat)
            e0 = es[0]
            psi0 = cs[:, 0]

            print e0
            print psi0
            # all matrices setup, solve linear response (complex)
            psi1_minus = la.solve_perturb(omega + 1j * delta,
                                          unit_mat_minus,
                                          hmat_minus,
                                          e0,
                                          psi0,
                                          perturb_dop_mat,
                                          project=False,
                                          sign_ham=-1.)

            gfminus = N.dot(psi1_minus, N.dot(perturb_dop_mat, psi0))

            psi1_plus = la.solve_perturb(omega + 1j * delta,
                                         unit_mat_plus,
                                         hmat_plus,
                                         e0,
                                         psi0,
                                         perturb_cop_mat,
                                         project=False)

            gfplus = N.dot(psi1_plus, N.dot(perturb_cop_mat, psi0))

            d_gf, c_gf = _sp_gf(hlat, omega + 1j * delta, perturb, nocc)

            print omega, gfplus.imag, c_gf.imag, gfminus.imag, d_gf.imag
            print >> fd, omega - mu, gfplus.imag + gfminus.imag, c_gf.imag + d_gf.imag
Exemple #5
0
def main():
    # main loop for single-particle GF
    utils.dtype = N.complex128

    nimp = 4
    nimp_sp = 2 * nimp
    nsites = 8
    nocc = nsites / 2
    nsites_sp = nsites * 2
    ndim = 2
    sz = 0
    # sites numbered in order as imp+bath ... ext
    sites_imp = range(0, 2 * nimp_sp)
    sites_ext = range(2 * nimp_sp, nsites_sp)
    ncore = 2 * nocc - 2 * nimp
    cocc = range(2 * nimp_sp, 2 * nimp_sp + ncore)
    vocc = range(2 * nimp_sp + ncore, nsites_sp)

    N.set_printoptions(precision=3)

    #t=1. # hopping
    gamma = 0.005
    rho0 = (nsites - 2) / 2.
    t = 0.1  #N.sqrt(gamma/(rho0*N.pi))
    #gamma = (t**2)*pi*0.1
    delta = 0.005  # broadening
    #a=12.5
    #    for u in [0.0,4.0,10.0]:
    for u in [0., 2.5, 5., 7.5]:
        u *= t
        # Single impurity Anderson model
        mu = 0.
        hlat, hall, hlat_sp, hall_sp, e0 = models_embed.si_anderson_imp_ext_ni_h(
            t, u, nocc, nimp, nsites)
        hop, himp, hcs_imp, hds_imp, hcs_ext, hds_ext, hext = models_embed.si_anderson_imp_ext_h(
            hall_sp, u, nocc, nimp, nsites)
        #print hext
        #        single site Hubbard in DMET basis
        #mu=u/2
        #hlat,hall,hlat_sp,hall_sp,e0=models_embed.hubbard_imp_ext_ni_h(t,u,nocc,nimp,nsites)
        #hop,himp,hcs_imp,hds_imp,hcs_ext,hds_ext,hext=models_embed.hubbard_imp_ext_h(hall_sp,u,nocc,nimp,nsites)

        # g.s embedding basis
        pemb, pcore, pvirt = embed.embed(hlat, nimp, nocc)

        # perturbation operator
        perturb = utils.zeros([nsites])
        perturb[0] = 1.
        p_coeffs = N.array([1])
        perturb_dop = models.ContractedD(N.array([0]), p_coeffs)
        perturb_cop = models.ContractedC(N.array([0]), p_coeffs)

        fd = file(
            "siam_emb_dos_nsites" + str(nsites) + '_U' + str(u) + '_nimp' +
            str(nimp) + '_eta' + str(delta), "w")

        for omega in N.arange(-1., 1., 0.01):

            ops_dict = response_embed.mb_sp_ops(hlat, perturb,
                                                omega + 1j * delta, nimp, nocc,
                                                pemb, pcore, pvirt)

            configs_dict = response_embed.mb_configs(nsites, nimp, nimp_sp,
                                                     2 * nocc - nimp_sp, 0)

            neutral_ops_configs, plus_ops_configs, minus_ops_configs = response_embed.mb_sp_ops_configs(
                ops_dict, configs_dict)

            #print minus_ops_configs
            # basis is setup, now build matrix representations
            perturb_dop_mat = opbasis_ni.oimp_matrix_bra_ket_form(
                perturb_dop, minus_ops_configs, neutral_ops_configs, cocc,
                vocc)
            perturb_cop_mat = opbasis_ni.oimp_matrix_bra_ket_form(
                perturb_cop, plus_ops_configs, neutral_ops_configs, cocc, vocc)
            #print plus_ops_configs
            # h, N-1 configs

            #print minus_ops_configs
            himp_mat_minus = opbasis_ni.oimp_matrix_form(
                himp, minus_ops_configs, cocc, vocc)
            himp_ext_mat_minus = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, minus_ops_configs, cocc,
                vocc)
            #print himp_ext_mat_minus
            hext_mat_minus = opbasis_ni.hext_matrix_form(
                hext, minus_ops_configs, cocc, vocc, e0)
            hmat_minus = himp_mat_minus + himp_ext_mat_minus + hext_mat_minus
            unit_mat_minus = opbasis_ni.oimp_matrix_form(
                models.Unit(), minus_ops_configs, cocc, vocc)
            #print hext_mat_minus

            # h, N+1 configs
            himp_mat_plus = opbasis_ni.oimp_matrix_form(
                himp, plus_ops_configs, cocc, vocc)
            himp_ext_mat_plus = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, plus_ops_configs, cocc,
                vocc)
            hext_mat_plus = opbasis_ni.hext_matrix_form(
                hext, plus_ops_configs, cocc, vocc, e0)
            hmat_plus = himp_mat_plus + himp_ext_mat_plus + hext_mat_plus
            unit_mat_plus = opbasis_ni.oimp_matrix_form(
                models.Unit(), plus_ops_configs, cocc, vocc)

            # h, neutral configs
            himp_mat = opbasis_ni.oimp_matrix_form(himp, neutral_ops_configs,
                                                   cocc, vocc)
            himp_ext_mat = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, neutral_ops_configs, cocc,
                vocc)
            hext_mat = opbasis_ni.hext_matrix_form(hext, neutral_ops_configs,
                                                   cocc, vocc, e0)
            hmat = himp_mat + himp_ext_mat + hext_mat
            unit_mat = opbasis_ni.oimp_matrix_form(models.Unit(),
                                                   neutral_ops_configs, cocc,
                                                   vocc)

            # get neutral ground-state energy
            es, cs = la.peigh(hmat, unit_mat)
            e_gs = es[0]
            psi0 = cs[:, 0]

            #print e0
            #print psi0
            #print N.dot(perturb_dop_mat,psi0)
            # all matrices setup, solve linear response (complex)

            psi1_minus = la.solve_perturb(omega + 1j * delta,
                                          unit_mat_minus,
                                          hmat_minus,
                                          e_gs,
                                          psi0,
                                          perturb_dop_mat,
                                          project=False,
                                          sign_ham=-1.)

            gfminus = N.dot(psi1_minus, N.dot(perturb_dop_mat, psi0))

            psi1_plus = la.solve_perturb(omega + 1j * delta,
                                         unit_mat_plus,
                                         hmat_plus,
                                         e_gs,
                                         psi0,
                                         perturb_cop_mat,
                                         project=False)

            #print N.dot(perturb_cop_mat,psi0)

            #print hmat

            gfplus = N.dot(psi1_plus, N.dot(perturb_cop_mat, psi0))

            d_gf, c_gf = _sp_gf(hlat, omega + 1j * delta, perturb, nocc)

            #print omega, gfplus.imag,c_gf.imag, gfminus.imag,d_gf.imag
            #print >>fd, omega-mu, -1.*(gfplus.imag),-1.*(c_gf.imag+d_gf.imag)
            print >> fd, omega - mu, -(1 / N.pi) * (gfplus.imag + gfminus.imag)
Exemple #6
0
def main():
    # main loop for single-particle GF
    utils.dtype = N.complex128

    nimp = 1
    nimp_sp = 2 * nimp
    nsites = 300
    nocc = nsites / 2
    nsites_sp = nsites * 2
    ndim = 2
    sz = 0
    # sites numbered in order as imp+bath ... ext
    sites_imp = range(0, 2 * nimp_sp)
    sites_ext = range(2 * nimp_sp, nsites_sp)
    ncore = 2 * nocc - 2 * nimp
    cocc = range(2 * nimp_sp, 2 * nimp_sp + ncore)
    vocc = range(2 * nimp_sp + ncore, nsites_sp)

    N.set_printoptions(precision=3)

    #t=1. # hopping
    gamma = 0.05
    rho0 = (nsites - 2) / 2.
    t = N.sqrt(gamma / (rho0 * N.pi))
    #t = 0.1
    #gamma = (t**2)*pi*0.1
    delta = 1e-12  # broadening
    #a=12.5
    #    for u in [0.0,4.0,10.0]:
    for u in [10.]:
        u *= gamma
        # Single impurity Anderson model
        mu = 0.
        hlat, hall, hlat_sp, hall_sp, e0 = models_embed.si_anderson_imp_ext_ni_h(
            t, u, nocc, nimp, nsites)
        hop, himp, hcs_imp, hds_imp, hcs_ext, hds_ext, hext = models_embed.si_anderson_imp_ext_h(
            hall_sp, u, nocc, nimp, nsites)
        #print hext
        #        single site Hubbard in DMET basis
        #mu=u/2
        #hlat,hall,hlat_sp,hall_sp,e0=models_embed.hubbard_imp_ext_ni_h(t,u,nocc,nimp,nsites)
        #hop,himp,hcs_imp,hds_imp,hcs_ext,hds_ext,hext=models_embed.hubbard_imp_ext_h(hall_sp,u,nocc,nimp,nsites)

        # g.s embedding basis
        pemb, pcore, pvirt = embed.embed(hlat, nimp, nocc)

        # perturbation operator
        perturb = utils.zeros([nsites])
        perturb[0] = 1.
        p_coeffs = N.array([1])
        perturb_dop = models.ContractedD(N.array([0]), p_coeffs)

        perturb_cop = models.ContractedC(N.array([0]), p_coeffs)

        #fd=file("siam_emb_dos_nsites"+str(nsites)+'_U'+str(u)+'_nimp'+str(nimp)+'_eta'+str(delta),"w")
        fdEnminus = file("En_minus", "w")
        fdCnminus = file("Cn_minus", "w")
        fdEnplus = file("En_plus", "w")
        fdCnplus = file("Cn_plus", "w")
        for omega in [1e-08]:  #N.arange(-1.,1.,0.1):
            #print omega
            ops_dict = response_embed.mb_sp_ops(hlat, perturb,
                                                omega + 1j * delta, nimp, nocc,
                                                pemb, pcore, pvirt)

            configs_dict = response_embed.mb_configs(nsites, nimp, nimp_sp,
                                                     2 * nocc - nimp_sp, 0)

            neutral_ops_configs, plus_ops_configs, minus_ops_configs = response_embed.mb_sp_ops_configs(
                ops_dict, configs_dict)

            #print _ops_configs
            # basis is setup, now build matrix representations
            perturb_dop_mat = opbasis_ni.oimp_matrix_bra_ket_form(
                perturb_dop, minus_ops_configs, neutral_ops_configs, cocc,
                vocc)
            perturb_cop_mat = opbasis_ni.oimp_matrix_bra_ket_form(
                perturb_cop, plus_ops_configs, neutral_ops_configs, cocc, vocc)

            # h, N-1 configs

            #print ops_dict['d'][0]
            himp_mat_minus = opbasis_ni.oimp_matrix_form(
                himp, minus_ops_configs, cocc, vocc)
            himp_ext_mat_minus = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, minus_ops_configs, cocc,
                vocc)
            #print himp_ext_mat_minus
            hext_mat_minus = opbasis_ni.hext_matrix_form(
                hext, minus_ops_configs, cocc, vocc, e0)
            hmat_minus = himp_mat_minus + himp_ext_mat_minus + hext_mat_minus
            unit_mat_minus = opbasis_ni.oimp_matrix_form(
                models.Unit(), minus_ops_configs, cocc, vocc)
            #print hext_mat_minus

            # h, N+1 configs
            himp_mat_plus = opbasis_ni.oimp_matrix_form(
                himp, plus_ops_configs, cocc, vocc)
            himp_ext_mat_plus = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, plus_ops_configs, cocc,
                vocc)
            hext_mat_plus = opbasis_ni.hext_matrix_form(
                hext, plus_ops_configs, cocc, vocc, e0)
            hmat_plus = himp_mat_plus + himp_ext_mat_plus + hext_mat_plus
            unit_mat_plus = opbasis_ni.oimp_matrix_form(
                models.Unit(), plus_ops_configs, cocc, vocc)

            # h, neutral configs
            himp_mat = opbasis_ni.oimp_matrix_form(himp, neutral_ops_configs,
                                                   cocc, vocc)
            himp_ext_mat = opbasis_ni.himp_ext_matrix_form(
                hcs_imp, hds_ext, hds_imp, hcs_ext, neutral_ops_configs, cocc,
                vocc)
            hext_mat = opbasis_ni.hext_matrix_form(hext, neutral_ops_configs,
                                                   cocc, vocc, e0)
            hmat = himp_mat + himp_ext_mat + hext_mat
            unit_mat = opbasis_ni.oimp_matrix_form(models.Unit(),
                                                   neutral_ops_configs, cocc,
                                                   vocc)

            #print hext_mat_minus

            # get neutral ground-state energy
            es, cs = la.peigh(hmat, unit_mat)
            e_gs = es[0]
            psi0 = cs[:, 0]

            es_minus, cs_minus = la.peigh(hmat_minus, unit_mat_minus)

            Enarray = es_minus - e_gs * N.ones(len(es_minus))
            print >> fdEnminus, omega, str(list(Enarray))[1:-1].translate(
                None, ',')
            es_plus, cs_plus = la.peigh(hmat_plus, unit_mat_plus)

            Enarray = es_plus - e_gs * N.ones(len(es_minus))
            print >> fdEnplus, omega, str(list(Enarray))[1:-1].translate(
                None, ',')

            gfminus = 0.
            mat_el_list_minus = []
            for i in xrange(len(es_minus)):
                ket = N.dot(perturb_dop_mat, psi0)
                bra = N.transpose(cs_minus[:, i].conjugate())
                mat_el = N.dot(bra, ket)
                mat_el *= mat_el.conjugate()
                mat_el_list_minus.append(mat_el.real)
                den = omega + 1j * delta - e_gs + es_minus[i]
                gfminus += (mat_el / den)

            print >> fdCnminus, omega, str(mat_el_list_minus)[1:-1].translate(
                None, ',')

            gfplus = 0.
            mat_el_list_plus = []
            for i in xrange(len(es_plus)):
                ket = N.dot(perturb_cop_mat, psi0)
                bra = N.transpose(cs_plus[:, i].conjugate())
                mat_el = N.dot(bra, ket)
                mat_el *= mat_el.conjugate()
                mat_el_list_plus.append(mat_el.real)
                den = omega + 1j * delta + e_gs - es_plus[i]
                gfplus += (mat_el / den)

            print >> fdCnplus, omega, str(mat_el_list_plus)[1:-1].translate(
                None, ',')