예제 #1
0
def dipole_generator(component, interval):
    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()
    grids = dft.Grids(mol)
    grids.atom_grid = (99, 590)
    grids.build()
    scf_eng = scf.RHF(mol)
    scf_eng.conv_tol_grad = 1e-8
    nc_eng = dft.RKS(mol, xc="B3LYPg")
    nc_eng.grids = grids

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

    scf_eng.get_hcore = get_hcore
    nc_eng.get_hcore = get_hcore
    scf_eng.run()
    diph = DipoleNCDFT({
        "scf_eng": scf_eng,
        "nc_eng": nc_eng,
        "cphf_tol": 1e-10
    })
    return diph.E_1
예제 #2
0
 def __init__(self, datafile):
     self.verbose = logger.NOTE
     self.stdout = sys.stdout
     self.max_memory = lib.param.MAX_MEMORY
     self.chkfile = datafile
     self.scratch = lib.param.TMPDIR
     self.nthreads = lib.num_threads()
     self.non0tab = False
     self.corr = False
     self.occdrop = 1e-6
     self.chf = 0.0
     self.small_rho_cutoff = 1e-6
     self.prune = False
     ##################################################
     # don't modify the following attributes, they are not input options
     self.mol = lib.chkfile.load_mol(self.chkfile)
     self.grids = dft.Grids(self.mol)
     self.frevol = None
     self.rdm1 = None
     self.nocc = None
     self.mo_coeff = None
     self.mo_occ = None
     self.natm = None
     self.coords = None
     self.charges = None
     self.nelectron = None
     self.charge = None
     self.spin = None
     self.nprims = None
     self.nmo = None
     self._keys = set(self.__dict__.keys())
예제 #3
0
 def gen_grids(self, rad_points=99, sph_points=590, atom_grid=None):
     grids = dft.Grids(self.mol)
     grids.atom_grid = atom_grid
     if atom_grid is None:
         grids.atom_grid = (rad_points, sph_points)
     grids.radi_method = dft.gauss_chebyshev
     grids.becke_scheme = dft.gen_grid.stratmann
     grids.build()
     return grids
예제 #4
0
 def gen_grids(self, atom_grid=None):
     grids = dft.Grids(self.mol)
     grids.atom_grid = atom_grid
     if atom_grid is None:
         grids.atom_grid = (99, 590)
     grids.radi_method = dft.gauss_chebyshev
     grids.becke_scheme = dft.gen_grid.stratmann
     grids.build()
     return grids
예제 #5
0
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())
예제 #6
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
예제 #7
0
    def gga_eng(self):
        if self._gga_eng is not NotImplemented:
            return self._gga_eng

        grids = dft.Grids(self.mol)
        grids.atom_grid = (99, 590)
        grids.becke_scheme = dft.gen_grid.stratmann
        grids.build()

        gga_eng = scf.RKS(self.mol)
        gga_eng.grids = grids
        gga_eng.conv_tol = 1e-11
        gga_eng.conv_tol_grad = 1e-9
        gga_eng.max_cycle = 100
        gga_eng.xc = self.xc

        self._gga_eng = gga_eng
        return self._gga_eng
예제 #8
0
def dipole_generator(component, interval):
    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()
    grids = dft.Grids(mol)
    grids.atom_grid = (99, 590)
    grids.build()
    scf_eng = scf.RHF(mol)
    nc_eng = dft.RKS(mol, xc="B3LYPg")
    nc_eng.grids = grids

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

    scf_eng.get_hcore = get_hcore
    nc_eng.get_hcore = get_hcore
    scf_eng.run()
    return nc_eng.energy_tot(dm=scf_eng.make_rdm1())
예제 #9
0
#!/usr/bin/env python
'''
Show the functionality of the mode option.
'''

from pyscf import dft, gto
from var_mesh import var_mesh

mol = gto.M(atom='O 0 0 0; H 0 0 0.95691; H 0.95691 0 -0.23987')
mesh = dft.Grids(mol)

# Call var_mesh with the different mode options
print('mode=PySCF:')
var_mesh(mesh, mode='pyscf')
# If the code does not support different grids for different atom types, the
# precise option has no effect
print('\nmode=ERKALE:')
var_mesh(mesh, precise=True, mode='erkale')
print('\nmode=GAMESS:')
mesh = var_mesh(mesh, precise=False, mode='gamess')
# One can see, that the GAMESS grid differs from the PySCF grid
print('GAMESS grid: %s' % mesh.atom_grid)
예제 #10
0
class TestGradR:

    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()
    grids = dft.Grids(mol); grids.atom_grid = (99, 590); grids.build()
    grids_cphf = dft.Grids(mol); grids_cphf.atom_grid = (50, 194); grids_cphf.build()

    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 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_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)

    def test_r_mp2_grad(self):
        scf_eng = scf.RHF(self.mol).run()
        mp2_eng = mp.MP2(scf_eng).run()
        mp2_grad = mp2_eng.Gradients().run()
        gradh = GradMP2({"scf_eng": scf_eng})
        formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/NH3-MP2-freq.fchk"))
        # ASSERT: energy - Gaussian
        assert np.allclose(gradh.eng, formchk.total_energy())
        # ASSERT: energy - PySCF
        assert np.allclose(gradh.eng, mp2_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, mp2_grad.de, 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_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_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)
예제 #11
0
class TestHessR:

    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()
    grids = dft.Grids(mol)
    grids.atom_grid = (99, 590)
    grids.build()
    grids_cphf = dft.Grids(mol)
    grids_cphf.atom_grid = (50, 194)
    grids_cphf.build()

    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_hess(self):
        scf_eng = dft.RKS(self.mol, xc="B3LYPg")
        scf_eng.grids = self.grids
        scf_eng.run()
        scf_hess = scf_eng.Hessian().run()
        gradh = GradSCF({"scf_eng": scf_eng, "cphf_grids": self.grids_cphf})
        hessh = HessSCF({"deriv_A": gradh})
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/NH3-B3LYP-freq.fchk"))
        # ASSERT: hessian - Gaussian
        assert np.allclose(hessh.E_2, formchk.hessian(), atol=1e-5, rtol=2e-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_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)

    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 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)
예제 #12
0
class TestGradU:

    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()
    grids = dft.Grids(mol)
    grids.atom_grid = (99, 590)
    grids.build()
    grids_cphf = dft.Grids(mol)
    grids_cphf.atom_grid = (50, 194)
    grids_cphf.build()

    def test_u_uhf_grad(self):
        scf_eng = scf.UHF(self.mol).run()
        scf_grad = scf_eng.Gradients().run()
        gradh = GradUSCF({"scf_eng": scf_eng})
        formchk = FormchkInterface(
            resource_filename("pyxdh", "Validation/gaussian/CH3-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=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_u_b3lyp_grad(self):
        scf_eng = dft.UKS(self.mol, xc="B3LYPg")
        scf_eng.grids = self.grids
        scf_eng.run()
        scf_grad = scf_eng.Gradients().run()
        gradh = GradUSCF({"scf_eng": scf_eng})
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/CH3-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_u_hfb3lyp_grad(self):
        scf_eng = scf.UHF(self.mol)
        scf_eng.conv_tol_grad = 1e-10
        scf_eng.run()
        nc_eng = dft.UKS(self.mol, xc="B3LYPg")
        nc_eng.grids = self.grids
        gradh = GradUNCDFT({
            "scf_eng": scf_eng,
            "nc_eng": nc_eng,
            "cphf_tol": 1e-15
        })
        with open(
                resource_filename(
                    "pyxdh",
                    "Validation/numerical_deriv/CH3-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)

    def test_u_mp2_grad(self):
        scf_eng = scf.UHF(self.mol)
        scf_eng.conv_tol_grad = 1e-8
        scf_eng.max_cycle = 128
        scf_eng.run()
        assert scf_eng.converged
        mp2_eng = mp.MP2(scf_eng).run()
        mp2_grad = mp2_eng.Gradients().run()
        gradh = GradUMP2({"scf_eng": scf_eng})
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/CH3-MP2-freq.fchk"))
        # ASSERT: energy - Gaussian
        assert np.allclose(gradh.eng, formchk.total_energy())
        # ASSERT: energy - PySCF
        assert np.allclose(gradh.eng, mp2_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, mp2_grad.de, atol=1e-6, rtol=1e-4)

    def test_u_xyg3_grad(self):
        scf_eng = dft.UKS(self.mol, xc="B3LYPg")
        scf_eng.grids = self.grids
        scf_eng.conv_tol_grad = 1e-10
        scf_eng.max_cycle = 128
        scf_eng.run()
        nc_eng = dft.UKS(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,
            "cphf_tol": 1e-10
        }
        gradh = GradUXDH(config)
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/CH3-XYG3-force.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_u_xygjos_grad(self):
        scf_eng = dft.UKS(self.mol, xc="B3LYPg")
        scf_eng.grids = self.grids
        scf_eng.conv_tol_grad = 1e-10
        scf_eng.max_cycle = 128
        scf_eng.run()
        nc_eng = dft.UKS(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 = GradUXDH(config)
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/CH3-XYGJOS-force.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)
예제 #13
0
mf._numint.libxc = dft.xcfun
# PySCF-1.6.1 and newer supports the .TDDFT method to create a TDDFT
# object after importing tdscf module.
td = mf.TDDFT()
print(td.kernel()[0] * 27.2114)

#
# Overwriting the relevant attributes of the ground state mf object,
# the TDDFT calculations can be run with different XC, grids.
#
mf.xc = 'lda,vwn'
mf.grids.set(level=2).kernel(with_non0tab=True)
td = mf.TDDFT()
print(td.kernel()[0] * 27.2114)

#
# Overwriting the ground state SCF object is unsafe.  A better solution is to
# create a new fake SCF object to hold different XC, grids parameters.
#
from pyscf.dft import numint

mf = dft.RKS(mol).run(xc='pbe0')
mf1 = copy.copy(mf)
mf1.xc = 'lda,vwn'
mf1.grids = dft.Grids(mol)
mf1.grids.level = 2
mf1._numint = numint.NumInt()
mf1._numint.libxc = dft.xcfun
td = mf1.TDDFT()
print(td.kernel()[0] * 27.2114)
예제 #14
0
class TestDipoleR:

    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()
    grids = dft.Grids(mol)
    grids.atom_grid = (99, 590)
    grids.build()
    grids_cphf = dft.Grids(mol)
    grids_cphf.atom_grid = (50, 194)
    grids_cphf.build()

    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_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_r_hfb3lyp_dipole(self):
        scf_eng = scf.RHF(self.mol)
        scf_eng.conv_tol_grad = 1e-8
        scf_eng.run()
        nc_eng = dft.RKS(self.mol, xc="B3LYPg")
        nc_eng.grids = self.grids
        diph = DipoleNCDFT({"scf_eng": scf_eng, "nc_eng": nc_eng})
        with open(
                resource_filename(
                    "pyxdh", "Validation/numerical_deriv/NH3-HFB3LYP-dip.dat"),
                "rb") as f:
            ref_dip = pickle.load(f)
        # ASSERT: dipole - numerical
        assert np.allclose(diph.E_1, ref_dip, atol=1e-6, rtol=1e-4)

    def test_r_mp2_dipole(self):
        scf_eng = scf.RHF(self.mol).run()
        diph = DipoleMP2({"scf_eng": scf_eng})
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/NH3-MP2-freq.fchk"))
        # ASSERT: dipole - Gaussian
        assert np.allclose(diph.E_1, formchk.dipole(), 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_r_xyg3_dipole(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
        }
        diph = DipoleXDH(config)
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/NH3-XYG3-freq.fchk"))
        # ASSERT: grad - Gaussian
        assert np.allclose(diph.E_1, formchk.dipole(), atol=1e-6, rtol=1e-4)

    def test_r_xygjos_dipole(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
        }
        diph = DipoleXDH(config)
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/NH3-XYGJOS-freq.fchk"))
        # ASSERT: grad - Gaussian
        assert np.allclose(diph.E_1, formchk.dipole(), atol=1e-6, rtol=1e-4)
예제 #15
0
class TestDipDerivSCF:

    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()
    grids = dft.Grids(mol)
    grids.atom_grid = (99, 590)
    grids.build()
    grids_cphf = dft.Grids(mol)
    grids_cphf.atom_grid = (50, 194)
    grids_cphf.build()

    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_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)

    def test_r_mp2_dipderiv(self):
        scf_eng = scf.RHF(self.mol).run()
        gradh = GradMP2({"scf_eng": scf_eng})
        diph = DipoleMP2({"scf_eng": scf_eng})
        ddh = DipDerivMP2({"deriv_A": diph, "deriv_B": gradh})
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/NH3-MP2-freq.fchk"))
        # ASSERT: hessian - Gaussian
        assert np.allclose(ddh.E_2.T,
                           formchk.dipolederiv(),
                           atol=5e-6,
                           rtol=2e-4)

    def test_r_xyg3_dipderiv(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)
        diph = DipoleXDH(config)
        ddh = DipDerivXDH({"deriv_A": diph, "deriv_B": gradh})
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/NH3-XYG3-freq.fchk"))
        # ASSERT: hessian - Gaussian
        np.allclose(ddh.E_2.T, formchk.dipolederiv(), atol=5e-6, rtol=2e-4)

    def test_r_xygjos_dipderiv(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)
        diph = DipoleXDH(config)
        ddh = DipDerivXDH({"deriv_A": diph, "deriv_B": gradh})
        formchk = FormchkInterface(
            resource_filename("pyxdh",
                              "Validation/gaussian/NH3-XYGJOS-freq.fchk"))
        # ASSERT: hessian - Gaussian
        np.allclose(ddh.E_2.T, formchk.dipolederiv(), atol=5e-6, rtol=2e-4)