def MinDiffFromFlux(model, fluxdist, reacs=None, it=0, cleanup=True):
    """ pre: fluxdist = {reac:flux_val} """
    state = model.GetState()
    obj = {}
    if not reacs:
        reacs = fluxdist.keys()
    for r in reacs:
        rowname = r + '_' + str(it) + '_mindifffromflux'
        colplus = r + '_' + str(it) + '_mindifffromflux+'
        colminus = r + '_' + str(it) + '_mindifffromflux-'
        model.AddMetabolite(rowname)
        model.GetReaction(r).add_metabolites({model.GetMetabolite(rowname): 1})
        model.AddReaction(colplus, {model.GetMetabolite(rowname): 1})
        model.AddReaction(colminus, {model.GetMetabolite(rowname): -1})
        model.SetMetBounds(rowname, fluxdist[r], fluxdist[r])
        obj[colplus] = 1
        obj[colminus] = 1
    model.ZeroObjective()
    model.SetObjective(obj)
    model.SetObjDirec('Min')
    model.Solve(False)
    if cleanup:
        model.CleanUpTempVar('_mindifffromflux')
    model.SetState(state, IncSol=False)
