Beispiel #1
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')
Beispiel #2
0
    def test_collect_data(self):
        basico.add_parameter('quantity', initial_value=1)
        mod = basico.get_current_model().getModel()
        assert (isinstance(mod, COPASI.CModel))
        mod.applyInitialValues()
        data = basico.model_info._collect_data(cns=[
            'CN=Root,Model=The Brusselator,Reference=Time',
            'CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Reference=InitialVolume',
            'CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Reference=Rate',
            'CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Reference=Volume',
            'CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[X],Reference=InitialParticleNumber',
            'CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[X],Reference=ParticleNumber',
            'CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[X],Reference=ParticleNumberRate',
            'CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[X],Reference=Rate',
            'CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[X],Reference=Concentration',
            'CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[X],Reference=InitialConcentration',
            'CN=Root,Model=The Brusselator,Vector=Values[quantity],Reference=Value',
            'CN=Root,Model=The Brusselator,Vector=Values[quantity],Reference=InitialValue',
            'CN=Root,Model=The Brusselator,Vector=Values[quantity],Reference=Rate',
            'CN=Root,Model=The Brusselator,Vector=Reactions[R1],Reference=Flux',
            'CN=Root,Model=The Brusselator,Vector=Reactions[R1],Reference=ParticleFlux',
            'CN=Root,Model=The Brusselator,Vector=Reactions[R1],ParameterGroup=Parameters,Parameter=k1,Reference=Value'
        ])

        data2 = basico.model_info._collect_data(names=[
            'Time', 'Compartments[compartment].InitialVolume',
            'Compartments[compartment].Rate',
            'Compartments[compartment].Volume', 'X.InitialParticleNumber',
            'X.ParticleNumber', 'X.InitialParticleNumberRate',
            'X.ParticleNumberRate', 'X.Rate', '[X]', '[X]_0',
            'Values[quantity]', 'Values[quantity].InitialValue',
            'Values[quantity].Rate', '(R1).Flux', '(R1).ParticleFlux',
            '(R1).k1'
        ])
        self.assertTrue(data2 is not None)
Beispiel #3
0
 def test_events(self):
     basico.add_parameter('p0', initial_value=10)
     basico.add_event('e0',
                      trigger='Time > 10',
                      assignments=[('Values[p0]', 1)])
     e = basico.as_dict(basico.get_events('e0', exact=True))
     self.assertIsNotNone(e)
     self.assertEqual(e['trigger'], 'Time > 10')
     self.assertEqual(e['assignments'][0]['target'], 'Values[p0]')
     self.assertEqual(e['assignments'][0]['expression'], '1')
     basico.remove_event('e0', exact=True)
     e = basico.as_dict(basico.get_events('e0', exact=True))
     self.assertIsNone(e)
Beispiel #4
0
 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))
Beispiel #5
0
    def test_invalid_expression(self):
        self.assertLogs(
            basico.add_parameter(
                'invald',
                type='assignment',
                expression=
                'Values[offset] .InitialValue + Values[signal] .InitialValue'))

        self.assertLogs(
            basico.add_parameter(
                'invald2',
                initial_expression=
                'Values[offset] .InitialValue + Values[signal] .InitialValue'))

        # check that the interpreter did not crash
        self.assertTrue(True)
Beispiel #6
0
    def test_expressions(self):
        basico.new_model(name='Model 4', volume_unit='ml', quantity_unit='mmol')

        basico.add_species('PGME', initial_concentration=20)
        basico.add_species('7-ADCA', initial_concentration=10)
        basico.add_species('CEX', initial_concentration=0)
        basico.add_species('PG', initial_concentration=2)

        params = ['K_s', 'k2',  'K_n', 'k3',  'k4',  'k5',  'k6',   'K_si', 'K_p', 'k_4b',  'e0', 'kd', 'K_p2i']
        values = [14,25920,290,25020,4416000,29460,99600,20,39,547560,0.000198000000000000,0.0385800000000000,12]
        for k, v in zip(params, values):
            basico.add_parameter(k, initial_value=v)

        basico.add_equation('A = k4 * [7-ADCA] / K_n + k5 * [7-ADCA] / K_n + k6 * [PGME] / K_si + k3')
        basico.add_equation('e = e0 /(1 + [PGME]^2/ (K_s * K_si) + [7-ADCA] / K_n + ( k2 * [PGME] /(K_s * A))*( 1 + [7-ADCA]/K_n + [PGME]/K_si)+[CEX]/K_p+[PG]/K_p2i)*exp(-kd*t)')
        basico.add_equation('B = (k2 * e * [PGME]/K_s)*(1/A) + (k_4b * e * [CEX]/K_p)*(1/A)')

        dxdt_1 = '-k2 * e * [PGME]/K_s - k6 * B * [PGME]/K_si'
        dxdt_4 = 'B * (k3 + k5*[7-ADCA]/K_n + k6* [PGME]/K_si)'
        dxdt_3 = '-({0}) - ({1})'.format(dxdt_1, dxdt_4)
        dxdt_2 = '-({0})'.format(dxdt_3)
        basico.add_equation('d[PGME]/dt=' + dxdt_1)
        basico.add_equation('d[PG]/dt=' + dxdt_4)
        basico.add_equation('d[CEX]/dt=' + dxdt_3)
        basico.add_equation('d[7-ADCA]/dt=' + dxdt_2)

        template = basico.get_fit_item_template(include_global=True, default_lb=1e-2, default_ub=1e6)
        to_remove = None
        for d in template:
            # set lower bound for the equilibrium constants
            if 'Values[K_si' in d['name']:
                d['upper'] = 50
                continue
            if 'Values[K' in d['name']:
                d['upper'] = 1000
                continue
            if 'Values[k_d' in d['name']:
                d['upper'] = 0.5
                d['lower'] = 0.3

        basico.set_fit_parameters(template)

        self.assertTrue(True)
Beispiel #7
0
 def setUp(self):
     self.dm = basico.new_model(name='Himmelblau')
     self.assertTrue(self.dm is not None)
     self.assertTrue(isinstance(self.dm, COPASI.CDataModel))
     basico.add_parameter('x', initial_value=0)
     basico.add_parameter('y', initial_value=0)
     basico.add_parameter(
         'f',
         type='assignment',
         expression=
         '({Values[x].InitialValue}^2+{Values[y].InitialValue}-11)^2+({Values[x].InitialValue}+{Values[y].InitialValue}^2-7)^2'
     )
Beispiel #8
0
 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')
Beispiel #9
0
 def test_change_mapping(self):
     basico.add_function('MA Keq', 'vr*(Keq-1)')
     basico.add_parameter('K_d', initial_value=1)
     basico.add_reaction('r1 ma keq', scheme='A -> B', function='MA KD', mapping={'vr': 1000, 'Keq': 'K_d'})