def test_ccsd_t_complex(self): mol = gto.M() numpy.random.seed(12) nocc, nvir = 3, 4 nmo = nocc + nvir eris = cc.rccsd._ChemistsERIs() eri1 = (numpy.random.random( (nmo, nmo, nmo, nmo)) + numpy.random.random( (nmo, nmo, nmo, nmo)) * .8j - .5 - .4j) eri1 = eri1 + eri1.transpose(1, 0, 2, 3) eri1 = eri1 + eri1.transpose(0, 1, 3, 2) eri1 = eri1 + eri1.transpose(2, 3, 0, 1) eri1 *= .1 eris.ovvv = eri1[:nocc, nocc:, nocc:, nocc:] eris.ovoo = eri1[:nocc, nocc:, :nocc, :nocc] eris.ovov = eri1[:nocc, nocc:, :nocc, nocc:] t1 = (numpy.random.random((nocc, nvir)) * .1 + numpy.random.random( (nocc, nvir)) * .1j) t2 = (numpy.random.random( (nocc, nocc, nvir, nvir)) * .1 + numpy.random.random( (nocc, nocc, nvir, nvir)) * .1j) t2 = t2 + t2.transpose(1, 0, 3, 2) mf = scf.RHF(mol) mcc = cc.CCSD(mf) f = (numpy.random.random((nmo, nmo)) * .1 + numpy.random.random( (nmo, nmo)) * .1j) eris.fock = f + f.T.conj() + numpy.diag(numpy.arange(nmo)) eris.mo_energy = eris.fock.diagonal().real e0 = ccsd_t.kernel(mcc, eris, t1, t2) eri2 = numpy.zeros((nmo * 2, nmo * 2, nmo * 2, nmo * 2), dtype=numpy.complex128) orbspin = numpy.zeros(nmo * 2, dtype=int) orbspin[1::2] = 1 eri2[0::2, 0::2, 0::2, 0::2] = eri1 eri2[1::2, 1::2, 0::2, 0::2] = eri1 eri2[0::2, 0::2, 1::2, 1::2] = eri1 eri2[1::2, 1::2, 1::2, 1::2] = eri1 eri2 = eri2.transpose(0, 2, 1, 3) - eri2.transpose(0, 2, 3, 1) fock = numpy.zeros((nmo * 2, nmo * 2), dtype=numpy.complex128) fock[0::2, 0::2] = eris.fock fock[1::2, 1::2] = eris.fock eris1 = gccsd._PhysicistsERIs() eris1.ovvv = eri2[:nocc * 2, nocc * 2:, nocc * 2:, nocc * 2:] eris1.oovv = eri2[:nocc * 2, :nocc * 2, nocc * 2:, nocc * 2:] eris1.ooov = eri2[:nocc * 2, :nocc * 2, :nocc * 2, nocc * 2:] eris1.fock = fock eris1.mo_energy = fock.diagonal().real t1 = gccsd.spatial2spin(t1, orbspin) t2 = gccsd.spatial2spin(t2, orbspin) gcc = gccsd.GCCSD(scf.GHF(gto.M())) e1 = gccsd_t.kernel(gcc, eris1, t1, t2) self.assertAlmostEqual(e0, e1.real, 9) self.assertAlmostEqual(e1, -0.98756910139720788 - 0.0019567929592079489j, 9)
def test_ccsd_t_complex(self): mol = gto.M() numpy.random.seed(12) nocc, nvir = 3, 4 nmo = nocc + nvir eris = cc.rccsd._ChemistsERIs() eri1 = (numpy.random.random((nmo,nmo,nmo,nmo)) + numpy.random.random((nmo,nmo,nmo,nmo)) * .8j - .5-.4j) eri1 = eri1 + eri1.transpose(1,0,2,3) eri1 = eri1 + eri1.transpose(0,1,3,2) eri1 = eri1 + eri1.transpose(2,3,0,1) eri1 *= .1 eris.ovvv = eri1[:nocc,nocc:,nocc:,nocc:] eris.ovoo = eri1[:nocc,nocc:,:nocc,:nocc] eris.ovov = eri1[:nocc,nocc:,:nocc,nocc:] t1 = (numpy.random.random((nocc,nvir)) * .1 + numpy.random.random((nocc,nvir)) * .1j) t2 = (numpy.random.random((nocc,nocc,nvir,nvir)) * .1 + numpy.random.random((nocc,nocc,nvir,nvir)) * .1j) t2 = t2 + t2.transpose(1,0,3,2) mf = scf.RHF(mol) mcc = cc.CCSD(mf) f = (numpy.random.random((nmo,nmo)) * .1 + numpy.random.random((nmo,nmo)) * .1j) eris.fock = f+f.T.conj() + numpy.diag(numpy.arange(nmo)) eris.mo_energy = eris.fock.diagonal().real e0 = ccsd_t.kernel(mcc, eris, t1, t2) eri2 = numpy.zeros((nmo*2,nmo*2,nmo*2,nmo*2), dtype=numpy.complex) orbspin = numpy.zeros(nmo*2,dtype=int) orbspin[1::2] = 1 eri2[0::2,0::2,0::2,0::2] = eri1 eri2[1::2,1::2,0::2,0::2] = eri1 eri2[0::2,0::2,1::2,1::2] = eri1 eri2[1::2,1::2,1::2,1::2] = eri1 eri2 = eri2.transpose(0,2,1,3) - eri2.transpose(0,2,3,1) fock = numpy.zeros((nmo*2,nmo*2), dtype=numpy.complex) fock[0::2,0::2] = eris.fock fock[1::2,1::2] = eris.fock eris1 = gccsd._PhysicistsERIs() eris1.ovvv = eri2[:nocc*2,nocc*2:,nocc*2:,nocc*2:] eris1.oovv = eri2[:nocc*2,:nocc*2,nocc*2:,nocc*2:] eris1.ooov = eri2[:nocc*2,:nocc*2,:nocc*2,nocc*2:] eris1.fock = fock eris1.mo_energy = fock.diagonal().real t1 = gccsd.spatial2spin(t1, orbspin) t2 = gccsd.spatial2spin(t2, orbspin) gcc = gccsd.GCCSD(scf.GHF(gto.M())) e1 = gccsd_t.kernel(gcc, eris1, t1, t2) self.assertAlmostEqual(e0, e1.real, 9) self.assertAlmostEqual(e1, -0.98756910139720788-0.0019567929592079489j, 9)
def test_uccsd_t_complex(self): mol = gto.M() numpy.random.seed(12) nocca, noccb, nvira, nvirb = 3, 2, 4, 5 nmo = nocca + nvira eris = cc.uccsd._ChemistsERIs() eris.nocca = nocca eris.noccb = noccb eris.nocc = (nocca, noccb) eri1 = (numpy.random.random((3,nmo,nmo,nmo,nmo)) + numpy.random.random((3,nmo,nmo,nmo,nmo)) * .8j - .5-.4j) eri1 = eri1 + eri1.transpose(0,2,1,4,3).conj() eri1[0] = eri1[0] + eri1[0].transpose(2,3,0,1) eri1[2] = eri1[2] + eri1[2].transpose(2,3,0,1) eri1 *= .1 eris.ovvv = eri1[0,:nocca,nocca:,nocca:,nocca:] eris.ovov = eri1[0,:nocca,nocca:,:nocca,nocca:] eris.ovoo = eri1[0,:nocca,nocca:,:nocca,:nocca] eris.OVVV = eri1[2,:noccb,noccb:,noccb:,noccb:] eris.OVOV = eri1[2,:noccb,noccb:,:noccb,noccb:] eris.OVOO = eri1[2,:noccb,noccb:,:noccb,:noccb] eris.voVP = eri1[1,nocca:,:nocca,noccb:,: ] eris.ovVV = eri1[1,:nocca,nocca:,noccb:,noccb:] eris.ovOV = eri1[1,:nocca,nocca:,:noccb,noccb:] eris.ovOO = eri1[1,:nocca,nocca:,:noccb,:noccb] eris.OVvv = eri1[1,nocca:,nocca:,:noccb,noccb:].transpose(2,3,0,1) eris.OVoo = eri1[1,:nocca,:nocca,:noccb,noccb:].transpose(2,3,0,1) t1a = .1 * numpy.random.random((nocca,nvira)) + numpy.random.random((nocca,nvira))*.1j t1b = .1 * numpy.random.random((noccb,nvirb)) + numpy.random.random((noccb,nvirb))*.1j t2aa = .1 * numpy.random.random((nocca,nocca,nvira,nvira)) + numpy.random.random((nocca,nocca,nvira,nvira))*.1j t2aa = t2aa - t2aa.transpose(0,1,3,2) t2aa = t2aa - t2aa.transpose(1,0,2,3) t2bb = .1 * numpy.random.random((noccb,noccb,nvirb,nvirb)) + numpy.random.random((noccb,noccb,nvirb,nvirb))*.1j t2bb = t2bb - t2bb.transpose(0,1,3,2) t2bb = t2bb - t2bb.transpose(1,0,2,3) t2ab = .1 * numpy.random.random((nocca,noccb,nvira,nvirb)) + numpy.random.random((nocca,noccb,nvira,nvirb))*.1j f = (numpy.random.random((2,nmo,nmo)) * .4 + numpy.random.random((2,nmo,nmo)) * .4j) eris.focka = f[0]+f[0].T.conj() + numpy.diag(numpy.arange(nmo)) eris.fockb = f[1]+f[1].T.conj() + numpy.diag(numpy.arange(nmo)) eris.mo_energy = (eris.focka.diagonal().real, eris.fockb.diagonal().real) t1 = t1a, t1b t2 = t2aa, t2ab, t2bb mcc = cc.UCCSD(scf.UHF(mol)) mcc.nocc = eris.nocc e0 = uccsd_t.kernel(mcc, eris, t1, t2) eri2 = numpy.zeros((nmo*2,nmo*2,nmo*2,nmo*2), dtype=eri1.dtype) orbspin = numpy.zeros(nmo*2,dtype=int) orbspin[1::2] = 1 eri2[0::2,0::2,0::2,0::2] = eri1[0] eri2[1::2,1::2,0::2,0::2] = eri1[1].transpose(2,3,0,1) eri2[0::2,0::2,1::2,1::2] = eri1[1] eri2[1::2,1::2,1::2,1::2] = eri1[2] eri2 = eri2.transpose(0,2,1,3) - eri2.transpose(0,2,3,1) fock = numpy.zeros((nmo*2,nmo*2), dtype=eris.focka.dtype) fock[0::2,0::2] = eris.focka fock[1::2,1::2] = eris.fockb eris1 = gccsd._PhysicistsERIs() nocc = nocca + noccb eris1.ovvv = eri2[:nocc,nocc:,nocc:,nocc:] eris1.oovv = eri2[:nocc,:nocc,nocc:,nocc:] eris1.ooov = eri2[:nocc,:nocc,:nocc,nocc:] eris1.fock = fock eris1.mo_energy = fock.diagonal().real t1 = gccsd.spatial2spin(t1, orbspin) t2 = gccsd.spatial2spin(t2, orbspin) gcc = gccsd.GCCSD(scf.GHF(gto.M())) e1 = gccsd_t.kernel(gcc, eris1, t1, t2) self.assertAlmostEqual(e0, e1.real, 9) self.assertAlmostEqual(e1, -0.056092415718338388-0.011390417704868244j, 9)