'Create a new ``TIDS`` object from ``components`` and ``indices``
``components``  ``TensorHead`` objects representing the components
of the tensor expression.
``indices``     ``TensorIndex`` objects, the indices. Contractions are
detected upon construction.'

@staticmethod
def from_components_and_indices(components, indices):

    tids = None
    cur_pos = 0
    for i in components:
        tids_sing = TIDS([i], *TIDS.free_dum_from_indices(*indices[cur_pos:(cur_pos + i.rank)]))
        if (tids is None):
            tids = tids_sing
        else:
            tids *= tids_sing
        cur_pos += i.rank
    if (tids is None):
        tids = TIDS([], [], [])
    tids.free.sort(key=(lambda x: x[0].name))
    tids.dum.sort()
    return tids
