/// <summary> /// /// </summary> /// <param name="aSpecies"></param> /// <returns></returns> public int getConstant(SpeciesStruct aSpecies) { if (this.Model.Level == 1) { if (aSpecies.BoundaryCondition) return 1; else return 0; } else if (this.Model.Level == 2) { if (aSpecies.Constant) return 1; else return 0; } else throw new EcellException("Version" + this.Model.Level + " ????"); }
/// <summary> /// /// </summary> /// <param name="aSpecies"></param> /// <returns></returns> public double getSpeciesValue(SpeciesStruct aSpecies) { if ( !aSpecies.InitialAmount.Equals(double.NaN)) { return aSpecies.InitialAmount; } else if (this.Model.Level == 2 && !aSpecies.InitialConcentration.Equals(double.NaN)) { double aSize = this.Model.CompartmentSize[ aSpecies.Compartment ]; return aSpecies.InitialConcentration * aSize; } else throw new EcellException(string.Format( "InitialAmount or InitialConcentration of Species {0} must be defined.", aSpecies.ID )); }
/// <summary> /// /// </summary> /// <param name="aSpecies"></param> /// <returns></returns> public string getSpeciesID(SpeciesStruct aSpecies) { string aCompartmentID = aSpecies.Compartment; if ( aCompartmentID == "" ) throw new EcellException("compartment property of Species must be defined"); string aSpeciesID; if ( this.Model.Level == 1 ) aSpeciesID = this.Model.getPath( aCompartmentID ) + ':' + aSpecies.Name; else if ( this.Model.Level == 2 ) aSpeciesID = this.Model.getPath( aCompartmentID ) + ':' + aSpecies.ID; else throw new EcellException("Version"+ this.Model.Level + " ????"); return aSpeciesID; }
/// <summary> /// [ SpeciesStruct ] /// [[ Id , Name , Compartment , InitialAmount , InitialConcentration , SubstanceUnit , SpatialSizeUnit , Unit , HasOnlySubstanceUnit , BoundaryCondition , Charge , Constant ]] /// </summary> /// <param name="aSBMLmodel"></param> /// <returns></returns> public static List<SpeciesStruct> getSpecies(Model aSBMLmodel) { List<SpeciesStruct> list = new List<SpeciesStruct>(); ListOfSpecies listOfSpecies = aSBMLmodel.getListOfSpecies(); for (int i = 0; i < listOfSpecies.size(); i++ ) { Species aSpecies = aSBMLmodel.getSpecies(i); string anId_Sp = aSpecies.getId(); string aName_Sp = aSpecies.getName(); string aCompartment_Sp = aSpecies.getCompartment(); double anInitialAmount_Sp = GetInitialAmount(aSpecies); double anInitialConcentration_Sp = GetInitialConcentration(aSpecies); string aSubstanceUnit_Sp = aSpecies.getSubstanceUnits(); string aSpatialSizeUnit_Sp = aSpecies.getSpatialSizeUnits(); string anUnit_Sp = aSpecies.getUnits(); bool aHasOnlySubstanceUnit_Sp = aSpecies.getHasOnlySubstanceUnits(); bool aBoundaryCondition_Sp = aSpecies.getBoundaryCondition(); int aCharge_Sp = aSpecies.getCharge(); bool aConstant_Sp = aSpecies.getConstant(); SpeciesStruct species = new SpeciesStruct( anId_Sp, aName_Sp, aCompartment_Sp, anInitialAmount_Sp, anInitialConcentration_Sp, aSubstanceUnit_Sp, aSpatialSizeUnit_Sp, anUnit_Sp, aHasOnlySubstanceUnit_Sp, aBoundaryCondition_Sp, aCharge_Sp, aConstant_Sp); list.Add( species ); } return list; }
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); }
public void TestSBML_Species() { SBMLReader reader = new SBMLReader(); SBMLDocument document = reader.readSBML(TestConstant.SBML_Oscillation); SBML_Model model = new SBML_Model(document.getModel()); SBML_Compartment sc = new SBML_Compartment(model); SBML_Species species = new SBML_Species(model); // getConstant SpeciesStruct ss = new SpeciesStruct(); int i = species.getConstant(ss); Assert.AreEqual(0, i, "getConstant returns unexpected value."); ss.Constant = true; i = species.getConstant(ss); Assert.AreEqual(1, i, "getConstant returns unexpected value."); model.Level = 1; i = species.getConstant(ss); Assert.AreEqual(0, i, "getConstant returns unexpected value."); ss.BoundaryCondition = true; i = species.getConstant(ss); Assert.AreEqual(1, i, "getConstant returns unexpected value."); try { model.Level = 0; i = species.getConstant(ss); } catch (Exception) { } // getSpeciesValue double d = species.getSpeciesValue(ss); Assert.AreEqual(0.0, d, "getSpeciesValue returns unexpected value."); model.Level = 2; ss.InitialAmount = double.NaN; ss.Compartment = "cell"; d = species.getSpeciesValue(ss); Assert.AreEqual(0.0, d, "getSpeciesValue returns unexpected value."); try { ss.InitialConcentration = double.NaN; d = species.getSpeciesValue(ss); } catch (Exception) { } // getSpeciesID ss.ID = "Test1"; string id = species.getSpeciesID(ss); Assert.AreEqual("/cell:Test1", id, "getSpeciesID returns unexpected value."); try { model.Level = 1; ss.Name = "Test2"; id = species.getSpeciesID(ss); } catch (Exception) { } try { model.Level = 0; id = species.getSpeciesID(ss); } catch (Exception) { } try { model.Level = 2; ss.Compartment = ""; id = species.getSpeciesID(ss); } catch (Exception) { } }
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."); }