Beispiel #1
0
    def test_cgf_overlap(self):
        """
        Test kinetic integrals for contracted Gaussians

        Sij = <cgf_i | cgf_j>
        """

        # construct integrator object
        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule("H2")
        mol.add_atom('H', 0.0, 0.0, 0.0)
        mol.add_atom('H', 0.0, 0.0, 1.4)
        cgfs, nuclei = mol.build_basis('sto3g')

        S = np.zeros((2, 2))
        S[0, 0] = integrator.overlap(cgfs[0], cgfs[0])
        S[0, 1] = S[1, 0] = integrator.overlap(cgfs[0], cgfs[1])
        S[1, 1] = integrator.overlap(cgfs[1], cgfs[1])

        S11 = 1.0
        S12 = 0.65931845
        np.testing.assert_almost_equal(S[0, 0], S11, 4)
        np.testing.assert_almost_equal(S[1, 1], S11, 4)
        np.testing.assert_almost_equal(S[0, 1], S12, 4)
Beispiel #2
0
    def test_integrals_h2o_openmp_sto3g(self):
        """
        Test OpenMP integral evaluation for H2O using sto-3g basis set
        """

        # construct integrator object
        integrator = PyQInt()

        # build water molecule
        mol = Molecule("H2O")
        mol.add_atom('H', 0.7570, 0.5860, 0.0)
        mol.add_atom('H', -0.7570, 0.5860, 0.0)
        mol.add_atom('O', 0.0, 0.0, 0.0)
        cgfs, nuclei = mol.build_basis('sto3g')

        # evaluate all integrals
        ncpu = multiprocessing.cpu_count()
        S, T, V, teint = integrator.build_integrals_openmp(cgfs, nuclei)

        # load results from npy files
        S_result = np.load(os.path.join(os.path.dirname(__file__), 'results', 'h2o_overlap_sto3g.npy'))
        T_result = np.load(os.path.join(os.path.dirname(__file__), 'results', 'h2o_kinetic_sto3g.npy'))
        V_result = np.load(os.path.join(os.path.dirname(__file__), 'results', 'h2o_nuclear_sto3g.npy'))
        teint_result = np.load(os.path.join(os.path.dirname(__file__), 'results', 'h2o_teint_sto3g.npy'))

        # assessment
        self.assertEqual(len(cgfs), 7)
        self.assertEqual(S.shape[0], S.shape[1])
        self.assertEqual(S.shape[0], len(cgfs))
        np.testing.assert_almost_equal(S, S_result, 4)
        np.testing.assert_almost_equal(T, T_result, 4)
        np.testing.assert_almost_equal(V, V_result, 4)
        np.testing.assert_almost_equal(teint, teint_result, 4)
Beispiel #3
0
    def testDerivBF_pxy(self):
        """
        Test Derivative of the px-type basis functions in y-direction
        """

        # construct integrator object
        integrator = PyQInt()

        # build gtos
        nucleus = [-0.5, 0.0, 0.0]
        gto1 = gto(0.154329, [-0.50, 0.0, 0.0], 3.425251, 1, 0, 0)
        gto2 = gto(0.154329, [0.50, 0.0, 0.0], 3.425251, 1, 0, 0)

        # derivative towards bf coordinates
        t1 = integrator.nuclear_gto_deriv_bf(gto1, gto1, nucleus, 1)

        # test the first derivative of the second hydrogen atom in the
        # Cartesian direction
        t2 = integrator.nuclear_gto_deriv_bf(gto2, gto2, nucleus, 1)

        # also calculate this integral using finite difference
        fx_fd_01 = calculate_fy_bf_finite_difference(gto1, nucleus)
        fx_fd_02 = calculate_fy_bf_finite_difference(gto2, nucleus)

        # testing
        np.testing.assert_almost_equal(-2 * t1, fx_fd_01, 4)
        np.testing.assert_almost_equal(-2 * t2, fx_fd_02, 4)
Beispiel #4
0
    def testPlotGrid(self):
        """
        Test plotting of 1b2 molecular orbital of H2O
        """
        # coefficients
        coeff = [
            8.37612e-17, -2.73592e-16, -0.713011, -1.8627e-17, 9.53496e-17,
            -0.379323, 0.379323
        ]

        # construct integrator object
        integrator = PyQInt()

        # build water molecule
        mol = Molecule('H2O')
        mol.add_atom('O', 0.0, 0.0, 0.0)
        mol.add_atom('H', 0.7570, 0.5860, 0.0)
        mol.add_atom('H', -0.7570, 0.5860, 0.0)
        cgfs, nuclei = mol.build_basis('sto3g')

        # build grid
        x = np.linspace(-2, 2, 50)
        y = np.linspace(-2, 2, 50)
        xx, yy = np.meshgrid(x, y)
        zz = np.zeros(len(x) * len(y))
        grid = np.vstack([xx.flatten(), yy.flatten(), zz]).reshape(3, -1).T
        res = integrator.plot_wavefunction(grid, coeff, cgfs).reshape(
            (len(y), len(x)))

        ans = np.load(
            os.path.join(os.path.dirname(__file__), 'results',
                         'h2o_orb_1b2.npy'))
        np.testing.assert_almost_equal(res, ans, 8)
Beispiel #5
0
    def testFunctionsCGF(self):
        """
        Test getting amplitude from CGF
        """

        # construct integrator object
        integrator = PyQInt()

        # get compile info
        compile_info = integrator.get_compile_info()

        # build hydrogen molecule
        mol = Molecule()
        mol.add_atom('H', 0.0, 0.0, 0.0)
        cgfs, nuclei = mol.build_basis('sto3g')

        # test values at these coordinates
        coords = []
        for x in np.linspace(0, 10, 10):
            coords.append([x, x, x])

        # results
        ans = [
            6.2825e-01, 7.1229e-02, 6.8672e-03, 3.0000e-04, 3.7662e-06,
            1.3536e-08, 1.3927e-11, 4.1021e-15, 3.4591e-19, 8.3505e-24
        ]

        # test for each coord
        amps = []
        for i, coord in enumerate(coords):
            amp = cgfs[0].get_amp(coord)
            amps.append(amp)

        np.testing.assert_almost_equal(amps, ans, 4)
Beispiel #6
0
    def test_cgf_kinetic(self):
        """
        Test kinetic integrals for contracted Gaussians

        Tij = <cgf_i | -1/2 nabla^{2} | cgf_j>
        """

        # construct integrator object
        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule("H2")
        mol.add_atom('H', 0.0, 0.0, 0.0)
        mol.add_atom('H', 0.0, 0.0, 1.4)
        cgfs, nuclei = mol.build_basis('sto3g')

        T = np.zeros((2, 2))
        T[0, 0] = integrator.kinetic(cgfs[0], cgfs[0])
        T[0, 1] = T[1, 0] = integrator.kinetic(cgfs[0], cgfs[1])
        T[1, 1] = integrator.kinetic(cgfs[1], cgfs[1])

        T11 = 0.7600315809249878
        T12 = 0.2364544570446014
        np.testing.assert_almost_equal(T[0, 0], T11, 4)
        np.testing.assert_almost_equal(T[1, 1], T11, 4)
        np.testing.assert_almost_equal(T[0, 1], T12, 4)
Beispiel #7
0
    def test_cgf_repulsion(self):
        """
        Test two-electron integrals for contracted Gaussians

        (ij|kl) = <cgf_i cgf_j | r_ij | cgf_k cgf_l>
        """

        # construct integrator object
        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule("H2")
        mol.add_atom('H', 0.0, 0.0, 0.0)
        mol.add_atom('H', 0.0, 0.0, 1.4)
        cgfs, nuclei = mol.build_basis('sto3g')

        T1111 = integrator.repulsion(cgfs[0], cgfs[0], cgfs[0], cgfs[0])
        T1122 = integrator.repulsion(cgfs[0], cgfs[0], cgfs[1], cgfs[1])
        T1112 = integrator.repulsion(cgfs[0], cgfs[0], cgfs[0], cgfs[1])
        T2121 = integrator.repulsion(cgfs[1], cgfs[0], cgfs[1], cgfs[0])
        T1222 = integrator.repulsion(cgfs[0], cgfs[1], cgfs[1], cgfs[1])
        T2211 = integrator.repulsion(cgfs[1], cgfs[1], cgfs[0], cgfs[0])

        np.testing.assert_almost_equal(T1111, 0.7746056914329529, 4)
        np.testing.assert_almost_equal(T1122, 0.5696758031845093, 4)
        np.testing.assert_almost_equal(T1112, 0.4441076656879812, 4)
        np.testing.assert_almost_equal(T2121, 0.2970285713672638, 4)

        # test similarity between two-electron integrals
        np.testing.assert_almost_equal(T1222, T1112, 4)
        np.testing.assert_almost_equal(T1122, T2211, 4)
Beispiel #8
0
    def test_compiler_info(self):
        """
        Test automatic integral evaluation for hydrogen molecule
        """

        # construct integrator object
        integrator = PyQInt()

        compiler_info = integrator.get_compile_info()
        self.assertTrue(len(compiler_info["compiler_version"]) > 4)
        self.assertTrue(len(compiler_info["compile_date"]) > 10)
        self.assertTrue(len(compiler_info["compile_time"]) > 4)
        self.assertTrue(len(compiler_info["openmp_version"]) > 2)
Beispiel #9
0
def calculate_force_finite_difference(cgf1, cgf2, nucleus, charge, coord):
    # build integrator object
    integrator = PyQInt()

    # distance
    diff = 0.00001

    # build hydrogen molecule
    nucleus[coord] -= diff / 2.0
    left = integrator.nuclear(cgf1, cgf2, nucleus, charge)
    nucleus[coord] += diff
    right = integrator.nuclear(cgf1, cgf2, nucleus, charge)

    return (right - left) / diff
Beispiel #10
0
    def test_cgf_nuclear(self):
        """
        Test nuclear attraction integrals for contracted Gaussians

        V^{(c)}_ij = <cgf_i | -Zc / |r-Rc| | cgf_j>
        """

        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule("H2")
        mol.add_atom('H', 0.0, 0.0, 0.0)
        mol.add_atom('H', 0.0, 0.0, 1.4)
        cgfs, nuclei = mol.build_basis('sto3g')

        V1 = np.zeros((2,2))
        V1[0,0] = integrator.nuclear(cgfs[0], cgfs[0], cgfs[0].p, 1)
        V1[0,1] = V1[1,0] = integrator.nuclear(cgfs[0], cgfs[1], cgfs[0].p, 1)
        V1[1,1] = integrator.nuclear(cgfs[1], cgfs[1], cgfs[0].p, 1)

        V2 = np.zeros((2,2))
        V2[0,0] = integrator.nuclear(cgfs[0], cgfs[0], cgfs[1].p, 1)
        V2[0,1] = V2[1,0] = integrator.nuclear(cgfs[0], cgfs[1], cgfs[1].p, 1)
        V2[1,1] = integrator.nuclear(cgfs[1], cgfs[1], cgfs[1].p, 1)

        V11 = -1.2266135215759277
        V12 = -0.5974172949790955
        V22 = -0.6538270711898804
        np.testing.assert_almost_equal(V1[0,0], V11, 4)
        np.testing.assert_almost_equal(V1[1,1], V22, 4)
        np.testing.assert_almost_equal(V1[0,1], V12, 4)
        np.testing.assert_almost_equal(V2[0,0], V22, 4)
        np.testing.assert_almost_equal(V2[1,1], V11, 4)
        np.testing.assert_almost_equal(V2[0,1], V12, 4)
Beispiel #11
0
    def testDerivH2(self):
        """
        Test Derivatives of dihydrogen
        """

        # build integrator object
        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule('H2')
        mol.add_atom('H', -0.5, 0.0, 0.0)
        mol.add_atom('H', 0.5, 0.0, 0.0)
        cgfs, nuclei = mol.build_basis('sto3g')

        fx1 = integrator.nuclear_deriv(cgfs[0], cgfs[0], nuclei[0][0],
                                       nuclei[0][1], nuclei[0][0], 0)
        fx2 = integrator.nuclear_deriv(cgfs[1], cgfs[1], nuclei[0][0],
                                       nuclei[0][1], nuclei[0][0], 0)

        ans1 = calculate_force_finite_difference(cgfs[0], cgfs[0],
                                                 nuclei[0][0], nuclei[0][1], 0)
        ans2 = calculate_force_finite_difference(cgfs[1], cgfs[1],
                                                 nuclei[0][0], nuclei[0][1], 0)

        np.testing.assert_almost_equal(fx1, ans1, 4)
        np.testing.assert_almost_equal(fx2, ans2, 4)

        # assert that the nuclear gradient in the x direction is zero because the
        # basis functions spawn from this atom
        self.assertTrue(np.abs(fx1) < 1e-8)

        # assert that the nuclear gradient has a meaningful number
        self.assertTrue(np.abs(fx2) > 1e-1)

        fx3 = integrator.nuclear_deriv(cgfs[0], cgfs[0], nuclei[1][0],
                                       nuclei[1][1], nuclei[1][0], 0)
        fx4 = integrator.nuclear_deriv(cgfs[1], cgfs[1], nuclei[1][0],
                                       nuclei[1][1], nuclei[1][0], 0)

        ans3 = calculate_force_finite_difference(cgfs[0], cgfs[0],
                                                 nuclei[1][0], nuclei[1][1], 0)
        ans4 = calculate_force_finite_difference(cgfs[1], cgfs[1],
                                                 nuclei[1][0], nuclei[1][1], 0)

        np.testing.assert_almost_equal(fx3, ans3, 4)
        np.testing.assert_almost_equal(fx4, ans4, 4)

        fy1 = integrator.nuclear_deriv(cgfs[0], cgfs[0], nuclei[0][0],
                                       nuclei[0][1], nuclei[0][0], 1)
        fy2 = integrator.nuclear_deriv(cgfs[1], cgfs[1], nuclei[0][0],
                                       nuclei[0][1], nuclei[0][0], 1)

        ans5 = calculate_force_finite_difference(cgfs[0], cgfs[0],
                                                 nuclei[0][0], nuclei[0][1], 1)
        ans6 = calculate_force_finite_difference(cgfs[1], cgfs[1],
                                                 nuclei[0][0], nuclei[0][1], 1)

        np.testing.assert_almost_equal(fy1, ans5, 4)
        np.testing.assert_almost_equal(fy2, ans6, 4)
Beispiel #12
0
def calculate_fy_op_finite_difference(_gto, nucleus):
    """
    Calculate the operator derivative in the y-direction using
    a finite difference method
    """
    # build integrator object
    integrator = PyQInt()

    diff = 0.000001
    nucleus[1] -= diff / 2.0
    left = integrator.nuclear_gto(_gto, _gto, nucleus)
    nucleus[1] += diff
    right = integrator.nuclear_gto(_gto, _gto, nucleus)

    return (right - left) / diff
Beispiel #13
0
    def test_gto_repulsion(self):
        """
        Test two-electron integrals for primitive GTOs

        (ij|kl) = <gto_i gto_j | r_ij | gto_k gto_l>
        """

        # construct integrator object
        integrator = PyQInt()

        # test GTO
        gto1 = gto(0.154329, [0.0, 0.0, 0.0], 3.425251, 0, 0, 0)
        gto2 = gto(0.535328, [0.0, 0.0, 0.0], 0.623914, 0, 0, 0)
        gto3 = gto(0.444635, [0.0, 0.0, 0.0], 0.168855, 0, 0, 0)
        repulsion = integrator.repulsion_gto(gto1, gto1, gto1, gto1)
        result = 2.0883402824401855
        np.testing.assert_almost_equal(repulsion, result, 4)
Beispiel #14
0
    def test_gto_nuclear(self):
        """
        Test nuclear attraction integral for GTOs

        V^{(c)}_ij = <gto_i | -1 / |r-Rc| | gto_j>
        """

        # construct integrator object
        integrator = PyQInt()

        # test GTO
        gto1 = gto(0.154329, [0.0, 0.0, 0.0], 3.425251, 0, 0, 0)
        gto2 = gto(0.535328, [0.0, 0.0, 0.0], 0.623914, 0, 0, 0)
        gto3 = gto(0.444635, [0.0, 0.0, 0.0], 0.168855, 0, 0, 0)
        nuclear = integrator.nuclear_gto(gto1, gto1, [0.0, 0.0, 1.0])
        result = -0.31049036979675293
        np.testing.assert_almost_equal(nuclear, result, 4)
Beispiel #15
0
    def test_gto_kinetic(self):
        """
        Test kinetic integrals for primitive GTOs

        Tij = <gto_I | -1/2 nabla^{2} | gto_j>
        """

        # construct integrator object
        integrator = PyQInt()

        # test GTO
        gto1 = gto(0.154329, [0.0, 0.0, 0.0], 3.425251, 0, 0, 0)
        gto2 = gto(0.535328, [0.0, 0.0, 0.0], 0.623914, 0, 0, 0)
        gto3 = gto(0.444635, [0.0, 0.0, 0.0], 0.168855, 0, 0, 0)
        kinetic = integrator.kinetic_gto(gto1, gto1)
        result = 1.595603108406067
        np.testing.assert_almost_equal(kinetic, result, 4)
Beispiel #16
0
    def test_gto_overlap(self):
        """
        Test kinetic integrals for GTOs

        Sij = <gto_i | gto_j>
        """

        # construct integrator object
        integrator = PyQInt()

        # test GTO
        gto1 = gto(0.154329, [0.0, 0.0, 0.0], 3.425251, 0, 0, 0)
        gto2 = gto(0.535328, [0.0, 0.0, 0.0], 0.623914, 0, 0, 0)
        gto3 = gto(0.444635, [0.0, 0.0, 0.0], 0.168855, 0, 0, 0)
        overlap = integrator.overlap_gto(gto1, gto1)
        result = 0.31055691838264465
        np.testing.assert_almost_equal(overlap, result, 4)
Beispiel #17
0
    def testDerivRepulsionGTO(self):
        # construct integrator object
        integrator = PyQInt()

        # build gtos
        gto1 = gto(0.154329, [-0.50, 0.0, 0.0], 3.425251, 0, 0, 0)
        gto2 = gto(0.154329, [-0.50, 0.0, 0.0], 3.425251, 0, 0, 0)
        gto3 = gto(0.154329, [0.50, 0.0, 0.0], 3.425251, 0, 0, 0)
        gto4 = gto(0.154329, [0.50, 0.0, 0.0], 3.425251, 0, 0, 0)

        # perform integration
        rep1 = integrator.repulsion_gto_deriv(gto1, gto2, gto3, gto4, 0)
        rep2 = integrator.repulsion_gto_deriv(gto2, gto1, gto3, gto4, 0)

        # perform finite difference
        ans1 = calculate_deriv_gto(gto1, gto2, gto3, gto4, 0)

        np.testing.assert_almost_equal(rep1, ans1, 4)
Beispiel #18
0
def calculate_fy_bf_finite_difference(_gto, nucleus):
    """
    Calculate the basis function derivative in the y-direction using
    a finite difference method
    """
    # build integrator object
    integrator = PyQInt()

    diff = 0.01
    gto1 = gto(0.154329, [_gto.p[0], _gto.p[1] - diff / 2, _gto.p[2]],
               3.425251, _gto.l, _gto.m, _gto.n)
    gto2 = gto(0.154329, [_gto.p[0], _gto.p[1] + diff / 2, _gto.p[2]],
               3.425251, _gto.l, _gto.m, _gto.n)

    left = integrator.nuclear_gto(gto1, gto1, nucleus)
    right = integrator.nuclear_gto(gto2, gto2, nucleus)

    return (right - left) / diff
Beispiel #19
0
    def testDerivH2(self):
        """
        Test Derivatives of dihydrogen
        """

        # build integrator object
        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule('H2')
        mol.add_atom('H', -0.5, 0.0, 0.0)
        mol.add_atom('H', 0.5, 0.0, 0.0)
        cgfs, nuclei = mol.build_basis('sto3g')

        # calculate derivative towards H1 in the x-direction
        fx1 = integrator.overlap_deriv(cgfs[0], cgfs[0], nuclei[0][0], 0)
        fx2 = integrator.overlap_deriv(cgfs[1], cgfs[1], nuclei[0][0], 0)

        ans1 = calculate_force_finite_difference(mol, 0, 0, 0, 0)
        ans2 = calculate_force_finite_difference(mol, 0, 1, 1, 0)

        # assert that the overlap of two CGFs that spawn from
        # the same nucleus will not change in energy due to a
        # change of the nucleus coordinates
        np.testing.assert_almost_equal(fx1, ans1, 4)
        np.testing.assert_almost_equal(fx1, 0.0, 4)
        np.testing.assert_almost_equal(fx2, ans2, 4)
        np.testing.assert_almost_equal(fx2, 0.0, 4)

        # assert that the cross-terms will change
        fx3 = integrator.overlap_deriv(cgfs[0], cgfs[1], nuclei[0][0], 0)
        fx4 = integrator.overlap_deriv(cgfs[0], cgfs[1], nuclei[1][0], 0)
        fx5 = integrator.overlap_deriv(cgfs[1], cgfs[0], nuclei[0][0], 0)
        fx6 = integrator.overlap_deriv(cgfs[1], cgfs[0], nuclei[1][0], 0)

        ans3 = calculate_force_finite_difference(mol, 0, 0, 1, 0)
        ans4 = calculate_force_finite_difference(mol, 1, 0, 1, 0)
        ans5 = calculate_force_finite_difference(mol, 0, 1, 0, 0)
        ans6 = calculate_force_finite_difference(mol, 1, 1, 0, 0)

        np.testing.assert_almost_equal(fx3, ans3, 4)
        np.testing.assert_almost_equal(fx4, ans4, 4)
        np.testing.assert_almost_equal(fx5, ans5, 4)
        np.testing.assert_almost_equal(fx6, ans6, 4)
Beispiel #20
0
def calculate_force_finite_difference(mol, nuc_id, cgf_id1, cgf_id2, coord):
    # build integrator object
    integrator = PyQInt()

    # distance
    diff = 0.00001

    mol1 = deepcopy(mol)
    mol1.atoms[nuc_id][1][coord] -= diff / 2
    mol2 = deepcopy(mol)
    mol2.atoms[nuc_id][1][coord] += diff / 2

    # build hydrogen molecule
    cgfs1, nuclei = mol1.build_basis('sto3g')
    left = integrator.overlap(cgfs1[cgf_id1], cgfs1[cgf_id2])
    cgfs2, nuclei = mol2.build_basis('sto3g')
    right = integrator.overlap(cgfs2[cgf_id1], cgfs2[cgf_id2])

    return (right - left) / diff
Beispiel #21
0
def calculate_deriv_gto(gto1, gto2, gto3, gto4, coord):
    # build integrator object
    integrator = PyQInt()

    # distance
    diff = 0.00001
    p = np.zeros(3)
    p[coord] = diff

    gto1_new1 = gto(gto1.c, gto1.p - 0.5 * p, gto1.alpha, gto1.l, gto1.m,
                    gto1.n)
    gto1_new2 = gto(gto1.c, gto1.p + 0.5 * p, gto1.alpha, gto1.l, gto1.m,
                    gto1.n)

    # build hydrogen molecule
    left = integrator.repulsion_gto(gto1_new1, gto2, gto3, gto4)
    right = integrator.repulsion_gto(gto1_new2, gto2, gto3, gto4)

    return (right - left) / diff
Beispiel #22
0
    def testDerivOpt_d1(self):
        """
        Test Derivative of the nuclear attraction operator in x-direction
        for d-type orbitals
        """

        # construct integrator object
        integrator = PyQInt()

        # build gtos
        nucleus = np.array([-0.5, 0.0, 0.0])
        gto1 = gto(0.154329, nucleus, 3.425251, 2, 0, 0)
        gto2 = gto(0.154329, -nucleus, 3.425251, 2, 0, 0)

        t1a = integrator.nuclear_gto_deriv_op(gto1, gto1, nucleus, 0)
        t1b = integrator.nuclear_gto_deriv_bf(gto1, gto1, nucleus, 0)

        t2a = integrator.nuclear_gto_deriv_op(gto2, gto2, nucleus, 0)
        t2b = integrator.nuclear_gto_deriv_bf(gto2, gto2, nucleus, 0)

        # also calculate this integral using finite difference
        fd_01 = calculate_fx_op_finite_difference(gto1, nucleus)
        fd_02a = calculate_fx_op_finite_difference(gto2, nucleus)
        fd_02b = calculate_fx_bf_finite_difference(gto2, nucleus)

        # testing
        np.testing.assert_almost_equal(t1a, 0.0, 4)
        np.testing.assert_almost_equal(t1b, 0.0, 4)

        np.testing.assert_almost_equal(-2.0 * t2b, fd_02b, 4)
        np.testing.assert_almost_equal(t2a, fd_02a, 4)
Beispiel #23
0
    def testDerivH2O(self):
        """
        Test Derivatives of dihydrogen
        """

        # build integrator object
        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule()
        mol.add_atom('O', 0.0, 0.0, 0.0)
        mol.add_atom('H', 0.7570, 0.5860, 0.0)
        mol.add_atom('H', -0.7570, 0.5860, 0.0)
        cgfs, nuclei = mol.build_basis('sto3g')

        # calculate derivative towards H1 in the x-direction
        fx1 = integrator.kinetic_deriv(cgfs[2], cgfs[2], nuclei[1][0], 0)  # px
        fx2 = integrator.kinetic_deriv(cgfs[2], cgfs[3], nuclei[1][0], 0)  # py

        ans1 = calculate_force_finite_difference(mol, 1, 2, 2, 0)
        ans2 = calculate_force_finite_difference(mol, 1, 3, 3, 0)

        # assert that the kinetic of two CGFs that spawn from
        # the same nucleus will not change in energy due to a
        # change of the nucleus coordinates
        np.testing.assert_almost_equal(fx1, ans1, 4)
        np.testing.assert_almost_equal(fx2, ans2, 4)

        # assert that the cross-terms will change
        fx3 = integrator.kinetic_deriv(cgfs[2], cgfs[5], nuclei[1][0], 0)
        fx4 = integrator.kinetic_deriv(cgfs[2], cgfs[5], nuclei[1][0], 0)

        ans3 = calculate_force_finite_difference(mol, 1, 2, 5, 0)
        ans4 = calculate_force_finite_difference(mol, 1, 2, 5, 0)

        np.testing.assert_almost_equal(fx3, ans3, 4)
        self.assertFalse(fx3 == 0.0)
        np.testing.assert_almost_equal(fx4, ans4, 4)
        self.assertFalse(fx4 == 0.0)
Beispiel #24
0
    def test_integrals_h2(self):
        """
        Test automatic integral evaluation for hydrogen molecule
        """

        # construct integrator object
        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule()
        mol.add_atom('H', 0.0, 0.0, 0.0)
        mol.add_atom('H', 0.0, 0.0, 1.4)
        cgfs, nuclei = mol.build_basis('sto3g')

        # evaluate all integrals
        ncpu = multiprocessing.cpu_count()
        S, T, V, teint = integrator.build_integrals(cgfs,
                                                    nuclei,
                                                    npar=ncpu,
                                                    verbose=False)

        # overlap integrals
        S_result = np.matrix([[1.0, 0.65931845], [0.65931845, 1.0]])

        # kinetic integrals
        T_result = np.matrix([[0.7600315809249878, 0.2364544570446014],
                              [0.2364544570446014, 0.7600315809249878]])

        # nuclear attraction integrals
        V1_result = np.matrix([[-1.2266135215759277, -0.5974172949790955],
                               [-0.5974172949790955, -0.6538270711898804]])
        V2_result = np.matrix([[-0.6538270711898804, -0.5974172949790955],
                               [-0.5974172949790955, -1.2266135215759277]])
        V_result = V1_result + V2_result

        # two-electron integrals
        T1111 = 0.7746056914329529
        T1122 = 0.5696758031845093
        T1112 = 0.4441076219081878
        T1212 = 0.2970285713672638

        # perform tests
        np.testing.assert_almost_equal(S, S_result, 4)
        np.testing.assert_almost_equal(T, T_result, 4)
        np.testing.assert_almost_equal(V, V_result, 4)
        np.testing.assert_almost_equal(teint[integrator.teindex(0, 0, 0, 0)],
                                       T1111, 4)
        np.testing.assert_almost_equal(teint[integrator.teindex(0, 0, 1, 1)],
                                       T1122, 4)
        np.testing.assert_almost_equal(teint[integrator.teindex(0, 0, 0, 1)],
                                       T1112, 4)
        np.testing.assert_almost_equal(teint[integrator.teindex(0, 1, 0, 1)],
                                       T1212, 4)
Beispiel #25
0
    def test_two_electron_indices(self):
        """
        Test unique two-electron indices
        """
        integrator = PyQInt()

        np.testing.assert_almost_equal(integrator.teindex(1, 1, 2, 1),
                                       integrator.teindex(1, 1, 1, 2), 4)
        np.testing.assert_almost_equal(integrator.teindex(1, 1, 2, 1),
                                       integrator.teindex(2, 1, 1, 1), 4)
        np.testing.assert_almost_equal(integrator.teindex(1, 2, 1, 1),
                                       integrator.teindex(2, 1, 1, 1), 4)
        np.testing.assert_almost_equal(integrator.teindex(1, 1, 1, 2),
                                       integrator.teindex(1, 1, 2, 1), 4)
        self.assertNotEqual(integrator.teindex(1, 1, 1, 1),
                            integrator.teindex(1, 1, 2, 1))
        self.assertNotEqual(integrator.teindex(1, 1, 2, 1),
                            integrator.teindex(1, 1, 2, 2))
Beispiel #26
0
    def test_strings(self):
        """
        Test automatic integral evaluation for hydrogen molecule
        """

        # construct integrator object
        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule('H2')
        mol.add_atom('H', 0.0, 0.0, 0.0)
        mol.add_atom('H', 0.0, 0.0, 1.4)
        cgfs, nuclei = mol.build_basis('sto3g')

        ans = "CGF; R=(0.000000,0.000000,0.000000)\n"
        ans += " 01 | GTO : c=0.154329, alpha=3.425251, l=0, m=0, n=0, R=(0.000000,0.000000,0.000000)\n"
        ans += " 02 | GTO : c=0.535328, alpha=0.623914, l=0, m=0, n=0, R=(0.000000,0.000000,0.000000)\n"
        ans += " 03 | GTO : c=0.444635, alpha=0.168855, l=0, m=0, n=0, R=(0.000000,0.000000,0.000000)\n"
        self.assertEqual(str(cgfs[0]), ans)

        ans = "Molecule: H2\n"
        ans += " H (0.000000,0.000000,0.000000)\n"
        ans += " H (0.000000,0.000000,1.400000)\n"
        self.assertEqual(str(mol), ans)
Beispiel #27
0
    def testDerivH2O(self):
        """
        Test Derivatives of water
        """

        # build integrator object
        integrator = PyQInt()

        # build hydrogen molecule
        mol = Molecule()
        mol.add_atom('O', 0.0, 0.0, 0.0)
        mol.add_atom('H', 0.7570, 0.5860, 0.0)
        mol.add_atom('H', -0.7570, 0.5860, 0.0)
        cgfs, nuclei = mol.build_basis('sto3g')

        # calculate derivative of 2s AO on oxygen towards H1 in the x-direction
        fx1 = integrator.repulsion_deriv(cgfs[2], cgfs[2], cgfs[2], cgfs[2],
                                         nuclei[1][0], 0)  # px
        fx2 = integrator.repulsion_deriv(cgfs[2], cgfs[3], cgfs[3], cgfs[3],
                                         nuclei[1][0], 0)  # py

        ans1 = calculate_force_finite_difference(mol, 1, 2, 2, 2, 2, 0)
        ans2 = calculate_force_finite_difference(mol, 1, 3, 3, 3, 3, 0)

        # assert that the repulsion of two CGFs that spawn from
        # the same nucleus will not change in energy due to a
        # change of the nucleus coordinates
        np.testing.assert_almost_equal(fx1, ans1, 4)
        np.testing.assert_almost_equal(fx2, ans2, 4)

        # assert that the cross-terms will change
        fx3 = integrator.repulsion_deriv(cgfs[3], cgfs[3], cgfs[5], cgfs[5],
                                         nuclei[0][0], 0)
        fx4 = integrator.repulsion_deriv(cgfs[3], cgfs[3], cgfs[5], cgfs[5],
                                         nuclei[1][0], 0)
        fx5 = integrator.repulsion_deriv(cgfs[5], cgfs[3], cgfs[5], cgfs[3],
                                         nuclei[0][0], 0)
        fx6 = integrator.repulsion_deriv(cgfs[3], cgfs[5], cgfs[3], cgfs[5],
                                         nuclei[1][0], 0)

        # mol | nuc_id | cgf_id1 | cgf_id2 | cgf_id3 | cgf_id4 | coord
        ans3 = calculate_force_finite_difference(mol, 0, 3, 3, 5, 5, 0)
        ans4 = calculate_force_finite_difference(mol, 1, 3, 3, 5, 5, 0)
        ans5 = calculate_force_finite_difference(mol, 0, 5, 3, 5, 3, 0)
        ans6 = calculate_force_finite_difference(mol, 1, 3, 5, 3, 5, 0)

        # assert that these are non-trivial tests
        self.assertFalse(ans3 == 0.0)
        self.assertFalse(ans4 == 0.0)
        self.assertFalse(ans5 == 0.0)
        self.assertFalse(ans6 == 0.0)

        np.testing.assert_almost_equal(fx3, ans3, 10)
        np.testing.assert_almost_equal(fx4, ans4, 10)
        np.testing.assert_almost_equal(fx5, ans5, 10)
        np.testing.assert_almost_equal(fx6, ans6, 10)

        # assert that the cross-terms will change
        fx7 = integrator.repulsion_deriv(cgfs[2], cgfs[3], cgfs[5], cgfs[6],
                                         nuclei[0][0], 0)
        fx8 = integrator.repulsion_deriv(cgfs[2], cgfs[3], cgfs[5], cgfs[6],
                                         nuclei[1][0], 1)
        fx9 = integrator.repulsion_deriv(cgfs[2], cgfs[3], cgfs[5], cgfs[6],
                                         nuclei[2][0], 1)

        # get answers
        ans7 = calculate_force_finite_difference(mol, 0, 2, 3, 5, 6, 0)
        ans8 = calculate_force_finite_difference(mol, 1, 2, 3, 5, 6, 1)
        ans9 = calculate_force_finite_difference(mol, 2, 2, 3, 5, 6, 1)

        # assert that these are non-trivial tests
        self.assertFalse(ans7 == 0.0)
        self.assertFalse(ans8 == 0.0)
        self.assertFalse(ans9 == 0.0)

        np.testing.assert_almost_equal(fx7, ans7, 10)
        np.testing.assert_almost_equal(fx8, ans8, 10)
        np.testing.assert_almost_equal(fx9, ans9, 10)