END_TEST START_TEST (test_SpeciesReference_setStoichiometryMath) { const ASTNode_t *math = SBML_parseFormula("k3 / k2"); StoichiometryMath_t *stoich = StoichiometryMath_create(2, 4); StoichiometryMath_setMath(stoich, math); const StoichiometryMath_t * math1; char * formula; SpeciesReference_setStoichiometryMath(SR, stoich); math1 = SpeciesReference_getStoichiometryMath(SR); fail_unless( math1 != NULL ); formula = SBML_formulaToString(StoichiometryMath_getMath(math1)); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "k3 / k2") ); fail_unless( SpeciesReference_isSetStoichiometryMath(SR) ); safe_free(formula); }
END_TEST START_TEST (test_StoichiometryMath_setMath) { ASTNode_t *math = SBML_parseFormula("lambda(x, x^3)"); const ASTNode_t * math1; char * formula; StoichiometryMath_setMath(D, math); math1 = StoichiometryMath_getMath(D); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); fail_unless( StoichiometryMath_getMath(D) != math ); fail_unless( StoichiometryMath_isSetMath(D) ); safe_free(formula); /* Reflexive case (pathological) */ StoichiometryMath_setMath(D, (ASTNode_t *) StoichiometryMath_getMath(D)); math1 = StoichiometryMath_getMath(D); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); safe_free(formula); StoichiometryMath_setMath(D, NULL); fail_unless( !StoichiometryMath_isSetMath(D) ); if (StoichiometryMath_getMath(D) != NULL) { fail("StoichiometryMath_setMath(D, NULL) did not clear ASTNode."); } ASTNode_free(math); }
END_TEST START_TEST (test_StoichiometryMath_setMath1) { ASTNode_t *math = SBML_parseFormula("2 * k"); int i = StoichiometryMath_setMath(D, math); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( StoichiometryMath_getMath(D) != math ); fail_unless( StoichiometryMath_isSetMath(D) ); i = StoichiometryMath_setMath(D, NULL); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( StoichiometryMath_getMath(D) == NULL ); fail_unless( !StoichiometryMath_isSetMath(D) ); ASTNode_free(math); }
SBML_ODESOLVER_API int drawModel(Model_t *m, char* file, char *format) { /** if SOSlib has been compiled without graphviz, the graph will be written to a text file in graphviz' dot format */ #if !USE_GRAPHVIZ SolverError_error(WARNING_ERROR_TYPE, SOLVER_ERROR_NO_GRAPHVIZ, "odeSolver has been compiled without GRAPHIZ. ", "Graphs are printed to stdout in graphviz' .dot format."); drawModelTxt(m, file); #else GVC_t *gvc; Agraph_t *g; Agnode_t *r; Agnode_t *s; Agedge_t *e; Agsym_t *a; Species_t *sp; Reaction_t *re; const ASTNode_t *math; SpeciesReference_t *sref; SpeciesReference_t *mref; char *output[4]; char *command = "dot"; char *formatopt; char *outfile; int i,j; int reversible; char name[WORDSIZE]; char label[WORDSIZE]; /* setting name of outfile */ ASSIGN_NEW_MEMORY_BLOCK(outfile, strlen(file)+ strlen(format)+7, char, 0); sprintf(outfile, "-o%s_rn.%s", file, format); /* setting output format */ ASSIGN_NEW_MEMORY_BLOCK(formatopt, strlen(format)+3, char, 0); sprintf(formatopt, "-T%s", format); /* construct command-line */ output[0] = command; output[1] = formatopt; output[2] = outfile; output[3] = NULL; /* set up renderer context */ gvc = (GVC_t *) gvContext(); #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION < 4 dotneato_initialize(gvc, 3, output); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 parse_args(gvc, 3, output); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvParseArgs(gvc, 3, output); #endif g = agopen("G", AGDIGRAPH); /* avoid overlapping nodes, for graph embedding by neato */ a = agraphattr(g, "overlap", ""); agxset(g, a->index, "scale"); for ( i=0; i<Model_getNumReactions(m); i++ ) { re = Model_getReaction(m,i); reversible = Reaction_getReversible(re); sprintf(name, "%s", Reaction_getId(re)); r = agnode(g,name); a = agnodeattr(g, "shape", "ellipse"); agxset(r, a->index, "box"); if ( Reaction_getFast(re) ) { a = agnodeattr(g, "color", ""); agxset(r, a->index, "red"); a = agnodeattr(g, "fontcolor", ""); agxset(r, a->index, "red"); } sprintf(label, "%s", Reaction_isSetName(re) ? Reaction_getName(re) : Reaction_getId(re)); agset(r, "label", label); sprintf(label, "%s.htm", Reaction_getId(re)); a = agnodeattr(g, "URL", ""); agxset(r, a->index, label); for ( j=0; j<Reaction_getNumModifiers(re); j++ ) { mref = Reaction_getModifier(re,j); sp = Model_getSpeciesById(m, SpeciesReference_getSpecies(mref)); sprintf(name,"%s", Species_getId(sp)); s = agnode(g,name); sprintf(label, "%s", Species_isSetName(sp) ? Species_getName(sp) : Species_getId(sp)); agset(s, "label", label); if ( Species_getBoundaryCondition(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "blue"); } if ( Species_getConstant(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "green4"); } sprintf(label, "%s.htm", Species_getId(sp)); a = agnodeattr(g, "URL", ""); agxset(s, a->index, label); e = agedge(g,s,r); a = agedgeattr(g, "style", ""); agxset(e, a->index, "dashed"); a = agedgeattr(g, "arrowhead", ""); agxset(e, a->index, "odot"); } for ( j=0; j<Reaction_getNumReactants(re); j++ ) { sref = Reaction_getReactant(re,j); sp = Model_getSpeciesById(m, SpeciesReference_getSpecies(sref)); sprintf(name,"%s", Species_getId(sp)); s = agnode(g, name); sprintf(label, "%s", Species_isSetName(sp) ? Species_getName(sp) : Species_getId(sp)); agset(s, "label", label); if ( Species_getBoundaryCondition(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "blue"); } if ( Species_getConstant(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "green4"); } sprintf(label, "%s.htm", Species_getId(sp)); a = agnodeattr(g, "URL", ""); agxset(s, a->index, label); e = agedge(g,s,r); a = agedgeattr(g, "label", ""); if ( (SpeciesReference_isSetStoichiometryMath(sref)) ) { math = StoichiometryMath_getMath(SpeciesReference_getStoichiometryMath(sref)); if ( (strcmp(SBML_formulaToString(math),"1") != 0) ) agxset (e, a->index, SBML_formulaToString(math)); } else if ( SpeciesReference_getStoichiometry(sref) != 1 ) { sprintf(name, "%g", SpeciesReference_getStoichiometry(sref)); agxset (e, a->index, name); } if ( reversible == 1 ) { a = agedgeattr(g, "arrowhead", ""); agxset(e, a->index, "diamond"); a = agedgeattr(g, "arrowtail", ""); agxset(e, a->index, "odiamond"); } } for ( j=0; j<Reaction_getNumProducts(re); j++ ) { sref = Reaction_getProduct(re,j); sp = Model_getSpeciesById(m, SpeciesReference_getSpecies(sref)); sprintf(name,"%s", Species_getId(sp)); s = agnode(g,name); sprintf(label, "%s", Species_isSetName(sp) ? Species_getName(sp) : Species_getId(sp)); agset(s, "label", label); if ( Species_getBoundaryCondition(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "blue"); } if ( Species_getConstant(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "green4"); } sprintf(label, "%s.htm", Species_getId(sp)); a = agnodeattr(g, "URL", ""); agxset(s, a->index, label); e = agedge(g,r,s); a = agedgeattr(g, "label", ""); if ( SpeciesReference_isSetStoichiometryMath(sref) ) { math = StoichiometryMath_getMath(SpeciesReference_getStoichiometryMath(sref)); if ( (strcmp(SBML_formulaToString(math),"1") != 0) ) agxset (e, a->index, SBML_formulaToString(math)); } else if ( SpeciesReference_getStoichiometry(sref) != 1 ) { sprintf(name, "%g",SpeciesReference_getStoichiometry(sref)); agxset (e, a->index,name); } if ( reversible == 1 ) { a = agedgeattr(g, "arrowhead", ""); agxset(e, a->index, "diamond"); a = agedgeattr(g, "arrowtail", ""); agxset(e, a->index, "odiamond"); } } } /* Compute a layout */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 gvBindContext(gvc, g); dot_layout(g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 gvlayout_layout(gvc, g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvLayoutJobs(gvc, g); #endif /* Write the graph according to -T and -o options */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 dotneato_write(gvc); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 emit_jobs(gvc, g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvRenderJobs(gvc, g); #endif /* Clean out layout data */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 dot_cleanup(g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 gvlayout_cleanup(gvc, g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvFreeLayout(gvc, g); #endif /* Free graph structures */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 dot_cleanup(g); #else agclose(g); #endif /* Clean up output file and errors */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 gvFREEcontext(gvc); dotneato_eof(gvc); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 dotneato_terminate(gvc); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvFreeContext(gvc); #endif xfree(formatopt); xfree(outfile); #endif return 1; }