'Returns a ``_IndexStructure`` instance corresponding to the permutation ``g``
``g``  permutation corresponding to the tensor in the representation
used in canonicalization
``is_canon_bp``   if True, then ``g`` is the permutation
corresponding to the canonical form of the tensor'

def perm2tensor(self, g, is_canon_bp=False):

    sorted_free = [i[0] for i in self._get_sorted_free_indices_for_canon()]
    lex_index_types = self._get_lexicographically_sorted_index_types()
    lex_indices = self._get_lexicographically_sorted_indices()
    nfree = len(sorted_free)
    rank = self._ext_rank
    dum = [([None] * 2) for i in range(((rank - nfree) // 2))]
    free = []
    index_types = ([None] * rank)
    indices = ([None] * rank)
    for i in range(rank):
        gi = g[i]
        index_types[i] = lex_index_types[gi]
        indices[i] = lex_indices[gi]
        if (gi < nfree):
            ind = sorted_free[gi]
            assert (index_types[i] == sorted_free[gi].tensor_index_type)
            free.append((ind, i))
        else:
            j = (gi - nfree)
            (idum, cov) = divmod(j, 2)
            if cov:
                dum[idum][1] = i
            else:
                dum[idum][0] = i
    dum = [tuple(x) for x in dum]
    return _IndexStructure(free, dum, index_types, indices)
