Skip to content

Port MSCommunity onto cshenry/ModelSEEDpy main (import paths, CompatModelUtil, runtime fixes) - #3

Open
cshenry wants to merge 3 commits into
mainfrom
fix/modelseedpy-core-import-paths
Open

cshenry wants to merge 3 commits into
mainfrom
fix/modelseedpy-core-import-paths

Conversation

@cshenry

@cshenry cshenry commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

MSCommunity at 2dcff16 targets the freiburgermsu/ModelSEEDpy lineage and fails against cshenry/ModelSEEDpy main, which is the tree KBUtilLib builds on. This branch ports it across without adding any new modelling behaviour.

  • 58f0970: import-path fixes (modelseedpy.core.msminimalmedia, modelseedpy.core.exceptions), plus a restored isnumber and the mediaName → medianame rename. Also adds a make_model_util() signature adapter. Any non-default environment/climit/o2limit now raises instead of being silently dropped.
  • c3259f3: CompatModelUtil(MSModelUtil) restores the 11 MSModelUtil members MSCommunity needs. It also ports convert_kbase_media so add_medium accepts an MSMedia, and an unrecognised medium raises rather than leaving the model unconstrained.
  • a914801: four runtime fixes found by the live tests:
    • create_constraint(printing=)
    • remove_constraint suffix semantics for _regularization
    • compute_max_biomass/compute_max_atp read self.community.util.model
    • set_abundance payload shape

Verification

  • KBUtilLib tests/modeling/test_ms_community_utils_live.py, using the ModelSEED-shaped asymmetric fixture: 9 passed, 1 skipped. The skip is the no-QP refusal path, which can't run because a QP solver is present.
  • Two real E. coli members, solved with glpk:
    • community FBA reaches growth 1.1706 with carbon
    • with no carbon source it reaches 0.0, so the no-carbon control passes

Not ported

rxn_mets_list and solution_to_variables_dict were not ported. Both are used only inside phenotypes(), which KBUtilLib never calls.

🤖 Generated with Claude Code

Albert (kbhub) and others added 3 commits October 10, 2026 05:38
MSCommunity @ 2dcff16 targets the freiburgermsu/ModelSEEDpy lineage and
fails against cshenry/ModelSEEDpy main, the tree KBUtilLib builds on.
Fixed here with no invented modelling semantics:

- commhelper: import minimizeFlux_withGrowth/bioFlux_check from
  modelseedpy.core.msminimalmedia, NoFluxError/ObjectiveError from
  modelseedpy.core.exceptions; they are not re-exported from
  modelseedpy.core.
- commhelper/mskineticsfba: FBAHelper.isnumber is gone; restored as a
  module-level isnumber copied from modelseedpy datastandardization.
- mscommsim: FBAHelper.mediaName -> medianame (exact rename).
- commhelper: the nonMSID lookahead was evaluated eagerly but can only
  match an id ending in digits and is unused on the branch that
  non-ModelSEED ids always take; it raised AttributeError on .group()
  for every such id. Now evaluated only where used.
- commhelper: make_model_util() adapts MSModelUtil's signature. copy= is
  honoured locally when unsupported (dropping it would mutate the
  caller's models); environment/climit/o2limit RAISE when non-default,
  since dropping an uptake limit would yield plausible wrong fluxes.
  climit/o2limit exist in no reachable ModelSEEDpy.

INCOMPLETE: ~11 MSModelUtil members are still missing (add_objective,
create_constraint, add_minimal_objective_cons, carbon_exchange_list,
exchange_mets_list, add_medium, run_fba, remove_cons_vars,
metabolites_set, standard_exchanges, remove_constraint). No live
community test passes yet. rxn_mets_list and solution_to_variables_dict
remain unported; both sit only in phenotypes(), never called by KBUtilLib.
…ersion

Completes the port begun in 58f0970. Community modeling now runs end to end
on real ModelSEED models.

- CompatModelUtil(MSModelUtil) restores the members MSCommunity needs that
  cshenry/ModelSEEDpy main lacks: metabolites_set, exchange_mets_list,
  carbon_exchange_list, carbon_exchange_mets_list, standard_exchanges,
  add_cons_vars, remove_cons_vars, create_constraint, remove_constraint,
  add_objective, add_minimal_objective_cons, add_medium, run_fba. All ported
  from the freiburgermsu lineage (branch MSpy_freiburgermsu) except
  remove_constraint, whose contract is derived from its call sites.
  Two deliberate deviations, noted at their sites: Objective/Constraint come
  from self.model.problem rather than bare optlang, so they bind to the
  model's own solver interface.

- add_medium now ports FBAHelper.convert_kbase_media (absent from the
  installed ModelSEEDpy) so an MSMedia is accepted: uptake bound is the
  NEGATED lower bound, matching cobra's model.medium convention. A medium
  that is neither a mapping nor an MSMedia still RAISES -- applying no
  medium instead would silently leave the model unconstrained, which is
  exactly how a no-carbon control turns into a false positive.

VERIFIED on two real E. coli members (gf.json from the 2026-10-01
acceptance run, glpk; pod gurobi is size-limited and refuses a
genome-scale LP):
  build_community    -> CommunityModel, members c1/c2, abundances 0.5/0.5
  community FBA      -> status optimal, community_growth 1.1706,
                        kinetics NOT relaxed, 171 exchange fluxes
  gmm WITH carbon    -> 1.1706
  gmm NO carbon      -> 0.0        <- control passes
  cross_feeding_table-> two DataFrames (24,3) and (3,3)

Still unported: rxn_mets_list and solution_to_variables_dict, both only
inside phenotypes(), which KBUtilLib never calls; the latter has no
reachable original so porting it would mean guessing.
- commhelper.CompatModelUtil.create_constraint: accept printing= (c3259f3
  dropped it; mscommsim passes it at four sites, so predict_abundances
  raised TypeError).
- CompatModelUtil.remove_constraint: a name beginning with "_" also removes
  every constraint whose name ends with it. regularization() creates
  <member>_regularization and clears them with remove_constraint(
  "_regularization"); the exact-match contract left them in place, so the
  next ratio pass or the next predict_abundances call raised
  ContainerAlreadyContains.
- CommunityMember.compute_max_biomass/compute_max_atp: optimize via
  self.community.util.model; MSCommunity has no .model attribute.
- test_individual_species: store objective_value, not the Solution object,
  in the Biomass/ATP columns.
- _compute_relative_abundance_from_solution(update_abundances=True): pass
  set_abundance the {id: {"abundance": x}} shape it reads (bare floats
  raised IndexError; also present on main since 2d37cd4).

Verified: KBUtilLib tests/modeling/test_ms_community_utils_live.py goes
from 2 failed / 7 passed to 1 failed / 8 passed / 1 skipped. The remaining
failure is a symmetric test fixture (two identical members predict the
uniform default split), not this code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant