def write_yaml_model(model, dest='<STR_LIT:.>', convert_exchange=True,<EOL>split_subsystem=True):
yaml.SafeDumper.add_representer(OrderedDict, _dict_representer)<EOL>yaml.SafeDumper.add_representer(set, _set_representer)<EOL>yaml.SafeDumper.add_representer(frozenset, _set_representer)<EOL>yaml.SafeDumper.add_representer(<EOL>boolean.Expression, _boolean_expression_representer)<EOL>yaml.SafeDumper.add_representer(Decimal, _decimal_representer)<EOL>yaml.SafeDumper.ignore_aliases = lambda *args: True<EOL>yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,<EOL>_dict_constructor)<EOL>yaml_args = {'<STR_LIT>': False,<EOL>'<STR_LIT>': '<STR_LIT:utf-8>',<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:width>': <NUM_LIT>}<EOL>writer = ModelWriter()<EOL>with open(os.path.join(dest, '<STR_LIT>'), '<STR_LIT>') as f:<EOL><INDENT>writer.write_compounds(f, sorted(model.compounds, key=lambda c: c.id))<EOL><DEDENT>if model.default_flux_limit is None:<EOL><INDENT>model.default_flux_limit = detect_best_flux_limit(model)<EOL><DEDENT>if model.extracellular_compartment is None:<EOL><INDENT>model.extracellular_compartment = (<EOL>sbml.detect_extracellular_compartment(model))<EOL><DEDENT>if model.default_compartment is None:<EOL><INDENT>model.default_compartment = get_default_compartment(model)<EOL><DEDENT>if model.default_flux_limit is not None:<EOL><INDENT>logger.info('<STR_LIT>'.format(<EOL>model.default_flux_limit))<EOL><DEDENT>if convert_exchange:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>sbml.convert_exchange_to_compounds(model)<EOL><DEDENT>if len(model.compartments) == <NUM_LIT:0>:<EOL><INDENT>infer_compartment_entries(model)<EOL>logger.info('<STR_LIT>'.format(<EOL>len(model.compartments),<EOL>'<STR_LIT:U+002CU+0020>'.join(c.id for c in model.compartments)))<EOL><DEDENT>if len(model.compartments) != <NUM_LIT:0> and len(model.compartment_boundaries) == <NUM_LIT:0>:<EOL><INDENT>infer_compartment_adjacency(model)<EOL><DEDENT>reaction_files = reactions_to_files(model, dest, writer, split_subsystem)<EOL>if len(model.exchange) > <NUM_LIT:0>:<EOL><INDENT>with open(os.path.join(dest, '<STR_LIT>'), '<STR_LIT>') as f:<EOL><INDENT>yaml.safe_dump(model_exchange(model), f, **yaml_args)<EOL><DEDENT><DEDENT>reaction_limits = list(model_reaction_limits(model))<EOL>if len(reaction_limits) > <NUM_LIT:0>:<EOL><INDENT>with open(os.path.join(dest, '<STR_LIT>'), '<STR_LIT>') as f:<EOL><INDENT>yaml.safe_dump(reaction_limits, f, **yaml_args)<EOL><DEDENT><DEDENT>model_d = OrderedDict()<EOL>if model.name is not None:<EOL><INDENT>model_d['<STR_LIT:name>'] = model.name<EOL><DEDENT>if model.biomass_reaction is not None:<EOL><INDENT>model_d['<STR_LIT>'] = model.biomass_reaction<EOL><DEDENT>if model.default_flux_limit is not None:<EOL><INDENT>model_d['<STR_LIT>'] = model.default_flux_limit<EOL><DEDENT>if model.extracellular_compartment != '<STR_LIT:e>':<EOL><INDENT>model_d['<STR_LIT>'] = model.extracellular_compartment<EOL><DEDENT>if model.default_compartment != '<STR_LIT:c>':<EOL><INDENT>model_d['<STR_LIT>'] = model.default_compartment<EOL><DEDENT>if len(model.compartments) > <NUM_LIT:0>:<EOL><INDENT>adjacency = {}<EOL>for c1, c2 in model.compartment_boundaries:<EOL><INDENT>adjacency.setdefault(c1, set()).add(c2)<EOL>adjacency.setdefault(c2, set()).add(c1)<EOL><DEDENT>compartment_list = []<EOL>for compartment in sorted(model.compartments, key=lambda c: c.id):<EOL><INDENT>adjacent = adjacency.get(compartment.id)<EOL>if adjacent is not None and len(adjacent) == <NUM_LIT:1>:<EOL><INDENT>adjacent = next(iter(adjacent))<EOL><DEDENT>compartment_list.append(writer.convert_compartment_entry(<EOL>compartment, adjacent))<EOL><DEDENT>model_d['<STR_LIT>'] = compartment_list<EOL><DEDENT>model_d['<STR_LIT>'] = [{'<STR_LIT>': '<STR_LIT>'}]<EOL>model_d['<STR_LIT>'] = []<EOL>for reaction_file in reaction_files:<EOL><INDENT>model_d['<STR_LIT>'].append({'<STR_LIT>': reaction_file})<EOL><DEDENT>if len(model.exchange) > <NUM_LIT:0>:<EOL><INDENT>model_d['<STR_LIT>'] = [{'<STR_LIT>': '<STR_LIT>'}]<EOL><DEDENT>if len(reaction_limits) > <NUM_LIT:0>:<EOL><INDENT>model_d['<STR_LIT>'] = [{'<STR_LIT>': '<STR_LIT>'}]<EOL><DEDENT>with open(os.path.join(dest, '<STR_LIT>'), '<STR_LIT>') as f:<EOL><INDENT>yaml.safe_dump(model_d, f, **yaml_args)<EOL><DEDENT>
Write the given MetabolicModel to YAML files in dest folder.

    The parameter ``convert_exchange`` indicates whether the exchange reactions
    should be converted automatically to an exchange file.