Esempio n. 1
0
void printOdes_fromFile(char* filename)
{
		if (filename == NULL)
				return;

    int i;
    char *formula;
    variableIndex_t *vi = NULL;

    odeModel_t *model =
      ODEModel_createFromFile(filename);

	if (model == NULL)
	{
			printf("create odemodel fails:\n");
			return;
	}

    /* Get some information from constructed odeModel */
    printf("\n\n");
    printf("ODE Model Statistics:\n");
    printf("Number of ODEs:               %d\n",
	   ODEModel_getNeq(model));
    printf("Number of Assignments:        %d\n",
	   ODEModel_getNumAssignments(model));
    printf("Number of Constants:          %d\n",
	   ODEModel_getNumConstants(model));
    printf("                            ____\n");
    printf("Total number of values:       %d\n",
	   ODEModel_getNumValues(model));
    
    printf("\n");
    printf("ODEs:\n");
    for ( i=0; i<ODEModel_getNeq(model); i++ ){
      vi = ODEModel_getOdeVariableIndex(model, i);
      formula = SBML_formulaToString(ODEModel_getOde(model, vi));
      printf("d[%s]/dt = %s \n", ODEModel_getVariableName(model, vi), formula);
      free(formula);
      VariableIndex_free(vi);
    }
//    printf("Assigned Variables:\n");
//    for ( i=0; i<ODEModel_getNumAssignments(model); i++ ){
//      vi = ODEModel_getAssignedVariableIndex(model, i);
//      formula = SBML_formulaToString(ODEModel_getOde(model, vi));
//      printf("%s = %s \n", ODEModel_getVariableName(model, vi), formula);
//      free(formula);
//      VariableIndex_free(vi);
//    }
    printf("Constants:\n");
    for ( i=0; i<ODEModel_getNumConstants(model); i++ ){
      vi = ODEModel_getConstantIndex(model, i);
      printf("%s\n", ODEModel_getVariableName(model, vi));
      VariableIndex_free(vi);
    }
    printf("\n\n");

    
    ODEModel_free(model);
}
int main(void)
{
    int i;
    char *formula;
    variableIndex_t *vi = NULL;

    odeModel_t *model =
      ODEModel_createFromFile("basic-model1-forward-l2.xml");


    /* Get some information from constructed odeModel */
    printf("\n\n");
    printf("ODE Model Statistics:\n");
    printf("Number of ODEs:               %d\n",
	   ODEModel_getNeq(model));
    printf("Number of Assignments:        %d\n",
	   ODEModel_getNumAssignments(model));
    printf("Number of Constants:          %d\n",
	   ODEModel_getNumConstants(model));
    printf("                            ____\n");
    printf("Total number of values:       %d\n",
	   ODEModel_getNumValues(model));
    
    printf("\n");
    printf("ODEs:\n");
    for ( i=0; i<ODEModel_getNeq(model); i++ ){
      vi = ODEModel_getOdeVariableIndex(model, i);
      formula = SBML_formulaToString(ODEModel_getOde(model, vi));
      printf("d[%s]/dt = %s \n", ODEModel_getVariableName(model, vi), formula);
      free(formula);
      VariableIndex_free(vi);
    }
    printf("Assigned Variables:\n");
    for ( i=0; i<ODEModel_getNumAssignments(model); i++ ){
      vi = ODEModel_getAssignedVariableIndex(model, i);
      formula = SBML_formulaToString(ODEModel_getOde(model, vi));
      printf("%s = %s \n", ODEModel_getVariableName(model, vi), formula);
      free(formula);
      VariableIndex_free(vi);
    }
    printf("Constants:\n");
    for ( i=0; i<ODEModel_getNumConstants(model); i++ ){
      vi = ODEModel_getConstantIndex(model, i);
      printf("%s\n", ODEModel_getVariableName(model, vi));
      VariableIndex_free(vi);
    }
    printf("\n\n");

    
    ODEModel_free(model);
    return 1;
}
int main(void)
{
    int i, j, neq;
    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_constructSensitivity(odeModel) &&
	 ODEModel_getNeq(odeModel) ) {
      printf("\n\nSuccessfully constructed the parametric matrix S ");
      printf("as used for CVODES sensitivity analysis\n\n");
      printf("We might be interested in the `sparsity' of S,\n");
      printf("... we can just evaluate the parametric entries:\n\n");
      
      /* we need cvodeData for evaluating formulas */
      data = CvodeData_create(odeModel);
      printf("... how many parametric entries: %d\n\n",
	     ODEModel_getNsens(odeModel));
      
      /* now take a look at a all entries of S: */
      
      for ( i=0; i<ODEModel_getNeq(odeModel); i++ ) {
	
	vi = ODEModel_getOdeVariableIndex(odeModel, i);
	
	printf("\nODE VARIABLE %d: %s\n", i+1,
	       ODEModel_getVariableName(odeModel, vi));
	
	f = ODEModel_getOde(odeModel, vi);
	formula = SBML_formulaToString(f);

	printf("dY/dt =  %s \n", formula);
	free(formula);
      
	for ( j=0; j<ODEModel_getNsens(odeModel); j++ ) {
	  vj = ODEModel_getSensParamIndexByNum(odeModel, j);
	  printf("  Parameter %d: %s   ", j,
		 ODEModel_getVariableName(odeModel, vj));
	  f = ODEModel_getSensIJEntry(odeModel, i, j);
	  formula = SBML_formulaToString(f); 
	  printf("  S[%d][%d] = %s \n", i, j, formula);
	  free(formula);
	  VariableIndex_free(vj);
	}
	VariableIndex_free(vi);
      }

      printf("\n\n");      
      
      printf("Sensitivity: parametric matrix with initial conditions:\n");
      printSensiMatrix(odeModel, data);
      /* we must free this cvodeData structure */ 
      CvodeData_free(data);
      
      printf("Thx and good bye!\n");
    }
    else {
      SolverError_dumpAndClearErrors();
      printf("Sorry, for this system we couldn't generate the Parametric.\n");
      printf("Sensitivity can still be run with internal approximation.\n");
    }
      
    
    ODEModel_free(odeModel);
    return 1;
}
Esempio n. 4
0
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;
}