Example #1
0
def po_bolus(simulator, r):
    """ Oral bolus dose
    oral dose (single dose, at given start with given dose).
    Examples are the oral glucose tolerance test (OGTT) or the application of a drug orally,
    e.g., codeine, midazolam, caffeine or paracetamol.

    :return:
    """
    # set initial concentration of somatostatin in all blood compartments
    changes_init = pkpd.init_concentrations_changes(r, 'som', 0E-6)  # [0 nmol/L]

    # oral bolus dose
    # FIXME: dosing changesets
    changes_po_bolus = {
        'PODOSE_som': 10.0E-6,  # [mg]
    }

    # simulate
    tcsims = ensemble(
        TimecourseSim([
            Timecourse(start=0, end=1200, steps=600,
                       changes={
                           **changes_init,
                           **changes_po_bolus}
                       )
            ]),
        changeset=ChangeSet.parameter_sensitivity_changeset(r, 0.1)
    )
    return simulator.timecourses(tcsims)
def test_plotting():
    r = load_model(MODEL_REPRESSILATOR)
    simulator = Simulator(MODEL_REPRESSILATOR)

    changeset = ChangeSet.parameter_sensitivity_changeset(r, sensitivity=0.5)
    tcsims = ensemble(
        TimecourseSim([
            Timecourse(start=0, end=400, steps=400),
        ]), changeset)
    result = simulator.timecourses(tcsims)

    # create figure
    fig, (ax1) = plt.subplots(nrows=1, ncols=1, figsize=(5, 5))
    fig.subplots_adjust(wspace=0.3, hspace=0.3)

    add_line(ax=ax1, data=result, xid='time', yid="X", label="X")
    add_line(ax=ax1,
             data=result,
             xid='time',
             yid="Y",
             label="Y",
             color="darkblue")

    ax1.legend()
    plt.show()
Example #3
0
def run_parameter_scan(parallel=False):
    """Perform a parameter scan"""

    # [2] value scan
    scan_changeset = ChangeSet.scan_changeset('n',
                                              values=np.linspace(start=2,
                                                                 stop=10,
                                                                 num=8))
    tcsims = ensemble(sim=TimecourseSim([
        Timecourse(start=0, end=100, steps=100, changes={}),
        Timecourse(start=0, end=60, steps=100, changes={'[X]': 10}),
        Timecourse(start=0, end=60, steps=100, changes={'X': 10}),
    ]),
                      changeset=scan_changeset)
    print(tcsims[0])

    if parallel:
        simulator = SimulatorParallel(path=MODEL_REPRESSILATOR)
        results = simulator.timecourses(tcsims)
        assert isinstance(results, Result)

    else:
        simulator = SimulatorSerial(path=MODEL_REPRESSILATOR)
        results = simulator.timecourses(tcsims)
        assert isinstance(results, Result)

    return results
Example #4
0
def stepped_clamp(simulator, r):

    changes_init = pkpd.init_concentrations_changes(r, 'som', 0E-6)  # [0 nmol/L]
    tcsims = ensemble(
        TimecourseSim([
            Timecourse(start=0, end=60, steps=120, changes=changes_init),
            Timecourse(start=0, end=60, steps=120, changes={'Ri_som': 10.0E-6}),  # [mg/min],
            Timecourse(start=0, end=60, steps=120, changes={'Ri_som': 20.0E-6}),  # [mg/min],
            Timecourse(start=0, end=60, steps=120, changes={'Ri_som': 40.0E-6}),  # [mg/min],
            Timecourse(start=0, end=60, steps=120, changes={'Ri_som': 80.0E-6}),  # [mg/min],
        ]), ChangeSet.parameter_sensitivity_changeset(r, 0.1)
    )
    return simulator.timecourses(tcsims)
Example #5
0
def run_sensitivity():
    """ Parameter sensitivity simulations.

    :return:
    """
    simulator = Simulator(MODEL_REPRESSILATOR)

    # parameter sensitivity
    # FIXME: make work with parallel
    r = load_model(MODEL_REPRESSILATOR)
    changeset = ChangeSet.parameter_sensitivity_changeset(r)
    tc_sim = TimecourseSim([
        Timecourse(start=0, end=100, steps=100),
        Timecourse(start=0,
                   end=200,
                   steps=100,
                   model_changes={"boundary_condition": {
                       "X": True
                   }}),
        Timecourse(start=0,
                   end=100,
                   steps=100,
                   model_changes={"boundary_condition": {
                       "X": False
                   }}),
    ])
    tc_sims = ensemble(tc_sim, changeset=changeset)
    result = simulator.timecourses(tc_sims)

    # create figure
    fig, (ax1) = plt.subplots(nrows=1, ncols=1, figsize=(5, 5))
    fig.subplots_adjust(wspace=0.3, hspace=0.3)

    add_line(ax=ax1, data=result, xid='time', yid="X", label="X")
    add_line(ax=ax1,
             data=result,
             xid='time',
             yid="Y",
             label="Y",
             color="darkblue")
    add_line(ax=ax1,
             data=result,
             xid='time',
             yid="Z",
             label="Z",
             color="darkorange")

    ax1.legend()
    plt.show()
Example #6
0
def mix(simulator, r):
    """
    [5] combination experiments
    - somatostatin infusion + c-peptide bolus
    - hyperinsulinemic, euglycemic clamp
    """
    changes_init = pkpd.init_concentrations_changes(r, 'som', 0E-6)  # [0 nmol/L]
    tcsims = ensemble(
        TimecourseSim([
            Timecourse(start=0, end=60, steps=120, changes=changes_init),
            Timecourse(start=0, end=60, steps=120, changes={'IVDOSE_som': 10.0E-6}),
            Timecourse(start=0, end=60, steps=240, changes={'Ri_som': 10.0E-6}),  # [mg/min],
            Timecourse(start=0, end=60, steps=120, changes={'Ri_som': 10.0E-6, 'PODOSE_som': 10.0E-4}),
            Timecourse(start=0, end=120, steps=240, changes={'Ri_som': 0.0}),      # [mg/min],
        ]), ChangeSet.parameter_sensitivity_changeset(r, 0.1))

    return simulator.timecourses(tcsims)
Example #7
0
def iv_infusion(simulator, r):
    """ [3] constant infusion (for given period, tstart, tend)
        - somatostatin infusion
        - insulin infusion
        - glucose infusion
        - glucagon infusion

    :return:
    """
    changes_init = pkpd.init_concentrations_changes(r, 'som', 0E-6)  # [0 nmol/L]
    tcsims = ensemble(
        TimecourseSim([
            Timecourse(start=0, end=60, steps=120, changes=changes_init),
            Timecourse(start=0, end=120, steps=240, changes={'Ri_som': 10.0E-6}),  # [mg/min],
            Timecourse(start=0, end=120, steps=240, changes={'Ri_som': 0.0}),      # [mg/min],
        ]), ChangeSet.parameter_sensitivity_changeset(r, 0.1)
    )
    return simulator.timecourses(tcsims)
Example #8
0
def clamp(simulator, r):
    """
    clamping of substance (e.g. glucose, tstart, tend)
    - glucose clamping (euglycemic clamp)
    - insulin clamping (insulin clamp)

    :return:
    """
    changes_init = pkpd.init_concentrations_changes(r, 'som', 0E-6)  # [0 nmol/L]

    # FIXME: some bug in the concentrations and assignments
    tcsims = ensemble(
        TimecourseSim([
            Timecourse(start=0, end=60, steps=120, changes={**changes_init, **{'PODOSE_som': 1E-9}}),
            Timecourse(start=0, end=120, steps=240, model_changes={'boundary_condition': {"Ave_som": True}}), # clamp venous som
            Timecourse(start=0, end=120, steps=240, model_changes={'boundary_condition': {"Ave_som": False}}),   # release venous som,
        ]), ChangeSet.parameter_sensitivity_changeset(r, 0.1)
    )
    return simulator.timecourses(tcsims)
Example #9
0
def test_timecourse_ensemble():
    changeset = [
        {
            "[X]": 10.0
        },
        {
            "[X]": 15.0
        },
        {
            "[X]": 20.0
        },
        {
            "[X]": 25.0
        },
    ]
    simulator = Simulator(MODEL_REPRESSILATOR)
    tcsims = ensemble(TimecourseSim([
        Timecourse(start=0, end=400, steps=400),
    ]),
                      changeset=changeset)
    result = simulator.timecourses(tcsims)
    assert isinstance(result, Result)
Example #10
0
def iv_bolus(simulator, r):
    """ [2] bolus injection (at given time tstart, with given dose and given injection time, e.g. 5-10 min)
        - c-peptide bolus
        - ivGTT (glucose bolus)
        - insulin injection
    """
    changes_init = pkpd.init_concentrations_changes(r, 'som', 0E-6)  # [0 nmol/L]
    changes_iv_bolus = {
        'IVDOSE_som': 10E-6,  # [mg]
    }
    p_changeset = ChangeSet.parameter_sensitivity_changeset(r, 0.1)

    tcsims = ensemble(
        TimecourseSim([
            Timecourse(start=0, end=1200, steps=600,
                       changes={
                           **changes_init,
                           **changes_iv_bolus}
                       )
        ]), p_changeset)

    return simulator.timecourses(tcsims)