Пример #1
0
def _gamma2_intermediates(mycc, t1, t2, l1, l2, eris=None):
    dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = \
            gccsd_rdm._gamma2_intermediates(mycc, t1, t2, l1, l2)
    if eris is None: eris = mycc.ao2mo()

    nocc, nvir = t1.shape
    bcei = numpy.asarray(eris.ovvv).conj().transpose(3, 2, 1, 0)
    majk = numpy.asarray(eris.ooov).conj().transpose(2, 3, 0, 1)
    bcjk = numpy.asarray(eris.oovv).conj().transpose(2, 3, 0, 1)

    mo_e = eris.fock.diagonal().real
    eia = mo_e[:nocc, None] - mo_e[nocc:]
    d3 = lib.direct_sum('ia+jb+kc->ijkabc', eia, eia, eia)

    t3c = (numpy.einsum('jkae,bcei->ijkabc', t2, bcei) -
           numpy.einsum('imbc,majk->ijkabc', t2, majk))
    t3c = t3c - t3c.transpose(0, 1, 2, 4, 3, 5) - t3c.transpose(
        0, 1, 2, 5, 4, 3)
    t3c = t3c - t3c.transpose(1, 0, 2, 3, 4, 5) - t3c.transpose(
        2, 1, 0, 3, 4, 5)
    t3c /= d3

    t3d = numpy.einsum('ia,bcjk->ijkabc', t1, bcjk)
    t3d += numpy.einsum('ai,jkbc->ijkabc', eris.fock[nocc:, :nocc], t2)
    t3d = t3d - t3d.transpose(0, 1, 2, 4, 3, 5) - t3d.transpose(
        0, 1, 2, 5, 4, 3)
    t3d = t3d - t3d.transpose(1, 0, 2, 3, 4, 5) - t3d.transpose(
        2, 1, 0, 3, 4, 5)
    t3d /= d3

    goovv = numpy.einsum('kc,ijkabc->ijab', t1.conj(), t3c).conj() * (1. / 4)
    dovov += goovv.transpose(0, 2, 1, 3) - goovv.transpose(0, 3, 1, 2)

    m3 = t3c * 2 + t3d
    # *(1/8) instead of (1/4) because ooov appears 4 times in the 2pdm tensor due
    # to symmetrization, and its contribution is scaled by 1/2 in Tr(H,2pdm)
    gooov = numpy.einsum('imbc,ijkabc->jkma', t2, m3.conj()) * (1. / 8)
    dooov -= gooov.transpose(0, 2, 1, 3) - gooov.transpose(1, 2, 0, 3)

    govvv = numpy.einsum('jkae,ijkabc->iecb', t2, m3.conj()) * (1. / 8)
    dovvv += govvv.transpose(0, 2, 1, 3) - govvv.transpose(0, 3, 1, 2)
    return dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov
Пример #2
0
def make_rdm2(mycc, t1, t2, l1, l2, ao_repr=False, with_dm1=True):
    r'''
    Two-particle density matrix in the molecular spin-orbital representation

    dm2[p,q,r,s] = <p^\dagger r^\dagger s q>

    where p,q,r,s are spin-orbitals. p,q correspond to one particle and r,s
    correspond to another particle.  The contraction between ERIs (in
    Chemist's notation) and rdm2 is
    E = einsum('pqrs,pqrs', eri, rdm2)
    '''
    if t1 is None:
        t1 = mycc.t1
    if t2 is None:
        t2 = mycc.t2
    if l1 is None:
        l1 = mycc.l1
    if l2 is None:
        l2 = mycc.l2
    if l1 is None:
        l1, l2 = mycc.solve_lambda(t1, t2)

    d1 = _gamma1_intermediates(mycc, t1, t2, l1, l2)
    # ZHC TODO
    # use MPI for distributed intermediates
    t1, t2 = mycc.gather_amplitudes(t1, t2)
    l1, l2 = mycc.gather_lambda(l1, l2)

    if rank == 0:
        d2 = gccsd_rdm._gamma2_intermediates(mycc, t1, t2, l1, l2)
        rdm2 = gccsd_rdm._make_rdm2(mycc,
                                    d1,
                                    d2,
                                    with_dm1=with_dm1,
                                    with_frozen=True,
                                    ao_repr=ao_repr)
    else:
        rdm2 = None
    return rdm2
Пример #3
0
def _gamma2_intermediates(mycc, t1, t2, l1, l2, eris=None):
    dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = \
            gccsd_rdm._gamma2_intermediates(mycc, t1, t2, l1, l2)
    if eris is None: eris = mycc.ao2mo()

    nocc, nvir = t1.shape
    bcei = numpy.asarray(eris.ovvv).conj().transpose(3,2,1,0)
    majk = numpy.asarray(eris.ooov).conj().transpose(2,3,0,1)
    bcjk = numpy.asarray(eris.oovv).conj().transpose(2,3,0,1)

    mo_e = eris.mo_energy
    eia = mo_e[:nocc,None] - mo_e[nocc:]
    d3 = lib.direct_sum('ia+jb+kc->ijkabc', eia, eia, eia)

    t3c =(numpy.einsum('jkae,bcei->ijkabc', t2, bcei)
        - numpy.einsum('imbc,majk->ijkabc', t2, majk))
    t3c = t3c - t3c.transpose(0,1,2,4,3,5) - t3c.transpose(0,1,2,5,4,3)
    t3c = t3c - t3c.transpose(1,0,2,3,4,5) - t3c.transpose(2,1,0,3,4,5)
    t3c /= d3

    t3d = numpy.einsum('ia,bcjk->ijkabc', t1, bcjk)
    t3d += numpy.einsum('ai,jkbc->ijkabc', eris.fock[nocc:,:nocc], t2)
    t3d = t3d - t3d.transpose(0,1,2,4,3,5) - t3d.transpose(0,1,2,5,4,3)
    t3d = t3d - t3d.transpose(1,0,2,3,4,5) - t3d.transpose(2,1,0,3,4,5)
    t3d /= d3

    goovv  = numpy.einsum('kc,ijkabc->ijab', t1.conj(), t3c).conj() * (1./4)
    dovov += goovv.transpose(0,2,1,3) - goovv.transpose(0,3,1,2)

    m3 = t3c * 2 + t3d
# *(1/8) instead of (1/4) because ooov appears 4 times in the 2pdm tensor due
# to symmetrization, and its contribution is scaled by 1/2 in Tr(H,2pdm)
    gooov  = numpy.einsum('imbc,ijkabc->jkma', t2, m3.conj()) * (1./8)
    dooov -= gooov.transpose(0,2,1,3) - gooov.transpose(1,2,0,3)

    govvv  = numpy.einsum('jkae,ijkabc->iecb', t2, m3.conj()) * (1./8)
    dovvv += govvv.transpose(0,2,1,3) - govvv.transpose(0,3,1,2)
    return dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov