def model_to_dict(model, sort=False):
obj = OrderedDict()<EOL>obj["<STR_LIT>"] = list(map(metabolite_to_dict, model.metabolites))<EOL>obj["<STR_LIT>"] = list(map(reaction_to_dict, model.reactions))<EOL>obj["<STR_LIT>"] = list(map(gene_to_dict, model.genes))<EOL>obj["<STR_LIT:id>"] = model.id<EOL>_update_optional(model, obj, _OPTIONAL_MODEL_ATTRIBUTES,<EOL>_ORDERED_OPTIONAL_MODEL_KEYS)<EOL>if sort:<EOL><INDENT>get_id = itemgetter("<STR_LIT:id>")<EOL>obj["<STR_LIT>"].sort(key=get_id)<EOL>obj["<STR_LIT>"].sort(key=get_id)<EOL>obj["<STR_LIT>"].sort(key=get_id)<EOL><DEDENT>return obj<EOL>
Convert model to a dict.

    Parameters
    ----------
    model : cobra.Model
        The model to reformulate as a dict.
    sort : bool, optional
        Whether to sort the metabolites, reactions, and genes or maintain the
        order defined in the model.

    Returns
    -------
    OrderedDict
        A dictionary with elements, 'genes', 'compartments', 'id',
        'metabolites', 'notes' and 'reactions'; where 'metabolites', 'genes'
        and 'metabolites' are in turn lists with dictionaries holding all
        attributes to form the corresponding object.

    See Also
    --------
    cobra.io.model_from_dict