How to output reaction rates for each time step in Simbiology?

7 views (last 30 days)
Hi all,
I would like to see the calculated rates between species for each time step. Simbiology doesn't seem to have a function/option to do that (Please correct me if I'm wrong!). How can I get to my rates anyway?
Thanks, Frank

Accepted Answer

Frank Sommerhage
Frank Sommerhage on 22 Sep 2011
Thank you for your suggestions. They are definitely a good way to get one or two rates out of rather small models that do not have too many reactions pulling and pushing on one species.
I looked a little deeper into that problem and came up with a quick-'n'-dirty solution of my own. The function rateout.m records all reaction rates over time and exports the result into Matlab's workspace. Detailed instructions are in the file, which is now available in Matlab's File Central at:

More Answers (2)

Arthur Goldsipe
Arthur Goldsipe on 16 Sep 2011
Hi Frank,
Unfortunately, SimBiology does not currently provide direct access to the calculated rates. There are a couple of options for working around this limitation. If you are interested in the total rate of change of a species, then the easiest way to estimate that is probably by finite-differencing the simulation results. For example:
m1 = sbiomodel('example');
c = m1.addcompartment('c');
s = m1.addspecies('s', 100);
k = m1.addparameter('k', 0.5);
r = m1.addreaction('s -> null', 'ReactionRate', 'k*s');
[t1,y1] = sbiosimulate(m1);
dy_dt = diff(y1) ./ diff(t);
Or if you have a few reactions that you want to know the rate of, you can calculate them directly from the rate expression. You can either add this result directly to the simulation results by creating a repeated assignment rule or by calculating it after the simulation. For example, continuing from the example above:
% rate = k*s
rate1 = k.Value*y1;
% Or add a repeated assignment
m1.addparameter('rate', 'ConstantValue', false);
m1.addrule('rate = k*s', 'repeatedAssignment');
[t2, y2] = sbiosimulate(m1);
rate2 = y2(:,2);
% Compare the approaches
plot(t1(1:end-1),-dy_dt, 'x-', t1, rate1, 'o-', t2, rate2, '+-')
Hopefully that is a sufficient workaround. Good luck!
-Arthur
  3 Comments
Frank Sommerhage
Frank Sommerhage on 11 Apr 2019
Hi Sergey,
After I got the above answer in 2011, I wrote a tool to export the reaction rates for each time step. It worked well with versions from back in 2011 and 2012, but then I stopped working with SimBiology and did not update the code. The last I heard was that SimBiology includes an option to export the reaction rates by now, but I might be wrong. If it is still not included, download my old tool from MetlabCentral and try to tweak it for 2019.
Good Luck,
Frank
Sergey Kryazhimskiy
Sergey Kryazhimskiy on 11 Apr 2019
Hi Frank,
Thanks! Yes, I saw your code and will try now to get it to work in 2019a. But I was indeed hoping that there would be a built-in function.

Sign in to comment.


Aditya
Aditya on 19 Feb 2013
Edited: Aditya on 19 Feb 2013
Hello,
This piece of code was working marvelously in the older version of Matlab. I just updated to a newer version and its not doing its thing.
It is unable to obtain the reaction rates from the rateout rule into the matlab workspace. To be specific it is not declaring the rate as a global variable any more.
Is there is a work around for this?
Thanks,
Aditya

Communities

More Answers in the  SimBiology Community

Categories

Find more on Extend Modeling Environment in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!