Example #1
0
        public void loadAndParseTestv1L1()
        {
            // http://www.genome.ad.jp/dbget-bin/get_pathway?org_name=ecc&mapno=00020
            // Citrate Cycle for E. Coli CFT073
            MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.xml");

            // Assert name is equal
            Assert.AreEqual("Smallest_chemical_reaction_system_with_Hopf_bifurcation", s.model.ID);

            MuCell.Model.SBML.Reaction[] rs = s.model.listOfReactions.ToArray();
            Assert.AreEqual(5, rs.Length);

            System.Console.Write(rs[1].KineticLaw.math);

            MuCell.Model.SBML.Reaction[] reactions = s.model.listOfReactions.ToArray();

            // Check there are 3 kinetic laws
            Assert.AreEqual(5, reactions.Length);

            // Assert the correctness of serializes a kinetic law into a string
            Assert.AreEqual("k_1*X*A", reactions[0].KineticLaw.math.ToString());
            Assert.AreEqual("k_2*X*Y", reactions[1].KineticLaw.math.ToString());
            Assert.AreEqual("k_3*X", reactions[2].KineticLaw.math.ToString());
            Assert.AreEqual("k_4*Z", reactions[3].KineticLaw.math.ToString());
            Assert.AreEqual("k_5*Y", reactions[4].KineticLaw.math.ToString());
        }
Example #2
0
        public void simpleTest()
        {
            MuCell.Model.SBML.Reader.SBMLReader reader = new MuCell.Model.SBML.Reader.SBMLReader();
            FormulaParser fp = new FormulaParser(reader, "3.4+4/(abs(2-4))");
            MathTree formulaTree = fp.getFormulaTree();

            MuCell.Model.SBML.InnerNode root = (InnerNode)formulaTree.root;

            Assert.AreEqual(BinaryMathOperators.Plus, root.data);

            /// Assert that the left node is 3.4
            Assert.AreEqual(3.4, ((NumberLeafNode)(root.subtree.ToArray())[0]).data);

            // Assert that the right is divide

            MuCell.Model.SBML.InnerNode right = (InnerNode)(root.subtree.ToArray())[1];
            Assert.AreEqual(BinaryMathOperators.Divide, right.data);

            // Assert that the right's child is 4 and abs
            Assert.AreEqual(4, ((NumberLeafNode)right.subtree[0]).data);
            Assert.AreEqual(UnaryMathOperators.Abs, ((InnerNode)right.subtree[1]).data);
            // assert that this is a minus

            InnerNode minus_child = (InnerNode)((InnerNode)(right.subtree[1])).subtree[0];
            Assert.AreEqual(BinaryMathOperators.Minus, minus_child.data);

            Assert.AreEqual(2, ((NumberLeafNode)minus_child.subtree[0]).data);
            Assert.AreEqual(4, ((NumberLeafNode)minus_child.subtree[1]).data);

            // Finally evaluate and check the result

            // Fold the tree into a cell function
            CellEvaluationFunction fun = formulaTree.ToCellEvaluationFunction();
            Assert.AreEqual(5.4, fun(new StateSnapshot(), new CellInstance(new CellDefinition())));
        }
 public double evaluate(string formula, MuCell.Model.Experiment experiment, MuCell.Model.Simulation simulation)
 {
     MuCell.Model.SBML.Reader.SBMLReader reader = new MuCell.Model.SBML.Reader.SBMLReader();
     FormulaParser fp = new FormulaParser(reader, formula, this.models, experiment, simulation);
     MathTree formulaTree = fp.getFormulaTree();
     MuCell.Model.AggregateEvaluationFunction fun1 = formulaTree.ToAggregateEvaluationFunction();
     return fun1(simulation.GetCurrentState());
 }
Example #4
0
        public void ExtraCellularComponents()
        {
            MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.serialized.xml");
            MuCell.Model.SBML.Model model = s.model;

            // Fill in dummy data adding extracellular component data to model!
            //
            model.listOfComponents = new List<MuCell.Model.SBML.ExtracellularComponents.ComponentBase>();
            MuCell.Model.SBML.ExtracellularComponents.ComponentBase cb = new MuCell.Model.SBML.ExtracellularComponents.ComponentBase();
            model.listOfComponents.Add(cb);

            model.saveToXml("../../UnitTests/extracellularcomponents.serialized.xml");
        }
Example #5
0
        public void InvalidTimeSeriesEquation()
        {
            // simulation
            MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1");

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

            // Hopf model
            MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.level2.xml");
            List<MuCell.Model.SBML.Model> models = new List<MuCell.Model.SBML.Model>();
            models.Add(s.model);

            // Cell definition
            MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("celldef1");
            celldef1.addSBMLModel(s.model);

            experiment.addCellDefinition(celldef1);

            // Cells
            List<MuCell.Model.CellInstance> cells = new List<MuCell.Model.CellInstance>();

            for(int i=0;i<5;i++)
            {
                cells.Add(celldef1.createCell());
            }

            // StateSnapshot for intial state
            MuCell.Model.StateSnapshot initialState = new MuCell.Model.StateSnapshot(cells);
            MuCell.Model.Vector3 size = new MuCell.Model.Vector3(1, 1, 1);
            initialState.SimulationEnvironment = new MuCell.Model.Environment(size);

            // Parameters
            simulation.Parameters.InitialState = initialState;
            simulation.Parameters.SimulationLength = 3;
            simulation.Parameters.SnapshotInterval = 1;
            simulation.Parameters.StepTime = 1;

            // Time series
            MuCell.Model.TimeSeries ts1 = new MuCell.Model.TimeSeries("Average A", "(A)", 1.0);
            ts1.Initialize(models, experiment, simulation);
        }
Example #6
0
        public void SerializeEcc00020()
        {
            MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/ecc00020.xml");

            MuCell.Model.SBML.Model model = s.model;

            model.saveToXml("../../UnitTests/ecc00020.serialized.xml");

            // Load the serialized code
            MuCell.Model.SBML.Reader.SBMLReader sbmlSerialized = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/ecc00020.serialized.xml");
            // Assert its SBML object hierarchy is equal to the original
            s.model.SBMLEquals(sbmlSerialized.model);
        }
Example #7
0
        public void TestGenerateTimeSeries()
        {
            // simulation
            MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1");

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

            // Hopf model
            MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.level2.xml");
            List<MuCell.Model.SBML.Model> models = new List<MuCell.Model.SBML.Model>();
            models.Add(s.model);

            // Cell definition
            MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("celldef1");
            celldef1.addSBMLModel(s.model);

            experiment.addCellDefinition(celldef1);

            // Cells
            List<MuCell.Model.CellInstance> cells = new List<MuCell.Model.CellInstance>();

            for(int i=0;i<5;i++)
            {
                cells.Add(celldef1.createCell());
            }

            // StateSnapshot for intial state
            MuCell.Model.StateSnapshot initialState = new MuCell.Model.StateSnapshot(cells);
            MuCell.Model.Vector3 size = new MuCell.Model.Vector3(1, 1, 1);
            initialState.SimulationEnvironment = new MuCell.Model.Environment(size);

            // trime series
            MuCell.Model.TimeSeries ts1 = new MuCell.Model.TimeSeries("Average X", "X/celldef1", 0.01001d);
            ts1.Initialize(models, experiment, simulation);

            MuCell.Model.TimeSeries ts2 = new MuCell.Model.TimeSeries("Total X", "X", 0.01001d);
            ts2.Initialize(models, experiment, simulation);

            // Parameters
            MuCell.Model.SimulationParameters parameters = new MuCell.Model.SimulationParameters();

            parameters.TimeSeries.Add(ts1);
            parameters.TimeSeries.Add(ts2);

            parameters.InitialState = initialState;
            parameters.SimulationLength = 0.04004d;
            parameters.SnapshotInterval = 1;
            parameters.StepTime = 0.01001d;

            parameters.RelativeTolerance = 1E-8;
            parameters.SolverMethod = MuCell.Model.Solver.SolverMethods.RungeKutta;

            // Simulation
            simulation.Parameters = parameters;

            // Start simulation
            simulation.StartSimulation();

            // Now check the results

            Assert.AreEqual(5, ts1.Series.Count);
            Assert.AreEqual(5, ts2.Series.Count);

            double[] ts = ts1.Series.ToArray();
            double[] tst = ts2.Series.ToArray();

            Assert.AreEqual(2.5d, ts[0]);
            AssertDouble.AreEqual(rk_x_t1, ts[1]);
            AssertDouble.AreEqual(rk_x_t2, ts[2]);
            AssertDouble.AreEqual(rk_x_t3, ts[3]);
            AssertDouble.AreEqual(rk_x_t4, ts[4]);

            Assert.AreEqual(5*2.5d, tst[0]);
            AssertDouble.AreEqual(5*rk_x_t1, tst[1]);
            AssertDouble.AreEqual(5*rk_x_t2, tst[2]);
            AssertDouble.AreEqual(5*rk_x_t3, tst[3]);
            AssertDouble.AreEqual(5*rk_x_t4, tst[4]);
        }
Example #8
0
        public void testWithSpecies()
        {
            MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model();
            MuCell.Model.Experiment experiment = new MuCell.Model.Experiment("experimen1");
            MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1");
            setupExperiment(model, experiment, simulation);

            // Test parsing cell def references, group references etc.
            MuCell.Model.SBML.Reader.SBMLReader reader = new MuCell.Model.SBML.Reader.SBMLReader();
            FormulaParser fp = new FormulaParser(reader, "5.2+s2", model, experiment, simulation);
            MathTree formulaTree = fp.getFormulaTree();

            MuCell.Model.SBML.InnerNode root = (InnerNode)formulaTree.root;
            Assert.AreEqual(BinaryMathOperators.Plus, root.data);

            Assert.AreEqual(5.2, ((MuCell.Model.SBML.NumberLeafNode)(root.subtree.ToArray()[0])).data);

            Assert.AreEqual("5.2+s2", root.ToString());

            MuCell.Model.SBML.AggregateReferenceNode right = (MuCell.Model.SBML.AggregateReferenceNode)(root.subtree.ToArray()[1]);

            Assert.AreEqual("s2", right.ToString());

            Assert.AreEqual(null, right.CellDefinition);
            Assert.AreEqual(null, right.Group);
            Assert.AreEqual("s2", right.Species.ID);
        }
Example #9
0
        public void testWithVariables()
        {
            // create a formula
            MuCell.Model.SBML.Reader.SBMLReader reader = new MuCell.Model.SBML.Reader.SBMLReader();
            MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model();
            Species s = new Species("X");
            s.BoundaryCondition = false;
            model.AddId(s.ID, s); // else FormulaParser can't find what X is
            reader.model = model;

            FormulaParser fp = new FormulaParser(reader, "10+sin(X)", model);
            MathTree formulaTree = fp.getFormulaTree();

            // fold the function
            CellEvaluationFunction fun = formulaTree.ToCellEvaluationFunction();

            // create a new CellInstance with a variable X
            CellInstance cell = new CellInstance(new CellDefinition());
            cell.setSpeciesAmount("X", 2.3d);

            // evaluate and test that this gets the right result
            Assert.AreEqual(10+Math.Sin(2.3), fun(new StateSnapshot(), cell));
        }
Example #10
0
        public void testWithCellDefWithSpaces()
        {
            MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model();
            MuCell.Model.Experiment experiment = new MuCell.Model.Experiment("experimen1");
            MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1");
            setupExperiment(model, experiment, simulation);
            experiment.GetCellDefinition("celldef1").Name = "cell def1";

            Assert.That(experiment.ContainsCellDefinition("cell_def1"));

            // Test parsing cell def references, group references etc.
            MuCell.Model.SBML.Reader.SBMLReader reader = new MuCell.Model.SBML.Reader.SBMLReader();
            FormulaParser fp = new FormulaParser(reader, "cell_def1", model, experiment, simulation);
            MathTree formulaTree = fp.getFormulaTree();

            MuCell.Model.SBML.AggregateReferenceNode root = (MuCell.Model.SBML.AggregateReferenceNode)formulaTree.root;

            Assert.AreEqual("cell def1", root.ToString());

            Assert.AreEqual(experiment.getCellDefinitions()[0], root.CellDefinition);
            Assert.AreEqual(null, root.Group);
            Assert.AreEqual(null, root.Species);
        }
Example #11
0
        public void testWithGroup()
        {
            MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model();
            MuCell.Model.Experiment experiment = new MuCell.Model.Experiment("experimen1");
            MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1");
            setupExperiment(model, experiment, simulation);

            // Test parsing cell def references, group references etc.
            MuCell.Model.SBML.Reader.SBMLReader reader = new MuCell.Model.SBML.Reader.SBMLReader();
            FormulaParser fp = new FormulaParser(reader, "group1", model, experiment, simulation);
            MathTree formulaTree = fp.getFormulaTree();

            MuCell.Model.SBML.AggregateReferenceNode root = (MuCell.Model.SBML.AggregateReferenceNode)formulaTree.root;

            Assert.AreEqual("group1", root.ToString());

            Assert.AreEqual(null, root.CellDefinition);
            Assert.AreEqual("1", root.Group.ID);
            Assert.AreEqual(null, root.Species);
        }
Example #12
0
        public void testApproximateUnits()
        {
            MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model();
            MuCell.Model.Experiment experiment = new MuCell.Model.Experiment("experimen1");
            MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1");
            setupExperiment(model, experiment, simulation);

            // Test parsing cell def references, group references etc.
            MuCell.Model.SBML.Reader.SBMLReader reader = new MuCell.Model.SBML.Reader.SBMLReader();
            FormulaParser fp = new FormulaParser(reader, "5.2", model, experiment, simulation);
            MathTree formulaTree = fp.getFormulaTree();
            Assert.AreEqual("No units", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "5.2+10", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("No units", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "5.2-10", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("No units", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "5.2*10", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("No units", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "5.2/10", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("No units", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1+celldef2", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1-celldef1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1*celldef2", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells*Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1/celldef2", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells/Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1*celldef2*celldef1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells*Cells*Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1+10", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1*10", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1 / 34.2", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "4/celldef1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("1/Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "24/(celldef1*celldef1)", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("1/Cells*Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1.group1/(celldef1*celldef1)", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells/Cells*Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1/celldef1+10", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells/Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1.group1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1.group2 + celldef1.group1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1.group1/celldef1.group2", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells/Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "143/celldef1.group1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("1/Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s1*4", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s1*s2", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Concentration*Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s1*s2*celldef1.s1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Concentration*Concentration*Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s1*celldef1.group1.s1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Concentration*Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "group2.s2*celldef1.group1.s1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Concentration*Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s1/s2", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Concentration/Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "4.345/s1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("1/Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s1+celldef1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("No units", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "4.345/s1+celldef1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("No units", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1*celldef1.group1.s1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells*Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s2/celldef1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Concentration/Cells", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s2/celldef1+s1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("No units", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "s2/celldef1+celldef2", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("No units", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "celldef1/celldef1.group1.s1", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Cells/Concentration", formulaTree.ApproximateUnits());

            fp = new FormulaParser(reader, "Abs(s1)", model, experiment, simulation);
            formulaTree = fp.getFormulaTree();
            Assert.AreEqual("Concentration", formulaTree.ApproximateUnits());
        }
Example #13
0
        public void testIdentifiersLists()
        {
            MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.xml");
            MuCell.Model.SBML.Reader.SBMLReader reader = new MuCell.Model.SBML.Reader.SBMLReader();
            FormulaParser fp = new FormulaParser(reader, "X*A+k_1*B_A", s.model);
            MathTree formulaTree = fp.getFormulaTree();

            List<Species> formulaSpecies = fp.SpeciesFromFormula();
            Assert.AreEqual(2, formulaSpecies.Count);
            Assert.AreEqual("X", formulaSpecies.ToArray()[0].ID);
            Assert.AreEqual("A", formulaSpecies.ToArray()[1].ID);

            List<Parameter> parameters = fp.ParametersFromFormula();
            Assert.AreEqual(1, parameters.Count);
            Assert.AreEqual("k_1", parameters.ToArray()[0].ID);

            List<UnknownEntity> identifiers = fp.UnknownEntitiesFromFormula();
            Assert.AreEqual(1, identifiers.Count);
            Assert.AreEqual("B_A", identifiers.ToArray()[0].ID);
        }
Example #14
0
 public void TestHopfSimulationV1L2_RungeKutta()
 {
     // Hopf model
     MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.level2.xml");
     RunHopfSimulationRK(s);
 }
Example #15
0
 public void TestHopfParseAndReactionsL1V2()
 {
     // Hopf model
     MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.level2.xml");
     RunHopfParseAndReactions(s);
 }
Example #16
0
 /// <summary>
 /// Initalizes the time series function - must be called after setting the function string
 /// </summary>
 /// <param name="models">
 /// A <see cref="List`1"/>
 /// </param>
 /// <param name="experiment">
 /// A <see cref="Experiment"/>
 /// </param>
 /// <param name="simulation">
 /// A <see cref="Simulation"/>
 /// </param>
 public void InitializeTimeSeriesFunction(List<Model.SBML.Model> models, Experiment experiment, Simulation simulation)
 {
     if (this.functionString!=null)
         {
             // create a reader
             MuCell.Model.SBML.Reader.SBMLReader reader = new MuCell.Model.SBML.Reader.SBMLReader();
             // parse the formular
         SBML.FormulaParser fp = new SBML.FormulaParser(reader, this.functionString, models, experiment, simulation);
         // Get the formula tree
             SBML.MathTree formulaTree = fp.getFormulaTree();
             // Convert to a function
         this.function = formulaTree.ToAggregateEvaluationFunction();
             units = formulaTree.ApproximateUnits();
     }
 }
Example #17
0
        public void readXandYpositions()
        {
            MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/xy.serialized.xml");
            MuCell.Model.SBML.Model model = s.model;

            Assert.AreEqual(2, s.model.listOfSpecies[0].xPosition);
            Assert.AreEqual(3, s.model.listOfSpecies[0].yPosition);
            Assert.AreEqual(5, s.model.listOfSpecies[1].xPosition);
            Assert.AreEqual(6, s.model.listOfSpecies[1].yPosition);
        }
Example #18
0
        public void SerializeEmptyModelAndNotes()
        {
            // Load SBML
            MuCell.Model.SBML.Reader.SBMLReader sbml = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/data/test2.xml");
            // Assert that it serializes
            Assert.That(sbml.model.saveToXml("../../UnitTests/data/test2.Serialized.xml"));

            // Load the serialized code
            MuCell.Model.SBML.Reader.SBMLReader sbmlSerialized = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/data/test2.Serialized.xml");
            // Assert its SBML object hierarchy is equal to the original
            sbml.model.SBMLEquals(sbmlSerialized.model);
        }
Example #19
0
        public void SerializeModelWithCompartmentsAndSpeciesAndReaction()
        {
            // Load SBML
            MuCell.Model.SBML.Reader.SBMLReader sbml = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/data/test6.xml");
            // Assert that it serializes
            Assert.That(sbml.model.saveToXml("../../UnitTests/data/test6.Serialized.xml"));

            // Load the serialized code
            MuCell.Model.SBML.Reader.SBMLReader sbmlSerialized = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/data/test6.Serialized.xml");
            // Assert its SBML object hierarchy is equal to the original
            sbml.model.SBMLEquals(sbmlSerialized.model);
        }
Example #20
0
        public void SerializeHopfModelv1l2()
        {
            MuCell.Model.SBML.Reader.SBMLReader sbml = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.level2.xml");
            Assert.That(sbml.model.saveToXml("../../UnitTests/smallest.Hopf.level2.serialized.xml"));

            // Load the serialized code
            MuCell.Model.SBML.Reader.SBMLReader sbmlSerialized = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.level2.serialized.xml");
            // Assert its SBML object hierarchy is equal to the original
            sbml.model.SBMLEquals(sbmlSerialized.model);
        }
Example #21
0
        public void Setup(Experiment experiment, Simulation simulation, string speciesName)
        {
            // ********* INITIAL SETUP

            // Hopf model
            MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.xml");

            // Cell definition 1
            MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("celldef1");
            celldef1.addSBMLModel(s.model);

            // Create a NEW 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 = speciesName;
            species1.InitialAmount = 4.0d;

            // Set some values for species2
            species2.ID = "Y";
            species2.InitialAmount = 0.1d;

            model.AddId(speciesName, species1);
            model.AddId("Y", 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 = speciesName.Replace(' ', '_')+"*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 celldef2 = new MuCell.Model.CellDefinition("celldef2");
            celldef2.addSBMLModel(model);

            // instantiat the environment
            MuCell.Model.Vector3 size = new MuCell.Model.Vector3(1, 1, 1);
            MuCell.Model.Environment environment = new MuCell.Model.Environment(size);

            // Cells
            List<MuCell.Model.CellInstance> cells = new List<MuCell.Model.CellInstance>();

            // Create 10 cells of celldef1 and 20 cells of celldef2
            for(int i=0;i<10;i++){
                int a = ((i+2)%3)+1;
                int b = (i%3)+1;
                int c = ((i+1)%3)+1;
                CellInstance cell11 = celldef1.createCell();
                cells.Add(cell11);
                environment.AddCellToGroup(a, cell11);

                CellInstance cell21 = celldef2.createCell();
                CellInstance cell22 = celldef2.createCell();
                cells.Add(cell21);
                cells.Add(cell22);
                environment.AddCellToGroup(b, cell21);
                environment.AddCellToGroup(c, cell22);
            }

            // StateSnapshot for intial state
            MuCell.Model.StateSnapshot initialState = new MuCell.Model.StateSnapshot(cells);
            initialState.SimulationEnvironment = environment;

            // Parameters
            MuCell.Model.SimulationParameters parameters = new MuCell.Model.SimulationParameters();
            parameters.InitialState = initialState;
            parameters.SimulationLength = 0.01001d;
            parameters.SnapshotInterval = 1;
            parameters.StepTime = 0.01001d;

            parameters.SolverMethod = MuCell.Model.Solver.SolverMethods.RungeKutta;

            // Simulation
            simulation.Parameters = parameters;

            // Experiment
            experiment.addCellDefinition(celldef1);
            experiment.addCellDefinition(celldef2);
            experiment.addSimulation(simulation);

            // Start simulation
            simulation.StartSimulation();

            this.models = new List<MuCell.Model.SBML.Model>();
            this.models.Add(s.model);
            this.models.Add(model);
        }
Example #22
0
        public void readReactionXandYpositions()
        {
            MuCell.Model.SBML.Reader.SBMLReader s = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/smallest.Hopf.xml");

            s.model.listOfReactions[0].xPosition = 100.0f;
            s.model.listOfReactions[0].yPosition = 102.2f;
            s.model.listOfReactions[1].xPosition = 200.2f;
            s.model.listOfReactions[1].yPosition = 135.0f;
            s.model.listOfReactions[2].xPosition = 642.0f;
            s.model.listOfReactions[2].yPosition = 312.3f;
            s.model.listOfReactions[3].xPosition = 325.5f;
            s.model.listOfReactions[3].yPosition = 753.7f;
            s.model.listOfReactions[4].xPosition = 110.9f;
            s.model.listOfReactions[4].yPosition = 752.1f;

            s.model.saveToXml("../../UnitTests/xy.reactions.serialized.xml");
            MuCell.Model.SBML.Reader.SBMLReader r = new MuCell.Model.SBML.Reader.SBMLReader("../../UnitTests/xy.reactions.serialized.xml");

            Assert.AreEqual(100.0f, r.model.listOfReactions[0].xPosition);
            Assert.AreEqual(102.2f, r.model.listOfReactions[0].yPosition);
            Assert.AreEqual(200.2f, r.model.listOfReactions[1].xPosition);
            Assert.AreEqual(135.0f, r.model.listOfReactions[1].yPosition);
            Assert.AreEqual(642.0f, r.model.listOfReactions[2].xPosition);
            Assert.AreEqual(312.3f, r.model.listOfReactions[2].yPosition);
            Assert.AreEqual(325.5f, r.model.listOfReactions[3].xPosition);
            Assert.AreEqual(753.7f, r.model.listOfReactions[3].yPosition);
            Assert.AreEqual(110.9f, r.model.listOfReactions[4].xPosition);
            Assert.AreEqual(752.1f, r.model.listOfReactions[4].yPosition);
        }