def test_u_uhf_hess(self): scf_eng = scf.UHF(self.mol); scf_eng.conv_tol = 1e-12; scf_eng.conv_tol_grad = 1e-10 scf_eng.max_cycle = 256; scf_eng.run() gradh = GradUSCF({"scf_eng": scf_eng}) hessh = HessUSCF({"deriv_A": gradh}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/CH3-HF-freq.fchk")) assert np.allclose(hessh.E_2, formchk.hessian(), atol=1e-6, rtol=1e-4)
def test_B2PLYP_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 GradMP2 import pickle H2O2 = Mol_H2O2(xc="0.53*HF + 0.47*B88, 0.73*LYP") config = {"scf_eng": H2O2.gga_eng, "cc": 0.27} grad_helper = GradMP2(config) config = { "deriv_A": grad_helper, "deriv_B": grad_helper, } helper = HessMP2(config) E_2 = helper.E_2 formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/H2O2-B2PLYP-freq.fchk")) assert (np.allclose(E_2, formchk.hessian(), atol=1e-5, rtol=1e-4)) with open( resource_filename( "pyxdh", "Validation/numerical_deriv/mp2_hessian_b2plyp.dat"), "rb") as f: ref_hess = pickle.load(f)["hess"] assert (np.allclose(E_2, ref_hess, atol=1e-6, rtol=1e-4))
def test_MP2_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 GradMP2 H2O2 = Mol_H2O2() config = { "scf_eng": H2O2.hf_eng, "rotation": True, } grad_helper = GradMP2(config) config = { "deriv_A": grad_helper, "deriv_B": grad_helper, } helper = HessMP2(config) E_2 = helper.E_2 formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/H2O2-MP2-freq.fchk")) assert (np.allclose(E_2, formchk.hessian(), atol=1e-6, rtol=1e-4))
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 test_r_mp2_hess(self): scf_eng = scf.RHF(self.mol).run() gradh = GradMP2({"scf_eng": scf_eng}) hessh = HessMP2({"deriv_A": gradh}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-MP2-freq.fchk")) # ASSERT: hessian - Gaussian assert np.allclose(hessh.E_2, formchk.hessian(), 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_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)
def test_r_xyg3_hess(self): scf_eng = dft.RKS(self.mol, xc="B3LYPg") scf_eng.grids = self.grids scf_eng.run() nc_eng = dft.RKS(self.mol, xc="0.8033*HF - 0.0140*LDA + 0.2107*B88, 0.6789*LYP") nc_eng.grids = self.grids config = { "scf_eng": scf_eng, "nc_eng": nc_eng, "cc": 0.3211, "cphf_grids": self.grids_cphf } gradh = GradXDH(config) hessh = HessXDH({"deriv_A": gradh}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-XYG3-freq.fchk")) # ASSERT: hessian - Gaussian np.allclose(hessh.E_2, formchk.hessian(), atol=2e-5, rtol=2e-4)
def test_r_xygjos_hess(self): scf_eng = dft.RKS(self.mol, xc="B3LYPg") scf_eng.grids = self.grids scf_eng.run() nc_eng = dft.RKS(self.mol, xc="0.7731*HF + 0.2269*LDA, 0.2309*VWN3 + 0.2754*LYP") nc_eng.grids = self.grids config = { "scf_eng": scf_eng, "nc_eng": nc_eng, "cc": 0.4364, "ss": 0., "cphf_grids": self.grids_cphf } gradh = GradXDH(config) hessh = HessXDH({"deriv_A": gradh}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-XYGJOS-freq.fchk")) # ASSERT: hessian - Gaussian np.allclose(hessh.E_2, formchk.hessian(), atol=2e-5, rtol=2e-4)
def test_UHF_hess(self): from pkg_resources import resource_filename from pyxdh.Utilities.test_molecules import Mol_CH3 from pyxdh.Utilities import FormchkInterface from pyxdh.DerivOnce import GradUSCF CH3 = Mol_CH3() config = { "scf_eng": CH3.hf_eng, "cphf_tol": 1e-10, } grad_helper = GradUSCF(config) config = { "deriv_A": grad_helper, "deriv_B": grad_helper, "cphf_tol": 1e-10, } helper = HessUSCF(config) E_2 = helper.E_2 formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/CH3-HF-freq.fchk")) assert (np.allclose(E_2, formchk.hessian(), atol=1e-5, rtol=1e-4))