def update_amps(cc, t1, t2, eris, max_memory=2000): time0 = time.clock(), time.time() log = logger.Logger(cc.stdout, cc.verbose) nocc, nvir = t1.shape fock = eris.fock fov = fock[:nocc, nocc:] foo = fock[:nocc, :nocc] fvv = fock[nocc:, nocc:] mo_e = eris.fock.diagonal() eia = mo_e[:nocc, None] - mo_e[None, nocc:] eijab = lib.direct_sum('ia,jb->ijab', eia, eia) Foo = imd.cc_Foo(t1, t2, eris) Fvv = imd.cc_Fvv(t1, t2, eris) Fov = imd.cc_Fov(t1, t2, eris) Loo = imd.Loo(t1, t2, eris) Lvv = imd.Lvv(t1, t2, eris) Woooo = imd.cc_Woooo(t1, t2, eris) Wvvvv = imd.cc_Wvvvv(t1, t2, eris) Wvoov = imd.cc_Wvoov(t1, t2, eris) Wvovo = imd.cc_Wvovo(t1, t2, eris) # Move energy terms to the other side Foo -= foo Fvv -= fvv Loo -= foo Lvv -= fvv # T1 equation # TODO: Check this conj(). Hirata and Bartlett has # f_{vo}(a,i), which should be equal to f_{ov}^*(i,a) t1new = fov.conj().copy() t1new += -2 * einsum('kc,ka,ic->ia', fov, t1, t1) t1new += einsum('ac,ic->ia', Fvv, t1) t1new += -einsum('ki,ka->ia', Foo, t1) t1new += einsum('kc,kica->ia', Fov, 2 * t2) t1new += einsum('kc,ikca->ia', Fov, -t2) t1new += einsum('kc,ic,ka->ia', Fov, t1, t1) t1new += 2 * einsum('akic,kc->ia', eris.voov, t1) t1new += -einsum('kaic,kc->ia', eris.ovov, t1) t1new += 2 * einsum('akcd,ikcd->ia', eris.vovv, t2) t1new += -einsum('akdc,ikcd->ia', eris.vovv, t2) t1new += 2 * einsum('akcd,ic,kd->ia', eris.vovv, t1, t1) t1new += -einsum('akdc,ic,kd->ia', eris.vovv, t1, t1) t1new += -2 * einsum('klic,klac->ia', eris.ooov, t2) t1new += einsum('lkic,klac->ia', eris.ooov, t2) t1new += -2 * einsum('klic,ka,lc->ia', eris.ooov, t1, t1) t1new += einsum('lkic,ka,lc->ia', eris.ooov, t1, t1) # T2 equation # For conj(), see Hirata and Bartlett, Eq. (36) t2new = np.array(eris.oovv).conj() t2new += einsum('klij,klab->ijab', Woooo, t2) t2new += einsum('klij,ka,lb->ijab', Woooo, t1, t1) for a in range(nvir): Wvvvv_a = np.array(Wvvvv[a]) t2new[:, :, a, :] += einsum('bcd,ijcd->ijb', Wvvvv_a, t2) t2new[:, :, a, :] += einsum('bcd,ic,jd->ijb', Wvvvv_a, t1, t1) tmp = einsum('ac,ijcb->ijab', Lvv, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp = einsum('ki,kjab->ijab', Loo, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp2 = np.array(eris.vovv).transpose(3,2,1,0).conj() \ - einsum('kbic,ka->abic',eris.ovov,t1) tmp = einsum('abic,jc->ijab', tmp2, t1) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp2 = np.array(eris.ooov).transpose(3,2,1,0).conj() \ + einsum('akic,jc->akij',eris.voov,t1) tmp = einsum('akij,kb->ijab', tmp2, t1) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp = 2 * einsum('akic,kjcb->ijab', Wvoov, t2) - einsum( 'akci,kjcb->ijab', Wvovo, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp = einsum('akic,kjbc->ijab', Wvoov, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp = einsum('bkci,kjac->ijab', Wvovo, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) t1new /= eia t2new /= eijab time0 = log.timer_debug1('update t1 t2', *time0) return t1new, t2new
def update_amps(cc, t1, t2, eris): # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36) nocc, nvir = t1.shape fock = eris.fock fov = fock[:nocc, nocc:].copy() foo = fock[:nocc, :nocc].copy() fvv = fock[nocc:, nocc:].copy() Foo = imd.cc_Foo(t1, t2, eris) Fvv = imd.cc_Fvv(t1, t2, eris) Fov = imd.cc_Fov(t1, t2, eris) # Move energy terms to the other side Foo -= np.diag(np.diag(foo)) Fvv -= np.diag(np.diag(fvv)) # T1 equation t1new = np.asarray(fov).conj().copy() t1new += -2 * einsum('kc,ka,ic->ia', fov, t1, t1) t1new += einsum('ac,ic->ia', Fvv, t1) t1new += -einsum('ki,ka->ia', Foo, t1) t1new += 2 * einsum('kc,kica->ia', Fov, t2) t1new += -einsum('kc,ikca->ia', Fov, t2) t1new += einsum('kc,ic,ka->ia', Fov, t1, t1) t1new += 2 * einsum('kcai,kc->ia', eris.ovvo, t1) t1new += -einsum('kiac,kc->ia', eris.oovv, t1) eris_ovvv = np.asarray(eris.ovvv) t1new += 2 * einsum('kdac,ikcd->ia', eris_ovvv, t2) t1new += -einsum('kcad,ikcd->ia', eris_ovvv, t2) t1new += 2 * einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1) t1new += -einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1) t1new += -2 * einsum('kilc,klac->ia', eris.ooov, t2) t1new += einsum('likc,klac->ia', eris.ooov, t2) t1new += -2 * einsum('kilc,lc,ka->ia', eris.ooov, t1, t1) t1new += einsum('likc,lc,ka->ia', eris.ooov, t1, t1) # T2 equation t2new = np.asarray(eris.ovov).conj().transpose(0, 2, 1, 3).copy() if cc.cc2: Woooo2 = np.asarray(eris.oooo).transpose(0, 2, 1, 3).copy() Woooo2 += einsum('kilc,jc->klij', eris.ooov, t1) Woooo2 += einsum('ljkc,ic->klij', eris.ooov, t1) Woooo2 += einsum('kcld,ic,jd->klij', eris.ovov, t1, t1) t2new += einsum('klij,ka,lb->ijab', Woooo2, t1, t1) Wvvvv = einsum('kcbd,ka->abcd', eris_ovvv, -t1) Wvvvv = Wvvvv + Wvvvv.transpose(1, 0, 3, 2) Wvvvv += np.asarray(eris.vvvv).transpose(0, 2, 1, 3) t2new += einsum('abcd,ic,jd->ijab', Wvvvv, t1, t1) Lvv2 = fvv - einsum('kc,ka->ac', fov, t1) Lvv2 -= np.diag(np.diag(fvv)) tmp = einsum('ac,ijcb->ijab', Lvv2, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) Loo2 = foo + einsum('kc,ic->ki', fov, t1) Loo2 -= np.diag(np.diag(foo)) tmp = einsum('ki,kjab->ijab', Loo2, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) else: Loo = imd.Loo(t1, t2, eris) Lvv = imd.Lvv(t1, t2, eris) Loo -= np.diag(np.diag(foo)) Lvv -= np.diag(np.diag(fvv)) Woooo = imd.cc_Woooo(t1, t2, eris) Wvoov = imd.cc_Wvoov(t1, t2, eris) Wvovo = imd.cc_Wvovo(t1, t2, eris) Wvvvv = imd.cc_Wvvvv(t1, t2, eris) tau = t2 + einsum('ia,jb->ijab', t1, t1) t2new += einsum('klij,klab->ijab', Woooo, tau) t2new += einsum('abcd,ijcd->ijab', Wvvvv, tau) tmp = einsum('ac,ijcb->ijab', Lvv, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp = einsum('ki,kjab->ijab', Loo, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp = 2 * einsum('akic,kjcb->ijab', Wvoov, t2) tmp -= einsum('akci,kjcb->ijab', Wvovo, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp = einsum('akic,kjbc->ijab', Wvoov, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp = einsum('bkci,kjac->ijab', Wvovo, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp2 = einsum('kibc,ka->abic', eris.oovv, -t1) tmp2 += np.asarray(eris.ovvv).conj().transpose(1, 3, 0, 2) tmp = einsum('abic,jc->ijab', tmp2, t1) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp2 = einsum('kcai,jc->akij', eris.ovvo, t1) tmp2 += np.asarray(eris.ooov).transpose(3, 1, 2, 0).conj() tmp = einsum('akij,kb->ijab', tmp2, t1) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) mo_e = eris.fock.diagonal().real eia = mo_e[:nocc, None] - mo_e[None, nocc:] eijab = lib.direct_sum('ia,jb->ijab', eia, eia) t1new /= eia t2new /= eijab return t1new, t2new
def update_amps(cc, t1, t2, eris): # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36) assert(isinstance(eris, ccsd._ChemistsERIs)) nocc, nvir = t1.shape fock = eris.fock mo_e_o = eris.mo_energy[:nocc] mo_e_v = eris.mo_energy[nocc:] + cc.level_shift fov = fock[:nocc,nocc:].copy() foo = fock[:nocc,:nocc].copy() fvv = fock[nocc:,nocc:].copy() Foo = imd.cc_Foo(t1,t2,eris) Fvv = imd.cc_Fvv(t1,t2,eris) Fov = imd.cc_Fov(t1,t2,eris) # Move energy terms to the other side Foo[np.diag_indices(nocc)] -= mo_e_o Fvv[np.diag_indices(nvir)] -= mo_e_v #occ_act = np.arange(cc.frozen_occ,nocc) occ_act = np.arange(nocc) vir_act = np.arange(cc.nvir_act) #print("occ_act =", occ_act) #print("vir_act =", vir_act) ia_act = np.ix_(occ_act,vir_act) ijab_act = np.ix_(occ_act,occ_act,vir_act,vir_act) #print("ia =", ia_act) #print("ijab =", ijab_act) # T1 equation t1new = np.copy(fov.conj()) t1new[ia_act] -= 2*np.einsum('kc,ka,ic->ia', fov, t1, t1)[ia_act] t1new[ia_act] += np.einsum('ac,ic->ia', Fvv, t1)[ia_act] t1new[ia_act] += -np.einsum('ki,ka->ia', Foo, t1)[ia_act] t1new[ia_act] += 2*np.einsum('kc,kica->ia', Fov, t2)[ia_act] t1new[ia_act] += -np.einsum('kc,ikca->ia', Fov, t2)[ia_act] t1new[ia_act] += np.einsum('kc,ic,ka->ia', Fov, t1, t1)[ia_act] t1new[ia_act] += 2*np.einsum('kcai,kc->ia', eris.ovvo, t1)[ia_act] t1new[ia_act] += -np.einsum('kiac,kc->ia', eris.oovv, t1)[ia_act] eris_ovvv = np.asarray(eris.get_ovvv()) t1new[ia_act] += 2*lib.einsum('kdac,ikcd->ia', eris_ovvv, t2)[ia_act] t1new[ia_act] += -lib.einsum('kcad,ikcd->ia', eris_ovvv, t2)[ia_act] t1new[ia_act] += 2*lib.einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1)[ia_act] t1new[ia_act] += -lib.einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1)[ia_act] eris_ovoo = np.asarray(eris.ovoo, order='C') t1new[ia_act] +=-2*lib.einsum('lcki,klac->ia', eris_ovoo, t2)[ia_act] t1new[ia_act] += lib.einsum('kcli,klac->ia', eris_ovoo, t2)[ia_act] t1new[ia_act] +=-2*lib.einsum('lcki,lc,ka->ia', eris_ovoo, t1, t1)[ia_act] t1new[ia_act] += lib.einsum('kcli,lc,ka->ia', eris_ovoo, t1, t1)[ia_act] # T2 equation t2new = np.copy(np.asarray(eris.ovov).conj().transpose(0,2,1,3)) tmp2 = lib.einsum('kibc,ka->abic', eris.oovv, -t1) tmp2 += np.asarray(eris_ovvv).conj().transpose(1,3,0,2) tmp = lib.einsum('abic,jc->ijab', tmp2, t1) t2new[ijab_act] += (tmp + tmp.transpose(1,0,3,2))[ijab_act] tmp2 = lib.einsum('kcai,jc->akij', eris.ovvo, t1) tmp2 += eris_ovoo.transpose(1,3,0,2).conj() tmp = lib.einsum('akij,kb->ijab', tmp2, t1) t2new[ijab_act] -= (tmp + tmp.transpose(1,0,3,2))[ijab_act] Loo = imd.Loo(t1, t2, eris) Lvv = imd.Lvv(t1, t2, eris) Loo[np.diag_indices(nocc)] -= mo_e_o Lvv[np.diag_indices(nvir)] -= mo_e_v Woooo = imd.cc_Woooo(t1, t2, eris) Wvoov = imd.cc_Wvoov(t1, t2, eris) Wvovo = imd.cc_Wvovo(t1, t2, eris) Wvvvv = imd.cc_Wvvvv(t1, t2, eris) tau = t2 + np.einsum('ia,jb->ijab', t1, t1) t2new[ijab_act] += lib.einsum('klij,klab->ijab', Woooo, tau)[ijab_act] t2new[ijab_act] += lib.einsum('abcd,ijcd->ijab', Wvvvv, tau)[ijab_act] tmp = lib.einsum('ac,ijcb->ijab', Lvv, t2) t2new[ijab_act] += (tmp + tmp.transpose(1,0,3,2))[ijab_act] tmp = lib.einsum('ki,kjab->ijab', Loo, t2) t2new[ijab_act] -= (tmp + tmp.transpose(1,0,3,2))[ijab_act] tmp = 2*lib.einsum('akic,kjcb->ijab', Wvoov, t2) tmp -= lib.einsum('akci,kjcb->ijab', Wvovo, t2) t2new[ijab_act] += (tmp + tmp.transpose(1,0,3,2))[ijab_act] tmp = lib.einsum('akic,kjbc->ijab', Wvoov, t2) t2new[ijab_act] -= (tmp + tmp.transpose(1,0,3,2))[ijab_act] tmp = lib.einsum('bkci,kjac->ijab', Wvovo, t2) t2new[ijab_act] -= (tmp + tmp.transpose(1,0,3,2))[ijab_act] eia = mo_e_o[:,None] - mo_e_v eijab = lib.direct_sum('ia,jb->ijab',eia,eia) t1new /= eia t2new /= eijab return t1new, t2new
def update_amps(cc, t1, t2, eris): # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36) assert (isinstance(eris, ccsd._ChemistsERIs)) nocc, nvir = t1.shape fock = eris.fock mo_e_o = eris.mo_energy[:nocc] mo_e_v = eris.mo_energy[nocc:] + cc.level_shift fov = fock[:nocc, nocc:].copy() foo = fock[:nocc, :nocc].copy() fvv = fock[nocc:, nocc:].copy() Foo = imd.cc_Foo(t1, t2, eris) Fvv = imd.cc_Fvv(t1, t2, eris) Fov = imd.cc_Fov(t1, t2, eris) # Move energy terms to the other side Foo[np.diag_indices(nocc)] -= mo_e_o Fvv[np.diag_indices(nvir)] -= mo_e_v # T1 equation t1new = -2 * np.einsum('kc,ka,ic->ia', fov, t1, t1) t1new += np.einsum('ac,ic->ia', Fvv, t1) t1new += -np.einsum('ki,ka->ia', Foo, t1) t1new += 2 * np.einsum('kc,kica->ia', Fov, t2) t1new += -np.einsum('kc,ikca->ia', Fov, t2) t1new += np.einsum('kc,ic,ka->ia', Fov, t1, t1) t1new += fov.conj() t1new += 2 * np.einsum('kcai,kc->ia', eris.ovvo, t1) t1new += -np.einsum('kiac,kc->ia', eris.oovv, t1) eris_ovvv = np.asarray(eris.get_ovvv()) t1new += 2 * lib.einsum('kdac,ikcd->ia', eris_ovvv, t2) t1new += -lib.einsum('kcad,ikcd->ia', eris_ovvv, t2) t1new += 2 * lib.einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1) t1new += -lib.einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1) eris_ovoo = np.asarray(eris.ovoo, order='C') t1new += -2 * lib.einsum('lcki,klac->ia', eris_ovoo, t2) t1new += lib.einsum('kcli,klac->ia', eris_ovoo, t2) t1new += -2 * lib.einsum('lcki,lc,ka->ia', eris_ovoo, t1, t1) t1new += lib.einsum('kcli,lc,ka->ia', eris_ovoo, t1, t1) # T2 equation tmp2 = lib.einsum('kibc,ka->abic', eris.oovv, -t1) tmp2 += np.asarray(eris_ovvv).conj().transpose(1, 3, 0, 2) tmp = lib.einsum('abic,jc->ijab', tmp2, t1) t2new = tmp + tmp.transpose(1, 0, 3, 2) tmp2 = lib.einsum('kcai,jc->akij', eris.ovvo, t1) tmp2 += eris_ovoo.transpose(1, 3, 0, 2).conj() tmp = lib.einsum('akij,kb->ijab', tmp2, t1) t2new -= tmp + tmp.transpose(1, 0, 3, 2) t2new += np.asarray(eris.ovov).conj().transpose(0, 2, 1, 3) if cc.cc2: Woooo2 = np.asarray(eris.oooo).transpose(0, 2, 1, 3).copy() Woooo2 += lib.einsum('lcki,jc->klij', eris_ovoo, t1) Woooo2 += lib.einsum('kclj,ic->klij', eris_ovoo, t1) Woooo2 += lib.einsum('kcld,ic,jd->klij', eris.ovov, t1, t1) t2new += lib.einsum('klij,ka,lb->ijab', Woooo2, t1, t1) Wvvvv = lib.einsum('kcbd,ka->abcd', eris_ovvv, -t1) Wvvvv = Wvvvv + Wvvvv.transpose(1, 0, 3, 2) Wvvvv += np.asarray(eris.vvvv).transpose(0, 2, 1, 3) t2new += lib.einsum('abcd,ic,jd->ijab', Wvvvv, t1, t1) Lvv2 = fvv - np.einsum('kc,ka->ac', fov, t1) Lvv2 -= np.diag(np.diag(fvv)) tmp = lib.einsum('ac,ijcb->ijab', Lvv2, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) Loo2 = foo + np.einsum('kc,ic->ki', fov, t1) Loo2 -= np.diag(np.diag(foo)) tmp = lib.einsum('ki,kjab->ijab', Loo2, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) else: Loo = imd.Loo(t1, t2, eris) Lvv = imd.Lvv(t1, t2, eris) Loo[np.diag_indices(nocc)] -= mo_e_o Lvv[np.diag_indices(nvir)] -= mo_e_v Woooo = imd.cc_Woooo(t1, t2, eris) Wvoov = imd.cc_Wvoov(t1, t2, eris) Wvovo = imd.cc_Wvovo(t1, t2, eris) Wvvvv = imd.cc_Wvvvv(t1, t2, eris) tau = t2 + np.einsum('ia,jb->ijab', t1, t1) t2new += lib.einsum('klij,klab->ijab', Woooo, tau) t2new += lib.einsum('abcd,ijcd->ijab', Wvvvv, tau) tmp = lib.einsum('ac,ijcb->ijab', Lvv, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp = lib.einsum('ki,kjab->ijab', Loo, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp = 2 * lib.einsum('akic,kjcb->ijab', Wvoov, t2) tmp -= lib.einsum('akci,kjcb->ijab', Wvovo, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp = lib.einsum('akic,kjbc->ijab', Wvoov, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp = lib.einsum('bkci,kjac->ijab', Wvovo, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) eia = mo_e_o[:, None] - mo_e_v eijab = lib.direct_sum('ia,jb->ijab', eia, eia) t1new /= eia t2new /= eijab return t1new, t2new
def update_amps(cc, t1, t2, eris): # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36) time0 = time.clock(), time.time() log = logger.Logger(cc.stdout, cc.verbose) nocc, nvir = t1.shape fock = eris.fock fov = fock[:nocc,nocc:] foo = fock[:nocc,:nocc] fvv = fock[nocc:,nocc:] mo_e = eris.fock.diagonal() eia = mo_e[:nocc,None] - mo_e[None,nocc:] eijab = lib.direct_sum('ia,jb->ijab',eia,eia) Foo = imd.cc_Foo(t1,t2,eris) Fvv = imd.cc_Fvv(t1,t2,eris) Fov = imd.cc_Fov(t1,t2,eris) Loo = imd.Loo(t1,t2,eris) Lvv = imd.Lvv(t1,t2,eris) Woooo = imd.cc_Woooo(t1,t2,eris) Wvvvv = imd.cc_Wvvvv(t1,t2,eris) Wvoov = imd.cc_Wvoov(t1,t2,eris) Wvovo = imd.cc_Wvovo(t1,t2,eris) # Move energy terms to the other side Foo -= np.diag(np.diag(foo)) Fvv -= np.diag(np.diag(fvv)) Loo -= np.diag(np.diag(foo)) Lvv -= np.diag(np.diag(fvv)) # T1 equation t1new = np.array(fov).conj() t1new += -2*einsum('kc,ka,ic->ia',fov,t1,t1) t1new += einsum('ac,ic->ia',Fvv,t1) t1new += -einsum('ki,ka->ia',Foo,t1) t1new += 2*einsum('kc,kica->ia',Fov,t2) t1new += -einsum('kc,ikca->ia',Fov,t2) t1new += einsum('kc,ic,ka->ia',Fov,t1,t1) t1new += 2*einsum('akic,kc->ia',eris.voov,t1) t1new += -einsum('kaic,kc->ia',eris.ovov,t1) t1new += 2*einsum('akcd,ikcd->ia',eris.vovv,t2) t1new += -einsum('akdc,ikcd->ia',eris.vovv,t2) t1new += 2*einsum('akcd,ic,kd->ia',eris.vovv,t1,t1) t1new += -einsum('akdc,ic,kd->ia',eris.vovv,t1,t1) t1new += -2*einsum('klic,klac->ia',eris.ooov,t2) t1new += einsum('lkic,klac->ia',eris.ooov,t2) t1new += -2*einsum('klic,ka,lc->ia',eris.ooov,t1,t1) t1new += einsum('lkic,ka,lc->ia',eris.ooov,t1,t1) # T2 equation t2new = np.array(eris.oovv).conj() t2new += einsum('klij,klab->ijab',Woooo,t2) t2new += einsum('klij,ka,lb->ijab',Woooo,t1,t1) for a in range(nvir): Wvvvv_a = np.array(Wvvvv[a]) t2new[:,:,a,:] += einsum('bcd,ijcd->ijb',Wvvvv_a,t2) t2new[:,:,a,:] += einsum('bcd,ic,jd->ijb',Wvvvv_a,t1,t1) tmp = einsum('ac,ijcb->ijab',Lvv,t2) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp = einsum('ki,kjab->ijab',Loo,t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp2 = np.array(eris.vovv).transpose(3,2,1,0).conj() \ - einsum('kbic,ka->abic',eris.ovov,t1) tmp = einsum('abic,jc->ijab',tmp2,t1) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp2 = np.array(eris.ooov).transpose(3,2,1,0).conj() \ + einsum('akic,jc->akij',eris.voov,t1) tmp = einsum('akij,kb->ijab',tmp2,t1) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp = 2*einsum('akic,kjcb->ijab',Wvoov,t2) - einsum('akci,kjcb->ijab',Wvovo,t2) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp = einsum('akic,kjbc->ijab',Wvoov,t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp = einsum('bkci,kjac->ijab',Wvovo,t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) t1new /= eia t2new /= eijab time0 = log.timer_debug1('update t1 t2', *time0) return t1new, t2new
def update_amps(cc, t1, t2, eris, max_memory=2000): time0 = time.clock(), time.time() log = logger.Logger(cc.stdout, cc.verbose) nocc, nvir = t1.shape fock = eris.fock fov = fock[:nocc,nocc:] foo = fock[:nocc,:nocc] fvv = fock[nocc:,nocc:] mo_e = eris.fock.diagonal() eia = mo_e[:nocc,None] - mo_e[None,nocc:] eijab = lib.direct_sum('ia,jb->ijab',eia,eia) Foo = imd.cc_Foo(t1,t2,eris) Fvv = imd.cc_Fvv(t1,t2,eris) Fov = imd.cc_Fov(t1,t2,eris) Loo = imd.Loo(t1,t2,eris) Lvv = imd.Lvv(t1,t2,eris) Woooo = imd.cc_Woooo(t1,t2,eris) Wvvvv = imd.cc_Wvvvv(t1,t2,eris) Wvoov = imd.cc_Wvoov(t1,t2,eris) Wvovo = imd.cc_Wvovo(t1,t2,eris) # Move energy terms to the other side Foo -= foo Fvv -= fvv Loo -= foo Lvv -= fvv # T1 equation # TODO: Check this conj(). Hirata and Bartlett has # f_{vo}(a,i), which should be equal to f_{ov}^*(i,a) t1new = fov.conj().copy() t1new += -2*einsum('kc,ka,ic->ia',fov,t1,t1) t1new += einsum('ac,ic->ia',Fvv,t1) t1new += -einsum('ki,ka->ia',Foo,t1) t1new += einsum('kc,kica->ia',Fov,2*t2) t1new += einsum('kc,ikca->ia',Fov, -t2) t1new += einsum('kc,ic,ka->ia',Fov,t1,t1) t1new += 2*einsum('akic,kc->ia',eris.voov,t1) t1new += -einsum('kaic,kc->ia',eris.ovov,t1) t1new += 2*einsum('akcd,ikcd->ia',eris.vovv,t2) t1new += -einsum('akdc,ikcd->ia',eris.vovv,t2) t1new += 2*einsum('akcd,ic,kd->ia',eris.vovv,t1,t1) t1new += -einsum('akdc,ic,kd->ia',eris.vovv,t1,t1) t1new += -2*einsum('klic,klac->ia',eris.ooov,t2) t1new += einsum('lkic,klac->ia',eris.ooov,t2) t1new += -2*einsum('klic,ka,lc->ia',eris.ooov,t1,t1) t1new += einsum('lkic,ka,lc->ia',eris.ooov,t1,t1) # T2 equation # For conj(), see Hirata and Bartlett, Eq. (36) t2new = np.array(eris.oovv).conj() t2new += einsum('klij,klab->ijab',Woooo,t2) t2new += einsum('klij,ka,lb->ijab',Woooo,t1,t1) for a in range(nvir): Wvvvv_a = np.array(Wvvvv[a]) t2new[:,:,a,:] += einsum('bcd,ijcd->ijb',Wvvvv_a,t2) t2new[:,:,a,:] += einsum('bcd,ic,jd->ijb',Wvvvv_a,t1,t1) tmp = einsum('ac,ijcb->ijab',Lvv,t2) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp = einsum('ki,kjab->ijab',Loo,t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp2 = np.array(eris.vovv).transpose(3,2,1,0).conj() \ - einsum('kbic,ka->abic',eris.ovov,t1) tmp = einsum('abic,jc->ijab',tmp2,t1) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp2 = np.array(eris.ooov).transpose(3,2,1,0).conj() \ + einsum('akic,jc->akij',eris.voov,t1) tmp = einsum('akij,kb->ijab',tmp2,t1) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp = 2*einsum('akic,kjcb->ijab',Wvoov,t2) - einsum('akci,kjcb->ijab',Wvovo,t2) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp = einsum('akic,kjbc->ijab',Wvoov,t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp = einsum('bkci,kjac->ijab',Wvovo,t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) t1new /= eia t2new /= eijab time0 = log.timer_debug1('update t1 t2', *time0) return t1new, t2new
def update_amps(cc, t1, t2, eris): # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36) nocc, nvir = t1.shape fock = eris.fock fov = fock[:nocc,nocc:].copy() foo = fock[:nocc,:nocc].copy() fvv = fock[nocc:,nocc:].copy() Foo = imd.cc_Foo(t1,t2,eris) Fvv = imd.cc_Fvv(t1,t2,eris) Fov = imd.cc_Fov(t1,t2,eris) # Move energy terms to the other side Foo -= np.diag(np.diag(foo)) Fvv -= np.diag(np.diag(fvv)) # T1 equation t1new = np.asarray(fov).conj().copy() t1new +=-2*einsum('kc,ka,ic->ia', fov, t1, t1) t1new += einsum('ac,ic->ia', Fvv, t1) t1new += -einsum('ki,ka->ia', Foo, t1) t1new += 2*einsum('kc,kica->ia', Fov, t2) t1new += -einsum('kc,ikca->ia', Fov, t2) t1new += einsum('kc,ic,ka->ia', Fov, t1, t1) t1new += 2*einsum('kcai,kc->ia', eris.ovvo, t1) t1new += -einsum('kiac,kc->ia', eris.oovv, t1) eris_ovvv = np.asarray(eris.ovvv) t1new += 2*einsum('kdac,ikcd->ia', eris_ovvv, t2) t1new += -einsum('kcad,ikcd->ia', eris_ovvv, t2) t1new += 2*einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1) t1new += -einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1) t1new +=-2*einsum('kilc,klac->ia', eris.ooov, t2) t1new += einsum('likc,klac->ia', eris.ooov, t2) t1new +=-2*einsum('kilc,lc,ka->ia', eris.ooov, t1, t1) t1new += einsum('likc,lc,ka->ia', eris.ooov, t1, t1) # T2 equation t2new = np.asarray(eris.ovov).conj().transpose(0,2,1,3).copy() if cc.cc2: Woooo2 = np.asarray(eris.oooo).transpose(0,2,1,3).copy() Woooo2 += einsum('kilc,jc->klij', eris.ooov, t1) Woooo2 += einsum('ljkc,ic->klij', eris.ooov, t1) Woooo2 += einsum('kcld,ic,jd->klij', eris.ovov, t1, t1) t2new += einsum('klij,ka,lb->ijab', Woooo2, t1, t1) Wvvvv = einsum('kcbd,ka->abcd', eris_ovvv, -t1) Wvvvv = Wvvvv + Wvvvv.transpose(1,0,3,2) Wvvvv += np.asarray(eris.vvvv).transpose(0,2,1,3) t2new += einsum('abcd,ic,jd->ijab', Wvvvv, t1, t1) Lvv2 = fvv - einsum('kc,ka->ac', fov, t1) Lvv2 -= np.diag(np.diag(fvv)) tmp = einsum('ac,ijcb->ijab', Lvv2, t2) t2new += (tmp + tmp.transpose(1,0,3,2)) Loo2 = foo + einsum('kc,ic->ki', fov, t1) Loo2 -= np.diag(np.diag(foo)) tmp = einsum('ki,kjab->ijab', Loo2, t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) else: Loo = imd.Loo(t1, t2, eris) Lvv = imd.Lvv(t1, t2, eris) Loo -= np.diag(np.diag(foo)) Lvv -= np.diag(np.diag(fvv)) Woooo = imd.cc_Woooo(t1, t2, eris) Wvoov = imd.cc_Wvoov(t1, t2, eris) Wvovo = imd.cc_Wvovo(t1, t2, eris) Wvvvv = imd.cc_Wvvvv(t1, t2, eris) tau = t2 + einsum('ia,jb->ijab', t1, t1) t2new += einsum('klij,klab->ijab', Woooo, tau) t2new += einsum('abcd,ijcd->ijab', Wvvvv, tau) tmp = einsum('ac,ijcb->ijab', Lvv, t2) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp = einsum('ki,kjab->ijab', Loo, t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp = 2*einsum('akic,kjcb->ijab', Wvoov, t2) tmp -= einsum('akci,kjcb->ijab', Wvovo, t2) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp = einsum('akic,kjbc->ijab', Wvoov, t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp = einsum('bkci,kjac->ijab', Wvovo, t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp2 = einsum('kibc,ka->abic', eris.oovv, -t1) tmp2 += np.asarray(eris.ovvv).conj().transpose(1,3,0,2) tmp = einsum('abic,jc->ijab', tmp2, t1) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp2 = einsum('kcai,jc->akij', eris.ovvo, t1) tmp2 += np.asarray(eris.ooov).transpose(3,1,2,0).conj() tmp = einsum('akij,kb->ijab', tmp2, t1) t2new -= (tmp + tmp.transpose(1,0,3,2)) mo_e = eris.fock.diagonal().real eia = mo_e[:nocc,None] - mo_e[None,nocc:] eijab = lib.direct_sum('ia,jb->ijab',eia,eia) t1new /= eia t2new /= eijab return t1new, t2new
def update_amps(cc, t1, t2, eris): # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36) nocc, nvir = t1.shape fock = eris.fock fov = fock[:nocc, nocc:].copy() foo = fock[:nocc, :nocc].copy() fvv = fock[nocc:, nocc:].copy() Foo = imd.cc_Foo(0 * t1, t2, eris) Fvv = imd.cc_Fvv(0 * t1, t2, eris) Fov = imd.cc_Fov(t1, t2, eris) Foo -= np.diag(np.diag(foo)) Fvv -= np.diag(np.diag(fvv)) # T1 equation t1new = np.asarray(fov).conj().copy() t1new += lib.einsum('ac,ic->ia', Fvv, t1) t1new += -lib.einsum('ki,ka->ia', Foo, t1) t1new += 2 * lib.einsum('kc,kica->ia', Fov, t2) t1new += -lib.einsum('kc,ikca->ia', Fov, t2) t1new += 2 * lib.einsum('kcai,kc->ia', eris.ovvo, t1) t1new += -lib.einsum('kiac,kc->ia', eris.oovv, t1) eris_ovvv = np.asarray(eris.ovvv) t1new += 2 * lib.einsum('kdac,ikcd->ia', eris_ovvv, t2) t1new += -lib.einsum('kcad,ikcd->ia', eris_ovvv, t2) t1new += -2 * lib.einsum('kilc,klac->ia', eris.ooov, t2) t1new += lib.einsum('likc,klac->ia', eris.ooov, t2) # T2 equation t2new = np.asarray(eris.ovov).conj().transpose(0, 2, 1, 3).copy() Loo = imd.Loo(0 * t1, t2, eris) Lvv = imd.Lvv(0 * t1, t2, eris) Loo -= np.diag(np.diag(foo)) Lvv -= np.diag(np.diag(fvv)) Woooo = imd.cc_Woooo(0 * t1, t2, eris) Wvoov = imd.cc_Wvoov(0 * t1, t2, eris) Wvovo = imd.cc_Wvovo(0 * t1, t2, eris) Wvvvv = imd.cc_Wvvvv(0 * t1, t2, eris) t2new += lib.einsum('klij,klab->ijab', Woooo, t2) t2new += lib.einsum('abcd,ijcd->ijab', Wvvvv, t2) tmp = lib.einsum('ac,ijcb->ijab', Lvv, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp = lib.einsum('ki,kjab->ijab', Loo, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp = 2 * lib.einsum('akic,kjcb->ijab', Wvoov, t2) tmp -= lib.einsum('akci,kjcb->ijab', Wvovo, t2) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp = lib.einsum('akic,kjbc->ijab', Wvoov, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp = lib.einsum('bkci,kjac->ijab', Wvovo, t2) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) tmp2 = np.asarray(eris.ovvv).conj().transpose(1, 3, 0, 2) tmp = lib.einsum('abic,jc->ijab', tmp2, t1) t2new += (tmp + tmp.transpose(1, 0, 3, 2)) tmp2 = np.asarray(eris.ooov).transpose(3, 1, 2, 0).conj() tmp = lib.einsum('akij,kb->ijab', tmp2, t1) t2new -= (tmp + tmp.transpose(1, 0, 3, 2)) mo_e = eris.fock.diagonal().real eia = mo_e[:nocc, None] - mo_e[None, nocc:] eijab = lib.direct_sum('ia,jb->ijab', eia, eia) t1new /= eia t2new /= eijab return t1new, t2new
def update_amps(cc, t1, t2, eris): # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36) assert(isinstance(eris, ccsd._ChemistsERIs)) nocc, nvir = t1.shape fock = eris.fock mo_e_o = eris.mo_energy[:nocc] mo_e_v = eris.mo_energy[nocc:] + cc.level_shift fov = fock[:nocc,nocc:].copy() foo = fock[:nocc,:nocc].copy() fvv = fock[nocc:,nocc:].copy() Foo = imd.cc_Foo(t1,t2,eris) Fvv = imd.cc_Fvv(t1,t2,eris) Fov = imd.cc_Fov(t1,t2,eris) # Move energy terms to the other side Foo[np.diag_indices(nocc)] -= mo_e_o Fvv[np.diag_indices(nvir)] -= mo_e_v # T1 equation t1new =-2*np.einsum('kc,ka,ic->ia', fov, t1, t1) t1new += np.einsum('ac,ic->ia', Fvv, t1) t1new += -np.einsum('ki,ka->ia', Foo, t1) t1new += 2*np.einsum('kc,kica->ia', Fov, t2) t1new += -np.einsum('kc,ikca->ia', Fov, t2) t1new += np.einsum('kc,ic,ka->ia', Fov, t1, t1) t1new += fov.conj() t1new += 2*np.einsum('kcai,kc->ia', eris.ovvo, t1) t1new += -np.einsum('kiac,kc->ia', eris.oovv, t1) eris_ovvv = np.asarray(eris.get_ovvv()) t1new += 2*lib.einsum('kdac,ikcd->ia', eris_ovvv, t2) t1new += -lib.einsum('kcad,ikcd->ia', eris_ovvv, t2) t1new += 2*lib.einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1) t1new += -lib.einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1) eris_ovoo = np.asarray(eris.ovoo, order='C') t1new +=-2*lib.einsum('lcki,klac->ia', eris_ovoo, t2) t1new += lib.einsum('kcli,klac->ia', eris_ovoo, t2) t1new +=-2*lib.einsum('lcki,lc,ka->ia', eris_ovoo, t1, t1) t1new += lib.einsum('kcli,lc,ka->ia', eris_ovoo, t1, t1) # T2 equation tmp2 = lib.einsum('kibc,ka->abic', eris.oovv, -t1) tmp2 += np.asarray(eris_ovvv).conj().transpose(1,3,0,2) tmp = lib.einsum('abic,jc->ijab', tmp2, t1) t2new = tmp + tmp.transpose(1,0,3,2) tmp2 = lib.einsum('kcai,jc->akij', eris.ovvo, t1) tmp2 += eris_ovoo.transpose(1,3,0,2).conj() tmp = lib.einsum('akij,kb->ijab', tmp2, t1) t2new -= tmp + tmp.transpose(1,0,3,2) t2new += np.asarray(eris.ovov).conj().transpose(0,2,1,3) if cc.cc2: Woooo2 = np.asarray(eris.oooo).transpose(0,2,1,3).copy() Woooo2 += lib.einsum('lcki,jc->klij', eris_ovoo, t1) Woooo2 += lib.einsum('kclj,ic->klij', eris_ovoo, t1) Woooo2 += lib.einsum('kcld,ic,jd->klij', eris.ovov, t1, t1) t2new += lib.einsum('klij,ka,lb->ijab', Woooo2, t1, t1) Wvvvv = lib.einsum('kcbd,ka->abcd', eris_ovvv, -t1) Wvvvv = Wvvvv + Wvvvv.transpose(1,0,3,2) Wvvvv += np.asarray(eris.vvvv).transpose(0,2,1,3) t2new += lib.einsum('abcd,ic,jd->ijab', Wvvvv, t1, t1) Lvv2 = fvv - np.einsum('kc,ka->ac', fov, t1) Lvv2 -= np.diag(np.diag(fvv)) tmp = lib.einsum('ac,ijcb->ijab', Lvv2, t2) t2new += (tmp + tmp.transpose(1,0,3,2)) Loo2 = foo + np.einsum('kc,ic->ki', fov, t1) Loo2 -= np.diag(np.diag(foo)) tmp = lib.einsum('ki,kjab->ijab', Loo2, t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) else: Loo = imd.Loo(t1, t2, eris) Lvv = imd.Lvv(t1, t2, eris) Loo[np.diag_indices(nocc)] -= mo_e_o Lvv[np.diag_indices(nvir)] -= mo_e_v Woooo = imd.cc_Woooo(t1, t2, eris) Wvoov = imd.cc_Wvoov(t1, t2, eris) Wvovo = imd.cc_Wvovo(t1, t2, eris) Wvvvv = imd.cc_Wvvvv(t1, t2, eris) tau = t2 + np.einsum('ia,jb->ijab', t1, t1) t2new += lib.einsum('klij,klab->ijab', Woooo, tau) t2new += lib.einsum('abcd,ijcd->ijab', Wvvvv, tau) tmp = lib.einsum('ac,ijcb->ijab', Lvv, t2) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp = lib.einsum('ki,kjab->ijab', Loo, t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp = 2*lib.einsum('akic,kjcb->ijab', Wvoov, t2) tmp -= lib.einsum('akci,kjcb->ijab', Wvovo, t2) t2new += (tmp + tmp.transpose(1,0,3,2)) tmp = lib.einsum('akic,kjbc->ijab', Wvoov, t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) tmp = lib.einsum('bkci,kjac->ijab', Wvovo, t2) t2new -= (tmp + tmp.transpose(1,0,3,2)) eia = mo_e_o[:,None] - mo_e_v eijab = lib.direct_sum('ia,jb->ijab',eia,eia) t1new /= eia t2new /= eijab return t1new, t2new