Package org.sbml.jsbml

Examples of org.sbml.jsbml.Unit


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


  /**
   * Test method for {@link org.sbml.jsbml.AbstractNamedSBaseWithUnit#setUnits(org.sbml.jsbml.Unit)}.
   */
  @Test
  public void testSetUnitsUnit() {
    Unit unit = new Unit(kind, sbase.getLevel(), sbase.getVersion());
    sbase.setUnits(unit);
    assertTrue(sbase.isSetUnits());
    assertTrue(sbase.getUnits().equals(kind.toString().toLowerCase()));
    unit.setExponent(2d);
    sbase.setUnits(unit);
    assertTrue(sbase.isSetUnits());
    assertTrue(sbase.isSetUnitsInstance());
    assertTrue(sbase.getUnits().equals(
      '_' + "1_0_0_" + kind.toString() + '_'
        + Double.toString(unit.getExponent()).replace('.', '_')));
  }
View Full Code Here

                .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?
View Full Code Here

    // TODO: If there is a different value in a later SBML specification, this must be checked here.
    ASTNodeValue value = new ASTNodeValue(Maths.AVOGADRO_L3V1, this);
    UnitDefinition perMole = new UnitDefinition(level, version);
    perMole.setLevel(level);
    perMole.setId("per_mole");
    perMole.addUnit(new Unit(Kind.MOLE, -1, level, version));
    value.setUnits(perMole);
    return value;
  }
View Full Code Here

   *
   * @return
   */
  private ASTNodeValue invalid() {
    UnitDefinition ud = new UnitDefinition(level, version);
    ud.addUnit(new Unit(level, version));
    return new ASTNodeValue(ud, this);
  }
View Full Code Here

        right.getUnits().simplify();
        int mean, scale1, scale2;
        double v1 = left.toNumber().doubleValue(), v2 = right
            .toNumber().doubleValue();
        for (int i = 0; i < left.getUnits().getNumUnits(); i++) {
          Unit u1 = left.getUnits().getUnit(i);
          Unit u2 = right.getUnits().getUnit(i);
          if (((u1.getMultiplier() != u2.getMultiplier())
                    && (u1.getScale() != u2.getScale()) && (u1.getExponent() != u2.getExponent()))
                    && (u1.getMultiplier() != 0d) && (u2.getMultiplier() != 0d)) {

            mean = (Math.abs(u1.getScale()) + Math.abs(u2
                .getScale())) / 2;

            if (u1.getScale() > mean) {
              scale1 = Math.abs(u1.getScale()) - mean;
              scale2 = mean - u2.getScale();

            } else {
              scale2 = Math.abs(u2.getScale()) - mean;
              scale1 = mean - u1.getScale();
            }

            if (u1.getExponent() < 0) {
              scale1 = -scale1;
              scale2 = -scale2;
            }

            if (scale1 > mean) {
              v1 = v1
                  * Math.pow(10.0, -scale1 * u1.getExponent());
              v2 = v2
                  * Math.pow(10.0, -scale2 * u2.getExponent());

            } else {
              v1 = v1 * Math.pow(10.0, scale1 * u1.getExponent());
              v2 = v2 * Math.pow(10.0, scale2 * u2.getExponent());
            }

            if (u1.getMultiplier() > 1d) {
              v1 = v1 * u1.getMultiplier();
              u1.setMultiplier(1d);
            }

            if (u2.getMultiplier() > 1d) {
              v2 = v2 * u2.getMultiplier();
              u2.setMultiplier(1d);
            }

            u1.setScale(mean);
            u2.setScale(mean);

          }

        }
        left.setValue(v1);
 
View Full Code Here

  }

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

   */
  public static String toHTML(UnitDefinition ud) {
    StringBuilder sb = new StringBuilder();
    if (ud != null) {
      for (int i = 0; i < ud.getNumUnits(); i++) {
        Unit unit = ud.getUnit(i);
        if (i > 0) {
          sb.append(' ');
          sb.append(C_DOT);
          sb.append(' ');
        }
View Full Code Here

  /**
   * Test method for {@link org.sbml.jsbml.AbstractNamedSBaseWithUnit#setUnits(org.sbml.jsbml.Unit)}.
   */
  @Test
  public void testSetUnitsUnit() {
    Unit unit = new Unit(kind, sbase.getLevel(), sbase.getVersion());
    sbase.setUnits(unit);
    assertTrue(sbase.isSetUnits());
    assertTrue(sbase.getUnits().equals(kind.toString().toLowerCase()));
    unit.setExponent(2d);
    sbase.setUnits(unit);
    assertTrue(sbase.isSetUnits());
    assertTrue(sbase.isSetUnitsInstance());
    assertTrue(sbase.getUnits().equals(
      '_' + "1_0_0_" + kind.toString() + '_'
        + Double.toString(unit.getExponent()).replace('.', '_')));
  }
View Full Code Here

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

TOP

Related Classes of org.sbml.jsbml.Unit

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.