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