Esempio n. 1
0
    def test_chkfile_k_point(self):
        cell = pbcgto.Cell()
        cell.a = np.eye(3) * 6
        cell.mesh = [21] * 3
        cell.unit = 'B'
        cell.atom = '''He     2.    2.       3.
                      He     3.    2.       3.'''
        cell.basis = {'He': 'sto3g'}
        cell.verbose = 0
        cell.build()
        mf1 = pbcdft.RKS(cell)
        mf1.chkfile = tempfile.NamedTemporaryFile().name
        mf1.max_cycle = 1
        mf1.kernel()

        cell = pbcgto.Cell()
        cell.a = np.eye(3) * 6
        cell.mesh = [41] * 3
        cell.unit = 'B'
        cell.atom = '''He     2.    2.       3.
                       He     3.    2.       3.'''
        cell.basis = {'He': 'ccpvdz'}
        cell.verbose = 5
        cell.output = '/dev/null'
        cell.nimgs = [2, 2, 2]
        cell.build()
        mf = pbcdft.RKS(cell)
        np.random.seed(10)
        mf.kpt = np.random.random(3)
        mf.max_cycle = 1
        dm = mf.from_chk(mf1.chkfile)
        mf.conv_check = False
        self.assertAlmostEqual(mf.scf(dm), -4.7090816314173365, 8)
Esempio n. 2
0
    def test_chkfile_k_point(self):
        cell = pbcgto.Cell()
        cell.h = np.eye(3) * 6
        cell.gs = [10, 10, 10]
        cell.unit = 'B'
        cell.atom = '''He     2.    2.       3.
                      He     3.    2.       3.'''
        cell.basis = {'He': 'sto3g'}
        cell.verbose = 0
        cell.build()
        mf1 = pbcdft.RKS(cell)
        mf1.max_cycle = 1
        mf1.kernel()

        cell = pbcgto.Cell()
        cell.h = np.eye(3) * 6
        cell.gs = [20, 20, 20]
        cell.unit = 'B'
        cell.atom = '''He     2.    2.       3.
                       He     3.    2.       3.'''
        cell.basis = {'He': 'ccpvdz'}
        cell.verbose = 5
        cell.output = '/dev/null'
        cell.nimgs = [2, 2, 2]
        cell.build()
        mf = pbcdft.RKS(cell)
        np.random.seed(10)
        mf.kpt = np.random.random(3)
        mf.max_cycle = 1
        dm = mf.from_chk(mf1.chkfile)
        self.assertAlmostEqual(mf.scf(dm), -4.7088482555684914, 8)
Esempio n. 3
0
def test_cubic_diamond_C():
    """
    Take ASE Diamond structure, input into PySCF and run
    """
    ase_atom = Diamond(symbol='C', latticeconstant=3.5668)
    print "Cell volume =", ase_atom.get_volume()

    cell = pbcgto.Cell()
    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 = np.array([10, 10, 10])
    # cell.verbose = 7
    cell.build(None, None)
    mf = pbcdft.RKS(cell)
    mf.analytic_int = False
    mf.xc = 'lda,vwn'
    print mf.scf()

    # Gamma point gs: 10x10x10: -11.220279983393
    #             gs: 14x14x14: -11.220122248175
    # K pt calc
    scaled_kpts = ase.dft.kpoints.monkhorst_pack((2, 2, 2))
    abs_kpts = cell.get_abs_kpts(scaled_kpts)

    kmf = pyscf.pbc.scf.kscf.KRKS(cell, abs_kpts)
    kmf.analytic_int = False
    kmf.xc = 'lda,vwn'
    kmf.verbose = 7
    print kmf.scf()
Esempio n. 4
0
    def test_kpt_vs_supercell(self):
        ngs = 5
        nk = (3, 1, 1)
        # Comparison is only perfect for odd-numbered supercells and kpt sampling
        assert all(np.array(nk) % 2 == np.array([1, 1, 1]))
        cell = make_primitive_cell(ngs)
        scaled_kpts = ase.dft.kpoints.monkhorst_pack(nk)
        abs_kpts = cell.get_abs_kpts(scaled_kpts)
        kmf = pbcdft.KRKS(cell, abs_kpts)
        kmf.xc = 'lda,vwn'
        #kmf.analytic_int = False
        #kmf.verbose = 7
        ekpt = kmf.scf()

        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
        ])
        #supcell.verbose = 7
        supcell.build()

        mf = pbcdft.RKS(supcell)
        mf.xc = 'lda,vwn'
        #mf.verbose = 7
        esup = mf.scf() / np.prod(nk)

        #print("kpt sampling energy =", ekpt)
        #print("supercell energy    =", esup)
        self.assertAlmostEqual(ekpt, esup, 5)
Esempio n. 5
0
 def xtest_gamma(self):
     cell = make_primitive_cell(8)
     mf = pbcdft.RKS(cell)
     mf.xc = 'lda,vwn'
     #mf.verbose = 7
     e1 = mf.scf()
     self.assertAlmostEqual(e1, -10.2214263103747, 8)
Esempio n. 6
0
def run_dft(cell):
    """Run a gamma-point DFT (LDA) calculation."""
    mf = pbcdft.RKS(cell)
    mf.xc = 'lda,vwn'
    mf.verbose = 7
    print mf.scf()
    return mf
Esempio n. 7
0
 def test_rsh_aft_high_cost(self):
     from pyscf.pbc.df.aft import AFTDF
     mf = pbcdft.RKS(cell)
     mf.with_df = AFTDF(cell)
     mf.xc = 'camb3lyp'
     mf.kernel()
     self.assertAlmostEqual(mf.e_tot, -2.4745140705800446, 7)
Esempio n. 8
0
 def test_nr_rks_lda(self):
     mf = dft.RKS(cell)
     mf.xc = 'lda,'
     mf = scf.newton(mf)
     mf.conv_tol_grad = 1e-4
     mf.kernel()
     self.assertAlmostEqual(mf.e_tot, -9.7670882971475663, 8)
Esempio n. 9
0
    def test_pp_RKS(self):
        cell = pbcgto.Cell()

        cell.unit = 'A'
        cell.atom = '''
            Si    0.000000000    0.000000000    0.000000000;
            Si    0.000000000    2.715348700    2.715348700;
            Si    2.715348700    2.715348700    0.000000000;
            Si    2.715348700    0.000000000    2.715348700;
            Si    4.073023100    1.357674400    4.073023100;
            Si    1.357674400    1.357674400    1.357674400;
            Si    1.357674400    4.073023100    4.073023100;
            Si    4.073023100    4.073023100    1.357674400
        '''
        cell.basis = 'gth-szv'
        cell.pseudo = 'gth-pade'

        Lx = Ly = Lz = 5.430697500
        cell.h = np.diag([Lx, Ly, Lz])
        cell.gs = np.array([10, 10, 10])

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

        mf = pbcdft.RKS(cell)
        mf.xc = 'lda,vwn'
        self.assertAlmostEqual(mf.scf(), -31.081616722101646, 8)
Esempio n. 10
0
 def test_klda8_primitive_gamma(self):
     cell = make_primitive_cell(8)
     mf = pbcdft.RKS(cell)
     mf.xc = 'lda,vwn'
     #kmf.verbose = 7
     e1 = mf.scf()
     self.assertAlmostEqual(e1, -10.221426445656439, 8)
Esempio n. 11
0
 def test_nr_rks_gga(self):
     mf = dft.RKS(cell)
     mf.xc = 'b88,'
     mf = scf.newton(mf)
     mf.conv_tol_grad = 1e-4
     mf.kernel()
     self.assertAlmostEqual(mf.e_tot, -9.9355341416893559, 8)
Esempio n. 12
0
    def test_rsh_0d_ewald(self):
        L = 4.
        cell = pbcgto.Cell()
        cell.verbose = 0
        cell.a = np.eye(3) * L
        cell.atom = [
            ['He', (L / 2 + 0., L / 2 + 0., L / 2 + 1.)],
        ]
        cell.basis = {'He': [[0, (4.0, 1.0)], [0, (1.0, 1.0)]]}
        cell.dimension = 0
        cell.mesh = [60] * 3
        cell.build()
        mf = pbcdft.RKS(cell).density_fit()
        mf.xc = 'camb3lyp'
        mf.omega = '0.7'
        mf.exxdiv = 'ewald'
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.4836186361124617, 7)

        mol = cell.to_mol()
        mf1 = mol.RKS().density_fit()
        mf1.xc = 'camb3lyp'
        mf1.omega = '0.7'
        mf1.kernel()
        self.assertAlmostEqual(mf1.e_tot, mf.e_tot, 4)
Esempio n. 13
0
 def test_klda8_cubic_gamma(self):
     cell = build_cell([17]*3)
     mf = pbcdft.RKS(cell)
     mf.xc = 'lda,vwn'
     #kmf.verbose = 7
     e1 = mf.scf()
     self.assertAlmostEqual(e1, -44.892502703975893, 8)
Esempio n. 14
0
 def test_multigrid_rks(self):
     mf = dft.RKS(cell_he)
     mf.xc = 'lda,'
     ref = mf.get_veff(cell_he, dm_he[0])
     out = multigrid.multigrid(mf).get_veff(cell_he, dm_he[0])
     self.assertAlmostEqual(float(abs(ref - out).max()), 0, 9)
     self.assertAlmostEqual(abs(ref.exc - out.exc).max(), 0, 9)
     self.assertAlmostEqual(abs(ref.ecoul - out.ecoul).max(), 0, 9)
Esempio n. 15
0
    def test_rsh_mdf(self):
        mf = pbcdft.RKS(cell).mix_density_fit()
        mf.xc = 'camb3lyp'
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.4745138538438827, 7)

        mf.omega = .15
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.4766174820185456, 7)
Esempio n. 16
0
    def test_custom_rsh_df(self):
        mf = pbcdft.RKS(cell).density_fit()
        mf.xc = 'camb3lyp'
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.474520122522153, 7)

        mf.omega = .15
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.4766238116030683, 7)
Esempio n. 17
0
    def test_rsh_fft(self):
        mf = pbcdft.RKS(cell)
        mf.xc = 'camb3lyp'
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.4745140703871877, 7)

        mf.omega = .15
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.476617717375184, 7)
Esempio n. 18
0
    def test_rsh_fft(self):
        mf = pbcdft.RKS(cell)
        mf.xc = 'camb3lyp'
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.3032261128220544, 7)

        mf.omega = .15
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.3987595548455523, 7)
Esempio n. 19
0
    def test_rsh_mdf(self):
        mf = pbcdft.RKS(cell).mix_density_fit()
        mf.xc = 'camb3lyp'
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.303225896642264, 7)

        mf.omega = .15
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.398759319488945, 7)
Esempio n. 20
0
    def test_custom_rsh_df(self):
        mf = pbcdft.RKS(cell).density_fit()
        mf.xc = 'camb3lyp'
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.303232164939132, 7)

        mf.omega = .15
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -2.3987656490734555, 7)
Esempio n. 21
0
    def test_gamma_vs_ks_high_cost(self):
        mf = pdft.KRKS(cell)
        mf.kpts = cell.make_kpts([1, 1, 3])
        ek = mf.kernel()

        scell = ptools.super_cell(cell, [1, 1, 3])
        scell.mesh = [25, 25, 73]
        mf = pdft.RKS(scell)
        eg = mf.kernel()
        self.assertAlmostEqual(ek, eg / 3, 5)
Esempio n. 22
0
    def test_gamma_vs_ks(self):
        mf = pdft.KRKS(cell)
        mf.kpts = cell.make_kpts([1, 1, 3])
        ek = mf.kernel()

        scell = ptools.super_cell(cell, [1, 1, 3])
        scell.gs = [12, 12, 36]
        mf = pdft.RKS(scell)
        eg = mf.kernel()
        self.assertAlmostEqual(ek, eg / 3, 5)
Esempio n. 23
0
 def test_klda8_primitive_gamma(self):
     ase_atom = bulk('C', 'diamond', a=LATTICE_CONST)
     cell = build_cell(ase_atom, 8)
     mf = pbcdft.RKS(cell)
     mf.xc = 'lda,vwn'
     #kmf.verbose = 7
     e1 = mf.scf()
     #print "mf._ecoul =", mf._ecoul
     #print "mf._exc =", mf._exc
     self.assertAlmostEqual(e1, -10.221426938778345, 8)
Esempio n. 24
0
 def test_klda8_cubic_gamma(self):
     ase_atom = Diamond(symbol='C', latticeconstant=LATTICE_CONST)
     cell = build_cell(ase_atom, 8)
     mf = pbcdft.RKS(cell)
     mf.xc = 'lda,vwn'
     #kmf.verbose = 7
     e1 = mf.scf()
     #print "mf._ecoul =", mf._ecoul
     #print "mf._exc =", mf._exc
     self.assertAlmostEqual(e1, -44.892502703975893, 8)
Esempio n. 25
0
 def test_density_fit(self):
     L = 4.
     cell = pbcgto.Cell()
     cell.a = np.eye(3) * L
     cell.atom = [['He', (L / 2 + 0., L / 2 + 0., L / 2 + 1.)],
                  ['He', (L / 2 + 1., L / 2 + 0., L / 2 + 1.)]]
     cell.basis = {'He': [[0, (4.0, 1.0)], [0, (1.0, 1.0)]]}
     cell.build()
     mf = pbcdft.RKS(cell).density_fit()
     mf.kernel()
     self.assertAlmostEqual(mf.e_tot, -4.717699891018736, 7)
Esempio n. 26
0
def test_band_ase():
    from ase.lattice import bulk
    from ase.dft.kpoints import ibz_points, get_bandpath
    c = bulk('C', 'diamond', a=3.5668)
    print c.get_volume()
    points = ibz_points['fcc']
    G = points['Gamma']
    X = points['X']
    W = points['W']
    K = points['K']
    L = points['L']
    band_kpts, x, X = get_bandpath([L, G, X, W, K, G], c.cell, npoints=30)

    cell = pbcgto.Cell()
    cell.atom = pyscf_ase.ase_atoms_to_pyscf(c)
    cell.h = c.cell.T

    cell.basis = 'gth-szv'
    cell.pseudo = 'gth-pade'
    cell.gs = np.array([5, 5, 5])
    cell.verbose = 7
    cell.build(None, None)

    mf = pbcdft.RKS(cell)
    mf.analytic_int = False
    mf.xc = 'lda,vwn'
    print mf.scf()

    e_kn = []
    for kpt in band_kpts:
        fb, sb = mf.get_band_fock_ovlp(mf.get_hcore() + mf.get_veff(),
                                       mf.get_ovlp(), kpt)
        # fb, sb=mf.get_band_fock_ovlp(mf.get_hcore(),
        #                              mf.get_ovlp(), kpt)
        e, c = hf.eig(fb, sb)
        print kpt, e
        e_kn.append(e)

    emin = -1
    emax = 2

    plt.figure(figsize=(5, 6))
    nbands = cell.nao_nr()
    for n in range(nbands):
        plt.plot(x, [e_kn[i][n] for i in range(len(x))])
    for p in X:
        plt.plot([p, p], [emin, emax], 'k-')
    plt.plot([0, X[-1]], [0, 0], 'k-')
    plt.xticks(X, ['$%s$' % n for n in ['L', 'G', 'X', 'W', 'K', r'\Gamma']])
    plt.axis(xmin=0, xmax=X[-1], ymin=emin, ymax=emax)
    plt.xlabel('k-vector')

    plt.show()
Esempio n. 27
0
def test_cubic_diamond_He():
    """
    Take ASE Diamond structure, input into PySCF and run
    """
    ase_atom=Diamond(symbol='He', latticeconstant=3.5)
    print ase_atom.get_volume()

    cell = pbcgto.Cell()
    cell.atom=pyscf_ase.ase_atoms_to_pyscf(ase_atom)
    cell.h=ase_atom.cell.T
    cell.basis = {"He" : [[0, (1.0, 1.0)], [0, (0.8, 1.0)]] }

    cell.gs = np.array([15,15,15])
    # cell.verbose = 7
    cell.build(None, None)
    mf = pbcdft.RKS(cell)
    mf.analytic_int=False
    mf.xc = 'lda,vwn'
    print mf.scf()
    # Diamond cubic: -18.2278622592408

    mf = pbcdft.RKS(cell)
    mf.analytic_int=True
    mf.xc = 'lda,vwn'
    print mf.scf()
    # Diamond cubic (analytic): -18.2278622592283
    #                         = -4.556965564807075 / cell              

    # K pt calc
    scaled_kpts=ase.dft.kpoints.monkhorst_pack((2,2,2))
    abs_kpts=cell.get_abs_kpts(scaled_kpts)

    kmf = pyscf.pbc.scf.kscf.KRKS(cell, abs_kpts)
    kmf.analytic_int=False
    kmf.xc = 'lda,vwn'
    print kmf.scf()
Esempio n. 28
0
def test():

    ANALYTIC=False
    ase_atom=bulk('C', 'diamond', a=3.5668)

    cell = pbcgto.Cell()
    cell.atom=pyscf_ase.ase_atoms_to_pyscf(ase_atom)
    cell.h=ase_atom.cell
    cell.verbose = 7

    # gth-szv for C
    cell.basis = 'gth-szv'
    cell.pseudo = 'gth-pade'

    cell.gs = np.array([4,1,1])
    cell.build(None, None)

    print "N images: ", cell.nimgs
    cell.nimgs = [10,1,1]
    repcell = pyscf.pbc.tools.replicate_cell(cell, (3,1,1))
    print "REPCELL", repcell.pseudo

    mf = pbcdft.RKS(repcell)
    mf.verbose = 5
    mf.diis = False
    mf.analytic_int=ANALYTIC
    mf.xc = 'lda,vwn'
    mf.max_cycle = 1
    mf.init_guess = '1e'
    mf.scf()

    scaled_kpts=np.array(ase.dft.kpoints.monkhorst_pack((3,1,1)))
    abs_kpts=cell.get_abs_kpts(scaled_kpts)

    cell.gs = np.array([1,1,1])
    cell.nimgs = [14,1,1]
    cell.build(None, None)

    kmf = pyscf.pbc.scf.kscf.KRKS(cell, abs_kpts)
    kmf.analytic_int=ANALYTIC
    kmf.diis = False
    kmf.verbose = 5
    kmf.xc = 'lda,vwn'
    kmf.max_cycle = 1
    kmf.init_guess = '1e'
    kmf.scf()
Esempio n. 29
0
    def test_ccsd_t_non_hf_frozen(self):
        '''Tests ccsd and ccsd_t for non-Hartree-Fock references with frozen orbitals
        using supercell vs k-point calculation.'''
        n = 14
        cell = make_test_cell.test_cell_n3([n] * 3)
        #import sys
        #cell.stdout = sys.stdout
        #cell.verbose = 7

        nk = [2, 1, 1]
        kpts = cell.make_kpts(nk)
        kpts -= kpts[0]
        kks = pbcdft.KRKS(cell, kpts=kpts)
        ekks = kks.kernel()

        khf = pbcscf.KRHF(cell)
        khf.__dict__.update(kks.__dict__)

        mycc = pbcc.KRCCSD(khf, frozen=1)
        eris = mycc.ao2mo()
        ekcc, t1, t2 = mycc.kernel(eris=eris)

        ekcc_t = mycc.ccsd_t(eris=eris)

        # Run supercell
        from pyscf.pbc.tools.pbc import super_cell
        supcell = super_cell(cell, nk)
        rks = pbcdft.RKS(supcell)
        erks = rks.kernel()

        rhf = pbcscf.RHF(supcell)
        rhf.__dict__.update(rks.__dict__)

        mycc = pbcc.RCCSD(rhf, frozen=2)
        eris = mycc.ao2mo()
        ercc, t1, t2 = mycc.kernel(eris=eris)
        self.assertAlmostEqual(ercc / np.prod(nk), -0.11467718013872311, 6)
        self.assertAlmostEqual(ercc / np.prod(nk), ekcc, 6)

        ercc_t = mycc.ccsd_t(eris=eris)
        self.assertAlmostEqual(ercc_t / np.prod(nk), -0.00066503872045200996,
                               6)
        self.assertAlmostEqual(ercc_t / np.prod(nk), ekcc_t, 6)
Esempio n. 30
0
    def test_lda_grid30(self):
        cell = pbcgto.Cell()
        cell.unit = 'B'
        L = 10
        cell.a = np.diag([L]*3)
        cell.gs = np.array([20]*3)
        cell.atom = [['He', (L/2.,L/2.,L/2.)], ]
# these are some exponents which are not hard to integrate
        cell.basis = { 'He': [[0, (0.8, 1.0)],
                              [0, (1.0, 1.0)],
                              [0, (1.2, 1.0)]] }
        cell.verbose = 5
        cell.output = '/dev/null'
        cell.pseudo = None
        cell.build()
        mf = pbcdft.RKS(cell)
        mf.xc = 'LDA,VWN_RPA'
        mf.kpt = np.ones(3)
        e1 = mf.scf()
        self.assertAlmostEqual(e1, -2.6409616064015591, 8)