Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with 2D parameter scan #90

Open
StephanM87 opened this issue Jun 23, 2023 · 1 comment
Open

Problem with 2D parameter scan #90

StephanM87 opened this issue Jun 23, 2023 · 1 comment

Comments

@StephanM87
Copy link

I am trying to use PySCeS for a very simple chemical reaction, the goal is to define a model, perform a parameter scan and finally run simulations with the fitted parameters.

I followed the documentation for a 2D parameter scan, but unfortunately, I ran into a problem. There is probably a problem with my code, but at the moment I'm not exactly sure what the problem is in detail

My model is:

Modelname: simulatio_metaraminol
Description: Kinetic model to describe the synthesis of metaraminol from 3-OH-PAC

R1:
    x0 = s0
    k1*x0 - k2*s0
# parameters
k1 = 0.2
k2 = 0.1

# init values
x0 = 35.0
s0 = 0

The code for the parameter fit is:

import pysces

model = pysces.model('simulatio_metaraminol')

time_values = [0,1,2,3,4,5,6,7,8,23.6,24]
concentrations_s0 = [0, 6.27, 8.47, 10.77, 11.58,10.97, 11.75, 12.09, 12.10,14.55, 14.09]
concentrations_x0 = [35.16, 27.30,26.12, 28.45, 29.27, 25.90,24.29, 25.24,24.86,24.51,24.55]

scan = pysces.Scanner(model)

output = ['k1', 'k2']

p1 = ["x0", 35, 24.55, concentrations_x0]
p2 = ["s0", 0,14.09,concentrations_s0]

model.Scan2D(p1,p2, output, log=False)

At the moment I get as an error message:

Info: No reagents have been fixed
 
Calculating L matrix . . . . . . .  done.
Calculating K matrix . . . . . . . no flux conservation
 done.
 
MaxMode 0

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_32904\2699428414.py in <module>
     14 p2 = ["s0", 0,14.09,concentrations_s0]
     15 
---> 16 model.Scan2D(p1,p2, output, log=False)

~\anaconda3\envs\pysces2\lib\site-packages\pysces\PyscesModel.py in Scan2D(self, p1, p2, output, log)
   9213         sc1.addScanParameter(*p2)
   9214         sc1.addUserOutput(output)
-> 9215         sc1.Run()
   9216 
   9217         self.__scan2d_pars__ = [p1[0], p2[0], output]

~\anaconda3\envs\pysces2\lib\site-packages\pysces\PyscesScan.py in Run(self, ReRun)
    273         for gen in self.GenOrder:
    274             if self.GenDict[gen][4] == False:  # don't increase Tsteps for follower
--> 275                 Tsteps *= self.GenDict[gen][2]
    276         print(next(self.scanT.RUN))
    277         analysis_counter = 0

TypeError: can't multiply sequence by non-int of type 'list'

I'm unfortunately also a little bit confused with the Syntax of the 2D parameter scan:

    p1 is a list of [model parameter 1, start value, end value, points]

    p2 is a list of [model parameter 2, start value, end value, points]

    output the steady-state variable e.g. 'J_R1' or 'A_ss'

    log if True scan using log ranges for both axes
  • Are the start and end values the time or the measured values?
  • Are the points only the measured values or do they have to be submitted as for example data frame together with the time?
@jmrohwer
Copy link
Member

Hi Stephan,

Parameter scanning is only for repeated run of steady-state analyses, not for time simulations. What this method actually does, is changes the two parameters through the list of values and calculates the steady state for each of these, outputting the results.

The syntax of the parameter scan list is as follows:

p1 = ["k1", 1, 10, 10]
p2 = ["k2", 2, 20, 10]

This would vary the parameter "k1" from 1 to 10 in 10 points, i.e. [1, 2, 3, ..., 10]. If you select log, this would be on a log scale. And parameter "k2" from 2 to 20. The output argument is a list of steady-state variables to output (this would typically be fluxes or steady-state concentrations). In your example you are outputting the parameters k1 and k2, so that won't work.

What you want to do is different, i.e. run various simulations with different starting conditions. You would have to code this manually in a for loop, each time setting mod.x0_init and mod.s0_init (the initial values), setting mod.sim_time (list of time points you want to simulate over, and then calling mod.Simulate(userinit=1).

If you want to see how this is implemented for data fitting of time series, then you can look at the source code of the PySCeS ThinLayer to PyEnzyme: https://github.com/EnzymeML/PyEnzyme/blob/main/pyenzyme/thinlayers/TL_Pysces.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants