def test_kernel(self): myci = select_ci.SCI() e1, c1 = select_ci.kernel(h1, eri, norb, nelec) e2, c2 = direct_spin1.kernel(h1, eri, norb, nelec) self.assertAlmostEqual(e1, e2, 9) self.assertAlmostEqual(abs(numpy.dot(c1.ravel(), c2.ravel())), 1, 9) dm1_1 = myci.make_rdm1(c1, norb, nelec) dm1_2 = direct_spin1.make_rdm1(c2, norb, nelec) self.assertAlmostEqual(abs(dm1_1 - dm1_2).sum(), 0, 4) dm2_1 = myci.make_rdm2(c1, norb, nelec) dm2_2 = direct_spin1.make_rdm12(c2, norb, nelec)[1] self.assertAlmostEqual(abs(dm2_1 - dm2_2).sum(), 0, 2)
def test_contract(self): myci = select_ci.SCI() ci0 = select_ci.to_fci(civec_strs, norb, nelec) e1 = numpy.dot( civec_strs.ravel(), select_ci.contract_2e(eri, civec_strs, norb, nelec).ravel()) e2 = numpy.dot(ci0.ravel(), direct_spin1.contract_2e(eri, ci0, norb, nelec).ravel()) self.assertAlmostEqual(e1, e2, 9) dm1 = myci.make_rdm1(civec_strs, norb, nelec) self.assertAlmostEqual(finger(dm1), 0.70181046385686563, 9) dm1 = myci.trans_rdm1(civec_strs, civec_strs, norb, nelec) self.assertAlmostEqual(finger(dm1), 0.70181046385686563, 9) dm2 = myci.make_rdm2(civec_strs, norb, nelec) self.assertAlmostEqual(finger(dm2), -3.8397469683353962, 9)
def test_h8(self): mol = gto.Mole() mol.verbose = 0 mol.output = None mol.atom = [ ['H', (1., -1., 0.)], ['H', (0., -1., -1.)], ['H', (1., -0.5, -1.)], ['H', (0., -0., -1.)], ['H', (1., -0.5, 0.)], ['H', (0., 1., 1.)], ['H', (1., 2., 3.)], ['H', (1., 2., 4.)], ] mol.basis = 'sto-3g' mol.build() m = scf.RHF(mol).run() norb = m.mo_coeff.shape[1] nelec = mol.nelectron h1e = reduce(numpy.dot, (m.mo_coeff.T, m.get_hcore(), m.mo_coeff)) eri = ao2mo.kernel(m._eri, m.mo_coeff, compact=False) eri = eri.reshape(norb, norb, norb, norb) myci = select_ci.SCI() myci.select_cutoff = 1e-3 myci.ci_coeff_cutoff = 1e-3 e1, c1 = myci.kernel(h1e, eri, norb, nelec) self.assertAlmostEqual(e1, -11.894613845925514, 9) e, c = myci.kernel_fixed_space(h1e, eri, norb, nelec, c1._strs) self.assertAlmostEqual(e, -11.894613845925514, 9) res = myci.large_ci(c1, norb, nelec, .25) self.assertEqual([x[1] for x in res], ['0b1111', '0b1111', '0b10111', '0b10111']) self.assertEqual([x[2] for x in res], ['0b1111', '0b10111', '0b1111', '0b10111']) res = myci.large_ci(c1, norb, nelec, .25, return_strs=False) refa = numpy.array( ((0, 1, 2, 3), (0, 1, 2, 3), (0, 1, 2, 4), (0, 1, 2, 4))) refb = numpy.array( ((0, 1, 2, 3), (0, 1, 2, 4), (0, 1, 2, 3), (0, 1, 2, 4))) self.assertTrue(numpy.all([x[1] for x in res] == refa)) self.assertTrue(numpy.all([x[2] for x in res] == refb)) self.assertAlmostEqual(myci.spin_square(c1, norb, nelec)[0], 0, 2)
def test_enlarge_space(self): myci = select_ci.SCI() myci.select_cutoff = .1 myci.ci_coeff_cutoff = .01 cic = select_ci.enlarge_space(myci, civec_strs, eri, norb, nelec) cis = cic._strs self.assertEqual((len(cis[0]), len(cis[1])), (17, 18)) # 16,14 self.assertEqual(list(cis[0]), [ 7, 11, 13, 14, 19, 21, 22, 25, 26, 28, 35, 37, 41, 42, 49, 52, 56 ]) self.assertEqual(list(cis[1]), [ 7, 11, 13, 14, 19, 21, 22, 25, 28, 35, 37, 38, 41, 44, 49, 50, 52, 56 ]) self.assertAlmostEqual( abs(cic[[0, 1, 5]][:, [0, 1, 2]] - ci_coeff).sum(), 0, 12)
def test_contract1(self): myci = select_ci.SCI() nelec = (4, 3) strsa = cistring.gen_strings4orblist(range(norb), nelec[0]) strsb = cistring.gen_strings4orblist(range(norb), nelec[1]) ci0 = select_ci._as_SCIvector( numpy.random.random((len(strsa), len(strsb))), (strsa, strsb)) h2 = ao2mo.restore(1, eri, norb) c1 = myci.contract_2e(h2, ci0, norb, nelec) c2 = direct_spin1.contract_2e(h2, ci0, norb, nelec) self.assertAlmostEqual(abs(c1 - c2).sum(), 0, 9) dm1_1 = myci.make_rdm1(c1, norb, nelec) dm1_2 = direct_spin1.make_rdm1(c2, norb, nelec) self.assertAlmostEqual(abs(dm1_1 - dm1_2).sum(), 0, 9) dm2_1 = myci.make_rdm2(c1, norb, nelec) dm2_2 = direct_spin1.make_rdm12(c2, norb, nelec)[1] self.assertAlmostEqual(abs(dm2_1 - dm2_2).sum(), 0, 9)
def test_select_strs(self): myci = select_ci.SCI() myci.select_cutoff = 1e-3 norb, nelec = 10, 4 strs = cistring.gen_strings4orblist(range(norb), nelec) numpy.random.seed(11) mask = numpy.random.random(len(strs)) > .8 strs = strs[mask] nn = norb * (norb + 1) // 2 eri = (numpy.random.random(nn * (nn + 1) // 2) - .2)**3 eri[eri < .1] *= 3e-3 eri = ao2mo.restore(1, eri, norb) eri_pq_max = abs(eri.reshape(norb**2, -1)).max(axis=1).reshape(norb, norb) civec_max = numpy.random.random(len(strs)) strs_add0 = select_strs(myci, eri, eri_pq_max, civec_max, strs, norb, nelec) strs_add1 = select_ci.select_strs(myci, eri, eri_pq_max, civec_max, strs, norb, nelec) self.assertTrue(numpy.all(strs_add0 == strs_add1))
def test_select_strs1(self): myci = select_ci.SCI() myci.select_cutoff = .1 myci.ci_coeff_cutoff = .01 eri1 = ao2mo.restore(1, eri, norb) eri_pq_max = abs(eri1.reshape(norb**2, -1)).max(axis=1).reshape(norb, norb) civec_a_max = abs(ci_coeff).max(axis=1) civec_b_max = abs(ci_coeff).max(axis=0) strs_add0 = select_strs(myci, eri1, eri_pq_max, civec_a_max, ci_strs[0], norb, nelec // 2) strs_add1 = select_ci.select_strs(myci, eri1, eri_pq_max, civec_a_max, ci_strs[0], norb, nelec // 2) self.assertTrue(numpy.all(strs_add0 == strs_add1)) strs_add0 = select_strs(myci, eri1, eri_pq_max, civec_b_max, ci_strs[1], norb, nelec // 2) strs_add1 = select_ci.select_strs(myci, eri1, eri_pq_max, civec_b_max, ci_strs[1], norb, nelec // 2) self.assertTrue(numpy.all(strs_add0 == strs_add1))