Exemplo n.º 1
0
/** C.0: Loads, validates and parses an SBML file,
    also converts SBML level 1 to level 2 files,
    return NULL if errors were encountered during libSBML
    validation and consistency check, stores libSBML warngings
*/
SBMLDocument_t *
parseModel(char *file, int printMessage, int validate, char *schemaPath,
	   char *schema11FileName,
	   char *schema12FileName,
	   char *schema21FileName)
{
    unsigned int i, errors ;
    SBMLDocument_t *d;
    SBMLDocument_t *d2;
    SBMLReader_t *sr;

    if ( validate ) {
        if (  printMessage ) {
            fprintf(stderr, "Validating SBML.\n");
            fprintf(stderr, "This can take a while for SBML level 2.\n");
        }
        sr = newSBMLReader(schemaPath,
			   schema11FileName,
			   schema12FileName,
			   schema21FileName);
    }
    else {
        sr = SBMLReader_create();
    }

    d = SBMLReader_readSBML(sr, file);
    SBMLReader_free(sr);
    
    errors = 0;
    if ( validate ) {
      errors = SBMLDocument_getNumFatals(d) + SBMLDocument_getNumErrors(d);
    }
    
    if (SBMLDocument_getNumFatals(d) + SBMLDocument_getNumErrors(d) == 0)
        SBMLDocument_checkConsistency(d);
        /* AMF 9th Dec 2005 added back because inconsistent models can cause the
           solver to crash despite the consistancy check causing memory leaks - talk to Ben B! */

    /* check for warnings and errors */
    for (i =0 ; i != SBMLDocument_getNumWarnings(d); i++)
        storeSBMLError(WARNING_ERROR_TYPE, SBMLDocument_getWarning(d, i)); 

    for (i =0 ; i != SBMLDocument_getNumErrors(d); i++)
        storeSBMLError(ERROR_ERROR_TYPE, SBMLDocument_getError(d, i)); 

    for (i =0 ; i != SBMLDocument_getNumFatals(d); i++)
        storeSBMLError(FATAL_ERROR_TYPE, SBMLDocument_getFatal(d, i)); 

    RETURN_ON_ERRORS_WITH(NULL);
    
    /* convert level 1 models to level 2 */
    if ( SBMLDocument_getLevel(d) == 1 ) {      
        d2 = convertModel(d);
        SBMLDocument_free(d);
        if ( printMessage )
            fprintf(stderr, "SBML converted from level 1 to level 2.\n"); 
        return (d2);
    }
    return (d);
}
Exemplo n.º 2
0
SBMLReader_t *
newSBMLReader (char *schemaPath,
	       char *schema11,
	       char *schema12,
	       char *schema21)
{
  SBMLReader_t *sr;
  char *schema[3];

  schema[0] = concat(schemaPath, schema11);
  schema[1] = concat(schemaPath, schema12);
  schema[2] = concat(schemaPath, schema21);

  sr = SBMLReader_create();

  SBMLReader_setSchemaValidationLevel(sr, XML_SCHEMA_VALIDATION_BASIC);
  SBMLReader_setSchemaFilenameL1v1(sr, schema[0]);
  SBMLReader_setSchemaFilenameL1v2(sr, schema[1]);
  SBMLReader_setSchemaFilenameL2v1(sr, schema[2]);

  free(schema[0]);
  free(schema[1]);
  free(schema[2]);
  
  return (sr);  
}
Exemplo n.º 3
0
int
main (int argc, char *argv[]){
  int i, j;
  char *model;
  double time;
  double printstep;
  /* libSBML types */
  SBMLDocument_t *d;
  SBMLReader_t *sr;
  Model_t *m;
  /* SOSlib types */
  SBMLResults_t *results;
  timeCourse_t *tc;
  cvodeSettings_t *set;

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

  /* 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();
  CvodeSettings_setTime(set, time, printstep);
  CvodeSettings_setErrors(set, 1e-9, 1e-4, 1000);

  /* calling the SBML ODE Solver which returns SBMLResults */  
  results = SBML_odeSolver(d, set);
  
  if ( SolverError_getNum(FATAL_ERROR_TYPE) ) {
    printf("Integration not sucessful!\n");
    SolverError_dumpAndClearErrors();
    return(EXIT_FAILURE);
  }

  /* now we have the results and can free the inputs */
  CvodeSettings_free(set);
  SBMLDocument_free(d);

  /* print results */
  printf("### RESULTS \n");  
  SBMLResults_dump(results);
  SolverError_dumpAndClearErrors();
  /* now we can also free the result structure */
  SBMLResults_free(results);

  return (EXIT_SUCCESS);  
}
int
main (int argc, char *argv[]){
  int i, j;
  char *model;
  double time;
  double printstep;
  /* libSBML types */
  SBMLDocument_t *d;
  SBMLReader_t *sr;
  Model_t *m;
  Reaction_t *r;
  KineticLaw_t *kl;
  ASTNode_t *nary;
  ASTNode_t *diff;
  /* SOSlib types */
  SBMLResults_t *results;
  timeCourse_t *tc;
  cvodeSettings_t *set;

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

  /* parsing the SBML model with libSBML */
  sr = SBMLReader_create();
  d = SBMLReader_readSBML(sr, model);
  SBMLReader_free(sr);

  m = SBMLDocument_getModel(d);

  r = Model_getReaction(m,0);
  kl = Reaction_getKineticLaw(r);
  nary = KineticLaw_getMath(kl);
  printf("N-ary formula: %s\n", SBML_formulaToString(nary));
  diff = differentiateAST(nary, "Product");
  printf("N-ary diff: %s\n", SBML_formulaToString(diff));
  ASTNode_free(diff);

  return (EXIT_SUCCESS);  
}
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);  
}
Exemplo n.º 6
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);  
}