2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2011,2012,2013,2014,2015, 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.
46 #include <gromacs/utility/gmxomp.h>
48 #include <gromacs/trajectoryanalysis.h>
54 * Template class to serve as a basis for user analysis tools.
56 class AnalysisTemplate : public TrajectoryAnalysisModule
61 virtual void initOptions(IOptionsContainer *options,
62 TrajectoryAnalysisSettings *settings);
63 virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
64 const TopologyInformation &top);
66 virtual void analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
67 TrajectoryAnalysisModuleData *pdata);
69 virtual void finishAnalysis(int nframes);
70 virtual void writeOutput();
79 AnalysisNeighborhood nb_;
82 AnalysisDataAverageModulePointer avem_;
86 std::vector< std::pair< int, int > > fitting_pairs;
87 std::vector< std::vector < RVec > > trajectory;
88 std::vector< std::vector < RVec > > fitting_temp;
89 std::vector< long double > noise;
90 std::vector< int > index;
91 long double epsi = 0.15;
92 long double fitting_prec = 0.0001;
100 AnalysisTemplate::AnalysisTemplate()
103 registerAnalysisDataset(&data_, "avedist");
108 AnalysisTemplate::initOptions(IOptionsContainer *options,
109 TrajectoryAnalysisSettings *settings)
111 static const char *const desc[] = {
112 "This is a template for writing your own analysis tools for",
113 "GROMACS. The advantage of using GROMACS for this is that you",
114 "have access to all information in the topology, and your",
115 "program will be able to handle all types of coordinates and",
116 "trajectory files supported by GROMACS. In addition,",
117 "you get a lot of functionality for free from the trajectory",
118 "analysis library, including support for flexible dynamic",
119 "selections. Go ahead an try it![PAR]",
120 "To get started with implementing your own analysis program,",
121 "follow the instructions in the README file provided.",
122 "This template implements a simple analysis programs that calculates",
123 "average distances from a reference group to one or more",
127 settings->setHelpText(desc);
129 /*options->addOption(FileNameOption("o")
130 .filetype(eftPlot).outputFile()
131 .store(&fnDist_).defaultBasename("avedist")
132 .description("Average distances from reference group"));
134 options->addOption(SelectionOption("reference")
135 .store(&refsel_).required()
136 .description("Reference group to calculate distances from"));*/
137 options->addOption(SelectionOption("select")
138 .store(&selec).required()
139 .description("Atoms that are considered as part of the excluded volume"));
141 /* options->addOption(DoubleOption("cutoff").store(&cutoff_)
142 .description("Cutoff for distance calculation (0 = no cutoff)"));
144 settings->setFlag(TrajectoryAnalysisSettings::efRequireTop);*/
147 // -s '/home/toluk/Рабочий стол/reca_rd_2008/reca_rd.md.non-sol.tpr' -f '/home/toluk/Рабочий стол/reca_rd_2008/reca_rd.md.non-sol.xtc' -select 'name CA' -dt 500
148 // -s '/home/toluk/Data/dusc_trna/EcDusC_tRNA_FMN.md_npt.non-sol.tpr' -f '/home/toluk/Data/dusc_trna/EcDusC_tRNA_FMN.md_npt.non-sol.xtc' -select 'name CA' -dt 500
151 AnalysisTemplate::initAnalysis(const TrajectoryAnalysisSettings &settings,
152 const TopologyInformation & /*top*/)
154 //std::cout << "select start\n";
156 ConstArrayRef< int > atomind = selec.atomIndices();
157 for (ConstArrayRef< int >::iterator ai = atomind.begin(); (ai < atomind.end()); ai++) {
158 index.push_back(*ai);
160 //std::cout << "select finish\n";
165 AnalysisTemplate::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
166 TrajectoryAnalysisModuleData *pdata)
168 //std::cout << "trajectory start\n";
169 trajectory.resize(frames + 1);
170 trajectory[frames].resize(index.size());
171 for (int i = 0; i < index.size(); i++) {
172 trajectory[frames][i] = fr.x[index[i]];
175 //std::cout << "trajectory finish\n";
180 AnalysisTemplate::finishAnalysis(int /*nframes*/)
182 std::cout << "analys start\n";
184 fitting_pairs.resize(0);
185 for (int i = 0; i < index.size(); i++) {
186 fitting_pairs.push_back(std::make_pair (i, i));
188 //std::cout << "001\n";
189 long double noise_mid = 1;
191 std::vector< std::pair< int, int > > get_out;
192 //freopen("/home/toluk/Data/dusc_trna/output.txt", "w+", stdout);
197 std::cout << "start iteration\n";
198 noise.resize(index.size(), 0);
199 fitting_temp = trajectory;
201 for (int i = 1; i < frames; i++) {
202 new_fit(trajectory[0], fitting_temp[i], fitting_pairs, index.size(), fitting_prec);
204 std::cout << i << " / " << frames << "\n";
206 for (int j = 0; j < fitting_pairs.size(); j++) {
207 noise[fitting_pairs[j].first] += norm(trajectory[0][fitting_pairs[j].first] - fitting_temp[i][fitting_pairs[j].first]);
213 for (int i = 0; i < index.size(); i++) {
214 noise[fitting_pairs[i].first] /= (frames - 1);
215 noise_mid += noise[fitting_pairs[i].first];
217 noise_mid /= fitting_pairs.size();
219 get_out = fitting_pairs;
220 fitting_pairs.resize(0);
221 for (int i = 0; i < index.size(); i++) {
222 fitting_pairs.push_back(std::make_pair (i, i));
225 for (int i = 0; i < fitting_pairs.size(); i++) {
226 if (noise[fitting_pairs[i].first] > noise_mid) {
227 fitting_pairs.erase(fitting_pairs.begin() + i);
232 if (get_out == fitting_pairs) {
236 std::cout << noise_mid << " | " << fitting_pairs.size() << "\n";
237 for (int i = 0; i < fitting_pairs.size(); i++) {
238 std::cout << fitting_pairs[i].first << " ";
241 for (int i = 0; i < get_out.size(); i++) {
242 std::cout << get_out[i].first << " ";
244 for (int i = 0; i < fitting_pairs.size(); i++) {
245 std::cout << noise[get_out[i].first] << " ";
248 std::cout << "finish iteration\n";
256 while (noise_mid > epsi) {
257 std::cout << "start iteration\n";
258 noise.resize(index.size(), 0);
259 fitting_temp = trajectory;
261 for (int i = 1; i < frames; i++) {
262 new_fit(trajectory[0], fitting_temp[i], fitting_pairs, index.size(), fitting_prec);
264 std::cout << i << " / " << frames << "\n";
266 for (int j = 0; j < index.size(); j++) {
267 noise[j] += norm(trajectory[0][j] - fitting_temp[i][j]);
272 for (int i = 0; i < index.size(); i++) {
273 noise[i] /= (frames - 1);
275 for (int i = 0; i < fitting_pairs.size(); i++) {
276 noise_mid += noise[fitting_pairs[i].first];
279 noise_mid /= fitting_pairs.size();
281 for (int i = 0; i < fitting_pairs.size(); i++) {
282 if (noise[fitting_pairs[i].first] > noise_mid) {
283 fitting_pairs.erase(fitting_pairs.begin() + i);
288 std::cout << noise_mid << " | " << fitting_pairs.size() << "\n";
289 std::cout << "finish iteration\n";
293 fitting_pairs.resize(0);
294 for (int i = 0; i < noise.size(); i++) {
295 if (noise[i] <= epsi) {
296 fitting_pairs.push_back(std::make_pair (i, i));
302 std::cout << "analys finish\n";
307 AnalysisTemplate::writeOutput()
309 std::cout << "output start\n";
310 std::cout << "number of iterations: " << iter_count << "\n";
311 for (int i = 0; i < fitting_pairs.size(); i++) {
312 std::cout << fitting_pairs[i].first << " ";
315 for (int i = 0; i < fitting_pairs.size(); i++) {
316 std::cout << noise[fitting_pairs[i].first] << " ";
318 std::cout << "output finish\n";
322 * The main function for the analysis template.
325 main(int argc, char *argv[])
327 return gmx::TrajectoryAnalysisCommandLineRunner::runAsMain<AnalysisTemplate>(argc, argv);