Package org.sbml.jsbml

Examples of org.sbml.jsbml.KineticLaw


    HashSet<Reaction> reactionSet = new HashSet<Reaction>();
   
    reactionSet.add(r2);
    reactionSet.add(r3);
   
    KineticLaw kl = r2.createKineticLaw();
    kl.createLocalParameter("LP1");
   
    reactionSet.remove(r2); // unsuccessful as the hashCode of r2 has changed since we added it to the HashSet !!
    // The javadoc is misleading on this case as it just says that the equals method will be used
    // They probably use the hashcode as the key for the underlying HashMap.
   
View Full Code Here


    // Creating a new reaction without id
    Reaction r2 = model.createReaction();

    assertTrue(model.getNumReactions() == 2);

    KineticLaw k = r2.createKineticLaw();
   
    // Creating a new local parameter without id
    LocalParameter lp = k.createLocalParameter();
   
    lp.setMetaId("LP1_2");
    lp.setName("LP1_2");
    lp.setId("LP1");
   
    assertTrue(k.getLocalParameterCount() == 1);
   
    assertTrue(doc.findSBase("LP1_2") != null);

    assertTrue(k.getLocalParameter("LP1") != null);
    assertTrue(model.findLocalParameters("LP1").size() == 2);
    assertTrue(model.findReactionsForLocalParameter("LP1").size() == 1); // because r2 has no ID yet !!
   
    lp.setId("LP1_2"); // changing the id of the localParameter !!
   
    assertTrue(k.getLocalParameter("LP1") == null);
    assertTrue(k.getLocalParameter("LP1_2") != null);
   
    assertTrue(model.findLocalParameters("LP1_2").size() == 1);
   
    assertTrue(model.findLocalParameters("LP1").size() == 1);
   
View Full Code Here

   */
  @Test public void testRegister8() {
   
    Reaction r2 = model.createReaction("R2");
   
    KineticLaw kl = r2.createKineticLaw();

    ListOf<LocalParameter> listOfLP = new ListOf<LocalParameter>(2, 4);
    listOfLP.add(new LocalParameter("LP1"));
    listOfLP.add(new LocalParameter("LP2"));
    listOfLP.add(new LocalParameter("LP3"));
    listOfLP.add(new LocalParameter("LP1"));
   
    try {
     
      kl.setListOfLocalParameters(listOfLP);
     
      fail("We should not be able to register twice the same local parameter id.");
    } catch(IllegalArgumentException e) {
      // success
    }
   
    assertTrue(kl.getLocalParameterCount() == 0);
    assertTrue(model.findLocalParameters("LP1").size() == 1);
    assertTrue(model.findLocalParameters("LP2").size() == 0);
       
    // listOfLP.remove(3); // TODO : at the moment the list of local parameter is emptied if there is an error !! Should we clone the listOf
    // when using the setListOf methods ??

    listOfLP.clear();
    listOfLP.add(new LocalParameter("LP1"));
    listOfLP.add(new LocalParameter("LP2"));
    listOfLP.add(new LocalParameter("LP3"));

    try {
     
      kl.setListOfLocalParameters(listOfLP);
     
    } catch(IllegalArgumentException e) {
      fail("We should be able to set a valid list of local parameters.");
    }

    assertTrue(kl.getLocalParameterCount() == 3);
    assertTrue(model.findLocalParameters("LP1").size() == 2);
    assertTrue(model.findLocalParameters("LP2").size() == 1);
 
    kl.removeLocalParameter("LP2");
    kl.removeLocalParameter(1);
   
    assertTrue(kl.getLocalParameterCount() == 1);   
    assertTrue(model.findLocalParameters("LP2").size() == 0);   
    assertTrue(model.findLocalParameters("LP3").size() == 0);
   
    kl.createLocalParameter("LP2");

    assertTrue(kl.getLocalParameterCount() == 2);   
    assertTrue(model.findLocalParameters("LP2").size() == 1);
  }
View Full Code Here

        if (listOfElementsToWrite.isEmpty()) {
          listOfElementsToWrite = null;
        }
      } else if (sbase instanceof KineticLaw) {
        KineticLaw kineticLaw = (KineticLaw) sbase;

        if (kineticLaw.isSetListOfLocalParameters()) {
          listOfElementsToWrite = new ArrayList<Object>();
          listOfElementsToWrite.add(kineticLaw.getListOfLocalParameters());
        }
      } else if (sbase instanceof SpeciesReference) {
        SpeciesReference speciesReference = (SpeciesReference) sbase;

        if (speciesReference.isSetStoichiometryMath()) {
View Full Code Here

                    modifierSpeciesReference.getId(), modifierSpeciesReference.getElementName()));
              }
            }
          }
          if (reaction.isSetKineticLaw()) {
            KineticLaw kineticLaw = reaction.getKineticLaw();
            if (kineticLaw.isSetTimeUnits()
                && !kineticLaw.isSetTimeUnitsInstance()) {
              log4jLogger.warn("No UnitDefinition matches the timeUnitsID of kineticLaw.");
            }
            if (kineticLaw.isSetSubstanceUnits()
                && !kineticLaw.isSetSubstanceUnitsInstance()) {
              log4jLogger.warn("No UnitDefinition matches the substanceUnitsID of kineticLaw.");
            }
            if (kineticLaw.isSetListOfLocalParameters()) {
              for (int j = 0; j < kineticLaw.getNumLocalParameters(); j++) {
                LocalParameter parameter = kineticLaw
                    .getLocalParameter(j);
                if (parameter.isSetUnits()
                    && !parameter.isSetUnitsInstance()) {
                  log4jLogger.warn(String.format(
                    "No UnitDefinition matches the unitsID '%s'of the parameter %s.",
View Full Code Here

              return modifierSpeciesReference;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } else if (list.getParentSBMLObject() instanceof KineticLaw) {
            KineticLaw kineticLaw = (KineticLaw) list
                .getParentSBMLObject();
            // Level 3 : parameter and listOfParameters =>
            // localParameter and listOfLocalParameter
            if (elementName.equals("localParameter")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfLocalParameters)
                && kineticLaw.getLevel() >= 3) {
              LocalParameter localParameter = (LocalParameter) newContextObject;
              kineticLaw.addParameter(localParameter);

              return localParameter;
            } else if (elementName.equals("parameter")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfLocalParameters)
                && kineticLaw.isSetLevel()
                && kineticLaw.getLevel() < 3) {
              LocalParameter localParameter = new LocalParameter(
                  (Parameter) newContextObject);
              kineticLaw.addParameter(localParameter);

              return localParameter;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } else if (list.getParentSBMLObject() instanceof Event) {
            Event event = (Event) list.getParentSBMLObject();

            if (elementName.equals("eventAssignment")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfEventAssignments)
                && event.getLevel() > 1) {
              EventAssignment eventAssignment = (EventAssignment) newContextObject;
              event.addEventAssignment(eventAssignment);

              return eventAssignment;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof UnitDefinition) {
          UnitDefinition unitDefinition = (UnitDefinition) contextObject;

          if (elementName.equals("listOfUnits")) {
            ListOf<Unit> listOfUnits = (ListOf<Unit>) newContextObject;
            unitDefinition.setListOfUnits(listOfUnits);

            return listOfUnits;
          }
        } else if (contextObject instanceof Event) {
          Event event = (Event) contextObject;

          if (elementName.equals("listOfEventAssignments")) {
            ListOf<EventAssignment> listOfEventAssignments = (ListOf<EventAssignment>) newContextObject;
            event.setListOfEventAssignments(listOfEventAssignments);

            return listOfEventAssignments;
          } else if (elementName.equals("trigger")) {
            Trigger trigger = (Trigger) newContextObject;
            event.setTrigger(trigger);

            return trigger;
          } else if (elementName.equals("delay")) {
            Delay delay = (Delay) newContextObject;
            event.setDelay(delay);

            return delay;
          } else if (elementName.equals("priority")) {
            Priority priority = (Priority) newContextObject;
            event.setPriority(priority);

            return priority;
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof Reaction) {
          Reaction reaction = (Reaction) contextObject;
          if (elementName.equals("listOfReactants")) {
            ListOf<SpeciesReference> listOfReactants = (ListOf<SpeciesReference>) newContextObject;
            reaction.setListOfReactants(listOfReactants);

            return listOfReactants;
          } else if (elementName.equals("listOfProducts")) {
            ListOf<SpeciesReference> listOfProducts = (ListOf<SpeciesReference>) newContextObject;
            reaction.setListOfProducts(listOfProducts);

            return listOfProducts;
          } else if (elementName.equals("listOfModifiers")
              && reaction.getLevel() > 1) {
            ListOf<ModifierSpeciesReference> listOfModifiers = (ListOf<ModifierSpeciesReference>) newContextObject;
            reaction.setListOfModifiers(listOfModifiers);

            return listOfModifiers;
          } else if (elementName.equals("kineticLaw")) {
            KineticLaw kineticLaw = (KineticLaw) newContextObject;
            reaction.setKineticLaw(kineticLaw);

            return kineticLaw;
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof SpeciesReference) {
          SpeciesReference speciesReference = (SpeciesReference) contextObject;

          if (elementName.equals("stoichiometryMath")) {
            StoichiometryMath stoichiometryMath = (StoichiometryMath) newContextObject;
            speciesReference.setStoichiometryMath(stoichiometryMath);

            return stoichiometryMath;
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof KineticLaw) {
          KineticLaw kineticLaw = (KineticLaw) contextObject;

          if (elementName.equals("listOfLocalParameters")
              && kineticLaw.getLevel() >= 3) {
            ListOf<LocalParameter> listOfLocalParameters = (ListOf<LocalParameter>) newContextObject;
            kineticLaw.setListOfLocalParameters(listOfLocalParameters);
            listOfLocalParameters.setSBaseListType(ListOf.Type.listOfLocalParameters);

            return listOfLocalParameters;
          } else if (elementName.equals("listOfParameters")
              && kineticLaw.isSetLevel() && kineticLaw.getLevel() < 3) {
            ListOf<LocalParameter> listOfLocalParameters = (ListOf<LocalParameter>) newContextObject;
            kineticLaw.setListOfLocalParameters(listOfLocalParameters);
            listOfLocalParameters.setSBaseListType(ListOf.Type.listOfLocalParameters);

            return listOfLocalParameters;
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
View Full Code Here

          setRDFAbout(reaction);
          logger.warn("The reaction element '" + reaction.getId() + "' has an invalid rdf:about inside his annotation.");
        }

        if (reaction.isSetKineticLaw()){
          KineticLaw kineticLaw = reaction.getKineticLaw();

          if (!kineticLaw.hasValidAnnotation()){
            setRDFAbout(kineticLaw);
            logger.warn("The kineticLaw element '" + kineticLaw.getMetaId() + "' has an invalid rdf:about inside his annotation.");
          }

          if (kineticLaw.isSetListOfParameters()){
            for (LocalParameter parameter : kineticLaw.getListOfLocalParameters()){
              if (!parameter.hasValidAnnotation()){
                setRDFAbout(parameter);
                logger.warn("The local parameter element '" + parameter.getId() + "' has an invalid rdf:about inside his annotation.");
              }
            }
View Full Code Here

  @Test
  public void test_read_l1v1_branch() throws XMLStreamException, InvalidPropertiesFormatException, IOException, ClassNotFoundException {
    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);
    d = null;
  }
View Full Code Here

   
    /*
     * 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 ====");
View Full Code Here

        if (listOfElementsToWrite.isEmpty()) {
          listOfElementsToWrite = null;
        }
      } else if (sbase instanceof KineticLaw) {
        KineticLaw kineticLaw = (KineticLaw) sbase;

        if (kineticLaw.isSetListOfParameters()) {
          listOfElementsToWrite = new ArrayList<Object>();
          listOfElementsToWrite.add(kineticLaw.getListOfParameters());
        }
      }
    }
    return listOfElementsToWrite;
  }
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.KineticLaw

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.