These tutorials shows how to use PyBioNetGen’s library to run and plot a simple model, as well as create a BNG model object.
Make sure you have PyBioNetGen properly installed by running
If this command doesn’t print out help information, install PyBioNetGen with
pip install bionetgen
Finally, make sure to import the PyBioNetGen library.
Running and Plotting a Model
run method to run a BNGL model. Optionally, you can save the results in a new or existing folder.
result = bionetgen.run("SIR.bngl") # OR result = bionetgen.run("SIR.bngl", out = "SIR_folder")
To view the resulting gdat record array, you can either use the
or the index of the
result.gdats["SIR"][:10] # OR result[:10]
Similarly, to view the resulting cdat record array, use the
To plot the gdat record array, we’ll need matplotlib.
import matplotlib.pyplot as plt
Save the gdat record array as its own object. Then, the values can be plotted.
r = result for name in r.dtype.names: if name != "time": plt.plot(r['time'], r[name], label = name) plt.xlabel("time") plt.ylabel("species (counts)") _ = plt.legend(frameon = False)
Using the bngmodel object
bngmodel method to create a Python representation of a BNGL model.
model = bionetgen.bngmodel("SIR.bngl")
To view the model, you can
print() the entire BNGL model or just certain blocks of the model.
Interactive Jupyter notebooks versions of these tutorials can be found here: