Example #1
0
    def test_NucCoordDerivGenerator_by_SCFgrad(self):
        from pyxdh.Utilities.test_molecules import Mol_H2O2
        H2O2 = Mol_H2O2()
        mol = H2O2.mol
        hf_grad = H2O2.hf_grad

        generator = NucCoordDerivGenerator(mol, lambda mol_: scf.RHF(mol_).run())
        diff = NumericDiff(generator, lambda mf: mf.kernel())
        assert(np.allclose(
            hf_grad.kernel(),
            diff.derivative.reshape(mol.natm, 3),
            atol=1e-6, rtol=1e-4
        ))

        generator = NucCoordDerivGenerator(mol, lambda mol_: scf.RHF(mol_).run(), stencil=5)
        diff = NumericDiff(generator, lambda mf: mf.kernel())
        assert(np.allclose(
            hf_grad.kernel(),
            diff.derivative.reshape(mol.natm, 3),
            atol=1e-6, rtol=1e-4
        ))
Example #2
0
import pickle
from pyscf import scf, gto, dft
from pyxdh.Utilities import NumericDiff, NucCoordDerivGenerator


def mol_to_eng(mol):
    grids = dft.Grids(mol)
    grids.atom_grid = (99, 590)
    grids.build()
    scf_eng = scf.RHF(mol)
    scf_eng.conv_tol_grad = 1e-8
    scf_eng.run()
    nc_eng = dft.RKS(mol, xc="B3LYPg")
    nc_eng.grids = grids
    return nc_eng.energy_tot(dm=scf_eng.make_rdm1())


if __name__ == '__main__':
    name = __file__.split("/")[-1].split(".")[0]
    mol = gto.Mole(atom="N 0. 0. 0.; H .9 0. 0.; H 0. 1. 0.; H 0. 0. 1.1",
                   basis="6-31G",
                   verbose=0).build()
    num_obj = NucCoordDerivGenerator(mol, mol_to_eng)
    num_dif = NumericDiff(num_obj).derivative
    with open(name + ".dat", "wb") as f:
        pickle.dump(num_dif, f, pickle.HIGHEST_PROTOCOL)
Example #3
0
import pickle
from pyscf import scf, gto, dft
from pyxdh.Utilities import NumericDiff, NucCoordDerivGenerator


def mol_to_eng(mol):
    grids = dft.Grids(mol)
    grids.atom_grid = (99, 590)
    grids.build()
    scf_eng = scf.UHF(mol)
    scf_eng.conv_tol_grad = 1e-10
    scf_eng.max_cycle = 128
    scf_eng.run()
    nc_eng = dft.UKS(mol, xc="B3LYPg")
    nc_eng.grids = grids
    return nc_eng.energy_tot(dm=scf_eng.make_rdm1())


if __name__ == '__main__':
    name = __file__.split("/")[-1].split(".")[0]
    mol = gto.Mole(atom="C 0. 0. 0.; H 1. 0. 0.; H 0. 2. 0.; H 0. 0. 1.5",
                   basis="6-31G",
                   spin=1,
                   verbose=0).build()
    num_obj = NucCoordDerivGenerator(mol, mol_to_eng, interval=1e-4)
    num_dif = NumericDiff(num_obj).derivative
    with open(name + ".dat", "wb") as f:
        pickle.dump(num_dif, f, pickle.HIGHEST_PROTOCOL)
Example #4
0
import pickle

from pyxdh.Utilities.test_molecules import Mol_H2O2
from pyxdh.Utilities import NumericDiff, NucCoordDerivGenerator
from pyxdh.DerivOnce import GradMP2


def mol_to_grad_helper(mol):
    print("Processing...")
    H2O2 = Mol_H2O2(mol=mol, xc="0.53*HF + 0.47*B88, 0.73*LYP")
    config = {
        "scf_eng": H2O2.gga_eng,
        "cc": 0.27
    }
    helper = GradMP2(config)
    return helper


if __name__ == '__main__':
    result_dict = {}
    H2O2 = Mol_H2O2(xc="0.53*HF + 0.47*B88, 0.73*LYP")
    mol = H2O2.mol

    num_obj = NucCoordDerivGenerator(H2O2.mol, mol_to_grad_helper)
    num_dif = NumericDiff(num_obj, lambda helper: helper.E_1.reshape(-1))
    result_dict["hess"] = num_dif.derivative

    with open("mp2_hessian_b2plyp.dat", "wb") as f:
        pickle.dump(result_dict, f, pickle.HIGHEST_PROTOCOL)
Example #5
0
    N  0.  0.  0.
    H  1.5 0.  0.2
    H  0.1 1.2 0.
    H  0.  0.  1.
    """
    mol.basis = "cc-pVDZ"
    mol.verbose = 0
    mol.build()

    def mol_to_eng_true(mol):
        mf_scf = scf.RHF(mol).density_fit(auxbasis="cc-pVDZ-jkfit").run()
        mf_mp2 = mp.MP2(mf_scf)
        mf_mp2.with_df = df.DF(mol, auxbasis="cc-pVDZ-ri")
        return mf_mp2.run().e_tot

    def mol_to_eng_false(mol):
        mf_scf = scf.RHF(mol).density_fit(auxbasis="cc-pVDZ-jkfit").run()
        mf_mp2 = mp.MP2(mf_scf)
        return mf_mp2.run().e_tot

    # Check deviation of using jkfit and ri auxbasis in MP2 gradient
    num_true = NucCoordDerivGenerator(mol, mol_to_eng_true)
    num_false = NucCoordDerivGenerator(mol, mol_to_eng_false)
    val_true = NumericDiff(num_true).derivative
    val_false = NumericDiff(num_false).derivative
    assert (np.allclose(val_true, val_false, atol=1e-5, rtol=1e-4) is False)

    result_dict = {"grad": val_true}
    with open("df_mp2_grad_mp2.dat", "wb") as f:
        pickle.dump(result_dict, f, pickle.HIGHEST_PROTOCOL)