2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2009,2010, 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.
36 * \brief API for calculation of histograms with error estimates.
38 * The API is documented in more detail on a separate page:
41 * The functions within this file can be used and developed independently of
42 * the other parts of the library.
43 * Other parts of the library do not reference these functions.
55 /** Type of histogram. */
61 * Use gmx_histogram_increment() or gmx_histogram_increment_bin()
66 * Weighted histogram where different points contribute different amounts.
68 * Use gmx_histogram_add() or gmx_histogram_add_to_bin() to sample.
72 * Calculate averages within each bin.
74 * Use gmx_histogram_add_item() or gmx_histogram_add_item_to_bin() to sample.
79 /** Whether bins are centered at integer values. */
80 #define HIST_INTEGERBINS 1
81 /** Whether the values outside the range should be included in the histogram. */
83 /** Whether the initialization used binwidths. */
84 #define HIST_INITBW 128
86 /** Stores data for a histogram. */
87 typedef struct gmx_histogram_t gmx_histogram_t;
89 /*! \name Initialization functions
92 /** Initialize calculation of a histogram. */
94 gmx_histogram_create(gmx_histogram_t **h, e_histogram_t type, int nbins);
95 /** Initialize calculation of a histogram for a range. */
97 gmx_histogram_create_range(gmx_histogram_t **h, e_histogram_t type,
98 real start, real end, real binw, gmx_bool bIntegerBins);
99 /** Clears the bins in the histogram. */
101 gmx_histogram_clear(gmx_histogram_t *h);
102 /** Frees the memory allocated for a histogram. */
104 gmx_histogram_free(gmx_histogram_t *h);
105 /** Sets histogram range using a starting point and a bin width. */
107 gmx_histogram_set_binwidth(gmx_histogram_t *h, real start, real binw);
108 /** Sets histogram range using endpoint values. */
110 gmx_histogram_set_range(gmx_histogram_t *h, real start, real end);
111 /** Sets histogram bins to center at integer values. */
113 gmx_histogram_set_integerbins(gmx_histogram_t *h, gmx_bool bIntegerBins);
114 /** Sets histogram to include outlying values in the bins at the edges. */
116 gmx_histogram_set_all(gmx_histogram_t *h, gmx_bool bAll);
117 /** Sets block size for histogram averaging. */
119 gmx_histogram_set_blocksize(gmx_histogram_t *h, int bsize);
120 /** Sets output file for block histograms. */
122 gmx_histogram_set_block_output(gmx_histogram_t *h, FILE *fp);
125 /*! \name Access functions
128 /** Finds the histogram bin corresponding to a value. */
130 gmx_histogram_find_bin(gmx_histogram_t *h, real pos);
131 /** Returns the number of bins in a histogram. */
133 gmx_histogram_get_nbins(gmx_histogram_t *h);
134 /** Returns the bin width of a histogram. */
136 gmx_histogram_get_binwidth(gmx_histogram_t *h);
137 /** Returns the value of the histogram at a certain position. */
139 gmx_histogram_get_value(gmx_histogram_t *h, real pos, double *val, double *err);
140 /** Returns the value of the histogram in a certain bin. */
142 gmx_histogram_get_bin_value(gmx_histogram_t *h, int bin, double *val, double *err);
143 /** Returns an array of values for the histogram. */
145 gmx_histogram_get_values(gmx_histogram_t *h);
146 /** Returns an array of error values for the histogram. */
148 gmx_histogram_get_errors(gmx_histogram_t *h);
151 /*! \name Sampling functions
154 /** Increments the count in a histogram bin corresponding to \p pos. */
156 gmx_histogram_increment(gmx_histogram_t *h, real pos);
157 /** Increments the count in a histogram bin. */
159 gmx_histogram_increment_bin(gmx_histogram_t *h, int bin);
161 /** Adds a value to a histogram bin corresponding to \p pos. */
163 gmx_histogram_add(gmx_histogram_t *h, real pos, double value);
164 /** Adds a value to a histogram bin. */
166 gmx_histogram_add_to_bin(gmx_histogram_t *h, int bin, double value);
168 /** Adds a value to a histogram bin corresponding to \p pos. */
170 gmx_histogram_add_item(gmx_histogram_t *h, real pos, double value);
171 /** Adds a value to a histogram bin. */
173 gmx_histogram_add_item_to_bin(gmx_histogram_t *h, int bin, double value);
175 /** Finishes histogram sampling for a frame. */
177 gmx_histogram_finish_frame(gmx_histogram_t *h);
178 /** Normalizes a histogram. */
180 gmx_histogram_finish(gmx_histogram_t *h);
184 /*! \name Post-processing functions
187 /** Creates a new histogram with double the binwidth. */
189 gmx_histogram_resample_dblbw(gmx_histogram_t **dest, gmx_histogram_t *src,
190 gmx_bool bIntegerBins);
191 /** Makes a clone of a histogram. */
193 gmx_histogram_clone(gmx_histogram_t **dest, gmx_histogram_t *src);
194 /** Normalizes a histogram to a probability distribution. */
196 gmx_histogram_normalize_prob(gmx_histogram_t *h);
197 /** Scales a histogram with a custom normalization factor. */
199 gmx_histogram_scale(gmx_histogram_t *h, real norm);
200 /** Scales a histogram with a custom non-uniform normalization factor. */
202 gmx_histogram_scale_vec(gmx_histogram_t *h, real norm[]);
203 /** Writes a single histogram to a file. */
205 gmx_histogram_write(FILE *fp, gmx_histogram_t *h, gmx_bool bErrors);
206 /** Writes a set of histograms to a file. */
208 gmx_histogram_write_array(FILE *fp, int n, gmx_histogram_t *h[],
209 gmx_bool bValue, gmx_bool bErrors);
210 /** Writes a set of cumulative histograms to a file. */
212 gmx_histogram_write_cum_array(FILE *fp, int n, gmx_histogram_t *h[],
213 gmx_bool bValue, gmx_bool bErrors);