/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
*/
#include "distance.h"
+#include <string>
+
#include "gromacs/legacyheaders/pbc.h"
#include "gromacs/legacyheaders/vec.h"
#include "gromacs/analysisdata/analysisdata.h"
+#include "gromacs/analysisdata/modules/average.h"
+#include "gromacs/analysisdata/modules/histogram.h"
#include "gromacs/analysisdata/modules/plot.h"
#include "gromacs/options/basicoptions.h"
#include "gromacs/options/filenameoption.h"
#include "gromacs/selection/selection.h"
#include "gromacs/selection/selectionoption.h"
#include "gromacs/trajectoryanalysis/analysissettings.h"
+#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/stringutil.h"
namespace analysismodules
{
-const char Distance::name[] = "distance";
-const char Distance::shortDescription[] =
- "Calculate distances between pairs of positions";
+namespace
+{
+
+class Distance : public TrajectoryAnalysisModule
+{
+ public:
+ Distance();
+
+ virtual void initOptions(Options *options,
+ TrajectoryAnalysisSettings *settings);
+ virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
+ const TopologyInformation &top);
+
+ virtual void analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
+ TrajectoryAnalysisModuleData *pdata);
+
+ virtual void finishAnalysis(int nframes);
+ virtual void writeOutput();
+
+ private:
+ SelectionList sel_;
+ std::string fnAverage_;
+ std::string fnAll_;
+ std::string fnXYZ_;
+ std::string fnHistogram_;
+ std::string fnAllStats_;
+ double meanLength_;
+ double lengthDev_;
+ double binWidth_;
+
+ AnalysisData distances_;
+ AnalysisData xyz_;
+ AnalysisDataAverageModulePointer summaryStatsModule_;
+ AnalysisDataAverageModulePointer allStatsModule_;
+ AnalysisDataFrameAverageModulePointer averageModule_;
+ AnalysisDataSimpleHistogramModulePointer histogramModule_;
+
+ // Copy and assign disallowed by base.
+};
Distance::Distance()
- : TrajectoryAnalysisModule(name, shortDescription),
+ : TrajectoryAnalysisModule(DistanceInfo::name, DistanceInfo::shortDescription),
meanLength_(0.1), lengthDev_(1.0), binWidth_(0.001)
{
summaryStatsModule_.reset(new AnalysisDataAverageModule());
}
-Distance::~Distance()
-{
-}
-
-
void
Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
{
static const char *const desc[] = {
- "[TT]gmx distance[tt] calculates distances between pairs of positions",
+ "[THISMODULE] calculates distances between pairs of positions",
"as a function of time. Each selection specifies an independent set",
"of distances to calculate. Each selection should consist of pairs",
"of positions, and the distances are computed between positions 1-2,",
"each individual distance, calculated over the frames."
};
- options->setDescription(concatenateStrings(desc));
+ options->setDescription(desc);
options->addOption(FileNameOption("oav").filetype(eftPlot).outputFile()
.store(&fnAverage_).defaultBasename("distave")
}
-namespace
-{
-
/*! \brief
* Checks that selections conform to the expectations of the tool.
*/
}
}
-} // namespace
-
void
Distance::initAnalysis(const TrajectoryAnalysisSettings &settings,
plotm->setTitle("Average distance");
plotm->setXAxisIsTime();
plotm->setYLabel("Distance (nm)");
- // TODO: Add legends
+ for (size_t g = 0; g < sel_.size(); ++g)
+ {
+ plotm->appendLegend(sel_[g].name());
+ }
averageModule_->addModule(plotm);
}
{
AnalysisDataPlotModulePointer plotm(
new AnalysisDataPlotModule(settings.plotSettings()));
- plotm->setFileName(fnAll_);
+ plotm->setFileName(fnXYZ_);
plotm->setTitle("Distance");
plotm->setXAxisIsTime();
plotm->setYLabel("Distance (nm)");
plotm->setTitle("Distance histogram");
plotm->setXLabel("Distance (nm)");
plotm->setYLabel("Probability");
- // TODO: Add legends
+ for (size_t g = 0; g < sel_.size(); ++g)
+ {
+ plotm->appendLegend(sel_[g].name());
+ }
histogramModule_->averager().addModule(plotm);
}
plotm->setTitle("Statistics for individual distances");
plotm->setXLabel("Distance index");
plotm->setYLabel("Average/standard deviation (nm)");
- // TODO: Add legends
+ for (size_t g = 0; g < sel_.size(); ++g)
+ {
+ plotm->appendLegend(std::string(sel_[g].name()) + " avg");
+ plotm->appendLegend(std::string(sel_[g].name()) + " std.dev.");
+ }
// TODO: Consider whether this output format is the best possible.
allStatsModule_->addModule(plotm);
}
}
}
+} // namespace
+
+const char DistanceInfo::name[] = "distance";
+const char DistanceInfo::shortDescription[] =
+ "Calculate distances between pairs of positions";
+
+TrajectoryAnalysisModulePointer DistanceInfo::create()
+{
+ return TrajectoryAnalysisModulePointer(new Distance);
+}
+
} // namespace analysismodules
} // namespace gmx