def make_primitive(cas_coords, window_length=3):
    """Calculates running average of cas_coords with a fixed averaging window_length.

    Parameters
    ----------
    cas_coords : list(numpy.array or float or tuple)
        Each element of the list must have length 3.
    window_length : int, optional
        The number of coordinate sets to average each time.

    Returns
    -------
    s_primitive : list(numpy.array)
        Each array has length 3.

    Raises
    ------
    ValueError
        If the length of cas_coords is smaller than the window_length.
    """

    if len(cas_coords) >= window_length:
        primitive = []
        count = 0
        for _ in cas_coords[:-(window_length - 1)]:
            group = cas_coords[count:count + window_length]
            average_x = sum([x[0] for x in group]) / window_length
            average_y = sum([y[1] for y in group]) / window_length
            average_z = sum([z[2] for z in group]) / window_length
            primitive.append(numpy.array([average_x, average_y, average_z]))
            count += 1
    else:
        raise ValueError(
            'A primitive cannot be generated for {0} atoms using a (too large) '
            'averaging window_length of {1}.'.format(
                len(cas_coords), window_length))
    return primitive
def make_primitive ( cas_coords , window_length = 3 ) : if len ( cas_coords ) >= window_length : primitive = [ ] count = 0 for _ in cas_coords [ : - ( window_length - 1 ) ] : group = cas_coords [ count : count + window_length ] average_x = sum ( [ x [ 0 ] for x in group ] ) / window_length average_y = sum ( [ y [ 1 ] for y in group ] ) / window_length average_z = sum ( [ z [ 2 ] for z in group ] ) / window_length primitive . append ( numpy . array ( [ average_x , average_y , average_z ] ) ) count += 1 else : raise ValueError ( 'A primitive cannot be generated for {0} atoms using a (too large) ' 'averaging window_length of {1}.' . format ( len ( cas_coords ) , window_length ) ) return primitive
Calculates running average of cas_coords with a fixed averaging window_length.

    Parameters
    ----------
    cas_coords : list(numpy.array or float or tuple)
        Each element of the list must have length 3.
    window_length : int, optional
        The number of coordinate sets to average each time.

    Returns
    -------
    s_primitive : list(numpy.array)
        Each array has length 3.

    Raises
    ------
    ValueError
        If the length of cas_coords is smaller than the window_length.