def os_recursive(self, r, m, g1, g2, g3, g4, g5, g6, g7, g8):
        out3 = out4 = out5 = out6 = out7 = out8 = 0

        a_1 = g1.exponent
        a_2 = g2.exponent
        a_3 = g3.exponent
        a_4 = g4.exponent
        a_5 = a_1 + a_2
        a_6 = a_3 + a_4

        r_1 = g1.coordinates
        r_2 = g2.coordinates
        r_5 = gaussian_product_coordinate(a_1, r_1, a_2, r_2)

        out1 = (r_5[r] - r_1[r]) * self.os_begin(m, g1, g2, g3, g4)
        out2 = (self.r_7[r] - r_5[r]) * self.os_begin((m+1), g1, g2, g3, g4)
        if g5.integral_exponents[r] >= 0:
            out3 = self.os_count(g1.integral_exponents[r]) * (1 / (2 * a_5)) * self.os_begin(m, g5, g2, g3, g4)
            out4 = self.os_count(g1.integral_exponents[r]) * (self.a_7 / (2 * a_5**2)) * self.os_begin((m+1), g5, g2, g3, g4)
        if g6.integral_exponents[r] >= 0:
            out5 = self.os_count(g2.integral_exponents[r]) * (1 / (2 * a_5)) * self.os_begin(m, g1, g6, g3, g4)
            out6 = self.os_count(g2.integral_exponents[r]) * (self.a_7 / (2 * a_5**2)) * self.os_begin((m+1), g1, g6, g3, g4)
        if g7.integral_exponents[r] >= 0:
            out7 = self.os_count(g3.integral_exponents[r]) * (1 / (2*(a_5 + a_6))) * self.os_begin((m+1), g1, g2, g7, g4)
        if g8.integral_exponents[r] >= 0:
            out8 = self.os_count(g4.integral_exponents[r]) * (1 / (2*(a_5 + a_6))) * self.os_begin((m+1), g1, g2, g3, g8)

        return out1 + out2 + out3 - out4 + out5 - out6 + out7 + out8
    def integrate(self, g1, g2, g3, g4):
        l_1 = g1.integral_exponents
        l_2 = g2.integral_exponents
        l_3 = g3.integral_exponents
        l_4 = g4.integral_exponents
        l_total = sum(l_1) + sum(l_2) + sum(l_3) + sum(l_4)

        a_1 = g1.exponent
        a_2 = g2.exponent
        a_3 = g3.exponent
        a_4 = g4.exponent
        a_5 = a_1 + a_2
        a_6 = a_3 + a_4
        self.a_7 = (a_5 * a_6) / (a_5 + a_6)

        r_1 = g1.coordinates
        r_2 = g2.coordinates
        r_3 = g3.coordinates
        r_4 = g4.coordinates
        r_5 = gaussian_product_coordinate(a_1, r_1, a_2, r_2)
        r_6 = gaussian_product_coordinate(a_3, r_3, a_4, r_4)
        self.r_7 = gaussian_product_coordinate(a_5, r_5, a_6, r_6)

        r_12 = coordinate_distance(r_1, r_2)
        r_34 = coordinate_distance(r_3, r_4)
        r_56 = coordinate_distance(r_5, r_6)

        boys_x = (a_5 * a_6 * r_56**2) / (a_5 + a_6)
        boys_out1 = (2 * pi**(5/2)) / (a_5 * a_6 * sqrt(a_5 + a_6))
        boys_out2 = exp(((- a_1 * a_2 * r_12**2) / a_5) - ((a_3 * a_4 * r_34**2) / a_6))
        boys_out3 = boys_function(l_total, boys_x)

        self.end_dict = {l_total: boys_out1 * boys_out2 * boys_out3}

        while l_total >= 1:
            boys_out3 = boys_function_recursion(l_total, boys_x, boys_out3)
            l_total -= 1
            self.end_dict[l_total] = boys_out1 * boys_out2 * boys_out3

        if sum(l_1) >= sum(l_2) and sum(l_3) >= sum(l_4):
            return self.hgp_begin_horizontal(g1, g2, g3, g4)
        elif sum(l_1) >= sum(l_2):
            return self.hgp_begin_horizontal(g1, g2, g4, g3)
        elif sum(l_3) >= sum(l_4):
            return self.hgp_begin_horizontal(g2, g1, g3, g4)
        else:
            return self.hgp_begin_horizontal(g2, g1, g4, g3)
def orbital_overlap(gaussian_1, gaussian_2):
    a_1 = gaussian_1.exponent
    a_2 = gaussian_2.exponent
    l_1 = gaussian_1.integral_exponents
    l_2 = gaussian_2.integral_exponents

    r_a = gaussian_1.coordinates
    r_b = gaussian_2.coordinates
    r_ab = coordinate_distance(r_a, r_b)

    r_p = gaussian_product_coordinate(a_1, r_a, a_2, r_b)
    r_p_a = vector_minus(r_p, r_a)
    r_p_b = vector_minus(r_p, r_b)

    g = a_1 + a_2

    s_x = s_function(l_1[0], l_2[0], r_p_a[0], r_p_b[0], g)
    s_y = s_function(l_1[1], l_2[1], r_p_a[1], r_p_b[1], g)
    s_z = s_function(l_1[2], l_2[2], r_p_a[2], r_p_b[2], g)
    s_ij = (pi / g)**(3/2) * exp(- a_1 * a_2 * r_ab**2 / g) * s_x * s_y * s_z
    return s_ij
def nuclear_attraction(gaussian_1, gaussian_2, nuclei):
    a_1 = gaussian_1.exponent
    a_2 = gaussian_2.exponent
    l_1 = gaussian_1.integral_exponents
    l_2 = gaussian_2.integral_exponents

    r_a = gaussian_1.coordinates
    r_b = gaussian_2.coordinates
    r_c = nuclei.coordinates
    r_p = gaussian_product_coordinate(a_1, r_a, a_2, r_b)

    r_ab = coordinate_distance(r_a, r_b)
    r_pc = coordinate_distance(r_p, r_c)

    r_p_a = vector_minus(r_p, r_a)
    r_p_b = vector_minus(r_p, r_b)
    r_p_c = vector_minus(r_p, r_c)

    g = a_1 + a_2

    ans = 0
    for l in range(l_1[0] + l_2[0] + 1):
        for r in range(int(l/2) + 1):
            for i in range(int((l - 2*r) / 2) + 1):
                out1 = a_function(l, r, i, l_1[0], l_2[0], r_p_a[0], r_p_b[0], r_p_c[0], g)
                for m in range(l_1[1] + l_2[1] + 1):
                    for s in range(int(m/2) + 1):
                        for j in range(int((m - 2*s) / 2) + 1):
                            out2 = a_function(m, s, j, l_1[1], l_2[1], r_p_a[1], r_p_b[1], r_p_c[1], g)
                            for n in range(l_1[2] + l_2[2] + 1):
                                for t in range(int(n/2) + 1):
                                    for k in range(int((n - 2*t) / 2) + 1):
                                        out3 = a_function(n, t, k, l_1[2], l_2[2], r_p_a[2], r_p_b[2], r_p_c[2], g)
                                        v = (l + m + n) - 2*(r + s + t) - (i + j + k)
                                        out4 = boys_function(v, g * r_pc**2)
                                        out5 = out1 * out2 * out3 * out4
                                        ans += out5
    ans *= ((2 * pi) / g) * exp(- (a_1 * a_2 * r_ab**2) / g)
    return ans
    def vertical_recursion(self, r, m, g1, g2, g3, g4, g5, g6):
        out3 = out4 = out5 = 0

        a_1 = g1.exponent
        a_2 = g2.exponent
        a_3 = g3.exponent
        a_4 = g4.exponent
        a_5 = a_1 + a_2
        a_6 = a_3 + a_4

        r_1 = g1.coordinates
        r_2 = g2.coordinates
        r_5 = gaussian_product_coordinate(a_1, r_1, a_2, r_2)

        out1 = (r_5[r] - r_1[r]) * self.hgp_begin_vertical(m, g1, g2, g3, g4)
        out2 = (self.r_7[r] - r_5[r]) * self.hgp_begin_vertical((m+1), g1, g2, g3, g4)
        if g5.integral_exponents[r] >= 0:
            out3 = self.os_count(g1.integral_exponents[r]) * (1 / (2 * a_5)) * self.hgp_begin_vertical(m, g5, g2, g3, g4)
            out4 = self.os_count(g1.integral_exponents[r]) * (self.a_7 / (2 * a_5**2)) * self.hgp_begin_vertical((m+1), g5, g2, g3, g4)
        if g6.integral_exponents[r] >= 0:
            out5 = self.os_count(g3.integral_exponents[r]) * (1 / (2*(a_5 + a_6))) * self.hgp_begin_vertical((m+1), g1, g2, g6, g4)

        return out1 + out2 + out3 - out4 + out5