def run_sink_check(self, model, solver, threshold, implicit_sinks=True):
prob = solver.create_problem()<EOL>v = prob.namespace()<EOL>for reaction_id in model.reactions:<EOL><INDENT>lower, upper = model.limits[reaction_id]<EOL>v.define([reaction_id], lower=lower, upper=upper)<EOL><DEDENT>massbalance_lhs = {compound: <NUM_LIT:0> for compound in model.compounds}<EOL>for spec, value in iteritems(model.matrix):<EOL><INDENT>compound, reaction_id = spec<EOL>massbalance_lhs[compound] += v(reaction_id) * value<EOL><DEDENT>mass_balance_constrs = {}<EOL>for compound, lhs in iteritems(massbalance_lhs):<EOL><INDENT>if implicit_sinks:<EOL><INDENT>prob.add_linear_constraints(lhs >= <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>c, = prob.add_linear_constraints(lhs == <NUM_LIT:0>)<EOL>mass_balance_constrs[compound] = c<EOL><DEDENT><DEDENT>for compound, lhs in sorted(iteritems(massbalance_lhs)):<EOL><INDENT>if not implicit_sinks:<EOL><INDENT>mass_balance_constrs[compound].delete()<EOL><DEDENT>prob.set_objective(lhs)<EOL>try:<EOL><INDENT>result = prob.solve(lp.ObjectiveSense.Maximize)<EOL><DEDENT>except lp.SolverError as e:<EOL><INDENT>logger.warning('<STR_LIT>'.format(<EOL>compound, e))<EOL><DEDENT>if result.get_value(lhs) < threshold:<EOL><INDENT>yield compound<EOL><DEDENT>if not implicit_sinks:<EOL><INDENT>c, = prob.add_linear_constraints(lhs == <NUM_LIT:0>)<EOL>mass_balance_constrs[compound] = c<EOL><DEDENT><DEDENT>
Run sink production check method.