Exemplo n.º 1
0
        private bool checkBiStability(List <double> optPValuesArray, List <string> pNames, int checkParamIndex,
                                      int speciesIndex)
        {
            bool   isBiStable      = false;
            int    numOfParameters = optPValuesArray.Count;
            double tempCheckParamValue;
            var    decFloatingSpeciesArray = new double[20];
            var    incFloatingSpeciesArray = new double[20];
            double speciesValsSum          = 0.0;

            double[] speciesConcArray;

            //Set the parameter values to Optimized Parameter Values
            for (int i = 0; i < pNames.Count; i++)
            {
                rr.setValue(pNames[i], optPValuesArray[i]);
            }

            rr.setTimeStart(0);
            rr.setTimeEnd(simulationTime);

            BringToSteadyStateOrThrow();


            //Now decrement the parameter value and simulate untill steady state is reached.
            //Do this 20 times and store the species concentration in an array.
            for (int i = 0; i < 20; i++)
            {
                //Now Decrement the ith parameter value and calculate the species conc. at steady state
                tempCheckParamValue = (1.00 - 0.01 * (i + 1)) * optPValuesArray[checkParamIndex];

                rr.setValue(pNames[checkParamIndex], tempCheckParamValue);
                BringToSteadyStateOrThrow();
                speciesConcArray           = rr.getFloatingSpeciesConcentrations();
                decFloatingSpeciesArray[i] = speciesConcArray[speciesIndex];
            }

            rr.reset();

            rr.setValue(pNames[checkParamIndex], optPValuesArray[checkParamIndex]);
            rr.setTimeStart(0);
            rr.setTimeEnd(simulationTime);

            BringToSteadyStateOrThrow(1);

            //Now increment the parameter value and simulate untill steady state is reached.
            //Do this 20 times and store the species concentration in an array.
            for (int i = 0; i < 20; i++)
            {
                //Now Increment the ith parameter value and calculate the species conc. at steady state
                tempCheckParamValue = (1.00 + 0.01 * (i + 1)) * optPValuesArray[checkParamIndex];
                rr.setValue(pNames[checkParamIndex], tempCheckParamValue);
                BringToSteadyStateOrThrow();
                speciesConcArray           = rr.getFloatingSpeciesConcentrations();
                incFloatingSpeciesArray[i] = speciesConcArray[speciesIndex];
            }

            speciesValsSum = 0.0;
            for (int i = 2; i < 20; i++)
            {
                speciesValsSum = speciesValsSum + decFloatingSpeciesArray[i];
            }
            double decFloatSpeciesMean = speciesValsSum / 18;

            speciesValsSum = 0.0;
            for (int i = 2; i < 20; i++)
            {
                speciesValsSum = speciesValsSum + incFloatingSpeciesArray[i];
            }
            double incFloatSpeciesMean = speciesValsSum / 18;

            if (decFloatSpeciesMean > 2 * incFloatSpeciesMean || incFloatSpeciesMean > 2 * decFloatSpeciesMean)
            {
                isBiStable = true;
            }

            return(isBiStable);
        }
Exemplo n.º 2
0
        private void cmdSteadyState_Click(object sender, EventArgs e)
        {
            thread.QueueItem(() =>
            {
                if (m_sSBML != null)
                {
                    if (m_sSBML.Length > 0)
                    {
                        try
                        {
                            if (sim == null)
                            {
                                sim = new RoadRunner();
                            }

                            sim.loadSBML(m_sSBML);
                            sim.simulate();
                            double steadyState = sim.steadyState();
                            if (
                                MessageBox.Show(
                                    "Found steady state with sums of squares: " + steadyState +
                                    ". Do you want to use this state to be used?", "Steady state calculated",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                            {
                                return;
                            }
                            sim.simulate();
                            ArrayList floatingSpeciesNames  = sim.getFloatingSpeciesNames();
                            double[] speciesConcentrations1 = sim.getFloatingSpeciesConcentrations();
                            ArrayList boundarySpeciesNames  = sim.getBoundarySpeciesNames();
                            double[] speciesConcentrations2 = sim.getBoundarySpeciesConcentrations();
                            ArrayList parameterTupleList    = sim.getAllGlobalParameterTupleList();
                            NOM.loadSBML(m_sSBML);
                            for (int index = 0; index < floatingSpeciesNames.Count; ++index)
                            {
                                NOM.setValue((string)floatingSpeciesNames[index], speciesConcentrations1[index]);
                            }
                            for (int index = 0; index < boundarySpeciesNames.Count; ++index)
                            {
                                NOM.setValue((string)boundarySpeciesNames[index], speciesConcentrations2[index]);
                            }
                            foreach (ArrayList arrayList in parameterTupleList)
                            {
                                NOM.setValue((string)arrayList[0], (double)arrayList[1]);
                            }
                            m_sSBML = NOM.getSBML();
                            loadSBML(m_sSBML);
                            return;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Could not compute steady state due to: " + ex.Message,
                                            "Steady state could not be computed ...", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            return;
                        }
                    }
                }
                MessageBox.Show("There is no model to analyze. Load a model first.", "No Model loaded",
                                MessageBoxButtons.OK, MessageBoxIcon.Hand);
            });
        }