From: Alexey Shvetsov Date: Sun, 19 Jul 2015 08:31:37 +0000 (+0300) Subject: Merge branch 'master' into pygromacs X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=48c9a4855bde90a698842d4788168cb71744270c;hp=-c;p=alexxy%2Fgromacs.git Merge branch 'master' into pygromacs --- 48c9a4855bde90a698842d4788168cb71744270c diff --combined src/gromacs/trajectoryanalysis/cmdlinerunner.cpp index ac7f8b50a9,5ac15b6281..912db6c963 --- a/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp +++ b/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp @@@ -81,7 -81,7 +81,7 @@@ class TrajectoryAnalysisCommandLineRunn void parseOptions(TrajectoryAnalysisSettings *settings, TrajectoryAnalysisRunnerCommon *common, SelectionCollection *selections, - int *argc, char *argv[]); + int *argc, char *argv[], bool full=true); TrajectoryAnalysisModule *module_; bool bUseDefaultGroups_; @@@ -106,7 -106,7 +106,7 @@@ TrajectoryAnalysisCommandLineRunner::Im TrajectoryAnalysisSettings *settings, TrajectoryAnalysisRunnerCommon *common, SelectionCollection *selections, - int *argc, char *argv[]) + int *argc, char *argv[], bool full) { FileNameOptionManager fileoptManager; SelectionOptionManager seloptManager(selections); @@@ -117,16 -117,12 +117,16 @@@ options.addManager(&fileoptManager); options.addManager(&seloptManager); - options.addSubSection(&commonOptions); + if (full) { + options.addSubSection(&commonOptions); + } options.addSubSection(&selectionOptions); options.addSubSection(&moduleOptions); module_->initOptions(&moduleOptions, settings); - common->initOptions(&commonOptions); + if (full) { + common->initOptions(&commonOptions); + } selections->initOptions(&selectionOptions); { @@@ -138,19 -134,16 +138,19 @@@ options.finish(); } - common->optionsFinished(&commonOptions); + if (full) { + common->optionsFinished(&commonOptions); + } module_->optionsFinished(&moduleOptions, settings); common->initIndexGroups(selections, bUseDefaultGroups_); const bool bInteractive = StandardInputStream::instance().isInteractive(); seloptManager.parseRequestedFromStdin(bInteractive); - common->doneIndexGroups(selections); + common->doneIndexGroups(selections); common->initTopology(selections); + selections->compile(); } @@@ -201,20 -194,6 +201,20 @@@ TrajectoryAnalysisCommandLineRunner::ru const TopologyInformation &topology = common.topologyInformation(); module->initAnalysis(settings, topology); + TrajectoryAnalysisModule::Batch batch = module->getBatch(); + std::vector batchSelections; + std::vector impls; + for (size_t i = 0; i < batch.size(); i++) { + TrajectoryAnalysisModule *bmodule = batch[i]; + batchSelections.push_back(new SelectionCollection()); + impls.push_back(new Impl(bmodule)); + std::vector modArgv = module->getArgv(i); + int modArgc = modArgv.size(); + impls.back()->parseOptions(&settings, &common, batchSelections.back(), &modArgc, modArgv.data(), false); + + batch[i]->initAnalysis(settings, topology); + } + // Load first frame. common.initFirstFrame(); module->initAfterFirstFrame(settings, common.frame()); @@@ -226,17 -205,6 +226,17 @@@ AnalysisDataParallelOptions dataOptions; TrajectoryAnalysisModuleDataPointer pdata( module->startFrames(dataOptions, selections)); + + std::vector batchOptions; + std::vector batchDataPointers; + for (size_t i = 0; i < batch.size(); i++) { + batch[i]->initAfterFirstFrame(settings, common.frame()); + + batchOptions.push_back(AnalysisDataParallelOptions()); + batchDataPointers.push_back(batch[i]->startFrames( + batchOptions.back(), *batchSelections[i])); + } + do { common.initFrame(); @@@ -246,11 -214,6 +246,11 @@@ set_pbc(ppbc, topology.ePBC(), frame.box); } + for (size_t i = 0; i < batch.size(); i++) { + batchSelections[i]->evaluate(&frame, ppbc); + batch[i]->analyzeFrame(nframes, frame, ppbc, batchDataPointers[i].get()); + batch[i]->finishFrameSerial(nframes); + } selections.evaluate(&frame, ppbc); module->analyzeFrame(nframes, frame, ppbc, pdata.get()); module->finishFrameSerial(nframes); @@@ -258,14 -221,6 +258,14 @@@ ++nframes; } while (common.readNextFrame()); + for (size_t i = 0; i < batch.size(); i++) { + batch[i]->finishFrames(batchDataPointers[i].get()); + if (batchDataPointers[i].get() != NULL) { + batchDataPointers[i]->finish(); + } + batchDataPointers[i].reset(); + } + module->finishFrames(pdata.get()); if (pdata.get() != NULL) { @@@ -284,15 -239,6 +284,15 @@@ } // Restore the maximal groups for dynamic selections. + for (size_t i = 0; i < batch.size(); i++) { + batchSelections[i]->evaluateFinal(nframes); + batch[i]->finishAnalysis(nframes); + batch[i]->writeOutput(); + + delete batchSelections[i]; + delete impls[i]; + } + selections.evaluateFinal(nframes); module->finishAnalysis(nframes); @@@ -327,7 -273,7 +327,7 @@@ TrajectoryAnalysisCommandLineRunner::wr selections.initOptions(&selectionOptions); CommandLineHelpWriter(options) - .setShowDescriptions(true) + .setHelpText(settings.helpText()) .setTimeUnitString(settings.timeUnitManager().timeUnitAsString()) .writeHelp(context); } @@@ -354,16 -300,7 +354,16 @@@ class TrajectoryAnalysisCommandLineRunn */ RunnerCommandLineModule(const char *name, const char *description, ModuleFactoryMethod factory) - : name_(name), description_(description), factory_(factory) + : name_(name), description_(description), hasFunction_(true), factory_(factory), functor_(NULL) + { + } + + /*! \brief + * Overloaded constructor accepting a functor instead of function pointer. + */ + RunnerCommandLineModule(const char *name, const char *description, + ModuleFactoryFunctor *factory) + : name_(name), description_(description), hasFunction_(false), factory_(NULL), functor_(factory) { } @@@ -375,11 -312,9 +375,11 @@@ virtual void writeHelp(const CommandLineHelpContext &context) const; private: - const char *name_; - const char *description_; - ModuleFactoryMethod factory_; + const char *name_; + const char *description_; + bool hasFunction_; + ModuleFactoryMethod factory_; + ModuleFactoryFunctor *functor_; GMX_DISALLOW_COPY_AND_ASSIGN(RunnerCommandLineModule); }; @@@ -392,7 -327,7 +392,7 @@@ void TrajectoryAnalysisCommandLineRunne int TrajectoryAnalysisCommandLineRunner::Impl::RunnerCommandLineModule::run( int argc, char *argv[]) { - TrajectoryAnalysisModulePointer module(factory_()); + TrajectoryAnalysisModulePointer module(hasFunction_? factory_() : (*functor_)()); TrajectoryAnalysisCommandLineRunner runner(module.get()); return runner.run(argc, argv); } @@@ -400,7 -335,7 +400,7 @@@ void TrajectoryAnalysisCommandLineRunner::Impl::RunnerCommandLineModule::writeHelp( const CommandLineHelpContext &context) const { - TrajectoryAnalysisModulePointer module(factory_()); + TrajectoryAnalysisModulePointer module(hasFunction_? factory_() : (*functor_)()); TrajectoryAnalysisCommandLineRunner runner(module.get()); runner.writeHelp(context); } @@@ -414,15 -349,6 +414,15 @@@ TrajectoryAnalysisCommandLineRunner::ru return CommandLineModuleManager::runAsMainSingleModule(argc, argv, &module); } +// static +int +TrajectoryAnalysisCommandLineRunner::runAsMain( + int argc, char *argv[], ModuleFactoryFunctor *factory) +{ + Impl::RunnerCommandLineModule module(NULL, NULL, factory); + return CommandLineModuleManager::runAsMainSingleModule(argc, argv, &module); +} + // static void TrajectoryAnalysisCommandLineRunner::registerModule(