Beispiel #1
0
    def test_init_guess_by_chkfile(self):
        n = 9
        nk = (1, 1, 1)
        cell = make_primitive_cell([n] * 3)

        kpts = cell.make_kpts(nk)
        kmf = khf.KRHF(cell, kpts, exxdiv='vcut_sph')
        kmf.chkfile = tempfile.NamedTemporaryFile().name
        kmf.conv_tol = 1e-9
        ekpt = kmf.scf()
        dm1 = kmf.make_rdm1()
        dm2 = kmf.from_chk(kmf.chkfile)
        self.assertTrue(dm2.dtype == np.double)
        self.assertTrue(np.allclose(dm1, dm2))

        mf = pscf.RHF(cell, exxdiv='vcut_sph')
        mf.chkfile = kmf.chkfile
        mf.init_guess = 'chkfile'
        mf.max_cycle = 1
        e1 = mf.kernel()
        mf.conv_check = False
        self.assertAlmostEqual(e1, ekpt, 9)

        nk = (3, 1, 1)
        kpts = cell.make_kpts(nk)
        kmf1 = khf.KRHF(cell, kpts, exxdiv='vcut_sph')
        kmf1.conv_tol = 1e-9
        kmf1.chkfile = mf.chkfile
        kmf1.init_guess = 'chkfile'
        kmf1.max_cycle = 2
        ekpt = kmf1.scf()
        kmf1.conv_check = False
        self.assertAlmostEqual(ekpt, -11.215259853108822, 8)
Beispiel #2
0
    def test_init_guess_by_chkfile(self):
        ngs = 4
        nk = (1, 1, 1)
        cell = make_primitive_cell(ngs)

        kpts = cell.make_kpts(nk)
        kmf = khf.KRHF(cell, kpts, exxdiv='vcut_sph')
        ekpt = kmf.scf()
        dm1 = kmf.make_rdm1()
        dm2 = kmf.from_chk(kmf.chkfile)
        self.assertTrue(dm2.dtype == np.double)
        self.assertTrue(np.allclose(dm1, dm2))

        mf = pbchf.RHF(cell, exxdiv='vcut_sph')
        mf.chkfile = kmf.chkfile
        mf.init_guess = 'chkfile'
        dm1 = mf.from_chk(kmf.chkfile)
        mf.max_cycle = 1
        e1 = mf.kernel()
        self.assertAlmostEqual(e1, ekpt, 9)

        nk = (3, 1, 1)
        kpts = cell.make_kpts(nk)
        kmf1 = khf.KRHF(cell, kpts, exxdiv='vcut_sph')
        dm = kmf1.from_chk(mf.chkfile)
        kmf1.max_cycle = 1
        ekpt = kmf1.scf(dm)
        self.assertAlmostEqual(ekpt, -11.17814699669376, 8)
Beispiel #3
0
    def test_init_guess_by_chkfile(self):
        n = 9
        nk = (1, 1, 1)
        cell = make_primitive_cell([n]*3)

        kpts = cell.make_kpts(nk)
        kmf = khf.KRHF(cell, kpts, exxdiv='vcut_sph')
        kmf.conv_tol = 1e-9
        ekpt = kmf.scf()
        dm1 = kmf.make_rdm1()
        dm2 = kmf.from_chk(kmf.chkfile)
        self.assertTrue(dm2.dtype == np.double)
        self.assertTrue(np.allclose(dm1, dm2))

        mf = pbchf.RHF(cell, exxdiv='vcut_sph')
        mf.chkfile = kmf.chkfile
        mf.init_guess = 'chkfile'
        dm1 = mf.from_chk(kmf.chkfile)
        mf.max_cycle = 1
        e1 = mf.kernel(dm1)
        mf.conv_check = False
        self.assertAlmostEqual(e1, ekpt, 9)

        nk = (3, 1, 1)
        kpts = cell.make_kpts(nk)
        kmf1 = khf.KRHF(cell, kpts, exxdiv='vcut_sph')
        kmf1.conv_tol = 1e-9
        dm = kmf1.from_chk(mf.chkfile)
        kmf1.max_cycle = 2
        ekpt = kmf1.scf(dm)
        kmf1.conv_check = False
        self.assertAlmostEqual(ekpt, -11.215218432275057, 8)
Beispiel #4
0
    def test_kpt_vs_supercell_high_cost(self):
        # For large n, agreement is always achieved
        # n = 17
        # For small n, agreement only achieved if "wrapping" k-k'+G in get_coulG
        n = 9
        nk = (3, 1, 1)
        cell = make_primitive_cell([n]*3)

        abs_kpts = cell.make_kpts(nk, wrap_around=True)
        kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph')
        ekpt = kmf.scf()
        self.assertAlmostEqual(ekpt, -11.221426249047617, 8)

        nk = (5, 1, 1)
        abs_kpts = cell.make_kpts(nk, wrap_around=True)
        kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph')
        ekpt = kmf.scf()
        self.assertAlmostEqual(ekpt, -12.337299166550796, 8)

        supcell = pyscf.pbc.tools.super_cell(cell, nk)
        supcell.build()
        #print "supcell mesh =", supcell.mesh

        gamma = [0,0,0]
        mf = khf.KRHF(supcell, gamma, exxdiv='vcut_sph')
        esup = mf.scf()/np.prod(nk)

        #print "kpt sampling energy =", ekpt
        #print "supercell energy    =", esup
        #print "difference          =", ekpt-esup
        self.assertAlmostEqual(ekpt, esup, 6)
Beispiel #5
0
    def test_kpt_vs_supercell(self):
        # For large ngs, agreement is always achieved
        # ngs = 8
        # For small ngs, agreement only achieved if "wrapping" k-k'+G in get_coulG
        ngs = 4
        nk = (3, 1, 1)
        cell = make_primitive_cell(ngs)

        abs_kpts = cell.make_kpts(nk, wrap_around=True)
        kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph')
        ekpt = kmf.scf()
        self.assertAlmostEqual(ekpt, -11.221426249047617, 8)

        nk = (5, 1, 1)
        abs_kpts = cell.make_kpts(nk, wrap_around=True)
        kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph')
        ekpt = kmf.scf()
        self.assertAlmostEqual(ekpt, -12.337299166550796, 8)

        supcell = pyscf.pbc.tools.super_cell(cell, nk)
        supcell.gs = np.array([
            nk[0] * ngs + (nk[0] - 1) // 2, nk[1] * ngs + (nk[1] - 1) // 2,
            nk[2] * ngs + (nk[2] - 1) // 2
        ])
        #print "supcell gs =", supcell.gs
        supcell.build()

        gamma = [0, 0, 0]
        mf = khf.KRHF(supcell, gamma, exxdiv='vcut_sph')
        esup = mf.scf() / np.prod(nk)

        #print "kpt sampling energy =", ekpt
        #print "supercell energy    =", esup
        #print "difference          =", ekpt-esup
        self.assertAlmostEqual(ekpt, esup, 6)
Beispiel #6
0
 def test_krhf_2d(self):
     L = 4
     cell = pbcgto.Cell()
     cell.build(
         unit='B',
         a=np.eye(3) * 4,
         mesh=[10, 10, 20],
         atom='''He 2 0 0; He 3 0 0''',
         dimension=2,
         low_dim_ft_type='inf_vacuum',
         verbose=0,
         rcut=7.427535697575829,
         basis={
             'He': [
                 [0, (0.8, 1.0)],
                 #[0, (1.0, 1.0)],
                 [0, (1.2, 1.0)]
             ]
         })
     mf = khf.KRHF(cell)
     mf.with_df = df.AFTDF(cell)
     mf.with_df.eta = 0.2
     mf.with_df.mesh = cell.mesh
     mf.kpts = cell.make_kpts([2, 1, 1])
     e1 = mf.kernel()
     self.assertAlmostEqual(e1, -3.5376801775171911, 5)
Beispiel #7
0
 def test_krhf_1d(self):
     L = 4
     cell = pbcgto.Cell()
     cell.build(
         unit='B',
         a=np.eye(3) * 4,
         mesh=[8, 20, 20],
         atom='''He 2 0 0; He 3 0 0''',
         dimension=1,
         low_dim_ft_type='inf_vacuum',
         verbose=0,
         basis={
             'He': [
                 [0, (0.8, 1.0)],
                 #[0, (1.0, 1.0)],
                 [0, (1.2, 1.0)]
             ]
         })
     mf = khf.KRHF(cell)
     mf.with_df = df.AFTDF(cell)
     mf.with_df.eta = 0.2
     mf.init_guess = 'hcore'
     mf.kpts = cell.make_kpts([2, 1, 1])
     e1 = mf.kernel()
     self.assertAlmostEqual(e1, -3.5112358424228809, 5)
Beispiel #8
0
    def test_kpt_vs_supercell(self):
        # For large ngs, agreement is always achieved
        # ngs = 8
        # For small ngs, agreement only achieved if "wrapping" k-k'+G in get_coulG
        ngs = 4
        nk = (3, 1, 1)
        cell = make_primitive_cell(ngs)

        scaled_kpts = ase.dft.kpoints.monkhorst_pack(nk)
        abs_kpts = cell.get_abs_kpts(scaled_kpts)
        kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph')
        ekpt = kmf.scf()
        self.assertAlmostEqual(ekpt, -11.221426249047617, 8)

        nk = (5, 1, 1)
        scaled_kpts = ase.dft.kpoints.monkhorst_pack(nk)
        abs_kpts = cell.get_abs_kpts(scaled_kpts)
        kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph')
        ekpt = kmf.scf()
        self.assertAlmostEqual(ekpt, -12.337299038604856, 8)

        supcell = pyscf.pbc.tools.super_cell(cell, nk)
        supcell.gs = np.array([
            nk[0] * ngs + (nk[0] - 1) // 2, nk[1] * ngs + (nk[1] - 1) // 2,
            nk[2] * ngs + (nk[2] - 1) // 2
        ])
        #print "supcell gs =", supcell.gs
        supcell.build()

        scaled_gamma = ase.dft.kpoints.monkhorst_pack((1, 1, 1))
        gamma = supcell.get_abs_kpts(scaled_gamma)
        mf = khf.KRHF(supcell, gamma, exxdiv='vcut_sph')
        esup = mf.scf() / np.prod(nk)

        #print "kpt sampling energy =", ekpt
        #print "supercell energy    =", esup
        #print "difference          =", ekpt-esup
        self.assertAlmostEqual(ekpt, esup, 6)
Beispiel #9
0
 def test_coulG_ws(self):
     ase_atom = bulk('C', 'diamond', a=3.5668)
     cell = pbcgto.Cell()
     cell.unit = 'A'
     cell.atom = pyscf_ase.ase_atoms_to_pyscf(ase_atom)
     cell.a = ase_atom.cell
     cell.basis = 'gth-szv'
     cell.pseudo = 'gth-pade'
     cell.gs = [5] * 3
     cell.verbose = 5
     cell.output = '/dev/null'
     cell.build()
     mf = khf.KRHF(cell, exxdiv='vcut_ws')
     mf.kpts = cell.make_kpts([2, 2, 2])
     coulG = tools.get_coulG(cell, mf.kpts[2], True, mf)
     self.assertAlmostEqual(finger(coulG), 1.3245117871351604, 9)
Beispiel #10
0
 def test_coulG_ws(self):
     cell = pbcgto.Cell()
     cell.unit = 'A'
     cell.atom = 'C 0.,  0.,  0.; C 0.8917,  0.8917,  0.8917'
     cell.a = '''0.      1.7834  1.7834
                 1.7834  0.      1.7834
                 1.7834  1.7834  0.    '''
     cell.basis = 'gth-szv'
     cell.pseudo = 'gth-pade'
     cell.gs = [5] * 3
     cell.verbose = 5
     cell.output = '/dev/null'
     cell.build()
     mf = khf.KRHF(cell, exxdiv='vcut_ws')
     mf.kpts = cell.make_kpts([2, 2, 2])
     coulG = tools.get_coulG(cell, mf.kpts[2], True, mf)
     self.assertAlmostEqual(finger(coulG), 1.3245117871351604, 9)
Beispiel #11
0
 def test_coulG_ws(self):
     cell = pbcgto.Cell()
     cell.unit = 'A'
     cell.atom = 'C 0.,  0.,  0.; C 0.8917,  0.8917,  0.8917'
     cell.a = '''0.      1.7834  1.7834
                 1.7834  0.      1.7834
                 1.7834  1.7834  0.    '''
     cell.basis = 'gth-szv'
     cell.pseudo = 'gth-pade'
     cell.mesh = [11]*3
     cell.verbose = 5
     cell.output = '/dev/null'
     cell.build()
     mf = khf.KRHF(cell, exxdiv='vcut_ws')
     mf.kpts = cell.make_kpts([2,2,2])
     coulG = tools.get_coulG(cell, mf.kpts[2], True, mf, gs=[5,5,5])
     self.assertAlmostEqual(lib.fp(coulG), 1.3245365170998518+0j, 9)
Beispiel #12
0
    def test_kpt_vs_supercell_high_cost(self):
        # For large n, agreement is always achieved
        # n = 17
        # For small n, agreement only achieved if "wrapping" k-k'+G in get_coulG
        n = 9
        nk = (3, 1, 1)
        cell = make_primitive_cell([n] * 3)

        abs_kpts = cell.make_kpts(nk, wrap_around=True)
        kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph')
        ekpt = kmf.scf()
        self.assertAlmostEqual(ekpt, -11.221426249047617, 8)

        #        nk = (5, 1, 1)
        #        abs_kpts = cell.make_kpts(nk, wrap_around=True)
        #        kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph')
        #        ekpt = kmf.scf()
        #        self.assertAlmostEqual(ekpt, -12.337299166550796, 8)

        supcell = pyscf.pbc.tools.super_cell(cell, nk)
        mf = pscf.RHF(supcell, exxdiv='vcut_sph')
        esup = mf.scf() / np.prod(nk)
        self.assertAlmostEqual(ekpt, esup, 8)
Beispiel #13
0
def setUpModule():
    global cell, kmf, kumf, kpts
    cell = make_primitive_cell([9] * 3)
    kpts = cell.make_kpts([3, 1, 1])
    kmf = khf.KRHF(cell, kpts, exxdiv='vcut_sph').run(conv_tol=1e-9)
    kumf = kuhf.KUHF(cell, kpts, exxdiv='vcut_sph').run(conv_tol=1e-9)
Beispiel #14
0
                1.7834  0.      1.7834
                1.7834  1.7834  0.    '''

    cell.basis = 'gth-szv'
    cell.pseudo = 'gth-pade'
    cell.mesh = mesh

    cell.verbose = 7
    cell.output = '/dev/null'
    cell.build()
    return cell


cell = make_primitive_cell([9] * 3)
kpts = cell.make_kpts([3, 1, 1])
kmf = khf.KRHF(cell, kpts, exxdiv='vcut_sph').run(conv_tol=1e-9)
kumf = kuhf.KUHF(cell, kpts, exxdiv='vcut_sph').run(conv_tol=1e-9)


def tearDownModule():
    global cell, kmf, kumf
    cell.stdout.close()
    del cell, kmf, kumf


class KnownValues(unittest.TestCase):
    def test_analyze(self):
        rpop, rchg = kmf.analyze()  # pop at gamma point
        upop, uchg = kumf.analyze()
        self.assertTrue(isinstance(rpop, np.ndarray) and rpop.ndim == 1)
        self.assertAlmostEqual(abs(upop[0] + upop[1] - rpop).max(), 0, 7)