Example #1
0
def top_model(sbml_file, directory, emds, doc_fba=None, validate=True):
    """ Create 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>
    """)
    # Necessary to change into directory with submodel files
    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, time_unit=UNIT_TIME, create_port=False)

    # compartment
    compartment_id = "blood"
    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, unit_amount=UNIT_AMOUNT,
                                create_port=False)
    # dummy species
    builder.create_dummy_species(model, compartment_id=compartment_id, 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)

    # write SBML file
    sbmlio.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=validate)

    # change back into working dir
    os.chdir(working_dir)
def top_model(sbml_file, directory, emds, doc_fba=None, validate=True):
    """ Create 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>
    """)
    # Necessary to change into directory with submodel files
    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, time_unit=UNIT_TIME, create_port=False)

    # compartment
    compartment_id = "blood"
    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, unit_amount=UNIT_CONCENTRATION,
                                create_port=False)
    # dummy species
    builder.create_dummy_species(model, compartment_id=compartment_id, unit_amount=UNIT_CONCENTRATION)

    # 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)

    # write SBML file
    sbmlio.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=validate)

    # change back into working dir
    os.chdir(working_dir)
Example #3
0
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 = "cell"
    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=False,
                                unit_amount=UNIT_AMOUNT,
                                create_port=False)
    # dummy species
    builder.create_dummy_species(model,
                                 compartment_id=compartment_id,
                                 hasOnlySubstanceUnits=False,
                                 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)

    objects = [
        # kinetic parameters
        mc.Parameter(sid="Vmax_RATP", value=1, unit=UNIT_FLUX, constant=True),
        mc.Parameter(sid='k_RATP',
                     value=0.1,
                     unit=UNIT_CONCENTRATION,
                     constant=True),

        # balancing rules
        mc.AssignmentRule(sid="atp_tot",
                          value="atp + adp",
                          unit=UNIT_CONCENTRATION),
        mc.AssignmentRule(sid="c3_tot",
                          value="2 dimensionless * glc + pyr",
                          unit="mM")
    ]
    mc.create_objects(model, objects)

    ratp = mc.create_reaction(model,
                              rid="RATP",
                              name="atp -> adp",
                              fast=False,
                              reversible=False,
                              reactants={"atp": 1},
                              products={"adp": 1},
                              compartment=compartment_id,
                              formula='Vmax_RATP * atp/(k_RATP + atp)')

    # initial concentrations for fba exchange species
    initial_c = {'atp': 2.0, 'adp': 1.0, 'glc': 5.0, 'pyr': 0.0}
    for sid, value in initial_c.items():
        species = model.getSpecies(sid)
        species.setInitialConcentration(value)

    # write SBML file
    if annotations:
        annotator.annotate_sbml_doc(doc, annotations)
    sbmlio.write_sbml(doc,
                      filepath=os.path.join(directory, sbml_file),
                      validate=True)

    # change back the working dir
    os.chdir(working_dir)
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:
        annotation.annotate_sbml_doc(doc, annotations)
    sbmlio.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=True)

    # change back the working dir
    os.chdir(working_dir)
Example #5
0
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)
Example #6
0
def top_model(sbml_file, directory, emds, doc_fba=None):
    """ Create 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>
    """)
    # Necessary to change into directory with submodel files
    working_dir = os.getcwd()
    os.chdir(directory)

    model_id = "ecoli"
    doc = builder.template_doc_top(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, time_unit=UNIT_TIME, create_port=False)

    # compartment
    compartment_id = "bioreactor"
    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,
                                unit_amount=UNIT_AMOUNT,
                                create_port=False)

    # minimal medium with single carbon source
    initial_c = {
        'ac_e': 1.0,
        'acald_e': 1.0,
        'akg_e': 1.0,
        'co2_e': 1.0,
        'etoh_e': 1.0,
        'for_e': 1.0,
        'fru_e': 1.0,
        'fum_e': 1.0,
        'glc__D_e': 20.0,
        'gln__L_e': 10.0,
        'glu__L_e': 1.0,
        'h_e': 1.0,
        'h2o_e': 20.0,
        'lac__D_e': 1.0,
        'mal__L_e': 1.0,
        'nh4_e': 1.0,
        'o2_e': 1.0,
        'pi_e': 1.0,
        'pyr_e': 1.0,
        'succ_e': 1.0,
        'X': 0.001,
    }
    for sid, value in initial_c.items():
        species = model.getSpecies(sid)
        species.setInitialConcentration(value)

    # dummy species
    builder.create_dummy_species(model,
                                 compartment_id=compartment_id,
                                 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)

    # write SBML file
    sbml.write_sbml(doc,
                    filepath=os.path.join(directory, sbml_file),
                    validate=True)

    # change back into working dir
    os.chdir(working_dir)
def top_model(sbml_file, directory, emds, doc_fba=None, annotations=None):
    """
    Create diauxic comp model.
    Test script for working with the comp extension in SBML.

    One model composition combines all the kinetic models,
    in addition the higher level comp model is created which combines everything (i.e. the FBA & ODE models).
    For the simulation of the full combined model the tools have to figure out the subparts which are
    simulated with which simulation environment.
    Creates the full comp model as combination of FBA and comp models.

    The submodels must already exist in the given directory
    """
    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>
    """)
    # Necessary to change into directory with submodel files
    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, time_unit=UNIT_TIME, create_port=False)

    # compartment
    compartment_id = "bioreactor"
    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, unit_amount=UNIT_AMOUNT,
                                create_port=False)

    # dummy species
    builder.create_dummy_species(model, compartment_id=compartment_id, 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 kinetic concentrations
    initial_c = {
        'Glcxt': 10.8,
        'Ac': 0.4,
        'O2': 0.21,
        'X': 0.001,
    }
    for sid, value in initial_c.items():
        species = model.getSpecies(sid)
        species.setInitialConcentration(value)

    objects = [
        # biomass conversion factor
        # mc.Parameter(sid="Y", name="biomass [g_per_l]", value=1.0, unit="g_per_l"),
        # oxygen exchange parameters
        mc.Parameter(sid="O2_ref", name="O2 reference", value=0.21, unit=UNIT_CONCENTRATION),
        mc.Parameter(sid="kLa", name="O2 mass transfer", value=7.5, unit='per_h'),
    ]
    mc.create_objects(model, objects)

    # oxygen transfer reaction
    mc.create_reaction(model, rid="vO2_transfer", name="oxygen transfer", reversible=True,
                       reactants={}, products={"O2": 1}, formula="kLa * (O2_ref-O2) * bioreactor",
                       compartment="bioreactor")

    # write SBML file
    if annotations:
        annotation.annotate_sbml_doc(doc, annotations)
    sbmlio.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=True)

    # change back into working dir
    os.chdir(working_dir)
def top_model(sbml_file, directory, emds, doc_fba=None):
    """ Create 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>
    """)
    # Necessary to change into directory with submodel files
    working_dir = os.getcwd()
    os.chdir(directory)

    model_id = "ecoli"
    doc = builder.template_doc_top(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, time_unit=UNIT_TIME, create_port=False)

    # compartment
    compartment_id = "bioreactor"
    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, unit_amount=UNIT_AMOUNT, create_port=False)

    # minimal medium with single carbon source
    initial_c = {
        'ac_e': 1.0,
        'acald_e': 1.0,
        'akg_e': 1.0,
        'co2_e': 1.0,
        'etoh_e': 1.0,
        'for_e': 1.0,
        'fru_e': 1.0,
        'fum_e': 1.0,
        'glc__D_e': 20.0,
        'gln__L_e': 10.0,
        'glu__L_e': 1.0,
        'h_e': 1.0,
        'h2o_e': 20.0,
        'lac__D_e': 1.0,
        'mal__L_e': 1.0,
        'nh4_e': 1.0,
        'o2_e': 1.0,
        'pi_e': 1.0,
        'pyr_e': 1.0,
        'succ_e': 1.0,
        'X': 0.001,
    }
    for sid, value in initial_c.items():
        species = model.getSpecies(sid)
        species.setInitialConcentration(value)

    # dummy species
    builder.create_dummy_species(model, compartment_id=compartment_id, 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)

    # write SBML file
    sbmlio.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=True)

    # change back into working dir
    os.chdir(working_dir)
Example #9
0
def top_model(sbml_file, directory, emds, doc_fba=None, annotations=None):
    """
    Create diauxic comp model.
    Test script for working with the comp extension in SBML.

    One model composition combines all the kinetic models,
    in addition the higher level comp model is created which combines everything (i.e. the FBA & ODE models).
    For the simulation of the full combined model the tools have to figure out the subparts which are
    simulated with which simulation environment.
    Creates the full comp model as combination of FBA and comp models.

    The submodels must already exist in the given directory
    """
    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>
    """)
    # Necessary to change into directory with submodel files
    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, time_unit=UNIT_TIME, create_port=False)

    # compartment
    compartment_id = "bioreactor"
    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,
                                unit_amount=UNIT_AMOUNT,
                                create_port=False)

    # dummy species
    builder.create_dummy_species(model,
                                 compartment_id=compartment_id,
                                 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 kinetic concentrations
    initial_c = {
        'Glcxt': 10.8,
        'Ac': 0.4,
        'O2': 0.21,
        'X': 0.001,
    }
    for sid, value in initial_c.items():
        species = model.getSpecies(sid)
        species.setInitialConcentration(value)

    objects = [
        # biomass conversion factor
        # Parameter(sid="Y", name="biomass [g_per_l]", value=1.0, unit="g_per_l"),
        # oxygen exchange parameters
        Parameter(sid="O2_ref",
                  name="O2 reference",
                  value=0.21,
                  unit=UNIT_CONCENTRATION),
        Parameter(sid="kLa", name="O2 mass transfer", value=7.5, unit='per_h'),
    ]
    factory.create_objects(model, objects)

    # oxygen transfer reaction
    create_reaction(model,
                    rid="vO2_transfer",
                    name="oxygen transfer",
                    reversible=True,
                    reactants={},
                    products={"O2": 1},
                    formula="kLa * (O2_ref-O2) * bioreactor",
                    compartment="bioreactor")

    # write SBML file
    if annotations:
        annotator.annotate_sbml_doc(doc, annotations)
    sbmlio.write_sbml(doc,
                      filepath=os.path.join(directory, sbml_file),
                      validate=True)

    # change back into working dir
    os.chdir(working_dir)
Example #10
0
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 = "cell"
    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=False,
                                unit_amount=UNIT_AMOUNT, create_port=False)
    # dummy species
    builder.create_dummy_species(model, compartment_id=compartment_id, hasOnlySubstanceUnits=False,
                                 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)

    objects = [
        # kinetic parameters
        mc.Parameter(sid="Vmax_RATP", value=1, unit=UNIT_FLUX, constant=True),
        mc.Parameter(sid='k_RATP', value=0.1, unit=UNIT_CONCENTRATION, constant=True),

        # balancing rules
        mc.AssignmentRule(sid="atp_tot", value="atp + adp", unit=UNIT_CONCENTRATION),
        mc.AssignmentRule(sid="c3_tot", value="2 dimensionless * glc + pyr", unit="mM")
    ]
    mc.create_objects(model, objects)

    ratp = mc.create_reaction(model, rid="RATP", name="atp -> adp", fast=False, reversible=False,
                              reactants={"atp": 1}, products={"adp": 1}, compartment=compartment_id,
                              formula='Vmax_RATP * atp/(k_RATP + atp)')

    # initial concentrations for fba exchange species
    initial_c = {
        'atp': 2.0,
        'adp': 1.0,
        'glc': 5.0,
        'pyr': 0.0
    }
    for sid, value in initial_c.items():
        species = model.getSpecies(sid)
        species.setInitialConcentration(value)

    # write SBML file
    if annotations:
        annotation.annotate_sbml_doc(doc, annotations)
    sbmlio.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=True)

    # change back the working dir
    os.chdir(working_dir)