/usr/include/gromacs/analysisdata/modules/histogram.h is in libgromacs-dev 5.1.2-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | /*
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2010,2011,2012,2013,2014, 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
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* GROMACS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GROMACS; if not, see
* http://www.gnu.org/licenses, or write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* If you want to redistribute modifications to GROMACS, please
* consider that scientific software is very special. Version
* control is crucial - bugs must be traceable. We will be happy to
* consider code for inclusion in the official distribution, but
* derived work must not be called official GROMACS. Details are found
* in the README & COPYING files - if they are missing, get the
* official version at http://www.gromacs.org.
*
* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out http://www.gromacs.org.
*/
/*! \file
* \brief
* Declares analysis data modules for calculating histograms.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \inpublicapi
* \ingroup module_analysisdata
*/
#ifndef GMX_ANALYSISDATA_MODULES_HISTOGRAM_H
#define GMX_ANALYSISDATA_MODULES_HISTOGRAM_H
#include <boost/shared_ptr.hpp>
#include "gromacs/analysisdata/abstractdata.h"
#include "gromacs/analysisdata/arraydata.h"
#include "gromacs/analysisdata/datamodule.h"
namespace gmx
{
class AnalysisHistogramSettings;
/*! \brief
* Provides "named parameter" idiom for constructing histograms.
*
* \see histogramFromBins()
* \see histogramFromRange()
*
* Methods in this class do not throw.
*
* \inpublicapi
* \ingroup module_analysisdata
*/
class AnalysisHistogramSettingsInitializer
{
public:
/*! \brief
* Creates an empty initializer.
*
* Should not be called directly, but histogramFromRange() or
* histogramFromBins() should be used instead.
*/
AnalysisHistogramSettingsInitializer();
/*! \brief
* Sets the first bin location.
*
* Typically should not be called directly, but through
* histogramFromBins().
*/
AnalysisHistogramSettingsInitializer &start(real min)
{ min_ = min; return *this; }
/*! \brief
* Sets the number of bins in the histogram.
*
* If only the first bin location is specified, this value is required
* (and automatically provided if histogramFromBins() is used).
* If both the first and last bins are specified, either this value or
* binWidth() is required.
*/
AnalysisHistogramSettingsInitializer &binCount(int binCount)
{ binCount_ = binCount; return *this; }
/*! \brief
* Sets the first and last bin locations.
*
* Typically should not be called directly, but through
* histogramFromRange().
*/
AnalysisHistogramSettingsInitializer &range(real min, real max)
{ min_ = min; max_ = max; return *this; }
/*! \brief
* Sets the bin width of the histogram.
*
* If only the first bin location is specified, this value is required
* (and automatically provided if histogramFromBins() is used).
* If both the first and last bins are specified, either this value or
* binCount() is required.
* If a bin width is provided with both first and last bin locations,
* and the given bin width does not divide the range exactly, the last
* bin location is adjusted to match.
*/
AnalysisHistogramSettingsInitializer &binWidth(real binWidth)
{ binWidth_ = binWidth; return *this; }
/*! \brief
* Indicate that first and last bin locations to specify bin centers.
*
* If set, the first and last bin locations are interpreted as bin
* centers.
* If not set (the default), the first and last bin locations are
* interpreted as the edges of the whole histogram.
*
* Cannot be specified together with roundRange().
*/
AnalysisHistogramSettingsInitializer &integerBins(bool enabled = true)
{ bIntegerBins_ = enabled; return *this; }
/*! \brief
* Round first and last bin locations.
*
* If set, the resulting histogram will cover the range specified, but
* the actual bin locations will be rounded such that the edges fall
* on multiples of the bin width.
* Only implemented when both first and last bin location and bin width
* are defined.
* Cannot be specified together with integerBins() or with binCount().
*/
AnalysisHistogramSettingsInitializer &roundRange(bool enabled = true)
{ bRoundRange_ = enabled; return *this; }
/*! \brief
* Sets the histogram to match all values.
*
* If set, the histogram behaves as if the bins at the ends extended to
* +-infinity.
*/
AnalysisHistogramSettingsInitializer &includeAll(bool enabled = true)
{ bIncludeAll_ = enabled; return *this; }
private:
real min_;
real max_;
real binWidth_;
int binCount_;
bool bIntegerBins_;
bool bRoundRange_;
bool bIncludeAll_;
friend class AnalysisHistogramSettings;
};
/*! \brief
* Initializes a histogram using a range and a bin width.
*
* Does not throw.
*
* \inpublicapi
*/
inline AnalysisHistogramSettingsInitializer
histogramFromRange(real min, real max)
{
return AnalysisHistogramSettingsInitializer().range(min, max);
}
/*! \brief
* Initializes a histogram using bin width and the number of bins.
*
* Does not throw.
*
* \inpublicapi
*/
inline AnalysisHistogramSettingsInitializer
histogramFromBins(real start, int nbins, real binwidth)
{
return AnalysisHistogramSettingsInitializer()
.start(start).binCount(nbins).binWidth(binwidth);
}
/*! \brief
* Contains parameters that specify histogram bin locations.
*
* Methods in this class do not throw.
*
* \inpublicapi
* \ingroup module_analysisdata
*/
class AnalysisHistogramSettings
{
public:
//! Initializes undefined parameters.
AnalysisHistogramSettings();
/*! \brief
* Initializes parameters based on a named parameter object.
*
* This constructor is not explicit to allow initialization of
* histograms directly from AnalysisHistogramSettingsInitializer:
* \code
gmx::AnalysisDataSimpleHistogramModule *hist =
new gmx::AnalysisDataSimpleHistogramModule(
histogramFromRange(0.0, 5.0).binWidth(0.5));
* \endcode
*/
AnalysisHistogramSettings(const AnalysisHistogramSettingsInitializer &settings);
//! Returns the left edge of the first bin.
real firstEdge() const { return firstEdge_; }
//! Returns the right edge of the first bin.
real lastEdge() const { return lastEdge_; }
//! Returns the number of bins in the histogram.
int binCount() const { return binCount_; }
//! Returns the width of a bin in the histogram.
real binWidth() const { return binWidth_; }
//! Whether values beyond the edges are mapped to the edge bins.
bool includeAll() const { return bAll_; }
//! Returns a zero-based bin index for a value, or -1 if not in range.
int findBin(real y) const;
private:
real firstEdge_;
real lastEdge_;
real binWidth_;
real inverseBinWidth_;
int binCount_;
bool bAll_;
};
class AbstractAverageHistogram;
//! Smart pointer to manage an AbstractAverageHistogram object.
typedef boost::shared_ptr<AbstractAverageHistogram>
AverageHistogramPointer;
/*! \brief
* Base class for representing histograms averaged over frames.
*
* The averaging module for a per-frame histogram is always created by the
* histogram module class (e.g., AnalysisDataSimpleHistogramModule), and can be
* accessed using, e.g., AnalysisDataSimpleHistogramModule::averager().
* The user can alter some properties of the average histogram directly, but
* the main use of the object is to postprocess the histogram once the
* calculation is finished.
*
* This class can represent multiple histograms in one object: each column in
* the data is an independent histogram.
* The X values correspond to center of the bins, except for a cumulative
* histogram made with makeCumulative().
*
* \inpublicapi
* \ingroup module_analysisdata
*/
class AbstractAverageHistogram : public AbstractAnalysisArrayData
{
public:
virtual ~AbstractAverageHistogram();
//! Returns bin properties for the histogram.
const AnalysisHistogramSettings &settings() const { return settings_; }
/*! \brief
* Creates a copy of the histogram with double the bin width.
*
* \param[in] bIntegerBins If `true`, the first bin in the result will
* cover the first bin from the source. Otherwise, the first bin
* will cover first two bins from the source.
* \throws std::bad_alloc if out of memory.
*
* The caller is responsible of deleting the returned object.
*/
AverageHistogramPointer resampleDoubleBinWidth(bool bIntegerBins) const;
/*! \brief
* Creates a deep copy of the histogram.
*
* \throws std::bad_alloc if out of memory.
*
* The returned histogram is not necessarily of the same dynamic type
* as the original object, but contains the same data from the point of
* view of the AbstractAverageHistogram interface.
*
* The caller is responsible of deleting the returned object.
*/
AverageHistogramPointer clone() const;
//! Normalizes the histogram such that the integral over it is one.
void normalizeProbability();
/*! \brief
* Makes the histograms cumulative by summing up each bin to all bins
* after it.
*
* The X values in the data are adjusted such that they match the right
* edges of bins instead of bin centers.
*/
void makeCumulative();
//! Scales a single histogram by a uniform scaling factor.
void scaleSingle(int index, real factor);
//! Scales all histograms by a uniform scaling factor.
void scaleAll(real factor);
//! Scales the value of each bin by a different scaling factor.
void scaleAllByVector(real factor[]);
/*! \brief
* Notifies attached modules of the histogram data.
*
* After this function has been called, it is no longer possible to
* alter the histogram.
*/
void done() { AbstractAnalysisArrayData::valuesReady(); }
protected:
/*! \brief
* Creates a histogram module with undefined bins.
*
* Bin parameters must be defined with init() before data input is
* started.
*/
AbstractAverageHistogram();
//! Creates a histogram module with defined bin parameters.
explicit AbstractAverageHistogram(const AnalysisHistogramSettings &settings);
/*! \brief
* (Re)initializes the histogram from settings.
*/
void init(const AnalysisHistogramSettings &settings);
private:
AnalysisHistogramSettings settings_;
// Copy and assign disallowed by base.
};
/*! \brief
* Data module for per-frame histograms.
*
* Output data contains the same number of frames and data sets as the input
* data. Each frame contains the histogram(s) for the points in that frame.
* Each input data set is processed independently into the corresponding output
* data set. Missing values are ignored.
* All input columns for a data set are averaged into the same histogram.
* The number of columns for all data sets equals the number of bins in the
* histogram.
*
* The histograms are accumulated as 64-bit integers within a frame and summed
* in double precision across frames, even if the output data is in single
* precision.
*
* \inpublicapi
* \ingroup module_analysisdata
*/
class AnalysisDataSimpleHistogramModule : public AbstractAnalysisData,
public AnalysisDataModuleParallel
{
public:
/*! \brief
* Creates a histogram module with undefined bins.
*
* Bin parameters must be defined with init() before data input is
* started.
*/
AnalysisDataSimpleHistogramModule();
//! Creates a histogram module with defined bin parameters.
explicit AnalysisDataSimpleHistogramModule(const AnalysisHistogramSettings &settings);
virtual ~AnalysisDataSimpleHistogramModule();
/*! \brief
* (Re)initializes the histogram from settings.
*/
void init(const AnalysisHistogramSettings &settings);
/*! \brief
* Returns the average histogram over all frames.
*
* Can be called already before the histogram is calculated to
* customize the way the average histogram is calculated.
*
* \see AbstractAverageHistogram
*/
AbstractAverageHistogram &averager();
//! Returns bin properties for the histogram.
const AnalysisHistogramSettings &settings() const;
virtual int frameCount() const;
virtual int flags() const;
virtual bool parallelDataStarted(
AbstractAnalysisData *data,
const AnalysisDataParallelOptions &options);
virtual void frameStarted(const AnalysisDataFrameHeader &header);
virtual void pointsAdded(const AnalysisDataPointSetRef &points);
virtual void frameFinished(const AnalysisDataFrameHeader &header);
virtual void frameFinishedSerial(int frameIndex);
virtual void dataFinished();
private:
virtual AnalysisDataFrameRef tryGetDataFrameInternal(int index) const;
virtual bool requestStorageInternal(int nframes);
class Impl;
PrivateImplPointer<Impl> impl_;
// Copy and assign disallowed by base.
};
/*! \brief
* Data module for per-frame weighted histograms.
*
* Output data contains the same number of frames and data sets as the input
* data. Each frame contains the histogram(s) for the points in that frame,
* interpreted such that the first column passed to pointsAdded() determines
* the bin and the rest give weights to be added to that bin (input data should
* have at least two colums, and at least two columns should be added at the
* same time).
* Each input data set is processed independently into the corresponding output
* data set.
* All input columns for a data set are averaged into the same histogram.
* The number of columns for all data sets equals the number of bins in the
* histogram.
*
* The histograms are accumulated in double precision, even if the output data
* is in single precision.
*
* \inpublicapi
* \ingroup module_analysisdata
*/
class AnalysisDataWeightedHistogramModule : public AbstractAnalysisData,
public AnalysisDataModuleParallel
{
public:
//! \copydoc AnalysisDataSimpleHistogramModule::AnalysisDataSimpleHistogramModule()
AnalysisDataWeightedHistogramModule();
//! \copydoc AnalysisDataSimpleHistogramModule::AnalysisDataSimpleHistogramModule(const AnalysisHistogramSettings &)
explicit AnalysisDataWeightedHistogramModule(const AnalysisHistogramSettings &settings);
virtual ~AnalysisDataWeightedHistogramModule();
//! \copydoc AnalysisDataSimpleHistogramModule::init()
void init(const AnalysisHistogramSettings &settings);
//! \copydoc AnalysisDataSimpleHistogramModule::averager()
AbstractAverageHistogram &averager();
//! \copydoc AnalysisDataSimpleHistogramModule::settings()
const AnalysisHistogramSettings &settings() const;
virtual int frameCount() const;
virtual int flags() const;
virtual bool parallelDataStarted(
AbstractAnalysisData *data,
const AnalysisDataParallelOptions &options);
virtual void frameStarted(const AnalysisDataFrameHeader &header);
virtual void pointsAdded(const AnalysisDataPointSetRef &points);
virtual void frameFinished(const AnalysisDataFrameHeader &header);
virtual void frameFinishedSerial(int frameIndex);
virtual void dataFinished();
private:
virtual AnalysisDataFrameRef tryGetDataFrameInternal(int index) const;
virtual bool requestStorageInternal(int nframes);
class Impl;
PrivateImplPointer<Impl> impl_;
// Copy and assign disallowed by base.
};
/*! \brief
* Data module for bin averages.
*
* Output data contains one row for each bin; see AbstractAverageHistogram.
* Output data contains one column for each input data set.
* The value in a column is the average over all frames of that data set for
* that bin.
* The input data is interpreted such that the first column passed to
* pointsAdded() determines the bin and the rest give values to be added to
* that bin (input data should have at least two colums, and at least two
* columns should be added at the same time).
* All input columns for a data set are averaged into the same histogram.
*
* \inpublicapi
* \ingroup module_analysisdata
*/
class AnalysisDataBinAverageModule : public AbstractAnalysisArrayData,
public AnalysisDataModuleSerial
{
public:
//! \copydoc AnalysisDataSimpleHistogramModule::AnalysisDataSimpleHistogramModule()
AnalysisDataBinAverageModule();
//! \copydoc AnalysisDataSimpleHistogramModule::AnalysisDataSimpleHistogramModule(const AnalysisHistogramSettings &)
explicit AnalysisDataBinAverageModule(const AnalysisHistogramSettings &settings);
virtual ~AnalysisDataBinAverageModule();
//! \copydoc AnalysisDataSimpleHistogramModule::init()
void init(const AnalysisHistogramSettings &settings);
//! \copydoc AnalysisDataSimpleHistogramModule::settings()
const AnalysisHistogramSettings &settings() const;
virtual int flags() const;
virtual void dataStarted(AbstractAnalysisData *data);
virtual void frameStarted(const AnalysisDataFrameHeader &header);
virtual void pointsAdded(const AnalysisDataPointSetRef &points);
virtual void frameFinished(const AnalysisDataFrameHeader &header);
virtual void dataFinished();
private:
class Impl;
PrivateImplPointer<Impl> impl_;
// Copy and assign disallowed by base.
};
//! Smart pointer to manage an AnalysisDataSimpleHistogramModule object.
typedef boost::shared_ptr<AnalysisDataSimpleHistogramModule>
AnalysisDataSimpleHistogramModulePointer;
//! Smart pointer to manage an AnalysisDataWeightedHistogramModule object.
typedef boost::shared_ptr<AnalysisDataWeightedHistogramModule>
AnalysisDataWeightedHistogramModulePointer;
//! Smart pointer to manage an AnalysisDataBinAverageModule object.
typedef boost::shared_ptr<AnalysisDataBinAverageModule>
AnalysisDataBinAverageModulePointer;
} // namespace gmx
#endif
|