def detect_best_flux_limit(model):
    """Detect the best default flux limit to use for model output.

    The default flux limit does not change the model but selecting a good
    value reduced the amount of output produced and reduces clutter in the
    output files.
    """
    flux_limit_count = Counter()

    for reaction in model.reactions:
        if reaction.id not in model.limits:
            continue

        equation = reaction.properties['equation']
        if equation is None:
            continue

        _, lower, upper = model.limits[reaction.id]
        if upper is not None and upper > 0 and equation.direction.forward:
            flux_limit_count[upper] += 1
        if lower is not None and -lower > 0 and equation.direction.reverse:
            flux_limit_count[-lower] += 1

    if len(flux_limit_count) == 0:
        return None

    best_flux_limit, _ = flux_limit_count.most_common(1)[0]
    return best_flux_limit
def detect_best_flux_limit ( model ) : flux_limit_count = Counter ( ) for reaction in model . reactions : if reaction . id not in model . limits : continue equation = reaction . properties [ 'equation' ] if equation is None : continue _ , lower , upper = model . limits [ reaction . id ] if upper is not None and upper > 0 and equation . direction . forward : flux_limit_count [ upper ] += 1 if lower is not None and - lower > 0 and equation . direction . reverse : flux_limit_count [ - lower ] += 1 if len ( flux_limit_count ) == 0 : return None best_flux_limit , _ = flux_limit_count . most_common ( 1 ) [ 0 ] return best_flux_limit
Detect the best default flux limit to use for model output.

    The default flux limit does not change the model but selecting a good
    value reduced the amount of output produced and reduces clutter in the
    output files.