getUnitDefinition() public method

public getUnitDefinition ( long n ) : UnitDefinition
n long
return UnitDefinition
示例#1
0
        /// <summary>
        /// [ UnitDefinitionStruct ]
        /// [[ Id , Name , [ UnitStruct ] ]]
        /// </summary>
        /// <param name="aSBMLmodel"></param>
        /// <returns></returns>
        public static List<UnitDefinitionStruct> getUnitDefinition(Model aSBMLmodel)
        {
            List<UnitDefinitionStruct> list = new List<UnitDefinitionStruct>();

            ListOfUnitDefinitions listOfUnitDefinitions = aSBMLmodel.getListOfUnitDefinitions();
            for (int i = 0; i < listOfUnitDefinitions.size(); i++ )
            {
                UnitDefinition anUnitDefinition = aSBMLmodel.getUnitDefinition(i);

                string anId = anUnitDefinition.getId();
                string aName = anUnitDefinition.getName();

                List<UnitStruct> unitList = new List<UnitStruct>();

                ListOfUnits listOfUnits = anUnitDefinition.getListOfUnits();
                for (int j = 0; j < listOfUnits.size(); j++)
                {
                    Unit anUnit = anUnitDefinition.getUnit(j);

                    int anUnitKind = anUnit.getKind();
                    string aKind = libsbml.libsbml.UnitKind_toString( anUnitKind );
                    int anExponent = anUnit.getExponent();
                    int aScale = anUnit.getScale();
                    double aMultiplier = anUnit.getMultiplier();
                    double anOffset = anUnit.getOffset();

                    UnitStruct unit = new UnitStruct(
                        aKind,
                        anExponent,
                        aScale,
                        aMultiplier,
                        anOffset );

                    unitList.Add( unit );
                }

                UnitDefinitionStruct unitDefinition = new UnitDefinitionStruct(
                    anId,
                    aName,
                    unitList );

                list.Add(unitDefinition);
            }

            return list;
        }
 public void test_UnitDefinition_parent_add()
 {
     UnitDefinition ia = new UnitDefinition(2,4);
       Model m = new Model(2,4);
       ia.setId("u");
       ia.createUnit();
       m.addUnitDefinition(ia);
       ia = null;
       ListOf lo = m.getListOfUnitDefinitions();
       assertTrue( lo == m.getUnitDefinition(0).getParentSBMLObject() );
       assertTrue( m == lo.getParentSBMLObject() );
 }
 public void test_UnitDefinition_parent_create()
 {
     Model m = new Model(2,4);
       UnitDefinition ud = m.createUnitDefinition();
       ListOf lo = m.getListOfUnitDefinitions();
       assertTrue( lo == m.getUnitDefinition(0).getParentSBMLObject() );
       assertTrue( lo == ud.getParentSBMLObject() );
       assertTrue( m == lo.getParentSBMLObject() );
 }
示例#4
0
 public void test_UnitDefinition_ancestor_add()
 {
     UnitDefinition ia = new UnitDefinition(2,4);
       Model m = new Model(2,4);
       ia.setId("u");
       ia.createUnit();
       m.addUnitDefinition(ia);
       ia = null;
       ListOf lo = m.getListOfUnitDefinitions();
       UnitDefinition obj = m.getUnitDefinition(0);
       assertTrue( obj.getAncestorOfType(libsbml.SBML_MODEL) == m );
       assertTrue( obj.getAncestorOfType(libsbml.SBML_LIST_OF) == lo );
       assertTrue( obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == null );
       assertTrue( obj.getAncestorOfType(libsbml.SBML_EVENT) == null );
 }
示例#5
0
 public void test_UnitDefinition_ancestor_create()
 {
     Model m = new Model(2,4);
       UnitDefinition ud = m.createUnitDefinition();
       ListOf lo = m.getListOfUnitDefinitions();
       assertTrue( ud.getAncestorOfType(libsbml.SBML_MODEL) == m );
       assertTrue( ud.getAncestorOfType(libsbml.SBML_LIST_OF) == lo );
       assertTrue( ud.getAncestorOfType(libsbml.SBML_DOCUMENT) == null );
       assertTrue( ud.getAncestorOfType(libsbml.SBML_EVENT) == null );
       UnitDefinition obj = m.getUnitDefinition(0);
       assertTrue( obj.getAncestorOfType(libsbml.SBML_MODEL) == m );
       assertTrue( obj.getAncestorOfType(libsbml.SBML_LIST_OF) == lo );
       assertTrue( obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == null );
       assertTrue( obj.getAncestorOfType(libsbml.SBML_EVENT) == null );
 }
示例#6
0
 public void test_ReadSBML_metaid()
 {
     SBase sb;
       string s = wrapSBML_L2v1("<listOfFunctionDefinitions>" +
     "  <functionDefinition metaid='fd'/>" +
     "</listOfFunctionDefinitions>" +
     "<listOfUnitDefinitions>" +
     "  <unitDefinition metaid='ud'/>" +
     "</listOfUnitDefinitions>" +
     "<listOfCompartments>" +
     "  <compartment metaid='c'/>" +
     "</listOfCompartments>" +
     "<listOfSpecies>" +
     "  <species metaid='s'/>" +
     "</listOfSpecies>" +
     "<listOfParameters>" +
     "  <parameter metaid='p'/>" +
     "</listOfParameters>" +
     "<listOfRules>" +
     "  <rateRule metaid='rr'/>" +
     "</listOfRules>" +
     "<listOfReactions>" +
     "  <reaction metaid='rx'/>" +
     "</listOfReactions>" +
     "<listOfEvents>" +
     " <event metaid='e'/>" +
     "</listOfEvents>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M != null );
       sb = M.getFunctionDefinition(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "fd" == sb.getMetaId() ));
       sb = M.getUnitDefinition(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "ud" == sb.getMetaId() ));
       sb = M.getCompartment(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "c" == sb.getMetaId() ));
       sb = M.getSpecies(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "s" == sb.getMetaId() ));
       sb = M.getParameter(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "p" == sb.getMetaId() ));
       sb = M.getRule(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "rr" == sb.getMetaId() ));
       sb = M.getReaction(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "rx" == sb.getMetaId() ));
       sb = M.getEvent(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "e" == sb.getMetaId() ));
 }
示例#7
0
 public void test_ReadSBML_metaid_Unit()
 {
     SBase sb;
       UnitDefinition ud;
       string s = wrapSBML_L2v1("<listOfUnitDefinitions>" +
     "  <unitDefinition metaid='ud'>" +
     "    <listOfUnits metaid='lou'>" +
     "      <unit metaid='u'/>" +
     "    </listOfUnits>" +
     "  </unitDefinition>" +
     "</listOfUnitDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M != null );
       ud = M.getUnitDefinition(0);
       sb = ud;
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "ud" == sb.getMetaId() ));
       sb = ud.getListOfUnits();
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "lou" == sb.getMetaId() ));
       sb = ud.getUnit(0);
       assertEquals( true, sb.isSetMetaId() );
       assertTrue((  "u" == sb.getMetaId() ));
 }
示例#8
0
 public void test_ReadSBML_Unit_L2()
 {
     Unit u;
       UnitDefinition ud;
       string s = wrapSBML_L2v1("<listOfUnitDefinitions>" +
     "  <unitDefinition id='Fahrenheit'>" +
     "    <listOfUnits>" +
     "      <unit kind='Celsius' multiplier='1.8' offset='32'/>" +
     "    </listOfUnits>" +
     "  </unitDefinition>" +
     "</listOfUnitDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumUnitDefinitions() == 1 );
       ud = M.getUnitDefinition(0);
       assertEquals( true, ud.isSetId() );
       assertTrue((  "Fahrenheit" == ud.getId() ));
       assertTrue( ud.getNumUnits() == 1 );
       u = ud.getUnit(0);
       assertTrue( u.getKind() == libsbml.UNIT_KIND_CELSIUS );
       assertTrue( u.getExponent() == 1 );
       assertTrue( u.getScale() == 0 );
       assertTrue( u.getMultiplier() == 1.8 );
       assertTrue( u.getOffset() == 32 );
 }
示例#9
0
 public void test_ReadSBML_Unit_defaults_L1_L2()
 {
     Unit u;
       UnitDefinition ud;
       string s = wrapSBML_L1v2("<listOfUnitDefinitions>" +
     "  <unitDefinition name='bogomips'>" +
     "    <listOfUnits> <unit kind='second'/> </listOfUnits>" +
     "  </unitDefinition>" +
     "</listOfUnitDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumUnitDefinitions() == 1 );
       ud = M.getUnitDefinition(0);
       assertTrue((  "bogomips" == ud.getId() ));
       assertTrue( ud.getNumUnits() == 1 );
       u = ud.getUnit(0);
       assertTrue( u.getKind() == libsbml.UNIT_KIND_SECOND );
       assertTrue( u.getExponent() == 1 );
       assertTrue( u.getScale() == 0 );
       assertTrue( u.getMultiplier() == 1.0 );
       assertTrue( u.getOffset() == 0.0 );
 }
示例#10
0
 public void test_ReadSBML_UnitDefinition_L2()
 {
     UnitDefinition ud;
       string s = wrapSBML_L2v1("<listOfUnitDefinitions>" +
     "  <unitDefinition id='mmls' name='mmol/ls'/>" +
     "</listOfUnitDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumUnitDefinitions() == 1 );
       ud = M.getUnitDefinition(0);
       assertEquals( true, ud.isSetId() );
       assertEquals( true, ud.isSetName() );
       assertTrue((  "mmls" == ud.getId() ));
       assertTrue((  "mmol/ls" == ud.getName() ));
 }
示例#11
0
 public void test_ReadSBML_UnitDefinition()
 {
     UnitDefinition ud;
       string s = wrapSBML_L1v2("<listOfUnitDefinitions>" +
     "  <unitDefinition name='mmls'/>" +
     "</listOfUnitDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumUnitDefinitions() == 1 );
       ud = M.getUnitDefinition(0);
       assertTrue((  "mmls" == ud.getId() ));
 }
示例#12
0
 public void test_ReadSBML_Unit()
 {
     Unit u;
       UnitDefinition ud;
       string s = wrapSBML_L1v2("<listOfUnitDefinitions>" +
     "  <unitDefinition name='substance'>" +
     "    <listOfUnits> <unit kind='mole' scale='-3'/> </listOfUnits>" +
     "  </unitDefinition>" +
     "</listOfUnitDefinitions>");
       D = libsbml.readSBMLFromString(s);
       M = D.getModel();
       assertTrue( M.getNumUnitDefinitions() == 1 );
       ud = M.getUnitDefinition(0);
       assertTrue((  "substance" == ud.getId() ));
       assertTrue( ud.getNumUnits() == 1 );
       u = ud.getUnit(0);
       assertTrue( u.getKind() == libsbml.UNIT_KIND_MOLE );
       assertTrue( u.getExponent() == 1 );
       assertTrue( u.getScale() == -3 );
 }