def test_XYG3_dipderiv(self): from pkg_resources import resource_filename from pyxdh.Utilities.test_molecules import Mol_H2O2 from pyxdh.DerivOnce import DipoleXDH, GradXDH import pickle H2O2_sc = Mol_H2O2(xc="B3LYPg") H2O2_nc = Mol_H2O2(xc="0.8033*HF - 0.0140*LDA + 0.2107*B88, 0.6789*LYP") grids_cphf = H2O2_sc.gen_grids(50, 194) config = { "scf_eng": H2O2_sc.gga_eng, "nc_eng": H2O2_nc.gga_eng, "cc": 0.3211, "cphf_grids": grids_cphf } dip_helper = DipoleXDH(config) grad_helper = GradXDH(config) config = { "deriv_A": dip_helper, "deriv_B": grad_helper, } helper = DipDerivXDH(config) E_2 = helper.E_2 with open(resource_filename("pyxdh", "Validation/numerical_deriv/xdh_dipderiv_xyg3.dat"), "rb") as f: ref_polar = pickle.load(f)["dipderiv"] assert(np.allclose(E_2.T, ref_polar, atol=1e-6, rtol=1e-4))
def test_r_xygjos_grad(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) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/NH3-XYGJOS-freq.fchk")) # ASSERT: energy - Gaussian assert np.allclose(gradh.eng, formchk.total_energy()) # ASSERT: grad - Gaussian assert np.allclose(gradh.E_1, formchk.grad(), atol=5e-6, rtol=1e-4)
def test_r_xyg3_grad(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) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/NH3-XYG3-freq.fchk")) # ASSERT: energy - Gaussian assert np.allclose(gradh.eng, formchk.total_energy()) # ASSERT: grad - Gaussian assert np.allclose(gradh.E_1, formchk.grad(), atol=5e-6, rtol=1e-4)
def mol_to_grad_helper(mol): print("Processing...") H2O2_sc = Mol_H2O2(mol=mol, xc="B3LYPg") H2O2_nc = Mol_H2O2(mol=mol, xc="0.8033*HF - 0.0140*LDA + 0.2107*B88, 0.6789*LYP") config = { "scf_eng": H2O2_sc.gga_eng, "nc_eng": H2O2_nc.gga_eng, "cc": 0.3211 } helper = GradXDH(config) return helper
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)