def groupms_byenergy(microstates, ticks):
    """
    This function takes in a list of microstates and a list of energy numbers (N values), divide the microstates into N
    bands by using the energy number as lower boundaries. The list of energy will be sorted from small to large.
    """
    N = len(ticks)
    ticks.sort()
    ticks.append(1.0e100)    # add a big number as the rightest-most boundary
    resulted_bands = [[] for i in range(N)]

    for ms in microstates:
        it = -1
        for itick in range(N):
            if ticks[itick] <= ms.E < ticks[itick+1]:
                it = itick
                break
        if it >= 0:
            resulted_bands[it].append(ms)

    return resulted_bands