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()
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
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)
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()
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)
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)
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)
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)
color=color, label="sim {}".format(label)) else: x = data[xid] * xf ax.plot(x, data[yid], '-', color=color, label="sim {}".format(label)) if __name__ == "__main__": from sbmlsim.tests.constants import MODEL_REPRESSILATOR from sbmlsim.model import load_model from sbmlsim.parametrization import ChangeSet from sbmlsim.simulation_serial import TimecourseSimulation, Timecourse, timecourses r = load_model(MODEL_REPRESSILATOR) # parameter sensitivity changeset = ChangeSet.parameter_sensitivity_changeset(r, sensitivity=0.05) tc_sims = TimecourseSimulation([ 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 }}), ]).ensemble(changeset=changeset)
# FIXME: not sure if this is doing the correct thing or custom implementation of copy and deepcopy needed sim_new = deepcopy(sim) # changes are mixed in the first timecourse tc = sim_new.timecourses[0] for key, value in changes.items(): tc.add_change(key, value) sims.append(sim_new) return sims if __name__ == "__main__": tcsim = TimecourseSim([ Timecourse(0, 100, steps=101), Timecourse(0, 100, steps=101, changes={ 'k': 100, 'p': 200 }), Timecourse(0, 50, steps=51, changes={ 'k': 100, 'p': 50 }), ]) import numpy as np tcsims = ensemble(tcsim, changeset=ChangeSet.scan_changeset( "k2", np.linspace(0, 4, num=5))) for tcs in tcsims: print(tcs)