/// <summary> /// Brings the model to steady state or throws an exception if it cant /// </summary> /// <param name="verifyConcentrations">if true, the floating species concentration will be checked</param> /// <param name="cutoff">the value considered as close enough to steady state</param> /// <param name="retries">number of tries</param> /// <returns></returns> private double BringToSteadyStateOrThrow(int retries = 20, bool verifyConcentrations = false, double cutoff = 10E-5) { double steadyStateValue = 1; bool fndSteadyState = false; int simCount = 1; while (!fndSteadyState && simCount < retries) { rr.reset(); try { for (int k = 0; k < simCount; k++) { rr.simulate(); } steadyStateValue = rr.steadyState(); } catch (SBWException) { //simCount++; } if (steadyStateValue < cutoff) { fndSteadyState = true; if (verifyConcentrations) { double[] ststSpeciesValues = rr.getFloatingSpeciesConcentrations(); for (int i = 0; i < ststSpeciesValues.Length; i++) { if (ststSpeciesValues[i] < 0) { fndSteadyState = false; simCount++; break; } } } } else { simCount++; } } if (simCount == retries) { var ae = new BifException("Error in sbwBifGAOptimize", "Model has not reached steady state!!!"); throw ae; } return(steadyStateValue); }
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); }); }