Example #1
0
 def test_contract_2e_symm(self):
     norb, nelec = 7, (4, 4)
     strs = cistring.gen_strings4orblist(range(norb), nelec[0])
     numpy.random.seed(11)
     mask = numpy.random.random(len(strs)) > .3
     strsa = strs[mask]
     mask = numpy.random.random(len(strs)) > .2
     strsb = strs[mask]
     ci_strs = (strsa, strsb)
     civec_strs = selected_ci._as_SCIvector(
         numpy.random.random((len(strsa), len(strsb))), ci_strs)
     orbsym = (numpy.random.random(norb) * 4).astype(int)
     nn = norb * (norb + 1) // 2
     eri = ao2mo.restore(1,
                         (numpy.random.random(nn * (nn + 1) // 2) - .2)**3,
                         norb)
     oosym = orbsym[:, None] ^ orbsym
     oosym = oosym.reshape(-1, 1) ^ oosym.ravel()
     eri[oosym.reshape([norb] * 4) != 0] = 0
     ci0 = fci.selected_ci.to_fci(civec_strs, norb, nelec)
     ci0 = fci.addons.symmetrize_wfn(ci0, norb, nelec, orbsym)
     civec_strs = fci.selected_ci.from_fci(ci0, civec_strs._strs, norb,
                                           nelec)
     e1 = numpy.dot(
         civec_strs.ravel(),
         selected_ci_symm.contract_2e(eri,
                                      civec_strs,
                                      norb,
                                      nelec,
                                      orbsym=orbsym).ravel())
     e2 = numpy.dot(
         ci0.ravel(),
         direct_spin1_symm.contract_2e(eri, ci0, norb, nelec,
                                       orbsym=orbsym).ravel())
     self.assertAlmostEqual(e1, e2, 9)
Example #2
0
 def test_contract_2e_symm(self):
     norb, nelec = 7, (4,4)
     strs = cistring.make_strings(range(norb), nelec[0])
     numpy.random.seed(11)
     mask = numpy.random.random(len(strs)) > .3
     strsa = strs[mask]
     mask = numpy.random.random(len(strs)) > .2
     strsb = strs[mask]
     ci_strs = (strsa, strsb)
     civec_strs = selected_ci._as_SCIvector(numpy.random.random((len(strsa),len(strsb))), ci_strs)
     orbsym = (numpy.random.random(norb) * 4).astype(int)
     nn = norb*(norb+1)//2
     eri = ao2mo.restore(1, (numpy.random.random(nn*(nn+1)//2)-.2)**3, norb)
     oosym = orbsym[:,None] ^ orbsym
     oosym = oosym.reshape(-1,1) ^ oosym.ravel()
     eri[oosym.reshape([norb]*4)!=0] = 0
     ci0 = fci.selected_ci.to_fci(civec_strs, norb, nelec)
     ci0 = fci.addons.symmetrize_wfn(ci0, norb, nelec, orbsym)
     civec_strs = fci.selected_ci.from_fci(ci0, civec_strs._strs, norb, nelec)
     e1 = numpy.dot(civec_strs.ravel(), selected_ci_symm.contract_2e(eri, civec_strs, norb, nelec, orbsym=orbsym).ravel())
     e2 = numpy.dot(ci0.ravel(), direct_spin1_symm.contract_2e(eri, ci0, norb, nelec, orbsym=orbsym).ravel())
     self.assertAlmostEqual(e1, e2, 9)