def run_fermentor(): system = { 'dS': 'Q_in/V*(S_in-S)-1/Ys*mu_max*S/(S+K_S)*X', 'dX': '-Q_in/V*X+mu_max*S/(S+K_S)*X' } parameters = { 'mu_max': 0.4, 'K_S': 0.015, 'Q_in': 2, 'Ys': 0.67, 'S_in': 0.02, 'V': 20 } M_fermentor = Model('fermentor', system, parameters) M_fermentor.independent = {'t': np.linspace(0, 100, 5000)} M_fermentor.initial_conditions = {'S': 0.02, 'X': 5e-5} sens_numeric = NumericalLocalSensitivity(M_fermentor, parameters=['mu_max', 'K_S']) sens_analytic = DirectLocalSensitivity(M_fermentor, parameters=['mu_max', 'K_S']) #sens_out = sens.get_sensitivity() pert_factors = 10.**np.arange(-14, 0, 1) out_fig = sens.calc_quality_num_lsa(pert_factors) return out_fig, sens_numeric, sens_analytic
def michaelis_menten(): system = {'v': 'Vmax*S/(Ks + S)', 'dS': '-v', 'dP': 'v'} parameters = {'Vmax': 1e-1, 'Ks': 0.5} MMmodel = Model('MichaelisMenten', system, parameters) MMmodel.initial_conditions = {'S': 0.5, 'P': 0.0} MMmodel.independent = {'t': np.linspace(0, 72, 1000)} MMmodel.initialize_model() return MMmodel
def run_second_order(): ''' y'' + 2*tau*omega*y' + omega**2*y = omega**2*K*u x1 = y x1' = y' = x2 x2' = y''= -2*tau*omega*x2 - omega**2*x1 + K*omega**2 ''' parameters = {'K': 0.01, 'tau': 0.3, 'omega': 0.6} # mM system = { 'dx1': 'x2', 'dx2': '-2*tau*omega*x2 - (omega**2)*x1 + K*omega**2' } M1 = Model('second_order', system, parameters) M1.initial_conditions = {'x1': 0, 'x2': 0} M1.independent = {'t': np.linspace(0, 20, 10000)} M1.initialize_model() return M1.run()['x1'].values
def test_alg_state(): system = {'dP': 'k1 * P', 'dS': 'k2 * S', 'A': 'P + S'} parameters = {'k1': -0.2, 'k2': 1.0} model = Model('simple_test', system, parameters) x = np.linspace(0, 10, 11) model.initial_conditions = {'P': 50, 'S': 10} model.independent = {'t': x} result = model.run() # expected output (analytical solution) S = 10 * np.exp(1.0 * x) P = 50 * np.exp(-0.2 * x) expected = pd.DataFrame({'P': P, 'S': S}, index=x) expected['A'] = expected['S'] + expected['P'] expected.index.names = ['t'] assert_frame_equal(result, expected.reindex(columns=result.columns))
def test_alg_substitution(): system = {'dP': 'k1 * P + A', 'dS': 'k2 * S', 'A': 'S + P'} parameters = {'k1': -0.5, 'k2': 1.0} model = Model('simple_test', system, parameters) x = np.linspace(0, 10, 11) model.initial_conditions = {'P': 50, 'S': 10} model.independent = {'t': x} result = model.run() # expected output (analytical solution) k1, k2 = -0.5, 1.0 S = 10 * np.exp(k2 * x) P = 10 * (np.exp((k1 + 1)*x) - np.exp((k2)*x)) / (k1 - k2 + 1) \ + 50 * np.exp((k1 + 1)*x) expected = pd.DataFrame({'S': S, 'P': P}, index=x) expected['A'] = expected['S'] + expected['P'] expected.index.names = ['t'] assert_frame_equal(result, expected.reindex(columns=result.columns))
system = { 'dS': 'Q_in/V*(S_in-S)-1/Ys*mu_max*S/(S+K_S)*X', 'dX': '-Q_in/V*X+mu_max*S/(S+K_S)*X' } parameters = { 'mu_max': 0.4, 'K_S': 0.015, 'Q_in': 2, 'Ys': 0.67, 'S_in': 0.02, 'V': 20 } M1 = Model('ode', system, parameters) M1.independent = {'t': np.linspace(0, 100, 5000)} M1.initial_conditions = {'S': 0.02, 'X': 5e-5} result = M1._run() def test_model(): assert_almost_equal(result[-1, 0], 0.0049996401543859316, decimal=5) assert_almost_equal(result[-1, 1], 0.010050542322437175, decimal=5) if __name__ == "__main__": test_model()
def LSA_comparison(): # Plain ping-pong bi-bi kinetics ping_pong = ('(Vf*Vr*(MBA*Pyr-Ace*Ala/Keq))/(Vr*Km*Pyr + Vr*Kp*MBA +' 'Vr*Pyr*MBA + Vf*Kac*Ala/Keq + Vf*Kal*Ace/Keq +' 'Vf*Ace*Ala/Keq + Vr*Km*Pyr*Ala/Kialp +' 'Vf*Kal*MBA*Ace/(Keq*Kimp))') # Replace reactants of Shin & Kim by current reactants ping_pong = ping_pong.replace('MBA', 'IPA') # IPA = isopropylamine ping_pong = ping_pong.replace('Pyr', 'BA') # BA = benzylacetone ping_pong = ping_pong.replace('Ace', 'ACE') # ACE = acetone ping_pong = ping_pong.replace('Ala', 'MPPA') # MPPA = # Define system of interest system = { 'v': ping_pong, 'Keq': '((Vf/Vr)**2)*(Kac*Kal)/(Km*Kp)', 'dE': '-decay*E', 'dIPA': '-v*E', 'dBA': '-v*E', 'dACE': 'v*E', 'dMPPA': 'v*E' } # Define all model parameters parameters = { # Forward reaction parameters calibrated with data ULUND 'Vf': 2.47e-2, # umol/U/min 'Km': 143.18, # mM 'Kp': 3.52, # mM # Backward reaction parameters calibrated with data UGENT 'Vr': 1.996e-2, # umol/U/min 'Kac': 207.64, # mM 'Kal': 2.301, # mM # Remaining parameters to calibrate (first guess) 'Kialp': 1.39889, # mM 'Kimp': 2.9295, # mM 'decay': 0.00302837 } # 1/min # Make model instance M1 = Model('PPBB', system, parameters) res_time = 0.01 / 1.66e-4 / 2. # Set independent (time) range M1.independent = {'t': np.linspace(0, res_time, 1000)} # Set initial conditions M1.initial_conditions = { 'IPA': 65., 'BA': 5., 'ACE': 0., 'MPPA': 0., 'E': 0.68 } # Initialize model => Generate underlying functions M1.initialize_model() # DirectLocalSensitivity instance M1sens_dir = DirectLocalSensitivity(M1, parameters=['Kp', 'Vf', 'Km', 'Kal']) # NumericalLocalSensitivity instance M1sens_num = NumericalLocalSensitivity( M1, parameters=['Kp', 'Vf', 'Km', 'Kal']) M1sens_num.perturbation = 1e-5 # Calculate direct sensitivity dir_sens = M1sens_dir.get_sensitivity(method='PRS') # Calculate numerical sensivity num_sens = M1sens_num.get_sensitivity(method='PRS') return dir_sens, num_sens
def run_modsim_models(): # Data file_path = os.path.join(pyideas.BASE_DIR, '..', 'examples', 'data', 'grasdata.csv') data = pd.read_csv(file_path, header=0, names=['t', 'W']) data = data.set_index('t') measurements = Measurements(data) measurements.add_measured_errors({'W': 1.0}, method='absolute') # Logistic parameters = {'W0': 2.0805, 'Wf': 9.7523, 'mu': 0.0659} system = {'W': 'W0*Wf/(W0+(Wf-W0)*exp(-mu*t))'} M1 = Model('Modsim1', system, parameters) M1.independent = {'t': np.linspace(0, 72, 1000)} M1.initialize_model() # Perform parameter estimation M1optim = ParameterOptimisation(M1, measurements) M1optim.local_optimize() # Calc parameter uncertainty M1conf = CalibratedConfidence(M1optim) FIM1 = M1conf.get_FIM() # Exponential parameters = {'Wf': 10.7189, 'mu': 0.0310} system = {'W': 'Wf*(1-exp(-mu*t))'} M2 = Model('Modsim2', system, parameters) M2.independent = {'t': np.linspace(0, 72, 1000)} # Perform parameter estimation M2optim = ParameterOptimisation(M2, measurements) M2optim.local_optimize() # Calc parameter uncertainty M2conf = CalibratedConfidence(M2optim) FIM2 = M2conf.get_FIM() # Gompertz parameters = {'W0': 2.0424, 'D': 0.0411, 'mu': 0.0669} system = {'W': 'W0*exp((mu*(1-exp(-D*t)))/(D))'} M3 = Model('Modsim3', system, parameters) M3.independent = {'t': np.linspace(0, 72, 1000)} # Perform parameter estimation M3optim = ParameterOptimisation(M3, measurements) M3optim.local_optimize() # Calc parameter uncertainty M3conf = CalibratedConfidence(M3optim) FIM3 = M3conf.get_FIM() return M1, M2, M3, M1conf, M2conf, M3conf