public void setSimulationParameters(MuCell.Model.SimulationParameters simulationParameters)
        {
            simParameters = simulationParameters;
            if (simParameters.StepTime > 0)
            {
                foreach (Model.TimeSeries ts in listOfTimeSeries.Items)
                {
                    decimal currentTimeInterval = (decimal)ts.Parameters.TimeInterval;
                    decimal currentSimStep = (decimal)simParameters.StepTime;
                    ts.Parameters.TimeInterval = (double)(Math.Ceiling(currentTimeInterval / currentSimStep) * currentSimStep);
                    if (ts == listOfTimeSeries.SelectedItem)
                    {
                        numericUpDown1.Value = Math.Ceiling(currentTimeInterval / currentSimStep);
                        setTimeIntervalHelperLabel(ts);
                    }
                }
            }
            else
            {
                foreach (Model.TimeSeries ts in listOfTimeSeries.Items)
                {

                }
            }
        }
示例#2
0
 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());
 }
示例#3
0
        public void RunHopfParseAndReactions(MuCell.Model.SBML.Reader.SBMLReader s)
        {
            Assert.AreEqual(5, s.model.listOfReactions.Count);

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

            // Reaction 1
            Assert.AreEqual(2, reactions[0].Reactants.Count);
            Assert.AreEqual(1, reactions[0].Reactants.ToArray()[0].Stoichiometry);
            Assert.AreEqual(1, reactions[0].Reactants.ToArray()[1].Stoichiometry);
            Assert.AreEqual("X", reactions[0].Reactants.ToArray()[0].SpeciesID);
            Assert.AreEqual("A", reactions[0].Reactants.ToArray()[1].SpeciesID);

            Assert.AreEqual(1, reactions[0].Products.Count);
            Assert.AreEqual(2, reactions[0].Products.ToArray()[0].Stoichiometry);
            Assert.AreEqual("X", reactions[0].Products.ToArray()[0].SpeciesID);

            // Reaction 2
            Assert.AreEqual(2, reactions[1].Reactants.Count);
            Assert.AreEqual(1, reactions[1].Reactants.ToArray()[0].Stoichiometry);
            Assert.AreEqual(1, reactions[1].Reactants.ToArray()[1].Stoichiometry);
            Assert.AreEqual("X", reactions[1].Reactants.ToArray()[0].SpeciesID);
            Assert.AreEqual("Y", reactions[1].Reactants.ToArray()[1].SpeciesID);

            Assert.AreEqual(2, reactions[1].Products.Count);
            Assert.AreEqual(1, reactions[1].Products.ToArray()[0].Stoichiometry);
            Assert.AreEqual(1, reactions[1].Products.ToArray()[1].Stoichiometry);
            Assert.AreEqual("A", reactions[1].Products.ToArray()[0].SpeciesID);
            Assert.AreEqual("Y", reactions[1].Products.ToArray()[1].SpeciesID);

            // Reaction 3
            Assert.AreEqual(1, reactions[2].Reactants.Count);
            Assert.AreEqual(1, reactions[2].Reactants.ToArray()[0].Stoichiometry);
            Assert.AreEqual("X", reactions[2].Reactants.ToArray()[0].SpeciesID);

            Assert.AreEqual(1, reactions[2].Products.Count);
            Assert.AreEqual(1, reactions[2].Products.ToArray()[0].Stoichiometry);
            Assert.AreEqual("Z", reactions[2].Products.ToArray()[0].SpeciesID);

            // Reaction 4
            Assert.AreEqual(1, reactions[3].Reactants.Count);
            Assert.AreEqual(1, reactions[3].Reactants.ToArray()[0].Stoichiometry);
            Assert.AreEqual("Z", reactions[3].Reactants.ToArray()[0].SpeciesID);

            Assert.AreEqual(1, reactions[3].Products.Count);
            Assert.AreEqual(1, reactions[3].Products.ToArray()[0].Stoichiometry);
            Assert.AreEqual("Y", reactions[3].Products.ToArray()[0].SpeciesID);

            // Reaction 5
            Assert.AreEqual(1, reactions[4].Reactants.Count);
            Assert.AreEqual(1, reactions[4].Reactants.ToArray()[0].Stoichiometry);
            Assert.AreEqual("Y", reactions[4].Reactants.ToArray()[0].SpeciesID);

            Assert.AreEqual(1, reactions[4].Products.Count);
            Assert.AreEqual(1, reactions[4].Products.ToArray()[0].Stoichiometry);
            Assert.AreEqual("_void_", reactions[4].Products.ToArray()[0].SpeciesID);
        }
示例#4
0
        public static void setupExperiment(MuCell.Model.SBML.Model model, MuCell.Model.Experiment experiment, MuCell.Model.Simulation simulation)
        {
            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 cell definition
            MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("celldef1");
            celldef1.addSBMLModel(model);

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

            MuCell.Model.CellInstance cell1 = celldef1.createCell();
            MuCell.Model.CellInstance cell2 = celldef2.createCell();

            List<MuCell.Model.CellInstance> cells = new List<CellInstance>();
            cells.Add(cell1);
            cells.Add(cell2);

            // 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);
            // Create two groups with one cell of each type in each
            initialState.SimulationEnvironment.AddCellToGroup(1, celldef1.createCell());
            initialState.SimulationEnvironment.AddCellToGroup(2, celldef2.createCell());

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

            // Simulation
            simulation.Parameters = parameters;

            // Experiment

            experiment.addCellDefinition(celldef1);
            experiment.addCellDefinition(celldef2);
            experiment.addSimulation(simulation);
        }
 /// <summary>
 /// Sets which nutrient is selected in the nutrient list box
 /// </summary>
 /// <param name="nutrient"></param>
 public void setSelectedNutrient(MuCell.Model.NutrientField nutrient)
 {
     if (nutrientFieldListBox.Items.Contains(nutrient))
     {
         nutrientFieldListBox.SelectedItem = nutrient;
     }
 }
 /// <summary>
 /// Sets which group is selected in the group list box.
 /// </summary>
 /// <param name="group"></param>
 public void setSelectedGroup(MuCell.Model.SBML.Group group)
 {
     if (groupListBox.Items.Contains(group))
     {
         groupListBox.SelectedItem = group;
     }
 }
示例#7
0
        public void RunHopfSimulationRK(MuCell.Model.SBML.Reader.SBMLReader s)
        {
            // Cell definition
            MuCell.Model.CellDefinition celldef1 = new MuCell.Model.CellDefinition("celldef1");
            celldef1.addSBMLModel(s.model);

            // Cells
            List<MuCell.Model.CellInstance> cells = new List<MuCell.Model.CellInstance>();
            MuCell.Model.CellInstance cell1 = celldef1.createCell();
            cells.Add(cell1);

            // 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
            MuCell.Model.SimulationParameters parameters = new MuCell.Model.SimulationParameters();
            parameters.InitialState = initialState;
            parameters.SimulationLength = 0.01001d;
            parameters.SnapshotInterval = 2;
            parameters.StepTime = 0.01001d;

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

            // Simulation
            MuCell.Model.Simulation simulation = new MuCell.Model.Simulation("simulation1");
            simulation.Parameters = parameters;

            // Assert that is not complete at all
            Assert.AreEqual(0.0d, simulation.SimulationProgress());

            // 	Test the initial conditions
            Assert.AreEqual(1.0d, cell1.getSpeciesAmount("A"));
            Assert.AreEqual(2.5d, cell1.getSpeciesAmount("X"));
            Assert.AreEqual(2.5d, cell1.getSpeciesAmount("Y"));
            Assert.AreEqual(2.5d, cell1.getSpeciesAmount("Z"));
            Assert.AreEqual(0.0d, cell1.getSpeciesAmount("_void_"));

            // Start simulation
            simulation.StartSimulation();

            // Assert that is complete
            Assert.AreEqual(1.0d, simulation.SimulationProgress());

            // 	Test the results (test generated from the Python model)
            AssertDouble.AreEqual(1.0d, cell1.getSpeciesAmount("A"));
            AssertDouble.AreEqual(rk_x_t1, cell1.getSpeciesAmount("X"));
            AssertDouble.AreEqual(rk_y_t1, cell1.getSpeciesAmount("Y"));
            AssertDouble.AreEqual(rk_z_t1, cell1.getSpeciesAmount("Z"));
            Assert.AreEqual(0.0d, cell1.getSpeciesAmount("_void_"));

            // Make the simulation run a bit longer
            parameters.SimulationLength = 0.02002;
            simulation.UnPauseSimulation();

            AssertDouble.AreEqual(1.0d, cell1.getSpeciesAmount("A"));
            AssertDouble.AreEqual(rk_x_t2, cell1.getSpeciesAmount("X"));
            AssertDouble.AreEqual(rk_y_t2, cell1.getSpeciesAmount("Y"));
            AssertDouble.AreEqual(rk_z_t2, cell1.getSpeciesAmount("Z"));
            Assert.AreEqual(0.0d, cell1.getSpeciesAmount("_void_"));

            // Make the simulation run a bit longer
            parameters.SimulationLength = 0.03003;
            simulation.UnPauseSimulation();

            AssertDouble.AreEqual(1.0d, cell1.getSpeciesAmount("A"));
            AssertDouble.AreEqual(rk_x_t3, cell1.getSpeciesAmount("X"));
            AssertDouble.AreEqual(rk_y_t3, cell1.getSpeciesAmount("Y"));
            AssertDouble.AreEqual(rk_z_t3, cell1.getSpeciesAmount("Z"));
            Assert.AreEqual(0.0d, cell1.getSpeciesAmount("_void_"));
        }
        protected override MacroCommand resolveGraph(GraphNode[] nodes, GraphLink[] links, MuCell.View.IDrawingInterface drawable)
        {
            Vector2 topLeft = drawable.getScreenTopLeftInWorldCoordinates();
            Vector2 bottomRight = drawable.getScreenBottomRightInWorldCoordinates();

            float screenWidth = bottomRight.x - topLeft.x;
            float screenHeight = bottomRight.y - topLeft.y;

            float G = 60f;
            float sideForce = 30f;
            running = true;
            long iterationCount = 0;
            long renderTime = 1000;// (long)(1000.0 * (10.0 / nodes.Length));
            while (running)
            {
                for (int l = 0; l < links.Length; l++)
                {
                    GraphLink link = links[l];
                    link.step();
                }
                //push all nodes away from each other
                for (int a = 0; a < nodes.Length-1; a++)
                {
                    GraphNode nodeA = nodes[a];
                    for (int b = a + 1; b < nodes.Length; b++)
                    {
                        GraphNode nodeB = nodes[b];

                        Vector2 aToB = nodeB.getComponent().getPosition() - nodeA.getComponent().getPosition();

                        float distSqrd = aToB.getSqrdLength();
                        if (distSqrd < 1)
                        {
                            distSqrd = 1;
                        }
                        aToB.normalise();
                        Vector2 force = (aToB*G*(nodeA.getMass() * nodeB.getMass())) / distSqrd;

                        nodeA.push(-force);
                        nodeB.push(force);
                    }
                }

                //push all nodes in from the sides
                for (int a = 0; a < nodes.Length; a++)
                {
                    GraphNode nodeA = nodes[a];
                    Vector2 pos=nodeA.getComponent().getPosition();
                    float leftDistance = pos.x - topLeft.x;
                    if (leftDistance < 1f)
                    {
                        leftDistance = 1f;
                    }
                    float topDistance = pos.y - topLeft.y;
                    if (topDistance < 1f)
                    {
                        topDistance = 1f;
                    }
                    float rightDistance =bottomRight.x-pos.x;
                    if (rightDistance < 1f)
                    {
                        rightDistance = 1f;
                    }
                    float bottomDistance = bottomRight.y-pos.y;
                    if (bottomDistance < 1f)
                    {
                        bottomDistance = 1f;
                    }

                    Vector2 force = new Vector2((sideForce / leftDistance) - (sideForce / rightDistance), (sideForce / topDistance) - (sideForce / bottomDistance));
                    nodeA.push(force);
                }

                for (int n = 0; n < nodes.Length; n++)
                {
                    GraphNode node = nodes[n];
                    node.step();
                }
                iterationCount++;
                if (iterationCount % renderTime == 0)
                {
                    drawable.redrawGraphPanel();
                }

                //Thread.Sleep(100);
            }
            drawable.redrawGraphPanel();

            MacroCommand rearrangeCommand = new MacroCommand();
            for (int n = 0; n < nodes.Length; n++)
            {
                GraphNode node = nodes[n];
                MoveComponentCommand moveCommand = new MoveComponentCommand(node.getComponent(), node.getStartPosition(), node.getComponent().getPosition());
                rearrangeCommand.addCommand(moveCommand);
            }

            return rearrangeCommand;
        }
示例#9
0
 public MuCell.Model.Vector2 getClosestPoint(MuCell.Model.Vector2 otherPosition)
 {
     return mousePos;
 }