Example #1
0
def A_func(k, p):
    # Initialise A at zero
    A = 0
    # Sum over mu - upper limit is k+2 so the expression is evaluated for mu=k+1
    for mu in range(1, k + 2):
        A += bang(k) / ((p**mu) * bang(k - mu + 1))
    # Now multiply by the exponential term
    A *= np.exp(-p)
    return A
Example #2
0
def hybrid_permutation(y, z, max_comparision=100000):
    n = y.size + z.size
    r = y.size

    exact_comparisions = bang(n) / bang(r) / bang(n-r)

    if exact_comparisions > max_comparision:
        logging.warn('Using approximate test with %d samples' % max_comparision)
        return permutation(y, z, max_comparision)
    else:
        return exact_permutation(y, z)
Example #3
0
def B_func(k, pt):
    # Initialise B at zero
    B = 0
    # B(0) can be evaluated much more straightforwardly (see Mulliken or Stewart)
    # so include a check here to avoid unnecessary calculations
    if pt == 0:
        if k % 2 == 1:  # k odd
            B = 0
        elif k % 2 == 0:  # k even
            B = 2 / (k + 1)
    else:
        # Calculate each of the sums seperately for ease of understanding, then
        # multiply them by their exponential factors, then subtract them from B

        # Label the two sums B_1 and B_2 - calculate them both in the same loop
        # since the sums run over the same indices

        B_1 = 0
        B_2 = 0
        for mu in range(1, k + 2):
            B_1 += bang(k) / ((pt**mu) * bang(k - mu + 1))
            B_2 += (bang(k) * (-1)**(k - mu)) / ((pt**mu) * bang(k - mu + 1))
        B -= (B_1 * np.exp(-pt) + B_2 * np.exp(pt))
    return B
Example #4
0
def calc_prefactor(atoms, positions, basis, a, b):
    # Extract orbital properties from the basis set
    zeta_a = float(basis[a, -2])
    zeta_b = float(basis[b, -2])
    n_a = float(basis[a, 3])
    n_b = float(basis[b, 3])
    l_a = float(basis[a, 4])
    l_b = float(basis[b, 4])

    # Use atoms dictionary to match orbitals to atoms,
    # then get their coordinates from the list of positions
    # to calculate the bond length
    # label = string, index = integer

    atom_label_a = basis[a, 1]
    atom_label_b = basis[b, 1]
    atom_index_a = atoms[atom_label_a]
    atom_index_b = atoms[atom_label_b]
    R_ab = bond_length(positions, atom_index_a, atom_index_b)
    # bang = factorial
    prefactor = 0.5 * (zeta_a ** (n_a + 1/2) * (zeta_b ** (n_b + 1/2))) * \
                ((((2*l_a + 1) * (2*l_b + 1)) / (bang(2*n_a) * bang(2*n_b))) ** 0.5) \
                * R_ab ** (n_a + n_b + 1)
    return prefactor
Example #5
0
def calc_radial_overlap(atoms, positions, basis, a, b, m):
    # Extract orbital properties from the basis set
    zeta_a = float(basis[a, -2])
    zeta_b = float(basis[b, -2])
    na = int(basis[a, 3])
    nb = int(basis[b, 3])
    la = int(basis[a, 4])
    lb = int(basis[b, 4])

    # Use atoms dictionary to match orbitals to atoms,
    # then get their coordinates from the list of positions
    # to calculate the bond length
    # label = string, index = integer

    atom_label_a = basis[a, 1]
    atom_label_b = basis[b, 1]
    atom_index_a = atoms[atom_label_a]
    atom_index_b = atoms[atom_label_b]
    R_ab = bond_length(positions, atom_index_a, atom_index_b)

    # Define p and t

    p = (R_ab * (zeta_a + zeta_b)) / 2
    t = (zeta_a - zeta_b) / (zeta_a + zeta_b)

    # Initialise overlap at 0
    radial_overlap = 0
    # Write each sum as a for loop
    for ja in range(int((la - m) / 2) + 1):
        for jb in range(int((lb - m) / 2) + 1):
            for ka in range(m + 1):
                for kb in range(m + 1):
                    for Pa in range(na - la - 2 * ja + 1):
                        for Pb in range(nb - lb - 2 * jb + 1):
                            for qa in range(la - m - 2 * ja + 1):
                                for qb in range(lb - m - 2 * jb + 1):
                                    # Write each term on a different line and
                                    # multiply them all together
                                    radial_overlap += (
                                        get_C_lmj(la, m, ja) *
                                        get_C_lmj(lb, m, jb) *
                                        ((bang(lb - m - 2 * jb)) /
                                         (bang(lb - m - 2 * jb - qb) *
                                          bang(qb))) *
                                        ((bang(la - m - 2 * ja)) /
                                         (bang(la - m - 2 * ja - qa) *
                                          bang(qa))) *
                                        ((bang(na - la + 2 * ja)) /
                                         (bang(na - la + 2 * ja - Pa) *
                                          bang(Pa))) *
                                        ((bang(nb - lb + 2 * jb)) /
                                         (bang(nb - lb + 2 * jb - Pb) *
                                          bang(Pb))) * ((bang(m))**2) /
                                        (bang(m - ka) * bang(ka) *
                                         bang(m - kb) * bang(kb)) *
                                        (-1)**(ka + kb + m + Pb + qb) *
                                        B_func(2 * ka + Pa + Pb + qa + qb,
                                               p * t) *
                                        A_func(
                                            2 * kb + na - la + 2 * ja + nb - lb
                                            + 2 * jb - Pa - Pb + qa + qb, p))
    radial_overlap *= calc_prefactor(atoms, positions, basis, a, b)
    return radial_overlap
Example #6
0
def ncr(n,r):
    return bang(n)/(bang(r)*bang(n-r))
def stirling_num_of_2nd_kind(n,k):
  #'''stirling_num_of_2nd_kind(number_of_elements, number_of_sets)'''
  from math import factorial as bang
  from scipy.misc import comb
  return (1./bang(k))*np.sum(map(lambda j: (-1)**(k-j)*comb(k,j,exact=True)*j**n, range(k+1)))