2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010-2018, The GROMACS development team.
5 * Copyright (c) 2019, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
37 * \brief Testing/debugging tool for the selection engine.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_trajectoryanalysis
44 #include "gromacs/options/basicoptions.h"
45 #include "gromacs/options/ioptionscontainer.h"
46 #include "gromacs/selection/selection.h"
47 #include "gromacs/selection/selectionoption.h"
48 #include "gromacs/trajectoryanalysis/analysismodule.h"
49 #include "gromacs/trajectoryanalysis/analysissettings.h"
50 #include "gromacs/trajectoryanalysis/cmdlinerunner.h"
51 #include "gromacs/utility/arrayref.h"
52 #include "gromacs/utility/exceptions.h"
57 class SelectionTester
: public TrajectoryAnalysisModule
61 ~SelectionTester() override
;
63 void initOptions(IOptionsContainer
* options
, TrajectoryAnalysisSettings
* settings
) override
;
64 void initAnalysis(const TrajectoryAnalysisSettings
& settings
, const TopologyInformation
& top
) override
;
66 void analyzeFrame(int frnr
, const t_trxframe
& fr
, t_pbc
* pbc
, TrajectoryAnalysisModuleData
* pdata
) override
;
68 void finishAnalysis(int nframes
) override
;
69 void writeOutput() override
;
72 void printSelections();
74 SelectionList selections_
;
78 SelectionTester::SelectionTester() : nmaxind_(20) {}
80 SelectionTester::~SelectionTester() {}
82 void SelectionTester::printSelections()
84 fprintf(stderr
, "\nSelections:\n");
85 for (size_t g
= 0; g
< selections_
.size(); ++g
)
87 selections_
[g
].printDebugInfo(stderr
, nmaxind_
);
89 fprintf(stderr
, "\n");
92 void SelectionTester::initOptions(IOptionsContainer
* options
, TrajectoryAnalysisSettings
* settings
)
94 static const char* const desc
[] = { "This is a test program for selections." };
96 settings
->setHelpText(desc
);
99 SelectionOption("select").storeVector(&selections_
).required().multiValue().description("Selections to test"));
100 options
->addOption(IntegerOption("pmax").store(&nmaxind_
).description(
101 "Maximum number of indices to print in lists (-1 = print all)"));
104 void SelectionTester::initAnalysis(const TrajectoryAnalysisSettings
& /*settings*/,
105 const TopologyInformation
& /*top*/)
110 void SelectionTester::analyzeFrame(int /*frnr*/,
111 const t_trxframe
& /*fr*/,
113 TrajectoryAnalysisModuleData
* /*pdata*/)
115 fprintf(stderr
, "\n");
116 for (size_t g
= 0; g
< selections_
.size(); ++g
)
118 const Selection
& sel
= selections_
[g
];
121 fprintf(stderr
, " Atoms (%d pcs):", sel
.atomCount());
123 if (nmaxind_
>= 0 && n
> nmaxind_
)
127 ArrayRef
<const int> atoms
= sel
.atomIndices();
128 for (int i
= 0; i
< n
; ++i
)
130 fprintf(stderr
, " %d", atoms
[i
] + 1);
132 if (n
< sel
.atomCount())
134 fprintf(stderr
, " ...");
136 fprintf(stderr
, "\n");
138 fprintf(stderr
, " Positions (%d pcs):\n", sel
.posCount());
140 if (nmaxind_
>= 0 && n
> nmaxind_
)
144 for (int i
= 0; i
< n
; ++i
)
146 const SelectionPosition
& p
= sel
.position(i
);
147 fprintf(stderr
, " (%.2f,%.2f,%.2f) r=%d, m=%d, n=%d\n", p
.x()[XX
], p
.x()[YY
],
148 p
.x()[ZZ
], p
.refId(), p
.mappedId(), p
.atomCount());
150 if (n
< sel
.posCount())
152 fprintf(stderr
, " ...\n");
155 fprintf(stderr
, "\n");
158 void SelectionTester::finishAnalysis(int /*nframes*/)
163 void SelectionTester::writeOutput() {}
168 * The main function for the selection testing tool.
170 int main(int argc
, char* argv
[])
172 return gmx::TrajectoryAnalysisCommandLineRunner::runAsMain
<gmx::SelectionTester
>(argc
, argv
);