<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import pysb <EOL> import pysb . bng <EOL> import sympy <EOL> import re <EOL> import sys <EOL> import os <EOL> import pygraphviz <EOL> def run ( model ) : <EOL> """<STR_LIT>""" <EOL> pysb . bng . generate_equations ( model ) <EOL> graph = pygraphviz . AGraph ( directed = True , rankdir = "<STR_LIT>" ) <EOL> ic_species = [ cp for cp , parameter in model . initial_conditions ] <EOL> for i , cp in enumerate ( model . species ) : <EOL> species_node = '<STR_LIT>' % i <EOL> slabel = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ( cp ) ) <EOL> slabel += '<STR_LIT>' <EOL> color = "<STR_LIT>" <EOL> if len ( [ s for s in ic_species if s . is_equivalent_to ( cp ) ] ) : <EOL> color = "<STR_LIT>" <EOL> graph . add_node ( species_node , <EOL> label = slabel , <EOL> shape = "<STR_LIT>" , <EOL> fillcolor = color , style = "<STR_LIT>" , color = "<STR_LIT>" , <EOL> fontsize = "<STR_LIT>" , <EOL> margin = "<STR_LIT>" ) <EOL> for i , reaction in enumerate ( model . reactions_bidirectional ) : <EOL> reaction_node = '<STR_LIT>' % i <EOL> graph . add_node ( reaction_node , <EOL> label = reaction_node , <EOL> shape = "<STR_LIT>" , <EOL> fillcolor = "<STR_LIT>" , style = "<STR_LIT>" , color = "<STR_LIT>" , <EOL> fontsize = "<STR_LIT>" , <EOL> width = "<STR_LIT>" , height = "<STR_LIT>" , margin = "<STR_LIT>" ) <EOL> reactants = set ( reaction [ '<STR_LIT>' ] ) <EOL> products = set ( reaction [ '<STR_LIT>' ] ) <EOL> modifiers = reactants & products <EOL> reactants = reactants - modifiers <EOL> products = products - modifiers <EOL> attr_reversible = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } if reaction [ '<STR_LIT>' ] else { } <EOL> for s in reactants : <EOL> r_link ( graph , s , i , ** attr_reversible ) <EOL> for s in products : <EOL> r_link ( graph , s , i , _flip = True , ** attr_reversible ) <EOL> for s in modifiers : <EOL> r_link ( graph , s , i , arrowhead = "<STR_LIT>" ) <EOL> return graph . string ( ) <EOL> def r_link ( graph , s , r , ** attrs ) : <EOL> nodes = ( '<STR_LIT>' % s , '<STR_LIT>' % r ) <EOL> if attrs . get ( '<STR_LIT>' ) : <EOL> del attrs [ '<STR_LIT>' ] <EOL> nodes = reversed ( nodes ) <EOL> attrs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> graph . add_edge ( * nodes , ** attrs ) <EOL> usage = __doc__ <EOL> usage = usage [ <NUM_LIT:1> : ] <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) <= <NUM_LIT:1> : <EOL> print ( usage , end = '<STR_LIT:U+0020>' ) <EOL> exit ( ) <EOL> model_filename = sys . argv [ <NUM_LIT:1> ] <EOL> if not os . path . exists ( model_filename ) : <EOL> raise Exception ( "<STR_LIT>" % model_filename ) <EOL> if not re . search ( r'<STR_LIT>' , model_filename ) : <EOL> raise Exception ( "<STR_LIT>" % model_filename ) <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . dirname ( model_filename ) ) <EOL> model_name = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , os . path . basename ( model_filename ) ) <EOL> try : <EOL> model_module = __import__ ( model_name ) <EOL> except Exception as e : <EOL> print ( "<STR_LIT>" ) <EOL> raise <EOL> try : <EOL> model = model_module . __dict__ [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> raise Exception ( "<STR_LIT>" % model_filename ) <EOL> print ( run ( model ) ) </s>
