def write_layout(files_model, ex_mets, media, biomasses, outfile=
    'Consortium_layout.txt', maxCycles=1000, timeStep=0.1, spaceWidth=0.05,
    deathRate=0, numRunThreads=2, maxSpaceBiomass=10, biom_name=
    'total_biomass_log_template.txt', media_name='media_log_template.txt',
    flux_name='flux_log_template.txt'):
    """
    Writes the comets layout
    INPUTS -> files_model: list of strings containing model files,
              ex_mets: list of extracellular metabolites,
              media: dictionary of metabolite:concentration
              dictionary of files_model:initial biomass
              ... some of the COMETS parameters, that are described in http://www.bu.edu/segrelab/comets-parameters/
    OUPUTS -> creates a COMETS layout in "Consortium_layout.txt
    """
    with open(outfile, 'w') as f:
        lines4 = 'model_file\t' + '\t'.join(files_model)
        lines4 += '\n\tmodel_world\n\t\tgrid_size\t1\t1\n\t\tworld_media\n'
        f.write(lines4)
        for met in ex_mets:
            if met not in media:
                f.write('\t\t\t' + met + '\t' + '0.0\n')
            else:
                f.write('\t\t\t' + met + '\t' + str(media[met]) + '\n')
        f.write('\t\t//\n\t\tmedia\n\t\t//\n\t//\n\tinitial_pop\n')
        biomass_line = '\t\t0\t0'
        for file in files_model:
            biomass_line += '\t' + biomasses[file]
        f.write(biomass_line + '\n\t//\n')
        params = 'parameters\n    maxCycles = ' + str(maxCycles) + '\n'
        params += '    timeStep = ' + str(timeStep) + '\n'
        params += '    spaceWidth = ' + str(spaceWidth) + '\n'
        params += '    deathRate = ' + str(deathRate) + '\n'
        params += '    maxSpaceBiomass = ' + str(maxSpaceBiomass) + '\n'
        params += '    numRunThreads = ' + str(numRunThreads) + '\n'
        params += '    pixelScale = 100\n'
        params += '    allowCellOverlap = true\n'
        params += '    saveslideshow = false\n'
        params += '    writetotalbiomasslog = true\n'
        params += '    totalbiomasslogname = ' + biom_name + '\n'
        params += '    writemedialog = true\n'
        params += '    medialogname = ' + media_name + '\n'
        params += '    writefluxlog = true\n'
        params += '    fluxlogname = ' + flux_name + '\n'
        params += '    uselognametimestamp = false\n'
        params += '    exchangestyle = Monod Style\n'
        params += '    defaultKm = 0.01\n'
        params += '    defaultVmax = 20\n//\n'
        f.write(params)
    return
