Example #1
0
    def test_XYG3_grad(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface

        H2O2_sc = Mol_H2O2(xc="B3LYPg")
        H2O2_nc = Mol_H2O2(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
        }
        gmh = GradXDH(config)

        formchk = FormchkInterface(resource_filename("pyxdhalpha", "Validation/gaussian/H2O2-XYG3-force.fchk"))

        assert(np.allclose(
            gmh.eng,
            formchk.total_energy()
        ))
        assert(np.allclose(
            gmh.E_1, formchk.grad(),
            atol=1e-5, rtol=1e-4
        ))
Example #2
0
    def test_MP2_grad(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface

        from pyscf import mp, grad

        H2O2 = Mol_H2O2()
        config = {
            "scf_eng": H2O2.hf_eng
        }
        gmh = GradMP2(config)

        mp2_eng = mp.MP2(gmh.scf_eng)
        mp2_eng.kernel()
        mp2_grad = grad.mp2.Gradients(mp2_eng)
        mp2_grad.kernel()

        assert(np.allclose(
            gmh.E_1, mp2_grad.de,
            atol=1e-6, rtol=1e-4
        ))

        formchk = FormchkInterface(resource_filename("pyxdhalpha", "Validation/gaussian/H2O2-MP2-freq.fchk"))

        assert(np.allclose(
            gmh.E_1, formchk.grad(),
            atol=1e-6, rtol=1e-4
        ))
Example #3
0
    def test_B2PLYP_polar(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface
        from pyxdhalpha.DerivOnce import DipoleMP2

        H2O2 = Mol_H2O2(xc="0.53*HF + 0.47*B88, 0.73*LYP")
        config = {
            "scf_eng": H2O2.gga_eng,
            "cc": 0.27
        }
        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("pyxdhalpha", "Validation/gaussian/H2O2-B2PLYP-freq.fchk"))

        assert(np.allclose(
            - E_2, formchk.polarizability(),
            atol=1e-6, rtol=1e-4
        ))
Example #4
0
    def test_B2PLYP_hess(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface
        from pyxdhalpha.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("pyxdhalpha",
                              "Validation/gaussian/H2O2-B2PLYP-freq.fchk"))

        assert (np.allclose(E_2, formchk.hessian(), atol=1e-5, rtol=1e-4))

        with open(
                resource_filename(
                    "pyxdhalpha",
                    "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))
Example #5
0
    def test_MP2_hess(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface
        from pyxdhalpha.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("pyxdhalpha",
                              "Validation/gaussian/H2O2-MP2-freq.fchk"))

        assert (np.allclose(E_2, formchk.hessian(), atol=1e-6, rtol=1e-4))
Example #6
0
    def test_HF_polar(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface
        from pyxdhalpha.DerivOnce import DipoleSCF

        H2O2 = Mol_H2O2()
        config = {"scf_eng": H2O2.hf_eng}
        dip_helper = DipoleSCF(config)
        config = {
            "deriv_A": dip_helper,
            "deriv_B": dip_helper,
        }

        helper = PolarSCF(config)
        E_2 = helper.E_2

        formchk = FormchkInterface(
            resource_filename("pyxdhalpha",
                              "Validation/gaussian/H2O2-HF-freq.fchk"))

        assert (np.allclose(-E_2,
                            formchk.polarizability(),
                            atol=1e-6,
                            rtol=1e-4))
Example #7
0
    def test_B2PLYP_dipole(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface

        H2O2 = Mol_H2O2(xc="0.53*HF + 0.47*B88, 0.73*LYP")
        config = {"scf_eng": H2O2.gga_eng, "cc": 0.27}
        helper = DipoleMP2(config)

        formchk = FormchkInterface(
            resource_filename("pyxdhalpha",
                              "Validation/gaussian/H2O2-B2PLYP-freq.fchk"))

        assert (np.allclose(helper.E_1, formchk.dipole(), atol=1e-6,
                            rtol=1e-4))
Example #8
0
    def test_MP2_dipole(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface

        H2O2 = Mol_H2O2()
        config = {"scf_eng": H2O2.hf_eng}
        helper = DipoleMP2(config)

        formchk = FormchkInterface(
            resource_filename("pyxdhalpha",
                              "Validation/gaussian/H2O2-MP2-freq.fchk"))

        assert (np.allclose(helper.E_1, formchk.dipole(), atol=1e-6,
                            rtol=1e-4))
Example #9
0
    def test_HF_grad(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface

        H2O2 = Mol_H2O2()
        config = {"scf_eng": H2O2.hf_eng}
        helper = GradSCF(config)
        hf_grad = helper.scf_grad

        assert (np.allclose(helper.E_1, hf_grad.grad(), atol=1e-6, rtol=1e-4))

        formchk = FormchkInterface(
            resource_filename("pyxdhalpha",
                              "Validation/gaussian/H2O2-HF-freq.fchk"))

        assert (np.allclose(helper.E_1, formchk.grad(), atol=1e-6, rtol=1e-4))
Example #10
0
    def test_B3LYP_grad(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface

        H2O2 = Mol_H2O2()
        config = {"scf_eng": H2O2.gga_eng}
        helper = GradSCF(config)
        gga_grad = helper.scf_grad

        assert (np.allclose(helper.E_1, gga_grad.grad(), atol=1e-6, rtol=1e-4))

        formchk = FormchkInterface(
            resource_filename("pyxdhalpha",
                              "Validation/gaussian/H2O2-B3LYP-freq.fchk"))

        # TODO: This is a weaker compare! Try to modulize that someday.
        assert (np.allclose(helper.E_1, formchk.grad(), atol=1e-5, rtol=1e-4))
Example #11
0
    def test_B3LYP_dipole(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface

        H2O2 = Mol_H2O2()
        config = {"scf_eng": H2O2.gga_eng}
        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("pyxdhalpha",
                              "Validation/gaussian/H2O2-B3LYP-freq.fchk"))

        assert (np.allclose(helper.E_1, formchk.dipole(), atol=1e-6,
                            rtol=1e-4))
Example #12
0
    def test_B2PLYP_grad(self):

        from pkg_resources import resource_filename
        from pyxdhalpha.Utilities.test_molecules import Mol_H2O2
        from pyxdhalpha.Utilities import FormchkInterface

        H2O2 = Mol_H2O2(xc="0.53*HF + 0.47*B88, 0.73*LYP")
        config = {
            "scf_eng": H2O2.gga_eng,
            "cc": 0.27
        }
        gmh = GradMP2(config)

        formchk = FormchkInterface(resource_filename("pyxdhalpha", "Validation/gaussian/H2O2-B2PLYP-freq.fchk"))

        assert(np.allclose(
            gmh.eng,
            formchk.total_energy()
        ))
        assert(np.allclose(
            gmh.E_1, formchk.grad(),
            atol=1e-5, rtol=1e-4
        ))