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 valid_assert(config, resource_path): from pkg_resources import resource_filename from pyxdh.Utilities import FormchkInterface helper = DipoleSCF(config) assert (np.allclose(helper.E_1, helper.scf_eng.dip_moment(unit="A.U."), atol=1e-6, rtol=1e-4)) formchk = FormchkInterface(resource_filename("pyxdh", resource_path)) assert (np.allclose(helper.E_1, formchk.dipole(), atol=1e-6, rtol=1e-4))
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_r_rhf_dipole(self): scf_eng = scf.RHF(self.mol).run() diph = DipoleSCF({"scf_eng": scf_eng}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-HF-freq.fchk")) # ASSERT: dipole - Gaussian assert np.allclose(diph.E_1, formchk.dipole(), atol=1e-6, rtol=1e-4)
def test_MP2_polar(self): from pkg_resources import resource_filename from pyxdh.Utilities.test_molecules import Mol_H2O2 from pyxdh.Utilities import FormchkInterface from pyxdh.DerivOnce import DipoleMP2 H2O2 = Mol_H2O2() config = {"scf_eng": H2O2.hf_eng} dip_helper = DipoleMP2(config) config = { "deriv_A": dip_helper, "deriv_B": dip_helper, } helper = PolarMP2(config) E_2 = helper.E_2 formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/H2O2-MP2-freq.fchk")) assert (np.allclose(-E_2, formchk.polarizability(), 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_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_B2PLYP_polar(self): from pkg_resources import resource_filename from pyxdh.Utilities.test_molecules import Mol_H2O2 from pyxdh.Utilities import FormchkInterface from pyxdh.DerivOnce import DipoleMP2 H2O2 = Mol_H2O2(xc="0.53*HF + 0.47*B88, 0.73*LYP") grids_cphf = H2O2.gen_grids(50, 194) config = { "scf_eng": H2O2.gga_eng, "cc": 0.27, "cphf_grids": grids_cphf } dip_helper = DipoleMP2(config) config = {"deriv_A": dip_helper, "deriv_B": dip_helper} helper = PolarMP2(config) E_2 = helper.E_2 formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/H2O2-B2PLYP-freq.fchk")) assert (np.allclose(-E_2, formchk.polarizability(), atol=1e-6, rtol=1e-4))
def test_r_b2plyp_grad(self): scf_eng = dft.RKS(self.mol, xc="0.53*HF + 0.47*B88, 0.73*LYP"); scf_eng.grids = self.grids; scf_eng.run() gradh = GradMP2({"scf_eng": scf_eng, "cc": 0.27, "cphf_grids": self.grids_cphf}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/NH3-B2PLYP-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=1e-6, 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 valid_assert(dip_helper, grad_helper, resource_path): from pkg_resources import resource_filename from pyxdh.Utilities import FormchkInterface dipderiv_config = {"deriv_A": dip_helper, "deriv_B": grad_helper} helper = DipDerivSCF(dipderiv_config) E_2 = helper.E_2 formchk = FormchkInterface(resource_filename("pyxdh", resource_path)) assert (np.allclose(E_2.T, formchk.dipolederiv(), atol=1e-6, rtol=1e-4))
def test_UMP2_grad(self): from pyxdh.Utilities.test_molecules import Mol_CH3 from pkg_resources import resource_filename from pyxdh.Utilities import FormchkInterface CH3 = Mol_CH3() helper = GradUMP2({"scf_eng": CH3.hf_eng.run(), "cphf_tol": 1e-10}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/CH3-MP2-freq.fchk")) assert(np.allclose(helper.E_1, formchk.grad(), atol=1e-5, rtol=1e-4))
def test_r_b3lyp_dipole(self): scf_eng = dft.RKS(self.mol, xc="B3LYPg") scf_eng.grids = self.grids scf_eng.run() diph = DipoleSCF({"scf_eng": scf_eng}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-B3LYP-freq.fchk")) # ASSERT: dipole - Gaussian assert np.allclose(diph.E_1, formchk.dipole(), atol=1e-6, rtol=1e-4)
def test_u_uhf_dipole(self): scf_eng = scf.UHF(self.mol) scf_eng.conv_tol_grad = 1e-10 scf_eng.max_cycle = 128 scf_eng.run() diph = DipoleUSCF({"scf_eng": scf_eng}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/CH3-HF-freq.fchk")) # ASSERT: dipole - Gaussian assert np.allclose(diph.E_1, formchk.dipole(), 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_UB3LYP_grad(self): from pyxdh.Utilities.test_molecules import Mol_CH3 from pkg_resources import resource_filename from pyxdh.Utilities import FormchkInterface CH3 = Mol_CH3() helper = GradUSCF({"scf_eng": CH3.gga_eng}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/CH3-B3LYP-freq.fchk")) assert(np.allclose(helper.E_1, formchk.grad(), atol=1e-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 test_r_rhf_polar(self): scf_eng = scf.RHF(self.mol).run() diph = DipoleSCF({"scf_eng": scf_eng}) polh = PolarSCF({"deriv_A": diph}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-HF-freq.fchk")) # ASSERT: polar - Gaussian assert np.allclose(-polh.E_2, formchk.polarizability(), atol=1e-6, rtol=1e-4)
def test_UB2PLYP_grad(self): from pyxdh.Utilities.test_molecules import Mol_CH3 from pkg_resources import resource_filename from pyxdh.Utilities import FormchkInterface CH3 = Mol_CH3(xc="0.53*HF + 0.47*B88, 0.73*LYP") grids_cphf = CH3.gen_grids(atom_grid=(50, 194)) helper = GradUMP2({"scf_eng": CH3.gga_eng.run(), "cphf_tol": 1e-10, "cc": 0.27, "cphf_grids": grids_cphf}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/CH3-B2PLYP-freq.fchk")) assert(np.allclose(helper.E_1, formchk.grad(), atol=1e-5, rtol=1e-4))
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 valid_assert(dip_config, resource_path): from pkg_resources import resource_filename from pyxdh.Utilities import FormchkInterface from pyxdh.DerivOnce import DipoleSCF dip_helper = DipoleSCF(dip_config) polar_config = {"deriv_A": dip_helper, "deriv_B": dip_helper} helper = PolarSCF(polar_config) E_2 = helper.E_2 formchk = FormchkInterface(resource_filename("pyxdh", resource_path)) assert (np.allclose(-E_2, formchk.polarizability(), atol=1e-6, rtol=1e-4))
def test_u_uhf_polar(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() diph = DipoleUSCF({"scf_eng": scf_eng}) polh = PolarUSCF({"deriv_A": diph}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/CH3-HF-freq.fchk")) assert np.allclose(-polh.E_2, formchk.polarizability(), atol=1e-6, rtol=1e-4)
def test_r_b3lyp_polar(self): scf_eng = dft.RKS(self.mol, xc="B3LYPg") scf_eng.grids = self.grids scf_eng.run() diph = DipoleSCF({"scf_eng": scf_eng, "cphf_grids": self.grids_cphf}) polh = PolarSCF({"deriv_A": diph}) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-B3LYP-freq.fchk")) # ASSERT: polar - Gaussian assert np.allclose(-polh.E_2, formchk.polarizability(), atol=1e-6, rtol=1e-4)
def test_r_b2plyp_dipole(self): scf_eng = dft.RKS(self.mol, xc="0.53*HF + 0.47*B88, 0.73*LYP") scf_eng.grids = self.grids scf_eng.run() diph = DipoleMP2({ "scf_eng": scf_eng, "cc": 0.27, "cphf_grids": self.grids_cphf }) formchk = FormchkInterface( resource_filename("pyxdh", "Validation/gaussian/NH3-B2PLYP-freq.fchk")) # ASSERT: dipole - Gaussian assert np.allclose(diph.E_1, formchk.dipole(), atol=1e-6, rtol=1e-4)
def test_UXYGJOS_grad(self): from pyxdh.Utilities.test_molecules import Mol_CH3 from pkg_resources import resource_filename from pyxdh.Utilities import FormchkInterface CH3_sc = Mol_CH3(xc="B3LYPg") CH3_nc = Mol_CH3(xc="0.7731*HF + 0.2269*LDA, 0.2309*VWN3 + 0.2754*LYP") grids_cphf = CH3_sc.gen_grids(atom_grid=(50, 194)) helper = GradUXDH({"scf_eng": CH3_sc.gga_eng, "nc_eng": CH3_nc.gga_eng, "cc": 0.4364, "ss": 0., "cphf_tol": 1e-10, "cphf_grids": grids_cphf}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/CH3-XYGJOS-force.fchk")) assert(np.allclose(helper.E_1, formchk.grad(), atol=1e-5, rtol=1e-4))
def test_UXYG3_grad(self): from pyxdh.Utilities.test_molecules import Mol_CH3 from pkg_resources import resource_filename from pyxdh.Utilities import FormchkInterface CH3_sc = Mol_CH3(xc="B3LYPg") CH3_nc = Mol_CH3(xc="0.8033*HF - 0.0140*LDA + 0.2107*B88, 0.6789*LYP") grids_cphf = CH3_sc.gen_grids(atom_grid=(50, 194)) helper = GradUXDH({ "scf_eng": CH3_sc.gga_eng, "nc_eng": CH3_nc.gga_eng, "cc": 0.3211, "cphf_tol": 1e-10, "cphf_grids": grids_cphf}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/CH3-XYG3-force.fchk")) assert(np.allclose(helper.E_1, formchk.grad(), atol=1e-5, 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)