def test_SCF_dipderiv(self): from pyxdh.Utilities.test_molecules import Mol_H2O2 from pyxdh.DerivOnce import DipoleSCF, GradSCF # HF H2O2 = Mol_H2O2() dip_deriv = DipoleSCF({"scf_eng": H2O2.hf_eng, "cphf_tol": 1e-10}) grad_deriv = GradSCF({"scf_eng": H2O2.hf_eng, "cphf_tol": 1e-10}) self.valid_assert(dip_deriv, grad_deriv, "Validation/gaussian/H2O2-HF-freq.fchk") # B3LYP H2O2 = Mol_H2O2() grids_cphf = H2O2.gen_grids(50, 194) dip_deriv = DipoleSCF({ "scf_eng": H2O2.gga_eng, "cphf_grids": grids_cphf, "cphf_tol": 1e-10 }) grad_deriv = GradSCF({ "scf_eng": H2O2.gga_eng, "cphf_grids": grids_cphf, "cphf_tol": 1e-10 }) self.valid_assert(dip_deriv, grad_deriv, "Validation/gaussian/H2O2-B3LYP-freq.fchk")
def test_B3LYP_hess(self): from pkg_resources import resource_filename from pyxdh.Utilities.test_molecules import Mol_H2O2 from pyxdh.Utilities import FormchkInterface from pyxdh.DerivOnce import GradSCF H2O2 = Mol_H2O2() grids_cphf = H2O2.gen_grids(50, 194) config = { "scf_eng": H2O2.gga_eng } grad_helper = GradSCF(config) config = { "deriv_A": grad_helper, "deriv_B": grad_helper, "cphf_grids": grids_cphf } helper = HessSCF(config) E_2 = helper.E_2 formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/H2O2-B3LYP-freq.fchk")) assert(np.allclose( E_2, formchk.hessian(), atol=1e-5, rtol=1e-4 ))
def _get_E_1(self): E_1 = GradSCF._get_E_1(self) j_1 = self.scf_grad.get_j(dm=self.D) k_1 = self.scf_grad.get_k(dm=self.D) v_aux = j_1.aux - 0.5 * self.cx * k_1.aux E_1 += v_aux return E_1
def test_r_rhf_dipderiv(self): scf_eng = scf.RHF(self.mol).run() gradh = GradSCF({"scf_eng": scf_eng}) diph = DipoleSCF({"scf_eng": scf_eng}) ddh = DipDerivSCF({"deriv_A": diph, "deriv_B": gradh}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-HF-freq.fchk")) # ASSERT: hessian - Gaussian assert np.allclose(ddh.E_2.T, formchk.dipolederiv(), atol=5e-6, rtol=2e-4)
def test_r_b3lyp_grad(self): scf_eng = dft.RKS(self.mol, xc="B3LYPg"); scf_eng.grids = self.grids; scf_eng.run() scf_grad = scf_eng.Gradients().run() gradh = GradSCF({"scf_eng": scf_eng}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/NH3-B3LYP-freq.fchk")) # ASSERT: energy - Gaussian assert np.allclose(gradh.eng, formchk.total_energy()) # ASSERT: energy - PySCF assert np.allclose(gradh.eng, scf_eng.e_tot) # ASSERT: grad - Gaussian assert np.allclose(gradh.E_1, formchk.grad(), atol=5e-6, rtol=1e-4) # ASSERT: grad - PySCF assert np.allclose(gradh.E_1, scf_grad.de, atol=1e-6, rtol=1e-4)
def test_r_rhf_grad(self): scf_eng = scf.RHF(self.mol).run() scf_grad = scf_eng.Gradients().run() gradh = GradSCF({"scf_eng": scf_eng}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/NH3-HF-freq.fchk")) # ASSERT: energy - Gaussian assert np.allclose(gradh.eng, formchk.total_energy()) # ASSERT: energy - PySCF assert np.allclose(gradh.eng, scf_eng.e_tot) # ASSERT: grad - Gaussian assert np.allclose(gradh.E_1, formchk.grad(), atol=1e-6, rtol=1e-4) # ASSERT: grad - PySCF assert np.allclose(gradh.E_1, scf_grad.de, atol=1e-6, rtol=1e-4)
def test_r_rhf_hess(self): scf_eng = scf.RHF(self.mol).run() scf_hess = scf_eng.Hessian().run() gradh = GradSCF({"scf_eng": scf_eng}) hessh = HessSCF({"deriv_A": gradh}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-HF-freq.fchk")) # ASSERT: hessian - Gaussian assert np.allclose(hessh.E_2, formchk.hessian(), atol=1e-6, rtol=1e-4) # ASSERT: hessian - PySCF assert np.allclose(hessh.E_2, scf_hess.de.swapaxes(-2, -3).reshape( (-1, self.mol.natm * 3)), atol=1e-6, rtol=1e-4)
def test_r_b3lyp_dipderiv(self): scf_eng = dft.RKS(self.mol, xc="B3LYPg") scf_eng.grids = self.grids scf_eng.run() gradh = GradSCF({"scf_eng": scf_eng, "cphf_grids": self.grids_cphf}) diph = DipoleSCF({"scf_eng": scf_eng, "cphf_grids": self.grids_cphf}) ddh = DipDerivSCF({"deriv_A": diph, "deriv_B": gradh}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-B3LYP-freq.fchk")) # ASSERT: hessian - Gaussian assert np.allclose(ddh.E_2.T, formchk.dipolederiv(), atol=5e-6, rtol=2e-4)
def test_r_b3lyp_hess(self): scf_eng = dft.RKS(self.mol, xc="B3LYPg") scf_eng.grids = self.grids scf_eng.run() scf_hess = scf_eng.Hessian().run() gradh = GradSCF({"scf_eng": scf_eng, "cphf_grids": self.grids_cphf}) hessh = HessSCF({"deriv_A": gradh}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-B3LYP-freq.fchk")) # ASSERT: hessian - Gaussian assert np.allclose(hessh.E_2, formchk.hessian(), atol=1e-5, rtol=2e-4) # ASSERT: hessian - PySCF assert np.allclose(hessh.E_2, scf_hess.de.swapaxes(-2, -3).reshape( (-1, self.mol.natm * 3)), atol=1e-6, rtol=1e-4)