Repository navigation
Load SBML in VCell's units: unit_system= and convert_vcml_units - #63
Merged
Merged
Conversation
- pyvcell.vcml.convert_units(bio_model, unit_system="vcell"|"sbml"): the Biomodel in VCell's units (um, uM, s) or VCell's SBML units (dm, umol, l, s), every quantity converted by VCell (libvcell vcml_convert_units). VCell imports SBML in the SBML's own units, so convert_units(load_sbml_str(sbml)) gives the model in VCell's units. - Model.unit_system holds VCML's <ModelUnitSystem> attributes. The reader and writer used to drop it, so a model imported from SBML (in dm, umol, l) was written back with its numbers read in VCell's default units. Results are unchanged for that case (the numbers are self-consistent either way; checked bit for bit on the 1D fixture), but generated names now carry the model's units (s0_init_umol_l_1 rather than s0_init_uM). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…type-checks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeping <ModelUnitSystem> on the pyvcell Model broke a common pattern: a model from Antimony/SBML without units gets a unit system with a dimensionless length, and users then add a um geometry to it (examples/notebooks/sysbio-1-antimony.ipynb). The Model, reader and writer are back to main. Instead: - load_sbml_str/load_sbml_file(..., unit_system=None): "vcell" converts the imported VCML (which still carries its units) to VCell's units before reading; the default is unchanged. - convert_vcml_units(vcml_str, unit_system): the text-level utility. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <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.
VCell imports SBML in the SBML's own units; VCell itself writes SBML in dm, µmol, l and s. This PR adds a way to get such models in VCell's units: µm, µM and s, which VCell's spatial and stochastic math assumes. VCell does the conversion, geometry included, through libvcell's new
vcml_convert_units(virtualcell/libvcell#26).New API
load_sbml_str(sbml_str, unit_system=None)andload_sbml_file(...): withunit_system="vcell", the imported VCML, which still carries its<ModelUnitSystem>, is converted before pyvcell reads it. The default leaves the numbers as imported, which is today's behaviour.convert_vcml_units(vcml_str, unit_system): the text-level utility, for"vcell"or"sbml".Why not on the
Biomodel. A first version kept<ModelUnitSystem>on pyvcell'sModelthrough VCML read and write, and brokeexamples/notebooks/sysbio-1-antimony.ipynb.Model, reader and writer are unchanged here, and conversion happens on the VCML text instead.Tests:
test_load_sbml_in_vcell_unitsusesSmallSpatialProject_3D.xml(in dm) and checks:convert_vcml_unitsgoes back to dm;It skips with a libvcell that lacks
vcml_convert_units, and mypy passes against the released libvcell. Locally, with a libvcell built from #26,tests/vcml/test_utils.pyandtest_simulations.pypass, andsysbio-1-antimony.ipynbexecutes.Context: Phase 6 of viva-pde-particle, reading PDE/particle hybrids from SBML Spatial (virtualcell/vcell#2175). Suggested by @jcschaff: VCell converts units internally anyway, so pyvcell and libvcell should expose it.
🤖 Generated with Claude Code