def pbc(rnew, rold):
    """
    Periodic boundary conditions for an msd calculation

    Args:
        rnew (:py:attr:`float`, optional): New atomic position
        rold (:py:attr:`float`, optional): Previous atomic position

    Returns:
        cross (:py:attr:`bool`, optional): Has the atom cross a PBC?
        rnew (:py:attr:`float`, optional): New position
    """
    shift = abs(rold - rnew)
    shift = round(shift, 0)
    shift = int(shift)
    cross = False
    if shift < 2:
        if rnew - rold > 0.5:
            rnew = rnew - 1.0
            cross = True
        elif -(rnew - rold) > 0.5:
            rnew = rnew + 1.0
            cross = True
    else:
        if rnew - rold > 0.5:
            rnew = rnew - shift
            cross = True
        elif -(rnew - rold) > 0.5:
            rnew = rnew + shift 
            cross = True
    return cross, rnew