void ParameterScanWorker::run() { workerStarted(); //The user may have aborted the minization... check here.. if(mHost.isBeingTerminated()) { //user did set the terminate flag to true.. discard any data and get out of the //plugin execute code.. RRPLOG(lInfo)<<"The ParameterScanWorker was terminated.. aborting"; workerFinished(); return; } //Create arrayed data ArrayedParameter para(mHost.mParameter.getValueReference()); StringList selList(mHost.mSelectionList.getValue()); RoadRunner rr; rr.load(mHost.mSBML.getValue()); //Make sure time is the first column in the selectin list if(selList.size() && compareNoCase(selList[0], "time") != true) { selList.InsertAt(0,"time"); } rr.setSelections(selList); TelluriumData& data = mHost.mOutputData.getValueReference(); data.clear(); for(int i = 0; i < para.getNumberOfIncrements() + 1; i++) { rr::SimulateOptions options; options.flags |= rr::SimulateOptions::RESET_MODEL; options.start = mHost.mStartTime.getValue(); options.duration = mHost.mEndTime.getValue() - mHost.mStartTime.getValue(); options.steps = mHost.mNumberOfPointsPerSimulation.getValue() - 1; //Set parameter rr.setValue(para.getName(), para.getCurrentValue()); const RoadRunnerData *rrData = rr.simulate(&options); TelluriumData *temp = new TelluriumData(*rrData); data.append(*temp); delete temp; para.increment(); } //The Arrayed parameter need to be added to the data. data.setArrayedParameter(para); workerFinished(); }
/** * perform a stochastic ensemble calculation. * * :param: r an existing roadrunner obj, loaded with a mode. * :param: n how many ensembles to run. * :param: seed the seed value, use None to continue with previous * random number stream. * :param: start start time * :param: stop stop time * :param: ntps how many points display in the result. */ DoubleMatrix ensemble(RoadRunner &r, int n, unsigned long seed, double start, double stop, int npts) { // set the seed value of the integrator Integrator *itg = r.getIntegrator(Integrator::GILLESPIE); itg->setItem("seed", seed); // setup the simulation // create a sim opt obj, loads itself with // default values in ctor. SimulateOptions o; o.start = start; o.duration = stop; o.steps = npts; // we should reset the model each time we simulate, // set the RESET_MODEL bit. o.flags |= SimulateOptions::RESET_MODEL; o.integrator = Integrator::GILLESPIE; // make a result var DoubleMatrix result(npts+1, n+1); for (int i = 0; i < n; ++i) { const DoubleMatrix &sim = *r.simulate(&o); // copy result data colum for (int row = 0; row < npts+1; ++row) { result(row, i+1) = sim(row, 1); } } // copy result time column const DoubleMatrix &sim = *r.getSimulationData(); // copy result data colum for (int row = 0; row < npts+1; ++row) { result(row, 0) = sim(row, 0); } return result; }
bool TestModel::execute(bool inThread) { Log(lDebug)<<"Executing the TestModel plugin by Totte Karlsson"; RoadRunner rr; rr.load(mModel); rr::SimulateOptions opt; opt.start = 0; opt.duration = 10; opt.steps = 14; TelluriumData data(rr.simulate(&opt)); mTestData.setValue(data); //Add noise const PluginManager* PM = this->getPluginManager(); Plugin* noise = PM->getPlugin("AddNoise"); if(!noise) { stringstream msg; msg<<"The TestModel plugin dependes on the AddNoise plugin, which is not yet loaded."; throw(Exception(msg.str())); } mTestDataWithNoise.setValue(mTestData.getValue()); noise->setPropertyValue("Sigma", mSigma.getValueHandle()); noise->setPropertyValue("InputData", mTestDataWithNoise.getValueHandle()); noise->execute(); mTestDataWithNoise.setValue(noise->getPropertyValueHandle("InputData")); //Add weights addWeights(); return true; }
int main(int argc, char** argv) { std::string in_dir; std::string out_dir; std::string test_name; unsigned int level = 0; unsigned int version = 0; double start_time = 0.0; double duration = 0.0; std::list<std::string> variables; std::set<std::string> amounts; std::set<std::string> concentrations; double absolute_error = 0.0; double relative_error = 0.0; if (argc < 6) { std::cerr << "Usage: rr-sbml-benchmrk INPUT_DIRECTORY TESTNAME OUTPUTDIRECTORY SBMLLEVEL SBMLVERSION [steps override] [durration] [compiler] [-stiff]" << std::endl; exit(1); } in_dir = argv[1]; test_name = argv[2]; out_dir = argv[3]; level = strtol(argv[4], NULL, 10); version = strtol(argv[5], NULL, 10); if (level < 1 || level > 3) { std::cerr << "SBML Level " << level << " Version " << version << " not supported." << std::endl; exit(1); } if (level == 1 && (version < 1 || version > 2)) { std::cerr << "SBML Level " << level << " Version " << version << " not supported." << std::endl; exit(1); } std::ostringstream os; os << in_dir << "/" << test_name << "/" << test_name << "-settings.txt"; // open the settings file and parse it std::cout << "parsing file: " << os.str() << std::endl; std::ifstream f; std::string settingsFile = in_dir + "/" + test_name + "/" + test_name + "-settings.txt"; std::string sbmlFile; { stringstream os; os << in_dir << "/" << test_name << "/" << test_name << "-sbml-l" << level << "v" << version << ".xml"; sbmlFile = os.str(); } std::string output_filename; if (!out_dir.empty() || out_dir.compare("/dev/null") != 0) { stringstream os; os.str(""); os << out_dir << "/" << test_name << ".csv"; output_filename = os.str(); } RoadRunner roadRunner; LoadSBMLOptions opt; // don't generate cache for models opt.modelGeneratorOpt = opt.modelGeneratorOpt | LoadSBMLOptions::RECOMPILE; // no mutable initial conditions opt.modelGeneratorOpt = opt.modelGeneratorOpt & ~LoadSBMLOptions::MUTABLE_INITIAL_CONDITIONS; // read only model opt.modelGeneratorOpt = opt.modelGeneratorOpt | LoadSBMLOptions::READ_ONLY; opt.modelGeneratorOpt = opt.modelGeneratorOpt | LoadSBMLOptions::OPTIMIZE_CFG_SIMPLIFICATION; opt.modelGeneratorOpt = opt.modelGeneratorOpt | LoadSBMLOptions::OPTIMIZE_GVN; std::cout << "loading file: " << sbmlFile << std::endl; roadRunner.load(sbmlFile, &opt); SimulateOptions settings; settings.loadSBMLSettings(settingsFile); // override steps if (argc > 6) { int steps = strtol(argv[6], NULL, 0); if (steps > 0) { settings.steps = steps; } } if (argc > 7) { double dur = atof(argv[7]); if (dur > 0) { settings.duration = dur; } } for (int i = 0; i < argc; ++i) { if (string(argv[i]).find("stiff") != string::npos) { roadRunner.getIntegrator()->setValue("stiff", true); } } std::cout << "running for " << settings.steps << ", duration " << settings.duration << std::endl; std::cout << "absolute: " << roadRunner.getIntegrator()->getValue("absolute_tolerance").convert<bool>() << std::endl; std::cout << "relative: " << roadRunner.getIntegrator()->getValue("relative_tolerance").convert<bool>() << std::endl; std::cout << "stiff: " << (roadRunner.getIntegrator()->getValue("stiff").convert<bool>() ? "True" : "False") << std::endl; roadRunner.setSimulateOptions(settings); const DoubleMatrix& result = *roadRunner.simulate(0); if (!output_filename.empty()) { ofstream output; output.open(output_filename.c_str()); int rows = result.numRows(); int cols = result.numCols(); for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { output << result(i, j); if (j + 1 < cols) { output << ", "; } else { output << "\n"; } } } } return 0; }