/// <summary> /// Creates a new cell definition, choosing an appropriate name /// </summary> public void createNewCellDefinition() { Experiment parentExperiment = null; String namePrefix = "CellDef "; int highestID = 1; for (int attempt = 0; attempt < 1000; attempt++) { if (isCellDefinitionNameTaken(namePrefix + highestID)) { highestID++; } else { break; } } foreach (Experiment experiment in openExperiments) { if (experiment.Id == currentExperimentID) { parentExperiment = experiment; break; } } if (parentExperiment != null) { CellDefinition cell = new CellDefinition(namePrefix + highestID); cell.addSBMLModel(System.AppDomain.CurrentDomain.BaseDirectory+"/Models/blank.xml"); parentExperiment.addCellDefinition(cell); experimentTreePanelController.refreshTreeElements(getExperiments()); experimentTreePanelController.setSelectedCellDefinition(cell.Name); } }
/// <summary> /// Constructor for creating a cell instance with a cell definition /// </summary> /// <param name="cellDefinition"> /// A <see cref="CellDefinition"/> /// </param> public CellInstance(CellDefinition cellDefinition) { this.cellInstanceDefinition = cellDefinition; SBML.Model model = cellDefinition.getModel(); if (model != null) { this.species = cellDefinition.getModel().listOfSpecies; } // Initialize the specials Dictionary this.speciesVariables = new Dictionary<string, double>(); this.localSpeciesVariables = new Dictionary<string, double>(); this.localSpeciesDelta = new Dictionary<string, double>(); this.speciesToIndexMap = new Dictionary<string, int>(); this.indexToSpeciesMap = new Dictionary<int, string>(); // set up the list this.convertSpeciesListToVariables(); this.components = new List<MuCell.Model.SBML.ExtracellularComponents.ComponentWorldStateBase>(); this.flaggy = new MuCell.Model.SBML.ExtracellularComponents.FlagellaComponent(); cellInstanceSpatialContext = new SpatialContext(); }
/// <summary> /// Base constructor /// </summary> public AggregateReferenceNode(Experiment experiment, Simulation simulation) { this.cellDefinition = null; this.group = null; this.species = null; this.experiment = experiment; this.simulation = simulation; }
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); }
public void TestGroupOperators() { //create an environemnt, and an array of 100 cells MuCell.Model.Environment env = new MuCell.Model.Environment(new Vector3(1, 1, 1)); CellInstance[] cells = new CellInstance[100]; CellDefinition celDef = new CellDefinition("testCellDef"); for (int i = 0; i < 100; i++) { CellInstance cell = new CellInstance(celDef); cells[i] = cell; } //assert that there are no groups yet formed in the env Assert.That( env.GetGroups().Count == 0 ); //obtain an unused group index, and create a group with 25 cells in it int newGroupIndex1 = env.GetUnusedGroupIndex(); for (int i = 0; i < 25; i++) { env.AddCellToGroup(newGroupIndex1, cells[i]); } //assert that there is now one group Assert.That(env.GetGroups().Count == 1); //assert that it is the correct group Assert.That(env.ContainsGroup(newGroupIndex1)); //assert that there are 25 cells in the group Assert.That(env.CellsFromGroup(newGroupIndex1).Count == 25); //obtain another unused group index int newGroupIndex2 = env.GetUnusedGroupIndex(); //group indexes should differ Assert.That(newGroupIndex1 != newGroupIndex2); //add some cells to the new group index for (int i = 25; i < 50; i++) { env.AddCellToGroup(newGroupIndex2, cells[i]); } //assert that there is now one group Assert.That(env.GetGroups().Count == 2); }
public void setCellDefinitions(CellDefinition[] cellDefs) { CellTypeComboBox.Items.Clear(); foreach (CellDefinition cellDef in cellDefs) { CellTypeComboBox.Items.Add(cellDef); } if (CellTypeComboBox.Items.Count > 0) { CellTypeComboBox.SelectedIndex = 0; } }
public bool exptEquals(CellDefinition other) { if (this.Name != other.Name) { Console.Write("CellDefinition objects not equal: "); Console.WriteLine("this.Name='" + this.Name + "'; other.Name='" + other.Name); return false; } return true; }
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)); }
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); }
private List<Experiment> generateHardcodedExperiment() { List<Experiment> exps = new List<Experiment>(); Simulation sim1 = new Simulation("sim 1"); Simulation sim2 = new Simulation("sim 2"); Simulation sim3 = new Simulation("sim 3"); Simulation sim4 = new Simulation("sim 4"); Simulation sim5 = new Simulation("sim 5"); Simulation sim6 = new Simulation("sim 6"); sim1.Parameters.StepTime = 5.3d; sim5.Parameters.StepTime = -6.3d; CellDefinition cellDef1 = new CellDefinition("CellDef 1"); cellDef1.addSBMLModel("Models/smallest.Hopf.xml"); //CellDefinition cellDef2 = new CellDefinition("CellDef 2"); //CellDefinition cellDef3 = new CellDefinition("CellDef 3"); //CellDefinition cellDef4 = new CellDefinition("CellDef 4"); //CellDefinition cellDef5 = new CellDefinition("CellDef 5"); //CellDefinition cellDef6 = new CellDefinition("CellDef 6"); //CellDefinition cellDef7 = new CellDefinition("CellDef 7"); Experiment exp1 = new Experiment("Experiment 1"); Experiment exp2 = new Experiment("Experiment 2"); Experiment exp3 = new Experiment("Experiment 3"); exp1.Id = 1; exp2.Id = 2; exp3.Id = 3; exp1.addCellDefinition(cellDef1); exp1.addSimulation(sim1); exp1.addSimulation(sim2); exp1.addSimulation(sim3); /*exp2.addCellDefinition(cellDef2); exp2.addCellDefinition(cellDef3); exp2.addCellDefinition(cellDef4); exp2.addCellDefinition(cellDef5);*/ exp2.addSimulation(sim4); //exp3.addCellDefinition(cellDef6); //exp3.addCellDefinition(cellDef7); exp3.addSimulation(sim5); exp3.addSimulation(sim6); exps.Add(exp1); exps.Add(exp2); exps.Add(exp3); return exps; }
/// <summary> /// Removes a cell definition from the experiment /// </summary> /// <param name="cellDefinition"> /// A <see cref="CellDefinition"/> /// </param> public void removeCellDefinition(CellDefinition cellDefinition) { this.cellDefinitions.Remove(cellDefinition); }
/// <summary> /// Add a cell definition to the experiment /// </summary> /// <param name="cellDefinition"> /// A <see cref="CellDefinition"/> /// </param> public void addCellDefinition(CellDefinition cellDefinition) { this.cellDefinitions.Add(cellDefinition); }
/// <summary> /// Secondary constructor that takes a cell definition, /// a spatial context, a list of species and a species variables dictionary /// </summary> /// <param name="cellDefinition"> /// A <see cref="CellDefinition"/> /// </param> /// <param name="spatialContext"> /// A <see cref="SpatialContext"/> /// </param> /// <param name="species"> /// A <see cref="List`1"/> /// </param> /// <param name="speciesVariables"> /// A <see cref="Dictionary`2"/> /// </param> public CellInstance(CellDefinition cellDefinition, SpatialContext spatialContext, List<SBML.Species> species, Dictionary<string, double> speciesVariables, Dictionary<int, string> indexToSpeciesMap, Dictionary<string, int> speciesToIndexMap, Solver.SolverBase solver, List<SBML.ExtracellularComponents.ComponentWorldStateBase> components, System.Random random) { this.cellInstanceDefinition = cellDefinition; this.species = species; this.speciesVariables = speciesVariables; this.cellInstanceSpatialContext = spatialContext; this.indexToSpeciesMap = indexToSpeciesMap; this.speciesToIndexMap = speciesToIndexMap; this.solver = solver; this.components = components; this.randomObject = random; this.localSpeciesVariables = new Dictionary<string, double>(); this.localSpeciesDelta = new Dictionary<string, double>(); }