getModel() 공개 메소드

public getModel ( ) : Model
리턴 Model
예제 #1
0
 public void setUp()
 {
     string filename = "../../sbml/annotation/test/test-data/annotationL3.xml";
       d = libsbml.readSBML(filename);
       m = d.getModel();
       c = m.getCompartment(0);
 }
 public void test_SBMLConvertStrict_convertNonStrictSBO()
 {
     SBMLDocument d = new  SBMLDocument(2,4);
       Model m = d.createModel();
       Compartment c = m.createCompartment();
       c.setId( "c");
       c.setConstant(false);
       (c).setSBOTerm(64);
       assertTrue( d.setLevelAndVersion(2,3,true) == false );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 4 );
       assertTrue( d.setLevelAndVersion(2,2,true) == false );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 4 );
       assertTrue( d.setLevelAndVersion(2,1,true) == true );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 1 );
       Compartment c1 = d.getModel().getCompartment(0);
       assertTrue( (c1).getSBOTerm() == -1 );
       assertTrue( d.setLevelAndVersion(1,2,true) == true );
       assertTrue( d.getLevel() == 1 );
       assertTrue( d.getVersion() == 2 );
       Compartment c2 = d.getModel().getCompartment(0);
       assertTrue( (c2).getSBOTerm() == -1 );
       d = null;
 }
 public void test_SBMLConvertStrict_convertL1ParamRule()
 {
     SBMLDocument d = new  SBMLDocument(1,2);
       Model m = d.createModel();
       Compartment c = m.createCompartment();
       c.setId( "c");
       Parameter p = m.createParameter();
       p.setId( "p");
       Parameter p1 = m.createParameter();
       p1.setId( "p1");
       ASTNode math = libsbml.parseFormula("p");
       Rule ar = m.createAssignmentRule();
       ar.setVariable( "p1");
       ar.setMath(math);
       ar.setUnits( "mole");
       assertTrue( d.setLevelAndVersion(2,1,true) == true );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 1 );
       Rule r1 = d.getModel().getRule(0);
       assertTrue( r1.getUnits() == "" );
       d = null;
 }
예제 #4
0
 public void test_ReadSBML_FunctionDefinition()
 {
     FunctionDefinition fd;
       ASTNode math;
       string formula;
       string s = wrapSBML_L2v1("<listOfFunctionDefinitions>" +
     "  <functionDefinition id='pow3' name='cubed'>" +
     "    <math>" +
     "      <lambda>" +
     "        <bvar><ci> x </ci></bvar>" +
     "        <apply>" +
     "          <power/>" +
     "          <ci> x </ci>" +
     "          <cn> 3 </cn>" +
     "        </apply>" +
     "      </lambda>" +
     "    </math>" +
     "  </functionDefinition>" +
     "</listOfFunctionDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumFunctionDefinitions() == 1 );
       fd = M.getFunctionDefinition(0);
       assertTrue( fd != null );
       assertEquals( true, fd.isSetId() );
       assertEquals( true, fd.isSetName() );
       assertTrue((  "pow3"   == fd.getId() ));
       assertTrue((  "cubed"  == fd.getName() ));
       assertEquals( true, fd.isSetMath() );
       math = fd.getMath();
       formula = libsbml.formulaToString(math);
       assertTrue( formula != null );
       assertTrue((  "lambda(x, pow(x, 3))" == formula ));
 }
 public void test_SBMLConvertStrict_convertToL1()
 {
     SBMLDocument d = new  SBMLDocument(2,4);
       Model m = d.createModel();
       (m).setMetaId( "_m");
       Compartment c = m.createCompartment();
       c.setId( "c");
       (c).setSBOTerm(240);
       Species s = m.createSpecies();
       s.setId( "s");
       s.setCompartment( "c");
       assertTrue( d.setLevelAndVersion(1,2,true) == true );
       assertTrue( d.getLevel() == 1 );
       assertTrue( d.getVersion() == 2 );
       Model m1 = d.getModel();
       assertTrue( (m1).getMetaId() == "" );
       Compartment c1 = m1.getCompartment(0);
       assertTrue( (c1).getSBOTerm() == -1 );
       Species s1 = m1.getSpecies(0);
       assertTrue( s1.getHasOnlySubstanceUnits() == false );
       d = null;
 }
 public void test_SBMLConvert_convertToL3_localParameters()
 {
     SBMLDocument d = new  SBMLDocument(1,2);
       Model m = d.createModel();
       Compartment c = m.createCompartment();
       c.setId( "c" );
       Species s = m.createSpecies();
       s.setId( "s");
       s.setCompartment( "c");
       Reaction r = m.createReaction();
       SpeciesReference sr = r.createReactant();
       sr.setSpecies( "s");
       KineticLaw kl = r.createKineticLaw();
       kl.setFormula( "s*k");
       Parameter p = kl.createParameter();
       p.setId( "k");
       assertTrue( kl.getNumLocalParameters() == 0 );
       assertTrue( d.setLevelAndVersion(3,1,false) == true );
       m = d.getModel();
       r = m.getReaction(0);
       kl = r.getKineticLaw();
       assertTrue( kl.getNumLocalParameters() == 1 );
       LocalParameter lp = kl.getLocalParameter(0);
       d = null;
 }
 public void test_SBMLConvert_convertFromL3_modelUnits()
 {
     UnitDefinition ud;
       SBMLDocument d = new  SBMLDocument(3,1);
       Model m = d.createModel();
       m.setVolumeUnits( "litre");
       assertTrue( m.getNumUnitDefinitions() == 0 );
       assertTrue( d.setLevelAndVersion(1,2,false) == true );
       m = d.getModel();
       assertTrue( m.getNumUnitDefinitions() == 1 );
       ud = m.getUnitDefinition(0);
       assertTrue((  "volume" == ud.getId() ));
       assertTrue( ud.getNumUnits() == 1 );
       assertTrue( ud.getUnit(0).getKind() == libsbml.UNIT_KIND_LITRE );
 }
예제 #8
0
 public void test_Model_ancestor_create()
 {
     SBMLDocument d = new SBMLDocument();
       Model m = d.createModel();
       assertTrue( m.getAncestorOfType(libsbml.SBML_DOCUMENT) == d );
       Model obj = d.getModel();
       assertTrue( obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == d );
       d = null;
 }
예제 #9
0
 public void test_ReadSBML_metaid()
 {
     SBase sb;
       string s = wrapSBML_L2v1("<listOfFunctionDefinitions>" +
     "  <functionDefinition metaid='fd'/>" +
     "</listOfFunctionDefinitions>" +
     "<listOfUnitDefinitions>" +
     "  <unitDefinition metaid='ud'/>" +
     "</listOfUnitDefinitions>" +
     "<listOfCompartments>" +
     "  <compartment metaid='c'/>" +
     "</listOfCompartments>" +
     "<listOfSpecies>" +
     "  <species metaid='s'/>" +
     "</listOfSpecies>" +
     "<listOfParameters>" +
     "  <parameter metaid='p'/>" +
     "</listOfParameters>" +
     "<listOfRules>" +
     "  <rateRule metaid='rr'/>" +
     "</listOfRules>" +
     "<listOfReactions>" +
     "  <reaction metaid='rx'/>" +
     "</listOfReactions>" +
     "<listOfEvents>" +
     " <event metaid='e'/>" +
     "</listOfEvents>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M != null );
       sb = M.getFunctionDefinition(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "fd" == sb.getMetaId() ));
       sb = M.getUnitDefinition(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "ud" == sb.getMetaId() ));
       sb = M.getCompartment(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "c" == sb.getMetaId() ));
       sb = M.getSpecies(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "s" == sb.getMetaId() ));
       sb = M.getParameter(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "p" == sb.getMetaId() ));
       sb = M.getRule(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "rr" == sb.getMetaId() ));
       sb = M.getReaction(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "rx" == sb.getMetaId() ));
       sb = M.getEvent(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "e" == sb.getMetaId() ));
 }
예제 #10
0
        public void test_ReadSBML_line_col_numbers()
        {
            //setXMLParser();

              SBase sb;
              string s = "<?xml version='1.0' encoding='UTF-8'?>\n" +
            "<sbml xmlns='http://www.sbml.org/sbml/level2' level='2' version='1'>\n" +
            "  <model id='testModel' name='testModel'>\n" +
            "    <listOfReactions> <reaction/> </listOfReactions>\n" +
            "  </model>\n" +
            "</sbml>\n";
              D = libsbml.readSBMLFromString(s);
              M = D.getModel();
              assertTrue( M != null );
              sb = M;
              sb = M.getListOfReactions();
              sb = M.getReaction(0);
        }
예제 #11
0
 public void test_ReadSBML_KineticLaw_Parameter()
 {
     Reaction r;
       KineticLaw kl;
       Parameter p;
       string s = wrapSBML_L1v2("<listOfReactions>" +
     "  <reaction name='J1'>" +
     "    <kineticLaw formula='k1*X0'>" +
     "      <listOfParameters>" +
     "        <parameter name='k1' value='0'/>" +
     "      </listOfParameters>" +
     "    </kineticLaw>" +
     "  </reaction>" +
     "</listOfReactions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumReactions() == 1 );
       r = M.getReaction(0);
       kl = r.getKineticLaw();
       assertTrue((  "k1*X0" == kl.getFormula() ));
       assertTrue( kl.getNumParameters() == 1 );
       p = kl.getParameter(0);
       assertTrue((  "k1" == p.getId() ));
       assertTrue( p.getValue() == 0 );
 }
예제 #12
0
 public void test_ReadSBML_KineticLaw_L2()
 {
     Reaction r;
       KineticLaw kl;
       ASTNode math;
       string formula;
       string s = wrapSBML_L2v1("<listOfReactions>" +
     "  <reaction id='J1'>" +
     "    <kineticLaw>" +
     "      <math>" +
     "        <apply>" +
     "          <times/>" +
     "          <ci> k  </ci>" +
     "          <ci> S2 </ci>" +
     "          <ci> X0 </ci>" +
     "        </apply>" +
     "      </math>" +
     "    </kineticLaw>" +
     "  </reaction>" +
     "</listOfReactions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumReactions() == 1 );
       r = M.getReaction(0);
       assertTrue( r != null );
       kl = r.getKineticLaw();
       assertTrue( kl != null );
       assertEquals( true, kl.isSetMath() );
       math = kl.getMath();
       formula = kl.getFormula();
       assertTrue( formula != null );
       assertTrue((  "k * S2 * X0" == formula ));
 }
예제 #13
0
 public void test_ReadSBML_KineticLaw()
 {
     Reaction r;
       KineticLaw kl;
       string s = wrapSBML_L1v2("<listOfReactions>" +
     "  <reaction name='J1'>" +
     "    <kineticLaw formula='k1*X0'/>" +
     "  </reaction>" +
     "</listOfReactions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumReactions() == 1 );
       r = M.getReaction(0);
       kl = r.getKineticLaw();
       assertTrue((  "k1*X0" == kl.getFormula() ));
 }
예제 #14
0
 public void test_ReadSBML_FunctionDefinition_OnlyBVars()
 {
     FunctionDefinition fd;
       SBMLError error;
       int numErrors;
       ASTNode math;
       string formula;
       string s = wrapSBML_L2v1("<listOfFunctionDefinitions>" +
     "  <functionDefinition id='invalid'>" +
     "    <math xmlns='http://www.w3.org/1998/Math/MathML'>" +
     "      <lambda>" +
     "        <bvar><ci> x </ci></bvar>" +
     "        <bvar><ci> y </ci></bvar>" +
     "        <bvar><ci> z </ci></bvar>" +
     "      </lambda>" +
     "    </math>" +
     "  </functionDefinition>" +
     "</listOfFunctionDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       D.checkInternalConsistency();
       D.checkConsistency();
       numErrors = (int)D.getNumErrors();
       assertTrue( numErrors == 1 );
       error = D.getError(0);
       int errorId = (int)error.getErrorId();
       assertTrue( errorId == libsbml.NoBodyInFunctionDef );
       assertTrue( M.getNumFunctionDefinitions() == 1 );
       fd = M.getFunctionDefinition(0);
       assertTrue( fd != null );
       assertEquals( true, fd.isSetId() );
       assertEquals( false, fd.isSetName() );
       assertTrue((  "invalid"   == fd.getId() ));
       assertTrue( fd.getBody() == null );
       assertEquals( true, fd.isSetMath() );
       math = fd.getMath();
       formula = libsbml.formulaToString(math);
       assertTrue( formula != null );
       assertTrue((  "lambda(x, y, z)" == formula ));
 }
예제 #15
0
 public void test_ReadSBML_FunctionDefinition_MathReturnsCN()
 {
     FunctionDefinition fd;
       ASTNode math;
       string formula;
       string s = wrapSBML_L2v1("<listOfFunctionDefinitions>" +
     "  <functionDefinition id='getNumber'>" +
     "    <math>" +
     "      <lambda>" +
     "        <bvar><ci> x </ci></bvar>" +
     "        <cn> 42 </cn>" +
     "      </lambda>" +
     "    </math>" +
     "  </functionDefinition>" +
     "</listOfFunctionDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumFunctionDefinitions() == 1 );
       fd = M.getFunctionDefinition(0);
       assertTrue( fd != null );
       assertEquals( true, fd.isSetId() );
       assertEquals( false, fd.isSetName() );
       assertTrue((  "getNumber"   == fd.getId() ));
       assertEquals( true, fd.isSetMath() );
       math = fd.getMath();
       formula = libsbml.formulaToString(math);
       assertTrue( formula != null );
       assertTrue((  "lambda(x, 42)" == formula ));
 }
예제 #16
0
 public void test_ReadSBML_notes()
 {
     Reaction r;
       KineticLaw kl;
       string s = wrapSBML_L2v3("<listOfReactions>" +
     "<reaction name='J1'>" +
     "  <kineticLaw formula='k1*X0'>" +
     "    <notes>This is a test note.</notes>" +
     "    <listOfParameters>" +
     "      <parameter name='k1' value='0'/>" +
     "    </listOfParameters>" +
     "  </kineticLaw>" +
     "</reaction>" +
     "</listOfReactions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       r = M.getReaction(0);
       kl = r.getKineticLaw();
       assertTrue( kl.getNotes() != null );
       string notes = kl.getNotes().getChild(0).getCharacters();
       assertTrue( (  "This is a test note." != notes ) == false );
 }
예제 #17
0
 public void test_ReadSBML_notes_ListOf()
 {
     SBase sb;
       string s = wrapSBML_L2v1("<listOfFunctionDefinitions>" +
     "  <notes>My Functions</notes>" +
     "  <functionDefinition/>" +
     "</listOfFunctionDefinitions>" +
     "<listOfUnitDefinitions>" +
     "  <notes>My Units</notes>" +
     "  <unitDefinition/>" +
     "</listOfUnitDefinitions>" +
     "<listOfCompartments>" +
     "  <notes>My Compartments</notes>" +
     "  <compartment/>" +
     "</listOfCompartments>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M != null );
       sb = M.getListOfFunctionDefinitions();
       assertEquals( true, sb.isSetNotes() );
       string notes = sb.getNotes().getChild(0).getCharacters();
       assertTrue( (  "My Functions" != notes ) == false );
       sb = M.getListOfUnitDefinitions();
       assertEquals( true, sb.isSetNotes() );
       notes = sb.getNotes().getChild(0).getCharacters();
       assertTrue( (  "My Units" != notes ) == false );
       sb = M.getListOfCompartments();
       assertEquals( true, sb.isSetNotes() );
       notes = sb.getNotes().getChild(0).getCharacters();
       assertTrue( (  "My Compartments" != notes ) == false );
 }
예제 #18
0
 public void test_ReadSBML_metaid_Event()
 {
     SBase sb;
       Event e;
       string s = wrapSBML_L2v1("<listOfEvents>" +
     "  <event metaid='e'>" +
     "    <listOfEventAssignments metaid='loea'>" +
     "      <eventAssignment metaid='ea'/>" +
     "    </listOfEventAssignments>" +
     "  </event>" +
     "</listOfEvents>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M != null );
       e = M.getEvent(0);
       sb = e;
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "e" == sb.getMetaId() ));
       sb = e.getListOfEventAssignments();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "loea" == sb.getMetaId() ));
       sb = e.getEventAssignment(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "ea" == sb.getMetaId() ));
 }
예제 #19
0
 public void test_Model_ancestor_add()
 {
     SBMLDocument d = new SBMLDocument(2,4);
       Model m = new Model(2,4);
       d.setModel(m);
       assertTrue( d == d.getModel().getAncestorOfType(libsbml.SBML_DOCUMENT) );
       d = null;
 }
예제 #20
0
 public void test_ReadSBML_metaid_ListOf()
 {
     SBase sb;
       string s = wrapSBML_L2v1("<listOfFunctionDefinitions metaid='lofd'/>" +
     "<listOfUnitDefinitions     metaid='loud'/>" +
     "<listOfCompartments        metaid='loc'/>" +
     "<listOfSpecies             metaid='los'/>" +
     "<listOfParameters          metaid='lop'/>" +
     "<listOfRules               metaid='lor'/>" +
     "<listOfReactions           metaid='lorx'/>" +
     "<listOfEvents              metaid='loe'/>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M != null );
       sb = M.getListOfFunctionDefinitions();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "lofd" == sb.getMetaId() ));
       sb = M.getListOfUnitDefinitions();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "loud" == sb.getMetaId() ));
       sb = M.getListOfCompartments();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "loc" == sb.getMetaId() ));
       sb = M.getListOfSpecies();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "los" == sb.getMetaId() ));
       sb = M.getListOfParameters();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "lop" == sb.getMetaId() ));
       sb = M.getListOfRules();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "lor" == sb.getMetaId() ));
       sb = M.getListOfReactions();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "lorx" == sb.getMetaId() ));
       sb = M.getListOfEvents();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "loe" == sb.getMetaId() ));
 }
 public void test_Model_parent_add()
 {
     SBMLDocument d = new SBMLDocument(2,4);
       Model m = new Model(2,4);
       d.setModel(m);
       assertTrue( d == d.getModel().getParentSBMLObject() );
       d = null;
 }
예제 #22
0
 public void test_ReadSBML_metaid_Reaction()
 {
     SBase sb;
       Reaction r;
       string s = wrapSBML_L2v1("<listOfReactions>" +
     "  <reaction metaid='r'>" +
     "    <listOfReactants metaid='lor'>" +
     "      <speciesReference metaid='sr1'/>" +
     "    </listOfReactants>" +
     "    <listOfProducts metaid='lop'>" +
     "      <speciesReference metaid='sr2'/>" +
     "    </listOfProducts>" +
     "    <listOfModifiers metaid='lom'>" +
     "      <modifierSpeciesReference metaid='msr'/>" +
     "    </listOfModifiers>" +
     "    <kineticLaw metaid='kl'/>" +
     "  </reaction>" +
     "</listOfReactions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M != null );
       r = M.getReaction(0);
       sb = r;
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "r" == sb.getMetaId() ));
       sb = r.getListOfReactants();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "lor" == sb.getMetaId() ));
       sb = r.getReactant(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "sr1" == sb.getMetaId() ));
       sb = r.getListOfProducts();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "lop" == sb.getMetaId() ));
       sb = r.getProduct(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "sr2" == sb.getMetaId() ));
       sb = r.getListOfModifiers();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "lom" == sb.getMetaId() ));
       sb = r.getModifier(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "msr" == sb.getMetaId() ));
       sb = r.getKineticLaw();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "kl" == sb.getMetaId() ));
 }
 public void test_SBMLConvert_convertToL2v4_DuplicateAnnotations_model()
 {
     SBMLDocument d = new  SBMLDocument(2,1);
       Model m = d.createModel();
       string annotation =  "<rdf/>\n<rdf/>";
       int i = (m).setAnnotation(annotation);
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 1 );
       assertTrue( (m).getAnnotation().getNumChildren() == 2 );
       assertTrue( d.setLevelAndVersion(2,4,true) == true );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 4 );
       m = d.getModel();
       assertTrue( (m).getAnnotation().getNumChildren() == 1 );
       d = null;
 }
예제 #24
0
 public void test_ReadSBML_metaid_Unit()
 {
     SBase sb;
       UnitDefinition ud;
       string s = wrapSBML_L2v1("<listOfUnitDefinitions>" +
     "  <unitDefinition metaid='ud'>" +
     "    <listOfUnits metaid='lou'>" +
     "      <unit metaid='u'/>" +
     "    </listOfUnits>" +
     "  </unitDefinition>" +
     "</listOfUnitDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M != null );
       ud = M.getUnitDefinition(0);
       sb = ud;
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "ud" == sb.getMetaId() ));
       sb = ud.getListOfUnits();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "lou" == sb.getMetaId() ));
       sb = ud.getUnit(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "u" == sb.getMetaId() ));
 }
 public void test_SBMLConvert_convertToL3_stoichiometryMath()
 {
     SBMLDocument d = new  SBMLDocument(2,1);
       Model m = d.createModel();
       Compartment c = m.createCompartment();
       c.setId( "c" );
       Species s = m.createSpecies();
       s.setId( "s");
       s.setCompartment( "c");
       Reaction r = m.createReaction();
       SpeciesReference sr = r.createReactant();
       sr.setSpecies( "s");
       StoichiometryMath sm = sr.createStoichiometryMath();
       ASTNode ast = libsbml.parseFormula("c*2");
       sm.setMath(ast);
       assertTrue( m.getNumRules() == 0 );
       assertTrue( sr.isSetId() == false );
       assertTrue( d.setLevelAndVersion(3,1,false) == true );
       m = d.getModel();
       r = m.getReaction(0);
       sr = r.getReactant(0);
       assertTrue( m.getNumRules() == 1 );
       assertTrue( sr.isSetId() == true );
       Rule rule = m.getRule(0);
       assertTrue(( rule.getVariable() == sr.getId() ));
       d = null;
 }
예제 #26
0
 public void test_ReadSBML_AlgebraicRule()
 {
     Rule ar;
       string s = wrapSBML_L1v2("<listOfRules>" +
     "  <algebraicRule formula='x + 1'/>" +
     "</listOfRules>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumRules() == 1 );
       ar = M.getRule(0);
       assertTrue((  "x + 1" == ar.getFormula() ));
 }
예제 #27
0
 public void test_ReadSBML_Model()
 {
     string s = wrapXML("<sbml level='1' version='1'>" +
     "  <model name='testModel'></model>" +
     "</sbml>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue((  "testModel" == M.getId() ));
 }
예제 #28
0
 public void test_ReadSBML_Model_L2()
 {
     string s = wrapXML("<sbml level='2' version='1'>" +
     "  <model id='testModel'> </model>" +
     "</sbml>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertEquals( true, M.isSetId() );
       assertEquals( false, M.isSetName() );
       assertTrue((  "testModel" == M.getId() ));
 }
    //===============================================================================
    //
    //
    // Helper functions for writing/validating the given SBML documents.
    //
    //
    //===============================================================================
    /**
     *
     *  Validates the given SBMLDocument.
     *
     *   This function is based on validateSBML.cpp implemented by
     *   Sarah Keating, Ben Bornstein, and Michael Hucka.
     *
     */
    private static bool validateExampleSBML(SBMLDocument sbmlDoc)
    {
        if (sbmlDoc == null)
        {
            Console.Error.WriteLine("validateExampleSBML: given a null SBML Document");
            return false;
        }

        string consistencyMessages = "";
        string validationMessages = "";
        bool noProblems = true;
        int numCheckFailures = 0;
        int numConsistencyErrors = 0;
        int numConsistencyWarnings = 0;
        int numValidationErrors = 0;
        int numValidationWarnings = 0;

        // LibSBML 3.3 is lenient when generating models from scratch using the
        // API for creating objects.  Once the whole model is done and before it
        // gets written out, it's important to check that the whole model is in
        // fact complete, consistent and valid.

        numCheckFailures = (int)sbmlDoc.checkInternalConsistency();
        if (numCheckFailures > 0)
        {
            noProblems = false;
            for (int i = 0;
            i < numCheckFailures;
            i++)
            {
                SBMLError sbmlErr = sbmlDoc.getError(i);
                if (sbmlErr.isFatal() || sbmlErr.isError())
                {
                    ++numConsistencyErrors;
                }
                else
                {
                    ++numConsistencyWarnings;
                }
            }
            consistencyMessages = sbmlDoc.getErrorLog().toString();
        }

        // If the internal checks fail, it makes little sense to attempt
        // further validation, because the model may be too compromised to
        // be properly interpreted.

        if (numConsistencyErrors > 0)
        {
            consistencyMessages += "Further validation aborted.";
        }
        else
        {
            numCheckFailures = (int)sbmlDoc.checkConsistency();
            if (numCheckFailures > 0)
            {
                noProblems = false;
                for (int i = 0;
                i < numCheckFailures;
                i++)
                {
                    SBMLError sbmlErr = sbmlDoc.getError(i);
                    if (sbmlErr.isFatal() || sbmlErr.isError())
                    {
                        ++numValidationErrors;
                    }
                    else
                    {
                        ++numValidationWarnings;
                    }
                }

                validationMessages = sbmlDoc.getErrorLog().toString();
            }
        }

        if (noProblems)
            return true;
        else
        {
            if (numConsistencyErrors > 0)
            {
                Console.WriteLine("ERROR: encountered " + numConsistencyErrors
                + " consistency error" + (numConsistencyErrors == 1 ? "" : "s")
                + " in model '" + sbmlDoc.getModel().getId() + "'.");
            }
            if (numConsistencyWarnings > 0)
            {
                Console.WriteLine("Notice: encountered " + numConsistencyWarnings
                + " consistency warning" + (numConsistencyWarnings == 1 ? "" : "s")
                + " in model '" + sbmlDoc.getModel().getId() + "'.");
            }
            Console.WriteLine();
            Console.WriteLine(consistencyMessages);

            if (numValidationErrors > 0)
            {
                Console.WriteLine("ERROR: encountered " + numValidationErrors
                + " validation error" + (numValidationErrors == 1 ? "" : "s")
                + " in model '" + sbmlDoc.getModel().getId() + "'.");
            }
            if (numValidationWarnings > 0)
            {
                Console.WriteLine("Notice: encountered " + numValidationWarnings
                + " validation warning" + (numValidationWarnings == 1 ? "" : "s")
                + " in model '" + sbmlDoc.getModel().getId() + "'.");
            }
            Console.WriteLine();
            Console.WriteLine(validationMessages);

            return (numConsistencyErrors == 0 && numValidationErrors == 0);
        }
    }
예제 #30
0
 public void test_ReadSBML_Event_trigger()
 {
     Event e;
       Trigger trigger;
       string formula;
       string s = wrapSBML_L2v1("<listOfEvents>" +
     "  <event>" +
     "    <trigger>" +
     "      <math>" +
     "        <apply>" +
     "          <leq/>" +
     "          <ci> P1 </ci>" +
     "          <ci> t  </ci>" +
     "        </apply>" +
     "      </math>" +
     "   </trigger>" +
     "  </event>" +
     "</listOfEvents>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumEvents() == 1 );
       e = M.getEvent(0);
       assertTrue( e != null );
       assertEquals( false, e.isSetDelay() );
       assertEquals( true, e.isSetTrigger() );
       trigger = e.getTrigger();
       formula = libsbml.formulaToString(trigger.getMath());
       assertTrue( formula != null );
       assertTrue((  "leq(P1, t)" == formula ));
 }