Try to assign a positive mass to each compound

    Return True if successful. The masses are simply constrained by m_i > 1 and
    finding a solution under these conditions proves that the database is mass
    consistent.

def is_consistent(database, solver, exchange=set(), zeromass=set()):
    """Try to assign a positive mass to each compound

    Return True if successful. The masses are simply constrained by m_i > 1 and
    finding a solution under these conditions proves that the database is mass
    consistent.
    """

    prob = solver.create_problem()
    compound_set = _non_localized_compounds(database)
    mass_compounds = compound_set.difference(zeromass)

    # Define mass variables
    m = prob.namespace(mass_compounds, lower=1)
    prob.set_objective(m.sum(mass_compounds))

    # Define constraints
    massbalance_lhs = {reaction: 0 for reaction in database.reactions}
    for (compound, reaction), value in iteritems(database.matrix):
        if compound not in zeromass:
            mass = m(compound.in_compartment(None))
            massbalance_lhs[reaction] += mass * value
    for reaction, lhs in iteritems(massbalance_lhs):
        if reaction not in exchange:
            prob.add_linear_constraints(lhs == 0)

    result = prob.solve_unchecked(lp.ObjectiveSense.Minimize)
    return result.success