Beispiel #1
0
def binomial2(n, k):
    """Returns C(n,k) = n!/(k!(n-k)!)."""

    assert n >= 0 and k >= 0 and n >= k, \
        'n and k should be non-negative integers.'

    c = float(fac(n)) / (float(fac(k)) * float(fac(n - k)))
    return c
Beispiel #2
0
    def __init__(self, neighborlist, Gs, nmax, cutoff, fortran):
        self.globals = Parameters({'cutoff': cutoff, 'Gs': Gs, 'nmax': nmax})
        self.keyed = Parameters({'neighborlist': neighborlist})
        self.parallel_command = 'calculate_fingerprint_primes'
        self.fortran = fortran

        try:  # for scipy v <= 0.90
            from scipy import factorial as fac
        except ImportError:
            try:  # for scipy v >= 0.10
                from scipy.misc import factorial as fac
            except ImportError:  # for newer version of scipy
                from scipy.special import factorial as fac

        self.factorial = [fac(0.5 * _) for _ in range(4 * nmax + 3)]
Beispiel #3
0
def calculate_Z2(n, l, m, x, y, z):
    """
    The second implementation of Z_{nl}^{m}(x, y, z).
    """

    value1 = 0.
    k1 = (n - l) / 2
    for nu in range(k1 + 1):
        value1 += (x**2. + y**2. + z**2.)**(nu + 0.5 * l) * calculate_q(
            nu, k1, l)

    term1 = sqrt((2. * l + 1.) * float(fac(l + m)) * float(fac(l - m))) / \
        float(fac(l))
    term2 = 2.**(-m)
    term3 = (1j * x - y)**m
    term4 = z**(l - m)

    k2 = int((l - m) / 2.)
    value2 = 0.
    for mu in range(k2 + 1):
        term5 = binomial2(l, mu)
        term6 = binomial2(l - mu, m + mu)
        term7 = ((-1.) ** mu) * \
            ((x ** 2. + y ** 2.) ** mu) / ((4 * (z ** 2.)) ** mu)
        value2 += term5 * term6 * term7

    value2 *= term1 * term2 * term3 * term4
    value2 *= (1j)**m

    value = value1 * value2

    value = value / (x**2. + y**2. + z**2.)**(0.5 * l)

    value *= sqrt(3. / (4. * np.pi))

    return value
    def __init__(self, neighborlist, Gs, nmax, cutoff, cutofffn, fortran):
        self.globals = Parameters({'cutoff': cutoff,
                                   'cutofffn': cutofffn,
                                   'Gs': Gs,
                                   'nmax': nmax})
        self.keyed = Parameters({'neighborlist': neighborlist})
        self.parallel_command = 'calculate_fingerprint_prime'
        self.fortran = fortran

        try:  # for scipy v <= 0.90
            from scipy import factorial as fac
        except ImportError:
            try:  # for scipy v >= 0.10
                from scipy.misc import factorial as fac
            except ImportError:  # for newer version of scipy
                from scipy.special import factorial as fac

        self.factorial = [fac(0.5 * _) for _ in xrange(4 * nmax + 3)]
Beispiel #5
0
    def __init__(
        self,
        cutoff=6.5,
        Gs=None,
        nmax=1,
        fingerprints_tag=1,
    ):

        self.cutoff = cutoff
        self.Gs = Gs
        self.nmax = nmax
        self.fingerprints_tag = fingerprints_tag

        self.no_of_element_fingerprints = {}
        if Gs is not None:
            for element in Gs.keys():
                no_of_element_fps = 0
                if isinstance(nmax, dict):

                    for n in range(nmax[element] + 1):
                        for l in range(n + 1):
                            if (n - l) % 2 == 0:
                                no_of_element_fps += 1
                else:
                    for n in range(nmax + 1):
                        for l in range(n + 1):
                            if (n - l) % 2 == 0:
                                no_of_element_fps += 1

                self.no_of_element_fingerprints[element] = no_of_element_fps

        self.factorial = []
        for _ in range(4 * nmax + 3):
            self.factorial += [float(fac(0.5 * _))]

        # Checking if the functional forms of fingerprints in the train set
        # is the same as those of the current version of the code:
        if self.fingerprints_tag != 1:
            raise FingerprintsError('Functional form of fingerprints has been '
                                    'changed. Re-train you train images set, '
                                    'and use the new variables.')