2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014, 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.
36 * \brief Testing/debugging tool for the selection engine.
38 * \author Teemu Murtola <teemu.murtola@gmail.com>
39 * \ingroup module_trajectoryanalysis
43 #include "gromacs/options/basicoptions.h"
44 #include "gromacs/options/options.h"
45 #include "gromacs/selection/selection.h"
46 #include "gromacs/selection/selectionoption.h"
47 #include "gromacs/trajectoryanalysis/analysismodule.h"
48 #include "gromacs/trajectoryanalysis/analysissettings.h"
49 #include "gromacs/trajectoryanalysis/cmdlinerunner.h"
50 #include "gromacs/utility/arrayref.h"
51 #include "gromacs/utility/exceptions.h"
56 class SelectionTester : public TrajectoryAnalysisModule
60 virtual ~SelectionTester();
62 virtual void initOptions(Options *options,
63 TrajectoryAnalysisSettings *settings);
64 virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
65 const TopologyInformation &top);
67 virtual void analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
68 TrajectoryAnalysisModuleData *pdata);
70 virtual void finishAnalysis(int nframes);
71 virtual void writeOutput();
74 void printSelections();
76 SelectionList selections_;
80 SelectionTester::SelectionTester()
81 : TrajectoryAnalysisModule("testing", "Selection testing and debugging"),
86 SelectionTester::~SelectionTester()
91 SelectionTester::printSelections()
93 fprintf(stderr, "\nSelections:\n");
94 for (size_t g = 0; g < selections_.size(); ++g)
96 selections_[g].printDebugInfo(stderr, nmaxind_);
98 fprintf(stderr, "\n");
102 SelectionTester::initOptions(Options *options,
103 TrajectoryAnalysisSettings * /*settings*/)
105 static const char *const desc[] = {
106 "This is a test program for selections."
109 options->setDescription(desc);
111 options->addOption(SelectionOption("select").storeVector(&selections_)
112 .required().multiValue()
113 .description("Selections to test"));
114 options->addOption(IntegerOption("pmax").store(&nmaxind_)
115 .description("Maximum number of indices to print in lists (-1 = print all)"));
119 SelectionTester::initAnalysis(const TrajectoryAnalysisSettings & /*settings*/,
120 const TopologyInformation & /*top*/)
126 SelectionTester::analyzeFrame(int /*frnr*/, const t_trxframe & /*fr*/, t_pbc * /*pbc*/,
127 TrajectoryAnalysisModuleData * /*pdata*/)
129 fprintf(stderr, "\n");
130 for (size_t g = 0; g < selections_.size(); ++g)
132 const Selection &sel = selections_[g];
135 fprintf(stderr, " Atoms (%d pcs):", sel.atomCount());
137 if (nmaxind_ >= 0 && n > nmaxind_)
141 ConstArrayRef<int> atoms = sel.atomIndices();
142 for (int i = 0; i < n; ++i)
144 fprintf(stderr, " %d", atoms[i]+1);
146 if (n < sel.atomCount())
148 fprintf(stderr, " ...");
150 fprintf(stderr, "\n");
152 fprintf(stderr, " Positions (%d pcs):\n", sel.posCount());
154 if (nmaxind_ >= 0 && n > nmaxind_)
158 for (int i = 0; i < n; ++i)
160 const SelectionPosition &p = sel.position(i);
161 fprintf(stderr, " (%.2f,%.2f,%.2f) r=%d, m=%d, n=%d\n",
162 p.x()[XX], p.x()[YY], p.x()[ZZ],
163 p.refId(), p.mappedId(), p.atomCount());
165 if (n < sel.posCount())
167 fprintf(stderr, " ...\n");
170 fprintf(stderr, "\n");
174 SelectionTester::finishAnalysis(int /*nframes*/)
180 SelectionTester::writeOutput()
187 * The main function for the selection testing tool.
190 main(int argc, char *argv[])
192 return gmx::TrajectoryAnalysisCommandLineRunner::runAsMain<gmx::SelectionTester>(argc, argv);