2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014,2015,2018, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Declares gmx::TrajectoryAnalysisCommandLineRunner.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_trajectoryanalysis
43 #ifndef GMX_TRAJECTORYANALYSIS_CMDLINERUNNER_H
44 #define GMX_TRAJECTORYANALYSIS_CMDLINERUNNER_H
49 #include "gromacs/trajectoryanalysis/analysismodule.h"
54 class CommandLineModuleManager
;
55 class ICommandLineOptionsModule
;
58 * Runner for command-line trajectory analysis tools.
60 * This class provides static methods to implement a command-line analysis
61 * program, given a TrajectoryAnalysisModule object (or a factory of such).
62 * It takes care of common command-line parameters, initializing and evaluating
63 * selections, and looping over trajectory frames.
66 * \ingroup module_trajectoryanalysis
68 class TrajectoryAnalysisCommandLineRunner
72 * Factory method type for creating a trajectory analysis module.
74 * This method allows the module creation to be postponed to the point
75 * where the module is needed, reducing initialization costs in, e.g.,
76 * the `gmx` binary, and simplifying exception handling.
78 typedef std::function
<TrajectoryAnalysisModulePointer()>
82 * Implements a main() method that runs a given module.
84 * \tparam ModuleType Trajectory analysis module.
85 * \param argc \c argc passed to main().
86 * \param argv \c argv passed to main().
88 * This method abstracts away all the logic required to implement a
89 * main() method in user tools, allowing that to be changed without
90 * requiring changes to the tools themselves.
92 * \p ModuleType should be default-constructible and derive from
93 * TrajectoryAnalysisModule.
95 * Does not throw. All exceptions are caught and handled internally.
97 template <class ModuleType
>
98 static int runAsMain(int argc
, char *argv
[])
100 return runAsMain(argc
, argv
, &createModule
<ModuleType
>);
103 * Implements a main() method that runs a given module.
105 * \param argc \c argc passed to main().
106 * \param argv \c argv passed to main().
107 * \param factory Function that creates the module on demand.
109 * Implements the template runAsMain(), but can also be used
112 * Does not throw. All exceptions are caught and handled internally.
114 static int runAsMain(int argc
, char *argv
[],
115 const ModuleFactoryMethod
&factory
);
117 * Registers a command-line module that runs a given module.
119 * \param manager Manager to register the module to.
120 * \param name Name of the module to register.
121 * \param description One-line description for the module to register.
122 * \param factory Function that creates the module on demand.
124 * \p name and \p descriptions must be string constants or otherwise
125 * stay valid for the duration of the program execution.
127 static void registerModule(CommandLineModuleManager
*manager
,
128 const char *name
, const char *description
,
129 const ModuleFactoryMethod
&factory
);
131 * Create a command-line module that runs the provided analysis module.
133 * \param[in] module Module to run.
134 * \returns Command-line module that runs the provided analysis
136 * \throws std::bad_alloc if out of memory.
138 * This is mainly provided for testing purposes that want to bypass
139 * CommandLineModuleManager.
141 static std::unique_ptr
<ICommandLineOptionsModule
>
142 createModule(TrajectoryAnalysisModulePointer module
);
145 // Prevent instantiation.
146 TrajectoryAnalysisCommandLineRunner() {}
149 * Creates a trajectory analysis module of a given type.
151 * \tparam ModuleType Module to create.
153 template <class ModuleType
>
154 static TrajectoryAnalysisModulePointer
createModule()
156 return TrajectoryAnalysisModulePointer(new ModuleType());