def create_port_doc(): sbmlns = libsbml.SBMLNamespaces(3, 1, "comp", 1) doc = libsbml.SBMLDocument(sbmlns) doc.setPackageRequired("comp", True) model = doc.createModel() model.setId("toy_update") model.setName("toy (UPDATE submodel)") model.setSBOTerm(SBO_CONTINOUS_FRAMEWORK) objects = [ fac.Compartment( sid="extern", value=1.0, unit="m3", constant=True, name="external compartment", ), fac.Species( sid="A", name="A", initialConcentration=10.0, hasOnlySubstanceUnits=True, compartment="extern", ), fac.Species( sid="C", name="C", initialConcentration=0, hasOnlySubstanceUnits=True, compartment="extern", ), fac.Parameter(sid="EX_A", value=1.0, constant=False, sboTerm="SBO:0000613"), fac.Parameter(sid="EX_C", value=1.0, constant=False, sboTerm="SBO:0000613"), ] fac.create_objects(model, obj_iter=objects) return doc
def create_fba_doc(): sbmlns = libsbml.SBMLNamespaces(3, 1) sbmlns.addPackageNamespace("fbc", 2) sbmlns.addPackageNamespace("comp", 1) doc = libsbml.SBMLDocument(sbmlns) doc.setPackageRequired("comp", True) doc.setPackageRequired("fbc", False) model = doc.createModel() mplugin = model.getPlugin("fbc") mplugin.setStrict(True) objects = [ fac.Compartment(sid='cell', value=1.0), fac.Species(sid='A', initialConcentration=0, compartment="cell"), fac.Species(sid='B', initialConcentration=0, compartment="cell"), ] fac.create_objects(model, objects) return doc
def bounds_model(sbml_file, directory, doc_fba=None): """" Submodel for dynamically calculating the flux bounds. The dynamically changing flux bounds are the input to the FBA model. The units of the exchange fluxes must fit to the transported species. """ doc = builder.template_doc_bounds("ecoli") model = doc.getModel() bounds_notes = notes.format(""" <h2>BOUNDS submodel</h2> <p>Submodel for dynamically calculating the flux bounds. The dynamically changing flux bounds are the input to the FBA model.</p> """) utils.set_model_info(model, notes=bounds_notes, creators=creators, units=units, main_units=main_units) # dt compartment_id = "bioreactor" builder.create_dfba_dt(model, time_unit=UNIT_TIME, create_port=True) # compartment builder.create_dfba_compartment(model, compartment_id=compartment_id, unit_volume=UNIT_VOLUME, create_port=True) # dynamic species model_fba = doc_fba.getModel() builder.create_dfba_species(model, model_fba, compartment_id=compartment_id, unit_amount=UNIT_AMOUNT, create_port=True, exclude_sids=['X']) # FIXME: define biomass separately, also port needed for biomass mc.create_objects(model, [ mc.Parameter(sid='cf_X', value=1.0, unit="g_per_mmol", name="biomass conversion factor", constant=True), mc.Species(sid='X', initialAmount=0.001, compartment=compartment_id, name='biomass', substanceUnit='g', hasOnlySubstanceUnits=True, conversionFactor='cf_X') ]) # exchange & dynamic bounds if not biomass_weighting: builder.create_exchange_bounds(model, model_fba=model_fba, unit_flux=UNIT_FLUX, create_ports=True) builder.create_dynamic_bounds(model, model_fba, unit_flux=UNIT_FLUX) else: builder.create_exchange_bounds(model, model_fba=model_fba, unit_flux=UNIT_FLUX_PER_G, create_ports=True) builder.create_dynamic_bounds(model, model_fba, unit_flux=UNIT_FLUX_PER_G) sbmlio.write_sbml(doc, filepath=pjoin(directory, sbml_file), validate=True)
def update_model(sbml_file, directory, doc_fba=None): """ Submodel for dynamically updating the metabolite count/concentration. This updates the ode model based on the FBA fluxes. """ doc = builder.template_doc_update("ecoli") model = doc.getModel() update_notes = notes.format(""" <h2>UPDATE submodel</h2> <p>Submodel for dynamically updating the metabolite count. This updates the ode model based on the FBA fluxes.</p> """) utils.set_model_info(model, notes=update_notes, creators=creators, units=units, main_units=main_units) # compartment compartment_id = "bioreactor" builder.create_dfba_compartment(model, compartment_id=compartment_id, unit_volume=UNIT_VOLUME, create_port=True) # dynamic species model_fba = doc_fba.getModel() # creates all the exchange reactions, biomass must be handeled separately builder.create_dfba_species(model, model_fba, compartment_id=compartment_id, unit_amount=UNIT_AMOUNT, create_port=True) # FIXME: biomass via function mc.create_objects(model, [ mc.Parameter(sid='cf_biomass', value=1.0, unit="g_per_mmol", name="biomass conversion factor", constant=True), mc.Species(sid='X', initialAmount=0.001, compartment='c', name='biomass', substanceUnit='g', hasOnlySubstanceUnits=True, conversionFactor='cf_biomass') ]) # update reactions # FIXME: weight with X (biomass) builder.create_update_reactions(model, model_fba=model_fba, formula="-{}", unit_flux=UNIT_FLUX, modifiers=[]) # write SBML file sbmlio.write_sbml(doc, filepath=pjoin(directory, sbml_file), validate=True)
def fba_model(sbml_file, directory, annotations=None): """ FBA model :param sbml_file: output file name :param directory: output directory :return: SBMLDocument """ fba_notes = notes.format(""" <h2>FBA submodel</h2> <p>DFBA fba submodel. Unbalanced metabolites are encoded via exchange fluxes.</p> """) doc = builder.template_doc_fba(settings.MODEL_ID) model = doc.getModel() utils.set_model_info(model, notes=fba_notes, creators=creators, units=units, main_units=main_units) objects = [ # compartments mc.Compartment(sid='cell', value=1.0, unit=UNIT_VOLUME, constant=True, name='cell', spatialDimensions=3), # exchange species mc.Species(sid='atp', name="ATP", initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=False, compartment="cell"), mc.Species(sid='adp', name="ADP", initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=False, compartment="cell"), mc.Species(sid='glc', name="Glucose", initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=False, compartment="cell"), mc.Species(sid='pyr', name='Pyruvate', initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=False, compartment="cell"), # internal species mc.Species(sid='fru16bp', name='Fructose 1,6-bisphospate', initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=False, compartment="cell"), mc.Species(sid='pg2', name='2-Phosphoglycerate', initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=False, compartment="cell"), # bounds mc.Parameter(sid="ub_R3", value=1.0, unit=UNIT_FLUX, constant=True, sboTerm=builder.FLUX_BOUND_SBO), mc.Parameter(sid="zero", value=0.0, unit=UNIT_FLUX, constant=True, sboTerm=builder.FLUX_BOUND_SBO), mc.Parameter(sid="ub_default", value=builder.UPPER_BOUND_DEFAULT, unit=UNIT_FLUX, constant=True, sboTerm=builder.FLUX_BOUND_SBO), ] mc.create_objects(model, objects) # reactions r1 = mc.create_reaction(model, rid="R1", name="glu + 2 atp -> fru16bp + 2 adp", fast=False, reversible=False, reactants={ "glc": 1, "atp": 2 }, products={ "fru16bp": 1, 'adp': 2 }, compartment='cell') r2 = mc.create_reaction(model, rid="R2", name="fru16bp -> 2 pg2", fast=False, reversible=False, reactants={"fru16bp": 1}, products={"pg2": 2}, compartment='cell') r3 = mc.create_reaction(model, rid="R3", name="pg2 + adp -> pyr + atp", fast=False, reversible=False, reactants={ "pg2": 1, "adp": 2 }, products={ "pyr": 1, "atp": 2 }, compartment='cell') # flux bounds fbc.set_flux_bounds(r1, lb="zero", ub="ub_default") fbc.set_flux_bounds(r2, lb="zero", ub="ub_default") fbc.set_flux_bounds(r3, lb="zero", ub="ub_R3") # fbc.set_flux_bounds(ratp, lb="zero", ub="ub_RATP") # exchange reactions for sid in ['atp', 'adp', 'glc', 'pyr']: builder.create_exchange_reaction(model, species_id=sid, flux_unit=UNIT_FLUX) # objective function model_fbc = model.getPlugin("fbc") fbc.create_objective(model_fbc, oid="RATP_maximize", otype="maximize", fluxObjectives={"R3": 1.0}, active=True) if annotations: annotator.annotate_sbml_doc(doc, annotations) # write SBML sbmlio.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=True) return doc
value=0.0, unit=UNIT_KIND_LITRE, constant=False, name='erythrocyte'), ] ############################################################## # Species ############################################################## # tissue metabolites species = [ mc.Species('glc_ext', compartment="Vpl", initialConcentration=0, unit='mmole', name="glucose", hasOnlySubstanceUnits=True, constant=False, port=True), mc.Species('lac_ext', compartment="Vpl", initialConcentration=0, unit='mmole', name="lactate", hasOnlySubstanceUnits=True, constant=False, port=True), mc.Species('glcRBC', compartment="Vrbc", initialConcentration=0, unit='mmole',
############################################################## functions = [] ############################################################## # Compartments ############################################################## compartments = [ mc.Compartment('Vli', value=1.47, unit=UNIT_KIND_LITRE, constant=False, name='liver', port=True), mc.Compartment('Vext', value=1.0, unit=UNIT_KIND_LITRE, constant=False, name='liver blood', port=True), ] ############################################################## # Species ############################################################## species = [ mc.Species('Aext_glc', compartment="Vext", initialConcentration=5.0, unit='mmole', name="glucose", hasOnlySubstanceUnits=True, port=True), mc.Species('Aext_lac', compartment="Vext", initialConcentration=0.8, unit='mmole', name="lactate", hasOnlySubstanceUnits=True, port=True), mc.Species('Ali_glc', compartment="Vli", initialConcentration=5.0, unit='mmole', name="glucose", hasOnlySubstanceUnits=True), mc.Species('Ali_lac', compartment="Vli", initialConcentration=0.8, unit='mmole', name="lactate", hasOnlySubstanceUnits=True), ] ############################################################## # Parameters ############################################################## parameters = [] ##############################################################
def top_model(sbml_file, directory, emds, doc_fba, annotations=None): """ Create top comp model. Creates full comp model by combining fba, update and bounds model with additional kinetics in the top model. """ top_notes = notes.format(""" <h2>TOP model</h2> <p>Main comp DFBA model by combining fba, update and bounds model with additional kinetics in the top model.</p> """) working_dir = os.getcwd() os.chdir(directory) doc = builder.template_doc_top(settings.MODEL_ID, emds) model = doc.getModel() utils.set_model_info(model, notes=top_notes, creators=creators, units=units, main_units=main_units) # dt builder.create_dfba_dt(model, step_size=DT_SIM, time_unit=UNIT_TIME, create_port=False) # compartment compartment_id = "extern" builder.create_dfba_compartment(model, compartment_id=compartment_id, unit_volume=UNIT_VOLUME, create_port=False) # dynamic species model_fba = doc_fba.getModel() builder.create_dfba_species(model, model_fba, compartment_id=compartment_id, hasOnlySubstanceUnits=True, unit_amount=UNIT_AMOUNT, create_port=False) # dummy species builder.create_dummy_species(model, compartment_id=compartment_id, hasOnlySubstanceUnits=True, unit_amount=UNIT_AMOUNT) # exchange flux bounds builder.create_exchange_bounds(model, model_fba=model_fba, unit_flux=UNIT_FLUX, create_ports=False) # dummy reactions & flux assignments builder.create_dummy_reactions(model, model_fba=model_fba, unit_flux=UNIT_FLUX) # replacedBy (fba reactions) builder.create_top_replacedBy(model, model_fba=model_fba) # replaced builder.create_top_replacements(model, model_fba, compartment_id=compartment_id) # initial concentrations for fba exchange species initial_c = { 'A': 10.0, 'C': 0.0, } for sid, value in initial_c.items(): species = model.getSpecies(sid) species.setInitialConcentration(value) # kinetic model mc.create_objects( model, [ # kinetic species mc.Species(sid='D', initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=True, compartment="extern"), # kinetic mc.Parameter(sid="k_R4", value=0.1, constant=True, unit="per_s", sboTerm="SBO:0000009"), # bounds parameter mc.Parameter(sid='ub_R1', value=1.0, unit=UNIT_FLUX, constant=False, sboTerm="SBO:0000625"), ]) # kinetic reaction (MMK) mc.create_reaction(model, rid="R4", name="R4: C -> D", fast=False, reversible=False, reactants={"C": 1}, products={"D": 1}, formula="k_R4*C", compartment="extern") # kinetic flux bounds comp.replace_elements(model, 'ub_R1', ref_type=comp.SBASE_REF_TYPE_PORT, replaced_elements={ 'bounds': ['ub_R1_port'], 'fba': ['ub_R1_port'] }) # write SBML file if annotations: annotator.annotate_sbml_doc(doc, annotations) sbml.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=True) # change back the working dir os.chdir(working_dir)
def fba_model(sbml_file, directory, annotations=None): """ FBA model :param sbml_file: output file name :param directory: output directory :return: SBMLDocument """ fba_notes = notes.format(""" <h2>FBA submodel</h2> <p>DFBA fba submodel. Unbalanced metabolites are encoded via exchange fluxes.</p> """) doc = builder.template_doc_fba(settings.MODEL_ID) model = doc.getModel() utils.set_model_info(model, notes=fba_notes, creators=creators, units=units, main_units=main_units) objects = [ # compartments mc.Compartment(sid='extern', value=1.0, unit=UNIT_VOLUME, constant=True, name='external compartment', spatialDimensions=3), mc.Compartment(sid='cell', value=1.0, unit=UNIT_VOLUME, constant=True, name='cell', spatialDimensions=3), mc.Compartment(sid='membrane', value=1.0, unit=UNIT_AREA, constant=True, name='membrane', spatialDimensions=2), # exchange species mc.Species(sid='A', name="A", initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=True, compartment="extern"), mc.Species(sid='C', name="C", initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=True, compartment="extern"), # internal species mc.Species(sid='B1', name="B1", initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=True, compartment="cell"), mc.Species(sid='B2', name="B2", initialConcentration=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=True, compartment="cell"), # bounds mc.Parameter(sid="ub_R1", value=1.0, unit=UNIT_FLUX, constant=True, sboTerm=builder.FLUX_BOUND_SBO), mc.Parameter(sid="zero", value=0.0, unit=UNIT_FLUX, constant=True, sboTerm=builder.FLUX_BOUND_SBO), mc.Parameter(sid="ub_default", value=builder.UPPER_BOUND_DEFAULT, unit=UNIT_FLUX, constant=True, sboTerm=builder.FLUX_BOUND_SBO), ] mc.create_objects(model, objects) # reactions r1 = mc.create_reaction(model, rid="R1", name="A import (R1)", fast=False, reversible=True, reactants={"A": 1}, products={"B1": 1}, compartment='membrane') r2 = mc.create_reaction(model, rid="R2", name="B1 <-> B2 (R2)", fast=False, reversible=True, reactants={"B1": 1}, products={"B2": 1}, compartment='cell') r3 = mc.create_reaction(model, rid="R3", name="B2 export (R3)", fast=False, reversible=True, reactants={"B2": 1}, products={"C": 1}, compartment='membrane') # flux bounds fbc.set_flux_bounds(r1, lb="zero", ub="ub_R1") fbc.set_flux_bounds(r2, lb="zero", ub="ub_default") fbc.set_flux_bounds(r3, lb="zero", ub="ub_default") # exchange reactions builder.create_exchange_reaction(model, species_id="A", flux_unit=UNIT_FLUX) builder.create_exchange_reaction(model, species_id="C", flux_unit=UNIT_FLUX) # objective function model_fbc = model.getPlugin("fbc") fbc.create_objective(model_fbc, oid="R3_maximize", otype="maximize", fluxObjectives={"R3": 1.0}, active=True) # create ports for kinetic bounds comp.create_ports(model, portType=comp.PORT_TYPE_PORT, idRefs=["ub_R1"]) # write SBML if annotations: annotator.annotate_sbml_doc(doc, annotations) sbml.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=True) return doc
def fba_model(sbml_file, directory): """ Create FBA submodel. """ # Read the model fba_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/ecoli_fba.xml') doc_fba = sbml.read_sbml(fba_path) # add comp doc_fba.enablePackage( "http://www.sbml.org/sbml/level3/version1/comp/version1", "comp", True) doc_fba.setPackageRequired("comp", True) # add notes model = doc_fba.getModel() fba_notes = notes.format("""DFBA FBA submodel.""") utils.set_model_info(model, notes=fba_notes, creators=None, units=units, main_units=main_units) # clip R_ reaction and M_ metabolite prefixes utils.clip_prefixes_in_model(model) # set id & framework model.setId('ecoli_fba') model.setName('ecoli (FBA)') model.setSBOTerm(comp.SBO_FLUX_BALANCE_FRAMEWORK) # add units and information for species in model.getListOfSpecies(): species.setInitialConcentration(0.0) species.setHasOnlySubstanceUnits(False) species.setUnits(UNIT_AMOUNT) for compartment in model.getListOfCompartments(): compartment.setUnits(UNIT_VOLUME) # The ATPM (atp maintainance reactions creates many problems in the DFBA) # mainly resulting in infeasible solutions when some metabolites run out. # ATP -> ADP is part of the biomass, so we set the lower bound to zero r_ATPM = model.getReaction('ATPM') r_ATPM_fbc = r_ATPM.getPlugin(builder.SBML_FBC_NAME) lb_id = r_ATPM_fbc.getLowerFluxBound() model.getParameter(lb_id).setValue(0.0) # 8.39 before # make unique upper and lower bounds for exchange reaction if not biomass_weighting: builder.update_exchange_reactions(model=model, flux_unit=UNIT_FLUX) else: builder.update_exchange_reactions(model=model, flux_unit=UNIT_FLUX_PER_G) # add exchange reaction for biomass (X) # we are adding the biomass component to the biomass function and create an # exchange reaction for it r_biomass = model.getReaction('BIOMASS_Ecoli_core_w_GAM') # FIXME: refactor in function # FIXME: annotate biomass species (SBO for biomass missing) mc.create_objects(model, [ mc.Parameter(sid='cf_X', value=1.0, unit="g_per_mmol", name="biomass conversion factor", constant=True), mc.Species(sid='X', initialAmount=0.001, compartment='c', name='biomass', substanceUnit='g', hasOnlySubstanceUnits=True, conversionFactor='cf_X') ]) pr_biomass = r_biomass.createProduct() pr_biomass.setSpecies('X') pr_biomass.setStoichiometry(1.0) pr_biomass.setConstant(True) # FIXME: the flux units must fit to the species units. if not biomass_weighting: builder.create_exchange_reaction(model, species_id='X', flux_unit=UNIT_FLUX, exchange_type=builder.EXCHANGE_EXPORT) else: builder.create_exchange_reaction(model, species_id='X', flux_unit=UNIT_FLUX_PER_G, exchange_type=builder.EXCHANGE_EXPORT) # write SBML file sbml.write_sbml(doc_fba, filepath=pjoin(directory, sbml_file), validate=True) # Set kinetic laws to zero for kinetic simulation ''' for reaction in model.getListOfReactions(): ast_node = mc.ast_node_from_formula(model=model, formula='0 {}'.format(UNIT_FLUX)) law = reaction.createKineticLaw() law.setMath(ast_node) ''' return doc_fba
# Compartments ############################################################## compartments.extend([ mc.Compartment(sid='ext', unit=UNIT_KIND_LITRE, constant=False, value=1.0, name='blood', port=True), mc.Compartment(sid='cyto', unit=UNIT_KIND_LITRE, constant=False, value='V_cyto', name='cytosol', port=True), mc.Compartment(sid='mito', unit=UNIT_KIND_LITRE, constant=False, value='V_mito', name='mitochondrion'), mc.Compartment(sid='pm', spatialDimensions=2, unit='m2', constant=True, value='1.0 m2', name='plasma membrane'), mc.Compartment(sid='mm', spatialDimensions=2, unit='m2', constant=True, value='1.0 m2', name='mitochondrial membrane'), ]) ############################################################## # Species ############################################################## species.extend([ mc.Species('Aatp', compartment='cyto', initialConcentration=2.8000, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='ATP'), mc.Species('Aadp', compartment='cyto', initialConcentration=0.8000, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='ADP'), mc.Species('Aamp', compartment='cyto', initialConcentration=0.1600, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='AMP'), mc.Species('Autp', compartment='cyto', initialConcentration=0.2700, unit='mmole', boundaryCondition=False, hasOnlySubstanceUnits=True, name='UTP'), mc.Species('Audp', compartment='cyto', initialConcentration=0.0900, unit='mmole', boundaryCondition=False, hasOnlySubstanceUnits=True, name='UDP'), mc.Species('Agtp', compartment='cyto', initialConcentration=0.2900, unit='mmole', boundaryCondition=False, hasOnlySubstanceUnits=True, name='GTP'), mc.Species('Agdp', compartment='cyto', initialConcentration=0.1000, unit='mmole', boundaryCondition=False, hasOnlySubstanceUnits=True, name='GDP'), mc.Species('Anad', compartment='cyto', initialConcentration=1.2200, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='NAD+'), mc.Species('Anadh', compartment='cyto', initialConcentration=0.56E-3, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='NADH'), mc.Species('Aphos', compartment='cyto', initialConcentration=5.0000, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='phosphate'), mc.Species('App', compartment='cyto', initialConcentration=0.0080, unit='mmole', boundaryCondition=False, hasOnlySubstanceUnits=True, name='pyrophosphate'), mc.Species('Aco2', compartment='cyto', initialConcentration=5.0000, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='CO2'), mc.Species('Ah2o', compartment='cyto', initialConcentration=0.0, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='H2O'), mc.Species('Ah', compartment='cyto', initialConcentration=0.0, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='H+'), mc.Species('Aglc1p', compartment='cyto', initialConcentration=0.0120, unit='mmole', boundaryCondition=False, hasOnlySubstanceUnits=True,
def test_modelcreator_notebook(): """ If this test fails the respective notebook must be updated: :return: """ import libsbml from libsbml import (UNIT_KIND_SECOND, UNIT_KIND_ITEM, UNIT_KIND_MOLE, UNIT_KIND_KILOGRAM, UNIT_KIND_METRE, UNIT_KIND_LITRE) from sbmlutils import comp from sbmlutils import fbc from sbmlutils import sbmlio from sbmlutils import factory as fac from sbmlutils.dfba import builder, utils main_units = { 'time': 's', 'extent': UNIT_KIND_ITEM, 'substance': UNIT_KIND_ITEM, 'length': 'm', 'area': 'm2', 'volume': 'm3', } units = [ fac.Unit('s', [(UNIT_KIND_SECOND, 1.0)]), fac.Unit('item', [(UNIT_KIND_ITEM, 1.0)]), fac.Unit('kg', [(UNIT_KIND_KILOGRAM, 1.0)]), fac.Unit('m', [(UNIT_KIND_METRE, 1.0)]), fac.Unit('m2', [(UNIT_KIND_METRE, 2.0)]), fac.Unit('m3', [(UNIT_KIND_METRE, 3.0)]), fac.Unit('mM', [(UNIT_KIND_MOLE, 1.0, 0), (UNIT_KIND_METRE, -3.0)]), fac.Unit('per_s', [(UNIT_KIND_SECOND, -1.0)]), fac.Unit('item_per_s', [(UNIT_KIND_ITEM, 1.0), (UNIT_KIND_SECOND, -1.0)]), fac.Unit('item_per_m3', [(UNIT_KIND_ITEM, 1.0), (UNIT_KIND_METRE, -3.0)]), ] UNIT_TIME = 's' UNIT_AMOUNT = 'item' UNIT_AREA = 'm2' UNIT_VOLUME = 'm3' UNIT_CONCENTRATION = 'item_per_m3' UNIT_FLUX = 'item_per_s' # Create SBMLDocument with fba doc = builder.template_doc_fba(model_id="toy") model = doc.getModel() utils.set_units(model, units) utils.set_main_units(model, main_units) objects = [ # compartments fac.Compartment(sid='extern', value=1.0, unit=UNIT_VOLUME, constant=True, name='external compartment', spatialDimensions=3), fac.Compartment(sid='cell', value=1.0, unit=UNIT_VOLUME, constant=True, name='cell', spatialDimensions=3), fac.Compartment(sid='membrane', value=1.0, unit=UNIT_AREA, constant=True, name='membrane', spatialDimensions=2), # exchange species fac.Species(sid='A', name="A", value=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=True, compartment="extern"), fac.Species(sid='C', name="C", value=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=True, compartment="extern"), # internal species fac.Species(sid='B1', name="B1", value=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=True, compartment="cell"), fac.Species(sid='B2', name="B2", value=0, substanceUnit=UNIT_AMOUNT, hasOnlySubstanceUnits=True, compartment="cell"), # bounds fac.Parameter(sid="ub_R1", value=1.0, unit=UNIT_FLUX, constant=True, sboTerm=builder.FLUX_BOUND_SBO), fac.Parameter(sid="zero", value=0.0, unit=UNIT_FLUX, constant=True, sboTerm=builder.FLUX_BOUND_SBO), fac.Parameter(sid="ub_default", value=builder.UPPER_BOUND_DEFAULT, unit=UNIT_FLUX, constant=True, sboTerm=builder.FLUX_BOUND_SBO), ] fac.create_objects(model, objects) # reactions r1 = fac.create_reaction(model, rid="R1", name="A import (R1)", fast=False, reversible=True, reactants={"A": 1}, products={"B1": 1}, compartment='membrane') r2 = fac.create_reaction(model, rid="R2", name="B1 <-> B2 (R2)", fast=False, reversible=True, reactants={"B1": 1}, products={"B2": 1}, compartment='cell') r3 = fac.create_reaction(model, rid="R3", name="B2 export (R3)", fast=False, reversible=True, reactants={"B2": 1}, products={"C": 1}, compartment='membrane') # flux bounds fbc.set_flux_bounds(r1, lb="zero", ub="ub_R1") fbc.set_flux_bounds(r2, lb="zero", ub="ub_default") fbc.set_flux_bounds(r3, lb="zero", ub="ub_default") # exchange reactions builder.create_exchange_reaction(model, species_id="A", flux_unit=UNIT_FLUX) builder.create_exchange_reaction(model, species_id="C", flux_unit=UNIT_FLUX) # objective function model_fbc = model.getPlugin("fbc") fac.create_objective(model_fbc, oid="R3_maximize", otype="maximize", fluxObjectives={"R3": 1.0}, active=True) # write SBML file import tempfile sbml_file = tempfile.NamedTemporaryFile(suffix=".xml") sbmlio.write_sbml(doc=doc, filepath=sbml_file.name)
value=1, unit=UNIT_KIND_LITRE, constant=True, name='urine'), ] ############################################################## # Species ############################################################## species = SPECIES for s_id, s_dict in SUBSTANCES.items(): for c_id, c_name in COMPARTMENTS.items(): species.append( mc.Species('A{}_{}'.format(c_id, s_id), 0, compartment="V{}".format(c_id), unit='mmole', name="{} ({})".format(s_dict['name'], c_name), hasOnlySubstanceUnits=True)) species.append( mc.Species('Aurine_{}'.format(s_id), 0, compartment="Vurine", unit='mmole', name="{} (urine)".format(s_dict['name']), hasOnlySubstanceUnits=True), ) ############################################################## # Parameters ############################################################## parameters = [ # whole body data