def pick_window(min_dists, cutoff=0.45, cutoff_min=0.0, duration=20.0,
                padding=1.0, dt=0.05):
    """Find subtrajectories that seem to be attached.

    Parameters
    ----------
    min_dists : np.array
        minimum distance at each time
    cutoff : float
        distance to count as a contact (nm)
    duration : float
        duration to stay below cutoff to be considered stable (ns)
    padding : float
        time (ns) to skip analysis on either side of trajectory
    dt : float
        time (ns) between frames
    """
    contacted = [cutoff_min < d < cutoff for d in min_dists]
    ranges = []
    start = None
    for (i, val) in enumerate(contacted):
        if val and start is None:
            start = i
        elif not val and start is not None:
            ranges.append((start, i))
            start = None
    if start is not None:
        ranges.append((start, len(contacted)))

    duration_frames = int(duration / dt)
    padding_frames = int(padding / dt)
    return [(r[0]+padding_frames, r[1]-padding_frames)
            for r in ranges if r[1] - r[0] > duration_frames]