def test_finite_diff_uhf_grad(self): mf = scf.UHF(mol) mf.conv_tol = 1e-14 e0 = mf.kernel() g = grad.UHF(mf).kernel() mf_scanner = mf.as_scanner() e1 = mf_scanner('''O 0. 0. 0. 1 0. -0.758 0.587 1 0. 0.757 0.587''') e2 = mf_scanner('''O 0. 0. 0. 1 0. -0.756 0.587 1 0. 0.757 0.587''') self.assertAlmostEqual(g[1, 1], (e2 - e1) / 2e-3 * lib.param.BOHR, 5) e1 = mf_scanner('''O 0. 0. 0. 1 0. -0.7571 0.587 1 0. 0.757 0.587''') e2 = mf_scanner('''O 0. 0. 0. 1 0. -0.7569 0.587 1 0. 0.757 0.587''') self.assertAlmostEqual(g[1, 1], (e2 - e1) / 2e-4 * lib.param.BOHR, 7) mf = scf.UHF(mol1) mf.conv_tol = 1e-14 e0 = mf.kernel() g = grad.UHF(mf).kernel() mf_scanner = mf.as_scanner() e1 = mf_scanner(''' C 0.63540095 0.65803739 -0.00861418 H 0.99205538 -0.35077261 -0.00861418 H 0.99207379 1.16143558 -0.88226569 H -0.43459905 0.65805058 -0.00861418''') e2 = mf_scanner(''' C 0.63540095 0.65803739 -0.00861418 H 0.99205538 -0.35077261 -0.00861418 H 0.99207379 1.16343558 -0.88226569 H -0.43459905 0.65805058 -0.00861418''') self.assertAlmostEqual(g[2, 1], (e2 - e1) / 2e-3 * lib.param.BOHR, 5) e1 = mf_scanner(''' C 0.63540095 0.65803739 -0.00861418 H 0.99205538 -0.35077261 -0.00861418 H 0.99207379 1.16233558 -0.88226569 H -0.43459905 0.65805058 -0.00861418''') e2 = mf_scanner(''' C 0.63540095 0.65803739 -0.00861418 H 0.99205538 -0.35077261 -0.00861418 H 0.99207379 1.16253558 -0.88226569 H -0.43459905 0.65805058 -0.00861418''') self.assertAlmostEqual(g[2, 1], (e2 - e1) / 2e-4 * lib.param.BOHR, 7)
def test_nr_uhf(self): mf = scf.UHF(h2o_n) mf.conv_tol = 1e-14 mf.kernel() g = grad.UHF(mf) self.assertAlmostEqual(lib.finger(g.grad_elec()), 4.2250348208172541, 6)
def test_frozen(self): pt = mp.MP2(mf) pt.frozen = [0, 1, 10, 11, 12] pt.max_memory = 1 pt.kernel() g1 = ump2_grad.kernel(pt, pt.t2, mf_grad=grad.UHF(mf)) self.assertAlmostEqual(lib.finger(g1), -0.22437278030057645, 6)
def test_frozen(self): myci = ucisd.UCISD(mf) myci.frozen = [0, 1, 10, 11, 12] myci.max_memory = 1 myci.kernel() g1 = ucisd_grad.kernel(myci, myci.ci, mf_grad=grad.UHF(mf)) self.assertAlmostEqual(lib.finger(g1), -0.23578589551312196, 6)
def test_cisd_grad(self): myci = ucisd.UCISD(mf) myci.max_memory = 1 myci.conv_tol = 1e-10 myci.kernel() g1 = ucisd_grad.kernel(myci, myci.ci, mf_grad=grad.UHF(mf)) self.assertAlmostEqual(lib.finger(g1), -0.22651925227633429, 6)
def hf_grad(self): if self._hf_grad is not NotImplemented: return self._hf_grad if self.hf_eng.mo_coeff is None: self.hf_eng.kernel() hf_grad = grad.UHF(self.hf_eng) self._hf_grad = hf_grad return self._hf_grad
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
def test_finite_diff_uhf_grad(self): mf = scf.UHF(mol) mf.conv_tol = 1e-14 e0 = mf.kernel() g = grad.UHF(mf).kernel() mf_scanner = mf.as_scanner() e1 = mf_scanner(make_mol(0, (0, 0, 1e-4))) self.assertAlmostEqual(g[0, 2], (e1 - e0) / 1e-4 * lib.param.BOHR, 4) e1 = mf_scanner(make_mol(0, (0, 1e-5, 0))) self.assertAlmostEqual(g[0, 1], (e1 - e0) / 1e-5 * lib.param.BOHR, 4) e1 = mf_scanner(make_mol(1, (0., -0.7571, 0.587))) self.assertAlmostEqual(g[1, 1], (e0 - e1) / 1e-4 * lib.param.BOHR, 4) e1 = mf_scanner(make_mol(1, (0., -0.757, 0.5871))) self.assertAlmostEqual(g[1, 2], (e1 - e0) / 1e-4 * lib.param.BOHR, 4)
def initialization_pyscf(self): if (self.scf_eng.mo_coeff is NotImplemented or self.scf_eng.mo_coeff is None) and self.init_scf: self.scf_eng.kernel() if not self.scf_eng.converged: warnings.warn("SCF not converged!") if isinstance(self.scf_eng, dft.rks.RKS) or isinstance( self.scf_eng, dft.uks.UKS): self.xc = self.scf_eng.xc self.grids = self.scf_eng.grids self.xc_type = dft.libxc.xc_type(self.xc) self.cx = dft.numint.NumInt().hybrid_coeff(self.xc) self.scf_grad = grad.uks.Gradients(self.scf_eng) self.scf_hess = hessian.uks.Hessian(self.scf_eng) else: self.scf_grad = grad.UHF(self.scf_eng) self.scf_hess = hessian.UHF(self.scf_eng) return