Beispiel #1
0
 def test_ghf_stability(self):
     mf1 = scf.convert_to_ghf(mf)
     mo = mf1.stability()
     s = mf1.det_ovlp(mo, mf1.mo_coeff, mf1.mo_occ, mf1.mo_occ,
                      mf1.get_ovlp())[0]
     self.assertAlmostEqual(s, 1., 9)
     self.assertAlmostEqual(abs(mf1.mo_coeff - mo).max(), 0, 9)
Beispiel #2
0
 def test_ghf_stability(self):
     mf1 = scf.convert_to_ghf(mf)
     mo = mf1.stability()
     s = mf1.det_ovlp(mo, mf1.mo_coeff, mf1.mo_occ, mf1.mo_occ,
                      mf1.get_ovlp())[0]
     self.assertAlmostEqual(s, 1., 9)
     self.assertAlmostEqual(abs(mf1.mo_coeff-mo).max(), 0, 9)
Beispiel #3
0
    def test_trans_rdm_with_frozen(self):
        mol = gto.M(atom='''
        O   0.   0.       .0
        H   0.   -0.757   0.587
        H   0.   0.757    0.587''',
                    basis='sto3g')
        mf = scf.convert_to_ghf(scf.RHF(mol).run())
        orbspin = mf.mo_coeff.orbspin
        idxa = numpy.where(orbspin == 0)[0]
        idxb = numpy.where(orbspin == 1)[0]
        nmo_1c = mf.mo_coeff.shape[1] // 2

        def check_frozen(frozen):
            myci = ci.GCISD(mf)
            myci.frozen = frozen
            myci.nroots = 3
            myci.kernel()
            nocc = myci.nocc
            nmo = myci.nmo
            nfroz = len(frozen)
            try:
                ket_id = 1
                fciket = gcisd.to_fcivec(myci.ci[ket_id], mol.nelectron,
                                         orbspin, myci.frozen)
            except RuntimeError:
                ket_id = 2
                fciket = gcisd.to_fcivec(myci.ci[ket_id], mol.nelectron,
                                         orbspin, myci.frozen)
                # spin-forbidden transition
                cidm1 = myci.trans_rdm1(myci.ci[0], myci.ci[1], nmo, nocc)
                self.assertAlmostEqual(
                    abs(cidm1[idxa[:, None], idxa]).max(), 0, 7)
                self.assertAlmostEqual(
                    abs(cidm1[idxb[:, None], idxb]).max(), 0, 7)

            cibra = (myci.ci[0] + myci.ci[ket_id]) * numpy.sqrt(.5)
            fcibra = gcisd.to_fcivec(cibra, mol.nelectron, orbspin,
                                     myci.frozen)
            fcidm1 = fci.direct_spin1.trans_rdm1s(fcibra, fciket, nmo_1c,
                                                  mol.nelectron)
            cidm1 = myci.trans_rdm1(cibra, myci.ci[ket_id], nmo, nocc)
            self.assertAlmostEqual(
                abs(fcidm1[0] - cidm1[idxa[:, None], idxa]).max(), 0, 12)
            self.assertAlmostEqual(
                abs(fcidm1[1] - cidm1[idxb[:, None], idxb]).max(), 0, 12)

        check_frozen([10])
        check_frozen([10, 3])
Beispiel #4
0
    def test_uhf_stability(self):
        mf1 = scf.convert_to_uhf(mf)
        mo_i, mo_e = mf1.stability(internal=True, external=True)
        s = mf1.det_ovlp(mo_i, mf1.mo_coeff, mf1.mo_occ, mf1.mo_occ,
                         mf1.get_ovlp())[0]
        self.assertAlmostEqual(s, 1, 9)
        self.assertAlmostEqual(abs(mf1.mo_coeff[0] - mo_i[0]).max(), 0, 9)
        self.assertAlmostEqual(abs(mf1.mo_coeff[1] - mo_i[1]).max(), 0, 9)
        self.assertEqual(mo_e.shape, (56, 56))

        mf1 = scf.convert_to_ghf(mf).newton()
        s = mf1.det_ovlp(mo_e, mf1.mo_coeff, mf1.mo_occ, mf1.mo_occ,
                         mf1.get_ovlp())[0]
        self.assertAlmostEqual(s, 0.57993272190912937, 6)
        mf1.kernel(mo_coeff=mo_e, mo_occ=mf1.mo_occ)
        self.assertAlmostEqual(mf1.e_tot, -149.6097443357186, 8)
Beispiel #5
0
    def test_uhf_stability(self):
        mf1 = scf.convert_to_uhf(mf)
        mo_i, mo_e = mf1.stability(internal=True, external=True)
        s  = mf1.det_ovlp(mo_i, mf1.mo_coeff, mf1.mo_occ, mf1.mo_occ,
                          mf1.get_ovlp())[0]
        self.assertAlmostEqual(s, 1, 9)
        self.assertAlmostEqual(abs(mf1.mo_coeff[0]-mo_i[0]).max(), 0, 9)
        self.assertAlmostEqual(abs(mf1.mo_coeff[1]-mo_i[1]).max(), 0, 9)
        self.assertEqual(mo_e.shape, (56,56))

        mf1 = scf.convert_to_ghf(mf).newton()
        s = mf1.det_ovlp(mo_e, mf1.mo_coeff, mf1.mo_occ, mf1.mo_occ,
                         mf1.get_ovlp())[0]
        self.assertAlmostEqual(s, 0.57993272190912937, 6)
        mf1.kernel(mo_coeff=mo_e, mo_occ=mf1.mo_occ)
        self.assertAlmostEqual(mf1.e_tot, -149.6097443357186, 8)
Beispiel #6
0
    def test_trans_rdm_with_frozen(self):
        mol = gto.M(atom='''
        O   0.   0.       .0
        H   0.   -0.757   0.587
        H   0.   0.757    0.587''', basis='sto3g')
        mf = scf.convert_to_ghf(scf.RHF(mol).run())
        orbspin = mf.mo_coeff.orbspin
        idxa = numpy.where(orbspin == 0)[0]
        idxb = numpy.where(orbspin == 1)[0]
        nmo_1c = mf.mo_coeff.shape[1]//2

        def check_frozen(frozen):
            myci = ci.GCISD(mf)
            myci.frozen = frozen
            myci.nroots = 3
            myci.kernel()
            nocc = myci.nocc
            nmo = myci.nmo
            nfroz = len(frozen)
            try:
                ket_id = 1
                fciket = gcisd.to_fcivec(myci.ci[ket_id], mol.nelectron, orbspin, myci.frozen)
            except RuntimeError:
                ket_id = 2
                fciket = gcisd.to_fcivec(myci.ci[ket_id], mol.nelectron, orbspin, myci.frozen)
                # spin-forbidden transition
                cidm1  = myci.trans_rdm1(myci.ci[0], myci.ci[1], nmo, nocc)
                self.assertAlmostEqual(abs(cidm1[idxa[:,None],idxa]).max(), 0, 7)
                self.assertAlmostEqual(abs(cidm1[idxb[:,None],idxb]).max(), 0, 7)

            cibra = (myci.ci[0] + myci.ci[ket_id]) * numpy.sqrt(.5)
            fcibra = gcisd.to_fcivec(cibra, mol.nelectron, orbspin, myci.frozen)
            fcidm1 = fci.direct_spin1.trans_rdm1s(fcibra, fciket, nmo_1c, mol.nelectron)
            cidm1  = myci.trans_rdm1(cibra, myci.ci[ket_id], nmo, nocc)
            self.assertAlmostEqual(abs(fcidm1[0]-cidm1[idxa[:,None],idxa]).max(), 0, 12)
            self.assertAlmostEqual(abs(fcidm1[1]-cidm1[idxb[:,None],idxb]).max(), 0, 12)

        check_frozen([10])
        check_frozen([10,3])