def Edit_String_SimulData(data):
    """
    return string object made of lines which contains laue spots properties

    Called to be Edited in LaueToolsframe.control

    params:

    data tuple of spots properties
    data =(list_twicetheta, list_chi, list_energy, list_Miller, list_posX, list_posY,
           ListName, nb of(parent) grains,
            calibration parameters list, total nb of grains)
    """
    nb_total_grains = data[9]
    lines = 'Simulation Data from LAUE Pattern Program v1.0 2009 \n'
    lines += 'Total number of grains : %s\n' % int(nb_total_grains)
    lines += 'spot# h k l E 2theta chi X Y\n'
    nb = data[7]
    if isinstance(nb, int):
        nb_grains = data[7]
        TWT, CHI, ENE, MIL, XX, YY = data[:6]
        NAME = data[6]
        calib = data[8]
        for index_grain in range(nb_grains):
            nb_of_simulspots = len(TWT[index_grain])
            startgrain = '#G %d\t%s\t%d\n' % (index_grain, NAME[index_grain
                ], nb_of_simulspots)
            lines += startgrain
            for data_index in range(nb_of_simulspots):
                linedata = '%d\t%d\t%d\t%d\t%.5f\t%.4f\t%.4f\t%.4f\t%.4f\n' % (
                    data_index, MIL[index_grain][data_index][0], MIL[
                    index_grain][data_index][1], MIL[index_grain][
                    data_index][2], ENE[index_grain][data_index], TWT[
                    index_grain][data_index], CHI[index_grain][data_index],
                    XX[index_grain][data_index], YY[index_grain][data_index])
                lines += linedata
        lines += '#calibration parameters\n'
        for param in calib:
            lines += '# %s\n' % param
        return lines
    if isinstance(nb, list):
        print('nb in Edit_String_SimulData', nb)
        gen_i = 0
        TWT, CHI, ENE, MIL, XX, YY = data[:6]
        NAME = data[6]
        calib = data[8]
        for grain_ind in range(len(nb)):
            for tt in range(nb[grain_ind][1]):
                nb_of_simulspots = len(TWT[gen_i])
                startgrain = '#G %d\t%s\t%d\t%d\n' % (grain_ind, NAME[
                    grain_ind], tt, nb_of_simulspots)
                lines += startgrain
                for data_index in range(nb_of_simulspots):
                    linedata = (
                        '%d\t%d\t%d\t%d\t%.5f\t%.4f\t%.4f\t%.4f\t%.4f\n' %
                        (data_index, MIL[gen_i][data_index][0], MIL[gen_i][
                        data_index][1], MIL[gen_i][data_index][2], ENE[
                        gen_i][data_index], TWT[gen_i][data_index], CHI[
                        gen_i][data_index], XX[gen_i][data_index], YY[gen_i
                        ][data_index]))
                    lines += linedata
                gen_i += 1
        lines += '#calibration parameters\n'
        for param in calib:
            lines += '# %s\n' % param
        return lines
