def latticeWrapIdx(index, lattice_shape):
    """
        Returns periodic lattice index for a given iterable index
        :param index: List of cells
        :param lattice_shape: Oxygen distribution in lattice array shape
        :return: Modified indexes
    """
    if not hasattr(index, '__iter__'): return index  # handle integer slices
    if len(index) != len(lattice_shape): return index  # must reference a scalar
    if any(type(i) == slice for i in index): return index  # slices not supported
    if len(index) == len(lattice_shape):  # periodic indexing of scalars
        mod_index = tuple(((i % s + s) % s for i, s in zip(index, lattice_shape)))
        return mod_index
    raise ValueError('Unexpected index: {}'.format(index))