Beispiel #1
0
    def test_kernel_symm(self):
        mol = gto.Mole()
        mol.verbose = 0
        mol.output = None
        mol.atom = [
            ['O', ( 0., 0.    , 0.   )],
            ['H', ( 0., -0.757, 0.587)],
            ['H', ( 0., 0.757 , 0.587)],]
        mol.basis = 'sto-3g'
        mol.symmetry = 1
        mol.build()
        m = scf.RHF(mol).run()

        norb = m.mo_coeff.shape[1]
        nelec = mol.nelectron - 2
        h1e = reduce(numpy.dot, (m.mo_coeff.T, scf.hf.get_hcore(mol), m.mo_coeff))
        eri = ao2mo.incore.full(m._eri, m.mo_coeff)
        orbsym = symm.label_orb_symm(mol, mol.irrep_id, mol.symm_orb, m.mo_coeff)

        myci = selected_ci_symm.SCI().set(orbsym=orbsym, select_cutoff=.5e-3)
        e1, c1 = myci.kernel(h1e, eri, norb, nelec)
        myci = direct_spin1_symm.FCISolver().set(orbsym=orbsym)
        e2, c2 = myci.kernel(h1e, eri, norb, nelec)

        self.assertAlmostEqual(e1, e2, 6)
        c2_cut = selected_ci.from_fci(c2, c1._strs, norb, nelec)
        self.assertAlmostEqual(abs(numpy.dot(c1.ravel(), c2_cut.ravel())), 1, 6)

        myci = selected_ci_symm.SCI().set(orbsym=orbsym, select_cutoff=1e-5)
        e1, c1 = myci.kernel(h1e, eri, norb, nelec, ci0=c2_cut, wfnsym=0)
        self.assertAlmostEqual(e1, e2, 9)
        c2_cut = selected_ci.from_fci(c2, c1._strs, norb, nelec)
        self.assertAlmostEqual(abs(numpy.dot(c1.ravel(), c2_cut.ravel())), 1, 9)
Beispiel #2
0
    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 = (numpy.random.random(nn * (nn + 1) // 2) - .2)**3

    ci0 = selected_ci.to_fci(civec_strs, norb, nelec)
    ci0 = addons.symmetrize_wfn(ci0, norb, nelec, orbsym)
    civec_strs = selected_ci.from_fci(ci0, civec_strs._strs, norb, nelec)
    e1 = numpy.dot(
        civec_strs.ravel(),
        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())
    print(e1 - e2)

    mol = gto.Mole()
    mol.verbose = 0
    mol.output = None
    mol.atom = [
        ['O', (0., 0., 0.)],
        ['H', (0., -0.757, 0.587)],
Beispiel #3
0
 def test_from_to_fci(self):
     ci0 = selected_ci.to_fci(civec_strs, norb, nelec)
     ci1 = selected_ci.from_fci(ci0, ci_strs, norb, nelec)
     self.assertAlmostEqual(abs(ci1 - ci_coeff).sum(), 0, 12)
Beispiel #4
0
    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 = (numpy.random.random(nn*(nn+1)//2)-.2)**3

    ci0 = selected_ci.to_fci(civec_strs, norb, nelec)
    ci0 = addons.symmetrize_wfn(ci0, norb, nelec, orbsym)
    civec_strs = selected_ci.from_fci(ci0, civec_strs._strs, norb, nelec)
    e1 = numpy.dot(civec_strs.ravel(), 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())
    print(e1-e2)

    mol = gto.Mole()
    mol.verbose = 0
    mol.output = None
    mol.atom = [
        ['O', ( 0., 0.    , 0.   )],
        ['H', ( 0., -0.757, 0.587)],
        ['H', ( 0., 0.757 , 0.587)],]
    mol.basis = 'sto-3g'
    mol.symmetry = 1
    mol.build()
    m = scf.RHF(mol).run()
Beispiel #5
0
 def test_from_to_fci(self):
     ci0 = selected_ci.to_fci(civec_strs, norb, nelec)
     ci1 = selected_ci.from_fci(ci0, ci_strs, norb, nelec)
     self.assertAlmostEqual(abs(ci1-ci_coeff).sum(), 0, 12)