Fix drain_list loading: create DM_ demand reactions during model build#25
Merged
cshenry merged 1 commit intocshenry:mainfrom Apr 14, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MSTemplateBuilder.from_dict()was silently dropping thedrain_listfrom template JSON files, sotemplate.drainsstayed emptyMSBuilder.build_drains()fell back toDEFAULT_SINKSand only created SK_ (sink) reactions, never DM_ (demand) reactionsDM_cpd11416_c0, cobrapy FBA returns 0 growth becausecpd11416(Biomass) produced bybio1has no outletChanges
mstemplate.py:from_dict()now readsdrain_listintobuilder.drainsmsbuilder.py:build_demands()creates DM_ reactions for all drain compounds (previously requiredlower_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 withMSBuilder.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