Package org.sbml.libsbml

Examples of org.sbml.libsbml.Model


       
        extractData(lines);
  //  System.out.println("Extracted data...");
        ModelBuilder mb = new ModelBuilder();
  //        Model model = mb.buildModel(name, compartment, unitlines, jwsunitlines, metaboliteUnit, rateUnit, reactions, species, parameter, metaboliteConcentrations, assrules, algrules, ratrules);
        Model model = mb.buildModel(name, compartment, unitlines, jwsunitlines, reactions, species, parameter, metaboliteConcentrations, assrules, algrules, funrules, ratrules);
  //      System.out.println("Built model...");

  // Check the consistency of the model
//   SBMLDocument doc = new SBMLDocument();
//   doc.setModel(model);
//   System.out.println("Checking consistency...");
//   long numErrorsWarnings = 0;
//   doc.setConsistencyChecks(libsbml.CATEGORY_MODELING_PRACTICE, false);
//   try {
//       numErrorsWarnings = doc.checkConsistency();
//   } catch(Exception e) {
//       System.out.println("Caught exception doing consistency check: " + e.getMessage());
//       e.printStackTrace();
//   }
//   long numErrors = 0;
//   System.out.println("Contains " + numErrorsWarnings + " errors or warnings");
//   boolean hasErrors = false;
//   if (numErrorsWarnings > 0) {
//       for (int i = 0; i < numErrorsWarnings; i++) {
//     SBMLError err = doc.getError(i);
//     if (err.getSeverity() > libsbml.SEVERITY_WARNING) {
//         hasErrors = true;
//         break;
//     }
//       }
//       if (hasErrors) {
//     try {
//         PrintWriter out = new PrintWriter(name + ".txt");
//         System.out.println("Found " + numErrorsWarnings + " errors or warnings for model " + name);
//         out.println("Found " + numErrorsWarnings + " errors for model " + name);
//         for (int i = 0; i < numErrorsWarnings; i++) {
//       SBMLError err = doc.getError(i);
//       if (err.getSeverity() > libsbml.SEVERITY_WARNING) {
//           out.println(err.getMessage());
//           numErrors++;
//       }
//         }
//         out.close();
//     }
//     catch (IOException e) {
//         System.out.println("Caught IOException: " + e.getMessage());
//     }
//       }
//   }
//   if (hasErrors) {
//       throw new Exception("Invalid SBML: " + numErrors + " errors");
//   }
  // Write the xml string
        String xmlmodel = new String(model.toSBML());
        if(xmlmodel != null && xmlmodel.length() > 0){
            String h = getHeader();
            xml = h + xmlmodel +
            "</sbml>";
        }
View Full Code Here


 
   @Test
   @Ignore
      public void testEvaluateLightFunction() throws IOException {
          SBMLDocument light = libsbml.readSBML(Light.getAbsolutePath());
          Model m = light.getModel();
          ListOfFunctionDefinitions lofd = m.getListOfFunctionDefinitions();
          for (long i = 0; i < lofd.size(); i++) {
              FunctionDefinition fd = lofd.get(i);
            
              ASTNode root = convertSBMLMathToJavaMath(fd.getMath());
             
              System.err.println(new FormulaFormatter().formulaToString(root));

              // over each timestep
              for (double step = 0.1; step < 100; step += 0.5) {
                  EvaluationContext ec = new EvaluationContext();
                  for (ASTCi s : root.getIdentifiers()) {
                      if (!("t".equals(s.getString()))) {
                          double value = m.getParameter(s.getString()).getValue();
                          ec.setValueFor(s.getString(), value);
                      }

                  }
                  ec.setValueFor("t", step);
                  // evaluate 7th child of function math which is the actual formula
                  ASTNumber num = root.getChildAtIndex(7).evaluate(ec);
                  // this is the output
                  System.err.println(step + "\t" + num.getValue());
                  // now check events
                  for (long j = 0; j < m.getListOfEvents().size(); j++) {

                      Event eve = m.getListOfEvents().get(j);
                      Trigger trig = eve.getTrigger();
                    
                      // check triggers which we know are just time dependent
                      ASTNode root3 = convertSBMLMathToJavaMath(trig.getMath());
                      EvaluationContext e2 = new EvaluationContext();
                      e2.setValueFor("t", step);
                     

                      // if triggered
                      if (root3.evaluate(e2).isTruth()) {
                          // now do assignments
                          for (long k = 0; k < eve.getNumEventAssignments(); k++) {
                              EventAssignment ea = eve.getEventAssignment(k);
                              String var = ea.getVariable();
                              ASTNode rootAssign =convertSBMLMathToJavaMath(ea.getMath());
                              // evaluate assignment statements
                              EvaluationContext ec3 = new EvaluationContext();
                              for (ASTCi s : rootAssign.getIdentifiers()) {
                                  // assume we're just using parameters but this may
                                  // not be valid. T is not a parameter so must be defined
                                  // separately.
                                  if (!("t".equals(s.getString()))) {
                                      double value = m
                                              .getParameter(s.getString())
                                              .getValue();
                                      ec3.setValueFor(s.getString(), value);
                                  }

                              }
                              ec3.setValueFor("t", step);
                              // assume we're assigning a parameter value.
                              if (m.getParameter(var) != null) {
                                  m.getParameter(var).setValue(
                                          rootAssign.evaluate(ec3).getValue());
                              }

                          }
                      }
View Full Code Here

TOP

Related Classes of org.sbml.libsbml.Model

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.