Skip to content

Fix drain_list loading: create DM_ demand reactions during model build#25

Merged
cshenry merged 1 commit intocshenry:mainfrom
jplfaria:fix-drain-list-loading
Apr 14, 2026
Merged

Fix drain_list loading: create DM_ demand reactions during model build#25
cshenry merged 1 commit intocshenry:mainfrom
jplfaria:fix-drain-list-loading

Conversation

@jplfaria
Copy link
Copy Markdown

Summary

  • MSTemplateBuilder.from_dict() was silently dropping the drain_list from template JSON files, so template.drains stayed empty
  • MSBuilder.build_drains() fell back to DEFAULT_SINKS and only created SK_ (sink) reactions, never DM_ (demand) reactions
  • Without DM_cpd11416_c0, cobrapy FBA returns 0 growth because cpd11416 (Biomass) produced by bio1 has no outlet

Changes

  1. mstemplate.py: from_dict() now reads drain_list into builder.drains
  2. msbuilder.py: build_demands() creates DM_ reactions for all drain compounds (previously required lower_bound < 0, but template drain_list entries use [0, 1000])

Context

Found while building the modelseed-api REST backend. When loading templates from local JSON files via MSTemplateBuilder.from_dict() (instead of KBase workspace), models built with MSBuilder.build() had SK_ reactions but no DM_ reactions. The gapfiller adds DM_ to its internal clone, but they don't persist to the final model unless the LP solver includes them in the solution.

In KBase, templates loaded via the workspace object factory (kbase_api.get_from_ws()) may handle drain_list differently, which is why this wasn't caught before.

🤖 Generated with Claude Code

MSTemplateBuilder.from_dict() was silently dropping the drain_list
from template JSON files, so template.drains stayed empty. This
meant MSBuilder.build_drains() fell back to DEFAULT_SINKS and only
created SK_ (sink) reactions, never DM_ (demand) reactions.

Without DM_cpd11416_c0, cobrapy FBA returns 0 growth because the
biomass compound (cpd11416) produced by bio1 has no outlet.

Two fixes:
1. mstemplate.py: from_dict() now reads drain_list into builder.drains
2. msbuilder.py: build_demands() creates DM_ reactions for all drain
   compounds (previously required lower_bound < 0, but template
   drain_list entries use [0, 1000])

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cshenry cshenry merged commit 21a5f86 into cshenry:main Apr 14, 2026
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.

2 participants