Package org.sbml.jsbml

Examples of org.sbml.jsbml.UnitDefinition


    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.getUnitDefinitionCount() == 2);
    ud = M.getUnitDefinition(1);
    assertTrue(ud.getUnitCount() == 1);
    assertEquals(ud.getUnit(0), u);
  }
View Full Code Here


    assertEquals(ud.getUnit(0), u);
  }

  @Test
  public void test_Model_createUnitDefinition() {
    UnitDefinition ud = M.createUnitDefinition();
    assertTrue(ud != null);
    assertTrue(M.getUnitDefinitionCount() == 1);
    assertEquals(M.getUnitDefinition(0), ud);
  }
View Full Code Here

    assertTrue(M.getSpecies("Glucose2") == null);
  }

  @Test
  public void test_Model_getUnitDefinition() {
    UnitDefinition ud1 = new UnitDefinition(2, 4);
    UnitDefinition ud2 = new UnitDefinition(2, 4);
    ud1.setId("mmls");
    ud2.setId("volume");
    ud1.createUnit(Kind.LITRE);
    ud2.createUnit(Kind.LITRE);
    M.addUnitDefinition(ud1);
    M.addUnitDefinition(ud2);
    assertTrue(M.getUnitDefinitionCount() == 2);
    ud1 = M.getUnitDefinition(0);
    ud2 = M.getUnitDefinition(1);
    assertTrue(ud1.getId().equals("mmls"));
    assertTrue(ud2.getId().equals("volume"));
  }
View Full Code Here

    assertTrue(ud2.getId().equals("volume"));
  }

  @Test
  public void test_Model_getUnitDefinitionById() {
    UnitDefinition ud1 = new UnitDefinition(2, 4);
    UnitDefinition ud2 = new UnitDefinition(2, 4);
    ud1.setId("mmls");
    ud2.setId("volume");
    ud1.createUnit(Kind.LITRE);
    ud2.createUnit(Kind.LITRE);
    M.addUnitDefinition(ud1);
    M.addUnitDefinition(ud2);
    assertTrue(M.getUnitDefinitionCount() == 2);
    // assertNotEquals(M.getUnitDefinition("mmls"), ud1);
    // assertNotEquals(M.getUnitDefinition("volume"), ud2);
View Full Code Here

    o3 = null;
  }

  @Test
  public void test_Model_removeUnitDefinition() {
    UnitDefinition o1, o2, o3;
    o1 = M.createUnitDefinition();
    o2 = M.createUnitDefinition();
    o3 = M.createUnitDefinition();
    o3.setId("test");
    assertTrue(M.removeUnitDefinition(0).equals(o1));
View Full Code Here

    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.getCompartmentCount() == 1);
    c = m.getCompartment(0);
    assertTrue(c.getName().equals("compartmentOne"));
    assertTrue(c.getVolume() == 1);
    ud = c.getDerivedUnitDefinition();
    assertTrue(ud.getUnitCount() == 1);

    // assertTrue(ud.getUnit(0).getKind() == Unit.Kind.LITRE); // getDerivedUnitDefinition not working properly
    assertTrue(m.getSpeciesCount() == 4);
    s = m.getSpecies(0);
    assertTrue(s.getName().equals("S1"));
View Full Code Here

   */
  @Before
  public void setUp() throws Exception {
    Locale.setDefault(Locale.ENGLISH);
   
    ud1 = new UnitDefinition("ud1", level, version);
    ud2 = new UnitDefinition("ud2", level, version);
    ud3 = new UnitDefinition("ud3", level, version);
    ud4 = new UnitDefinition("ud4", level, version);
    ud5 = new UnitDefinition("ud5", level, version);
    ud6 = new UnitDefinition("ud6", level, version);
    ud7 = new UnitDefinition("ud7", level, version);
   
    // mole per litre
    ud1.addUnit(Kind.MOLE);
    ud1.addUnit(new Unit(Kind.LITRE, -1d, level, version));
   
View Full Code Here

  /**
   * Test method for {@link Unit#removeMultiplier()}.
   */
  @Test
  public void testRemoveMultiplier() {
    UnitDefinition uuu = new UnitDefinition("energy", level, version);
    int scale = 12;
    double multiplier = 10E-10d;
    double noise = 1E-23d;
    double exp = 1d;
    uuu.addUnit(new Unit(multiplier + noise, scale, Kind.JOULE, exp, level, version));
    uuu.getUnit(0).removeMultiplier();
    assertTrue(UnitDefinition.printUnits(uuu, true).equals("kJ"));
  }
View Full Code Here

   * Test method for {@link UnitDefinition#simplify()}.
   */
  @Test
  public void testSimplify() {
    // TODO: add more test cases!
    UnitDefinition udef = ud1.clone().divideBy(ud1).simplify();
    printTask('/', ud1, ud1, udef);
    assertTrue(UnitDefinition.printUnits(udef, true).equals("dimensionless"));
   
    udef = ud1.clone().divideBy(ud2).simplify();
    printTask('/', ud1, ud2, udef);
    assertTrue(UnitDefinition.printUnits(udef, true).equals("ml^(-2)*mol"));
   
    udef = ud1.clone().multiplyWith(ud2).simplify();
    printTask('*', ud1, ud2, udef);
    assertTrue(UnitDefinition.printUnits(udef, true).equals("\u03BCmol"));
   
    udef = ud1.clone().multiplyWith(ud2);
    udef = udef.simplify();
    udef = udef.divideBy(ud3);
    System.out.println(c(ud1) + '*' + c(ud2) + '/' + c(ud3) + " = " + c(udef));
    assertTrue(UnitDefinition.printUnits(udef, true).equals("\u03BCmol*(3600*s)^(-1)"));
   
    udef = ud3.clone().divideBy(ud4).simplify();
    printTask('/', ud3, ud4, udef);
    assertTrue(UnitDefinition.printUnits(udef, true).equals("60*dimensionless"));
   
    UnitDefinition u1 = new UnitDefinition(level, version);
    u1.addUnit(new Unit(-3, Unit.Kind.JOULE, level, version));
    u1.addUnit(new Unit(-3, Unit.Kind.MOLE, level, version));
   
    UnitDefinition u2 = new UnitDefinition(level, version);
    u2.addUnit(new Unit(Unit.Kind.JOULE, 5, level, version));
    u2.addUnit(new Unit(Unit.Kind.MOLE, 5, level, version));
   
    udef = u1.clone().divideBy(u2).simplify();
    printTask('/', u1, u2, udef);
    double pow = Math.pow(10, 3d/4d);
    assertTrue(UnitDefinition.printUnits(udef, true).equals('('+ Double.toString(pow) +"*J)^(-4)*(" + Double.toString(pow) + "*mol)^(-4)"));
   
    UnitDefinition u3 = new UnitDefinition(level, version);
    u3.addUnit(new Unit(Kind.MOLE, -4d, level, version));
    u3.addUnit(new Unit(Kind.SECOND, -1d, level, version));
    udef = ud5.clone().multiplyWith(u3).simplify();
    printTask('*', ud5, u3, udef);
    assertTrue(UnitDefinition.printUnits(udef, true).equals("hmol^(-3)*s^(-1)"));
   
    u1 = ud5.clone().raiseByThePowerOf(5d);
View Full Code Here

              return functionDefinition;
            } else 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;
              compartment.initDefaults();
              model.addCompartment(compartment);

              return compartment;
            } else if (elementName.equals("species")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfSpecies)
                && ((model.getLevel() == 1 && model
                    .getVersion() > 1) || model.getLevel() > 1)) {
              Species species = (Species) newContextObject;
              species.initDefaults();
              model.addSpecies(species);

              return species;
            }
            // level 1: species => specie
            else if (elementName.equals("specie")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfSpecies)
                && model.getLevel() == 1
                && model.getVersion() == 1) {
              Species species = (Species) newContextObject;
              species.initDefaults();
              model.addSpecies(species);

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

              return parameter;
            } else if (elementName.equals("initialAssignment")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfInitialAssignments)
                && ((model.getLevel() == 2 && model
                    .getVersion() > 1) || model.getLevel() >= 3)) {
              InitialAssignment initialAssignment = (InitialAssignment) newContextObject;
              model.addInitialAssignment(initialAssignment);

              return initialAssignment;
            } 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")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfRules)
                && model.getLevel() > 1) {
              AssignmentRule rule = (AssignmentRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("parameterRule")
                && list.getSBaseListType().equals(ListOf.Type.listOfRules)
                && model.getLevel() == 1)
            {
              ExplicitRule rule = (ExplicitRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("specieConcentrationRule")
                && list.getSBaseListType().equals(ListOf.Type.listOfRules)
                && model.getLevel() == 1
                && model.getVersion() == 1)
            {
              ExplicitRule rule = (ExplicitRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("speciesConcentrationRule")
                && list.getSBaseListType().equals(ListOf.Type.listOfRules)
                && model.getLevel() == 1
                && model.getVersion() == 2)
            {
              ExplicitRule rule = (ExplicitRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("compartmentVolumeRule")
                && list.getSBaseListType().equals(ListOf.Type.listOfRules)
                && model.getLevel() == 1)
            {
              ExplicitRule rule = (ExplicitRule) newContextObject;
              model.addRule(rule);

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

              return rule;
            } else if (elementName.equals("constraint")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfConstraints)
                && ((model.getLevel() == 2 && model
                    .getVersion() > 1) || model.getLevel() >= 3)) {
              Constraint constraint = (Constraint) newContextObject;
              model.addConstraint(constraint);

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

              return reaction;
            } else if (elementName.equals("event")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfEvents)
                && model.getLevel() > 1) {
              Event event = (Event) newContextObject;
              model.addEvent(event);
              event.initDefaults();

              return event;
            } else if (elementName.equals("compartmentType")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfCompartmentTypes)
                && (model.getLevel() == 2 && model.getVersion() > 1)) {
              CompartmentType compartmentType = (CompartmentType) newContextObject;
              model.addCompartmentType(compartmentType);

              return compartmentType;
            } else if (elementName.equals("speciesType")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfSpeciesTypes)
                && (model.getLevel() == 2 && model.getVersion() > 1)) {
              SpeciesType speciesType = (SpeciesType) newContextObject;
              model.addSpeciesType(speciesType);

              return speciesType;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } 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;
              unit.initDefaults();
              unitDefinition.addUnit(unit);

              return unit;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } else if (list.getParentSBMLObject() instanceof Reaction) {
            Reaction reaction = (Reaction) list
                .getParentSBMLObject();

            if (elementName.equals("speciesReference")
                && (reaction.getLevel() > 1 || (reaction
                    .getLevel() == 1 && reaction
                    .getVersion() == 2))) {
              SpeciesReference speciesReference = (SpeciesReference) newContextObject;
              speciesReference.initDefaults();

              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 {
                log4jLogger.warn("The element " + elementName + " is not recognized");
              }
            } else if (elementName.equals("specieReference")
                && reaction.getLevel() == 1) {
              SpeciesReference speciesReference = (SpeciesReference) newContextObject;
              speciesReference.initDefaults();

              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 {
                log4jLogger.warn("The element " + elementName + " is not recognized");
              }
            } else if (elementName
                .equals("modifierSpeciesReference")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfModifiers)
                && reaction.getLevel() > 1) {
              ModifierSpeciesReference modifierSpeciesReference = (ModifierSpeciesReference) newContextObject;
              reaction.addModifier(modifierSpeciesReference);

              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.addLocalParameter(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.addLocalParameter(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;
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.