3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
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.
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.
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.
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.
29 * For more info, check our website at http://www.gromacs.org
33 * Implements gmx::analysismodules::Distance.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36 * \ingroup module_trajectoryanalysis
47 #include "gromacs/analysisdata/analysisdata.h"
48 #include "gromacs/analysisdata/modules/plot.h"
49 #include "gromacs/options/basicoptions.h"
50 #include "gromacs/options/filenameoption.h"
51 #include "gromacs/options/options.h"
52 #include "gromacs/selection/selection.h"
53 #include "gromacs/selection/selectionoption.h"
54 #include "gromacs/trajectoryanalysis/analysissettings.h"
55 #include "gromacs/utility/exceptions.h"
56 #include "gromacs/utility/stringutil.h"
61 namespace analysismodules
64 const char Distance::name[] = "distance";
65 const char Distance::shortDescription[] =
66 "Calculate distances";
69 : options_(name, shortDescription), avem_(new AnalysisDataAverageModule())
71 data_.setColumnCount(4);
72 registerAnalysisDataset(&data_, "distance");
82 Distance::initOptions(TrajectoryAnalysisSettings *settings)
84 static const char *const desc[] = {
85 "g_dist can calculate the distance between two positions as",
86 "a function of time. The total distance and its",
87 "x, y and z components are plotted."
90 options_.setDescription(concatenateStrings(desc));
92 options_.addOption(FileNameOption("o").filetype(eftPlot).outputFile()
93 .store(&fnDist_).defaultValue("dist"));
94 options_.addOption(SelectionOption("select").required().valueCount(2)
101 Distance::initAnalysis(const TrajectoryAnalysisSettings &settings,
102 const TopologyInformation & /*top*/)
104 if (sel_[0].posCount() != 1)
106 GMX_THROW(InvalidInputError("The first selection does not define a single position"));
108 if (sel_[1].posCount() != 1)
110 GMX_THROW(InvalidInputError("The second selection does not define a single position"));
113 data_.addModule(avem_);
114 AnalysisDataPlotModulePointer plotm_(new AnalysisDataPlotModule());
115 plotm_->setSettings(settings.plotSettings());
116 plotm_->setFileName(fnDist_);
117 plotm_->setTitle("Distance");
118 plotm_->setXAxisIsTime();
119 plotm_->setYLabel("Distance (nm)");
120 data_.addModule(plotm_);
125 Distance::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
126 TrajectoryAnalysisModuleData *pdata)
128 AnalysisDataHandle dh = pdata->dataHandle(data_);
129 const Selection &sel1 = pdata->parallelSelection(sel_[0]);
130 const Selection &sel2 = pdata->parallelSelection(sel_[1]);
133 const SelectionPosition &p1 = sel1.position(0);
134 const SelectionPosition &p2 = sel2.position(0);
138 pbc_dx(pbc, p1.x(), p2.x(), dx);
142 rvec_sub(p1.x(), p2.x(), dx);
145 dh.startFrame(frnr, fr.time);
147 dh.setPoints(1, 3, dx);
153 Distance::finishAnalysis(int /*nframes*/)
159 Distance::writeOutput()
161 fprintf(stderr, "Average distance: %f\n", avem_->average(0));
162 fprintf(stderr, "Std. deviation: %f\n", avem_->stddev(0));
165 } // namespace analysismodules