Package org.sbml.jsbml

Examples of org.sbml.jsbml.UnitDefinition


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


    assertEquals(M.getFunctionDefinition(-2), null);
  }

  @Test
  public void test_Model_add_get_UnitDefinitions() {
    UnitDefinition ud1 = new UnitDefinition(2, 4);
    UnitDefinition ud2 = new UnitDefinition(2, 4);
    ud1.setId("ud1");
    ud2.setId("ud2");
    ud1.createUnit(Kind.LITRE);
    ud2.createUnit(Kind.METRE);
    M.addUnitDefinition(ud1);
    M.addUnitDefinition(ud2);
    assertTrue(M.getNumUnitDefinitions() == 2);
    // assertTrue(!M.getUnitDefinition(0).equals(ud1)); // would be the same in jsbml
    // assertTrue(!M.getUnitDefinition(1).equals(ud2));
View Full Code Here

    assertEquals(M.getSpeciesType(0), c);
  }

  @Test
  public void test_Model_createUnit() {
    UnitDefinition ud;
    Unit u;
    M.createUnitDefinition();
    M.createUnitDefinition();
    u = M.createUnit(Kind.LITRE);
    assertTrue(u != null);
    assertTrue(M.getNumUnitDefinitions() == 2);
    ud = M.getUnitDefinition(1);
    assertTrue(ud.getNumUnits() == 1);
    assertEquals(ud.getUnit(0), u);
  }
View Full Code Here

          if (listOfElementsToWrite.isEmpty()) {
            listOfElementsToWrite = null;
          }
        }
      } else if (sbase instanceof UnitDefinition) {
        UnitDefinition unitDefinition = (UnitDefinition) sbase;

        if (unitDefinition.isSetListOfUnits()) {
          listOfElementsToWrite = new ArrayList<Object>();
          listOfElementsToWrite.add(unitDefinition.getListOfUnits());
        }
      } else if (sbase instanceof Reaction) {
        Reaction reaction = (Reaction) sbase;
        listOfElementsToWrite = new ArrayList<Object>();
View Full Code Here

            Model model = (Model) list.getParentSBMLObject();
            if (elementName.equals("unitDefinition")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfUnitDefinitions)) {
              UnitDefinition unitDefinition = (UnitDefinition) newContextObject;
              model.addUnitDefinition(unitDefinition);

              return unitDefinition;
            } else if (elementName.equals("compartment")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfCompartments)) {
              Compartment compartment = (Compartment) newContextObject;
              model.addCompartment(compartment);

              return compartment;
            } else if (elementName.equals("specie")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfSpecies)) {
              Species species = (Species) newContextObject;
              model.addSpecies(species);

              return species;
            } else if (elementName.equals("parameter")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfParameters)) {
              Parameter parameter = (Parameter) newContextObject;
              model.addParameter(parameter);

              return parameter;
            } else if (elementName.equals("algebraicRule")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfRules)) {
              AlgebraicRule rule = (AlgebraicRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("assignmentRule") // TODO : wrong, there are no assignmentRule element, only more specialize rule
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfRules)) {
              AssignmentRule rule = (AssignmentRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("reaction")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfReactions)) {
              Reaction reaction = (Reaction) newContextObject;
              model.addReaction(reaction);

              return reaction;
            } else {
              // TODO : SBML syntax error, throw an exception?
            }
          } else if (list.getParentSBMLObject() instanceof UnitDefinition) {
            UnitDefinition unitDefinition = (UnitDefinition) list
                .getParentSBMLObject();

            if (elementName.equals("unit")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfUnits)) {
              Unit unit = (Unit) newContextObject;
              unitDefinition.addUnit(unit);

              return unit;
            } else {
              // TODO : SBML syntax error, throw an exception?
            }
          } else if (list.getParentSBMLObject() instanceof Reaction) {
            Reaction reaction = (Reaction) list
                .getParentSBMLObject();

            if (elementName.equals("specieReference")) {
              SpeciesReference speciesReference = (SpeciesReference) newContextObject;

              if (list.getSBaseListType().equals(
                  ListOf.Type.listOfReactants)) {
                reaction.addReactant(speciesReference);

                return speciesReference;
              } else if (list.getSBaseListType().equals(
                  ListOf.Type.listOfProducts)) {
                reaction.addProduct(speciesReference);

                return speciesReference;
              } else {
                // TODO : SBML syntax error, throw an exception?
              }
            } else {
              // TODO : SBML syntax error, throw an exception?
            }
          } else if (list.getParentSBMLObject() instanceof KineticLaw) {
            KineticLaw kineticLaw = (KineticLaw) list
                .getParentSBMLObject();

            if (elementName.equals("parameter")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfParameters)) {
              LocalParameter localParameter = (LocalParameter) newContextObject;
              kineticLaw.addParameter(localParameter);

              return localParameter;
            } else {
              // TODO : SBML syntax error, throw an exception?
            }
          } else {
            // TODO : SBML syntax error, throw an exception?
          }
        } 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 Reaction) {
          Reaction reaction = (Reaction) contextObject;
View Full Code Here

   
    assertTrue(doc.getLevel() == 2 && doc.getVersion() == 3);
   
    assertTrue(model.getNumUnitDefinitions() == 4);
   
    UnitDefinition microM = model.getUnitDefinition(2);
    UnitDefinition microMById = model.getUnitDefinition("microM");
   
    assertTrue(microM.equals(microMById));
   
    assertTrue(microM.getNumUnits() == 2);
    assertTrue(microM.getName().equals("microM"));
View Full Code Here

  private void setCompartmentUnits(Compartment compartment, Model model) {

    if (compartment.isSetUnits()) {
      String unitsID = compartment.getUnits();

      UnitDefinition unitDefinition = model.getUnitDefinition(unitsID);

      if (unitDefinition != null) {
        compartment.setUnits(unitDefinition);
      } else {
        // TODO : the unitDefinition ID doesn't match a unitDefinition,
View Full Code Here

  private void setEventTimeUnits(Event event, Model model) {

    if (event.isSetTimeUnits()) {
      String timeUnitsID = event.getTimeUnits();

      UnitDefinition unitDefinition = model
          .getUnitDefinition(timeUnitsID);

      if (unitDefinition != null) {
        event.setTimeUnits(unitDefinition);
      } else {
View Full Code Here

      Model model) {

    if (parameter.isSetUnits()) {
      String unitsID = parameter.getUnits();

      UnitDefinition unitDefinition = model.getUnitDefinition(unitsID);

      if (unitDefinition != null) {
        parameter.setUnits(unitDefinition);
      } else {
        // TODO : the unitDefinition ID doesn't match an unitDefinition,
View Full Code Here

  private void setSpeciesSubstanceUnits(Species species, Model model) {

    if (species.isSetSubstanceUnits()) {
      String substanceUnitsID = species.getSubstanceUnits();

      UnitDefinition unitDefinition = model
          .getUnitDefinition(substanceUnitsID);

      if (unitDefinition != null) {
        species.setSubstanceUnits(unitDefinition);
      }
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.UnitDefinition

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.