예제 #1
0
END_TEST


START_TEST (test_Reaction_getProductById)
{
  SpeciesReference_t *sr1 = SpeciesReference_create(2, 4);
  SpeciesReference_setSpecies(sr1, "P1");
  SpeciesReference_t *sr2 = SpeciesReference_create(2, 4);
  SpeciesReference_setSpecies(sr2, "P1");


  Reaction_addProduct(R, sr1);
  Reaction_addProduct(R, sr2);

  fail_unless( Reaction_getNumReactants(R) == 0 );
  fail_unless( Reaction_getNumProducts (R) == 2 );
  fail_unless( Reaction_getNumModifiers(R) == 0 );

  fail_unless( Reaction_getProductBySpecies(R, "P1") != sr1  );
  fail_unless( Reaction_getProductBySpecies(R, "P2") != sr2  );
  fail_unless( Reaction_getProductBySpecies(R, "P3") == NULL );

  SpeciesReference_free(sr1);
  SpeciesReference_free(sr2);
}
예제 #2
0
END_TEST



START_TEST (test_Reaction_addModifier1)
{
  Reaction_t *m = Reaction_create(2, 2);
  SpeciesReference_t *p 
    = SpeciesReference_createModifier(2, 2);
  SpeciesReference_t *p1 
    = SpeciesReference_createModifier(2, 2);
  SpeciesReference_setSpecies(p1, "k");
  SpeciesReference_setId(p1, "k1");

  int i = Reaction_addModifier(m, p);

  fail_unless( i == LIBSBML_INVALID_OBJECT);
  
  SpeciesReference_setSpecies(p, "k");
  SpeciesReference_setId(p, "k1");
  i = Reaction_addModifier(m, p);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( Reaction_getNumModifiers(m) == 1);

  i = Reaction_addModifier(m, p1);

  fail_unless( i == LIBSBML_DUPLICATE_OBJECT_ID);
  fail_unless( Reaction_getNumModifiers(m) == 1);

  SpeciesReference_free(p);
  SpeciesReference_free(p1);
  Reaction_free(m);
}
예제 #3
0
END_TEST


START_TEST (test_Reaction_getProduct)
{
  SpeciesReference_t *sr1 = SpeciesReference_create(2, 4);
  SpeciesReference_t *sr2 = SpeciesReference_create(2, 4);


  SpeciesReference_setSpecies(sr1, "P1");
  SpeciesReference_setSpecies(sr2, "P2");

  Reaction_addProduct(R, sr1);
  Reaction_addProduct(R, sr2);

  SpeciesReference_free(sr1);
  SpeciesReference_free(sr2);

  fail_unless( Reaction_getNumReactants(R) == 0 );
  fail_unless( Reaction_getNumProducts (R) == 2 );
  fail_unless( Reaction_getNumModifiers(R) == 0 );

  sr1 = Reaction_getProduct(R, 0);
  sr2 = Reaction_getProduct(R, 1);

  fail_unless( !strcmp(SpeciesReference_getSpecies(sr1), "P1") );
  fail_unless( !strcmp(SpeciesReference_getSpecies(sr2), "P2") );

}
예제 #4
0
END_TEST


START_TEST (test_Reaction_getModifierById)
{
  SpeciesReference_t *msr1 = SpeciesReference_createModifier(2, 4);
  SpeciesReference_t *msr2 = SpeciesReference_createModifier(2, 4);


  SpeciesReference_setSpecies(msr1, "M1");
  SpeciesReference_setSpecies(msr2, "M2");


  Reaction_addModifier(R, msr1);
  Reaction_addModifier(R, msr2);

  fail_unless( Reaction_getNumReactants(R) == 0 );
  fail_unless( Reaction_getNumProducts (R) == 0 );
  fail_unless( Reaction_getNumModifiers(R) == 2 );

  fail_unless( Reaction_getModifierBySpecies(R, "M1") != msr1 );
  fail_unless( Reaction_getModifierBySpecies(R, "M2") != msr2 );
  fail_unless( Reaction_getModifierBySpecies(R, "M3") == NULL );
  
  SpeciesReference_free(msr1);
  SpeciesReference_free(msr2);
}
END_TEST


START_TEST (test_SpeciesReference_setSpecies)
{
  const char *species = "X0";


  SpeciesReference_setSpecies(SR, species);

  fail_unless( !strcmp(SpeciesReference_getSpecies(SR), species) );
  fail_unless( SpeciesReference_isSetSpecies(SR) );

  if (SpeciesReference_getSpecies(SR) == species)
  {
    fail("SpeciesReference_setSpecies(...) did not make a copy of string.");
  }

  /* Reflexive case (pathological) */
  SpeciesReference_setSpecies(SR, SpeciesReference_getSpecies(SR));
  fail_unless( !strcmp(SpeciesReference_getSpecies(SR), species) );

  SpeciesReference_setSpecies(SR, NULL);
  fail_unless( !SpeciesReference_isSetSpecies(SR) );

  if (SpeciesReference_getSpecies(SR) != NULL)
  {
    fail("SpeciesReference_setSpecies(SR, NULL) did not clear string.");
  }
}
예제 #6
0
END_TEST


START_TEST (test_Reaction_getModifier)
{
  SpeciesReference_t *msr1 = SpeciesReference_createModifier(2, 4);
  SpeciesReference_t *msr2 = SpeciesReference_createModifier(2, 4);


  SpeciesReference_setSpecies(msr1, "M1");
  SpeciesReference_setSpecies(msr2, "M2");

  Reaction_addModifier(R, msr1);
  Reaction_addModifier(R, msr2);

  SpeciesReference_free(msr1);
  SpeciesReference_free(msr2);

  fail_unless( Reaction_getNumReactants(R) == 0 );
  fail_unless( Reaction_getNumProducts (R) == 0 );
  fail_unless( Reaction_getNumModifiers(R) == 2 );

  msr1 = Reaction_getModifier(R, 0);
  msr2 = Reaction_getModifier(R, 1);

  fail_unless(!strcmp(SpeciesReference_getSpecies(msr1), "M1"));
  fail_unless(!strcmp(SpeciesReference_getSpecies(msr2), "M2"));
}
END_TEST


START_TEST (test_SBMLConvert_addModifiersToReaction)
{
  SBMLDocument_t *d = SBMLDocument_createWithLevelAndVersion(1, 2);
  Model_t        *m = SBMLDocument_createModel(d);
  Reaction_t     *r = Model_createReaction(m);
  KineticLaw_t  *kl = Reaction_createKineticLaw(r);
  KineticLaw_setFormula(kl, "k1*S1*S2*S3*S4*S5");

  SpeciesReference_t *ssr1;
  SpeciesReference_t *ssr2;


  Species_t *s1 = Model_createSpecies( m ); 
  Species_setId( s1, "S1" );
  Species_t *s2 = Model_createSpecies( m ); 
  Species_setId( s2, "S2");
  Species_t *s3 = Model_createSpecies( m ); 
  Species_setId( s3, "S3");
  Species_t *s4 = Model_createSpecies( m ); 
  Species_setId( s4, "S4");
  Species_t *s5 = Model_createSpecies( m ); 
  Species_setId( s5, "S5");

  SpeciesReference_t *sr1 = Reaction_createReactant( r );
  SpeciesReference_t *sr2 = Reaction_createReactant( r );
  SpeciesReference_t *sr3 = Reaction_createProduct ( r );

  SpeciesReference_setSpecies(sr1, "S1");
  SpeciesReference_setSpecies(sr2, "S2");
  SpeciesReference_setSpecies(sr3, "S5");

  fail_unless( Reaction_getNumModifiers(r) == 0, NULL );

  fail_unless( SBMLDocument_setLevelAndVersionNonStrict(d, 2, 1) == 1, NULL );

  fail_unless( SBMLDocument_getLevel  (d) == 2, NULL );
  fail_unless( SBMLDocument_getVersion(d) == 1, NULL );


  fail_unless( Reaction_getNumModifiers(Model_getReaction(m, 0)) == 2, NULL );

  ssr1 = (SpeciesReference_t *) Reaction_getModifier(Model_getReaction(m, 0), 0);
  ssr2 = (SpeciesReference_t *) Reaction_getModifier(Model_getReaction(m, 0), 1);

  fail_unless( !strcmp(SpeciesReference_getSpecies(ssr1), "S3"), NULL );
  fail_unless( !strcmp(SpeciesReference_getSpecies(ssr2), "S4"), NULL );

  SBMLDocument_free(d);
}
END_TEST


START_TEST (test_SpeciesReference_setSpecies4)
{
  int i = SpeciesReference_setSpecies(sr, "mm");

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( SpeciesReference_isSetSpecies(sr) );

  i = SpeciesReference_setSpecies(sr, NULL);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( !SpeciesReference_isSetSpecies(sr) );
}
END_TEST


START_TEST (test_L3_SpeciesReference_species)
{
  const char *species = "cell";


  fail_unless( !SpeciesReference_isSetSpecies(SR) );
  
  SpeciesReference_setSpecies(SR, species);

  fail_unless( !strcmp(SpeciesReference_getSpecies(SR), species) );
  fail_unless( SpeciesReference_isSetSpecies(SR) );

  if (SpeciesReference_getSpecies(SR) == species)
  {
    fail("SpeciesReference_setSpecies(...) did not make a copy of string.");
  }

  SpeciesReference_unsetSpecies(SR);

  fail_unless( !SpeciesReference_isSetSpecies(SR) );

}
END_TEST


START_TEST (test_ModifierSpeciesReference_setSpecies)
{
  const char *s;
  const char *species = "s1";



  SpeciesReference_setSpecies(MSR, species);

  s = SpeciesReference_getSpecies(MSR);
  fail_unless( !strcmp(s, species) );
  fail_unless(SpeciesReference_isSetSpecies(MSR));

  if (SpeciesReference_getSpecies(MSR) == species)
  {
    fail( "ModifierSpeciesReference_setSpecies(...) "
          "did not make a copy of string." );
  }

  /* Reflexive case (pathological) */
  s = SpeciesReference_getSpecies(MSR);
  SpeciesReference_setSpecies(MSR, s);

  s = SpeciesReference_getSpecies(MSR);
  fail_unless( !strcmp(s, species) );

  SpeciesReference_setSpecies(MSR, NULL);
  fail_unless(!SpeciesReference_isSetSpecies(MSR));

  if (SpeciesReference_getSpecies(MSR) != NULL)
  {
    fail( "ModifierSpeciesReference_setSpecies(MSR, NULL) "
          "did not clear string." );
  }
}
END_TEST


START_TEST (test_SpeciesReference_setSpecies2)
{
  SpeciesReference_t *c = 
    SpeciesReference_create(2, 2);

  int i = SpeciesReference_setSpecies(c, "1cell");

  fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE );
  fail_unless( !SpeciesReference_isSetSpecies(c) );

  SpeciesReference_free(c);
}
예제 #12
0
END_TEST


START_TEST (test_Reaction_addModifier)
{
  SpeciesReference_t * msr = SpeciesReference_createModifier(2, 4);
  SpeciesReference_setSpecies(msr, "s");
  Reaction_addModifier(R, msr);

  fail_unless( Reaction_getNumReactants(R) == 0 );
  fail_unless( Reaction_getNumProducts (R) == 0 );
  fail_unless( Reaction_getNumModifiers(R) == 1 );

  SpeciesReference_free(msr);
}
END_TEST


START_TEST (test_SpeciesReference_setSpecies3)
{
  SpeciesReference_t *c = 
    SpeciesReference_create(2, 2);

  int i = SpeciesReference_setSpecies(c, "mole");

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( !strcmp(SpeciesReference_getSpecies(c), "mole") );
  fail_unless( SpeciesReference_isSetSpecies(c) );

  SpeciesReference_free(c);
}
예제 #14
0
END_TEST


START_TEST (test_Reaction_addModifier2)
{
  Reaction_t *m = Reaction_create(2, 2);
  SpeciesReference_t *p 
    = SpeciesReference_createModifier(2, 1);
  SpeciesReference_setSpecies(p, "k");

  int i = Reaction_addModifier(m, p);

  fail_unless( i == LIBSBML_VERSION_MISMATCH);
  fail_unless( Reaction_getNumModifiers(m) == 0);

  SpeciesReference_free(p);
  Reaction_free(m);
}
예제 #15
0
END_TEST


START_TEST (test_Reaction_addProduct3)
{
  Reaction_t *m = Reaction_create(2, 2);
  SpeciesReference_t *p 
    = SpeciesReference_create(1, 2);
  SpeciesReference_setSpecies(p, "k");

  int i = Reaction_addProduct(m, p);

  fail_unless( i == LIBSBML_LEVEL_MISMATCH);
  fail_unless( Reaction_getNumProducts(m) == 0);

  SpeciesReference_free(p);
  Reaction_free(m);
}
END_TEST


START_TEST (test_L3_SpeciesReference_hasRequiredAttributes )
{
  SpeciesReference_t *sr = SpeciesReference_create (3, 1);

  fail_unless ( !SpeciesReference_hasRequiredAttributes(sr));

  SpeciesReference_setSpecies(sr, "id");

  fail_unless ( !SpeciesReference_hasRequiredAttributes(sr));

  SpeciesReference_setConstant(sr, 0);

  fail_unless ( SpeciesReference_hasRequiredAttributes(sr));

  SpeciesReference_free(sr);
}
예제 #17
0
END_TEST


START_TEST (test_SBMLConvert_convertToL3_stoichiometryMath)
{
  SBMLDocument_t *d = SBMLDocument_createWithLevelAndVersion(2, 1);
  Model_t        *m = SBMLDocument_createModel(d);

  Compartment_t  *c = Model_createCompartment(m);
  Compartment_setId   ( c, "c" );

  Species_t *s = Model_createSpecies(m);
  Species_setId(s, "s");
  Species_setCompartment(s, "c");

  Reaction_t * r = Model_createReaction(m);
  SpeciesReference_t *sr = Reaction_createReactant(r);
  SpeciesReference_setSpecies(sr, "s");
  StoichiometryMath_t *sm = SpeciesReference_createStoichiometryMath(sr);

  ASTNode_t * ast = SBML_parseFormula("c*2");
  StoichiometryMath_setMath(sm, ast);

  fail_unless(Model_getNumRules(m) == 0);
  fail_unless(SpeciesReference_isSetId(sr) == 0);
  
  fail_unless( SBMLDocument_setLevelAndVersionNonStrict(d, 3, 1) == 1);

  m = SBMLDocument_getModel(d);
  r = Model_getReaction(m, 0);
  sr = Reaction_getReactant(r, 0);

  fail_unless(Model_getNumRules(m) == 1);
  fail_unless(SpeciesReference_isSetId(sr) == 1);
  
  Rule_t *rule = Model_getRule(m, 0);

  fail_unless( strcmp(SpeciesReference_getId(sr), Rule_getVariable(rule)) == 0 );

  SBMLDocument_free(d);
}
예제 #18
0
END_TEST

START_TEST (test_SBMLConvert_convertToL3_localParameters)
{
  SBMLDocument_t *d = SBMLDocument_createWithLevelAndVersion(1, 2);
  Model_t        *m = SBMLDocument_createModel(d);

  Compartment_t  *c = Model_createCompartment(m);
  Compartment_setId   ( c, "c" );

  Species_t *s = Model_createSpecies(m);
  Species_setId(s, "s");
  Species_setCompartment(s, "c");

  Reaction_t * r = Model_createReaction(m);
  SpeciesReference_t *sr = Reaction_createReactant(r);
  SpeciesReference_setSpecies(sr, "s");

  KineticLaw_t *kl = Reaction_createKineticLaw(r);

  KineticLaw_setFormula(kl, "s*k");
  Parameter_t *p = KineticLaw_createParameter(kl);
  Parameter_setId(p, "k");

  fail_unless(KineticLaw_getNumLocalParameters(kl) == 0);
  
  fail_unless( SBMLDocument_setLevelAndVersionNonStrict(d, 3, 1) == 1 );

  m = SBMLDocument_getModel(d);
  r = Model_getReaction(m,0);
  kl = Reaction_getKineticLaw(r);


  fail_unless(KineticLaw_getNumLocalParameters(kl) == 1);

  LocalParameter_t *lp = KineticLaw_getLocalParameter(kl, 0);

  SBMLDocument_free(d);
}
예제 #19
0
END_TEST


START_TEST (test_SBMLConvert_convertToL3_product)
{
  SBMLDocument_t *d = SBMLDocument_createWithLevelAndVersion(2, 2);
  Model_t        *m = SBMLDocument_createModel(d);
  Reaction_t     *r = Model_createReaction(m);

  SpeciesReference_t  *sr = Reaction_createProduct(r);
  SpeciesReference_t *sr1;

  SpeciesReference_setSpecies   ( sr, "s" );

  fail_unless( SBMLDocument_setLevelAndVersionNonStrict(d, 3, 1) == 1, NULL);

  sr1 = Reaction_getProduct(Model_getReaction(m, 0), 0);

  fail_unless(SpeciesReference_hasRequiredAttributes(sr1) == 1);

  SBMLDocument_free(d);
}
예제 #20
0
END_TEST


START_TEST (test_Reaction_removeModifier)
{
  SpeciesReference_t *o1, *o2, *o3;

   o1 = Reaction_createModifier(R);
   o2 = Reaction_createModifier(R);
   o3 = Reaction_createModifier(R);
  SpeciesReference_setSpecies(o3, "test");

  fail_unless( Reaction_removeModifier(R, 0) == o1 );
  fail_unless( Reaction_getNumModifiers(R)   == 2  );
  fail_unless( Reaction_removeModifier(R, 0) == o2 );
  fail_unless( Reaction_getNumModifiers(R)   == 1  );
  fail_unless( Reaction_removeModifierBySpecies(R,"test") == o3 );
  fail_unless( Reaction_getNumModifiers(R)   == 0  );

  SpeciesReference_free(o1);
  SpeciesReference_free(o2);
  SpeciesReference_free(o3);
}
예제 #21
0
LIBSBML_CPP_NAMESPACE_USE


int main(int argc,char** argv)
{
  int retval = 0;
  XMLNamespaces_t * comp;
  SBMLNamespaces_t * sbmlns;
  SBMLDocument_t * doc;
  Compartment_t * c;
  Species_t * s1;
  Species_t * s2;
  Species_t * s3;
  Species_t * s4;
  Reaction_t * r1;
  Reaction_t * r2;
  SpeciesReference_t *sr1;
  SpeciesReference_t *sr2;
  SpeciesReference_t *sr3;
  SpeciesReference_t *sr4;
  SpeciesReference_t *sr5;
  SpeciesReference_t *sr6;
  Model_t * model;
  CompSBMLDocumentPlugin_t * docPlug;
  CompModelPlugin_t *modelPlug;
  Submodel_t * sub1;
  Submodel_t * sub2;
  ModelDefinition_t * modDef;

  /* get comp registry entry */
  SBMLExtension_t *sbmlext = SBMLExtensionRegistry_getExtension("comp");

  /* create the sbml namespaces object with comp */
  comp = XMLNamespaces_create();
  XMLNamespaces_add(comp, SBMLExtension_getURI(sbmlext, 3, 1, 1), "comp");
  
  sbmlns = SBMLNamespaces_create(3, 1);
  SBMLNamespaces_addNamespaces(sbmlns, comp);

  /* create the document */
  doc = SBMLDocument_createWithSBMLNamespaces(sbmlns);

  /* set the comp reqd attribute to true */
  docPlug = (CompSBMLDocumentPlugin_t * )(SBase_getPlugin((SBase_t*)(doc), "comp"));
  SBMLDocumentPlugin_setRequired((SBMLDocumentPlugin_t*)(docPlug), 1);


  /* create the submodel */
  modDef = CompSBMLDocumentPlugin_createModelDefinition(docPlug);

  Model_setId((Model_t*)(modDef), "enzyme");
  Model_setName((Model_t*)(modDef), "enzyme");

  c = Model_createCompartment((Model_t*)(modDef));
  Compartment_setId(c, "comp");
  Compartment_setConstant(c, 1);
  Compartment_setSize(c, 1.0);
  Compartment_setSpatialDimensions(c, 3);

  s1 = Model_createSpecies((Model_t*)(modDef));
  Species_setId(s1, "S");
  Species_setCompartment(s1, "comp");
  Species_setHasOnlySubstanceUnits(s1, 0);
  Species_setBoundaryCondition(s1, 0);
  Species_setConstant(s1, 0);
  
  s2 = Model_createSpecies((Model_t*)(modDef));
  Species_setId(s2, "E");
  Species_setCompartment(s2, "comp");
  Species_setHasOnlySubstanceUnits(s2, 0);
  Species_setBoundaryCondition(s2, 0);
  Species_setConstant(s2, 0);
  
  s3 = Model_createSpecies((Model_t*)(modDef));
  Species_setId(s3, "D");
  Species_setCompartment(s3, "comp");
  Species_setHasOnlySubstanceUnits(s3, 0);
  Species_setBoundaryCondition(s3, 0);
  Species_setConstant(s3, 0);

  s4 = Model_createSpecies((Model_t*)(modDef));
  Species_setId(s4, "ES");
  Species_setCompartment(s4, "comp");
  Species_setHasOnlySubstanceUnits(s4, 0);
  Species_setBoundaryCondition(s4, 0);
  Species_setConstant(s4, 0);

  r1 = Model_createReaction((Model_t*)(modDef));
  Reaction_setId(r1, "J0");
  Reaction_setReversible(r1, 1);
  Reaction_setFast(r1, 0);

  sr1 = Reaction_createReactant(r1);
  SpeciesReference_setSpecies(sr1, "S");
  SpeciesReference_setStoichiometry(sr1, 1.0);
  SpeciesReference_setConstant(sr1, 1);


  sr2 = Reaction_createReactant(r1);
  SpeciesReference_setSpecies(sr2, "E");
  SpeciesReference_setStoichiometry(sr2, 1.0);
  SpeciesReference_setConstant(sr2, 1);

  sr3 = Reaction_createProduct(r1);
  SpeciesReference_setSpecies(sr3, "ES");
  SpeciesReference_setStoichiometry(sr3, 1.0);
  SpeciesReference_setConstant(sr3, 1);

  r2 = Model_createReaction((Model_t*)(modDef));
  Reaction_setId(r2, "J1");
  Reaction_setReversible(r2, 1);
  Reaction_setFast(r2, 0);

  sr4 = Reaction_createProduct(r2);
  SpeciesReference_setSpecies(sr4, "E");
  SpeciesReference_setStoichiometry(sr4, 1.0);
  SpeciesReference_setConstant(sr4, 1);

  sr5 = Reaction_createReactant(r2);
  SpeciesReference_setSpecies(sr5, "ES");
  SpeciesReference_setStoichiometry(sr5, 1.0);
  SpeciesReference_setConstant(sr5, 1);

  sr6 = Reaction_createProduct(r2);
  SpeciesReference_setSpecies(sr6, "D");
  SpeciesReference_setStoichiometry(sr6, 1.0);
  SpeciesReference_setConstant(sr6, 1);

  /* create the model */
  model = SBMLDocument_createModel(doc);
  Model_setId(model, "aggregate");

  /* add the submodels*/
  modelPlug = (CompModelPlugin_t*)(SBase_getPlugin((SBase_t *)(model), "comp"));

  sub1 = CompModelPlugin_createSubmodel(modelPlug);
  Submodel_setId(sub1, "submod1");
  Submodel_setModelRef(sub1, "enzyme");


  sub2 = CompModelPlugin_createSubmodel(modelPlug);
  Submodel_setId(sub2, "submod2");
  Submodel_setModelRef(sub2, "enzyme");

  /* write the file */
  writeSBMLToFile(doc, "enzyme_model.xml");

  return retval;
}
예제 #22
0
END_TEST


START_TEST (test_create_l1v1_units)
{
  Model_t            *m;
  Compartment_t      *c;
  KineticLaw_t       *kl;
  Parameter_t        *p;
  Reaction_t         *r;
  Species_t          *s;
  SpeciesReference_t *sr;
  Unit_t             *u;
  UnitDefinition_t   *ud;


  /**
   * <sbml level="1" version="1">
   */
  m = Model_create(2, 4);

  /**
   * <unitDefinition name="substance">
   *   <listOfUnits>
   *     <unit kind="mole" scale="-3"/>
   *   </listOfUnits>
   * </unitDefinition>
   */
  ud = Model_createUnitDefinition(m);
  UnitDefinition_setName(ud, "substance");

  u = Model_createUnit(m);
  Unit_setKind(u,UNIT_KIND_MOLE);
  Unit_setScale(u, -3);

  /**
   * <unitDefinition name="mls">
   *   <listOfUnits>
   *     <unit kind="mole"   scale="-3"/>
   *     <unit kind="liter"  exponent="-1"/>
   *     <unit kind="second" exponent="-1"/>
   *   </listOfUnits>
   * </unitDefinition>
   */
  ud = Model_createUnitDefinition(m);
  UnitDefinition_setName(ud, "mls");

  u = Model_createUnit(m);
  Unit_setKind(u, UNIT_KIND_MOLE);
  Unit_setScale(u, -3);

  u = Model_createUnit(m);
  Unit_setKind(u, UNIT_KIND_LITER);
  Unit_setExponent(u, -1);

  u = Model_createUnit(m);
  Unit_setKind(u, UNIT_KIND_SECOND);
  Unit_setExponent(u, -1);

  /**
   * <listOfCompartments>
   *   <compartment name="cell"/>
   * </listOfCompartments>
   */
  c = Model_createCompartment(m);
  Compartment_setName(c, "cell");

  /**
   * <listOfSpecies>
   *   <specie name="x0" compartment="cell" initialAmount="1"/>
   *   <specie name="x1" compartment="cell" initialAmount="1"/>
   *   <specie name="s1" compartment="cell" initialAmount="1"/>
   *   <specie name="s2" compartment="cell" initialAmount="1"/>
   * </listOfSpecies>
   */
  s = Model_createSpecies(m);
  Species_setName(s, "x0");
  Species_setCompartment(s, "cell");
  Species_setInitialAmount(s, 1);

  s = Model_createSpecies(m);
  Species_setName(s, "x1");
  Species_setCompartment(s, "cell");
  Species_setInitialAmount(s, 1);

  s = Model_createSpecies(m);
  Species_setName(s, "s1");
  Species_setCompartment(s, "cell");
  Species_setInitialAmount(s, 1);

  s = Model_createSpecies(m);
  Species_setName(s, "s2");
  Species_setCompartment(s, "cell"); 
  Species_setInitialAmount(s, 1);

  /**
   * <listOfParameters>
   *   <parameter name="vm" value="2" units="mls"/>
   *   <parameter name="km" value="2"/>
   * </listOfParameters>
   */
  p = Model_createParameter(m);
  Parameter_setName (p, "vm");
  Parameter_setUnits(p, "mls");
  Parameter_setValue(p, 2);

  p = Model_createParameter(m);
  Parameter_setName (p, "km");
  Parameter_setValue(p, 2);

  /**
   * <reaction name="v1">
   *   <listOfReactants>
   *     <specieReference specie="x0"/>
   *   </listOfReactants>
   *   <listOfProducts>
   *     <specieReference specie="s1"/>
   *   </listOfProducts>
   *   <kineticLaw formula="(vm * s1)/(km + s1)"/>
   * </reaction>
   */
  r = Model_createReaction(m);
  Reaction_setName(r, "v1");

  sr = Model_createReactant(m);
  SpeciesReference_setSpecies(sr, "x0");

  sr = Model_createProduct(m);
  SpeciesReference_setSpecies(sr, "s1");

  kl = Model_createKineticLaw(m);
  KineticLaw_setFormula(kl, "(vm * s1)/(km + s1)");

  /**
   * <reaction name="v2">
   *   <listOfReactants>
   *     <specieReference specie="s1"/>
   *   </listOfReactants>
   *   <listOfProducts>
   *     <specieReference specie="s2"/>
   *   </listOfProducts>
   *   <kineticLaw formula="(vm * s2)/(km + s2)"/>
   * </reaction>
   */
  r = Model_createReaction(m);
  Reaction_setName(r, "v2");

  sr = Model_createReactant(m);
  SpeciesReference_setSpecies(sr, "s1");

  sr = Model_createProduct(m);
  SpeciesReference_setSpecies(sr, "s2");

  kl = Model_createKineticLaw(m);
  KineticLaw_setFormula(kl, "(vm * s2)/(km + s2)");

  /**
   * <reaction name="v3">
   *   <listOfReactants>
   *     <specieReference specie="s2"/>
   *   </listOfReactants>
   *   <listOfProducts>
   *     <specieReference specie="x1"/>
   *   </listOfProducts>
   *   <kineticLaw formula="(vm * s1)/(km + s1)"/>
   * </reaction>
   */
  r = Model_createReaction(m);
  Reaction_setName(r, "v3");

  sr = Model_createReactant(m);
  SpeciesReference_setSpecies(sr, "s2");

  sr = Model_createProduct(m);
  SpeciesReference_setSpecies(sr, "x1");

  kl = Model_createKineticLaw(m);
  KineticLaw_setFormula(kl, "(vm * s1)/(km + s1)");

  Model_free(m);
}
예제 #23
0
LIBSBML_CPP_NAMESPACE_USE


int main(int argc,char** argv)
{
  int retval = 0;
  XMLNamespaces_t * fbc;
  SBMLNamespaces_t * sbmlns;
  SBMLDocument_t * doc;
  Compartment_t * compartment;
  Species_t * species;
  Reaction_t * reaction;
  SpeciesReference_t *reactant;
  SpeciesReference_t *product;
  Model_t * model;
  SBMLDocumentPlugin_t * docPlug;
  SBasePlugin_t * modelPlug;
  FluxBound_t * fluxBound;
  Objective_t * objective;
  FluxObjective_t * fluxObjective;

  /* get fbc registry entry */
  SBMLExtension_t *sbmlext = SBMLExtensionRegistry_getExtension("fbc");

  /* create the sbml namespaces object with fbc */
  fbc = XMLNamespaces_create();
  XMLNamespaces_add(fbc, SBMLExtension_getURI(sbmlext, 3, 1, 1), "fbc");
  
  sbmlns = SBMLNamespaces_create(3, 1);
  SBMLNamespaces_addNamespaces(sbmlns, fbc);

  /* create the document */
  doc = SBMLDocument_createWithSBMLNamespaces(sbmlns);

  /* set the fbc reqd attribute to false */
  docPlug = (SBMLDocumentPlugin_t*)(SBase_getPlugin((SBase_t*)(doc), "fbc"));
  SBMLDocumentPlugin_setRequired(docPlug, 0);

  // create the Model

  model = SBMLDocument_createModel(doc);

  // create the Compartment

  compartment = Model_createCompartment(model);
  Compartment_setId(compartment, "compartment");
  Compartment_setConstant(compartment, 1);
  Compartment_setSize(compartment, 1);

  // create the Species

  species = Model_createSpecies(model);
  Species_setId(species, "Node1");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 0);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  species = Model_createSpecies(model);
  Species_setId(species, "Node2");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 0);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  species = Model_createSpecies(model);
  Species_setId(species, "Node3");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 0);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  species = Model_createSpecies(model);
  Species_setId(species, "Node4");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 0);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  species = Model_createSpecies(model);
  Species_setId(species, "Node5");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 0);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  species = Model_createSpecies(model);
  Species_setId(species, "Node6");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 0);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  species = Model_createSpecies(model);
  Species_setId(species, "Node7");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 0);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  species = Model_createSpecies(model);
  Species_setId(species, "Node8");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 0);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  species = Model_createSpecies(model);
  Species_setId(species, "Node0");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 1);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  species = Model_createSpecies(model);
  Species_setId(species, "Node9");
  Species_setCompartment(species, "compartment");
  Species_setBoundaryCondition(species, 1);
  Species_setConstant(species, 0);
  Species_setHasOnlySubstanceUnits(species, 0);

  // create the Reactions

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J0");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node0");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node1");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J1");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node1");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node2");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J2");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node2");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node3");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J3");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node1");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node4");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J4");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node4");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node3");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J5");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node3");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node5");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J6");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node5");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node6");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J7");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node6");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node7");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J8");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node5");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node8");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J9");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node8");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node7");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  reaction = Model_createReaction(model);
  Reaction_setId(reaction, "J10");
  Reaction_setReversible(reaction, 0);
  Reaction_setFast(reaction, 0);
  reactant = Reaction_createReactant(reaction);
  SpeciesReference_setSpecies(reactant, "Node7");
  SpeciesReference_setStoichiometry(reactant, 1);
  SpeciesReference_setConstant(reactant, 1);
  product = Reaction_createProduct(reaction);
  SpeciesReference_setSpecies(product, "Node9");
  SpeciesReference_setStoichiometry(product, 1);
  SpeciesReference_setConstant(product, 1);

  // Get a SBasePlugin_t object plugged in the model object.

  modelPlug = SBase_getPlugin((SBase_t *)(model), "fbc");

  // create the fluxBound object and add it to model plugin

  fluxBound = FluxBound_create(3, 1, 1);
  FluxBound_setId(fluxBound, "bound1");
  FluxBound_setReaction(fluxBound, "J0");
  FluxBound_setOperation(fluxBound, "equal");
  FluxBound_setValue(fluxBound, 10);

  FbcModelPlugin_addFluxBound(modelPlug, fluxBound);

  // create the objective object and add it to model plugin

  objective = Objective_create(3, 1, 1);
  Objective_setId(objective, "obj1");
  Objective_setType(objective, "maximize");

  fluxObjective = Objective_createFluxObjective(objective);
  FluxObjective_setReaction(fluxObjective, "J8");
  FluxObjective_setCoefficient(fluxObjective, 1);

  FbcModelPlugin_addObjective(modelPlug, objective);

  // mark obj1 as active objective
  FbcModelPlugin_setActiveObjectiveId(modelPlug, "obj1");

  /* write the file */
  writeSBMLToFile(doc, "fbc_example1.xml");

  return retval;
}