def run_sink_check(self, model, solver, threshold, implicit_sinks=True):
        """Run sink production check method."""
        prob = solver.create_problem()

        # Create flux variables
        v = prob.namespace()
        for reaction_id in model.reactions:
            lower, upper = model.limits[reaction_id]
            v.define([reaction_id], lower=lower, upper=upper)

        # Build mass balance constraints
        massbalance_lhs = {compound: 0 for compound in model.compounds}
        for spec, value in iteritems(model.matrix):
            compound, reaction_id = spec
            massbalance_lhs[compound] += v(reaction_id) * value

        mass_balance_constrs = {}
        for compound, lhs in iteritems(massbalance_lhs):
            if implicit_sinks:
                # The constraint is merely >0 meaning that we have implicit
                # sinks for all compounds.
                prob.add_linear_constraints(lhs >= 0)
            else:
                # Save these constraints so we can temporarily remove them
                # to create a sink.
                c, = prob.add_linear_constraints(lhs == 0)
                mass_balance_constrs[compound] = c

        for compound, lhs in sorted(iteritems(massbalance_lhs)):
            if not implicit_sinks:
                mass_balance_constrs[compound].delete()

            prob.set_objective(lhs)
            try:
                result = prob.solve(lp.ObjectiveSense.Maximize)
            except lp.SolverError as e:
                logger.warning('Failed to solve for compound: {} ({})'.format(
                    compound, e))

            if result.get_value(lhs) < threshold:
                yield compound

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