def test_update_amps(self): mol = gto.M() nocc, nvir = 5, 12 nmo = nocc + nvir nmo_pair = nmo * (nmo + 1) // 2 mf = scf.RHF(mol) np.random.seed(12) mf._eri = np.random.random(nmo_pair * (nmo_pair + 1) // 2) mf.mo_coeff = np.random.random((nmo, nmo)) mf.mo_energy = np.arange(0., nmo) mf.mo_occ = np.zeros(nmo) mf.mo_occ[:nocc] = 2 vhf = mf.get_veff(mol, mf.make_rdm1()) cinv = np.linalg.inv(mf.mo_coeff) mf.get_hcore = lambda *args: (reduce(np.dot, (cinv.T * mf.mo_energy, cinv)) - vhf) mycc1 = rccsd.RCCSD(mf) eris1 = mycc1.ao2mo() mycc2 = ccsd.CCSD(mf) eris2 = mycc2.ao2mo() a = np.random.random((nmo, nmo)) * .1 eris1.fock += a + a.T.conj() eris2.fock += a + a.T t1 = np.random.random((nocc, nvir)) * .1 t2 = np.random.random((nocc, nocc, nvir, nvir)) * .1 t2 = t2 + t2.transpose(1, 0, 3, 2) t1b, t2b = ccsd.update_amps(mycc2, t1, t2, eris2) self.assertAlmostEqual(lib.finger(t1b), -106360.5276951083, 6) self.assertAlmostEqual(lib.finger(t2b), 66540.100267798145, 6) mycc2.max_memory = 0 t1a, t2a = ccsd.update_amps(mycc2, t1, t2, eris2) self.assertAlmostEqual(abs(t1a - t1b).max(), 0, 9) self.assertAlmostEqual(abs(t2a - t2b).max(), 0, 9) t2tril = ccsd._add_vvvv_tril(mycc2, t1, t2, eris2) self.assertAlmostEqual(lib.finger(t2tril), 13306.139402693696, 8) Ht2 = ccsd._add_vvvv_full(mycc2, t1, t2, eris2) self.assertAlmostEqual(lib.finger(Ht2), 760.50164232208408, 9) mycc1.cc2 = False t1a, t2a = rccsd.update_amps(mycc1, t1, t2, eris1) self.assertAlmostEqual(lib.finger(t1a), -106360.5276951083, 7) self.assertAlmostEqual(lib.finger(t2a), 66540.100267798145, 6) self.assertAlmostEqual(abs(t1a - t1b).max(), 0, 6) self.assertAlmostEqual(abs(t2a - t2b).max(), 0, 6) mycc1.cc2 = True t1a, t2a = rccsd.update_amps(mycc1, t1, t2, eris1) self.assertAlmostEqual(lib.finger(t1a), -106360.5276951083, 7) self.assertAlmostEqual(lib.finger(t2a), -1517.9391800662809, 7) mol = gto.Mole() mol.verbose = 0 mol.atom = [[8, (0., 0., 0.)], [1, (1., 0., 0.)], [1, (0., -0.757, 0.587)], [1, (0., 0.757, 0.587)]] mol.basis = { 'H': 'sto3g', 'O': 'cc-pvdz', } mol.charge = 1 mol.build(0, 0) mycc2.direct = True eris2.vvvv = None eris2.mol = mol mycc2.mo_coeff, eris2.mo_coeff = eris2.mo_coeff, None t2tril = ccsd._add_vvvv_tril(mycc2, t1, t2, eris2, with_ovvv=True) self.assertAlmostEqual(lib.finger(t2tril), 680.07199094501584, 9) t2tril = ccsd._add_vvvv_tril(mycc2, t1, t2, eris2, with_ovvv=False) self.assertAlmostEqual(lib.finger(t2tril), 446.56702664171348, 9) Ht2 = ccsd._add_vvvv_full(mycc2, t1, t2, eris2) self.assertAlmostEqual(lib.finger(Ht2), 48.122317842230686, 9) eri1 = np.random.random((nmo, nmo, nmo, nmo)) + np.random.random( (nmo, nmo, nmo, nmo)) * 1j eri1 = eri1.transpose(0, 2, 1, 3) eri1 = eri1 + eri1.transpose(1, 0, 3, 2).conj() eri1 = eri1 + eri1.transpose(2, 3, 0, 1) eri1 *= .1 eris1.oooo = eri1[:nocc, :nocc, :nocc, :nocc].copy() eris1.ovoo = eri1[:nocc, nocc:, :nocc, :nocc].copy() eris1.ovov = eri1[:nocc, nocc:, :nocc, nocc:].copy() eris1.oovv = eri1[:nocc, :nocc, nocc:, nocc:].copy() eris1.ovvo = eri1[:nocc, nocc:, nocc:, :nocc].copy() eris1.ovvv = eri1[:nocc, nocc:, nocc:, nocc:].copy() eris1.vvvv = eri1[nocc:, nocc:, nocc:, nocc:].copy() a = np.random.random((nmo, nmo)) * .1j eris1.fock = eris1.fock + a + a.T.conj() t1 = t1 + np.random.random((nocc, nvir)) * .1j t2 = t2 + np.random.random((nocc, nocc, nvir, nvir)) * .1j t2 = t2 + t2.transpose(1, 0, 3, 2) mycc1.cc2 = False t1a, t2a = rccsd.update_amps(mycc1, t1, t2, eris1) self.assertAlmostEqual(lib.finger(t1a), -13.32050019680894 - 1.8825765910430254j, 9) self.assertAlmostEqual(lib.finger(t2a), 9.2521062044785189 + 29.999480274811873j, 9) mycc1.cc2 = True t1a, t2a = rccsd.update_amps(mycc1, t1, t2, eris1) self.assertAlmostEqual(lib.finger(t1a), -13.32050019680894 - 1.8825765910430254j, 9) self.assertAlmostEqual(lib.finger(t2a), -0.056223856104895858 + 0.025472249329733986j, 9)
def test_update_amps(self): mol = gto.M() nocc, nvir = 5, 12 nmo = nocc + nvir nmo_pair = nmo*(nmo+1)//2 mf = scf.RHF(mol) np.random.seed(12) mf._eri = np.random.random(nmo_pair*(nmo_pair+1)//2) mf.mo_coeff = np.random.random((nmo,nmo)) mf.mo_energy = np.arange(0., nmo) mf.mo_occ = np.zeros(nmo) mf.mo_occ[:nocc] = 2 vhf = mf.get_veff(mol, mf.make_rdm1()) cinv = np.linalg.inv(mf.mo_coeff) mf.get_hcore = lambda *args: (reduce(np.dot, (cinv.T*mf.mo_energy, cinv)) - vhf) mycc1 = rccsd.RCCSD(mf) eris1 = mycc1.ao2mo() mycc2 = ccsd.CCSD(mf) eris2 = mycc2.ao2mo() a = np.random.random((nmo,nmo)) * .1 eris1.fock += a + a.T.conj() eris2.fock += a + a.T t1 = np.random.random((nocc,nvir)) * .1 t2 = np.random.random((nocc,nocc,nvir,nvir)) * .1 t2 = t2 + t2.transpose(1,0,3,2) t1b, t2b = ccsd.update_amps(mycc2, t1, t2, eris2) self.assertAlmostEqual(lib.finger(t1b), -106360.5276951083, 6) self.assertAlmostEqual(lib.finger(t2b), 66540.100267798145, 6) mycc2.max_memory = 0 t1a, t2a = ccsd.update_amps(mycc2, t1, t2, eris2) self.assertAlmostEqual(abs(t1a-t1b).max(), 0, 9) self.assertAlmostEqual(abs(t2a-t2b).max(), 0, 9) t2tril = ccsd._add_vvvv_tril(mycc2, t1, t2, eris2) self.assertAlmostEqual(lib.finger(t2tril), 13306.139402693696, 8) Ht2 = ccsd._add_vvvv_full(mycc2, t1, t2, eris2) self.assertAlmostEqual(lib.finger(Ht2), 760.50164232208408, 9) mycc1.cc2 = False t1a, t2a = rccsd.update_amps(mycc1, t1, t2, eris1) self.assertAlmostEqual(lib.finger(t1a), -106360.5276951083, 7) self.assertAlmostEqual(lib.finger(t2a), 66540.100267798145, 6) self.assertAlmostEqual(abs(t1a-t1b).max(), 0, 6) self.assertAlmostEqual(abs(t2a-t2b).max(), 0, 6) mycc1.cc2 = True t1a, t2a = rccsd.update_amps(mycc1, t1, t2, eris1) self.assertAlmostEqual(lib.finger(t1a), -106360.5276951083, 7) self.assertAlmostEqual(lib.finger(t2a), -1517.9391800662809, 7) mol = gto.Mole() mol.verbose = 0 mol.atom = [ [8 , (0. , 0. , 0.)], [1 , (1. , 0. , 0.)], [1 , (0. , -0.757 , 0.587)], [1 , (0. , 0.757 , 0.587)]] mol.basis = {'H': 'sto3g', 'O': 'cc-pvdz',} mol.charge = 1 mol.build(0, 0) mycc2.direct = True eris2.vvvv = None eris2.mol = mol mycc2.mo_coeff, eris2.mo_coeff = eris2.mo_coeff, None t2tril = ccsd._add_vvvv_tril(mycc2, t1, t2, eris2, with_ovvv=True) self.assertAlmostEqual(lib.finger(t2tril), 680.07199094501584, 9) t2tril = ccsd._add_vvvv_tril(mycc2, t1, t2, eris2, with_ovvv=False) self.assertAlmostEqual(lib.finger(t2tril), 446.56702664171348, 9) Ht2 = ccsd._add_vvvv_full(mycc2, t1, t2, eris2) self.assertAlmostEqual(lib.finger(Ht2), 48.122317842230686, 9) eri1 = np.random.random((nmo,nmo,nmo,nmo)) + np.random.random((nmo,nmo,nmo,nmo))*1j eri1 = eri1.transpose(0,2,1,3) eri1 = eri1 + eri1.transpose(1,0,3,2).conj() eri1 = eri1 + eri1.transpose(2,3,0,1) eri1 *= .1 eris1.oooo = eri1[:nocc,:nocc,:nocc,:nocc].copy() eris1.ovoo = eri1[:nocc,nocc:,:nocc,:nocc].copy() eris1.ovov = eri1[:nocc,nocc:,:nocc,nocc:].copy() eris1.oovv = eri1[:nocc,:nocc,nocc:,nocc:].copy() eris1.ovvo = eri1[:nocc,nocc:,nocc:,:nocc].copy() eris1.ovvv = eri1[:nocc,nocc:,nocc:,nocc:].copy() eris1.vvvv = eri1[nocc:,nocc:,nocc:,nocc:].copy() a = np.random.random((nmo,nmo)) * .1j eris1.fock = eris1.fock + a + a.T.conj() t1 = t1 + np.random.random((nocc,nvir)) * .1j t2 = t2 + np.random.random((nocc,nocc,nvir,nvir)) * .1j t2 = t2 + t2.transpose(1,0,3,2) mycc1.cc2 = False t1a, t2a = rccsd.update_amps(mycc1, t1, t2, eris1) self.assertAlmostEqual(lib.finger(t1a), -13.32050019680894-1.8825765910430254j, 9) self.assertAlmostEqual(lib.finger(t2a), 9.2521062044785189+29.999480274811873j, 9) mycc1.cc2 = True t1a, t2a = rccsd.update_amps(mycc1, t1, t2, eris1) self.assertAlmostEqual(lib.finger(t1a), -13.32050019680894-1.8825765910430254j, 9) self.assertAlmostEqual(lib.finger(t2a), -0.056223856104895858+0.025472249329733986j, 9)
def update_amps(self, t1, t2, eris): t1, t2 = ccsd.update_amps(self, t1, t2, eris) return numpy.zeros_like(t1), t2