Beispiel #1
0
    def test_finite_diff_uks_eph(self):
        mf = dft.UKS(mol)
        mf.grids.level = 6
        mf.grids.build()
        mf.xc = 'b3lyp'
        mf.conv_tol = 1e-16
        mf.conv_tol_grad = 1e-10
        mf.kernel()

        grad = mf.nuc_grad_method().kernel()
        self.assertTrue(abs(grad).max() < 1e-5)
        mat, omega = eph_fd.kernel(mf)
        matmo, _ = eph_fd.kernel(mf, mo_rep=True)

        myeph = uks.EPH(mf)
        eph, _ = myeph.kernel()
        ephmo, _ = myeph.kernel(mo_rep=True)

        for i in range(len(omega)):
            self.assertTrue(
                min(np.linalg.norm(eph[:, i] - mat[:, i]),
                    np.linalg.norm(eph[:, i] + mat[:, i])) < 1e-5)
            self.assertTrue(
                min(
                    abs(eph[:, i] - mat[:, i]).max(),
                    abs(eph[:, i] + mat[:, i]).max()) < 1e-5)
            self.assertTrue(
                min(np.linalg.norm(ephmo[:, i] - matmo[:, i]),
                    np.linalg.norm(ephmo[:, i] + matmo[:, i])) < 1e-5)
            self.assertTrue(
                min(
                    abs(ephmo[:, i] - matmo[:, i]).max(),
                    abs(ephmo[:, i] + matmo[:, i]).max()) < 1e-5)
Beispiel #2
0
    def test_finite_diff_rks_eph(self):
        mf = dft.RKS(mol)
        mf.chkfile = tempfile.NamedTemporaryFile().name
        mf.grids.level = 3
        mf.xc = 'b3lyp'
        mf.conv_tol = 1e-14
        mf.conv_tol_grad = 1e-9
        mf.kernel()

        grad = mf.nuc_grad_method().kernel()
        self.assertTrue(abs(grad).max() < 1e-5)
        mat, omega = eph_fd.kernel(mf)
        matmo, _ = eph_fd.kernel(mf, mo_rep=True)

        myeph = rks.EPH(mf)
        eph, _ = myeph.kernel()
        ephmo, _ = myeph.kernel(mo_rep=True)
        for i in range(len(omega)):
            self.assertTrue(
                min(np.linalg.norm(eph[i] -
                                   mat[i]), np.linalg.norm(eph[i] +
                                                           mat[i])) < 1e-5)
            self.assertTrue(
                min(abs(eph[i] - mat[i]).max(),
                    abs(eph[i] + mat[i]).max()) < 1e-5)
            self.assertTrue(
                min(np.linalg.norm(ephmo[i] - matmo[i]),
                    np.linalg.norm(ephmo[i] + matmo[i])) < 1e-5)
            self.assertTrue(
                min(
                    abs(ephmo[i] - matmo[i]).max(),
                    abs(ephmo[i] + matmo[i]).max()) < 1e-5)
Beispiel #3
0
    def test_finite_diff_rhf_eph(self):
        mf = scf.RHF(mol)
        mf.conv_tol = 1e-16
        mf.conv_tol_grad = 1e-10
        mf.kernel()

        grad = mf.nuc_grad_method().kernel()
        self.assertTrue(abs(grad).max() < 1e-5)
        mat, omega = eph_fd.kernel(mf)
        matmo, _ = eph_fd.kernel(mf, mo_rep=True)

        myeph = rhf.EPH(mf)
        eph, _ = myeph.kernel()
        ephmo, _ = myeph.kernel(mo_rep=True)
        for i in range(len(omega)):
            self.assertTrue(
                min(np.linalg.norm(eph[i] -
                                   mat[i]), np.linalg.norm(eph[i] +
                                                           mat[i])) < 1e-5)
            self.assertTrue(
                min(abs(eph[i] - mat[i]).max(),
                    abs(eph[i] + mat[i]).max()) < 1e-5)
            self.assertTrue(
                min(np.linalg.norm(ephmo[i] - matmo[i]),
                    np.linalg.norm(ephmo[i] + matmo[i])) < 1e-5)
            self.assertTrue(
                min(
                    abs(ephmo[i] - matmo[i]).max(),
                    abs(ephmo[i] + matmo[i]).max()) < 1e-5)
Beispiel #4
0
    def test_finite_diff_uhf_eph(self):
        mf = scf.UHF(mol)
        mf.chkfile = tempfile.NamedTemporaryFile().name
        mf.conv_tol = 1e-14
        mf.conv_tol_grad = 1e-9
        mf.kernel()

        grad = mf.nuc_grad_method().kernel()
        self.assertTrue(abs(grad).max() < 1e-5)
        mat, omega = eph_fd.kernel(mf)
        matmo, _ = eph_fd.kernel(mf, mo_rep=True)

        myeph = uhf.EPH(mf)
        eph, _ = myeph.kernel()
        ephmo, _ = myeph.kernel(mo_rep=True)
        for i in range(len(omega)):
            self.assertTrue(
                min(np.linalg.norm(eph[:, i] - mat[:, i]),
                    np.linalg.norm(eph[:, i] + mat[:, i])) < 1e-5)
            self.assertTrue(
                min(
                    abs(eph[:, i] - mat[:, i]).max(),
                    abs(eph[:, i] + mat[:, i]).max()) < 1e-5)
            self.assertTrue(
                min(np.linalg.norm(ephmo[:, i] - matmo[:, i]),
                    np.linalg.norm(ephmo[:, i] + matmo[:, i])) < 1e-5)
            self.assertTrue(
                min(
                    abs(ephmo[:, i] - matmo[:, i]).max(),
                    abs(ephmo[:, i] + matmo[:, i]).max()) < 1e-5)
Beispiel #5
0
#!/usr/bin/env python
'''
A simple example to run EPH calculation using finite difference.
'''
from pyscf import gto, dft
from pyscf.eph.eph_fd import kernel

mol = gto.M(atom='N 0 0 0; N 0 0 2.100825',
            basis='def2-svp',
            verbose=4,
            unit="bohr")
# this is a pre-computed relaxed molecule
# for geometry relaxation, refer to pyscf/example/geomopt
mf = dft.RKS(mol, xc='pbe,pbe')
mf.run()

grad = mf.nuc_grad_method().kernel()
assert (abs(grad).sum() < 1e-5)  # making sure the geometry is relaxed

mat, omega = kernel(mf, disp=1e-4, mo_rep=True)
print(mat.shape, omega)