<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import sys <EOL> import os <EOL> import re <EOL> import pygraphviz <EOL> import pysb . bng <EOL> def run ( model ) : <EOL> """<STR_LIT>""" <EOL> pysb . bng . generate_equations ( model ) <EOL> return render_species_as_dot ( model . species , model . name ) <EOL> def render_species_as_dot ( species_list , graph_name = "<STR_LIT>" ) : <EOL> graph = pygraphviz . AGraph ( name = "<STR_LIT>" % graph_name , rankdir = "<STR_LIT>" , <EOL> fontname = '<STR_LIT>' ) <EOL> graph . edge_attr . update ( fontname = '<STR_LIT>' , fontsize = <NUM_LIT:8> ) <EOL> for si , cp in enumerate ( species_list ) : <EOL> sgraph_name = '<STR_LIT>' % si <EOL> cp_label = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , <EOL> str ( cp ) ) + '<STR_LIT>' <EOL> sgraph_label = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' % ( si , cp_label ) <EOL> sgraph = graph . add_subgraph ( name = sgraph_name , label = sgraph_label , <EOL> color = "<STR_LIT>" , sortv = sgraph_name ) <EOL> bonds = { } <EOL> for mi , mp in enumerate ( cp . monomer_patterns ) : <EOL> monomer_node = '<STR_LIT>' % ( sgraph_name , mi ) <EOL> monomer_label = '<STR_LIT>' <EOL> monomer_label += '<STR_LIT>' % mp . monomer . name <EOL> for site in mp . monomer . sites : <EOL> site_state = None <EOL> cond = mp . site_conditions [ site ] <EOL> if isinstance ( cond , str ) : <EOL> site_state = cond <EOL> elif isinstance ( cond , tuple ) : <EOL> site_state = cond [ <NUM_LIT:0> ] <EOL> site_label = site <EOL> if site_state is not None : <EOL> site_label += '<STR_LIT>' % site_state <EOL> monomer_label += '<STR_LIT>' % ( site , site_label ) <EOL> for site , value in mp . site_conditions . items ( ) : <EOL> site_bonds = [ ] <EOL> if isinstance ( value , int ) : <EOL> site_bonds . append ( value ) <EOL> elif isinstance ( value , tuple ) : <EOL> site_bonds . append ( value [ <NUM_LIT:1> ] ) <EOL> elif isinstance ( value , list ) : <EOL> site_bonds += value <EOL> for b in site_bonds : <EOL> bonds . setdefault ( b , [ ] ) . append ( ( monomer_node , site ) ) <EOL> monomer_label += '<STR_LIT>' <EOL> sgraph . add_node ( monomer_node , <EOL> label = monomer_label , shape = "<STR_LIT:none>" , fontname = "<STR_LIT>" , <EOL> fontsize = <NUM_LIT:8> ) <EOL> for bi , sites in bonds . items ( ) : <EOL> node_names , port_names = list ( zip ( * sites ) ) <EOL> sgraph . add_edge ( node_names , tailport = port_names [ <NUM_LIT:0> ] , <EOL> headport = port_names [ <NUM_LIT:1> ] , label = str ( bi ) ) <EOL> return graph . string ( ) <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>
