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 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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public void TestSerializationEquality()
        {
            String filename = "../../UnitTests/expt1.serialized.xml";

            MuCell.Model.Experiment experiment = new MuCell.Model.Experiment("experiment1");

            Simulation simulation1 = new Simulation("simulation1");
            Results results = new Results();

            MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model();
            CellDefinition cellDef1 = new CellDefinition("cellDef1");
            cellDef1.addSBMLModel(model);

            for (int i = 0; i < 5; i++)
            {
                StateSnapshot snapshot = new StateSnapshot();
                for (int j = 0; j < 10; j++)
                {
                    CellInstance cell = new CellInstance(cellDef1);
                    cell.GroupID = j;
                    cell.CellInstanceSpatialContext.Position = new Vector3(1*j, 1+i, 2+j);
                    cell.CellInstanceSpatialContext.Velocity = new Vector3(4*i, 5+j, 3+i);
                    cell.CellInstanceSpatialContext.Volume = new Vector3(10+j, 14*i, 15*i);
                    cell.CellInstanceSpatialContext.Orientation = new Vector3(2+i, 3*j, 4*j);

                    snapshot.Cells.Add(cell);
                }
                MuCell.Model.Environment environment = new MuCell.Model.Environment(new Vector3(10 * i, 14 * i, 15 * i));

                SerializableDictionary<int, MuCell.Model.SBML.Group> dict = new SerializableDictionary<int, MuCell.Model.SBML.Group>();

                // create new groups x3
                MuCell.Model.SBML.Group group1 = new MuCell.Model.SBML.Group(1);
                group1.Col = System.Drawing.Color.Beige;
                MuCell.Model.SBML.Group group2 = new MuCell.Model.SBML.Group(2);
                group2.Col = System.Drawing.Color.Brown;
                MuCell.Model.SBML.Group group3 = new MuCell.Model.SBML.Group(3);
                group3.Col = System.Drawing.Color.Green;
                dict.Add(1, group1); dict.Add(2, group2); dict.Add(3, group3);
                environment.Groups = dict;

                //SerializableDictionary<int, MuCell.Model.NutrientField> nutDict = new SerializableDictionary<int, MuCell.Model.NutrientField>();

                //// create new nutrients x2
                //MuCell.Model.NutrientField nut1 = new MuCell.Model.NutrientField(1);
                //MuCell.Model.NutrientField nut2 = new MuCell.Model.NutrientField(2);
                //nut2.Col = System.Drawing.Color.Fuchsia;
                //nutDict.Add(1,nut1); nutDict.Add(2,nut2);
                //environment.Nutrients = nutDict;

                snapshot.SimulationEnvironment = environment;

                results.StateSnapshots.Add(snapshot);
            }
            results.CurrentState = results.StateSnapshots[4];

            for (int i = 0; i < 3; i++)
            {
                TimeSeries timeSeries = new TimeSeries("Function" + i, 1.2 * i);

                for (int j = 0; j < 20; j++)
                {
                    timeSeries.Series.Add(0.43+i*j+0.031*j);
                }

                results.TimeSeries.Add(timeSeries);
            }
            results.FilePath = "some-file-path";

            simulation1.SimulationResults = results;

            SimulationParameters simulationParams1 = new SimulationParameters();
            simulationParams1.TimeSeries = results.TimeSeries;
            simulationParams1.InitialState = results.StateSnapshots[0];
            // add to simulation
            simulation1.Parameters = simulationParams1;
            // expt.addSimulation
            experiment.addSimulation(simulation1);

            XmlSerializer s = new XmlSerializer(typeof(MuCell.Model.Experiment));
            TextWriter w = new StreamWriter(filename);
            s.Serialize(w, experiment);
            w.Close();

            TextReader tr = new StreamReader(filename);
            Experiment deserializedExpt = (Experiment)s.Deserialize(tr);
            tr.Close();

            Assert.IsTrue(experiment.exptEquals(deserializedExpt));
        }
Exemple #5
0
        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"));
        }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
        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"));
        }
Exemple #8
0
        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]);
        }
Exemple #9
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");
        }