Attempts to fit a heptad repeat to a set of Crick angles.

    Parameters
    ----------
    crangles: [float]
        A list of average Crick angles for the coiled coil.

    Returns
    -------
    fit_data: [(float, float, float)]
        Sorted list of fits for each heptad position.

def fit_heptad_register(crangles):
    """Attempts to fit a heptad repeat to a set of Crick angles.

    Parameters
    ----------
    crangles: [float]
        A list of average Crick angles for the coiled coil.

    Returns
    -------
    fit_data: [(float, float, float)]
        Sorted list of fits for each heptad position.
    """
    crangles = [x if x > 0 else 360 + x for x in crangles]
    hept_p = [x * (360.0 / 7.0) + ((360.0 / 7.0) / 2.0) for x in range(7)]
    ideal_crangs = [
        hept_p[0],
        hept_p[2],
        hept_p[4],
        hept_p[6],
        hept_p[1],
        hept_p[3],
        hept_p[5]
    ]
    full_hept = len(crangles) // 7
    ideal_crang_list = ideal_crangs * (full_hept + 2)  # This is dirty, too long but trimmed with zip
    fitting = []
    for i in range(7):
        ang_pairs = zip(crangles, ideal_crang_list[i:])
        ang_diffs = [abs(y - x) for x, y in ang_pairs]
        fitting.append((i, numpy.mean(ang_diffs), numpy.std(ang_diffs)))
    return sorted(fitting, key=lambda x: x[1])