コード例 #1
0
ファイル: SBML_Model.cs プロジェクト: ecell/ecell3-ide
        /// <summary>
        /// 
        /// </summary>
        /// <param name="anUnit"></param>
        /// <returns></returns>
        private double getNewUnitValue(UnitStruct anUnit)
        {
            double aValue = 1;

            // Scale
            if ( anUnit.Scale != 0 )
                aValue = aValue * Math.Pow( 10, anUnit.Scale );

            // Multiplier
            aValue = aValue * anUnit.Multiplier;

            // Exponent
            aValue = Math.Pow( aValue, anUnit.Exponent );

            // Offset
            aValue = aValue + anUnit.Offset;

            return aValue;
        }
コード例 #2
0
ファイル: TestStructs.cs プロジェクト: ecell/ecell3-ide
 public void TestConstructorOfStructs()
 {
     //
     CompartmentStruct c = new CompartmentStruct(
         "ID",
         "Name",
         0,
         0.0,
         0.0,
         "Unit",
         "Parent",
         false);
     //
     EventStruct e = new EventStruct(
         "ID",
         "Name",
         "Trigger",
         "delay",
         "TimeUnit",
         new List<EventAssignmentStruct>());
     //
     EventAssignmentStruct ea = new EventAssignmentStruct(
         "Variable",
         "Formula");
     //
     FunctionDefinitionStruct fd = new FunctionDefinitionStruct(
         "ID",
         "Name",
         "Formula");
     //
     ParameterStruct p = new ParameterStruct(
         "ID",
         "Name",
         0.0,
         "Unit",
         false);
     //
     ReactionStruct r = new ReactionStruct(
         "ID",
         "Name",
         new List<KineticLawStruct>(),
         false,
         false,
         new List<ReactantStruct>(),
         new List<ProductStruct>(),
         new List<string>());
     //
     KineticLawStruct k = new KineticLawStruct(
         "Formula",
         new List<string>(),
         "TimeUnit",
         "Substance",
         new List<ParameterStruct>(),
         null);
     //
     ReactantStruct rs = new ReactantStruct(
         "Species",
         0,
         "Formula",
         0);
     //
     ProductStruct ps = new ProductStruct(
         "Species",
         0.0,
         "Formula",
         0);
     //
     RuleStruct rule = new RuleStruct(
         0,
         "Formula",
         "Variable");
     //
     SpeciesStruct s = new SpeciesStruct(
         "ID",
         "Name",
         "Parent",
         0.0,
         0.0,
         "Substance",
         "Spatial",
         "Unit",
         false,
         false,
         0,
         false);
     //
     UnitDefinitionStruct ud = new UnitDefinitionStruct(
         "ID",
         "Name",
         new List<UnitStruct>());
     //
     UnitStruct u = new UnitStruct(
         "Kind",
         0,
         0,
         0.0,
         0.0);
     //
     VariableReferenceStruct v = new VariableReferenceStruct(
         "Name",
         "Variable",
         0);
     //
     InitialAssignmentStruct i = new InitialAssignmentStruct(
         "Name",
         0.0);
 }
コード例 #3
0
ファイル: SbmlFunctions.cs プロジェクト: ecell/ecell3-ide
        /// <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;
        }
コード例 #4
0
ファイル: TestStructs.cs プロジェクト: ecell/ecell3-ide
        public void TestSBML_Model()
        {
            SBMLReader reader = new SBMLReader();
            SBMLDocument document = reader.readSBML(TestConstant.SBML_Oscillation);

            SBML_Model model = new SBML_Model(document.getModel());

            // getSpeciesReferenceID
            SpeciesStruct ss = new SpeciesStruct();
            ss.Compartment = "cell";
            ss.ID = "Test1";
            ss.Name = "Test1";

            string id;
            try
            {
                id = model.getSpeciesReferenceID(ss.ID);
            }
            catch (Exception)
            {
            }
            model.SpeciesList.Add(ss);
            id = model.getSpeciesReferenceID(ss.ID);
            Assert.AreEqual("/cell:Test1", id, "getEventID returns unexpected value.");

            try
            {
                model.Level = 1;
                id = model.getSpeciesReferenceID(ss.ID);
            }
            catch (Exception)
            {
            }

            try
            {
                model.Level = 0;
                id = model.getSpeciesReferenceID(ss.ID);
            }
            catch (Exception)
            {
            }

            // setFunctionDefinitionToDictionary
            FunctionDefinitionStruct ud = new FunctionDefinitionStruct();
            ud.ID = "Function";
            ud.Name = "Function";
            ud.Formula = "1 * 2";
            model.FunctionDefinitionList.Add(ud);

            Type type = model.GetType();
            MethodInfo info1 = type.GetMethod("setFunctionDefinitionToDictionary", BindingFlags.NonPublic | BindingFlags.Instance);
            info1.Invoke(model, new object[] { });

            // getNewUnitValue
            MethodInfo info2 = type.GetMethod("getNewUnitValue", BindingFlags.NonPublic | BindingFlags.Instance);
            UnitStruct unit = new UnitStruct("Kind", 2, 1, 0.5, 3);
            double value = (double)info2.Invoke(model, new object[] { unit });
            Assert.AreEqual(28.0d, value, "getNewUnitValue returns unexpected value.");

            // convertUnit
            model.Level = 2;
            value = model.convertUnit("test", 0.1d);
            Assert.AreEqual(0.1d, value, "convertUnit returns unexpected value.");

            value = model.convertUnit("substance", 1.0d);
            Assert.AreEqual(1.0d, value, "convertUnit returns unexpected value.");

            model.Level = 1;
            value = model.convertUnit("test", 0.1d);
            Assert.AreEqual(0.1d, value, "convertUnit returns unexpected value.");

            value = model.convertUnit("minute", 1.0d);
            Assert.AreEqual(60.0d, value, "convertUnit returns unexpected value.");

            try
            {
                model.Level = 0;
                model.convertUnit("test", 0.1d);
            }
            catch (Exception)
            {
            }

            // getPath
            string path;
            try
            {
                path = model.getPath("");
            }
            catch (Exception)
            {
            }
            path = model.getPath("default");
            Assert.AreEqual("/", path, "getPath returns unexpected value.");
        }