Package org.sbml.jsbml

Examples of org.sbml.jsbml.Reaction


              int i = 0;
              SpeciesReference sr = null;

              while (i <= model.getNumReactions() - 1
                  && sr == null) {
                Reaction reaction = model.getReaction(i);

                if (reaction != null) {
                  sr = reaction.getReactant(variableID);
                  if (sr == null) {
                    sr = reaction.getProduct(variableID);
                  }
                }
              }

              speciesReference = sr;
View Full Code Here


              int i = 0;
              SpeciesReference sr = null;

              while (i <= model.getNumReactions() - 1
                  && sr == null) {
                Reaction reaction = model.getReaction(i);

                if (reaction != null) {
                  sr = reaction.getReactant(variableID);
                  if (sr == null) {
                    sr = reaction.getProduct(variableID);
                  }
                }
              }

              speciesReference = sr;
View Full Code Here

    math.addChild(pieces);
    fd.setMath(math);
    System.out.println(math.toMathML());
   
    Species species = m.createSpecies("spec");
    Reaction r = m.createReaction("r");
    r.addReactant(new SpeciesReference(species));
    KineticLaw kl = new KineticLaw(level, version);
    math = new ASTNode(fd, kl);
    math.addChild(new ASTNode(species, kl));
    math = ASTNode.times(math, new ASTNode(3.7, 8, kl));
    kl.setMath(math);
    r.setKineticLaw(kl);
   
    System.out.println(math.toMathML());

    try {
      new SBMLWriter().write(doc, System.out);
View Full Code Here

    assertTrue(x1.getName().equals("X1"));
    assertTrue(x1.getInitialAmount() == 0);
    assertTrue(x1.getBoundaryCondition() == true);
   
   
    Reaction r1 = model.getReaction(0);
   
    assertTrue(r1 != null);
   
    assertTrue(r1.getName().equals("reaction_1"));
    assertTrue(r1.getListOfReactants().size() == 1);
    assertTrue(r1.getListOfProducts().size() == 1);
    assertTrue(r1.getNumModifiers() == 0);
    assertTrue(r1.getReversible() == false);
   
    assertTrue(r1.getListOfReactants().get(0).getSpecies().equals("X0"));
    assertTrue(r1.getListOfProducts().get(0).getSpecies().equals("S1"));
   
    KineticLaw rdClkKL = r1.getKineticLaw();

    assertTrue(rdClkKL != null);
    assertTrue(rdClkKL.getListOfLocalParameters().size() == 1);
    assertTrue(rdClkKL.getListOfLocalParameters().get(0).getName().equals("k1"));
   
View Full Code Here

    SBMLDocument doc = new SBMLDocument(1, 2);
    Model m = doc.createModel();
    Compartment c = m.createCompartment("c1");
    Species s1 = m.createSpecies("s1", c);
    Species s2 = m.createSpecies("s2", c);
    Reaction r = m.createReaction("r1");
    r.createReactant(null, s1);
    r.createProduct(null, s2);
    KineticLaw kl = r.createKineticLaw();
    kl.setFormula("s1 * 3");
    SBMLWriter.write(doc, System.out, ' ', (short) 2);
  }
View Full Code Here

    SBMLDocument d;
    Model m;
    Compartment c;
    KineticLaw kl;
    LocalParameter p;
    Reaction r;
    Species s;
    SpeciesReference sr;
    UnitDefinition ud;
    String filename = DATA_FOLDER + "/libsbml-test-data/l1v1-branch.xml";
    d = new SBMLReader().readSBML(filename);
    if (d == null)
      ;
    {
    }
    assertTrue(d.getLevel() == 1);
    assertTrue(d.getVersion() == 1);
    m = d.getModel();
    assertTrue(m.getName().equals("Branch"));
    assertTrue(m.getNumCompartments() == 1);
    c = m.getCompartment(0);
    assertTrue(c.getName().equals("compartmentOne"));
    assertTrue(c.getVolume() == 1);
    ud = c.getDerivedUnitDefinition();
    assertTrue(ud.getNumUnits() == 1);

    // assertTrue(ud.getUnit(0).getKind() == Unit.Kind.LITRE); // getDerivedUnitDefinition not working properly
    assertTrue(m.getNumSpecies() == 4);
    s = m.getSpecies(0);
    assertTrue(s.getName().equals("S1"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == false);

    //    ud = s.getDerivedUnitDefinition(); // getDerivedUnitDefinition not working properly
//    assertTrue(ud.getNumUnits() == 2);
//    assertTrue(ud.getUnit(0).getKind() == Unit.Kind.MOLE);
//    assertTrue(ud.getUnit(0).getExponent() == 1);
//    assertTrue(ud.getUnit(1).getKind() == Unit.Kind.LITRE);
//    assertTrue(ud.getUnit(1).getExponent() == -1);
   
    s = m.getSpecies(1);
    assertTrue(s.getName().equals("X0"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == true);
    s = m.getSpecies(2);
    assertTrue(s.getName().equals("X1"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == true);
    s = m.getSpecies(3);
    assertTrue(s.getName().equals("X2"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == true);
    assertTrue(m.getNumReactions() == 3);
    r = m.getReaction(0);
    assertTrue(r.getName().equals("reaction_1"));
    assertTrue(r.getReversible() == false);
    assertTrue(r.getFast() == false);
    ud = r.getKineticLaw().getDerivedUnitDefinition();

    //    assertTrue(ud.getNumUnits() == 2);
//    assertTrue(ud.getUnit(0).getKind() == Unit.Kind.MOLE);
//    assertTrue(ud.getUnit(0).getExponent() == 1);
//    assertTrue(ud.getUnit(1).getKind() == Unit.Kind.LITRE);
//    assertTrue(ud.getUnit(1).getExponent() == -1);
   
    assertTrue(r.getKineticLaw().containsUndeclaredUnits() == true);
    r = m.getReaction(1);
    assertTrue(r.getName().equals("reaction_2"));
    assertTrue(r.getReversible() == false);
    assertTrue(r.getFast() == false);
    r = m.getReaction(2);
    assertTrue(r.getName().equals("reaction_3"));
    assertTrue(r.getReversible() == false);
    assertTrue(r.getFast() == false);
    r = m.getReaction(0);
    assertTrue(r.getNumReactants() == 1);
    assertTrue(r.getNumProducts() == 1);
    sr = r.getReactant(0);
    assertTrue(sr.getSpecies().equals("X0"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    sr = r.getProduct(0);
    assertTrue(sr.getSpecies().equals("S1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    kl = r.getKineticLaw();
    assertTrue(kl.getFormula().equals("k1*X0")); // We are not putting the same space in the formula
    assertTrue(kl.getNumParameters() == 1);
    p = kl.getParameter(0);
    assertTrue(p.getName().equals("k1"));
    assertTrue(p.getValue() == 0);
    r = m.getReaction(1);
    assertTrue(r.getNumReactants() == 1);
    assertTrue(r.getNumProducts() == 1);
    sr = r.getReactant(0);
    assertTrue(sr.getSpecies().equals("S1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    sr = r.getProduct(0);
    assertTrue(sr.getSpecies().equals("X1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    kl = r.getKineticLaw();
    assertTrue(kl.getFormula().equals("k2*S1")); // equals("k2 * S1")
    assertTrue(kl.getNumParameters() == 1);
    p = kl.getParameter(0);
    assertTrue(p.getName().equals("k2"));
    assertTrue(p.getValue() == 0);
    r = m.getReaction(2);
    assertTrue(r.getNumReactants() == 1);
    assertTrue(r.getNumProducts() == 1);
    sr = r.getReactant(0);
    assertTrue(sr.getSpecies().equals("S1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    sr = r.getProduct(0);
    assertTrue(sr.getSpecies().equals("X2"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    kl = r.getKineticLaw();
    assertTrue(kl.getFormula().equals("k3*S1")); // equals("k3 * S1")
    assertTrue(kl.getNumParameters() == 1);
    p = kl.getParameter(0);
    assertTrue(p.getName().equals("k3"));
    assertTrue(p.getValue() == 0);
View Full Code Here

  // The junit test file would test uniqueness of metaids and ids in the model. 
   
  // Setup : creating some simple objects
    SBMLDocument doc=new SBMLDocument(2,4);
    Model m=doc.createModel("model1");
    Reaction r = m.createReaction("id1");
    SpeciesReference s = new SpeciesReference();
    s.setMetaId("meta2");
    r.addReactant(s);
    r.setMetaId("meta");

    System.out.println("Reaction parent and model                    : " + r.getParent() + " " + r.getModel() + "\n");

    Reaction clonedReaction = r.clone();
   
    // Here everything is fine, the cloned reaction get created with all
    // the appropriate fields but the parent that is set to null for all cloned JSBML objects
    // (any objects that inherit from AbstracTreeNode)
    // That is why the getParent() and getModel() are returning null as they should
    System.out.println("Cloned reaction metaid and id                : " + clonedReaction.getMetaId() + " " + clonedReaction.getId());
    System.out.println("Cloned reaction metaid of the first reactant : " + clonedReaction.getReactant(0).getMetaId());
    System.out.println("Cloned reaction parent and model             : " + clonedReaction.getParent() + " " + clonedReaction.getModel() + "\n");
   
    System.out.println("Trying to add the cloned reaction to the model, which should not be possible");
    // Trying to add the
    boolean operationSuccessful = m.addReaction(clonedReaction);

    if (operationSuccessful != false) {
      throw new SBMLException("It should not be possible to add two elements with the same id in a ListOf class !!");
    }
    // Here the parent is still null as it should as the cloned reaction
    // was not added to the model as her id is the same as the reaction 'r'
    System.out.println("Cloned reaction parent and model still null  : " + clonedReaction.getParent() + " " + clonedReaction.getModel() + "\n");

    // setting a new unit id the the cloned reaction
    clonedReaction.setId("id2");
   
    System.out.println("Trying to add the cloned reaction to the model, with a new unique id. It is still not possible as the metaids are not unique.");
    try {
      m.addReaction(clonedReaction);
      throw new SBMLException("It should not be possible to add two elements with the same metaid in a SBML document !!");
    } catch (IllegalArgumentException e) {
      // success, the exception should be thrown there
    }

    // setting a new unique metaid to the reaction but not it's sub-elements
    clonedReaction.setMetaId("meta3");  
   
    System.out.println("Trying to add the cloned reaction to the model, with a new unique id and metaid. It is still not possible as the metaids are not unique.");
    try {
      operationSuccessful = m.addReaction(clonedReaction);
      throw new SBMLException("It should not be possible to add a reaction that has any sub-elements with a non unique metaid !!");
    } catch (IllegalArgumentException e) {
      // success, the exception should be thrown there
    }

    System.out.println("Trying to add the cloned reaction to the model, with a new unique id and metaid for all sub-elements.");
    // setting a new unique metaid to the reaction and all it's sub-elements
    clonedReaction.getReactant(0).setMetaId("meta4");

    // At the moment (rev 768), the reaction cannot be added to the model as the metaid 'meta3' as
    // been added in the list of metaids in the previous call to addReaction() where only the speciesReference id
    // was invalid
    try {
      operationSuccessful = m.addReaction(clonedReaction);

      if (operationSuccessful != true) {
        throw new SBMLException("It should be possible to add a reaction with an unique ids and metaids to a model !!");
      }
    } catch (IllegalArgumentException e) {
      // bug here
      System.out.println("Bug detected : there is a problem in the recursive adding of metaids !!!");
      System.out.println("The reaction was not added to the model where it should have been");
    }

    System.out.println("Cloned reaction parent and model should be set  : " + clonedReaction.getParent() + " " + clonedReaction.getModel());
    System.out.println("Model.getReaction(0) id                         : " + m.getReaction(0).getId());
    System.out.println("Model.getReaction(1)                            : " + m.getReaction(1));
    // System.out.println("Model.getReaction(1) parent                     : " + m.getReaction(1).getParent());

   
View Full Code Here

    SBMLDocument d;
    Model m;
    Compartment c;
    KineticLaw kl;
    LocalParameter p;
    Reaction r;
    Species s;
    SpeciesReference sr;
    UnitDefinition ud;
    String filename = DATA_FOLDER + "/libsbml-test-data/l1v1-branch.xml";
    d = new SBMLReader().readSBML(filename);
    if (d == null)
      ;
    {
    }
    assertTrue(d.getLevel() == 1);
    assertTrue(d.getVersion() == 1);
    m = d.getModel();
    assertTrue(m.getName().equals("Branch"));
    assertTrue(m.getNumCompartments() == 1);
    c = m.getCompartment(0);
    assertTrue(c.getName().equals("compartmentOne"));
    assertTrue(c.getVolume() == 1);
    ud = c.getDerivedUnitDefinition();
    assertTrue(ud.getNumUnits() == 1);

    // assertTrue(ud.getUnit(0).getKind() == Unit.Kind.LITRE); // getDerivedUnitDefinition not working properly
    assertTrue(m.getNumSpecies() == 4);
    s = m.getSpecies(0);
    assertTrue(s.getName().equals("S1"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == false);

    //    ud = s.getDerivedUnitDefinition(); // getDerivedUnitDefinition not working properly
//    assertTrue(ud.getNumUnits() == 2);
//    assertTrue(ud.getUnit(0).getKind() == Unit.Kind.MOLE);
//    assertTrue(ud.getUnit(0).getExponent() == 1);
//    assertTrue(ud.getUnit(1).getKind() == Unit.Kind.LITRE);
//    assertTrue(ud.getUnit(1).getExponent() == -1);
   
    s = m.getSpecies(1);
    assertTrue(s.getName().equals("X0"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == true);
    s = m.getSpecies(2);
    assertTrue(s.getName().equals("X1"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == true);
    s = m.getSpecies(3);
    assertTrue(s.getName().equals("X2"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == true);
    assertTrue(m.getNumReactions() == 3);
    r = m.getReaction(0);
    assertTrue(r.getName().equals("reaction_1"));
    assertTrue(r.getReversible() == false);
    assertTrue(r.getFast() == false);
    ud = r.getKineticLaw().getDerivedUnitDefinition();

    //    assertTrue(ud.getNumUnits() == 2);
//    assertTrue(ud.getUnit(0).getKind() == Unit.Kind.MOLE);
//    assertTrue(ud.getUnit(0).getExponent() == 1);
//    assertTrue(ud.getUnit(1).getKind() == Unit.Kind.LITRE);
//    assertTrue(ud.getUnit(1).getExponent() == -1);
   
    assertTrue(r.getKineticLaw().containsUndeclaredUnits() == true);
    r = m.getReaction(1);
    assertTrue(r.getName().equals("reaction_2"));
    assertTrue(r.getReversible() == false);
    assertTrue(r.getFast() == false);
    r = m.getReaction(2);
    assertTrue(r.getName().equals("reaction_3"));
    assertTrue(r.getReversible() == false);
    assertTrue(r.getFast() == false);
    r = m.getReaction(0);
    assertTrue(r.getNumReactants() == 1);
    assertTrue(r.getNumProducts() == 1);
    sr = r.getReactant(0);
    assertTrue(sr.getSpecies().equals("X0"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    sr = r.getProduct(0);
    assertTrue(sr.getSpecies().equals("S1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    kl = r.getKineticLaw();
    assertTrue(kl.getFormula().equals("k1*X0")); // We are not putting the same space in the formula
    assertTrue(kl.getNumParameters() == 1);
    p = kl.getParameter(0);
    assertTrue(p.getName().equals("k1"));
    assertTrue(p.getValue() == 0);
    r = m.getReaction(1);
    assertTrue(r.getNumReactants() == 1);
    assertTrue(r.getNumProducts() == 1);
    sr = r.getReactant(0);
    assertTrue(sr.getSpecies().equals("S1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    sr = r.getProduct(0);
    assertTrue(sr.getSpecies().equals("X1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    kl = r.getKineticLaw();
    assertTrue(kl.getFormula().equals("k2*S1")); // equals("k2 * S1")
    assertTrue(kl.getNumParameters() == 1);
    p = kl.getParameter(0);
    assertTrue(p.getName().equals("k2"));
    assertTrue(p.getValue() == 0);
    r = m.getReaction(2);
    assertTrue(r.getNumReactants() == 1);
    assertTrue(r.getNumProducts() == 1);
    sr = r.getReactant(0);
    assertTrue(sr.getSpecies().equals("S1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    sr = r.getProduct(0);
    assertTrue(sr.getSpecies().equals("X2"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    kl = r.getKineticLaw();
    assertTrue(kl.getFormula().equals("k3*S1")); // equals("k3 * S1")
    assertTrue(kl.getNumParameters() == 1);
    p = kl.getParameter(0);
    assertTrue(p.getName().equals("k3"));
    assertTrue(p.getValue() == 0);
View Full Code Here

  @Test
  public void idTest() {
    int level = 2, version = 4;
    SBMLDocument doc = new SBMLDocument(level, version);
    Model model = doc.createModel("myModel");
    Reaction r1 = model.createReaction("r1");
   
    /*
     * Local Parameters
     */
    logger.debug("==== LocalParameters ====");
    KineticLaw kl = r1.createKineticLaw();
    LocalParameter parameter = kl.createLocalParameter("lp1");
    parameter.setValue(2d);
    kl.getListOfLocalParameters().add(new LocalParameter("lp2"));
    try {
      kl.createLocalParameter("lp1");
      fail();
    } catch (IllegalArgumentException exc) {
      logger.debug(exc.getLocalizedMessage());
      assertTrue(kl.getListOfLocalParameters()
                   .filterList(new NameFilter(parameter.getId())).size() == 1);
    }
    kl.removeLocalParameter(parameter);
    assertTrue(kl.getListOfLocalParameters()
               .filterList(new NameFilter(parameter.getId())).size() == 0);
    assertTrue(kl.getLocalParameter(parameter.getId()) == null);
    // remove ListOfLocalParameters
    ListOf<LocalParameter> listOfLP = kl.getListOfLocalParameters();
    kl.unsetListOfLocalParameters();
    assertTrue(!listOfLP.contains(parameter));
    assertTrue(kl.getLocalParameter("lp2") == null);
    // add ListOfLocalParameters
    listOfLP.add(parameter);
    kl.setListOfLocalParameters(listOfLP);
    assertTrue(kl.getLocalParameter(parameter.getId()) != null);
   
    /*
     * Compartments
     */
    logger.debug("==== Compartments ====");
    Compartment c1 = model.createCompartment("c1");
    c1.setSize(2d);
    Compartment c2 = model.createCompartment("c2");
    try {
      c2.setId(c1.getId());
      fail();
    } catch (IllegalArgumentException exc) {
      System.err.println(exc.getLocalizedMessage());
      assertTrue(!c2.getId().equals(c1.getId()));
    }
    // remove ListOfCompartments
    ListOf<Compartment> listOfC = model.getListOfCompartments();
    model.unsetListOfCompartments();
    // add ListOfCompartments
    model.setListOfCompartments(listOfC);
    Compartment c3 = new Compartment(level, version);
    c3.setId("c3");
    model.addCompartment(c3);
    c3.setId("c4");
   
    /*
     * Species and Species References
     */
    logger.debug("==== Species ====");
    Species s1 = model.createSpecies("s1", c1);
    Species p1 = model.createSpecies("p1", c1);
    r1.createReactant(s1);
    r1.createProduct(p1);
    r1.getProduct(0).setId("p1ref");
   
    /*
     * Reactions
     */
    logger.debug("==== Reactions ====");
    Reaction r2 = new Reaction(level, version);
    SpeciesReference sr1 = r2.createReactant(s1);
    sr1.setId("sr1");
    r2.createModifier(p1);
    r2.setId("r2");
    model.addReaction(r2);
   
    /*
     * Function Definitions
     */
 
View Full Code Here

    k2.setId("k2");
    k1.setValue(3.14);
    k2.setValue(2.72);
    M.addParameter(k1);
    M.addParameter(k2);
    Reaction r1 = new Reaction(2, 4);
    r1.setId("reaction_1");
    KineticLaw kl = new KineticLaw(2, 4);
    kl.setFormula("k1 * X0");
    LocalParameter k3 = new LocalParameter(2, 4);
    LocalParameter k4 = new LocalParameter(2, 4);
    k3.setId("k1");
    k4.setId("k2");
    k3.setValue(2.72);
    k4.setValue(3.14);
    kl.addParameter(k3);
    kl.addParameter(k4);
    r1.setKineticLaw(kl);
    M.addReaction(r1);
    KineticLaw kl1 = M.getReaction(0).getKineticLaw();
    // assertTrue(!kl1.getParameter("k1").equals(k3)); // TODO : compare Parameter and LocalParameter
    // assertTrue(!kl1.getParameter("k1").equals(k1)); // We are not doinga clone of the object and even it will return true
    // assertTrue(!kl1.getParameter("k2").equals(k4)); // TODO : compare Parameter and LocalParameter
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.Reaction

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.