コード例 #1
0
def bounds_model(sbml_file, directory, doc_fba, annotations=None):
    """"
    Bounds model.
    """
    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>
    """)
    doc = builder.template_doc_bounds(settings.MODEL_ID)
    model = doc.getModel()
    utils.set_model_info(model,
                         notes=bounds_notes,
                         creators=creators,
                         units=units, main_units=main_units)

    builder.create_dfba_dt(model, step_size=DT_SIM, time_unit=UNIT_TIME, create_port=True)

    # compartment
    compartment_id = 'extern'
    builder.create_dfba_compartment(model, compartment_id=compartment_id, unit_volume=UNIT_VOLUME,
                                    create_port=True)

    # species
    model_fba = doc_fba.getModel()
    builder.create_dfba_species(model, model_fba, compartment_id=compartment_id, unit_amount=UNIT_AMOUNT,
                                hasOnlySubstanceUnits=True, create_port=True)

    # exchange bounds
    builder.create_exchange_bounds(model, model_fba=model_fba, unit_flux=UNIT_FLUX, create_ports=True)


    objects = [
        # exchange bounds
        # FIXME: readout the FBA network bounds
        mc.Parameter(sid="lb_default", value=builder.LOWER_BOUND_DEFAULT, unit=UNIT_FLUX, constant=True),

        # kinetic bound parameter & calculation
        mc.Parameter(sid='ub_R1', value=1.0, unit=UNIT_FLUX, constant=False, sboTerm="SBO:0000625"),
        mc.Parameter(sid='k1', value=-0.2, unit="per_s", name="k1", constant=False),
        mc.RateRule(sid="ub_R1", value="k1*ub_R1"),

        # bound assignment rules
        mc.AssignmentRule(sid="lb_EX_A", value='max(lb_default, -A/dt)'),
        mc.AssignmentRule(sid="lb_EX_C", value='max(lb_default, -C/dt)'),
    ]
    mc.create_objects(model, objects)

    # ports
    comp.create_ports(model, portType=comp.PORT_TYPE_PORT,
                      idRefs=["ub_R1"])
    if annotations:
        annotator.annotate_sbml_doc(doc, annotations)
    sbmlio.write_sbml(doc, filepath=os.path.join(directory, sbml_file), validate=True)
コード例 #2
0
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.
    """
    doc = builder.template_doc_bounds(settings.MODEL_ID)
    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 = "blood"
    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)

    # bounds
    builder.create_exchange_bounds(model, model_fba=model_fba, unit_flux=UNIT_FLUX, create_ports=True)

    # bounds
    fba_prefix = "fba"
    model_fba = doc_fba.getModel()
    objects = []
    ex_rids = utils.find_exchange_reactions(model_fba)
    for ex_rid, sid in ex_rids.items():
        r = model_fba.getReaction(ex_rid)

        # lower & upper bound parameters
        r_fbc = r.getPlugin(builder.SBML_FBC_NAME)
        lb_id = r_fbc.getLowerFluxBound()
        fba_lb_id = fba_prefix + lb_id
        lb_value = model_fba.getParameter(lb_id).getValue()

        objects.extend([
            # default bounds from fba
            mc.Parameter(sid=fba_lb_id, value=lb_value, unit=UNIT_FLUX, constant=False),
            # uptake bounds (lower bound)
            mc.AssignmentRule(sid=lb_id, value="max({}, -{}*{}/dt)".format(fba_lb_id, compartment_id, sid)),
        ])
    mc.create_objects(model, objects)

    sbmlio.write_sbml(doc, filepath=pjoin(directory, sbml_file), validate=True)
コード例 #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)
コード例 #4
0
                 '-',
                 constant=True,
                 name='volume fraction erythrocytes'),
]

##############################################################
# Assignments
##############################################################
assignments = []

##############################################################
# AssignmentRules
##############################################################
rules = [
    # volumes
    mc.AssignmentRule('Vrbc', 'Vpl * alpha', UNIT_KIND_LITRE),
]

##############################################################
# Reactions
##############################################################
reactions = [
    ReactionTemplate(
        rid="GLCIM",
        name="GLCIM (glc_ext -> glcRBC)",
        equation="glc_ext -> glcRBC",
        compartment='Vrbc',
        pars=[
            mc.Parameter('GLCIM_Vmax',
                         100,
                         'mmole_per_h',
コード例 #5
0
def xpp2sbml(
    xpp_file: Path,
    sbml_file: Path,
    force_lower: bool = False,
    validate: bool = True,
    debug: bool = False,
):
    """Reads given xpp_file and converts to SBML file.

    :param xpp_file: xpp input ode file
    :param sbml_file: sbml output file
    :param force_lower: force lower case for all lines
    :param validate: perform validation on the generated SBML file
    :return:
    """
    print("-" * 80)
    print("xpp2sbml: ", xpp_file, "->", sbml_file)
    print("-" * 80)
    doc = libsbml.SBMLDocument(3, 1)
    model = doc.createModel()

    parameters = []
    initial_assignments = []
    rate_rules = []
    assignment_rules = []
    functions = [
        # definition of min and max
        fac.Function("max",
                     "lambda(x,y, piecewise(x,gt(x,y),y) )",
                     name="minimum"),
        fac.Function("min",
                     "lambda(x,y, piecewise(x,lt(x,y),y) )",
                     name="maximum"),
        # heav (heavyside)
        fac.Function(
            "heav",
            "lambda(x, piecewise(0,lt(x,0), 0.5, eq(x, 0), 1,gt(x,0), 0))",
            name="heavyside",
        ),
        # mod (modulo)
        fac.Function("mod", "lambda(x,y, x % y)", name="modulo"),
    ]
    function_definitions = []
    events = []

    def replace_fdef():
        """ Replace all arguments within the formula definitions."""
        changes = False
        for k, fdata in enumerate(function_definitions):
            for i in range(len(function_definitions)):
                if i != k:
                    # replace i with k
                    formula = function_definitions[i]["formula"]
                    new_formula = xpp_helpers.replace_formula(
                        formula,
                        fid=function_definitions[k]["fid"],
                        old_args=function_definitions[k]["old_args"],
                        new_args=function_definitions[k]["new_args"],
                    )
                    if new_formula != formula:
                        function_definitions[i]["formula"] = new_formula
                        function_definitions[i]["new_args"] = list(
                            sorted(
                                set(function_definitions[i]["new_args"] +
                                    function_definitions[k]["new_args"])))
                        changes = True

        return changes

    def create_initial_assignment(sid, value):
        """ Helper for creating initial assignments """
        # check if valid identifier
        if "(" in sid:
            warnings.warn(
                "sid is not valid: {}. Initial assignment is not generated".
                format(sid))
            return

        try:
            f_value = float(value)
            parameters.append(
                fac.Parameter(
                    sid=sid,
                    value=f_value,
                    name="{} = {}".format(sid, value),
                    constant=False,
                ))
        except ValueError:
            """
            Initial data are optional, XPP sets them to zero by default (many xpp model don't write the p(0)=0.
            """
            parameters.append(
                fac.Parameter(sid=sid, value=0.0, name=sid, constant=False))
            initial_assignments.append(
                fac.InitialAssignment(sid=sid,
                                      value=value,
                                      name="{} = {}".format(sid, value)))

    ###########################################################################
    # First iteration to parse relevant lines and get the replacement patterns
    ###########################################################################
    parsed_lines = []
    # with open(xpp_file, encoding="utf-8") as f:
    with open(xpp_file) as f:
        lines = f.readlines()

        # add info to sbml
        text = escape_string("".join(lines))
        fac.set_notes(model, NOTES.format(text))

        old_line = None
        for line in lines:
            if force_lower:
                line = line.lower()

            # clean up the ends
            line = line.rstrip("\n").strip()
            # handle douple continuation characters in some models
            line = line.replace("\\\\", "\\")
            # handle semicolons
            line = line.rstrip(";")

            # join continuation
            if old_line:
                line = old_line + line
                old_line = None

            # empty line
            if len(line) == 0:
                continue
            # comment line
            if line[0] in XPP_COMMENT_CHARS:
                continue
            # xpp setting
            if line.startswith(XPP_SETTING_CHAR):
                continue
            # end word
            if line == XPP_END_WORD:
                continue
            # line continuation
            if line.endswith(XPP_CONTINUATION_CHAR):
                old_line = line.rstrip(XPP_CONTINUATION_CHAR)
                continue

            # handle the power function
            line = line.replace("**", "^")

            # handle if(...)then(...)else()
            pattern_ite = re.compile(
                r"if\s*\((.*)\)\s*then\s*\((.*)\)\s*else\s*\((.*)\)")
            pattern_ite_sub = re.compile(
                r"if\s*\(.*\)\s*then\s*\(.*\)\s*else\s*\(.*\)")
            groups = re.findall(pattern_ite, line)
            for group in groups:
                condition = group[0]
                assignment = group[1]
                otherwise = group[2]
                f_piecewise = "piecewise({}, {}, {})".format(
                    assignment, condition, otherwise)
                line = re.sub(pattern_ite_sub, f_piecewise, line)

            ################################
            # Function definitions
            ################################
            """ Functions are defined in xpp via fid(arguments) = formula
            f(x,y) = x^2/(x^2+y^2)
            They can have up to 9 arguments.
            The difference to SBML functions is that xpp functions have access to the global parameter values
            """
            f_pattern = re.compile(r"(.*)\s*\((.*)\)\s*=\s*(.*)")
            groups = re.findall(f_pattern, line)
            if groups:
                # function definitions found
                fid, args, formula = groups[0]
                # handles the initial assignments which look like function definitions
                if args == "0":
                    parsed_lines.append(line)
                    continue

                # necessary to find the additional arguments from the ast_node
                ast = libsbml.parseL3Formula(formula)
                names = set(xpp_helpers.find_names_in_ast(ast))
                old_args = [t.strip() for t in args.split(",")]
                new_args = [a for a in names if a not in old_args]

                # handle special functions
                if fid == "power":
                    warnings.warn(
                        "power function cannot be added to model, rename function."
                    )
                else:
                    # store functions with additional arguments
                    function_definitions.append({
                        "fid": fid,
                        "old_args": old_args,
                        "new_args": new_args,
                        "formula": formula,
                    })
                # don't append line, function definition has been handeled
                continue

            parsed_lines.append(line)
    if debug:
        print("\n\nFUNCTION_DEFINITIONS")
        pprint(function_definitions)

    # functions can use functions so this also must be replaced
    changes = True
    while changes:
        changes = replace_fdef()

    # clean the new arguments
    for fdata in function_definitions:
        fdata["new_args"] = list(sorted(set(fdata["new_args"])))

    if debug:
        print("\nREPLACED FUNCTION_DEFINITIONS")
        pprint(function_definitions)

    # Create function definitions
    for k, fdata in enumerate(function_definitions):
        fid = fdata["fid"]
        formula = fdata["formula"]
        arguments = ",".join(fdata["old_args"] + fdata["new_args"])
        functions.append(
            fac.Function(fid, "lambda({}, {})".format(arguments, formula)), )

    ###########################################################################
    # Second iteration
    ###########################################################################
    if debug:
        print("\nPARSED LINES")
        pprint(parsed_lines)
        print("\n\n")
    for line in parsed_lines:

        # replace function definitions in lines
        new_line = line
        for fdata in function_definitions:
            new_line = xpp_helpers.replace_formula(new_line, fdata["fid"],
                                                   fdata["old_args"],
                                                   fdata["new_args"])

        if new_line != line:
            if False:
                print("\nReplaced FD", fdata["fid"], ":", new_line)
                print("->", new_line, "\n")
            line = new_line

        if debug:
            # line after function replacements
            print("*" * 3, line, "*" * 3)

        ################################
        # Start parsing the given line
        ################################
        # check for the equal sign
        tokens = line.split("=")
        tokens = [t.strip() for t in tokens]

        #######################
        # Line without '=' sign
        #######################
        # wiener
        if len(tokens) == 1:
            items = [t.strip() for t in tokens[0].split(" ") if len(t) > 0]
            # keyword, value
            if len(items) == 2:
                xid, sid = items[0], items[1]
                xpp_type = parse_keyword(xid)

                # wiener
                if xpp_type == XPP_WIE:
                    """Wiener parameters are normally distributed numbers with zero mean
                    and unit standard deviation. They are useful in stochastic simulations since
                    they automatically scale with change in the integration time step.
                    Their names are listed separated by commas or spaces."""
                    # FIXME: this should be encoded using dist
                    parameters.append(fac.Parameter(sid=sid, value=0.0))
                    continue  # line finished
            else:
                warnings.warn("XPP line not parsed: '{}'".format(line))

        #####################
        # Line with '=' sign
        #####################
        # parameter, aux, ode, initial assignments
        elif len(tokens) >= 2:
            left = tokens[0]
            items = [t.strip() for t in left.split(" ") if len(t) > 0]
            # keyword based information, i.e 2 items are on the left of the first '=' sign
            if len(items) == 2:
                xid = items[0]  # xpp keyword
                xpp_type = parse_keyword(xid)
                expression = (" ".join(items[1:]) + "=" + "=".join(tokens[1:])
                              )  # full expression after keyword
                parts = parts_from_expression(expression)
                if False:
                    print("xid:", xid)
                    print("expression:", expression)
                    print("parts:", parts)

                # parameter & numbers
                if xpp_type in [XPP_PAR, XPP_NUM]:
                    """Parameter values are optional; if not they are set to zero.
                    Number declarations are like parameter declarations, except that they cannot be
                    changed within the program and do not appear in the parameter window."""
                    for part in parts:
                        sid, value = sid_value_from_part(part)
                        create_initial_assignment(sid, value)

                # aux
                elif xpp_type == XPP_AUX:
                    """Auxiliary quantities are expressions that depend on all of your dynamic
                    variables which you want to keep track of. Energy is one such example. They are declared
                    like fixed quantities, but are prefaced by aux ."""
                    for part in parts:
                        sid, value = sid_value_from_part(part)
                        if sid == value:
                            # avoid circular dependencies (no information in statement)
                            pass
                        else:
                            assignment_rules.append(
                                fac.AssignmentRule(sid=sid, value=value))

                # init
                elif xpp_type == XPP_INIT:
                    for part in parts:
                        sid, value = sid_value_from_part(part)
                        create_initial_assignment(sid, value)

                # table
                elif xpp_type == XPP_TAB:
                    """The Table declaration allows the user to specify a function of 1 variable in terms
                    of a lookup table which uses linear interpolation. The name of the function follows the
                    declaration and this is followed by (i) a filename (ii) or a function of "t"."""
                    warnings.warn(
                        "XPP_TAB not supported: XPP line not parsed: '{}'".
                        format(line))

                else:
                    warnings.warn("XPP line not parsed: '{}'".format(line))

            elif len(items) >= 2:
                xid = items[0]
                xpp_type = parse_keyword(xid)
                # global
                if xpp_type == XPP_GLO:
                    """Global flags are expressions that signal events when they change sign, from less than
                    to greater than zero if sign=1 , greater than to less than if sign=-1 or either way
                    if sign=0. The condition should be delimited by braces {} The events are of the form
                    variable=expression, are delimited by braces, and separated by semicolons. When the
                    condition occurs all the variables in the event set are changed possibly discontinuously.
                    """

                    # global sign {condition} {name1 = form1; ...}
                    pattern_global = re.compile(
                        r"([+,-]{0,1}\d{1})\s+\{{0,1}(.*)\{{0,1}\s+\{(.*)\}")
                    groups = re.findall(pattern_global, line)
                    if groups:
                        g = groups[0]
                        sign = int(g[0])
                        trigger = g[1]
                        # FIXME: handle sign=-1, sign=0, sign=+1
                        if sign == -1:
                            trigger = g[1] + ">= 0"
                        elif sign == 1:
                            trigger = g[1] + ">= 0"
                        elif sign == 0:
                            trigger = g[1] + ">= 0"

                        assignment_parts = [t.strip() for t in g[2].split(";")]
                        assignments = {}
                        for p in assignment_parts:
                            key, value = p.split("=")
                            assignments[key] = value

                        events.append(
                            fac.Event(
                                sid="e{}".format(len(events)),
                                trigger=trigger,
                                assignments=assignments,
                            ))

                    else:
                        warnings.warn(
                            "global expression could not be parsed: {}".format(
                                line))
                else:
                    warnings.warn("XPP line not parsed: '{}'".format(line))

            # direct assignments
            elif len(items) == 1:
                right = tokens[1]

                # init
                if left.endswith("(0)"):
                    sid, value = left[0:-3], right
                    create_initial_assignment(sid, value)

                # difference equations
                elif left.endswith("(t+1)"):
                    warnings.warn(
                        "Difference Equations not supported: XPP line not parsed: '{}'"
                        .format(line))

                # ode
                elif left.endswith("'"):
                    sid = left[0:-1]
                    rate_rules.append(fac.RateRule(sid=sid, value=right))
                elif left.endswith("/dt"):
                    sid = left[1:-3]
                    rate_rules.append(fac.RateRule(sid=sid, value=right))
                # assignment rules
                else:
                    assignment_rules.append(
                        fac.AssignmentRule(sid=left, value=right))
            else:
                warnings.warn("XPP line not parsed: '{}'".format(line))

    # add time
    assignment_rules.append(
        fac.AssignmentRule(sid="t", value="time", name="model time"))

    # create SBML objects
    objects = (parameters + initial_assignments + functions + rate_rules +
               assignment_rules + events)
    fac.create_objects(model, obj_iter=objects, debug=False)
    """
    Parameter values are optional; if not they are set to zero in xpp.
    Many models do not encode the initial zeros.
    """
    for p in doc.getModel().getListOfParameters():
        if not p.isSetValue():
            p.setValue(0.0)

    sbml.write_sbml(
        doc,
        sbml_file,
        validate=validate,
        program_name="sbmlutils",
        program_version=__version__,
        units_consistency=False,
    )
コード例 #6
0

##############################################################
# Assignments
##############################################################
assignments = []

##############################################################
# AssignmentRules
##############################################################
rules = []
# add concentrations
for s in species:

    rules.append(
        mc.AssignmentRule(f'C{s.sid[1:]}', f'{s.sid}/{s.compartment}',
                          'mM', name=f'{s.name} concentration ({s.compartment})'),
    )

##############################################################
# Reactions
##############################################################
reactions = [

    ReactionTemplate(
        rid="GLCIM",
        name="GLCIM (glc_ext <-> glc)",
        equation="Aext_glc <-> Ali_glc",
        compartment='Vli',
        pars=[
            mc.Parameter('GLCIM_Vmax', 1E3, 'mmole_per_hl',
                         name='Glucose utilization brain'),
コード例 #7
0
ファイル: Reactions.py プロジェクト: mdziurzynski/sbmlutils
    # C6H1206 (0) + C10H12N5O13P3 (-4)  <-> C6H11O9P (-2) + C10H12N5O10P2 (-3) + H (1)
    compartment='cyto',
    pars=[
        mc.Parameter('GK_n_gkrp', 2, 'dimensionless'),
        mc.Parameter('GK_k_glc1', 15, 'mM'),
        mc.Parameter('GK_k_fru6p', 0.010, 'mM'),
        mc.Parameter('GK_b', 0.7, 'dimensionless'),
        mc.Parameter('GK_n', 1.6, 'dimensionless'),
        mc.Parameter('GK_k_glc', 7.5, 'mM'),
        mc.Parameter('GK_k_atp', 0.26, 'mM'),
        mc.Parameter('GK_Vmax', 25.2, 'mmole_per_min'),
    ],
    rules=[
        mc.AssignmentRule(
            'GK_gc_free',
            '(glc^GK_n_gkrp / (glc^GK_n_gkrp + GK_k_glc1^GK_n_gkrp) ) * '
            '(1 dimensionless - GK_b*fru6p/(fru6p + GK_k_fru6p))',
            'dimensionless'),
    ],
    formula=
    ('f_gly * GK_Vmax * GK_gc_free * (atp/(GK_k_atp + atp)) * (glc^GK_n/(glc^GK_n + GK_k_glc^GK_n))',
     'mmole_per_min'))

G6PASE = ReactionTemplate(
    rid='G6PASE',
    name='D-Glucose-6-phosphate Phosphatase',
    equation='Aglc6p + Ah2o => Aglc + Aphos []',
    # C6H11O9P (-2) + H2O (0) -> C6H12O6 (0) + HO4P (-2)
    compartment='cyto',
    pars=[
        mc.Parameter('G6PASE_k_glc6p', 2, 'mM'),
コード例 #8
0
    mc.Species('Aadp_mito', compartment='mito', initialConcentration=0.8000, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='ADP'),
    mc.Species('Agtp_mito', compartment='mito', initialConcentration=0.2900, unit='mmole', boundaryCondition=False, hasOnlySubstanceUnits=True, name='GTP'),
    mc.Species('Agdp_mito', compartment='mito', initialConcentration=0.1000, unit='mmole', boundaryCondition=False, hasOnlySubstanceUnits=True, name='GDP'),
    mc.Species('Acoa_mito', compartment='mito', initialConcentration=0.0550, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='coenzyme A'),
    mc.Species('Anadh_mito', compartment='mito', initialConcentration=0.2400, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='NADH'),
    mc.Species('Anad_mito', compartment='mito', initialConcentration=0.9800, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='NAD+'),
    mc.Species('Ah2o_mito', compartment='mito', initialConcentration=0.0, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='H20'),
    mc.Species('Ah_mito', compartment='mito', initialConcentration=0.0, unit='mmole', boundaryCondition=True, hasOnlySubstanceUnits=True, name='H+'),
])
# ---------------------------------
# Concentration
# ---------------------------------
for s in species:
    aid = s.sid[1:]
    rules.append(
        mc.AssignmentRule(f'{aid}', f'{s.sid}/{s.compartment}', 'mM', name=f'{s.name} concentration'),
    )

##############################################################
# Parameters
##############################################################
parameters.extend([
    mc.Parameter('V_cyto', 1.0, UNIT_KIND_LITRE, True, name='cytosolic volume'),
    mc.Parameter('f_mito', 0.2, 'dimensionless', True, name='mitochondrial volume factor'),
    mc.Parameter('Vliver', 1.5, UNIT_KIND_LITRE, True, name='liver volume'),
    mc.Parameter('fliver', 0.583333333333334, 'dimensionless', True, name='parenchymal fraction liver'),
    mc.Parameter('bodyweight', 70, 'kg', True, name='bodyweight'),

    mc.Parameter('sec_per_min', 60, 's_per_min', True, name='time conversion'),
    mc.Parameter('mumole_per_mmole', 1000, 'mumole_per_mmole', True, name='amount conversion'),
コード例 #9
0
##############################################################
# Assignments
##############################################################
assignments = [
    mc.InitialAssignment('Ave_caf', 'IVDOSE_caf', 'mg'),
    mc.InitialAssignment('D_caf', 'PODOSE_caf', 'mg'),
    mc.InitialAssignment('Ave_px', 'IVDOSE_px', 'mg'),
    mc.InitialAssignment('D_px', 'PODOSE_px', 'mg'),
]

##############################################################
# Rules
##############################################################
rules = [
    # absorption px identical to caf
    mc.AssignmentRule('Ka_px', 'Ka_caf', 'per_h'),

    # clearance of px relative to caf (both via Cyp1a2)
    mc.AssignmentRule('HLM_CLint_px', 'fcl_px_caf*HLM_CLint_caf',
                      'mulitre_per_min_mg'),

    # volumes
    mc.AssignmentRule('Vgu', 'BW*FVgu', UNIT_KIND_LITRE),
    mc.AssignmentRule('Vki', 'BW*FVki', UNIT_KIND_LITRE),
    mc.AssignmentRule('Vli', 'BW*FVli', UNIT_KIND_LITRE),
    mc.AssignmentRule('Vlu', 'BW*FVlu', UNIT_KIND_LITRE),
    mc.AssignmentRule('Vsp', 'BW*FVsp', UNIT_KIND_LITRE),
    mc.AssignmentRule('Vve', 'BW*FVve', UNIT_KIND_LITRE),
    mc.AssignmentRule('Var', 'BW*FVar', UNIT_KIND_LITRE),
    mc.AssignmentRule('Vpl', 'BW*FVpl', UNIT_KIND_LITRE),
    mc.AssignmentRule('Vre', 'BW*FVre', UNIT_KIND_LITRE),
コード例 #10
0
    mc.RateRule('Gp', 'EGP +Ra -U_ii -E -k_1*Gp +k_2*Gt', 'mg_per_kgmin'),
    mc.RateRule('Gt', '-U_id + k_1*Gp -k_2*Gt', 'mg_per_kgmin'),
    mc.RateRule('Il', '-(m_1+m_3)*Il + m_2*Ip + S', 'pmol_per_kg'),
    mc.RateRule('Ip', '-(m_2+m_4)*Ip + m_1*Il', 'pmol_per_kg'),
    mc.RateRule('Qsto1', '-k_gri*Qsto1', '?'),
    mc.RateRule('Qsto2', '(-k_empt*Qsto2)+k_gri*Qsto1', '?'),
    mc.RateRule('Qgut', '(-k_abs*Qgut)+k_empt*Qsto2', '?'),
    mc.RateRule('I1', '-k_i*(I1-I)', '?'),
    mc.RateRule('Id', '-k_i*(Id-I1)', '?'),
    mc.RateRule('INS', '(-p_2U*INS)+p_2U*(I-I_b)', '?'),
    mc.RateRule('Ipo', '(-gamma*Ipo)+S_po', '?'),
    mc.RateRule('Y', '-alpha*(Y-beta*(G-G_b))', '?'),
]

rules = [
    mc.AssignmentRule('aa', '5/2/(1-b)/D', '?'),
    mc.AssignmentRule('cc', '5/2/d/D', '?'),
    mc.AssignmentRule('EGP',
                      'k_p1-k_p2*Gp-k_p3*Id-k_p4*Ipo',
                      'mg_per_kgmin',
                      name='EGP endogenous glucose production'),
    mc.AssignmentRule('V_mmax', '(1-part)*(V_m0+V_mX*INS)', '?'),
    mc.AssignmentRule('V_fmax', 'part*(V_f0+V_fX*INS)', '?'),
    mc.AssignmentRule('E', '0', 'mg_per_kgmin', 'renal excretion'),
    mc.AssignmentRule('S',
                      'gamma*Ipo',
                      'pmol_per_kgmin',
                      name='S insulin secretion'),
    mc.AssignmentRule('I', 'Ip/V_I', 'pmol_per_l', name='I plasma insulin'),
    mc.AssignmentRule('G', 'Gp/V_G', 'mg_per_dl', name='G plasma Glucose'),
    mc.AssignmentRule('HE',
コード例 #11
0
                    unit='-',
                    constant=True,
                    name='{} plasma partition coefficient'.format(c_name)))

##############################################################
# Assignments
##############################################################
assignments = []

##############################################################
# AssignmentRules
##############################################################
rules = [
    # Rest body volume
    mc.AssignmentRule(
        'FVre',
        '1.0 litre_per_kg - (FVgu + FVki + FVli + FVlu + FVsp + FVve + FVar + FVpl)',
        'litre_per_kg'),
    # Rest body perfusion
    mc.AssignmentRule('FQre', '1.0 dimensionless - (FQgu + FQki + FQh + FQsp)',
                      'dimensionless'),

    # Body surface area (Haycock1978)
    mc.AssignmentRule(
        'BSA',
        '0.024265 m2 * power(BW/1 kg, 0.5378) * power(HEIGHT/1 cm, 0.3964)',
        'm2'),

    # cardiac output (depending on heart rate and bodyweight)
    mc.AssignmentRule('CO', 'BW*COBW + (HR-HRrest)*COHRI / 60 s_per_min',
                      'ml_per_s'),
    # cardiac output (depending on bodyweight)