int main (void) { cvodeSettings_t *options = CvodeSettings_createWithTime(10000, 1000); odeModel_t *odemodel = ODEModel_createFromFile("MAPK.xml"); integratorInstance_t *ii = IntegratorInstance_create(odemodel, options); ASTNode_t *f = SBML_parseFormula("MAPK_PP"); ASTNode_t *f2 = SBML_parseFormula("MAPK + MAPK_P"); ASTNode_t *f3 = SBML_parseFormula("MAPK + MAPK_P + MAPK_PP"); cvodeData_t *data = IntegratorInstance_getData(ii); while( ! IntegratorInstance_timeCourseCompleted(ii) ) if ( IntegratorInstance_integrateOneStep(ii ) ) { printf(" active MAPK concentration at time %g:\t%7.3f\n", IntegratorInstance_getTime(ii), evaluateAST(f, data)); printf("inactive MAPK concentration at time %g:\t%7.3f\n", IntegratorInstance_getTime(ii), evaluateAST(f2, data)); printf(" total:\t%7.3f\n\n", evaluateAST(f3, data)); } else break; SolverError_dump(); ODEModel_free(odemodel); IntegratorInstance_free(ii); ASTNode_free(f); ASTNode_free(f2); return (EXIT_SUCCESS); }
void DumpState( integratorInstance_t *iia, variableIndex_t *v1, variableIndex_t *v2 ) { printf( " %g %g %g\n", IntegratorInstance_getTime(iia), IntegratorInstance_getVariableValue(iia, v1), IntegratorInstance_getVariableValue(iia, v2)); }
END_TEST START_TEST(test_IntegratorInstance_integrate) { integratorInstance_t *ii; cvodeSettings_t *cs; int r; model = ODEModel_createFromFile(EXAMPLES_FILENAME("MAPK.xml")); cs = CvodeSettings_create(); ii = IntegratorInstance_create(model, cs); r = IntegratorInstance_integrate(ii); ck_assert_int_eq(r, 1); CHECK_DOUBLE_WITH_TOLERANCE(IntegratorInstance_getTime(ii), 1.0); ck_assert_int_eq(IntegratorInstance_timeCourseCompleted(ii), 1); CvodeSettings_free(cs); IntegratorInstance_free(ii); }
int main (int argc, char *argv[]) { int neq, nass, nconst; char *x[3]; double x0[3]; char *ode[2]; ASTNode_t *ast[2]; double time, rtol, atol; double printstep; /* SBML model containing events */ Model_t *events; /* SOSlib types */ odeModel_t *om; cvodeSettings_t *set; integratorInstance_t *ii; variableIndex_t *vi; /* parsing input ODEs and settings */ /* time and error settings */ time = 0.5; rtol = atol = 1.0E-9; printstep = 10; /* variables */ neq = 2; x[0] = "C_cy"; x0[0] = 0.0; ode[0] = "((150.0 * (3.8 - (p * D_cy) - (p * C_cy)) * (1.0 - (p * C_cy))) - (9.0 * C_cy))"; x[1] = "D_cy"; x0[1] = 9.0; ode[1] = "(3.8 - (3.0 * D_cy) - (p * D_cy) - (p * C_cy))"; /* parameters */ nconst = 1; x[2] = "p"; x0[2] = 0.2; /* assignments */ nass = 0; /* SBML model containing events */ events = NULL; /* creating ODE ASTs from strings */ ast[0] = SBML_parseFormula(ode[0]); ast[1] = SBML_parseFormula(ode[1]); /* end of input parsing */ /* Setting SBML ODE Solver integration parameters */ set = CvodeSettings_createWithTime(time, printstep); CvodeSettings_setErrors(set, atol, rtol, 1e4); CvodeSettings_setStoreResults(set, 0); /* activating default sensitivity */ CvodeSettings_setSensitivity(set, 1); /* creating odeModel */ /* `events' could be an SBML model containing events */ om = ODEModel_createFromODEs(ast, neq, nass, nconst, x, x0, events); /* creating integrator */ ii = IntegratorInstance_create(om,set); /* integrate */ printf("integrating:\n"); while( !IntegratorInstance_timeCourseCompleted(ii) ) { if ( !IntegratorInstance_integrateOneStep(ii) ) { SolverError_dump(); break; } else IntegratorInstance_dumpData(ii); } /* Specific data interfaces: */ /* names are stored in the odeModel and values are independently stored in the integrator: you can get different values from different integrator instances built from the same model */ vi = ODEModel_getVariableIndex(om, "C_cy"); printf("\nVariable %s has final value of %g at time %g\n\n", ODEModel_getVariableName(om, vi), IntegratorInstance_getVariableValue(ii, vi), IntegratorInstance_getTime(ii)); VariableIndex_free(vi); vi = ODEModel_getVariableIndex(om, "p"); printf("Sensitivies to %s:\n", ODEModel_getVariableName(om, vi)); IntegratorInstance_dumpPSensitivities(ii, vi); printf("\n\n"); VariableIndex_free(vi); /* finished, free stuff */ /* free ASTs */ ASTNode_free(ast[0]); ASTNode_free(ast[1]); /* free solver structures */ IntegratorInstance_free(ii); ODEModel_free(om); CvodeSettings_free(set); return (EXIT_SUCCESS); }
int main(void) { char *formula; variableIndex_t *vi = NULL; variableIndex_t *vj = NULL; const ASTNode_t *f = NULL; cvodeData_t *data = NULL; cvodeSettings_t *set; integratorInstance_t *iI; /* first load an SBML model and directly construct the internal odeModel from it */ odeModel_t *odeModel = ODEModel_createFromFile("MAPK.xml"); if ( ODEModel_constructJacobian(odeModel) && ODEModel_getNeq(odeModel) ) { printf("\n\nSuccessfully constructed the jacobian matrix J\n\n"); printf("We might be interested in the `sparsity' of J,\n"); printf("... we can just evaluate the jacobian entries:\n\n"); /* we need cvodeData for evaluating formulas */ data = CvodeData_create(odeModel); /* ! IMPORTANT : initialize values */ CvodeData_initializeValues(data); printf("Jacobian with initial conditions:\n"); printJacobian(odeModel, data); /* we must free this cvodeData structure */ CvodeData_free(data); printf("Does it change after integration?\n\n"); /* creating settings and integrate */ set = CvodeSettings_create(); CvodeSettings_setTime(set, 1000, 1); iI = IntegratorInstance_create(odeModel, set); IntegratorInstance_integrate(iI); /* get cvodeData from integratorInstance, it contains the values at the last time point, and just do the same as above */ data = IntegratorInstance_getData(iI); printf("Jacobian at time %g:\n", IntegratorInstance_getTime(iI)); printJacobian(odeModel, data); printf("J[6,4] changed its sign. Let's take a look at the equations:\n\n"); vi = ODEModel_getOdeVariableIndex(odeModel, 6); vj = ODEModel_getOdeVariableIndex(odeModel, 4); f = ODEModel_getOde(odeModel, vi); formula = SBML_formulaToString(f); printf("The ODE d%s/dt = \n%s \n\n", ODEModel_getVariableName(odeModel, vi), formula); free(formula); f = ODEModel_getJacobianEntry(odeModel, vi, vj); formula = SBML_formulaToString(f); printf("The jacobian entry (d%s/dt)/d%s = \n%s \n\n", ODEModel_getVariableName(odeModel, vi), ODEModel_getVariableName(odeModel, vj), formula); free(formula); VariableIndex_free(vi); VariableIndex_free(vj); printf("MAPK_P is both a substrate and a product of MKK_PP "); printf("in different reactions.\nTherefor the corresponding "); printf("entry in the jacobian can change its sign, depending "); printf("on concentrations!\n"); /* finally draw a `species interaction graph' of the jacobian' */ drawJacoby(data, "jacobian", "gif"); printf("Take a look at jacobian interaction graph in"); printf("file jacobian_jm.gif that has just been constructed.\n"); printf("If you have compiled w/o graphviz, you just have a textfile"); printf(" jacobian.dot\n"); printf("Thx and good bye!\n"); /* note that this cvodeData MUST NOT be freed, it stays with and will be freed together with integratorInstance */ IntegratorInstance_free(iI); CvodeSettings_free(set); } else { SolverError_dumpAndClearErrors(); printf("Sorry, for this system we couldn't generate the Jacobian.\n"); printf("Integration can still be run with internal approximation.\n"); } ODEModel_free(odeModel); return 1; }