def create_metabolic_model(self):
def _translate_compartments(reaction, compartment):<EOL><INDENT>"""<STR_LIT>"""<EOL>left = (((c.in_compartment(compartment), v)<EOL>if c.compartment is None else (c, v))<EOL>for c, v in reaction.left)<EOL>right = (((c.in_compartment(compartment), v)<EOL>if c.compartment is None else (c, v))<EOL>for c, v in reaction.right)<EOL>return Reaction(reaction.direction, left, right)<EOL><DEDENT>database = DictDatabase()<EOL>for reaction in self.reactions:<EOL><INDENT>if reaction.equation is not None:<EOL><INDENT>equation = _translate_compartments(<EOL>reaction.equation, self.default_compartment)<EOL>database.set_reaction(reaction.id, equation)<EOL><DEDENT><DEDENT>undefined_compartments = set()<EOL>undefined_compounds = set()<EOL>extracellular_compounds = set()<EOL>extracellular = self.extracellular_compartment<EOL>for reaction in database.reactions:<EOL><INDENT>for compound, _ in database.get_reaction_values(reaction):<EOL><INDENT>if compound.name not in self.compounds:<EOL><INDENT>undefined_compounds.add(compound.name)<EOL><DEDENT>if compound.compartment == extracellular:<EOL><INDENT>extracellular_compounds.add(compound.name)<EOL><DEDENT>if compound.compartment not in self.compartments:<EOL><INDENT>undefined_compartments.add(compound.compartment)<EOL><DEDENT><DEDENT><DEDENT>for compartment in sorted(undefined_compartments):<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(compartment))<EOL><DEDENT>for compound in sorted(undefined_compounds):<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(compound))<EOL><DEDENT>exchange_compounds = set()<EOL>for exchange_compound in self.exchange:<EOL><INDENT>if exchange_compound.compartment == extracellular:<EOL><INDENT>exchange_compounds.add(exchange_compound.name)<EOL><DEDENT><DEDENT>for compound in sorted(extracellular_compounds - exchange_compounds):<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(compound))<EOL><DEDENT>for compound in sorted(exchange_compounds - extracellular_compounds):<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(compound))<EOL><DEDENT>model_definition = None<EOL>if len(self.model) > <NUM_LIT:0>:<EOL><INDENT>model_definition = self.model<EOL><DEDENT>return MetabolicModel.load_model(<EOL>database, model_definition, itervalues(self.exchange),<EOL>itervalues(self.limits), v_max=self.default_flux_limit)<EOL>
Create a :class:`psamm.metabolicmodel.MetabolicModel`.