Esempio n. 1
0
 /// <summary>
 /// Get the compartment ID.
 /// </summary>
 /// <param name="aCompartment">the compartment object.</param>
 /// <returns>the comaprtment ID.</returns>
 public string getCompartmentID(CompartmentStruct aCompartment)
 {
     string aSystemID;
     if ( aCompartment.Outside == "" )
     {
         if ( this.Model.Level == 1 )
             aSystemID = "/:" + aCompartment.Name;
         else if ( this.Model.Level == 2 )
             aSystemID = "/:" + aCompartment.ID;
         else
             throw new EcellException("Compartment Class needs a ['ID']");
     }
     else
     {
         if( this.Model.Level == 1 )
             aSystemID = this.Model.getPath(aCompartment.Outside) + ":" + aCompartment.Name;
         else if (this.Model.Level == 2)
             aSystemID = this.Model.getPath(aCompartment.Outside) + ":" + aCompartment.ID;
         else
             throw new EcellException("Compartment Class needs a ['ID']");
     }
     return "System:" + aSystemID;
 }
Esempio n. 2
0
        private void setSizeToDictionary(CompartmentStruct aCompartment)
        {
            string aCompartmentID;
            if (this.Model.Level == 1)
                aCompartmentID = aCompartment.Name;
            else if (this.Model.Level == 2)
                aCompartmentID = aCompartment.ID;
            else
                throw new EcellException();

            if (!aCompartment.Volume.Equals(double.NaN))
                this.Model.CompartmentSize[aCompartmentID] = aCompartment.Volume;
            else
                this.Model.CompartmentSize[aCompartmentID] = this.getOutsideSize(aCompartment.Outside);
        }
Esempio n. 3
0
        private void setUnitToDictionary(CompartmentStruct aCompartment)
        {
            string aCompartmentID;
            if( this.Model.Level == 1 )
                aCompartmentID = aCompartment.Name;
            else if( this.Model.Level == 2 )
                aCompartmentID = aCompartment.ID;
            else
                throw new EcellException();

            if( aCompartment.Unit != "" )
                this.Model.CompartmentUnit[ aCompartmentID ] = aCompartment.Unit;
            else
                this.Model.CompartmentUnit[ aCompartmentID ] = this.getOutsideUnit( aCompartment.Outside );
        }
Esempio n. 4
0
 /// <summary>
 /// Get the compartment unit.
 /// </summary>
 /// <param name="aCompartment">the compartment object.</param>
 /// <returns>the compartment unit.</returns>
 public string getCompartmentUnit(CompartmentStruct aCompartment)
 {
     if ( this.Model.Level == 1 )
         return this.Model.CompartmentUnit[ aCompartment.Name ];
     else if (this.Model.Level == 2)
         return this.Model.CompartmentUnit[ aCompartment.ID ];
     else
         throw new EcellException();
 }
Esempio n. 5
0
 /// <summary>
 /// Get the compartment size.
 /// </summary>
 /// <param name="aCompartment">the compartment object.</param>
 /// <returns>the compartment size.</returns>
 public double getCompartmentSize(CompartmentStruct aCompartment)
 {
     if (this.Model.Level == 1)
         return this.Model.CompartmentSize[aCompartment.Name];
     else if (this.Model.Level == 2)
         return this.Model.CompartmentSize[aCompartment.ID];
     else
         throw new EcellException();
 }
Esempio n. 6
0
        /// <summary>
        /// [ CompartmentStruct ]
        /// [[ Id , Name , SpatialDimension , Size , Volume , Unit , Ouside , Constant ]]
        /// </summary>
        /// <param name="aSBMLmodel"></param>
        /// <returns></returns>
        public static List<CompartmentStruct> getCompartment(Model aSBMLmodel)
        {
            List<CompartmentStruct> list = new List<CompartmentStruct>();
            ListOfCompartments compartments = aSBMLmodel.getListOfCompartments();
            for (int i = 0; i < compartments.size(); i++ )
            {
                Compartment item = aSBMLmodel.getCompartment(i);
                string anId = item.getId();
                string aName = item.getName();
                long aSpatialDimension = item.getSpatialDimensions();
                double aSize = GetCompartmentSize(item);
                double aVolume = GetCompartmentVolume(item);

                string anUnit = item.getUnits();
                string anOutside = item.getOutside();
                bool aConstant = item.getConstant();

                CompartmentStruct compartment = new CompartmentStruct(
                    anId,
                    aName,
                    aSpatialDimension,
                    aSize,
                    aVolume,
                    anUnit,
                    anOutside,
                    aConstant);

                list.Add(compartment);
            }
            return list;
        }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
        public void TestSBML_Compartment()
        {
            SBMLReader reader = new SBMLReader();
            SBMLDocument document = reader.readSBML(TestConstant.SBML_Oscillation);

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

            CompartmentStruct cs = new CompartmentStruct();
            try
            {
                c.getCompartmentID(cs);
            }
            catch (Exception)
            {
            }
            string id;

            cs.Outside = "";
            cs.ID = "Test1";
            id = c.getCompartmentID(cs);
            Assert.AreEqual("System:/:Test1", id, "getCompartmentID returns unexpected value.");

            try
            {
                model.Level = 1;
                id = c.getCompartmentID(cs);
            }
            catch (Exception)
            {
            }

            try
            {
                model.Level = 0;
                id = c.getCompartmentID(cs);
            }
            catch (Exception)
            {
            }

            model.Level = 2;
            cs.Outside = "cell";
            id = c.getCompartmentID(cs);
            Assert.AreEqual("System:/cell:Test1", id, "getCompartmentID returns unexpected value.");

            try
            {
                model.Level = 1;
                id = c.getCompartmentID(cs);
            }
            catch (Exception)
            {
            }

            try
            {
                model.Level = 0;
                id = c.getCompartmentID(cs);
            }
            catch (Exception)
            {
            }

            // GetModuleType
            Type type = c.GetType();
            MethodInfo info1 = type.GetMethod("setSizeToDictionary", BindingFlags.NonPublic | BindingFlags.Instance);
            MethodInfo info2 = type.GetMethod("setUnitToDictionary", BindingFlags.NonPublic | BindingFlags.Instance);
            try
            {
                info1.Invoke(c, new object[] { cs });
            }
            catch (Exception)
            {
            }
            try
            {
                info2.Invoke(c, new object[] { cs });
            }
            catch (Exception)
            {
            }
            model.Level = 1;
            cs.Volume = double.NaN;
            cs.Name = "Test1";
            info1.Invoke(c, new object[] { cs });
            info2.Invoke(c, new object[] { cs });

            // getOutsideSize
            model.Level = 2;
            MethodInfo info3 = type.GetMethod("getOutsideSize", BindingFlags.NonPublic | BindingFlags.Instance);
            double size;
            size = (double)info3.Invoke(c, new object[] { "" });
            Assert.AreEqual(1.0d, size, "getOutsideSize returns unexpected value.");

            size = (double)info3.Invoke(c, new object[] { "cell" });
            Assert.AreEqual(1.0d, size, "getOutsideSize returns unexpected value.");

            // getOutsideUnit
            MethodInfo info4 = type.GetMethod("getOutsideUnit", BindingFlags.NonPublic | BindingFlags.Instance);
            string unit;
            unit = (string)info4.Invoke(c, new object[] { "" });
            Assert.AreEqual("", unit, "getCompartmentSize returns unexpected value.");

            unit = (string)info4.Invoke(c, new object[] { "cell" });
            Assert.AreEqual("", unit, "getCompartmentSize returns unexpected value.");

            // getCompartmentSize
            size = c.getCompartmentSize(cs);
            Assert.AreEqual(1.0d, size, "getCompartmentSize returns unexpected value.");

            model.Level = 1;
            size = c.getCompartmentSize(cs);
            Assert.AreEqual(1.0d, size, "getCompartmentSize returns unexpected value.");

            try
            {
                model.Level = 0;
                size = c.getCompartmentSize(cs);
            }
            catch (Exception)
            {
            }

            // getCompartmentUnit
            model.Level = 2;
            id = c.getCompartmentUnit(cs);
            Assert.AreEqual(null, id, "getCompartmentUnit returns unexpected value.");

            model.Level = 1;
            id = c.getCompartmentUnit(cs);
            Assert.AreEqual(null, id, "getCompartmentUnit returns unexpected value.");

            try
            {
                model.Level = 0;
                id = c.getCompartmentUnit(cs);
            }
            catch (Exception)
            {
            }
        }