Tuesday, February 10, 2009

Model Summary View

The Model Summary Tool is a window on which other tools can post relevant information. The Model Summary Tool sends two signals: the first allows the tools to declare the variables and equations that they are going to display, and the second allows each tool to look at what the other tools are displaying and modify the information presented. For example. the Stoichiometry and Rates tool posts all the rates, and the Numerical Attributes tool uses this information to show only the parameters that are being used in those equations (rather than showing all the numerical attributes). 
Add Image

Monday, February 9, 2009

Network Layout using NetworkX

Below is the Python code that uses the Networkx module to layout the network. Hopefully the code is self-explanatory. The code is saved in "c/nxAutoLayout.py"

import pytc
import networkx as nx

nodes = pytc.itemsOfFamily("node");

connections = pytc.itemsOfFamily("connection");

numNodes = len(nodes);

numConnections = len(connections);

M = [];

for i in range(0,numConnections):


   connected_nodes = pytc.getConnectedParts( connections[i] );

   for j in connected_nodes:

       n = 0;

       for k in range(0,numNodes):

           if nodes[k] == j:

           n = k;


       n += numConnections;

       M.append( (i,n) ); #connection i and node k are connected

G = nx.Graph();

G.add_nodes_from( range( 0, numConnections + numNodes ) );


Pos = nx.spring_layout(G);

minx = 0;

maxx = 0;

miny = 0;

maxy = 0;

for i in range(0,len(Pos)):

    if minx == 0 or minx > Pos[i][0]:

        minx = Pos[i][0];

    if miny == 0 or miny > Pos[i][1]:

        miny = Pos[i][1];

    if maxx == 0 or maxx <>

        maxx = Pos[i][0];

    if maxy == 0 or maxy <>

        maxy = Pos[i][0];

for i in range(0,len(Pos)):

   Pos[i][0] += - minx;

   Pos[i][0] *= 500.0/(maxx - minx);

   Pos[i][1] += - miny;

   Pos[i][1] *= 500.0/(maxy - miny);

for i in range(0,numConnections):


for i in range(numConnections,numConnections+numNodes):


print "layout finished";

Sunday, February 8, 2009

Changing the Parts Tree

Since the Parts Tree and Connection Tree are loaded from an XML file, it was long anticipated that a feature would be added which allows users to replace the default tree. Now, that feature is available. 

Right-click on the parts or connections tree allows replacement of the XML file for the tree. The new tree will not take effect until the next time TinkerCell starts. 

The natural problems with this is that the heirarchy or parts depends on the tree structure, which can be problematic for some plugins that use the isA("...") to determine whether a part belongs to a particular family. 


Measurement Units

The ItemFamily in TinkerCell has now been modified to include a Pair called measurementUnit.

This pair indicates the unit by which a part is measured. The measurement unit for Species family, for example, would be ("concentration", "mM")

This means that values such as "concentration" that were once places under "Attributes" are no longer attributes. The "Initial Value" data stores these values. The name "concentration" can be obtained by looking at the measurementUnit of the Species family. The same applies to all other families. Connection families do not have any measurement units at the moments (should they?). 

Important implications:
  1. units are not determined by the model, but by the family tree
  2. users cannot change the units while constructing models
  3. changing units means changing the parts/connections tree
  4. units are part of the "standards" defined by the parts and connections tree

Sunday, February 1, 2009

Python Modules inside TinkerCell

Since Python is embedded inside TinkerCell, a user does not need Python installed on his/her computer in order to use Python in TinkerCell. Of course, this is not an issue for Linux users, because it is very easy to install Python modules. 

Various useful Python modules will be included in TinkerCell. 

NumPy and SciPy are Python modules with functions ranging from numerical integration to statistics. Get more information at  numpy.scipy.org and www.scipy.org

PySCeS builds on SciPy and provides various useful functionalities for analysis of dynamical systems, particularly biological systems. Get more information at pysces.sourceforge.net

Networkx is a module with a few useful graph algorithms, particularly graph layout algorithms. Get more information at networkx.lanl.gov

Rpy is a Python version of the popular R statistical language. Get more information at rpy.sourceforge.net/

Python Interpreter inside TinkerCell

It is not a good idea to load and unload the Python interpreter. It can cause Python to crash if external modules are loaded. 

The DynamicCodePlugin has been modified to alleviate this issue. 

The solution:  
The PythinInterpreterThread class runs as a separate thread. It initializes the Python interpreter when TinkerCell is loaded, and it finalizes (i.e. quits) the interpreter when TinkerCell exists. 

Now, it is very easy to call Python code inside a C program. The hillEquations.c function that generates the automatic Hill equation calls a Python code like this:

#include "TC_api.h"

int main()
    return 0;


What happens here is that the DynamicCodePlugin accepts the string and sends it to the already loaded Python interpreter. This makes the process fast because the interpreter is already loaded. 


The Python interpreter runs as a single separate thread. This means that only one Python program can run at a time. In other words, Python programs are not as multi-threaded as C programs. But it is probably rare that someone would need to run multiple Python programs at once.