def test_reaction_charge_balance(read_only_model): """ Expect all reactions to be charge balanced. This will exclude biomass, exchange and demand reactions as they are unbalanced by definition. It will also fail all reactions where at least one metabolite does not have a charge defined. In steady state, for each metabolite the sum of influx equals the sum of outflux. Hence the net charges of both sides of any model reaction have to be equal. Reactions where at least one metabolite does not have a formula are not considered to be balanced, even though the remaining metabolites participating in the reaction might be. """ ann = test_reaction_charge_balance.annotation internal_rxns = con_helpers.get_internals(read_only_model) ann["data"] = get_ids( consistency.find_charge_unbalanced_reactions(internal_rxns)) ann["metric"] = len(ann["data"]) / len(internal_rxns) ann["message"] = wrapper.fill( """A total of {} ({:.2%}) reactions are charge unbalanced with at least one of the metabolites not having a charge or the overall charge not equal to 0: {}""".format( len(ann["data"]), ann["metric"], truncate(ann["data"]))) assert len(ann["data"]) == 0, ann["message"]
def test_reaction_charge_balance(model): """ Expect all reactions to be charge balanced. This will exclude biomass, exchange and demand reactions as they are unbalanced by definition. It will also fail all reactions where at least one metabolite does not have a charge defined. In steady state, for each metabolite the sum of influx equals the sum of efflux. Hence the net charges of both sides of any model reaction have to be equal. Reactions where at least one metabolite does not have a charge are not considered to be balanced, even though the remaining metabolites participating in the reaction might be. Implementation: For each reaction that isn't a boundary or biomass reaction check if each metabolite has a non-zero charge attribute and if so calculate if the overall sum of charges of reactants and products is equal to zero. """ ann = test_reaction_charge_balance.annotation internal_rxns = con_helpers.get_internals(model) ann["data"] = get_ids( consistency.find_charge_unbalanced_reactions(internal_rxns)) ann["metric"] = len(ann["data"]) / len(internal_rxns) ann["message"] = wrapper.fill( """A total of {} ({:.2%}) reactions are charge unbalanced with at least one of the metabolites not having a charge or the overall charge not equal to 0: {}""".format(len(ann["data"]), ann["metric"], truncate(ann["data"]))) assert len(ann["data"]) == 0, ann["message"]
def test_reaction_charge_balance(model): """ Expect all reactions to be charge balanced. This will exclude biomass, exchange and demand reactions as they are unbalanced by definition. It will also fail all reactions where at least one metabolite does not have a charge defined. In steady state, for each metabolite the sum of influx equals the sum of efflux. Hence the net charges of both sides of any model reaction have to be equal. Reactions where at least one metabolite does not have a charge are not considered to be balanced, even though the remaining metabolites participating in the reaction might be. Implementation: For each reaction that isn't a boundary or biomass reaction check if each metabolite has a non-zero charge attribute and if so calculate if the overall sum of charges of reactants and products is equal to zero. """ ann = test_reaction_charge_balance.annotation internal_rxns = con_helpers.get_internals(model) ann["data"] = get_ids( consistency.find_charge_unbalanced_reactions(internal_rxns)) ann["metric"] = len(ann["data"]) / len(internal_rxns) ann["message"] = wrapper.fill( """A total of {} ({:.2%}) reactions are charge unbalanced with at least one of the metabolites not having a charge or the overall charge not equal to 0: {}""".format( len(ann["data"]), ann["metric"], truncate(ann["data"]))) assert len(ann["data"]) == 0, ann["message"]
def test_find_charge_unbalanced_reactions(model, num): """Expect all reactions to be charge balanced.""" internal_rxns = con_helpers.get_internals(model) reactions = consistency.find_charge_unbalanced_reactions(internal_rxns) assert len(reactions) == num
def test_find_charge_unbalanced_reactions(model, num): """Expect all reactions to be charge balanced.""" internal_rxns = con_helpers.get_internals(model) reactions = consistency.find_charge_unbalanced_reactions(internal_rxns) assert len(reactions) == num