def _mat_spin_convert(M, spin=None):
    """ Conversion of Siesta spin matrices to sisl spin matrices

    The matrices from Siesta are given in a format adheering to the following
    concept:

    A non-colinear calculation has the following entries (in C-index) for
    the sparse matrix:

    H[:, [0, 1, 2, 3]]
    H11 == H[:, 0]
    H22 == H[:, 1]
    H12 == H[:, 2] - 1j H[:, 3] # spin-box Hermitian
    H21 == H[:, 2] + 1j H[:, 3]

    Although it really does not make sense to change anything, we
    do change it to adhere to the spin-orbit case (see below).
    I.e. what Siesta *saves* is the -Im[H12], which we now store
    as Im[H12].


    A spin-orbit calculation has the following entries (in C-index) for
    the sparse matrix:

    H[:, [0, 1, 2, 3, 4, 5, 6, 7]]
    H11 == H[:, 0] + H[:, 4]
    H22 == H[:, 1] + H[:, 5]
    H12 == H[:, 2] - 1j H[:, 3] # spin-box Hermitian
    H21 == H[:, 6] + 1j H[:, 7]
    """
    if spin is None:
        if M.spin.is_noncolinear:
            M._csr._D[:, (3)] = -M._csr._D[:, (3)]
        elif M.spin.is_spinorbit:
            M._csr._D[:, (3)] = -M._csr._D[:, (3)]
    elif spin.is_noncolinear:
        M._D[:, (3)] = -M._D[:, (3)]
    elif spin.is_spinorbit:
        M._D[:, (3)] = -M._D[:, (3)]
