Esempio n. 1
0
 /// <summary>
 /// Base constructor
 /// </summary>
 public Simulation()
 {
     // Seeds the random object
     this.randomObject = new Random(0);
     this.snapshotCache = new SnapshotCache(10);
     this.currentState = null;
 }
Esempio n. 2
0
 /// <summary>
 /// Base constructor
 /// </summary>
 public Simulation()
 {
     int seed = Math.Abs((int)(DateTime.Now.Ticks));
     System.Console.WriteLine("Seeding simulation random object - seed = "+seed.ToString());
     this.randomObject = new Random(seed);
     this.snapshotCache = new SnapshotCache(10);
     this.currentState = null;
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor for the Simulator
        /// </summary>
        /// <param name="name">
        /// A <see cref="String"/>
        /// </param>
        public Simulation(String name)
        {
            this.name = name;
            this.parameters = new SimulationParameters();
            this.SimulationResults = new Results();
            this.listener = null;

            // Seeds the random object
            this.randomObject = new Random(0);
            this.snapshotCache = new SnapshotCache(10);
            this.currentState = null;
        }
Esempio n. 5
0
        /// <summary>
        /// Clone method for StateSnapshots
        /// </summary>
        /// <returns>
        /// A <see cref="Object"/>
        /// </returns>
        public Object Clone()
        {
            StateSnapshot cloned = new StateSnapshot();
            // Clone the cell instances within
            foreach(CellInstance cell in this.cells)
            {
                cloned.cells.Add((CellInstance)cell.Clone());
            }
            // Clone the environment
            cloned.simulationEnvironment = (Environment)this.simulationEnvironment.Clone();

            return cloned;
        }
Esempio n. 6
0
        /// <summary>
        /// Constructor for the Simulator
        /// </summary>
        /// <param name="name">
        /// A <see cref="String"/>
        /// </param>
        public Simulation(String name)
        {
            this.name = name;
            this.parameters = new SimulationParameters();
            this.SimulationResults = new Results();
            this.listener = null;

            // Seeds the random object based on the time
            int seed = Math.Abs((int)(DateTime.Now.Ticks));
            System.Console.WriteLine("Seeding simulation random object - seed = "+seed.ToString());
            this.randomObject = new Random(seed);
            this.snapshotCache = new SnapshotCache(10);
            this.currentState = null;
        }
Esempio n. 7
0
 public SnapshotCache(int maxCacheSize)
 {
     this.maxCacheSize = maxCacheSize;
     renderingFrame = null;
     buffer = new Queue<StateSnapshot>();
 }
Esempio n. 8
0
        /// <summary>
        /// Private method for performing the spatial simulation.
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="currentState"></param>
        /// <param name="time"></param>
        /// <param name="StepTime"></param>
        private void SpatialSimulator(CellInstance cell, StateSnapshot currentState, double time, double StepTime)
        {
            Vector3 p = cell.CellInstanceSpatialContext.Position;
            Vector3 v = cell.CellInstanceSpatialContext.Velocity;
            Vector3 ang = cell.CellInstanceSpatialContext.Orientation;
            float visc = currentState.SimulationEnvironment.Viscosity;
            float h = (float)StepTime;

            //viscous drag (Stokes's drag)
            v.x += -visc * h * v.x * 1.5f;
            v.y += -visc * h * v.y * 1.5f;
            v.z += -visc * h * v.z * 1.5f;

            //cell collisions
            if (currentState.SimulationEnvironment.EnableCellCollisions)
            {
                foreach (CellInstance cellB in currentState.Cells)
                {
                    if (cell != cellB) //avoid collision with self
                    {
                        //the vector from the centre of this cell to cellB
                        Vector3 dist = new Vector3(p.x - cellB.CellInstanceSpatialContext.Position.x,
                                                   p.y - cellB.CellInstanceSpatialContext.Position.y,
                                                   p.z - cellB.CellInstanceSpatialContext.Position.z);
                        float distMag = dist.magnitude();

                        if (distMag < cell.CellInstanceSpatialContext.Radius*0.001 + cellB.CellInstanceSpatialContext.Radius*0.001)
                        {
                            /*
                             * Collision occured: accelerate this cell away from the centre of the cell it is colliding with:
                             */

                            dist.unitVect(); //normalize
                            dist.x *= -h*0.1f;
                            dist.y *= -h*0.1f;
                            dist.z *= -h*0.1f;

                            //accelerate this cell and the one it collided with in oppose directions:
                            v.x -= dist.x;
                            v.y -= dist.y;
                            v.z -= dist.z;
                            cellB.CellInstanceSpatialContext.Accelerate(dist);

                        }

                    }
                }

            }

            //positional change
            p.x += v.x * h;
            p.y += v.y * h;
            p.z += v.z * h;

            //check that boundary conditions are maintained (most of the time this will be true, and will be the only test needed)
            if (!currentState.SimulationEnvironment.Boundary.InsideBoundary(p))
            {
                /*
                 * If the cell is not inside the environment boundary, we move it back
                 * and attempt to move the cell by individual components (this allows
                 * the cell to "slide" along the edges of the boundary without
                 * breaking the boundary conditions). In most cases these three boundary
                 * checks should not be necessary
                 */

                //begin by checking x component, so move back y and z components
                p.y -= v.y * h;
                p.z -= v.z * h;
                if (!currentState.SimulationEnvironment.Boundary.InsideBoundary(p))
                {
                    //x failed, so move back x
                    p.x -= v.x * h;
                }

                //check y component
                p.y += v.y * h;
                if (!currentState.SimulationEnvironment.Boundary.InsideBoundary(p))
                {
                    //y failed
                    p.y -= v.y * h;
                }

                //check z component
                p.z += v.z * h;
                if (!currentState.SimulationEnvironment.Boundary.InsideBoundary(p))
                {
                    //z failed
                    p.z -= v.z * h;
                }

            }

            cell.CellInstanceSpatialContext.Position = p;
            cell.CellInstanceSpatialContext.Velocity = v;
            cell.CellInstanceSpatialContext.Orientation = ang;
        }
Esempio n. 9
0
 /// <summary>
 /// Start the simulation running
 /// </summary>                        
 public void StartSimulation()
 {
     this.runningStatus = true;
     // Clone the initial state into the current state
     this.currentState = (StateSnapshot)this.parameters.InitialState.Clone();
     //this.currentState = this.parameters.InitialState;
     // init cell models
     this.InitializeCells();
     this.StartMainSimulationLoop(0);
 }
Esempio n. 10
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));
        }
Esempio n. 11
0
 /// <summary>
 /// Resets the concentrations in the cells to their initial values
 /// </summary>
 public void ResetCellConcentrations(StateSnapshot initialState)
 {
     foreach (Species s in this.species)
     {
         this.speciesVariables[s.ID] = s.initialValue;
     }
 }
Esempio n. 12
0
 public bool exptEquals(StateSnapshot other)
 {
     if (this.SimulationEnvironment.exptEquals(other.SimulationEnvironment) == false)
     {
         Console.Write("StateSnapshot objects not equal: ");
         Console.Write("this.SimulationEnvironment.volume=" + this.SimulationEnvironment.volume);
         Console.WriteLine("; other.SimulationEnvironment.volume=" + other.SimulationEnvironment.volume);
         return false;
     }
     // check CellInstances
     try
     {
         for (int i = 0; i < this.Cells.Count; i++)
         {
             if (this.Cells[i].exptEquals(other.Cells[i]) == false)
             {
                 Console.Write("StateSnapshot objects not equal: ");
                 Console.WriteLine("this.Cells[" + i + "] != other.Cells[" + i + "]");
                 return false;
             }
         }
     }
     catch (Exception e)
     {
         // Array out of bounds; lists are unequal
         Console.Write("SimulationParameters objects not equal: ");
         Console.WriteLine("List lengths differed");
         return false;
     }
     return true;
 }
Esempio n. 13
0
 public StateSnapshot getStateToRender()
 {
     lock (buffer)
     {
         //to prevent buffer underrun
         if (buffer.Count > 0)
         {
             renderingFrame = buffer.Dequeue();
         }
         return renderingFrame;
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Private method for performing the spatial simulation.
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="currentState"></param>
        /// <param name="time"></param>
        /// <param name="StepTime"></param>
        private void SpatialSimulator(CellInstance cell, StateSnapshot currentState, double time, double StepTime)
        {
            Vector3 p = cell.CellInstanceSpatialContext.Position;
            Vector3 v = cell.CellInstanceSpatialContext.Velocity;
            Vector3 ang = cell.CellInstanceSpatialContext.Orientation;
            float visc = currentState.SimulationEnvironment.Viscosity;
            float h = (float)StepTime;

            //viscous drag (Stokes's drag)
            v.x += -visc * h * v.x * 1.5f;
            v.y += -visc * h * v.y * 1.5f;
            v.z += -visc * h * v.z * 1.5f;

            //positional change
            p.x += v.x * h;
            p.y += v.y * h;
            p.z += v.z * h;

            //check that boundary conditions are maintained (most of the time this will be true, and will be the only test needed)
            if (!currentState.SimulationEnvironment.Boundary.InsideBoundary(p))
            {
                /*
                 * If the cell is not inside the environment boundary, we move it back
                 * and attempt to move the cell by individual components (this allows
                 * the cell to "slide" along the edges of the boundary without
                 * breaking the boundary conditions). In most cases these three boundary
                 * checks should not be necessary
                 */

                //begin by checking x component, so move back y and z components
                p.y -= v.y * h;
                p.z -= v.z * h;
                if (!currentState.SimulationEnvironment.Boundary.InsideBoundary(p))
                {
                    //x failed, so move back x
                    p.x -= v.x * h;
                }

                //check y component
                p.y += v.y * h;
                if (!currentState.SimulationEnvironment.Boundary.InsideBoundary(p))
                {
                    //y failed
                    p.y -= v.y * h;
                }

                //check z component
                p.z += v.z * h;
                if (!currentState.SimulationEnvironment.Boundary.InsideBoundary(p))
                {
                    //z failed
                    p.z -= v.z * h;
                }

            }

            cell.CellInstanceSpatialContext.Position = p;
            cell.CellInstanceSpatialContext.Velocity = v;
            cell.CellInstanceSpatialContext.Orientation = ang;
        }
Esempio n. 15
0
 /// <summary>
 /// Applies the function to a state
 /// </summary>
 /// <param name="state">
 /// A <see cref="StateSnapshot"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.double"/>
 /// </returns>
 public double evaluateNext(StateSnapshot state)
 {
     if (this.function != null)
     {
         return this.function(state);
     }
     else
     {
         return 0.0d;
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Draws a nutrient field cross section
        /// </summary>
        /// <param name="simState"></param>
        /// <param name="res"></param>
        private void DrawNutrientField(StateSnapshot simState, float res)
        {
            if (simState != null)
            {

                foreach (int nutrientIndex in simState.SimulationEnvironment.GetNutrients())
                {
                    NutrientField nutrient = simState.SimulationEnvironment.GetNutrientFieldObject(nutrientIndex);
                    float r, g, b;

                    if (!nutrient.FieldLoaded)
                    {
                        continue;
                    }

                    r = (float)nutrient.Col.R / 256;
                    g = (float)nutrient.Col.G / 256;
                    b = (float)nutrient.Col.B / 256;

                    Vector3 pos = new Vector3(0, 0, 0); ;

                    // PanelViewState.CrossSection.Depth

                    float imin = PanelViewState.CrossSectionOffset.x - PanelViewState.CrossSection.Width / 2;
                    float jmin = PanelViewState.CrossSectionOffset.y - PanelViewState.CrossSection.Height / 2;
                    float kmin = PanelViewState.CrossSectionOffset.z - PanelViewState.CrossSection.Depth / 2;

                    float imax = imin + PanelViewState.CrossSection.Width;
                    float jmax = jmin + PanelViewState.CrossSection.Height;
                    float kmax = kmin + PanelViewState.CrossSection.Depth;

                    //vertical cross section
                    if (PanelViewState.CrossSection.Height < PanelViewState.CrossSection.Depth)
                    {
                        jmin = PanelViewState.CrossSectionOffset.y;
                        jmax = PanelViewState.CrossSectionOffset.y + 0.001f;

                    }
                    else
                    {
                        kmin = PanelViewState.CrossSectionOffset.z;
                        kmax = PanelViewState.CrossSectionOffset.z + 0.001f;
                    }

                    GL.Disable(EnableCap.Texture2d);
                    GL.DepthMask(false); //disable depth writes
                    GL.Disable(EnableCap.CullFace);

                    GL.Begin(BeginMode.Quads);

                    if (PanelViewState.CrossSection.Height > PanelViewState.CrossSection.Depth)
                    {

                        float k = kmin;
                        float halfRes = res / 2;

                        for (float i = imin; i < imax; i += res)
                        {
                            for (float j = jmin; j < jmax; j += res)
                            {
                                float level = (0.55f * nutrient.GetNutrientLevelApprox(i, j, k) / spatialViewState.NutrientIntensityScale);
                                if (level!=0){
                                    // bump up if not 0
                                    level+=0.2f;
                                }
                               // float level = nutrient.GetNutrientLevel(i, j, k);

                                if (level > 1.0f) level = 1.0f;
                                GL.Color4(r, g, b, level);
                                pos.x = i;
                                pos.y = j;
                                pos.z = k;

                                GL.Vertex3(pos.x - halfRes, pos.y - halfRes, pos.z);
                                GL.Vertex3(pos.x - halfRes, pos.y + halfRes, pos.z);
                                GL.Vertex3(pos.x + halfRes, pos.y + halfRes, pos.z);
                                GL.Vertex3(pos.x + halfRes, pos.y - halfRes, pos.z);

                            }

                        }

                    }
                    else
                    {

                        float j = kmin;
                        float halfRes = res / 2;

                        for (float i = imin; i < imax; i += res)
                        {
                            for (float k = kmin; k < kmax; k += res)
                            {
                                 float level = nutrient.GetNutrientLevelApprox(i, j, k);
                               // float level = nutrient.GetNutrientLevel(i, j, k);

                                if (level > 1.0f) level = 1.0f;
                                GL.Color4(r, g, b, level);
                                pos.x = i;
                                pos.y = j;
                                pos.z = k;

                                GL.Vertex3(pos.x - halfRes, pos.y, pos.z - halfRes);
                                GL.Vertex3(pos.x - halfRes, pos.y, pos.z +halfRes);
                                GL.Vertex3(pos.x + halfRes, pos.y, pos.z + halfRes);
                                GL.Vertex3(pos.x + halfRes, pos.y, pos.z - halfRes);

                            }

                        }
                    }

                    GL.End();
                    GL.DepthMask(true);
                    GL.Enable(EnableCap.CullFace);

                }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Draws all the cells in the environment
        /// </summary>
        /// <param name="simState"></param>
        private void DrawCells(StateSnapshot simState)
        {
            if (simState!= null)
            {
                Vector3 pos;
                GL.Enable(EnableCap.DepthTest);
                GL.Enable(EnableCap.Texture2d);

                foreach (CellToSort cellToSort in sortedCells)
                    {
                        CellInstance cell = cellToSort.cell;
                        MuCell.Model.SBML.Group groupObj = simState.SimulationEnvironment.GetGroupObject(cell.GroupID);

                        pos = cell.CellInstanceSpatialContext.Position;
                        GL.PushMatrix();

                            GL.Translate(pos.x, pos.y, pos.z);

                            GLDrawHelper.BillboardCheatSphericalBegin(view);

                                GL.Color4((float)groupObj.Col.R / 256, (float)groupObj.Col.G / 256, (float)groupObj.Col.B / 256, 1.0f);

                                    GL.BindTexture(TextureTarget.Texture2d, GLTextures.GetTex(0,(int)view));
                                    GL.DepthMask(false);
                                    GL.Begin(BeginMode.Quads);

                                        GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-1.10f, -1.10f);
                                        GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(1.10f, -1.10f);
                                        GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(1.10f, 1.10f);
                                        GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-1.10f, 1.10f);

                                    GL.End();
                                    GL.DepthMask(true);

                            GLDrawHelper.BillboardEnd();
                        GL.PopMatrix();

                    }
                    GL.Disable(EnableCap.Texture2d);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Sorts cells according to their depth from the camera, and places the result
        /// in sortedCells
        /// </summary>
        /// <param name="simState"></param>
        private void SortCells(StateSnapshot simState)
        {
            if (simState!= null)
            {
                Vector3 pos;

                sortedCells.Clear();

                foreach (CellInstance cell in simState.Cells)
                {

                    pos = cell.CellInstanceSpatialContext.Position;
                    GL.PushMatrix();
                        GL.Translate(pos.x, pos.y, pos.z);
                         sortedCells.Add(new CellToSort(cell,GLDrawHelper.GetDepth()));
                    GL.PopMatrix();

                }

                if (view == Views.ThreeDAnalyzer)
                {
                    sortedCells.Sort();
                }

            }
        }
Esempio n. 19
0
 public void pushState(StateSnapshot currentStateClone)
 {
     lock (buffer)
     {
         //to prevent buffer overrun
         if (buffer.Count == maxCacheSize)
         {
             buffer.Dequeue();
         }
         buffer.Enqueue(currentStateClone);
     }
 }
Esempio n. 20
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);
        }
Esempio n. 21
0
 public static void SpatialSimulatorZZZ(CellInstance cell, StateSnapshot currentState, double time, double StepTime)
 {
 }
Esempio n. 22
0
 /// <summary>
 /// Evaluates the time series to add the next data point
 /// </summary>
 /// <param name="state">
 /// A <see cref="StateSnapshot"/>
 /// </param>
 public void evaluate(StateSnapshot state)
 {
     // Evaluate the inner function with the state and add to the series
     addDataPoint(parameters.evaluateNext(state));
 }
Esempio n. 23
0
 public Results()
 {
     this.timeSeries = new List<TimeSeries>();
     this.stateSnapshots = new List<StateSnapshot>();
     this.currentState = new StateSnapshot();
 }
Esempio n. 24
0
        /// <summary>
        /// Allows all reactions within the cell to run for the current timestep
        /// </summary>
        /// <param name="currentState">
        /// A <see cref="StateSnapshot"/>
        /// </param>
        /// <param name="time">
        /// A <see cref="System.Double"/>
        /// </param>
        /// <param name="stepTime">
        /// A <see cref="System.Double"/>
        /// </param>
        public void DoTimeStep(StateSnapshot currentState, double time, double stepTime)
        {
            // set the current state
            this.currentState = currentState;

            // Do the component simulations
            foreach (SBML.ExtracellularComponents.ComponentWorldStateBase component in this.components)
            {
                component.DoTimeStep(this, currentState, time, stepTime);
            }

            // Step the cvode module
            double endTime = this.solver.OneStep(time, stepTime);

            // get values off vector
            for (int i = 0; i < this.speciesToIndexMap.Count; i++)
            {
                this.speciesVariables[indexToSpeciesMap[i]] = this.solver.GetValue(i);
            }
        }