Code beautification with uncrustify
[alexxy/gromacs.git] / src / programs / gmx / legacymodules.cpp
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11  * Copyright (c) 2001-2009, The GROMACS development team,
12  * check out http://www.gromacs.org for more information.
13
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * If you want to redistribute modifications, please consider that
20  * scientific software is very special. Version control is crucial -
21  * bugs must be traceable. We will be happy to consider code for
22  * inclusion in the official distribution, but derived work must not
23  * be called official GROMACS. Details are found in the README & COPYING
24  * files - if they are missing, get the official version at www.gromacs.org.
25  *
26  * To help us fund GROMACS development, we humbly ask that you cite
27  * the papers on the package - you can find them in the top README file.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \internal \brief
32  * Implements command-line modules for pre-5.0 binaries.
33  *
34  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
35  */
36 #include "legacymodules.h"
37
38 #include "gromacs/commandline/cmdlinemodule.h"
39 #include "gromacs/commandline/cmdlinemodulemanager.h"
40 #include "gromacs/onlinehelp/helpwritercontext.h"
41 #include "gromacs/utility/exceptions.h"
42
43 #include "gromacs/legacyheaders/gmx_ana.h"
44
45 namespace
46 {
47
48 /*! \internal \brief
49  * Command-line module for wrapping pre-5.0 binaries.
50  *
51  * Implements a gmx::CommandLineModuleInterface, given a function with
52  * C/C++ main signature.
53  */
54 class LegacyCmdLineWrapper : public gmx::CommandLineModuleInterface
55 {
56     public:
57         //! Function pointer type for the main function of the module.
58         typedef int (*MainFunction)(int argc, char *argv[]);
59
60         /*! \brief
61          * Convenience function for creating and registering a module.
62          *
63          * \param[in] manager  Module manager to which to register the module.
64          * \param[in] main     Main function to wrap.
65          * \param[in] name     Name for the new module.
66          * \param[in] shortDescription One-line description for the new module.
67          */
68         static void registerModule(gmx::CommandLineModuleManager *manager,
69                                    MainFunction main, const char *name,
70                                    const char *shortDescription)
71         {
72             gmx::CommandLineModulePointer module(
73                     new LegacyCmdLineWrapper(main, name, shortDescription));
74             manager->addModule(gmx::move(module));
75         }
76
77         /*! \brief
78          * Creates a wrapper module for the given main function.
79          *
80          * \see registerModule()
81          */
82         LegacyCmdLineWrapper(MainFunction main, const char *name,
83                              const char *shortDescription)
84             : main_(main), name_(name), shortDescription_(shortDescription)
85         {
86         }
87
88         virtual const char *name() const
89         {
90             return name_;
91         }
92         virtual const char *shortDescription() const
93         {
94             return shortDescription_;
95         }
96
97         virtual int run(int argc, char *argv[]);
98         virtual void writeHelp(const gmx::HelpWriterContext &context) const;
99
100     private:
101         MainFunction            main_;
102         const char             *name_;
103         const char             *shortDescription_;
104
105 };
106
107 int LegacyCmdLineWrapper::run(int argc, char *argv[])
108 {
109     return main_(argc, argv);
110 }
111
112 void LegacyCmdLineWrapper::writeHelp(const gmx::HelpWriterContext &context) const
113 {
114     if (context.outputFormat() != gmx::eHelpOutputFormat_Console)
115     {
116         GMX_THROW(gmx::NotImplementedError(
117                           "Command-line help is not implemented for this output format"));
118     }
119     char *argv[2];
120     // TODO: The constness should not be cast away.
121     argv[0] = const_cast<char *>(name_);
122     argv[1] = const_cast<char *>("-h");
123     main_(2, argv);
124 }
125
126 } // namespace
127
128 void registerLegacyModules(gmx::CommandLineModuleManager *manager)
129 {
130     LegacyCmdLineWrapper::registerModule(manager, &gmx_do_dssp, "do_dssp",
131                                          "Assign secondary structure and calculate solvent accessible surface area");
132     LegacyCmdLineWrapper::registerModule(manager, &gmx_editconf, "editconf",
133                                          "Convert and manipulates structure files");
134     LegacyCmdLineWrapper::registerModule(manager, &gmx_eneconv, "eneconv",
135                                          "Convert energy files");
136     LegacyCmdLineWrapper::registerModule(manager, &gmx_genbox, "genbox",
137                                          "Solvate a system");
138     LegacyCmdLineWrapper::registerModule(manager, &gmx_genconf, "genconf",
139                                          "Multiply a conformation in 'random' orientations");
140     LegacyCmdLineWrapper::registerModule(manager, &gmx_genion, "genion",
141                                          "Generate monoatomic ions on energetically favorable positions");
142     LegacyCmdLineWrapper::registerModule(manager, &gmx_genpr, "genrestr",
143                                          "Generate position restraints or distance restraints for index groups");
144     LegacyCmdLineWrapper::registerModule(manager, &gmx_make_edi, "make_edi",
145                                          "Generate input files for essential dynamics sampling");
146     LegacyCmdLineWrapper::registerModule(manager, &gmx_make_ndx, "make_ndx",
147                                          "Make index files");
148     LegacyCmdLineWrapper::registerModule(manager, &gmx_mk_angndx, "mk_angndx",
149                                          "Generate index files for 'gmx angle'");
150     LegacyCmdLineWrapper::registerModule(manager, &gmx_trjcat, "trjcat",
151                                          "Concatenate trajectory files");
152     LegacyCmdLineWrapper::registerModule(manager, &gmx_trjconv, "trjconv",
153                                          "Convert and manipulates trajectory files");
154     LegacyCmdLineWrapper::registerModule(manager, &gmx_trjorder, "trjorder",
155                                          "Order molecules according to their distance to a group");
156     LegacyCmdLineWrapper::registerModule(manager, &gmx_xpm2ps, "xpm2ps",
157                                          "Convert XPM (XPixelMap) matrices to postscript or XPM");
158
159     // TODO: Include remaining binaries from src/tools/.
160     // These are commented out below, and have some issues to consider how to
161     // best handle them.
162     LegacyCmdLineWrapper::registerModule(manager, &gmx_anadock, "anadock",
163                                          "Cluster structures from Autodock runs");
164     LegacyCmdLineWrapper::registerModule(manager, &gmx_anaeig, "anaeig",
165                                          "Analyze eigenvectors/normal modes");
166     LegacyCmdLineWrapper::registerModule(manager, &gmx_analyze, "analyze",
167                                          "Analyze data sets");
168     LegacyCmdLineWrapper::registerModule(manager, &gmx_g_angle, "angle",
169                                          "Calculate distributions and correlations for angles and dihedrals");
170     LegacyCmdLineWrapper::registerModule(manager, &gmx_bar, "bar",
171                                          "Calculate free energy difference estimates through Bennett's acceptance ratio");
172     LegacyCmdLineWrapper::registerModule(manager, &gmx_bond, "bond",
173                                          "Calculate distances between atoms and bond length distributions");
174     LegacyCmdLineWrapper::registerModule(manager, &gmx_bundle, "bundle",
175                                          "Analyze bundles of axes, e.g., helices");
176     LegacyCmdLineWrapper::registerModule(manager, &gmx_chi, "chi",
177                                          "Calculate everything you want to know about chi and other dihedrals");
178     LegacyCmdLineWrapper::registerModule(manager, &gmx_cluster, "cluster",
179                                          "Cluster structures");
180     LegacyCmdLineWrapper::registerModule(manager, &gmx_clustsize, "clustsize",
181                                          "Calculate size distributions of atomic clusters");
182     LegacyCmdLineWrapper::registerModule(manager, &gmx_confrms, "confrms",
183                                          "Fit two structures and calculates the RMSD");
184     LegacyCmdLineWrapper::registerModule(manager, &gmx_covar, "covar",
185                                          "Calculate and diagonalize the covariance matrix");
186     LegacyCmdLineWrapper::registerModule(manager, &gmx_current, "current",
187                                          "Calculate dielectric constants and charge autocorrelation function");
188     LegacyCmdLineWrapper::registerModule(manager, &gmx_density, "density",
189                                          "Calculate the density of the system");
190     LegacyCmdLineWrapper::registerModule(manager, &gmx_densmap, "densmap",
191                                          "Calculate 2D planar or axial-radial density maps");
192     LegacyCmdLineWrapper::registerModule(manager, &gmx_densorder, "densorder",
193                                          "Calculate surface fluctuations");
194     LegacyCmdLineWrapper::registerModule(manager, &gmx_dielectric, "dielectric",
195                                          "Calculate frequency dependent dielectric constants");
196     LegacyCmdLineWrapper::registerModule(manager, &gmx_dipoles, "dipoles",
197                                          "Compute the total dipole plus fluctuations");
198     LegacyCmdLineWrapper::registerModule(manager, &gmx_disre, "disre",
199                                          "Analyze distance restraints");
200     LegacyCmdLineWrapper::registerModule(manager, &gmx_dist, "dist",
201                                          "Calculate distances between centers of mass of two groups");
202     LegacyCmdLineWrapper::registerModule(manager, &gmx_dos, "dos",
203                                          "Analyze density of states and properties based on that");
204     LegacyCmdLineWrapper::registerModule(manager, &gmx_dyecoupl, "dyecoupl",
205                                          "Extract dye dynamics from trajectories");
206     LegacyCmdLineWrapper::registerModule(manager, &gmx_dyndom, "dyndom",
207                                          "Interpolate and extrapolate structure rotations");
208     LegacyCmdLineWrapper::registerModule(manager, &gmx_enemat, "enemat",
209                                          "Extract an energy matrix from an energy file");
210     LegacyCmdLineWrapper::registerModule(manager, &gmx_energy, "energy",
211                                          "Writes energies to xvg files and display averages");
212     LegacyCmdLineWrapper::registerModule(manager, &gmx_filter, "filter",
213                                          "Frequency filter trajectories, useful for making smooth movies");
214     LegacyCmdLineWrapper::registerModule(manager, &gmx_gyrate, "gyrate",
215                                          "Calculate the radius of gyration");
216     LegacyCmdLineWrapper::registerModule(manager, &gmx_h2order, "h2order",
217                                          "Compute the orientation of water molecules");
218     LegacyCmdLineWrapper::registerModule(manager, &gmx_hbond, "hbond",
219                                          "Compute and analyze hydrogen bonds");
220     LegacyCmdLineWrapper::registerModule(manager, &gmx_helix, "helix",
221                                          "Calculate basic properties of alpha helices");
222     LegacyCmdLineWrapper::registerModule(manager, &gmx_helixorient, "helixorient",
223                                          "Calculate local pitch/bending/rotation/orientation inside helices");
224     LegacyCmdLineWrapper::registerModule(manager, &gmx_hydorder, "hydorder",
225                                          "Compute tetrahedrality parameters around a given atom");
226     LegacyCmdLineWrapper::registerModule(manager, &gmx_kinetics, "kinetics",
227                                          "Analyze kinetic constants from properties based on the Eyring model");
228     LegacyCmdLineWrapper::registerModule(manager, &gmx_lie, "lie",
229                                          "Estimate free energy from linear combinations");
230     LegacyCmdLineWrapper::registerModule(manager, &gmx_mdmat, "mdmat",
231                                          "Calculate residue contact maps");
232     LegacyCmdLineWrapper::registerModule(manager, &gmx_mindist, "mindist",
233                                          "Calculate the minimum distance between two groups");
234     LegacyCmdLineWrapper::registerModule(manager, &gmx_morph, "morph",
235                                          "Interpolate linearly between conformations");
236     LegacyCmdLineWrapper::registerModule(manager, &gmx_msd, "msd",
237                                          "Calculates mean square displacements");
238     LegacyCmdLineWrapper::registerModule(manager, &gmx_nmeig, "nmeig",
239                                          "Diagonalize the Hessian for normal mode analysis");
240     LegacyCmdLineWrapper::registerModule(manager, &gmx_nmens, "nmens",
241                                          "Generate an ensemble of structures from the normal modes");
242     LegacyCmdLineWrapper::registerModule(manager, &gmx_nmtraj, "nmtraj",
243                                          "Generate a virtual oscillating trajectory from an eigenvector");
244     LegacyCmdLineWrapper::registerModule(manager, &gmx_options, "options",
245                                          NULL);
246     LegacyCmdLineWrapper::registerModule(manager, &gmx_order, "order",
247                                          "Compute the order parameter per atom for carbon tails");
248     //LegacyCmdLineWrapper::registerModule(manager, &gmx_pme_error, "pme_error",
249     //        "Estimate the error of using PME with a given input file");
250     LegacyCmdLineWrapper::registerModule(manager, &gmx_polystat, "polystat",
251                                          "Calculate static properties of polymers");
252     LegacyCmdLineWrapper::registerModule(manager, &gmx_potential, "potential",
253                                          "Calculate the electrostatic potential across the box");
254     LegacyCmdLineWrapper::registerModule(manager, &gmx_principal, "principal",
255                                          "Calculate principal axes of inertia for a group of atoms");
256     LegacyCmdLineWrapper::registerModule(manager, &gmx_rama, "rama",
257                                          "Compute Ramachandran plots");
258     LegacyCmdLineWrapper::registerModule(manager, &gmx_rdf, "rdf",
259                                          "Calculate radial distribution functions");
260     LegacyCmdLineWrapper::registerModule(manager, &gmx_rms, "rms",
261                                          "Calculate RMSDs with a reference structure and RMSD matrices");
262     LegacyCmdLineWrapper::registerModule(manager, &gmx_rmsdist, "rmsdist",
263                                          "Calculate atom pair distances averaged with power -2, -3 or -6");
264     LegacyCmdLineWrapper::registerModule(manager, &gmx_rmsf, "rmsf",
265                                          "Calculate atomic fluctuations");
266     LegacyCmdLineWrapper::registerModule(manager, &gmx_rotacf, "rotacf",
267                                          "Calculate the rotational correlation function for molecules");
268     LegacyCmdLineWrapper::registerModule(manager, &gmx_rotmat, "rotmat",
269                                          "Plot the rotation matrix for fitting to a reference structure");
270     LegacyCmdLineWrapper::registerModule(manager, &gmx_saltbr, "saltbr",
271                                          "Compute salt bridges");
272     LegacyCmdLineWrapper::registerModule(manager, &gmx_sans, "sans",
273                                          "Compute the small angle neutron scattering spectra");
274     LegacyCmdLineWrapper::registerModule(manager, &gmx_sas, "sas",
275                                          "Compute solvent accessible surface area");
276     LegacyCmdLineWrapper::registerModule(manager, &gmx_saxs, "saxs",
277                                          "Calculates SAXS structure factors based on Cromer's method");
278     LegacyCmdLineWrapper::registerModule(manager, &gmx_sgangle, "sgangle",
279                                          "Compute the angle and distance between two groups");
280     LegacyCmdLineWrapper::registerModule(manager, &gmx_sham, "sham",
281                                          "Compute free energies or other histograms from histograms");
282     LegacyCmdLineWrapper::registerModule(manager, &gmx_sigeps, "sigeps",
283                                          "Convert c6/12 or c6/cn combinations to and from sigma/epsilon");
284     LegacyCmdLineWrapper::registerModule(manager, &gmx_sorient, "sorient",
285                                          "Analyze solvent orientation around solutes");
286     LegacyCmdLineWrapper::registerModule(manager, &gmx_spatial, "spatial",
287                                          "Calculate the spatial distribution function");
288     LegacyCmdLineWrapper::registerModule(manager, &gmx_spol, "spol",
289                                          "Analyze solvent dipole orientation and polarization around solutes");
290     LegacyCmdLineWrapper::registerModule(manager, &gmx_tcaf, "tcaf",
291                                          "Calculate viscosities of liquids");
292     LegacyCmdLineWrapper::registerModule(manager, &gmx_traj, "traj",
293                                          "Plot x, v, f, box, temperature and rotational energy from trajectories");
294     //LegacyCmdLineWrapper::registerModule(manager, &gmx_tune_pme, "tune_pme",
295     //        "Time mdrun as a function of PME nodes to optimize settings");
296     LegacyCmdLineWrapper::registerModule(manager, &gmx_vanhove, "vanhove",
297                                          "Compute Van Hove correlation functions");
298     LegacyCmdLineWrapper::registerModule(manager, &gmx_velacc, "velacc",
299                                          "Calculate velocity autocorrelation functions");
300     LegacyCmdLineWrapper::registerModule(manager, &gmx_wham, "wham",
301                                          "Perform weighted histogram analysis after umbrella sampling");
302     LegacyCmdLineWrapper::registerModule(manager, &gmx_wheel, "wheel",
303                                          "Plot helical wheels");
304
305     // TODO: Also include binaries from other directories than src/tools/:
306     //        "g_protonate|Protonate structures");
307     //        "g_x2top|Generate a primitive topology from coordinates ");
308     //        "g_xrama|Show animated Ramachandran plots");
309     //        "gmxcheck|Check and compare files");
310     //        "gmxdump|Make binary files human readable");
311     //        "grompp|Make a run input file");
312     //        "mdrun|finds a potential energy minimum and calculates the Hessian");
313     //        "mdrun|performs a simulation, do a normal mode analysis or an energy minimization");
314     //        "mdrun|with -rerun (re)calculates energies for trajectory frames");
315     //        "ngmx|Display a trajectory");
316     //        "pdb2gmx|Convert coordinate files to topology and FF-compliant coordinate files");
317     //        "tpbconv|Make a run input file for restarting a crashed run");
318 }