int
main (int argc, char *argv[]){
  int i, j;
  char *model, *parameter, *reaction;
  double start, end, steps, value;
  double time ;
  double printstep;

  /* libSBML types */
  SBMLDocument_t *d;
  SBMLReader_t *sr;

  /* SOSlib types */
  cvodeSettings_t *set;
  varySettings_t *vs;
  SBMLResultsMatrix_t *resM;
  SBMLResults_t *results;
 
  /* parsing command-line arguments */
  if (argc < 8 ) {
    fprintf(stderr,
	    "usage %s sbml-model-file simulation-time time-steps"
	    " start-value end-value step-number parameter-id"
	    " [optional reaction-id]\n",
            argv[0]);
    exit(EXIT_FAILURE);
  }
  model = argv[1];
  time = atof(argv[2]);
  printstep = atoi(argv[3]);
  
  parameter = argv[7];
  start = atof(argv[4]);
  end = atof(argv[5]);
  steps = atoi(argv[6]);
  
  if ( argc > 8 ) {
      reaction = argv[8];
  }
  else{
    reaction = NULL;
  }
  
  printf("### Varying parameter %s (reaction %s) from %f to %f in %f steps\n",
	 parameter, reaction, start, end, steps);
  
  /* parsing the SBML model with libSBML */
  sr = SBMLReader_create();
  d = SBMLReader_readSBML(sr, model);
  SBMLReader_free(sr);  

  /* Setting SBML ODE Solver integration parameters with default values */
  set = CvodeSettings_create();
  /* resetting the values we need */
  CvodeSettings_setTime(set, time, printstep);
  CvodeSettings_setErrors(set, 1e-18, 1e-10, 10000);
  CvodeSettings_setSwitches(set, 1, 0, 1, 1, 1, 0, 0); 
  CvodeSettings_setSteadyState(set, 1); 

  /* Setting SBML Ode Solver batch integration parameters */
  vs = VarySettings_allocate(1, steps+1);
  VarySettings_addParameter(vs, parameter, reaction, start, end);
  VarySettings_dump(vs);

  /* calling the SBML ODE Solver Batch function,
     and retrieving SBMLResults */
  resM = SBML_odeSolverBatch(d, set, vs);

  if ( resM == NULL ) {
    printf("### Parameter variation not succesful!\n");
    return(0);
  }
    /* we don't need these anymore */
  CvodeSettings_free(set);  
  SBMLDocument_free(d);
  VarySettings_free(vs);

  results = resM->results[0][0];

  for ( i=0; i<resM->i; i++ ) {
    for ( j=0; j<resM->j; j++ ) {
      results = SBMLResultsMatrix_getResults(resM, i, j);
      printf("### RESULTS Parameter %d, Step %d \n", i+1, j+1);
      /* printing results only for species*/
      SBMLResults_dumpSpecies(results);
    }
  }

  /* SolverError_dumpAndClearErrors(); */
  SBMLResultsMatrix_free(resM);
  return (EXIT_SUCCESS);  
}
Ejemplo n.º 2
0
int
main (int argc, char *argv[]){
  int i;
  char *model;

  /* libSBML types */
  SBMLDocument_t *d;
  SBMLReader_t *sr;

  /* SOSlib types */
  SBMLResults_t *results;
  cvodeSettings_t *set;

  double printstep;
  double endtime;
  
  /* parsing command-line arguments */
  if (argc < 2 ) {
    fprintf(stderr,
	    "usage %s sbml-model-file\n",
            argv[0]);
    exit(EXIT_FAILURE);
  }
  model = argv[1];   

  /* parsing the SBML model with libSBML */
  sr = SBMLReader_create();
  d = SBMLReader_readSBML(sr, model);
  SBMLReader_free(sr);
  
  /* Setting SBML ODE Solver integration parameters  */
  set = CvodeSettings_create();
  /* setting endtime to 25 and printstep number to 6 */  
  printstep = 6;
  endtime = 25;
  CvodeSettings_setTime(set, endtime, printstep);
 
  /* writing predefined output times:
     IMPORTANT: can not exceed the set printstep number !!
                and first time must equal 0 !! */
  CvodeSettings_setTimeStep(set, 1, 0.5);
  for ( i=2; i<=CvodeSettings_getPrintsteps(set); i++ ) 
    CvodeSettings_setTimeStep(set, i, (i-1)*(i-1));

  /* printing integration settings */
  /* CvodeSettings_dump(set); */
  
  /* calling the SBML ODE Solver, and retrieving SBMLResults */  
  results = SBML_odeSolver(d, set);
  
  CvodeSettings_free(set);
  SBMLDocument_free(d);
  
  if ( results == NULL ) {
    printf("Integration not sucessful!\n");
    return (EXIT_FAILURE);  
  }

  /* printing results only for species*/
  SBMLResults_dumpSpecies(results);

  /* now we can also free the result structure */
  SBMLResults_free(results);

  return (EXIT_SUCCESS);  
}