Esempio n. 1
0
    def test_jk_metric(self):
        numpy.random.seed(12)
        nao = mol.nao_nr()
        dm = numpy.random.random((nao,nao))
        dm = dm + dm.T
        vj0, vk0 = scf.RHF(mol).get_jk(mol, dm)
        ej0 = numpy.einsum('ij,ij->', vj0, dm)
        ek0 = numpy.einsum('ij,ij->', vk0, dm)
        jkdf = mdf.MDF(mol)
        jkdf.metric = 'S'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10,)*3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm)-ej0, 9.5034429456575253e-5, 9)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm)-ek0, -4.759826947520196e-5, 9)

        jkdf = mdf.MDF(mol)
        jkdf.metric = 'T'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10,)*3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm)-ej0, 0.005304754655668375, 9)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm)-ek0, 0.076335586801803856, 9)

        jkdf = mdf.MDF(mol)
        jkdf.metric = 'J'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10,)*3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm)-ej0, -6.56455759013852e-5, 9)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm)-ek0, -4.965601597461955e-5, 9)
Esempio n. 2
0
    def test_rhf_0d(self):
        from pyscf.df import mdf_jk
        from pyscf.scf import hf
        L = 4
        cell = pbcgto.Cell()
        cell.build(unit = 'B',
                   a = numpy.eye(3)*L*5,
                   gs = [10]*3,
                   atom = '''He 2 2 2; He 2 2 3''',
                   dimension = 0,
                   verbose = 0,
                   basis = { 'He': [[0, (0.8, 1.0)],
                                    [0, (1.0, 1.0)],
                                    [0, (1.2, 1.0)]]})
        mol = cell.to_mol()
        mf = mdf_jk.density_fit(hf.RHF(mol))
        mf.with_df.gs = [10]*3
        mf.with_df.auxbasis = {'He':[[0, (1e6, 1)]]}
        mf.with_df.charge_constraint = False
        mf.with_df.metric = 'S'
        eref = mf.kernel()

        mf = pbchf.RHF(cell)
        mf.with_df = pdf.PWDF(cell)
        mf.get_hcore = lambda *args: hf.get_hcore(mol)
        mf.energy_nuc = lambda *args: mol.energy_nuc()
        e1 = mf.kernel()
        self.assertAlmostEqual(e1, eref, 8)
Esempio n. 3
0
    def test_rhf_0d(self):
        from pyscf.df import mdf_jk
        from pyscf.scf import hf
        L = 4
        cell = pbcgto.Cell()
        cell.build(
            unit='B',
            a=numpy.eye(3) * L * 5,
            gs=[10] * 3,
            atom='''He 2 2 2; He 2 2 3''',
            dimension=0,
            verbose=0,
            basis={'He': [[0, (0.8, 1.0)], [0, (1.0, 1.0)], [0, (1.2, 1.0)]]})
        mol = cell.to_mol()
        mf = mdf_jk.density_fit(hf.RHF(mol))
        mf.with_df.gs = [10] * 3
        mf.with_df.auxbasis = {'He': [[0, (1e6, 1)]]}
        mf.with_df.charge_constraint = False
        mf.with_df.metric = 'S'
        eref = mf.kernel()

        mf = pbchf.RHF(cell)
        mf.with_df = pdf.PWDF(cell)
        mf.exxdiv = None
        mf.get_hcore = lambda *args: hf.get_hcore(mol)
        mf.energy_nuc = lambda *args: mol.energy_nuc()
        e1 = mf.kernel()
        self.assertAlmostEqual(e1, eref, 8)
Esempio n. 4
0
 def test_j(self):
     numpy.random.seed(12)
     nao = mol.nao_nr()
     dm = numpy.random.random((nao,nao))
     dm = dm + dm.T
     mf = mdf_jk.density_fit(scf.RHF(mol), auxbasis='weigend', gs=(10,)*3)
     vj1 = mf.get_j(mol, dm)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm), 50.470715659848707, 9)
Esempio n. 5
0
    def test_jk_charge_constraint(self):
        numpy.random.seed(12)
        nao = mol.nao_nr()
        dm = numpy.random.random((nao, nao))
        dm = dm + dm.T
        vj0, vk0 = scf.RHF(mol).get_jk(mol, dm)
        ej0 = numpy.einsum('ij,ij->', vj0, dm)
        ek0 = numpy.einsum('ij,ij->', vk0, dm)
        jkdf = mdf.MDF(mol)
        jkdf.charge_constraint = False
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10, ) * 3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vj1, dm) - ej0, 0.0003166388141693232, 9)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vk1, dm) - ek0, 0.0005799101835037845, 9)

        jkdf = mdf.MDF(mol)
        jkdf.charge_constraint = False
        jkdf.metric = 'T'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10, ) * 3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vj1, dm) - ej0, 0.12360821384800857, 9)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vk1, dm) - ek0, 0.4701984522179572, 9)

        jkdf = mdf.MDF(mol)
        jkdf.charge_constraint = False
        jkdf.metric = 'J'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10, ) * 3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vj1, dm) - ej0, -6.3466650786381251e-5, 9)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vk1, dm) - ek0, -4.5425207332527862e-5, 9)
Esempio n. 6
0
 def test_j(self):
     numpy.random.seed(12)
     nao = mol.nao_nr()
     dm = numpy.random.random((nao, nao))
     dm = dm + dm.T
     mf = mdf_jk.density_fit(scf.RHF(mol),
                             auxbasis='weigend',
                             gs=(10, ) * 3)
     vj1 = mf.get_j(mol, dm)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm),
                            50.470715659848707, 9)
Esempio n. 7
0
 def test_jk(self):
     numpy.random.seed(12)
     nao = mol.nao_nr()
     dm = numpy.random.random((nao,nao))
     dm = dm + dm.T
     #mf = poisson_jk.with_poisson_(scf.RHF(mol), auxbasis='weigend', gs=(10,)*3)
     mf = mdf_jk.density_fit(scf.RHF(mol), auxbasis='weigend', gs=(10,)*3)
     vj1, vk1 = mf.get_jk(mol, dm)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm), 50.470715659848707, 9)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm), 66.448255856461131, 9)
     vk1 = mf.get_k(mol, dm, hermi=0)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm), 66.448255856461131, 9)
Esempio n. 8
0
    def test_jk_metric(self):
        numpy.random.seed(12)
        nao = mol.nao_nr()
        dm = numpy.random.random((nao, nao))
        dm = dm + dm.T
        vj0, vk0 = scf.RHF(mol).get_jk(mol, dm)
        ej0 = numpy.einsum('ij,ij->', vj0, dm)
        ek0 = numpy.einsum('ij,ij->', vk0, dm)
        jkdf = mdf.MDF(mol)
        jkdf.metric = 'S'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10, ) * 3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vj1, dm) - ej0, 9.5034429456575253e-5, 9)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vk1, dm) - ek0, -4.759826947520196e-5, 9)

        jkdf = mdf.MDF(mol)
        jkdf.metric = 'T'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10, ) * 3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vj1, dm) - ej0, 0.005304754655668375, 9)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vk1, dm) - ek0, 0.076335586801803856, 9)

        jkdf = mdf.MDF(mol)
        jkdf.metric = 'J'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10, ) * 3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vj1, dm) - ej0, -6.56455759013852e-5, 9)
        self.assertAlmostEqual(
            numpy.einsum('ij,ij->', vk1, dm) - ek0, -4.965601597461955e-5, 9)
Esempio n. 9
0
 def test_jk_hermi0(self):
     numpy.random.seed(12)
     nao = mol.nao_nr()
     dm = numpy.random.random((nao,nao))
     dm = dm + dm.T
     dm[:2,-3:] *= .5
     vj0, vk0 = scf.RHF(mol).get_jk(mol, dm, hermi=0)
     ej0 = numpy.einsum('ij,ij->', vj0, dm)
     ek0 = numpy.einsum('ij,ij->', vk0, dm)
     mf = mdf_jk.density_fit(scf.RHF(mol), auxbasis='weigend', gs=(10,)*3)
     vj1, vk1 = mf.get_jk(mol, dm, hermi=0)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm)-ej0, 0.00010173096167420681, 9)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm)-ek0, -6.4503261583581661e-5, 9)
Esempio n. 10
0
    def test_jk_charge_constraint(self):
        numpy.random.seed(12)
        nao = mol.nao_nr()
        dm = numpy.random.random((nao,nao))
        dm = dm + dm.T
        vj0, vk0 = scf.RHF(mol).get_jk(mol, dm)
        ej0 = numpy.einsum('ij,ij->', vj0, dm)
        ek0 = numpy.einsum('ij,ij->', vk0, dm)
        jkdf = mdf.MDF(mol)
        jkdf.charge_constraint = False
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10,)*3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm)-ej0, 0.0003166388141693232, 9)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm)-ek0, 0.0005799101835037845, 9)

        jkdf = mdf.MDF(mol)
        jkdf.charge_constraint = False
        jkdf.metric = 'T'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10,)*3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm)-ej0, 0.12360821384800857, 9)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm)-ek0, 0.4701984522179572, 9)

        jkdf = mdf.MDF(mol)
        jkdf.charge_constraint = False
        jkdf.metric = 'J'
        jkdf.auxbasis = 'weigend'
        jkdf.gs = (10,)*3
        mf = mdf_jk.density_fit(scf.RHF(mol), with_df=jkdf)
        vj1, vk1 = mf.get_jk(mol, dm)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm)-ej0, -6.3466650786381251e-5, 9)
        self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm)-ek0, -4.5425207332527862e-5, 9)
Esempio n. 11
0
 def test_jk_hermi0(self):
     numpy.random.seed(12)
     nao = mol.nao_nr()
     dm = numpy.random.random((nao, nao))
     dm = dm + dm.T
     dm[:2, -3:] *= .5
     vj0, vk0 = scf.RHF(mol).get_jk(mol, dm, hermi=0)
     ej0 = numpy.einsum('ij,ij->', vj0, dm)
     ek0 = numpy.einsum('ij,ij->', vk0, dm)
     mf = mdf_jk.density_fit(scf.RHF(mol),
                             auxbasis='weigend',
                             gs=(10, ) * 3)
     vj1, vk1 = mf.get_jk(mol, dm, hermi=0)
     self.assertAlmostEqual(
         numpy.einsum('ij,ij->', vj1, dm) - ej0, 0.00010173096167420681, 9)
     self.assertAlmostEqual(
         numpy.einsum('ij,ij->', vk1, dm) - ek0, -6.4503261583581661e-5, 9)
Esempio n. 12
0
 def test_jk(self):
     numpy.random.seed(12)
     nao = mol.nao_nr()
     dm = numpy.random.random((nao, nao))
     dm = dm + dm.T
     #mf = poisson_jk.with_poisson_(scf.RHF(mol), auxbasis='weigend', gs=(10,)*3)
     mf = mdf_jk.density_fit(scf.RHF(mol),
                             auxbasis='weigend',
                             gs=(10, ) * 3)
     vj1, vk1 = mf.get_jk(mol, dm)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vj1, dm),
                            50.470715659848707, 9)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm),
                            66.448255856461131, 9)
     vk1 = mf.get_k(mol, dm, hermi=0)
     self.assertAlmostEqual(numpy.einsum('ij,ij->', vk1, dm),
                            66.448255856461131, 9)
Esempio n. 13
0
 def update_mf(self, mf):
     from pyscf.df import mdf_jk
     return mdf_jk.density_fit(mf, self.auxbasis, self.gs, with_df=self)