I'm looking for a decent implementation of Gillespie's Direct Method in Python, as if I code the algorithm myself I'm nigh positive I'll do it inefficiently.
Anyone have a favorite?
(Disclaimer: I haven't used any of the packages or code below.)
Finding any implementation of Gillespie's method in Python was a bit of a challenge; the most fruitful search terms seemed to be "tau leap" or "kinetic Monte Carlo." This blog post implements Gillespie's algorithm, though it's not clear that it's efficient. One of the commenters mentions some other Gillespie/SSA algorithm implementations in Python that solve problems out of a textbook; the relevant problems are 6.3 through 6.6 on this website.
The most promising implementations in Python that I found were StochPy and Python language bindings to COPASI. I also found what looked like promising C++ codes in SPPARKS, STOCKS, and StochKit; they're not Python, but maybe you can wrap around one of them in Python if it looks particularly promising to you.
I would warmly recommend to use StochKit, which is really extremely reliable and efficient. It implements the Gillespie's direct method as well as its most popular optimized variants. Furthermore, it has a built-in mechanism for selecting the appropriate simulation scheme depending on your network.
However, it is written in C++. If you really need to integrate it with a Python, that shouldn't be a problem. I use it extensively in MATLAB scripts (basically, MATLAB writes a descriptor of the simulation, calls StochKit, and finally performs the data analysis). I'm sure you could do pretty much the same thing with NumPy or SciPy.
As you may already know if you're asking this question, Gillespie's method is often used in computational systems biology. There are a number of software system that provide implementations; you may want to browse the SBML Software Guide to find some of them (specifically, the ones that are known to support SBML, something that I realize may not be relevant to your needs). However, Geoff Oxberry is correct that Python-based implementations of Gillespie's algorithms seem to be uncommon compared to C++ and Java implementations. In addition to StochPy, I'm aware of the following Python-based packages (in alphabetical order):
If, in your application, you can use software that's coded in something other than Python but can be wrapped with a Python interface, then there is
Finally, if you don't need your simulation to be run locally and can instead use web services, then there are the following options:
These lists are still incomplete, but hopefully they will help.