Exemple #1
0
def kernel(cc, t1, t2, l1, l2, eris=None):
    if eris is None:
        eris = _ERIS(cc, cc.mo_coeff)
    mol = cc.mol
    mo_coeff = cc.mo_coeff
    mo_energy = cc._scf.mo_energy
    nao, nmo = mo_coeff.shape
    nocc = numpy.count_nonzero(cc.mo_occ > 0)
    nvir = nmo - nocc
    mo_e_o = mo_energy[:nocc]
    mo_e_v = mo_energy[nocc:]
    with_frozen = not (cc.frozen is None or cc.frozen is 0)

    d1 = _gamma1_intermediates(cc, t1, t2, l1, l2)
    d2 = _gamma2_intermediates(cc, t1, t2, l1, l2)

    dm2 = ccsd_rdm._make_rdm2(cc, d1, d2, with_dm1=False, with_frozen=False)
    eri = ao2mo.restore(1, ao2mo.full(cc.mol, mo_coeff), nmo)
    Imat = numpy.einsum('jqrs,iqrs->ij', dm2, eri) * -1
    Ioo = Imat[:nocc, :nocc]
    Ivv = Imat[nocc:, nocc:]
    doo, dov, dvo, dvv = d1
    if with_frozen:
        OA, VA, OF, VF = index_frozen_active(cc)
        doo[OF[:, None], OA] = Ioo[OF[:, None], OA] / lib.direct_sum(
            'i-j->ij', mo_e_o[OF], mo_e_o[OA])
        doo[OA[:, None], OF] = Ioo[OA[:, None], OF] / lib.direct_sum(
            'i-j->ij', mo_e_o[OA], mo_e_o[OF])
        dvv[VF[:, None], VA] = Ivv[VF[:, None], VA] / lib.direct_sum(
            'a-b->ab', mo_e_v[VF], mo_e_v[VA])
        dvv[VA[:, None], VF] = Ivv[VA[:, None], VF] / lib.direct_sum(
            'a-b->ab', mo_e_v[VA], mo_e_v[VF])
    dm1 = scipy.linalg.block_diag(doo + doo.T, dvv + dvv.T)
    dm1ao = reduce(numpy.dot, (mo_coeff, dm1, mo_coeff.T))
    vj, vk = cc._scf.get_jk(cc.mol, dm1ao)
    Xvo = reduce(numpy.dot,
                 (mo_coeff[:, nocc:].T, vj * 2 - vk, mo_coeff[:, :nocc]))
    Xvo += Imat[:nocc, nocc:].T - Imat[nocc:, :nocc]

    dm1 += ccsd_grad._response_dm1(cc, Xvo, eris)
    Imat[nocc:, :nocc] = Imat[:nocc, nocc:].T

    h1 = -(mol.intor('int1e_ipkin', comp=3) + mol.intor('int1e_ipnuc', comp=3))
    s1 = -mol.intor('int1e_ipovlp', comp=3)
    zeta = lib.direct_sum('i-j->ij', mo_energy, mo_energy)
    eri1 = mol.intor('int2e_ip1', comp=3).reshape(3, nao, nao, nao, nao)
    eri1 = numpy.einsum('xipkl,pj->xijkl', eri1, mo_coeff)
    eri1 = numpy.einsum('xijpl,pk->xijkl', eri1, mo_coeff)
    eri1 = numpy.einsum('xijkp,pl->xijkl', eri1, mo_coeff)
    g0 = ao2mo.restore(1, ao2mo.full(mol, mo_coeff), nmo)

    de = numpy.empty((mol.natm, 3))
    for k, (sh0, sh1, p0, p1) in enumerate(mol.offset_nr_by_atom()):
        mol.set_rinv_origin(mol.atom_coord(k))
        vrinv = -mol.atom_charge(k) * mol.intor('int1e_iprinv', comp=3)

        # 2e AO integrals dot 2pdm
        de2 = numpy.zeros(3)
        for i in range(3):
            g1 = numpy.einsum('pjkl,pi->ijkl', eri1[i, p0:p1], mo_coeff[p0:p1])
            g1 = g1 + g1.transpose(1, 0, 2, 3)
            g1 = g1 + g1.transpose(2, 3, 0, 1)
            g1 *= -1
            hx = (numpy.einsum('pq,pi,qj->ij', h1[i, p0:p1], mo_coeff[p0:p1],
                               mo_coeff) +
                  reduce(numpy.dot, (mo_coeff.T, vrinv[i], mo_coeff)))
            hx = hx + hx.T
            sx = numpy.einsum('pq,pi,qj->ij', s1[i, p0:p1], mo_coeff[p0:p1],
                              mo_coeff)
            sx = sx + sx.T

            fij = (hx[:nocc, :nocc] -
                   numpy.einsum('ij,j->ij', sx[:nocc, :nocc], mo_e_o) * .5 -
                   numpy.einsum('ij,i->ij', sx[:nocc, :nocc], mo_e_o) * .5 -
                   numpy.einsum('kl,ijlk->ij', sx[:nocc, :nocc],
                                g0[:nocc, :nocc, :nocc, :nocc]) * 2 +
                   numpy.einsum('kl,iklj->ij', sx[:nocc, :nocc],
                                g0[:nocc, :nocc, :nocc, :nocc]) +
                   numpy.einsum('ijkk->ij', g1[:nocc, :nocc, :nocc, :nocc]) * 2
                   - numpy.einsum('ikkj->ij', g1[:nocc, :nocc, :nocc, :nocc]))

            fab = (hx[nocc:, nocc:] -
                   numpy.einsum('ij,j->ij', sx[nocc:, nocc:], mo_e_v) * .5 -
                   numpy.einsum('ij,i->ij', sx[nocc:, nocc:], mo_e_v) * .5 -
                   numpy.einsum('kl,ijlk->ij', sx[:nocc, :nocc],
                                g0[nocc:, nocc:, :nocc, :nocc]) * 2 +
                   numpy.einsum('kl,iklj->ij', sx[:nocc, :nocc],
                                g0[nocc:, :nocc, :nocc, nocc:]) +
                   numpy.einsum('ijkk->ij', g1[nocc:, nocc:, :nocc, :nocc]) * 2
                   - numpy.einsum('ikkj->ij', g1[nocc:, :nocc, :nocc, nocc:]))

            if with_frozen:
                fij[OA[:, None], OF] -= numpy.einsum(
                    'ij,j->ij', sx[OA[:, None], OF], mo_e_o[OF]) * .5
                fij[OA[:, None], OF] += numpy.einsum(
                    'ij,i->ij', sx[OA[:, None], OF], mo_e_o[OA]) * .5
                fij[OF[:, None], OA] -= numpy.einsum(
                    'ij,j->ij', sx[OF[:, None], OA], mo_e_o[OA]) * .5
                fij[OF[:, None], OA] += numpy.einsum(
                    'ij,i->ij', sx[OF[:, None], OA], mo_e_o[OF]) * .5
                fab[VA[:, None], VF] -= numpy.einsum(
                    'ij,j->ij', sx[VA[:, None], VF], mo_e_v[VF]) * .5
                fab[VA[:, None], VF] += numpy.einsum(
                    'ij,i->ij', sx[VA[:, None], VF], mo_e_v[VA]) * .5
                fab[VF[:, None], VA] -= numpy.einsum(
                    'ij,j->ij', sx[VF[:, None], VA], mo_e_v[VA]) * .5
                fab[VF[:, None], VA] += numpy.einsum(
                    'ij,i->ij', sx[VF[:, None], VA], mo_e_v[VF]) * .5

            fai = (
                hx[nocc:, :nocc] -
                numpy.einsum('ai,i->ai', sx[nocc:, :nocc], mo_e_o) -
                numpy.einsum('kl,ijlk->ij', sx[:nocc, :nocc],
                             g0[nocc:, :nocc, :nocc, :nocc]) * 2 +
                numpy.einsum('kl,iklj->ij', sx[:nocc, :nocc],
                             g0[nocc:, :nocc, :nocc, :nocc]) +
                numpy.einsum('ijkk->ij', g1[nocc:, :nocc, :nocc, :nocc]) * 2 -
                numpy.einsum('ikkj->ij', g1[nocc:, :nocc, :nocc, :nocc]))

            f1 = numpy.zeros((nmo, nmo))
            f1[:nocc, :nocc] = fij
            f1[nocc:, nocc:] = fab
            f1[nocc:, :nocc] = fai
            f1[:nocc, nocc:] = fai.T
            de2[i] += numpy.einsum('ij,ji', f1, dm1)
            de2[i] += numpy.einsum('ij,ji', sx, Imat)
            de2[i] += numpy.einsum('iajb,iajb', dm2, g1) * .5

        de[k] = de2

    return de
Exemple #2
0
def kernel(cc, t1, t2, l1, l2, eris=None):
    if eris is None:
        eris = _ERIS(cc, cc.mo_coeff)
    mol = cc.mol
    mo_coeff = cc.mo_coeff
    mo_energy = cc._scf.mo_energy
    nao, nmo = mo_coeff.shape
    nocc = numpy.count_nonzero(cc.mo_occ > 0)
    nvir = nmo - nocc
    mo_e_o = mo_energy[:nocc]
    mo_e_v = mo_energy[nocc:]
    with_frozen = not (cc.frozen is None or cc.frozen is 0)

    d1 = _gamma1_intermediates(cc, t1, t2, l1, l2)
    d2 = _gamma2_intermediates(cc, t1, t2, l1, l2)

    dm2 = ccsd_rdm._make_rdm2(cc, d1, d2, with_dm1=False, with_frozen=False)
    eri = ao2mo.restore(1, ao2mo.full(cc.mol, mo_coeff), nmo)
    Imat = numpy.einsum('jqrs,iqrs->ij', dm2, eri) * -1
    Ioo = Imat[:nocc,:nocc]
    Ivv = Imat[nocc:,nocc:]
    doo, dov, dvo, dvv = d1
    if with_frozen:
        OA, VA, OF, VF = index_frozen_active(cc)
        doo[OF[:,None],OA] = Ioo[OF[:,None],OA] / lib.direct_sum('i-j->ij', mo_e_o[OF], mo_e_o[OA])
        doo[OA[:,None],OF] = Ioo[OA[:,None],OF] / lib.direct_sum('i-j->ij', mo_e_o[OA], mo_e_o[OF])
        dvv[VF[:,None],VA] = Ivv[VF[:,None],VA] / lib.direct_sum('a-b->ab', mo_e_v[VF], mo_e_v[VA])
        dvv[VA[:,None],VF] = Ivv[VA[:,None],VF] / lib.direct_sum('a-b->ab', mo_e_v[VA], mo_e_v[VF])
    dm1 = scipy.linalg.block_diag(doo+doo.T, dvv+dvv.T)
    dm1ao = reduce(numpy.dot, (mo_coeff, dm1, mo_coeff.T))
    vj, vk = cc._scf.get_jk(cc.mol, dm1ao)
    Xvo = reduce(numpy.dot, (mo_coeff[:,nocc:].T, vj*2-vk, mo_coeff[:,:nocc]))
    Xvo += Imat[:nocc,nocc:].T - Imat[nocc:,:nocc]

    dm1 += ccsd_grad._response_dm1(cc, Xvo, eris)
    Imat[nocc:,:nocc] = Imat[:nocc,nocc:].T

    h1 =-(mol.intor('int1e_ipkin', comp=3)
         +mol.intor('int1e_ipnuc', comp=3))
    s1 =-mol.intor('int1e_ipovlp', comp=3)
    zeta = lib.direct_sum('i-j->ij', mo_energy, mo_energy)
    eri1 = mol.intor('int2e_ip1', comp=3).reshape(3,nao,nao,nao,nao)
    eri1 = numpy.einsum('xipkl,pj->xijkl', eri1, mo_coeff)
    eri1 = numpy.einsum('xijpl,pk->xijkl', eri1, mo_coeff)
    eri1 = numpy.einsum('xijkp,pl->xijkl', eri1, mo_coeff)
    g0 = ao2mo.restore(1, ao2mo.full(mol, mo_coeff), nmo)

    de = numpy.empty((mol.natm,3))
    for k,(sh0, sh1, p0, p1) in enumerate(mol.offset_nr_by_atom()):
        mol.set_rinv_origin(mol.atom_coord(k))
        vrinv = -mol.atom_charge(k) * mol.intor('int1e_iprinv', comp=3)

# 2e AO integrals dot 2pdm
        de2 = numpy.zeros(3)
        for i in range(3):
            g1 = numpy.einsum('pjkl,pi->ijkl', eri1[i,p0:p1], mo_coeff[p0:p1])
            g1 = g1 + g1.transpose(1,0,2,3)
            g1 = g1 + g1.transpose(2,3,0,1)
            g1 *= -1
            hx =(numpy.einsum('pq,pi,qj->ij', h1[i,p0:p1], mo_coeff[p0:p1], mo_coeff)
               + reduce(numpy.dot, (mo_coeff.T, vrinv[i], mo_coeff)))
            hx = hx + hx.T
            sx = numpy.einsum('pq,pi,qj->ij', s1[i,p0:p1], mo_coeff[p0:p1], mo_coeff)
            sx = sx + sx.T

            fij =(hx[:nocc,:nocc]
                  - numpy.einsum('ij,j->ij', sx[:nocc,:nocc], mo_e_o) * .5
                  - numpy.einsum('ij,i->ij', sx[:nocc,:nocc], mo_e_o) * .5
                  - numpy.einsum('kl,ijlk->ij', sx[:nocc,:nocc],
                                 g0[:nocc,:nocc,:nocc,:nocc]) * 2
                  + numpy.einsum('kl,iklj->ij', sx[:nocc,:nocc],
                                 g0[:nocc,:nocc,:nocc,:nocc])
                  + numpy.einsum('ijkk->ij', g1[:nocc,:nocc,:nocc,:nocc]) * 2
                  - numpy.einsum('ikkj->ij', g1[:nocc,:nocc,:nocc,:nocc]))

            fab =(hx[nocc:,nocc:]
                  - numpy.einsum('ij,j->ij', sx[nocc:,nocc:], mo_e_v) * .5
                  - numpy.einsum('ij,i->ij', sx[nocc:,nocc:], mo_e_v) * .5
                  - numpy.einsum('kl,ijlk->ij', sx[:nocc,:nocc],
                                 g0[nocc:,nocc:,:nocc,:nocc]) * 2
                  + numpy.einsum('kl,iklj->ij', sx[:nocc,:nocc],
                                 g0[nocc:,:nocc,:nocc,nocc:])
                  + numpy.einsum('ijkk->ij', g1[nocc:,nocc:,:nocc,:nocc]) * 2
                  - numpy.einsum('ikkj->ij', g1[nocc:,:nocc,:nocc,nocc:]))

            if with_frozen:
                fij[OA[:,None],OF] -= numpy.einsum('ij,j->ij', sx[OA[:,None],OF], mo_e_o[OF]) * .5
                fij[OA[:,None],OF] += numpy.einsum('ij,i->ij', sx[OA[:,None],OF], mo_e_o[OA]) * .5
                fij[OF[:,None],OA] -= numpy.einsum('ij,j->ij', sx[OF[:,None],OA], mo_e_o[OA]) * .5
                fij[OF[:,None],OA] += numpy.einsum('ij,i->ij', sx[OF[:,None],OA], mo_e_o[OF]) * .5
                fab[VA[:,None],VF] -= numpy.einsum('ij,j->ij', sx[VA[:,None],VF], mo_e_v[VF]) * .5
                fab[VA[:,None],VF] += numpy.einsum('ij,i->ij', sx[VA[:,None],VF], mo_e_v[VA]) * .5
                fab[VF[:,None],VA] -= numpy.einsum('ij,j->ij', sx[VF[:,None],VA], mo_e_v[VA]) * .5
                fab[VF[:,None],VA] += numpy.einsum('ij,i->ij', sx[VF[:,None],VA], mo_e_v[VF]) * .5

            fai =(hx[nocc:,:nocc]
                  - numpy.einsum('ai,i->ai', sx[nocc:,:nocc], mo_e_o)
                  - numpy.einsum('kl,ijlk->ij', sx[:nocc,:nocc],
                                 g0[nocc:,:nocc,:nocc,:nocc]) * 2
                  + numpy.einsum('kl,iklj->ij', sx[:nocc,:nocc],
                                 g0[nocc:,:nocc,:nocc,:nocc])
                  + numpy.einsum('ijkk->ij', g1[nocc:,:nocc,:nocc,:nocc]) * 2
                  - numpy.einsum('ikkj->ij', g1[nocc:,:nocc,:nocc,:nocc]))

            f1 = numpy.zeros((nmo,nmo))
            f1[:nocc,:nocc] = fij
            f1[nocc:,nocc:] = fab
            f1[nocc:,:nocc] = fai
            f1[:nocc,nocc:] = fai.T
            de2[i] += numpy.einsum('ij,ji', f1, dm1)
            de2[i] += numpy.einsum('ij,ji', sx, Imat)
            de2[i] += numpy.einsum('iajb,iajb', dm2, g1) * .5

        de[k] = de2

    return de