sys-bio / tellurium

Python Environment for Modeling and Simulating Biological Systems
http://tellurium.analogmachine.org/
Apache License 2.0
110 stars 36 forks source link

Bug using exportToMatlab. :bug: #540

Closed fernandonobel closed 3 years ago

fernandonobel commented 3 years ago

First of all, I really like tellurium, you are doing a great work with this tool :)

When I try to export a SBML model to Matlab, I get the following error:

Traceback (most recent call last):
  File "test.py", line 28, in <module>
    r.exportToMatlab('./test.xml')
  File "/home/nobel/Sync/python/workspace/onemodel/env/lib/python3.8/site-packages/tellurium/roadrunner/extended_roadrunner.py", line 223, in exportToMatlab
    f.write(self.getMatlab(current))
  File "/home/nobel/Sync/python/workspace/onemodel/env/lib/python3.8/site-packages/tellurium/roadrunner/extended_roadrunner.py", line 163, in getMatlab
    return sbml2matlab(sbml)
TypeError: 'module' object is not callable

I think the solution could be modifying the line 163 in the file tellurium/roadrunner/extended_roadrunner.py from:

return sbml2matlab(sbml)

, into:

return sbml2matlab.sbml2matlab(sbml)

Here is the code I used to generate the error.

import os

import tellurium as te
import roadrunner

r = te.loada("""
$Xo -> S1; k1*Xo;
S1 -> $X1; k2*S1;

k1 = 0.2; 
k2 = 0.45;

alpha = 1; 
f = 2;

Xo := alpha*f

at time > 20: alpha = 2

""")

m = r.simulate (0, 100, 300, ['time', 'Xo', 'S1'])

currentDir = os.getcwd()
r.plot(title='My plot', xtitle='Time', ytitle='Concentration', dpi=150,
       savefig='./test.png')  # save image to current directory as "test.png"

r.exportToMatlab('./test.xml')

My operating system is Linux Mint 19, python version is 3.8.0 and tellurium version 2.2.0.

hsauro commented 3 years ago

Thanks for information, we should update the code. We hope to make a new release in October.

fernandonobel commented 3 years ago

Thank you for the quick reply :)

luciansmith commented 3 years ago

Apologies for the slow followup! Your report and diagnosis were exactly correct, and a fix is now in the source code.

fernandonobel commented 3 years ago

Nice!