def test_rsh_df(self): mf = pbcdft.KUKS(cell) mf.xc = 'camb3lyp' mf.kernel() self.assertAlmostEqual(mf.e_tot, -2.3032261128220544, 7) mf = pbcdft.KUKS(cell).density_fit() mf.xc = 'camb3lyp' mf.omega = .15 mf.kernel() self.assertAlmostEqual(mf.e_tot, -2.3987656490734555, 7)
def test_klda8_cubic_kpt_222_high_cost(self): cell = pbcgto.Cell() cell.unit = 'A' cell.a = '''3.5668 0. 0. 0. 3.5668 0. 0. 0. 3.5668''' cell.mesh = np.array([17] * 3) cell.atom = ''' C, 0., 0., 0. C, 0.8917, 0.8917, 0.8917 C, 1.7834, 1.7834, 0. C, 2.6751, 2.6751, 0.8917 C, 1.7834, 0. , 1.7834 C, 2.6751, 0.8917, 2.6751 C, 0. , 1.7834, 1.7834 C, 0.8917, 2.6751, 2.6751''' cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.verbose = 5 cell.output = '/dev/null' cell.build() kpts = cell.make_kpts((2, 2, 2), with_gamma_point=False) mf = pbcdft.KUKS(cell, kpts) mf.conv_tol = 1e-9 mf.xc = 'lda,vwn' e1 = mf.scf() self.assertAlmostEqual(e1, -45.42583489512954, 8)
def test_nr_kuks_lda(self): mf = dft.KUKS(cell, cell.make_kpts([2, 1, 1])) mf.xc = 'lda,' mf = scf.newton(mf) mf.conv_tol_grad = 1e-4 mf.kernel() self.assertAlmostEqual(mf.e_tot, -10.307756038726733, 8)
def test_nr_kuks_gga(self): mf = dft.KUKS(cell, cell.make_kpts([2, 1, 1])) mf.xc = 'b88,' mf = scf.newton(mf) mf.conv_tol_grad = 1e-4 mf.kernel() self.assertAlmostEqual(mf.e_tot, -10.446717855794008, 8)
def test_multigrid_kuks(self): mf = dft.KUKS(cell_he) mf.xc = 'lda,' ref = mf.get_veff(cell_he, numpy.array((dm_he, dm_he)), kpts=kpts) out = multigrid.multigrid(mf).get_veff(cell_he, (dm_he, dm_he), kpts=kpts) 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)
def test_lda_grad(self): mf = dft.KUKS(cell, kpts) mf.xc = 'lda,vwn' mf.conv_tol = 1e-10 mf.conv_tol_grad = 1e-6 g_scan = mf.nuc_grad_method().as_scanner() g = g_scan(cell)[1] self.assertAlmostEqual(lib.fp(g), -0.22166962318360375, 6) mfs = g_scan.base.as_scanner() e1 = mfs([['C', [0.0, 0.0, 0.0]], ['C', [1.685068664391,1.685068664391,1.685068664391+disp/2.0]]]) e2 = mfs([['C', [0.0, 0.0, 0.0]], ['C', [1.685068664391,1.685068664391,1.685068664391-disp/2.0]]]) self.assertAlmostEqual(g[1,2], (e1-e2)/disp, 6)
def test_gga_grad(self): mf = dft.KUKS(cell, kpts) mf.xc = 'pbe,pbe' mf.conv_tol = 1e-10 mf.conv_tol_grad = 1e-6 g_scan = mf.nuc_grad_method().as_scanner() g = g_scan(cell)[1] self.assertAlmostEqual(lib.fp(g), -0.21844074846755882, 6) mfs = g_scan.base.as_scanner() e1 = mfs([['C', [0.0, 0.0, 0.0]], ['C', [1.685068664391,1.685068664391,1.685068664391+disp/2.0]]]) e2 = mfs([['C', [0.0, 0.0, 0.0]], ['C', [1.685068664391,1.685068664391,1.685068664391-disp/2.0]]]) self.assertAlmostEqual(g[1,2], (e1-e2)/disp, 6)
def test_uks_gen_g_hop(self): mf = dft.KUKS(cell, cell.make_kpts([2,1,1])) mf.xc = 'b3lyp' nao = cell.nao_nr() numpy.random.seed(1) mo = numpy.random.random((2,2,nao,nao)) + 0j mo_occ = numpy.zeros((2,2,nao)) mo_occ[:,:,:5] = 1 nocc, nvir = 5, nao-5 dm1 = numpy.random.random(4*nvir*nocc) + .1j mf = scf.newton(mf) mf.grids.build() g, hop, hdiag = mf.gen_g_hop(mo, mo_occ, [mf.get_hcore()]*2) self.assertAlmostEqual(numpy.linalg.norm(hop(dm1)), 28.01954683540594, 7)
def get_solids_energy(xc="lda", with_df=False): solnames = ["H"] for solname in solnames: t0 = time.time() sol = get_solid(solname) mf = dft.KUKS(sol, kpts=np.zeros(3)) if with_df: auxbasis = "def2-svp-jkfit" mf = mf.density_fit(auxbasis=auxbasis) mf.xc = xc mf.grids.level = 4 energy = mf.kernel() t1 = time.time() print("Solid %s: %.8e (%.3e)" % (solname, energy, t1 - t0))
def test_hybrid_grad(self): mf = dft.KUKS(cell, kpts) mf.xc = 'b3lyp' mf.exxdiv = None mf.conv_tol = 1e-10 mf.conv_tol_grad = 1e-6 g_scan = mf.nuc_grad_method().as_scanner() g = g_scan(cell)[1] self.assertAlmostEqual(lib.fp(g), -0.19544969829285652, 6) mfs = g_scan.base.as_scanner() e1 = mfs([['C', [0.0, 0.0, 0.0]], ['C', [1.685068664391,1.685068664391,1.685068664391+disp/2.0]]]) e2 = mfs([['C', [0.0, 0.0, 0.0]], ['C', [1.685068664391,1.685068664391,1.685068664391-disp/2.0]]]) self.assertAlmostEqual(g[1,2], (e1-e2)/disp, 6)
def copy_mf(mf, cell): if mf.__class__.__name__ == 'KRHF': mf1 = scf.KRHF(cell) elif mf.__class__.__name__ == 'KUHF': mf1 = scf.KUHF(cell) elif mf.__class__.__name__ == 'KRKS': mf1 = dft.KRKS(cell) mf1.xc = mf.xc elif mf.__class__.__name__ == 'KUKS': mf1 = dft.KUKS(cell) mf1.xc = mf.xc mf1.kpts = mf.kpts mf1.exxdiv = getattr(mf, 'exxdiv', None) mf1.conv_tol = mf.conv_tol mf1.conv_tol_grad = mf.conv_tol_grad return mf1
def test_klda8_cubic_kpt_222(self): ase_atom = Diamond(symbol='C', latticeconstant=LATTICE_CONST) cell = pbcgto.Cell() cell.unit = 'A' cell.h = ase_atom.cell cell.gs = np.array([8]*3) cell.atom = pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.verbose = 5 cell.output = '/dev/null' cell.build() kpts = cell.make_kpts((2,2,2)) mf = pbcdft.KUKS(cell, kpts) mf.xc = 'lda,vwn' e1 = mf.scf() self.assertAlmostEqual(e1, -45.42583489512954, 8) self.assertAlmostEqual(mf._ecoul, 3.2519161200384685, 8) self.assertAlmostEqual(mf._exc, -13.937886385300949, 8)
cell.unit = 'B' cell.atom = ''' C 0. 0. 0. C 1.68506879 1.68506879 1.68506879 ''' cell.a = ''' 0. 3.37013758 3.37013758 3.37013758 0. 3.37013758 3.37013758 3.37013758 0. ''' cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.mesh = [37] * 3 cell.build() mf = dft.KUKS(cell, cell.make_kpts([2, 1, 1])).set(exxdiv=None, xc='b88,p86') #mf.with_df = df.MDF(cell, cell.make_kpts([2,1,1])) #mf.with_df.auxbasis = 'weigend' #mf.with_df._cderi = 'eri3d-mdf.h5' #mf.with_df.build(with_j3c=False) mf.run() td = TDDFT(mf) td.verbose = 5 td.nstates = 5 print(td.kernel()[0] * 27.2114) mf.xc = 'lda,vwn' mf.run() td = TDA(mf) td.verbose = 5
cell.atom = ''' C 3.17500000 3.17500000 3.17500000 H 2.54626556 2.54626556 2.54626556 H 3.80373444 3.80373444 2.54626556 H 2.54626556 3.80373444 3.80373444 ''' cell.basis = 'sto-3g' cell.a = np.eye(3) * 6.35 cell.gs = [15] * 3 cell.spin = 1 cell.verbose = 5 cell.build() nk = [1, 1, 1] abs_kpts = cell.make_kpts(nk) kmf = dft.KUKS(cell, abs_kpts).mix_density_fit() kmf.xc = 'pbe' ekpt = kmf.run() num_wann = 4 keywords = \ ''' exclude_bands : 1,6-8 begin projections C:sp3 end projections ''' w90 = pywannier90.W90(kmf, cell, nk, num_wann, other_keywords=keywords) w90.kernel() w90.plot_wf(grid=[25, 25, 25], supercell=nk)
'''Non-relativistic restricted Hartree-Fock gradients''' def __init__(self, mf): uhf_grad.Gradients.__init__(self, mf) self.grids = None self.grid_response = False self._keys = self._keys.union(['grid_response', 'grids']) get_veff = get_veff if __name__ == '__main__': from pyscf.pbc import dft, gto, scf cell = gto.Cell() cell.atom = [['He', [0.0, 0.0, 0.0]], ['He', [1, 1.1, 1.2]]] cell.basis = 'gth-dzv' cell.a = np.eye(3) * 3 cell.mesh = [19, 19, 19] cell.unit = 'bohr' cell.pseudo = 'gth-pade' cell.verbose = 5 cell.build() nmp = [1, 1, 5] kpts = cell.make_kpts(nmp) kmf = dft.KUKS(cell, kpts) kmf.exxdiv = None kmf.xc = 'b3lyp' kmf.kernel() mygrad = Gradients(kmf) mygrad.kernel()
cell.atom = ''' C 0. 0. 0. C 1.68506879 1.68506879 1.68506879 ''' cell.a = ''' 0. 3.37013758 3.37013758 3.37013758 0. 3.37013758 3.37013758 3.37013758 0. ''' cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.mesh = [25] * 3 cell.build() kpts = cell.make_kpts([2, 1, 1]) mf = scf.KRHF(cell, kpts[1:]).set(exxdiv=None).run() #mf.with_df = df.DF(cell, kpts) #mf.with_df.auxbasis = 'weigend' #mf.with_df._cderi = 'eri3d-df.h5' #mf.with_df.build(with_j3c=False) rhf_stability(mf, True, True, verbose=5) mf = scf.KUHF(cell, kpts).set(exxdiv=None).run() uhf_stability(mf, True, True, verbose=5) mf = dft.KRKS(cell, kpts).set(xc='bp86').run() rhf_stability(mf, True, True, verbose=5) mf = dft.KUKS(cell, kpts).set(xc='bp86').run() uhf_stability(mf, True, True, verbose=5)
def test_rsh_df(self): mf = pbcdft.KUKS(cell).density_fit() mf.xc = 'camb3lyp' mf.omega = .15 mf.kernel() self.assertAlmostEqual(mf.e_tot, -2.4766238116030683, 7)
def test_rsh_fft(self): mf = pbcdft.KUKS(cell) mf.xc = 'camb3lyp' mf.kernel() self.assertAlmostEqual(mf.e_tot, -2.4745140703871877, 7)
def KUKS(cell, *args): from pyscf.pbc import dft return dft.KUKS(cell, *args)
def test_rsh_df(self): mf = pbcdft.KUKS(cell).density_fit() mf.xc = 'camb3lyp' mf.omega = .15 mf.kernel() self.assertAlmostEqual(mf.e_tot, -2.399571378419408, 7)