def pib(coords, box):
    """
    Pack coordinates into periodic box.

    Args:
        coords: (N,3) numpy array of atom coordinates.
        box: (3,3) numpy array of box parameters.

    Returns:
        coords: (N,3) numpy array of packed coordinates (overwrites input).
    """
    import numpy as np
    import numpy as np
    assert len(coords.shape) == 2
    assert coords.shape[1] == 3
    assert box.shape == (3, 3)
    boxinv = np.zeros(3)
    boxinv[0] = 1.0 / box[0, 0]
    boxinv[1] = 1.0 / box[1, 1]
    boxinv[2] = 1.0 / box[2, 2]
    for xyz in coords:
        s = np.floor(xyz[2] * boxinv[2])
        xyz[2] -= s * box[2, 2]
        xyz[1] -= s * box[2, 1]
        xyz[0] -= s * box[2, 0]
        s = np.floor(xyz[1] * boxinv[1])
        xyz[1] -= s * box[1, 1]
        xyz[0] -= s * box[1, 0]
        s = np.floor(xyz[0] * boxinv[0])
        xyz[0] -= s * box[0, 0]
    return coords
