Пример #1
0
 /// <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;
 }
Пример #2
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);
        }
Пример #3
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));
        }
Пример #4
0
 public ModifierSpeciesReference(Species species)
 {
     this.species = species;
 }
Пример #5
0
 public SpeciesCommand(Species species, bool adding, Model.SBML.Model model)
 {
     this.species = species;
     this.adding = adding;
     this.model = model;
 }
Пример #6
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);
        }
Пример #7
0
        public void SpeciesElement(Hashtable attrs)
        {
            Species species = new Species(attrs);
            if (species.ID != null)
            {
                this.model.AddId(species.ID, species);
            }

            SpeciesType speciesType = null;
            Compartment compartment = null;
            Double initialAmount = -1d;
            Double initialConcentration = -1d;
            String substanceUnits = null;
            Boolean hasOnlySubstanceUnits = false;
            Boolean boundaryCondition = false;
            Boolean constant = false;

            if (attrs.ContainsKey("initialamount"))
                initialAmount = Double.Parse((String)attrs["initialamount"]);
            if (attrs.ContainsKey("initialconcentration"))
                initialConcentration = Double.Parse((String)attrs["initialconcentration"]);
            if (attrs.ContainsKey("substanceunits"))
                substanceUnits = (String)attrs["substanceunits"];
            if (attrs.ContainsKey("hasonlysubstanceunits"))
                hasOnlySubstanceUnits = Boolean.Parse((String)attrs["hasonlysubstanceunits"]);
            if (attrs.ContainsKey("boundarycondition"))
                boundaryCondition = Boolean.Parse((String)attrs["boundarycondition"]);
            if (attrs.ContainsKey("constant"))
                constant = Boolean.Parse((String)attrs["constant"]);

            if (attrs.ContainsKey("speciestype"))
            {
                String sTypeId = (String)attrs["speciesType"];
                speciesType = (SpeciesType)this.model.findObject(sTypeId);
            }

            if (attrs.ContainsKey("compartment"))
            {
                String cId = (String)attrs["compartment"];
                compartment = (Compartment)this.model.findObject(cId);
            }

            if (attrs.ContainsKey("substanceunits"))
            {
                substanceUnits = (String)attrs["substanceunits"];
            }
            else
            {
                // look it up based on units of compartment;
            }

            species.AddProperties(speciesType, compartment, initialAmount,
                initialConcentration, substanceUnits, hasOnlySubstanceUnits, boundaryCondition,
                constant);

            this.model.listOfSpecies.Add(species);
        }
Пример #8
0
 public SpeciesReference(Species species, double stoichiometry)
 {
     this.species = species;
     this.stoichiometry = stoichiometry;
 }
Пример #9
0
 public SpeciesReference(Species species)
 {
     this.species = species;
     this.stoichiometry = 1;
 }