예제 #1
0
    def test_HF_B3LYP_hess(self):

        from pkg_resources import resource_filename
        from pyxdh.Utilities.test_molecules import Mol_H2O2
        from pyxdh.DerivOnce import GradNCDFT
        import pickle

        H2O2 = Mol_H2O2()
        config = {
            "scf_eng": H2O2.hf_eng,
            "nc_eng": H2O2.gga_eng,
            "rotation": True,
        }
        grad_helper = GradNCDFT(config)

        config = {
            "deriv_A": grad_helper,
            "deriv_B": grad_helper,
        }
        helper = HessNCDFT(config)
        E_2 = helper.E_2

        with open(resource_filename("pyxdh", "Validation/numerical_deriv/ncdft_hessian_hf_b3lyp.dat"), "rb") as f:
            ref_hess = pickle.load(f)["hess"]

        assert (np.allclose(
            E_2, ref_hess,
            atol=1e-6, rtol=1e-4
        ))
예제 #2
0
 def test_r_hfb3lyp_grad(self):
     scf_eng = scf.RHF(self.mol).run()
     nc_eng = dft.RKS(self.mol, xc="B3LYPg")
     nc_eng.grids = self.grids
     gradh = GradNCDFT({"scf_eng": scf_eng, "nc_eng": nc_eng})
     with open(resource_filename("pyxdh", "Validation/numerical_deriv/NH3-HFB3LYP-grad.dat"), "rb") as f:
         ref_grad = pickle.load(f).reshape(-1, 3)
     # ASSERT: energy - theoretical
     assert np.allclose(gradh.eng, nc_eng.energy_tot(dm=scf_eng.make_rdm1()))
     # ASSERT: grad - numerical
     assert np.allclose(gradh.E_1, ref_grad, atol=1e-6, rtol=1e-4)
예제 #3
0
def mol_to_grad(mol):
    grids = dft.Grids(mol)
    grids.atom_grid = (99, 590)
    grids.build()
    scf_eng = scf.RHF(mol)
    scf_eng.conv_tol = 1e-12
    scf_eng.conv_tol_grad = 1e-10
    scf_eng.max_cycle = 256
    scf_eng.run()
    nc_eng = dft.RKS(mol, xc="B3LYPg")
    nc_eng.grids = grids
    gradh = GradNCDFT({"scf_eng": scf_eng, "nc_eng": nc_eng})
    return gradh.E_1
예제 #4
0
def dipole_generator(component, interval):
    H2O2 = Mol_H2O2()
    mol = H2O2.mol

    def get_hcore(mol=mol):
        return scf.rhf.get_hcore(
            mol) - interval * mol.intor("int1e_r")[component]

    H2O2.hf_eng.get_hcore = get_hcore
    H2O2.gga_eng.get_hcore = get_hcore

    config = {"scf_eng": H2O2.hf_eng, "nc_eng": H2O2.gga_eng}
    helper = GradNCDFT(config)
    return helper
예제 #5
0
 def test_r_hfb3lyp_hess(self):
     scf_eng = scf.RHF(self.mol)
     scf_eng.conv_tol_grad = 1e-10
     scf_eng.max_cycle = 256
     scf_eng.run()
     nc_eng = dft.RKS(self.mol, xc="B3LYPg")
     nc_eng.grids = self.grids
     gradh = GradNCDFT({"scf_eng": scf_eng, "nc_eng": nc_eng})
     hessh = HessNCDFT({"deriv_A": gradh})
     with open(
             resource_filename(
                 "pyxdh",
                 "Validation/numerical_deriv/NH3-HFB3LYP-hess.dat"),
             "rb") as f:
         ref_hess = pickle.load(f)
     # ASSERT: hessian - numerical
     assert np.allclose(hessh.E_2,
                        ref_hess.reshape((-1, self.mol.natm * 3)),
                        atol=5e-6,
                        rtol=1e-4)
예제 #6
0
    def test_HF_B3LYP_dipderiv(self):

        from pkg_resources import resource_filename
        from pyxdh.Utilities.test_molecules import Mol_H2O2
        from pyxdh.DerivOnce import DipoleNCDFT, GradNCDFT
        import pickle

        H2O2 = Mol_H2O2()
        config = {"scf_eng": H2O2.hf_eng, "nc_eng": H2O2.gga_eng}
        dip_helper = DipoleNCDFT(config)
        grad_helper = GradNCDFT(config)
        config = {"deriv_A": dip_helper, "deriv_B": grad_helper}

        helper = DipDerivNCDFT(config)
        E_2 = helper.E_2

        with open(
                resource_filename(
                    "pyxdh",
                    "Validation/numerical_deriv/ncdft_dipderiv_hf_b3lyp.dat"),
                "rb") as f:
            ref_dipderiv = pickle.load(f)["dipderiv"]

        assert (np.allclose(E_2.T, ref_dipderiv, atol=1e-6, rtol=1e-4))
예제 #7
0
def mol_to_grad_helper(mol):
    H2O2 = Mol_H2O2(mol=mol)
    H2O2.hf_eng.kernel()
    config = {"scf_eng": H2O2.hf_eng, "nc_eng": H2O2.gga_eng}
    helper = GradNCDFT(config)
    return helper