def test_rks_b3lypg(self): mf = dft.RKS(h2o) mf.grids.prune = None mf.run(conv_tol=1e-15, xc='b3lypg') g = grad.RKS(mf) g1 = g.grad() self.assertAlmostEqual(finger(g1), 0.066541921001296467, 9)
def test_rks_bp86(self): mf = dft.RKS(h2o) mf.grids.prune = None mf.run(conv_tol=1e-15, xc='b88,p86') g = grad.RKS(mf) g1 = g.grad() self.assertAlmostEqual(finger(g1), 0.10362532283229957, 9)
def test_rks_lda(self): mf = dft.RKS(h2o) mf.grids.prune = None mf.run(conv_tol=1e-15, xc='lda,vwn') g = grad.RKS(mf) g1 = g.grad() self.assertAlmostEqual(finger(g1), 0.098438461959390822, 9)
def gga_grad(self): if self._gga_grad is not NotImplemented: return self._gga_grad if self.gga_eng.mo_coeff is None: self.gga_eng.kernel() gga_grad = grad.RKS(self.gga_eng) self._gga_grad = gga_grad return self._gga_grad
def test_rks_scanner(self): mol1 = mol.copy() mol1.set_geom_(''' H 0. 0. 0.9 F 0. 0.1 0.''') mf_scanner = grad.RKS(scf.RKS(mol).set(conv_tol=1e-14)).as_scanner() e, de = mf_scanner(mol) self.assertAlmostEqual(finger(de), 0.458572523892797, 7) e, de = mf_scanner(mol1) self.assertAlmostEqual(finger(de), 0.12763259021187467, 7)
def EF(molstr,basis = "6-311g**", xc = "PBE0"): m1 = gto.Mole() m1.atom = molstr m1.basis = basis m1.build() mf = dft.RKS(m1) mf.xc = xc mf.kernel() energy = mf.e_tot force = grad.RKS(mf).kernel()/0.52917721092 * -JOULEPERHARTREE return energy, force
def calc_gradients_elec(mole, one_dm: np.ndarray, mf, coeffs, occs, energies): """Calculate electronic part of nuclear gradients. Parameters ---------- mole A PySCF mole object. one_dm One-particle density matrix understood by IOdata projected and formatted in a PySCF-compatible way (single 2d array or list for a,b 2d arrays) mf A PySCF mean field object. Its only use is method specification. coeffs AO coefficient matrix understood by IOdata projected and formatted in a PySCF-compatible way (single 2d array or list for a,b 2d arrays) occs Occupation numbers formatted in a PySCF-compatible way (single 1d array or list for a,b 1d arrays) energies MO energies formatted in a PySCF-compatible way (single 1d array or list for a,b 1d arrays) Returns ------- grad_elec Nuclear gradients in a.u. per cartesian coordinate per atom. (Due to electrons) """ mo_energy = energies mo_coeff = coeffs mo_occ = occs if len(one_dm) == 2: try: grad_elec = grad.UKS(mf).grad_elec(mo_energy=mo_energy, mo_coeff=mo_coeff, mo_occ=mo_occ) except: grad_elec = grad.UHF(mf).grad_elec(mo_energy=mo_energy, mo_coeff=mo_coeff, mo_occ=mo_occ) else: try: grad_elec = grad.RKS(mf).grad_elec(mo_energy=mo_energy, mo_coeff=mo_coeff, mo_occ=mo_occ) except: grad_elec = grad.RHF(mf).grad_elec(mo_energy=mo_energy, mo_coeff=mo_coeff, mo_occ=mo_occ) return grad_elec
verb = 0 # integer verbosity flag # Do a mean-field KS-DFT calculation at dist mol = gto.Mole( atom=coord, basis=basisname, charge=0, spin=0) # build a molecule, neutral species, spin is N\alpha-N\beta here mol.build() mf = scf.RKS(mol) # run DFT calculation as reference mf.verbose = verb # reduce output mf.xc = 'lda,vwn' # we select an approximate xc functional, many options available e.g. 'pbe,pbe' or 'b3lyp' edft = mf.kernel() # get DFT energy nelec = mol.nelec # number of electrons print('The number of electrons is now {0}'.format(nelec)) print(' At a distance R = {0} angstrom:'.format(dist)) print(' DFT energy: {0} a.u.\n'.format(edft)) # total energies gradients = grad.RKS(mf).kernel( ) # We calculate analytical nuclear gradients, we choose the level of theory of the gradients print(mol.atom_coords()) print(gradients) dist = 1.5 coord = 'H 0 0 0; H 0 0 {0}'.format(str(dist)) # Do a mean-field KS-DFT calculation at a new dist mol = gto.Mole( atom=coord, basis=basisname, charge=0, spin=0) # build a molecule, neutral species, spin is N\alpha-N\beta here mol.build() mf = scf.RKS(mol) # run DFT calculation as reference mf.verbose = verb # reduce output mf.xc = 'lda,vwn' # we select an approximate xc functional, many options available e.g. 'pbe,pbe' or 'b3lyp' edft = mf.kernel() # get DFT energy nelec = mol.nelec # number of electrons
#!/usr/bin/env python ''' Set the default XC functional library to XCFun (https://github.com/dftlibs/xcfun) ''' from pyscf import gto, dft, grad mol = gto.M( atom = ''' F 0. 0. 0. H 0. 0. 1.587 ''', basis = 'ccpvdz') # # Modifying _NumInt.libxc changes the default XC library globally. All DFT # calculations will call the xcfun to evaluate XC values. # dft.numint._NumInt.libxc = dft.xcfun mf = dft.RKS(mol) mf.xc = 'b88,lyp' mf.kernel() grad.RKS(mf).run()