public void TestWithParameters() { // Create a model MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model(); MuCell.Model.SBML.Species species1 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Species species2 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Parameter parameter = new MuCell.Model.SBML.Parameter(); parameter.ID = "k_1"; parameter.Value = 0.07d; model.listOfParameters = new List<MuCell.Model.SBML.Parameter>(); model.listOfParameters.Add(parameter); model.listOfSpecies = new List<MuCell.Model.SBML.Species>(); model.listOfSpecies.Add(species1); model.listOfSpecies.Add(species2); // Set some values for species1 species1.ID = "s1"; species1.InitialAmount = 1.0d; // Set some values for species2 species2.ID = "s2"; species2.InitialAmount = 12.0d; model.AddId("s1", species1); model.AddId("s2", species2); model.AddId("k_1", parameter); // Set up the reaction MuCell.Model.SBML.Reaction reaction1 = new MuCell.Model.SBML.Reaction("reaction1"); // Set up the kinetic law reaction1.KineticLaw = new MuCell.Model.SBML.KineticLaw(model); reaction1.KineticLaw.Formula = "s1*s2*k_1"; // set up the species reference for the reactants MuCell.Model.SBML.SpeciesReference ref1 = new MuCell.Model.SBML.SpeciesReference(species1, 1); // set up the species references for the products MuCell.Model.SBML.SpeciesReference ref2 = new MuCell.Model.SBML.SpeciesReference(species2, 3); // Add the references reaction1.Reactants.Add(ref1); reaction1.Products.Add(ref2); // set up the cell definition MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("cell1"); celldef1.addSBMLModel(model); // set up a cell MuCell.Model.CellInstance cell1 = celldef1.createCell(); cell1.localSpeciesDelta.Add("s1", 0.0d); cell1.localSpeciesDelta.Add("s2", 0.0d); cell1.localSpeciesVariables.Add("s1", 1.0d); cell1.localSpeciesVariables.Add("s2", 12.0d); // set up the statesnaphost MuCell.Model.StateSnapshot state1 = new MuCell.Model.StateSnapshot(); state1.Cells.Add(cell1); // get the eval function MuCell.Model.EffectReactionEvaluationFunction fun1 = reaction1.ToEffectReactionEvaluationFunction(); // Evaluate fun1(state1, cell1); cell1.setSpeciesAmount("s1", cell1.UnitTestGetSpeciesAmountsAndDeltas("s1")); cell1.setSpeciesAmount("s2", cell1.UnitTestGetSpeciesAmountsAndDeltas("s2")); cell1.UnitTestClearDeltas(); AssertDouble.AreEqual(1.0d-0.84d, cell1.getLocalSimulationSpeciesAmount("s1")); AssertDouble.AreEqual(12.0d+0.84d*3.0d, cell1.getLocalSimulationSpeciesAmount("s2")); System.Console.WriteLine("about to eval"); // Evaluate again fun1(state1, cell1); cell1.setSpeciesAmount("s1", cell1.UnitTestGetSpeciesAmountsAndDeltas("s1")); cell1.setSpeciesAmount("s2", cell1.UnitTestGetSpeciesAmountsAndDeltas("s2")); cell1.UnitTestClearDeltas(); AssertDouble.AreEqual(0.16d-0.162624d, cell1.getLocalSimulationSpeciesAmount("s1")); AssertDouble.AreEqual(14.52d+0.162624d*3.0d, cell1.getLocalSimulationSpeciesAmount("s2")); // Check the param is the same Assert.AreEqual(0.07m, parameter.Value); }
public void treeStructureTest() { MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model(); MuCell.Model.SBML.Reaction reaction1 = new MuCell.Model.SBML.Reaction(); model.listOfReactions = new List<MuCell.Model.SBML.Reaction>(); model.listOfReactions.Add(reaction1); MuCell.Model.SBML.KineticLaw kw1 = new MuCell.Model.SBML.KineticLaw(model); kw1.math = new MuCell.Model.SBML.MathTree(); kw1.math.root = new MuCell.Model.SBML.InnerNode(MuCell.Model.SBML.BinaryMathOperators.Times); reaction1.KineticLaw = kw1; model.AddId("reaction1", kw1); MuCell.Model.SBML.Reaction[] reactions = model.listOfReactions.ToArray(); Assert.AreEqual(1, reactions.Length); Assert.AreEqual(MuCell.Model.SBML.BinaryMathOperators.Times, ((MuCell.Model.SBML.InnerNode)(reactions[0].KineticLaw.math.root)).data); }
public void TestWithSpecies() { // Create a model MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model(); MuCell.Model.SBML.Species species1 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Species species2 = new MuCell.Model.SBML.Species(); model.listOfSpecies = new List<MuCell.Model.SBML.Species>(); model.listOfSpecies.Add(species1); model.listOfSpecies.Add(species2); // Set some values for species1 species1.ID = "s1"; species1.InitialAmount = 4.0d; // Set some values for species2 species2.ID = "s2"; species2.InitialAmount = 0.1d; model.AddId("s1", species1); model.AddId("s2", species2); // Set up the reaction MuCell.Model.SBML.Reaction reaction1 = new MuCell.Model.SBML.Reaction("reaction1"); model.listOfReactions = new List<MuCell.Model.SBML.Reaction>(); model.listOfReactions.Add(reaction1); // Set up the kinetic law reaction1.KineticLaw = new MuCell.Model.SBML.KineticLaw(model); reaction1.KineticLaw.Formula = "(s1)*2"; // set up the species reference for the reactants MuCell.Model.SBML.SpeciesReference ref1 = new MuCell.Model.SBML.SpeciesReference(species1, 1); // set up the species references for the products MuCell.Model.SBML.SpeciesReference ref2 = new MuCell.Model.SBML.SpeciesReference(species1, 0.75); MuCell.Model.SBML.SpeciesReference ref3 = new MuCell.Model.SBML.SpeciesReference(species2, 2); // Add the references reaction1.Reactants.Add(ref1); reaction1.Products.Add(ref2); reaction1.Products.Add(ref3); // set up the cell definition MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("cell1"); celldef1.addSBMLModel(model); // set up a cell MuCell.Model.CellInstance cell1 = celldef1.createCell(); cell1.localSpeciesDelta.Add("s1", 0.0d); cell1.localSpeciesDelta.Add("s2", 0.0d); cell1.localSpeciesVariables.Add("s1", 4.0d); cell1.localSpeciesVariables.Add("s2", 0.1d); // set up the statesnaphost MuCell.Model.StateSnapshot state1 = new MuCell.Model.StateSnapshot(); state1.Cells.Add(cell1); // get the eval function MuCell.Model.EffectReactionEvaluationFunction fun1 = reaction1.ToEffectReactionEvaluationFunction(); // Evaluate fun1(state1, cell1); cell1.setSpeciesAmount("s1", cell1.UnitTestGetSpeciesAmountsAndDeltas("s1")); cell1.setSpeciesAmount("s2", cell1.UnitTestGetSpeciesAmountsAndDeltas("s2")); cell1.UnitTestClearDeltas(); Assert.AreEqual(2.0d, cell1.getLocalSimulationSpeciesAmount("s1")); Assert.AreEqual(16.1d, cell1.getLocalSimulationSpeciesAmount("s2")); // Evaluate again fun1(state1, cell1); cell1.setSpeciesAmount("s1", cell1.UnitTestGetSpeciesAmountsAndDeltas("s1")); cell1.setSpeciesAmount("s2", cell1.UnitTestGetSpeciesAmountsAndDeltas("s2")); cell1.UnitTestClearDeltas(); Assert.AreEqual(1.0d, cell1.getLocalSimulationSpeciesAmount("s1")); Assert.AreEqual(24.1d, cell1.getLocalSimulationSpeciesAmount("s2")); }
public void testRenaming() { MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model(); MuCell.Model.SBML.Species species1 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Species species2 = new MuCell.Model.SBML.Species(); model.listOfSpecies = new List<MuCell.Model.SBML.Species>(); model.listOfSpecies.Add(species1); model.listOfSpecies.Add(species2); // Set some values for species1 species1.ID = "species1"; species1.InitialAmount = 4.0d; species1.InitialConcentration = 7.0d; species1.xPosition = 2.0f; // Set some values for species2 that has the same id and same values species2.ID = "species2"; species2.InitialAmount = 4.0d; species2.InitialConcentration = 7.0d; species2.xPosition = 2.0f; // Add to the model model.AddId(species1.ID, species1); model.AddId(species2.ID, species2); // Rename species1.ID = "new_species1"; // Check the id in the species object Assert.AreEqual("new_species1", species1.ID); Assert.AreEqual("species1", species1.getOldID()); model.updateID(species1); // Check the ids in the model Assert.IsTrue(model.idExists("new_species1")); Assert.IsTrue(model.idExists("species2")); Assert.IsFalse(model.idExists("species1")); }
public void testNonDataDuplicate() { MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model(); MuCell.Model.SBML.Species species1 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Species species2 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Species species3 = new MuCell.Model.SBML.Species(); model.listOfSpecies = new List<MuCell.Model.SBML.Species>(); model.listOfSpecies.Add(species1); model.listOfSpecies.Add(species2); model.listOfSpecies.Add(species3); // Set some values for species1 species1.ID = "species1"; species1.InitialAmount = 4.0d; species1.InitialConcentration = 7.0d; species1.xPosition = 2.0f; // Set some values for species2 that has the same id and same values species2.ID = "species1"; species2.InitialAmount = 4.0d; species2.InitialConcentration = 7.0d; species2.xPosition = 2.0f; // Set some values for species3 that has the same id but DIFFERENT values species3.ID = "species1"; // Difference species3.InitialAmount = 5.0d; species3.InitialConcentration = 7.0d; species3.xPosition = 2.0f; // Add to the model model.AddId(species1.ID, species1); model.AddId(species2.ID, species2); model.AddId(species3.ID, species3); try { model.processDuplicates(); } catch (MuCell.Model.SBML.DuplicateSBMLObjectIdException e) { // Assert that an exception has been thrown Assert.IsTrue(true); } }
public void testInterrogateModelForIDs() { MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model(); model.listOfReactions = new List<MuCell.Model.SBML.Reaction>(); model.listOfSpecies = new List<MuCell.Model.SBML.Species>(); MuCell.Model.SBML.Species species1 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Species species2 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Species species3 = new MuCell.Model.SBML.Species(); species1.ID = "species1"; species2.ID = "species2"; species3.ID = "species 3"; model.AddId("species1", species1); MuCell.Model.SBML.Reaction r1 = new MuCell.Model.SBML.Reaction(); MuCell.Model.SBML.SpeciesReference sp1r = new MuCell.Model.SBML.SpeciesReference(); sp1r.species = species1; MuCell.Model.SBML.SpeciesReference sp2r = new MuCell.Model.SBML.SpeciesReference(); sp2r.species = species2; MuCell.Model.SBML.SpeciesReference sp3r = new MuCell.Model.SBML.SpeciesReference(); sp3r.species = species3; r1.Reactants.Add(sp1r); r1.Reactants.Add(sp2r); r1.Products.Add(sp3r); MuCell.Model.SBML.KineticLaw kl = new MuCell.Model.SBML.KineticLaw(model); r1.KineticLaw = kl; MuCell.Model.SBML.Parameter k1 = new MuCell.Model.SBML.Parameter(); k1.ID = "k1"; r1.Parameters.Add(k1); r1.Formula = "species1*species_3*k1"; model.listOfSpecies.Add(species1); model.listOfReactions.Add(r1); // Assert the unknown entities Assert.AreEqual(2, r1.KineticLaw.UnknownEntitiesFromFormula().Count); Assert.AreEqual("species_3", r1.KineticLaw.UnknownEntitiesFromFormula().ToArray()[0].ID); Assert.AreEqual("k1", r1.KineticLaw.UnknownEntitiesFromFormula().ToArray()[1].ID); // Assert missing items in model Assert.IsTrue(model.idExists("species1")); Assert.IsFalse(model.idExists("species2")); Assert.IsFalse(model.idExists("species 3")); Assert.IsFalse(model.idExists("k1")); model.InterrogateModelForMissingIDs(); // redo formula r1.Formula = "species1*species_3*k1"; // assert no unknown entities Assert.AreEqual(0, r1.KineticLaw.UnknownEntitiesFromFormula().Count); // Assert everything is in the model Assert.IsTrue(model.idExists("species1")); Assert.IsTrue(model.idExists("species2")); Assert.IsTrue(model.idExists("species 3")); Assert.IsTrue(model.idExists("k1")); }
public void testDataDuplicate() { MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model(); MuCell.Model.SBML.Species species1 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Species species2 = new MuCell.Model.SBML.Species(); model.listOfSpecies = new List<MuCell.Model.SBML.Species>(); model.listOfSpecies.Add(species1); model.listOfSpecies.Add(species2); // Set some values for species1 species1.ID = "species1"; species1.InitialAmount = 4.0d; species1.InitialConcentration = 7.0d; species1.xPosition = 2.0f; // Set some values for species2 that has the same id and same values species2.ID = "species1"; species2.InitialAmount = 4.0d; species2.InitialConcentration = 7.0d; species2.xPosition = 2.0f; // Add to the model model.AddId(species1.ID, species1); model.AddId(species2.ID, species2); // Check that we have two species Assert.AreEqual(2, model.listOfSpecies.Count); // Should remove species2 model.processDuplicates(); // Check there is now only 1 species in the model Assert.AreEqual(1, model.listOfSpecies.Count); // Check that it is species1 Assert.AreEqual(species1, model.listOfSpecies.ToArray()[0]); }
public void serializeXandYPositions() { MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model(); MuCell.Model.SBML.Species species1 = new MuCell.Model.SBML.Species(); MuCell.Model.SBML.Species species2 = new MuCell.Model.SBML.Species(); model.listOfSpecies = new List<MuCell.Model.SBML.Species>(); model.listOfSpecies.Add(species1); model.listOfSpecies.Add(species2); // Set some values for species1 species1.ID = "species1"; species1.InitialAmount = 4.0; species1.InitialConcentration = 7.0; species1.xPosition = 2.0f; species1.yPosition = 3.0f; // Set some values for species2 species2.ID = "species2"; species2.InitialAmount = 1.0; species2.InitialConcentration = 3.0; species2.xPosition = 5.0f; species2.yPosition = 6.0f; // Add to the model model.AddId(species1.ID, species1); model.AddId(species2.ID, species2); model.saveToXml("../../UnitTests/xy.serialized.xml"); }