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
40 #include "gromacs/legacyheaders/pbc.h"
41 #include "gromacs/legacyheaders/vec.h"
43 #include "gromacs/analysisdata/analysisdata.h"
44 #include "gromacs/analysisdata/modules/plot.h"
45 #include "gromacs/options/basicoptions.h"
46 #include "gromacs/options/filenameoption.h"
47 #include "gromacs/options/options.h"
48 #include "gromacs/selection/selection.h"
49 #include "gromacs/selection/selectionoption.h"
50 #include "gromacs/trajectoryanalysis/analysissettings.h"
51 #include "gromacs/utility/exceptions.h"
52 #include "gromacs/utility/stringutil.h"
57 namespace analysismodules
60 const char Distance::name[] = "distance";
61 const char Distance::shortDescription[] =
62 "Calculate distances";
65 : TrajectoryAnalysisModule(name, shortDescription),
66 avem_(new AnalysisDataAverageModule())
68 data_.setColumnCount(4);
69 registerAnalysisDataset(&data_, "distance");
79 Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
81 static const char *const desc[] = {
82 "g_dist can calculate the distance between two positions as",
83 "a function of time. The total distance and its",
84 "x, y and z components are plotted."
87 options->setDescription(concatenateStrings(desc));
89 options->addOption(FileNameOption("o").filetype(eftPlot).outputFile()
90 .store(&fnDist_).defaultBasename("dist")
91 .description("Computed distances"));
92 options->addOption(SelectionOption("select").required().valueCount(2)
98 Distance::initAnalysis(const TrajectoryAnalysisSettings &settings,
99 const TopologyInformation & /*top*/)
101 if (sel_[0].posCount() != 1)
103 GMX_THROW(InvalidInputError("The first selection does not define a single position"));
105 if (sel_[1].posCount() != 1)
107 GMX_THROW(InvalidInputError("The second selection does not define a single position"));
110 data_.addModule(avem_);
111 AnalysisDataPlotModulePointer plotm_(new AnalysisDataPlotModule());
112 plotm_->setSettings(settings.plotSettings());
113 plotm_->setFileName(fnDist_);
114 plotm_->setTitle("Distance");
115 plotm_->setXAxisIsTime();
116 plotm_->setYLabel("Distance (nm)");
117 data_.addModule(plotm_);
122 Distance::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
123 TrajectoryAnalysisModuleData *pdata)
125 AnalysisDataHandle dh = pdata->dataHandle(data_);
126 const Selection &sel1 = pdata->parallelSelection(sel_[0]);
127 const Selection &sel2 = pdata->parallelSelection(sel_[1]);
130 const SelectionPosition &p1 = sel1.position(0);
131 const SelectionPosition &p2 = sel2.position(0);
135 pbc_dx(pbc, p1.x(), p2.x(), dx);
139 rvec_sub(p1.x(), p2.x(), dx);
142 dh.startFrame(frnr, fr.time);
144 dh.setPoints(1, 3, dx);
150 Distance::finishAnalysis(int /*nframes*/)
156 Distance::writeOutput()
158 fprintf(stderr, "Average distance: %f\n", avem_->average(0));
159 fprintf(stderr, "Std. deviation: %f\n", avem_->stddev(0));
162 } // namespace analysismodules