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

Error at tutorial visualization step #568

Open
lhdp0110 opened this issue Sep 23, 2022 · 3 comments
Open

Error at tutorial visualization step #568

lhdp0110 opened this issue Sep 23, 2022 · 3 comments

Comments

@lhdp0110
Copy link

When I enter the command:
[path-to-pysb]/pysb/tools/render_reactions.py [path-to-pysb-model-file]/mymodel.py > mymodel.dot
Replacing with appropriate path names as instructed, I get the following error:
NameError: name 'mymodel' is not defined

What may cause this? Thank you

@jmuhlich
Copy link
Member

Could you provide the entire stack trace from your terminal? It would be helpful to see the exact line that's failing as well as everything leading up to it.

@lhdp0110
Copy link
Author

lhdp0110 commented Sep 29, 2022

Thank you for your reply, here is the entire error message:

`'C:/Users/.../anaconda3/pkgs/pysb-1.14.0-py_0/site-packages/pysb/tools/render_reactions.py' 'C:/Users/.../anaconda3/Scripts/PySB/mymodel.py' > mymodel.dot
Traceback (most recent call last):

Input In [14] in <cell line: 1>
'C:/Users/.../anaconda3/pkgs/pysb-1.14.0-py_0/site-packages/pysb/tools/render_reactions.py' 'C:/Users/.../anaconda3/Scripts/PySB/mymodel.py' > mymodel.dot

NameError: name 'mymodel' is not defined`

I ran this line interactively after running the following:

import the pysb module and all its methods and functions

from pysb import *

instantiate a model

Model()

declare monomers

Monomer('C8', ['b'])
Monomer('Bid', ['b', 'S'], {'S':['u', 't']})

input the parameter values

Parameter('kf', 1.0e-07)
Parameter('kr', 1.0e-03)
Parameter('kc', 1.0)

now input the rules

Rule('C8_Bid_bind', C8(b=None) + Bid(b=None, S='u') | C8(b=1) % Bid(b=1, S='u'), *[kf, kr])
Rule('tBid_from_C8Bid', C8(b=1) % Bid(b=1, S='u') >> C8(b=None) + Bid(b=None, S='t'), kc)

initial conditions

Parameter('C8_0', 1000)
Parameter('Bid_0', 10000)
Initial(C8(b=None), C8_0)
Initial(Bid(b=None, S='u'), Bid_0)

Observables

Observable('obsC8', C8(b=None))
Observable('obsBid', Bid(b=None, S='u'))
Observable('obstBid', Bid(b=None, S='t'))

import mymodel as m

(I'm sorry, I cannot figure out how to format the above code properly)
Is is possible that this is due to Graphviz or another requirement not being properly installed?

@jmuhlich
Copy link
Member

It looks like you are entering the command as a cell in a Jupyter notebook. That command as written must be run from the shell instead. If you want to run the visualization from a notebook you'll need Python code:

First, delete the line import mymodel as m. The Model object is already available under the variable model. Next you will need to add the following import lines:

from IPython.display import SVG
import pygraphviz
import pysb.tools.render_reactions

Then we call the pysb render_reactions tool and store the result as a GraphViz graph object in g:

g = pygraphviz.AGraph(string=pysb.tools.render_reactions.run(model))

Finally we call graphviz to perform layout and SVG rendering, displaying the SVG inline in the notebook:

SVG(g.draw(prog="dot", format="svg"))

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