def test_get_parameter(self): params = basico.get_parameters() self.assertEqual(params.shape[0], 3) params = basico.get_parameters('epsilon') self.assertEqual(params.shape[0], 1) value = params.iloc[0].initial_value self.assertEqual(value, 0.78)
def test_amount(self): params = basico.get_parameters(type='assignment') self.assertIsNone(params) basico.add_amount_expressions() params2 = basico.get_parameters(type='assignment') self.assertIsNotNone(params2) basico.remove_amount_expressions() param3 = basico.get_parameters(type='assignment') self.assertIsNone(param3)
def test_global_parameters(self): basico.add_parameter('p', initial_value=3) v = basico.get_parameters('p', exact=True) self.assertIsNotNone(v) basico.set_parameters('p', exact=True, initial_expression=' 1 / {Time}', expression='{Time}', status='assignment') v = basico.as_dict(basico.get_parameters('p')) self.assertEqual(v['type'], 'assignment') self.assertEqual(v['expression'], 'Time') self.assertEqual(v['initial_expression'], '') basico.remove_parameter('p') self.assertIsNone(basico.get_parameters('v', exact=True))
def test_set_parameter(self): params = basico.get_parameters('epsilon') self.assertEqual(params.shape[0], 1) value = params.iloc[0].initial_value self.assertEqual(value, 0.78) basico.set_parameters('epsilon', initial_value=2.0) params = basico.get_parameters('epsilon') self.assertEqual(params.shape[0], 1) value = params.iloc[0].initial_value self.assertEqual(value, 2.0) basico.set_parameters('Values[epsilon]', initial_value=3.0) params = basico.get_parameters('Values[epsilon]') self.assertEqual(params.shape[0], 1) value = params.iloc[0].initial_value self.assertEqual(value, 3.0)
def test_parameter_mapping(self): m = 'Test_global_param' dm = basico.new_model(name=m) r = 'R' basico.add_parameter('k_global', 1, unit='1/s') basico.add_reaction(r, 'A -> B', function='Mass action (irreversible)') params = basico.get_parameters() self.assertTrue(len(params) == 1) params2 = basico.get_reaction_parameters(r) self.assertTrue(len(params2) == 1) self.assertTrue(params2.type[0] == 'local') basico.set_reaction(r, mapping={'k1': 'k_global'}) params2 = basico.get_reaction_parameters(r) self.assertTrue(len(params2) == 1) self.assertTrue(params2.type[0] == 'global') basico.set_reaction(r, mapping={'k1': 1.0}) params2 = basico.get_reaction_parameters(r) self.assertTrue(len(params2) == 1) self.assertTrue(params2.type[0] == 'local') basico.set_reaction_parameters('(R).k1', mapped_to='k_global') params2 = basico.get_reaction_parameters(r) self.assertTrue(len(params2) == 1) self.assertTrue(params2.type[0] == 'global')
def test_get_parameters(self): params = basico.get_parameters() signal = params.loc['signal'] expression = signal.expression self.assertTrue(expression != '') conversion = basico.model_info._replace_names_with_cns(expression) self.assertTrue(conversion != '') expression = basico.model_info._replace_cns_with_names(conversion) self.assertTrue(expression != '')
def test_add_ode(self): basico.add_equation('d[PG]/dt=([E]/((k_4 [7-ADCA])/K_n +(k_5 [7-ADCA])/K_n +(k_6 [PGME])/K_si +k3))((k_2 [PGME])/K_s +(k_4b [CEX])/K_p )(k_3+(k_5 [7-ADCA])/K_n +(k_6 [PGME])/K_si )') basico.add_equation( 'd[CEX]/dt=(k_2 [E][PGME])/K_s -([E]/((k_4 [7-ADCA])/K_n +(k_5 [7-ADCA])/K_n +(k_6 [PGME])/K_si +k3))((k_2 [PGME])/K_s +(k_4b [CEX])/K_p )(k_3+(k_5 [7-ADCA])/K_n )') basico.add_equation( '[E]=([EA]_0 exp(-k_d t))/(1+([PGME])/K_s + ((k_2 [PGME])/(K_s ((k_4 [7-ADCA])/K_n +(k_5 [7-ADCA])/K_n +(k_6 [PGME])/K_si +k3) ))(1+([7-ADCA])/K_n +([PGME])/K_si )+([CEX])/K_p +([PG])/K_p2i )') species = basico.get_species() self.assertEqual(species.loc['PG'].type, 'ode') self.assertEqual(species.loc['PG'].expression, '[E] / ( Values[k_4] * [7-ADCA] / Values[K_n] + Values[k_5] * [7-ADCA] / Values[K_n] + Values[k_6] * [PGME] / Values[K_si] + Values[k3] ) * ( Values[k_2] * [PGME] / Values[K_s] + Values[k_4b] * [CEX] / Values[K_p] ) * ( Values[k_3] + Values[k_5] * [7-ADCA] / Values[K_n] + Values[k_6] * [PGME] / Values[K_si] )') self.assertEqual(species.loc['E'].type, 'assignment') self.assertEqual(species.loc['E'].expression, '[EA]_0 * exp ( - Values[k_d] * Time ) / ( 1 + [PGME] / Values[K_s] + Values[k_2] * [PGME] / ( Values[K_s] * ( Values[k_4] * [7-ADCA] / Values[K_n] + Values[k_5] * [7-ADCA] / Values[K_n] + Values[k_6] * [PGME] / Values[K_si] + Values[k3] ) ) * ( 1 + [7-ADCA] / Values[K_n] + [PGME] / Values[K_si] ) + [CEX] / Values[K_p] + [PG] / Values[K_p2i] )') basico.add_equation('obs=sin(t)') self.assertEqual(basico.get_parameters().loc['obs'].type, 'assignment') self.assertEqual(basico.get_parameters().loc['obs'].expression, 'sin ( Time )') # encountered an odd issue when pasting in equations with unicode characters tokens = basico.model_info._tokenize_eqn(u'[E]=([E]_0 exp(-k_d t))/(1+[PGME]/K_s +[PGME]^2/(K_s K_si )+[7-ADCA]/K_n +((k_2 [PGME])/(K_s ((k_4 [7-ADCA])/K_n +(k_5 [7-ADCA])/K_n +k3) ))((k_2 [PGME])/K_s +(k_7 [PGME]^2)/(K_s K_si )+(k_4b [CEX])/K_p )(1+[7-ADCA]/K_n +[PGME]/K_si )+[CEX]/K_p +[PG]/K_p2i )') self.assertTrue(tokens is not None) self.assertEqual(tokens['tokens'][3], 'exp')
def test_load_biomodel(self): dm = basico.load_biomodel(10) self.assertTrue(dm is not None) self.assertTrue(isinstance(dm, COPASI.CDataModel)) self.assertTrue('Kholodenko2000' in basico.model_io.overview()) basico.remove_datamodel(dm) dm = basico.load_biomodel("MODEL1006230012") self.assertTrue(dm is not None) self.assertTrue(isinstance(dm, COPASI.CDataModel)) self.assertTrue('Stewart2009' in basico.model_io.overview()) params = basico.get_parameters() self.assertEqual(params.shape[0], 176) basico.remove_datamodel(dm)
def test_add_parameter(self): basico.add_parameter('sin_time', type='assignment', expression='sin({Time})') p = basico.get_parameters('sin_time') self.assertEqual('assignment', str(p.iloc[0]['type'])) self.assertEqual('sin ( Time )', str(p.iloc[0]['expression'])) basico.remove_parameter('sin_time')