def test_from_fcivec(self): myci = scf.UHF(gto.M()).apply(ci.CISD) nocca, noccb = nelec = (3,2) nvira, nvirb = 5, 6 myci.nocc = nocc = nocca, noccb nmo = 8 myci.nmo = (nmo,nmo) numpy.random.seed(12) civec = numpy.random.random(myci.vector_size()) ci0 = ucisd.to_fcivec(civec, nmo, nelec) self.assertAlmostEqual(abs(civec-ucisd.from_fcivec(ci0, nmo, nelec)).max(), 0, 9) nocc = 3 nvir = 5 nmo = nocc + nvir c1a = numpy.random.random((nocc,nvir)) c1b = numpy.random.random((nocc,nvir)) c2aa = numpy.random.random((nocc,nocc,nvir,nvir)) c2bb = numpy.random.random((nocc,nocc,nvir,nvir)) c2ab = numpy.random.random((nocc,nocc,nvir,nvir)) c1 = (c1a, c1b) c2 = (c2aa, c2ab, c2bb) cisdvec = ucisd.amplitudes_to_cisdvec(1., c1, c2) fcivec = ucisd.to_fcivec(cisdvec, nmo, nocc*2) cisdvec1 = ucisd.from_fcivec(fcivec, nmo, nocc*2) self.assertAlmostEqual(abs(cisdvec-cisdvec1).max(), 0, 12) ci1 = ucisd.to_fcivec(cisdvec1, nmo, (nocc,nocc)) self.assertAlmostEqual(abs(fcivec-ci1).max(), 0, 12)
def test_from_fcivec(self): myci = scf.UHF(gto.M()).apply(ci.CISD) nocca, noccb = nelec = (3, 2) nvira, nvirb = 5, 6 myci.nocc = nocc = nocca, noccb nmo = 8 myci.nmo = (nmo, nmo) numpy.random.seed(12) civec = numpy.random.random(myci.vector_size()) ci0 = ucisd.to_fcivec(civec, nmo, nelec) self.assertAlmostEqual( abs(civec - ucisd.from_fcivec(ci0, nmo, nelec)).max(), 0, 9) nocc = 3 nvir = 5 nmo = nocc + nvir c1a = numpy.random.random((nocc, nvir)) c1b = numpy.random.random((nocc, nvir)) c2aa = numpy.random.random((nocc, nocc, nvir, nvir)) c2bb = numpy.random.random((nocc, nocc, nvir, nvir)) c2ab = numpy.random.random((nocc, nocc, nvir, nvir)) c1 = (c1a, c1b) c2 = (c2aa, c2ab, c2bb) cisdvec = ucisd.amplitudes_to_cisdvec(1., c1, c2) fcivec = ucisd.to_fcivec(cisdvec, nmo, nocc * 2) cisdvec1 = ucisd.from_fcivec(fcivec, nmo, nocc * 2) self.assertAlmostEqual(abs(cisdvec - cisdvec1).max(), 0, 12) ci1 = ucisd.to_fcivec(cisdvec1, nmo, (nocc, nocc)) self.assertAlmostEqual(abs(fcivec - ci1).max(), 0, 12)
def test_from_fcivec(self): numpy.random.seed(12) nocc = 3 nvir = 5 nmo = nocc + nvir orbspin = numpy.zeros(nmo*2, dtype=int) orbspin[1::2] = 1 c1a = numpy.random.random((nocc,nvir)) c1b = numpy.random.random((nocc,nvir)) c2aa = numpy.random.random((nocc,nocc,nvir,nvir)) c2bb = numpy.random.random((nocc,nocc,nvir,nvir)) c2ab = numpy.random.random((nocc,nocc,nvir,nvir)) c2ab = c2ab + c2ab.transpose(1,0,3,2) c1 = gcisd.spatial2spin((c1a, c1b), orbspin) c2 = gcisd.spatial2spin((c2aa, c2ab, c2bb), orbspin) cisdvec = gcisd.amplitudes_to_cisdvec(1., c1, c2) fcivec = gcisd.to_fcivec(cisdvec, nocc*2, orbspin) cisdvec1 = gcisd.from_fcivec(fcivec, nocc*2, orbspin) self.assertAlmostEqual(abs(cisdvec-cisdvec1).max(), 0, 12) ci1 = gcisd.to_fcivec(cisdvec1, nocc*2, orbspin) self.assertAlmostEqual(abs(fcivec-ci1).max(), 0, 12) vec1 = gcisd.from_ucisdvec(ucisd.amplitudes_to_cisdvec(1, (c1a,c1b), (c2aa,c2ab,c2bb)), nocc*2, orbspin) self.assertAlmostEqual(abs(cisdvec - vec1).max(), 0, 12) c1 = gcisd.spatial2spin((c1a, c1a), orbspin) c2aa = c2ab - c2ab.transpose(1,0,2,3) c2 = gcisd.spatial2spin((c2aa, c2ab, c2aa), orbspin) cisdvec = gcisd.amplitudes_to_cisdvec(1., c1, c2) vec1 = gcisd.from_rcisdvec(ci.cisd.amplitudes_to_cisdvec(1, c1a, c2ab), nocc*2, orbspin) self.assertTrue(numpy.all(cisdvec == vec1))
def test_from_fcivec(self): numpy.random.seed(12) nocc = 3 nvir = 5 nmo = nocc + nvir orbspin = numpy.zeros(nmo*2, dtype=int) orbspin[1::2] = 1 c1a = numpy.random.random((nocc,nvir)) c1b = numpy.random.random((nocc,nvir)) c2aa = numpy.random.random((nocc,nocc,nvir,nvir)) c2bb = numpy.random.random((nocc,nocc,nvir,nvir)) c2ab = numpy.random.random((nocc,nocc,nvir,nvir)) c2ab = c2ab + c2ab.transpose(1,0,3,2) c1 = gcisd.spatial2spin((c1a, c1b), orbspin) c2 = gcisd.spatial2spin((c2aa, c2ab, c2bb), orbspin) cisdvec = gcisd.amplitudes_to_cisdvec(1., c1, c2) fcivec = gcisd.to_fcivec(cisdvec, nocc*2, orbspin) cisdvec1 = gcisd.from_fcivec(fcivec, nocc*2, orbspin) self.assertAlmostEqual(abs(cisdvec-cisdvec1).max(), 0, 12) ci1 = gcisd.to_fcivec(cisdvec1, nocc*2, orbspin) self.assertAlmostEqual(abs(fcivec-ci1).max(), 0, 12) vec1 = gcisd.from_ucisdvec(ucisd.amplitudes_to_cisdvec(1, (c1a,c1b), (c2aa,c2ab,c2bb)), nocc*2, orbspin) self.assertAlmostEqual(abs(cisdvec - vec1).max(), 0, 12) c1 = gcisd.spatial2spin((c1a, c1a), orbspin) c2aa = c2ab - c2ab.transpose(1,0,2,3) c2 = gcisd.spatial2spin((c2aa, c2ab, c2aa), orbspin) cisdvec = gcisd.amplitudes_to_cisdvec(1., c1, c2) vec1 = gcisd.from_rcisdvec(ci.cisd.amplitudes_to_cisdvec(1, c1a, c2ab), nocc*2, orbspin) self.assertTrue(numpy.all(cisdvec == vec1))
def test_overlap(self): nmo = 8 nocc = nocca, noccb = (4,3) numpy.random.seed(2) nvira, nvirb = nmo-nocca, nmo-noccb cibra = ucisd.amplitudes_to_cisdvec(numpy.random.rand(1), (numpy.random.rand(nocca,nvira), numpy.random.rand(noccb,nvirb)), (numpy.random.rand(nocca,nocca,nvira,nvira), numpy.random.rand(nocca,noccb,nvira,nvirb), numpy.random.rand(noccb,noccb,nvirb,nvirb))) ciket = ucisd.amplitudes_to_cisdvec(numpy.random.rand(1), (numpy.random.rand(nocca,nvira), numpy.random.rand(noccb,nvirb)), (numpy.random.rand(nocca,nocca,nvira,nvira), numpy.random.rand(nocca,noccb,nvira,nvirb), numpy.random.rand(noccb,noccb,nvirb,nvirb))) fcibra = ucisd.to_fcivec(cibra, nmo, nocc) fciket = ucisd.to_fcivec(ciket, nmo, nocc) s_mo = numpy.random.random((nmo,nmo)) s0 = fci.addons.overlap(fcibra, fciket, nmo, nocc, s_mo) s1 = ucisd.overlap(cibra, ciket, nmo, nocc, (s_mo, s_mo)) self.assertAlmostEqual(s1, s0, 9)
def test_overlap(self): nmo = 8 nocc = nocca, noccb = (4, 3) numpy.random.seed(2) nvira, nvirb = nmo - nocca, nmo - noccb cibra = ucisd.amplitudes_to_cisdvec( numpy.random.rand(1), (numpy.random.rand(nocca, nvira), numpy.random.rand(noccb, nvirb)), (numpy.random.rand(nocca, nocca, nvira, nvira), numpy.random.rand(nocca, noccb, nvira, nvirb), numpy.random.rand(noccb, noccb, nvirb, nvirb))) ciket = ucisd.amplitudes_to_cisdvec( numpy.random.rand(1), (numpy.random.rand(nocca, nvira), numpy.random.rand(noccb, nvirb)), (numpy.random.rand(nocca, nocca, nvira, nvira), numpy.random.rand(nocca, noccb, nvira, nvirb), numpy.random.rand(noccb, noccb, nvirb, nvirb))) fcibra = ucisd.to_fcivec(cibra, nmo, nocc) fciket = ucisd.to_fcivec(ciket, nmo, nocc) s_mo = numpy.random.random((nmo, nmo)) s0 = fci.addons.overlap(fcibra, fciket, nmo, nocc, s_mo) s1 = ucisd.overlap(cibra, ciket, nmo, nocc, (s_mo, s_mo)) self.assertAlmostEqual(s1, s0, 9)
def to_ucisdvec(civec, nmo, nocc, orbspin): '''Convert the GCISD coefficient vector to UCISD coefficient vector''' c0, c1, c2 = cisdvec_to_amplitudes(civec, nmo, nocc) c1 = spin2spatial(c1, orbspin) c2 = spin2spatial(c2, orbspin) ucisdvec = ucisd.amplitudes_to_cisdvec(c0, c1, c2) unorm = numpy.linalg.norm(ucisdvec) if unorm < 1e-2: raise RuntimeError('GCISD vector corresponds to spin-flip excitation. ' 'It cannot be converted to UCISD wfn.' 'norm(UCISD) = %s' % unorm) elif unorm < 0.99: warnings.warn('GCISD vector has spin-flip excitation. ' 'They are ignored when converting to UCISD wfn. ' 'norm(UCISD) = %s' % unorm) return ucisdvec
def to_ucisdvec(civec, nmo, nocc, orbspin): '''Convert the GCISD coefficient vector to UCISD coefficient vector''' c0, c1, c2 = cisdvec_to_amplitudes(civec, nmo, nocc) c1 = spin2spatial(c1, orbspin) c2 = spin2spatial(c2, orbspin) ucisdvec = ucisd.amplitudes_to_cisdvec(c0, c1, c2) unorm = numpy.linalg.norm(ucisdvec) if unorm < 1e-2: raise RuntimeError('GCISD vector corresponds to spin-flip excitation. ' 'It cannot be converted to UCISD wfn.' 'norm(UCISD) = %s' % unorm) elif unorm < 0.99: warnings.warn('GCISD vector has spin-flip excitation. ' 'They are ignored when converting to UCISD wfn. ' 'norm(UCISD) = %s' % unorm) return ucisdvec