def periodic_distance(a, b, periodic):
    '''
    Periodic distance between two arrays. Periodic is a 3
    dimensional array containing the 3 box sizes.

    '''
    a = np.array(a)
    b = np.array(b)
    periodic = np.array(periodic)

    delta = np.abs(a - b)
    delta = np.where(delta > 0.5 * periodic, periodic - delta, delta)
    return np.sqrt((delta ** 2).sum(axis=-1))
Periodic distance between two arrays. Periodic is a 3
    dimensional array containing the 3 box sizes.