def cc_Wovvo(t1,t2,eris): eris_ovvo = - _cp(eris.ovov).transpose(0,1,3,2) eris_oovo = - _cp(eris.ooov).transpose(0,1,3,2) Wmbej = eris_ovvo.copy() Wmbej += einsum('jf,mbef->mbej',t1,eris.ovvv) Wmbej += -einsum('nb,mnej->mbej',t1,eris_oovo) Wmbej += -0.5*einsum('jnfb,mnef->mbej',t2,eris.oovv) Wmbej += -einsum('jf,nb,mnef->mbej',t1,t1,eris.oovv) return Wmbej
def cc_Wovvo(t1, t2, eris): eris_ovvo = -_cp(eris.ovov).transpose(0, 1, 3, 2) eris_oovo = -_cp(eris.ooov).transpose(0, 1, 3, 2) Wmbej = eris_ovvo.copy() Wmbej += einsum('jf,mbef->mbej', t1, eris.ovvv) Wmbej += -einsum('nb,mnej->mbej', t1, eris_oovo) Wmbej += -0.5 * einsum('jnfb,mnef->mbej', t2, eris.oovv) Wmbej += -einsum('jf,nb,mnef->mbej', t1, t1, eris.oovv) return Wmbej
def init_amps(self, eris): time0 = time.clock(), time.time() mo_e = eris.fock.diagonal() nocc = self.nocc() nvir = mo_e.size - nocc t1 = np.zeros((nocc,nvir), eris.dtype) #eia = mo_e[:nocc,None] - mo_e[None,nocc:] #t1 = eris.fock[:nocc,nocc:] / eia t2 = np.zeros((nocc,nocc,nvir,nvir), eris.dtype) self.emp2 = 0 foo = eris.fock[:nocc,:nocc] fvv = eris.fock[nocc:,nocc:] eia = np.zeros((nocc,nvir)) eijab = np.zeros((nocc,nocc,nvir,nvir)) for i in range(nocc): for a in range(nvir): eia[i,a] = (foo[i,i] - fvv[a,a]).real for j in range(nocc): for b in range(nvir): eijab[i,j,a,b] = ( foo[i,i] + foo[j,j] - fvv[a,a] - fvv[b,b] ).real t2[i,j,a,b] = eris.oovv[i,j,a,b]/eijab[i,j,a,b] eris_oovv = _cp(eris.oovv) self.emp2 = 0.25*einsum('ijab,ijab',t2,eris_oovv.conj()).real logger.info(self, 'Init t2, MP2 energy = %.15g', self.emp2) logger.timer(self, 'init mp2', *time0) return self.emp2, t1, t2
def Wvvvo(t1,t2,eris): eris_ovvo = - _cp(eris.ovov).transpose(0,1,3,2) eris_vvvo = - _cp(eris.ovvv).transpose(2,3,1,0).conj() eris_oovo = - _cp(eris.ooov).transpose(0,1,3,2) tmp1 = einsum('mbef,miaf->abei',eris.ovvv,t2) tmp2 = ( einsum('ma,mbei->abei',t1,eris_ovvo) - einsum('ma,nibf,mnef->abei',t1,t2,eris.oovv) ) FFov = Fov(t1,t2,eris) WWvvvv = Wvvvv(t1,t2,eris) tau = make_tau(t2,t1,t1) Wabei = ( eris_vvvo - einsum('me,miab->abei',FFov,t2) + einsum('if,abef->abei',t1,WWvvvv) + 0.5 * einsum('mnei,mnab->abei',eris_oovo,tau) - tmp1 + tmp1.transpose(1,0,2,3) - tmp2 + tmp2.transpose(1,0,2,3) ) return Wabei
def cc_Wvvvv(t1,t2,eris): eris_vovv = _cp(eris.ovvv).transpose(1,0,3,2) tau = make_tau(t2,t1,t1) tmp = einsum('mb,amef->abef',t1,eris_vovv) Wabef = eris.vvvv - tmp + tmp.transpose(1,0,2,3) Wabef += 0.25*einsum('mnab,mnef->abef',tau,eris.oovv) return Wabef
def Wvvvo_incore(t1, t2, eris): eris_ovvo = -_cp(eris.ovov).transpose(0, 1, 3, 2) eris_vvvo = -_cp(eris.ovvv).transpose(2, 3, 1, 0).conj() eris_oovo = -_cp(eris.ooov).transpose(0, 1, 3, 2) tmp1 = einsum('mbef,miaf->abei', eris.ovvv, t2) tmp2 = (einsum('ma,mbei->abei', t1, eris_ovvo) - einsum('ma,nibf,mnef->abei', t1, t2, eris.oovv)) FFov = Fov(t1, t2, eris) #TODO: Wasteful to create Wvvvv twice (now cc_Wvvvv three times!) WWvvvv = Wvvvv(t1, t2, eris) tau = make_tau(t2, t1, t1) Wabei = (eris_vvvo - einsum('me,miab->abei', FFov, t2) + einsum('if,abef->abei', t1, WWvvvv) + 0.5 * einsum('mnei,mnab->abei', eris_oovo, tau) - tmp1 + tmp1.transpose(1, 0, 2, 3) - tmp2 + tmp2.transpose(1, 0, 2, 3)) return Wabei
def Wvvvo_incore(t1,t2,eris): eris_ovvo = - _cp(eris.ovov).transpose(0,1,3,2) eris_vvvo = - _cp(eris.ovvv).transpose(2,3,1,0).conj() eris_oovo = - _cp(eris.ooov).transpose(0,1,3,2) tmp1 = einsum('mbef,miaf->abei',eris.ovvv,t2) tmp2 = ( einsum('ma,mbei->abei',t1,eris_ovvo) - einsum('ma,nibf,mnef->abei',t1,t2,eris.oovv) ) FFov = Fov(t1,t2,eris) #TODO: Wasteful to create Wvvvv twice (now cc_Wvvvv three times!) WWvvvv = Wvvvv(t1,t2,eris) tau = make_tau(t2,t1,t1) Wabei = ( eris_vvvo - einsum('me,miab->abei',FFov,t2) + einsum('if,abef->abei',t1,WWvvvv) + 0.5 * einsum('mnei,mnab->abei',eris_oovo,tau) - tmp1 + tmp1.transpose(1,0,2,3) - tmp2 + tmp2.transpose(1,0,2,3) ) return Wabei
def cc_Fvv(t1, t2, eris): nocc, nvir = t1.shape fov = eris.fock[:nocc, nocc:] fvv = eris.fock[nocc:, nocc:] eris_vovv = _cp(eris.ovvv).transpose(1, 0, 3, 2) tau_tilde = make_tau(t2, t1, t1, fac=0.5) Fae = (fvv - 0.5 * einsum('me,ma->ae', fov, t1) + einsum('mf,amef->ae', t1, eris_vovv) - 0.5 * einsum('mnaf,mnef->ae', tau_tilde, eris.oovv)) return Fae
def cc_Fvv(t1,t2,eris): nocc, nvir = t1.shape fov = eris.fock[:nocc,nocc:] fvv = eris.fock[nocc:,nocc:] eris_vovv = _cp(eris.ovvv).transpose(1,0,3,2) tau_tilde = make_tau(t2,t1,t1,fac=0.5) Fae = ( fvv - 0.5*einsum('me,ma->ae',fov,t1) + einsum('mf,amef->ae',t1,eris_vovv) - 0.5*einsum('mnaf,mnef->ae',tau_tilde,eris.oovv) ) return Fae
def Wvvvo(t1, t2, eris): eris_ovvo = -_cp(eris.ovov).transpose(0, 1, 3, 2) eris_vvvo = -_cp(eris.ovvv).transpose(2, 3, 1, 0).conj() eris_oovo = -_cp(eris.ooov).transpose(0, 1, 3, 2) tmp1 = einsum('mbef,miaf->abei', eris.ovvv, t2) tmp2 = (einsum('ma,mbei->abei', t1, eris_ovvo) - einsum('ma,nibf,mnef->abei', t1, t2, eris.oovv)) FFov = Fov(t1, t2, eris) tau = make_tau(t2, t1, t1) Wabei = eris_vvvo Wabei += -einsum('me,miab->abei', FFov, t2) Wabei += 0.5 * einsum('mnei,mnab->abei', eris_oovo, tau) Wabei += -tmp1 + tmp1.transpose(1, 0, 2, 3) Wabei += -tmp2 + tmp2.transpose(1, 0, 2, 3) nocc, nvir = t1.shape #TODO: Wasteful to create Wvvvv twice (now cc_Wvvvv three times!) _Wvvvv = Wvvvv(t1, t2, eris) for a in range(nvir): Wabei[a] += einsum('if,bef->bei', t1, _Wvvvv[a]) return Wabei
def energy(cc, t1, t2, eris): nocc, nvir = t1.shape fock = eris.fock e = einsum('ia,ia', fock[:nocc,nocc:], t1) t1t1 = einsum('ia,jb->ijab',t1,t1) tau = t2 + 2*t1t1 eris_oovv = _cp(eris.oovv) e += 0.25 * np.dot(tau.flatten(), eris_oovv.flatten()) #e += (0.25*np.einsum('ijab,ijab',t2,eris_oovv) # + 0.5*np.einsum('ia,jb,ijab',t1,t1,eris_oovv)) return e.real
def Wvvvo(t1,t2,eris): eris_ovvo = - _cp(eris.ovov).transpose(0,1,3,2) eris_vvvo = - _cp(eris.ovvv).transpose(2,3,1,0).conj() eris_oovo = - _cp(eris.ooov).transpose(0,1,3,2) tmp1 = einsum('mbef,miaf->abei',eris.ovvv,t2) tmp2 = ( einsum('ma,mbei->abei',t1,eris_ovvo) - einsum('ma,nibf,mnef->abei',t1,t2,eris.oovv) ) FFov = Fov(t1,t2,eris) tau = make_tau(t2,t1,t1) Wabei = eris_vvvo Wabei += -einsum('me,miab->abei',FFov,t2) Wabei += 0.5 * einsum('mnei,mnab->abei',eris_oovo,tau) Wabei += -tmp1 + tmp1.transpose(1,0,2,3) Wabei += -tmp2 + tmp2.transpose(1,0,2,3) nocc,nvir = t1.shape #TODO: Wasteful to create Wvvvv twice (now cc_Wvvvv three times!) _Wvvvv = Wvvvv(t1,t2,eris) for a in range(nvir): Wabei[a] += einsum('if,bef->bei',t1,_Wvvvv[a]) return Wabei
def Wovoo(t1, t2, eris): eris_ovvo = -_cp(eris.ovov).transpose(0, 1, 3, 2) tmp1 = einsum('mnie,jnbe->mbij', eris.ooov, t2) tmp2 = (einsum('ie,mbej->mbij', t1, eris_ovvo) - einsum('ie,njbf,mnef->mbij', t1, t2, eris.oovv)) FFov = Fov(t1, t2, eris) WWoooo = Woooo(t1, t2, eris) tau = make_tau(t2, t1, t1) Wmbij = (eris.ovoo - einsum('me,ijbe->mbij', FFov, t2) - einsum('nb,mnij->mbij', t1, WWoooo) + 0.5 * einsum('mbef,ijef->mbij', eris.ovvv, tau) + tmp1 - tmp1.transpose(0, 1, 3, 2) + tmp2 - tmp2.transpose(0, 1, 3, 2)) return Wmbij
def Wovoo(t1,t2,eris): eris_ovvo = - _cp(eris.ovov).transpose(0,1,3,2) tmp1 = einsum('mnie,jnbe->mbij',eris.ooov,t2) tmp2 = ( einsum('ie,mbej->mbij',t1,eris_ovvo) - einsum('ie,njbf,mnef->mbij',t1,t2,eris.oovv) ) FFov = Fov(t1,t2,eris) WWoooo = Woooo(t1,t2,eris) tau = make_tau(t2,t1,t1) Wmbij = ( eris.ovoo - einsum('me,ijbe->mbij',FFov,t2) - einsum('nb,mnij->mbij',t1,WWoooo) + 0.5 * einsum('mbef,ijef->mbij',eris.ovvv,tau) + tmp1 - tmp1.transpose(0,1,3,2) + tmp2 - tmp2.transpose(0,1,3,2) ) return Wmbij
def Wvovv(t1, t2, eris): eris_vovv = -_cp(eris.ovvv).transpose(1, 0, 2, 3) Wamef = eris_vovv - einsum('na,nmef->amef', t1, eris.oovv) return Wamef
def Wvovv(t1,t2,eris): eris_vovv = - _cp(eris.ovvv).transpose(1,0,2,3) Wamef = eris_vovv - einsum('na,nmef->amef',t1,eris.oovv) return Wamef
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 #nov = nocc*nvir fock = eris.fock #t1new = numpy.zeros_like(t1) #t2new = numpy.zeros_like(t2) 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) tau = imd.make_tau(t2,t1,t1) Fvv = imd.cc_Fvv(t1,t2,eris) Foo = imd.cc_Foo(t1,t2,eris) Fov = imd.cc_Fov(t1,t2,eris) Woooo = imd.cc_Woooo(t1,t2,eris) Wvvvv = imd.cc_Wvvvv(t1,t2,eris) Wovvo = imd.cc_Wovvo(t1,t2,eris) # Move energy terms to the other side Fvv -= fvv Foo -= foo # eris might be an HDF5 Dataset, so _cp to ndarray eris_oovo = - _cp(eris.ooov).transpose(0,1,3,2) eris_ovvo = - _cp(eris.ovov).transpose(0,1,3,2) eris_vvvo = - _cp(eris.ovvv).transpose(2,3,1,0).conj() # T1 equation # TODO: Does this need a conj()? Usually zero w/ canonical HF. t1new = fov.copy() t1new += einsum('ie,ae->ia',t1,Fvv) t1new += -einsum('ma,mi->ia',t1,Foo) t1new += einsum('imae,me->ia',t2,Fov) t1new += -einsum('nf,naif->ia',t1,eris.ovov) t1new += -0.5*einsum('imef,maef->ia',t2,eris.ovvv) t1new += -0.5*einsum('mnae,nmei->ia',t2,eris_oovo) # T2 equation # For conj(), see Hirata and Bartlett, Eq. (36) t2new = np.array(eris.oovv, copy=True).conj() Ftmp = Fvv - 0.5*einsum('mb,me->be',t1,Fov) tmp = einsum('ijae,be->ijab',t2,Ftmp) t2new += (tmp - tmp.transpose(0,1,3,2)) Ftmp = Foo + 0.5*einsum('je,me->mj',t1,Fov) tmp = einsum('imab,mj->ijab',t2,Ftmp) t2new -= (tmp - tmp.transpose(1,0,2,3)) t2new += ( 0.5*einsum('mnab,mnij->ijab',tau,Woooo) + 0.5*einsum('ijef,abef->ijab',tau,Wvvvv) ) tmp = einsum('imae,mbej->ijab',t2,Wovvo) tmp -= einsum('ie,ma,mbej->ijab',t1,t1,eris_ovvo) t2new += ( tmp - tmp.transpose(0,1,3,2) - tmp.transpose(1,0,2,3) + tmp.transpose(1,0,3,2) ) tmp = einsum('ie,abej->ijab',t1,eris_vvvo) t2new += (tmp - tmp.transpose(1,0,2,3)) tmp = einsum('ma,mbij->ijab',t1,eris.ovoo) t2new -= (tmp - tmp.transpose(0,1,3,2)) t1new /= eia t2new /= eijab time0 = log.timer_debug1('update t1 t2', *time0) return t1new, t2new