END_TEST START_TEST (test_KineticLaw_getParameterById) { Parameter_t *k1 = Parameter_create(2, 4); Parameter_t *k2 = Parameter_create(2, 4); Parameter_setId(k1, "k1"); Parameter_setId(k2, "k2"); Parameter_setValue(k1, 3.14); Parameter_setValue(k2, 2.72); KineticLaw_addParameter(kl, k1); KineticLaw_addParameter(kl, k2); Parameter_free(k1); Parameter_free(k2); fail_unless( KineticLaw_getNumParameters(kl) == 2 ); k1 = KineticLaw_getParameterById(kl, "k1"); k2 = KineticLaw_getParameterById(kl, "k2"); fail_unless( !strcmp(Parameter_getId(k1), "k1") ); fail_unless( !strcmp(Parameter_getId(k2), "k2") ); fail_unless( Parameter_getValue(k1) == 3.14 ); fail_unless( Parameter_getValue(k2) == 2.72 ); }
END_TEST START_TEST (test_Parameter_setId) { char *id = "Km1"; Parameter_setId(P, id); fail_unless( !strcmp(Parameter_getId(P), id) ); fail_unless( Parameter_isSetId(P) ); if (Parameter_getId(P) == id) { fail("Parameter_setId(...) did not make a copy of string."); } /* Reflexive case (pathological) */ Parameter_setId(P, Parameter_getId(P)); fail_unless( !strcmp(Parameter_getId(P), id) ); Parameter_setId(P, NULL); fail_unless( !Parameter_isSetId(P) ); if (Parameter_getId(P) != NULL) { fail("Parameter_setId(P, NULL) did not clear string."); } }
/* create contents of myResult object */ myResult *create_myResult(Model_t *m, mySpecies *mySp[], myParameter *myParam[], myCompartment *myComp[], double sim_time, double dt, int print_interval) { int i; myResult *result; int num_of_species = Model_getNumSpecies(m); int num_of_parameters = Model_getNumParameters(m); int num_of_compartments = Model_getNumCompartments(m); int end_cycle = get_end_cycle(sim_time, dt); result = (myResult *)malloc(sizeof(myResult)); result->error_code = NoError; result->error_message = NULL; result->num_of_columns_sp = num_of_species; result->num_of_columns_param = num_of_parameters; result->num_of_columns_comp = num_of_compartments; result->num_of_rows = end_cycle / print_interval + 1; result->column_name_time = dupstr("time"); result->column_name_sp = (const char **)malloc(sizeof(char *) * num_of_species); result->column_name_param = (const char **)malloc(sizeof(char *) * num_of_parameters); result->column_name_comp = (const char **)malloc(sizeof(char *) * num_of_compartments); result->values_time = (double *)malloc(sizeof(double) * result->num_of_rows); result->values_sp = (double *)malloc(sizeof(double) * num_of_species * result->num_of_rows); result->values_param = (double *)malloc(sizeof(double) * num_of_parameters * result->num_of_rows); result->values_comp = (double *)malloc(sizeof(double) * num_of_compartments * result->num_of_rows); for(i=0; i<num_of_species; i++){ result->column_name_sp[i] = dupstr(Species_getId(mySp[i]->origin)); } for(i=0; i<num_of_parameters; i++){ result->column_name_param[i] = dupstr(Parameter_getId(myParam[i]->origin)); } for(i=0; i<num_of_compartments; i++){ result->column_name_comp[i] = dupstr(Compartment_getId(myComp[i]->origin)); } return result; }
void myInitialAssignment_initTarget( myInitialAssignment *assign, mySpecies **species, unsigned int num_of_species, myParameter **parameters, unsigned int num_of_parameters, myCompartment **compartments, unsigned int num_of_compartments) { unsigned int i; InitialAssignment_t *origin; const char *origin_symbol; origin = myInitialAssignment_getOrigin(assign); origin_symbol = InitialAssignment_getSymbol(origin); for (i = 0; i < num_of_species; i++) { if (strcmp(origin_symbol, Species_getId(species[i]->origin)) == 0) { myInitialAssignment_setTargetSpecies(assign, species[i]); return; } } for (i = 0; i < num_of_parameters; i++) { if (strcmp(origin_symbol, Parameter_getId(parameters[i]->origin)) == 0) { myInitialAssignment_setTargetParameter(assign, parameters[i]); return; } } for (i = 0; i < num_of_compartments; i++) { if (strcmp(origin_symbol, Compartment_getId(compartments[i]->origin)) == 0) { myInitialAssignment_setTargetCompartment(assign, compartments[i]); return; } } }
END_TEST START_TEST (test_L3_Parameter_id) { char *id = "mitochondria"; fail_unless( !Parameter_isSetId(P) ); Parameter_setId(P, id); fail_unless( !strcmp(Parameter_getId(P), id) ); fail_unless( Parameter_isSetId(P) ); if (Parameter_getId(P) == id) { fail("Parameter_setId(...) did not make a copy of string."); } }
void print_result_list(Model_t *m, mySpecies *mySp[], myParameter *myParam[], myCompartment *myComp[]){ FILE *fp = NULL; unsigned int i; int column = 2; if ((fp = my_fopen(fp, "./simulation_results/result_list.dat", "w")) == NULL) { return; } TRACE(("Result : Species List\n")); fprintf(fp, "Result : Species List\n"); for(i=0; i<Model_getNumSpecies(m); i++){ /* if(!(Species_getConstant(mySp[i]->origin) && Species_getBoundaryCondition(mySp[i]->origin))){ //XXX must remove this */ fprintf(fp, "column %d : ID=%s Name=%s\n", column, Species_getId(mySp[i]->origin), Species_getName(mySp[i]->origin)); column++; /* } */ } TRACE(("\n")); fprintf(fp, "\n"); fprintf(fp, "Result : Parameter List\n"); column = 2; for(i=0; i<Model_getNumParameters(m); i++){ /* if(!Parameter_getConstant(myParam[i]->origin)){ //XXX must remove this */ TRACE(("column %d : ID=%s Name=%s\n", column, Parameter_getId(myParam[i]->origin), Parameter_getName(myParam[i]->origin))); fprintf(fp, "column %d : ID=%s Name=%s\n", column, Parameter_getId(myParam[i]->origin), Parameter_getName(myParam[i]->origin)); column++; /* } */ } TRACE(("Result : Compartment List\n")); fprintf(fp, "Result : Compartment List\n"); column = 2; for(i=0; i<Model_getNumCompartments(m); i++){ /* if(!Compartment_getConstant(myComp[i]->origin)){ //XXX must remove this */ TRACE(("column %d : ID=%s Name=%s\n", column, Compartment_getId(myComp[i]->origin), Compartment_getName(myComp[i]->origin))); fprintf(fp, "column %d : ID=%s Name=%s\n", column, Compartment_getId(myComp[i]->origin), Compartment_getName(myComp[i]->origin)); column++; /* } */ } fclose(fp); }
END_TEST START_TEST (test_Parameter_setId2) { int i = Parameter_setId(P, "cell"); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( Parameter_isSetId(P) ); fail_unless( !strcmp(Parameter_getId(P), "cell" )); i = Parameter_setId(P, NULL); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( !Parameter_isSetId(P) ); }
END_TEST START_TEST (test_L3_Parameter_createWithNS ) { XMLNamespaces_t *xmlns = XMLNamespaces_create(); XMLNamespaces_add(xmlns, "http://www.sbml.org", "testsbml"); SBMLNamespaces_t *sbmlns = SBMLNamespaces_create(3,1); SBMLNamespaces_addNamespaces(sbmlns,xmlns); Parameter_t *p = Parameter_createWithNS (sbmlns); fail_unless( SBase_getTypeCode ((SBase_t *) p) == SBML_PARAMETER ); fail_unless( SBase_getMetaId ((SBase_t *) p) == NULL ); fail_unless( SBase_getNotes ((SBase_t *) p) == NULL ); fail_unless( SBase_getAnnotation((SBase_t *) p) == NULL ); fail_unless( SBase_getLevel ((SBase_t *) p) == 3 ); fail_unless( SBase_getVersion ((SBase_t *) p) == 1 ); fail_unless( Parameter_getNamespaces (p) != NULL ); fail_unless( XMLNamespaces_getLength(Parameter_getNamespaces(p)) == 2 ); fail_unless( Parameter_getId (p) == NULL ); fail_unless( Parameter_getName (p) == NULL ); fail_unless( Parameter_getUnits (p) == NULL ); fail_unless( isnan(Parameter_getValue(p))); fail_unless( Parameter_getConstant(p) == 1 ); fail_unless( !Parameter_isSetId (p) ); fail_unless( !Parameter_isSetName (p) ); fail_unless( !Parameter_isSetValue (p) ); fail_unless( !Parameter_isSetUnits (p) ); fail_unless( !Parameter_isSetConstant(p) ); Parameter_free(p); }
int main (int argc, char* argv[]) { unsigned int i,j,errors; const char* filename; SBMLDocument_t* document; Model_t* m; if (argc != 2) { printf("\nUsage: printNotes filename\n\n"); return 1; } filename = argv[1]; document = readSBML(filename); errors = SBMLDocument_getNumErrors( document); printf("\n%s\n\n", filename); if(errors > 0) { SBMLDocument_printErrors(document, stderr); SBMLDocument_free(document); return errors; } /* Model */ m = SBMLDocument_getModel(document); printNotes((SBase_t*)m, Model_getId(m)); for(i=0; i < Model_getNumReactions(m); i++) { Reaction_t* re = Model_getReaction( m, i); printNotes((SBase_t*)re, Reaction_getId(re)); /* SpeciesReference (Reactant) */ for(j=0; j < Reaction_getNumReactants( re); j++) { SpeciesReference_t* rt = Reaction_getReactant(re, j); if (SBase_isSetNotes((SBase_t*) rt)) printf(" "); printNotes((SBase_t*)rt, SpeciesReference_getSpecies( rt ) ); } /* SpeciesReference (Product) */ for(j=0; j < Reaction_getNumProducts( re ); j++) { SpeciesReference_t* rt = Reaction_getProduct( re, j); if (SBase_isSetNotes((SBase_t*) rt)) printf(" "); printNotes((SBase_t*)rt, SpeciesReference_getSpecies( rt ) ); } /* ModifierSpeciesReference (Modifiers) */ for(j=0; j < Reaction_getNumModifiers( re ); j++) { SpeciesReference_t* md = Reaction_getModifier(re, j); if (SBase_isSetNotes((SBase_t*) md)) printf(" "); printNotes((SBase_t*)md, SpeciesReference_getSpecies( md ) ); } /* KineticLaw */ if(Reaction_isSetKineticLaw( re )) { KineticLaw_t* kl = Reaction_getKineticLaw( re ); if (SBase_isSetNotes((SBase_t*) kl)) printf(" "); printNotes((SBase_t*)kl, ""); /* Parameter */ for(j=0; j < KineticLaw_getNumParameters( kl ); j++) { Parameter_t* pa = KineticLaw_getParameter( kl, j); if (SBase_isSetNotes((SBase_t*) pa)) printf(" "); printNotes((SBase_t*)pa, Parameter_getId(pa)); } } } /* Species */ for(i=0; i < Model_getNumSpecies(m); i++) { Species_t* sp = Model_getSpecies(m, i); printNotes((SBase_t*)sp, Species_getId(sp)); } /* Compartments */ for(i=0; i < Model_getNumCompartments( m ); i++) { Compartment_t* sp = Model_getCompartment(m, i); printNotes((SBase_t*)sp, Compartment_getId(sp)); } /* FunctionDefinition */ for(i=0; i < Model_getNumFunctionDefinitions(m); i++) { FunctionDefinition_t* sp = Model_getFunctionDefinition(m, i); printNotes((SBase_t*)sp, FunctionDefinition_getId(sp)); } /* UnitDefinition */ for(i=0; i < Model_getNumUnitDefinitions(m); i++) { UnitDefinition_t* sp = Model_getUnitDefinition( m, i); printNotes((SBase_t*)sp, UnitDefinition_getId(sp)); } /* Parameter */ for(i=0; i < Model_getNumParameters( m ); i++) { Parameter_t* sp = Model_getParameter( m, i); printNotes((SBase_t*)sp, Parameter_getId(sp)); } /* Rule */ for(i=0; i < Model_getNumReactions( m ); i++) { Rule_t* sp = Model_getRule(m, i); printNotes((SBase_t*)sp, ""); } /* InitialAssignment */ for(i=0; i < Model_getNumInitialAssignments(m); i++) { InitialAssignment_t* sp = Model_getInitialAssignment(m, i); printNotes((SBase_t*)sp, ""); } /* Event */ for(i=0; i < Model_getNumEvents(m); i++) { Event_t* sp = Model_getEvent(m, i); printNotes((SBase_t*)sp, Event_getId(sp)); /* Trigger */ if(Event_isSetTrigger( sp )) { Trigger_t* tg = Event_getTrigger(sp); if (SBase_isSetNotes( (SBase_t*) tg)) printf( " " ); printNotes((SBase_t*)tg, ""); } /* Delay */ if(Event_isSetDelay(sp)) { Delay_t* dl = Event_getDelay(sp); if (SBase_isSetNotes( (SBase_t*) dl)) printf( " " ); printNotes((SBase_t*) dl, ""); } /* EventAssignment */ for(j=0; j < Event_getNumEventAssignments(sp); j++) { EventAssignment_t* ea = Event_getEventAssignment(sp, j); if (SBase_isSetNotes( (SBase_t*) ea)) printf( " " ); printNotes((SBase_t*)ea, ""); } } /* SpeciesType */ for(i=0; i < Model_getNumSpeciesTypes(m); i++) { SpeciesType_t* sp = Model_getSpeciesType(m, i); printNotes((SBase_t*)sp, SpeciesType_getId(sp)); } /* Constraints */ for(i=0; i < Model_getNumConstraints(m); i++) { Constraint_t* sp = Model_getConstraint(m, i); printNotes((SBase_t*)sp, ""); } SBMLDocument_free( document ); return errors; }
void printReactions(Model_t *m, FILE *f) { int i,j,k; Reaction_t *r; SpeciesReference_t *sref; KineticLaw_t *kl; Rule_t *rl; AssignmentRule_t *asr; AlgebraicRule_t *alr; RateRule_t *rr; Event_t *e; EventAssignment_t *ea; Parameter_t *p; FunctionDefinition_t *fd; SBMLTypeCode_t type; const ASTNode_t *math; math = NULL; fprintf(f, "\n"); for(i=0;i<Model_getNumParameters(m);i++){ if(i==0) fprintf(f, "# Global parameters:\n"); p = Model_getParameter(m,i); if(Parameter_isSetId(p)) fprintf(f, "%s ", Parameter_getId(p)); if(Parameter_isSetName(p)) fprintf(f, "(%s) ", Parameter_getName(p)); if(Parameter_isSetValue(p)) fprintf(f, "= %g; ", Parameter_getValue(p)); if(Parameter_isSetUnits(p)) fprintf(f, "[%s]; ", Parameter_getUnits(p)); if(!Parameter_getConstant(p)) fprintf(f, "(variable);"); fprintf(f, "\n"); if ( i==Model_getNumParameters(m)-1 ) fprintf(f, "\n"); } fprintf(f, "# Reactions:\n"); for ( i=0; i<Model_getNumReactions(m); i++ ) { r = Model_getReaction(m,i); fprintf(f, "%s: %s", Reaction_isSetName(r) ? Reaction_getName(r) : Reaction_getId(r), Reaction_getFast(r) ? "(fast)" : ""); for ( k=0; k<Reaction_getNumReactants(r); k++ ) { sref = Reaction_getReactant(r,k); if ( SpeciesReference_isSetStoichiometryMath(sref) ) fprintf(f, "%s ", SBML_formulaToString(\ SpeciesReference_getStoichiometryMath(sref))); else if ( SpeciesReference_getStoichiometry(sref) != 1. ) fprintf(f, "%g ", SpeciesReference_getStoichiometry(sref)); fprintf(f, "%s", SpeciesReference_getSpecies(sref)); if(k+1<Reaction_getNumReactants(r)) fprintf(f, "%s", " + "); } fprintf(f, "%s", Reaction_getReversible(r) ? " <-> " : " -> "); for ( k=0; k<Reaction_getNumProducts(r); k++ ) { sref = Reaction_getProduct(r,k); if ( SpeciesReference_isSetStoichiometryMath(sref) ) fprintf(f, "%s ", SBML_formulaToString(\ SpeciesReference_getStoichiometryMath(sref))); else if ( SpeciesReference_getStoichiometry(sref) != 1. ) fprintf(f, "%g ", SpeciesReference_getStoichiometry(sref)); fprintf(f, "%s", SpeciesReference_getSpecies(sref)); if(k+1<Reaction_getNumProducts(r)) fprintf(f, "%s", " + "); } fprintf(f, "; "); if(Reaction_isSetKineticLaw(r)){ kl = Reaction_getKineticLaw(r); math = KineticLaw_getMath(kl); fprintf(f, "%s;", SBML_formulaToString(math)); for(k=0;k<KineticLaw_getNumParameters(kl);k++){ p = KineticLaw_getParameter(kl,k); fprintf(f, " %s", Parameter_getId(p)); if(Parameter_isSetName(p)) fprintf(f, " (%s)", Parameter_getName(p)); if(Parameter_isSetValue(p)) fprintf(f, " = %g", Parameter_getValue(p)); if(Parameter_isSetUnits(p)) fprintf(f, " [%s]", Parameter_getUnits(p)); if ( !Parameter_getConstant(p) ) fprintf(f, " (variable)"); fprintf(f, ";"); } /* fprintf(f, "\n"); */ }else fprintf(f, "# no rate law is set for this reaction."); fprintf(f, "\n"); } for(i=0;i<Model_getNumRules(m);i++){ rl = Model_getRule(m,i); if ( i == 0 ) { fprintf(f, "# Rules:\n"); } type = SBase_getTypeCode((SBase_t *)rl); if ( type == SBML_RATE_RULE ) { rr = (RateRule_t *) rl; fprintf(f, " rateRule: d%s/dt = ", RateRule_getVariable(rr)); } if ( type == SBML_ALGEBRAIC_RULE ) { alr = (AlgebraicRule_t *) rl; fprintf(f, " algebraicRule: 0 = "); } if ( type == SBML_ASSIGNMENT_RULE ) { asr = (AssignmentRule_t *) rl; fprintf(f, " assignmentRule (%s): %s = ", RuleType_toString(AssignmentRule_getType(asr)), AssignmentRule_getVariable(asr)); } if(!Rule_isSetMath(rl)){ if(Rule_isSetFormula(rl)){ Rule_setMathFromFormula(rl); } } if(Rule_isSetMath(rl)) fprintf(f, "%s\n", SBML_formulaToString(Rule_getMath(rl))); } fprintf(f, "\n"); for(i=0;i<Model_getNumEvents(m);i++){ if(i==0) fprintf(f, "# Events:\n"); e = Model_getEvent(m,i); if(Event_isSetId(e)) fprintf(f, "%s: ", Event_getId(e)); if(Event_isSetName(e)) fprintf(f, "(%s) ", Event_getName(e)); if(Event_isSetTrigger(e)) { math = Event_getTrigger(e); fprintf(f, "trigger: %s\n", SBML_formulaToString(math)); } if(Event_isSetDelay(e)) fprintf(f, "delay: %s;\n", SBML_formulaToString(Event_getDelay(e))); if(Event_isSetTimeUnits(e)) fprintf(f, "time Units: %s;\n", Event_getTimeUnits(e)); for(k=0;k<Event_getNumEventAssignments(e);k++){ ea = Event_getEventAssignment(e,k); if(EventAssignment_isSetVariable(ea)) fprintf(f, " event: %s = %s;\n", EventAssignment_getVariable(ea), EventAssignment_isSetMath(ea) ? SBML_formulaToString(EventAssignment_getMath(ea)) : "# no math set;\n"); } if(i==Model_getNumEvents(m)-1) fprintf(f, "\n"); } for ( i=0; i<Model_getNumFunctionDefinitions(m); i++ ) { if ( i==0 ) fprintf(f, "# Functions:\n"); fd = Model_getFunctionDefinition(m,i); if ( FunctionDefinition_isSetName(fd) ) fprintf(f, "%s: ", FunctionDefinition_getName(fd)); if(FunctionDefinition_isSetId(fd) && FunctionDefinition_isSetMath(fd)){ fprintf(f, "%s( ", FunctionDefinition_getId(fd)); math = FunctionDefinition_getMath(fd); for(j=0;j<ASTNode_getNumChildren(math)-1;j++){ fprintf(f, "%s", SBML_formulaToString(ASTNode_getChild(math, j))); if(j<ASTNode_getNumChildren(math)-2) fprintf(f, ", "); if(j==ASTNode_getNumChildren(math)-2) fprintf(f, ") = "); } fprintf(f, "%s;", SBML_formulaToString(ASTNode_getRightChild(math))); } fprintf(f, "\n"); } }
void myRule_initTarget( myRule *rule, mySpecies **species, unsigned int num_of_species, myParameter **parameters, unsigned int num_of_parameters, myCompartment **compartments, unsigned int num_of_compartments, myReaction **reactions, unsigned int num_of_reactions) { unsigned int i, j; Rule_t *origin; const char *origin_var; mySpecies *sp; myParameter *param; myCompartment *comp; myReaction *re; mySpeciesReference *product, *reactant; origin = myRule_getOrigin(rule); origin_var = Rule_getVariable(origin); for (i = 0; i < num_of_species; i++) { sp = species[i]; if (strcmp(origin_var, Species_getId(sp->origin)) == 0) { myRule_setTargetSpecies(rule, sp); mySpecies_setDependingRule(sp, rule); return; } } for (i = 0; i < num_of_parameters; i++) { param = parameters[i]; if (strcmp(origin_var, Parameter_getId(param->origin)) == 0) { myRule_setTargetParameter(rule, param); myParameter_setDependingRule(param, rule); return; } } for (i = 0; i < num_of_compartments; i++) { comp = compartments[i]; if (strcmp(origin_var, Compartment_getId(comp->origin)) == 0) { myRule_setTargetCompartment(rule, comp); myCompartment_setDependingRule(comp, rule); return; } } for (i=0; i < num_of_reactions; i++) { re = reactions[i]; for (j = 0; j < re->num_of_products; j++) { product = re->products[j]; if (SpeciesReference_isSetId(product->origin) && strcmp(origin_var, SpeciesReference_getId(product->origin)) == 0) { myRule_setTargetSpeciesReference(rule, product); mySpeciesReference_setDependingRule(product, rule); return; } } for (j = 0; j < re->num_of_reactants; j++) { reactant = re->reactants[j]; if (SpeciesReference_isSetId(reactant->origin) && strcmp(origin_var, SpeciesReference_getId(reactant->origin)) == 0) { myRule_setTargetSpeciesReference(rule, reactant); mySpeciesReference_setDependingRule(reactant, rule); return; } } } }