18#include "colvarvalue.h"
71 std::vector<colvar *>
cv;
77 inline size_t address(std::vector<int>
const &ix)
const
80 for (
size_t i = 0; i <
nd; i++) {
81 addr += ix[i]*
static_cast<size_t>(
nxc[i]);
84 cvmodule->
error(
"Error: exceeding bounds in colvar_grid.\n", COLVARS_BUG_ERROR);
132 inline std::vector<int>
const &
sizes()
const
138 inline void set_sizes(std::vector<int>
const &new_sizes)
159 int setup(std::vector<int>
const &nx_i,
161 size_t const &mult_i = 1)
164 cvmodule->
log(
"Allocating grid: multiplicity = "+
cvm::to_str(mult_i)+
179 for (
int i =
nd-1; i >= 0; i--) {
183 return COLVARS_ERROR;
202 return setup(this->
nx, T(), this->mult);
252 this->
setup(nx_i, t, mult_i);
261 bool add_extra_bin =
false,
262 std::shared_ptr<const colvar_grid_params> params =
nullptr,
263 std::string config = std::string())
267 this->init_from_colvars(colvars, mult_i, add_extra_bin, params, config);
273 colvar_grid(std::string
const &filename,
size_t mult_i = 1);
275 int init_from_colvars(std::vector<colvar *>
const &colvars,
277 bool add_extra_bin =
false,
278 std::shared_ptr<const colvar_grid_params> params =
nullptr,
279 std::string config = std::string())
282 cvmodule->
log(
"Reading grid configuration from collective variables.\n");
292 cvmodule->
log(
"Allocating a grid for "+
cvm::to_str(colvars.size())+
293 " collective variables, multiplicity = "+
cvm::to_str(mult_i)+
".\n");
296 for (i = 0; i <
nd; i++) {
299 "constructed for scalar variables. "
300 "ABF and histogram can not be used; metadynamics "
301 "can be used with useGrids disabled.\n", COLVARS_INPUT_ERROR);
302 return COLVARS_ERROR;
305 if (
cv[i]->width <= 0.0) {
307 "variable with negative or zero width.\n", COLVARS_INPUT_ERROR);
308 return COLVARS_ERROR;
321 if (i > 0 &&
cv[i-1] ==
cv[i]) {
331 if (!config.empty()) {
336 cvm::error_static(
"Error: init_from_colvars was passed both a grid config and a template grid.", COLVARS_BUG_ERROR);
337 return COLVARS_BUG_ERROR;
342 if (params->nd !=
nd) {
343 cvm::error_static(
"Trying to initialize grid from template with wrong dimension (" +
346 return COLVARS_ERROR;
355 for (i = 0; i <
nd; i++) {
374 this->init_from_boundaries();
375 return this->
setup();
378 int init_from_boundaries()
381 cvmodule->
log(
"Configuring grid dimensions from colvars boundaries.\n");
396 int nbins_round = (int)(nbins+0.5);
399 cvmodule->
log(
"Warning: grid interval("+
402 ") is not commensurate to its bin width("+
405 (nbins_round *
widths[i]);
409 cvmodule->
log(
"Number of points is "+
cvm::to_str((
int) nbins_round)+
412 nx.push_back(nbins_round);
420 inline void wrap(std::vector<int> & ix)
const
422 for (
size_t i = 0; i <
nd; i++) {
424 ix[i] = (ix[i] +
nx[i]) %
nx[i];
426 if (ix[i] < 0 || ix[i] >=
nx[i]) {
427 cvm::error_static(
"Trying to wrap illegal index vector (non-PBC) for a grid point: "
440 for (
size_t i = 0; i <
nd; i++) {
442 ix[i] = (ix[i] +
nx[i]) %
nx[i];
443 }
else if (ix[i] < 0 || ix[i] >=
nx[i]) {
452 inline bool wrap_to_edge(std::vector<int> & ix, std::vector<int> & edge_bin)
const
456 for (
size_t i = 0; i <
nd; i++) {
458 ix[i] = (ix[i] +
nx[i]) %
nx[i];
460 }
else if (ix[i] < 0) {
463 }
else if (ix[i] >=
nx[i]) {
465 edge_bin[i] =
nx[i] - 1;
483 for (
size_t i = 0; i <
nd; i++) {
500 cv[i]->actual_value().vector1d_value[iv] :
501 cv[i]->
value().vector1d_value[iv], i);
533 if (bin_index < 0) bin_index=0;
534 if (bin_index >=
int(
nx[i])) bin_index=int(
nx[i])-1;
535 return (
int) bin_index;
558 return new_offset.
real_value + new_width * (0.5 + i_bin);
564 size_t const &imult = 0)
590 if (other_grid.
multiplicity() != this->multiplicity()) {
592 "different multiplicity.\n");
596 if (other_grid.
data.size() != this->data.size()) {
598 "different size.\n");
602 for (
size_t i = 0; i <
data.size(); i++) {
614 if (other_grid.
multiplicity() != this->multiplicity()) {
616 "different multiplicity.\n");
620 if (other_grid.
data.size() != this->data.size()) {
622 "different size.\n");
627 for (
size_t i = 0; i <
data.size(); i++) {
637 for (
size_t i = 0; i <
data.size(); i++) out_data[i] =
data[i];
646 for (
size_t i = 0; i <
data.size(); i++)
data[i] = in_data[i];
660 inline T
const &
value(std::vector<int>
const &ix,
661 size_t const &imult = 0)
const
667 inline T
const &
value(
size_t i)
const
675 for (
size_t i = 0; i <
nt; i++)
683 for (
size_t i = 0; i <
nt; i++)
690 for (
size_t i = 0; i <
nt; i++)
700 for (
size_t i = 0; i <
nd; i++) {
711 for (
size_t i = 0; i <
nd; i++) {
722 for (
size_t i = 0; i <
nd; i++) {
732 bool skip_hard_boundaries =
false)
735 for (
size_t i = 0; i <
nd; i++) {
763 if (other_grid.
multiplicity() != this->multiplicity()) {
765 "different multiplicity.\n");
770 std::vector<cvm::real>
const &gw = this->
widths;
772 std::vector<cvm::real>
const &ogw = other_grid.
widths;
775 std::vector<int> oix = other_grid.
new_index();
778 cvmodule->
log(
"Remapping grid...\n");
781 for (
size_t i = 0; i <
nd; i++) {
792 for (
size_t im = 0; im <
mult; im++) {
799 cvmodule->
log(
"Remapping done.\n");
807 if (other_grid.
multiplicity() != this->multiplicity()) {
809 "different multiplicity.\n");
812 if (scale_factor != 1.0)
813 for (
size_t i = 0; i <
data.size(); i++) {
814 data[i] +=
static_cast<T
>(scale_factor * other_grid.
data[i]);
818 for (
size_t i = 0; i <
data.size(); i++) {
827 size_t const &imult = 0)
const
829 return value(ix, imult);
837 size_t const &imult = 0,
858 return std::vector<int> (
nd, 0);
863 inline bool index_ok(std::vector<int>
const &ix)
const
865 for (
size_t i = 0; i <
nd; i++) {
866 if ( (ix[i] < 0) || (ix[i] >=
int(
nx[i])) )
874 inline void incr(std::vector<int> &ix)
const
876 for (
int i = ix.size()-1; i >= 0; i--) {
880 if (ix[i] >=
nx[i]) {
910 for (
size_t i = 0; i <
nd; i++) {
916 widths[i])) > 1.0E-10) ) {
918 "inconsistent with that of its colvars.\n");
929 for (
size_t i = 0; i <
nd; i++) {
939 (
data.size() != other_grid.
data.size()) ) {
941 "two grids that are supposed to be equal, "
942 "aside from the data stored.\n");
961 std::istream &
read_raw(std::istream &is);
979 std::ostream &
write_raw(std::ostream &os,
size_t const buf_size = 3)
const;
987 std::istream &
read_multicol(std::istream &is,
bool add =
false);
991 std::string description =
"grid file",
999 std::string description =
"grid file")
const;
1006 std::string description =
"grid file")
const;
1026 std::shared_ptr<const colvar_grid_params> params =
nullptr);
1029 std::string config);
1063 std::istream &
read_raw(std::istream &is);
1071 std::ostream &
write_raw(std::ostream &os,
size_t const buf_size = 3)
const;
1079 std::istream &
read_multicol(std::istream &is,
bool add =
false);
1083 std::string description =
"grid file",
1091 std::string description =
"grid file")
const;
1098 std::string description =
"grid file")
const;
1103 size_t const &imult = 0,
1109 if (this->has_parent_data) {
1126 for (
size_t i = 0; i <
nd; i++) {
1145 for (i = -radius; i <= radius; i++) {
1155 for (i = -radius; i <= radius; i++) {
1157 for (j = -radius; j <= radius; j++) {
1168 for (i = -radius; i <= radius; i++) {
1170 for (j = -radius; j <= radius; j++) {
1172 for (k = -radius; k <= radius; k++) {
1184 cvm::error_static(
"Error: local_sample_count is not implemented for grids of dimension > 3", COLVARS_NOT_IMPLEMENTED);
1190 return count / nbins;
1200 int n = 0,
int offset = 0)
1203 std::vector<int> ix = ix0;
1208 A0 =
value(ix) + offset;
1211 A1 =
value(ix) + offset;
1215 return (cvmodule->
logn(A1) - cvmodule->
logn(A0))
1218 }
else if (ix[n] > 0 && ix[n] <
nx[n]-1) {
1220 A0 =
value(ix) + offset;
1223 A1 =
value(ix) + offset;
1227 return (cvmodule->
logn(A1) - cvmodule->
logn(A0))
1232 int increment = (ix[n] == 0 ? 1 : -1);
1234 A0 =
value(ix) + offset;
1235 ix[n] += increment; A1 =
value(ix) + offset;
1236 ix[n] += increment; A2 =
value(ix) + offset;
1237 if (A0 * A1 * A2 == 0) {
1240 return (-1.5 * cvmodule->
logn(A0) + 2. * cvmodule->
logn(A1)
1241 - 0.5 * cvmodule->
logn(A2)) * increment /
widths[n];
1254 std::vector<int> ix = ix0;
1266 return (A1 - A0) / (
widths[n] * 2.);
1268 }
else if (ix[n] > 0 && ix[n] <
nx[n]-1) {
1277 return (A1 - A0) / (
widths[n] * 2.);
1281 int increment = (ix[n] == 0 ? 1 : -1);
1284 ix[n] += increment; A1 =
value(ix);
1285 ix[n] += increment; A2 =
value(ix);
1286 return (-1.5 * A0 + 2. * A1
1287 - 0.5 * A2) * increment /
widths[n];
1313 std::shared_ptr<const colvar_grid_params> params =
nullptr,
1314 bool add_extra_bin =
false,
1315 std::string config = std::string());
1323 size_t const &imult = 0)
1353 std::istream &
read_raw(std::istream &is);
1361 std::ostream &
write_raw(std::ostream &os,
size_t const buf_size = 3)
const;
1369 std::istream &
read_multicol(std::istream &is,
bool add =
false);
1373 std::string description =
"grid file",
1381 std::string description =
"grid file")
const;
1388 std::string description =
"grid file")
const;
1397 std::vector<int> ix;
1401 for (n = 0; n < 2; n++) {
1406 ix[1-n]++;
wrap(ix);
1410 grad[n] = 0.5 * (A1 - A0) /
widths[n];
1412 }
else if (
nd == 3) {
1417 for (i = 0; i<2; i++) {
1419 for (j = 0; j<2; j++) {
1421 for (k = 0; k<2; k++) {
1423 p[index++] =
value(ix);
1433 grad[0] = 0.25 * ((p[4] + p[5] + p[6] + p[7]) - (p[0] + p[1] + p[2] + p[3])) /
widths[0];
1435 grad[1] = 0.25 * ((p[2] + p[3] + p[6] + p[7]) - (p[0] + p[1] + p[4] + p[5])) /
widths[1];
1437 grad[2] = 0.25 * ((p[1] + p[3] + p[5] + p[7]) - (p[0] + p[2] + p[4] + p[6])) /
widths[2];
1448 int n = 0,
int offset = 0)
1451 std::vector<int> ix = ix0;
1456 A0 =
value(ix) + offset;
1459 A1 =
value(ix) + offset;
1463 return (cvmodule->
logn(A1) - cvmodule->
logn(A0))
1466 }
else if (ix[n] > 0 && ix[n] <
nx[n]-1) {
1468 A0 =
value(ix) + offset;
1471 A1 =
value(ix) + offset;
1475 return (cvmodule->
logn(A1) - cvmodule->
logn(A0))
1480 int increment = (ix[n] == 0 ? 1 : -1);
1482 A0 =
value(ix) + offset;
1483 ix[n] += increment; A1 =
value(ix) + offset;
1484 ix[n] += increment; A2 =
value(ix) + offset;
1485 if (A0 * A1 * A2 == 0) {
1488 return (-1.5 * cvmodule->
logn(A0) + 2. * cvmodule->
logn(A1)
1489 - 0.5 * cvmodule->
logn(A2)) * increment /
widths[n];
1502 std::vector<int> ix = ix0;
1514 return (A1 - A0) / (
widths[n] * 2.);
1516 }
else if (ix[n] > 0 && ix[n] <
nx[n]-1) {
1529 int increment = (ix[n] == 0 ? 1 : -1);
1532 ix[n] += increment; A1 =
value(ix);
1533 ix[n] += increment; A2 =
value(ix);
1543 size_t const &imult = 0)
const override
1548 "larger than 1 in a scalar data grid.\n");
1563 size_t const &imult = 0,
1564 bool add =
false)
override
1568 "larger than 1 in a scalar data grid.\n");
1636 std::shared_ptr<colvar_grid_count> samples_in =
nullptr,
1637 std::shared_ptr<const colvar_grid_params> params =
nullptr,
1638 std::string config = std::string());
1664 std::istream &
read_raw(std::istream &is);
1672 std::ostream &
write_raw(std::ostream &os,
size_t const buf_size = 3)
const;
1680 std::istream &
read_multicol(std::istream &is,
bool add =
false);
1684 std::string description =
"grid file",
1692 std::string description =
"grid file")
const;
1699 std::string description =
"grid file")
const;
1702 inline void vector_value(std::vector<int>
const &ix, std::vector<cvm::real> &v)
const
1706 int count =
samples->value(ix);
1709 for (
size_t i = 0; i <
mult; i++) {
1710 v[i] = invcount * p[i];
1713 for (
size_t i = 0; i <
mult; i++) {
1718 for (
size_t i = 0; i <
mult; i++) {
1726 inline void acc_value(std::vector<int>
const &ix, std::vector<colvarvalue>
const &values) {
1727 for (
size_t imult = 0; imult <
mult; imult++) {
1728 data[
address(ix) + imult] += values[imult].real_value;
1737 for (
size_t imult = 0; imult <
mult; imult++) {
1747 size_t const &imult = 0)
const override
1751 return ( (s =
samples->value(ix)) > 0) ?
1764 if ( weight <= min_samples ) {
1769 fact = 1.0 / weight;
1792 fact = weight > 0. ? 1. / weight : 0.;
1814 fact = weight > 0. ? 1. / weight : 0.;
1819 for (
size_t imult = 0; imult <
mult; imult++) {
1820 grad[imult] = fact * p[imult];
1829 size_t const &imult = 0,
1830 bool add =
false)
override
1850 if (
nd != 1 ||
nx[0] == 0) {
Colvar_grid derived class to hold counters in discrete n-dim colvar space.
Definition: colvargrid.h:1014
colvar_grid_count()
Default constructor.
Definition: colvargrid.cpp:21
int local_sample_count(int radius)
Return the average number of samples in a given "radius" around current bin Really a hypercube of len...
Definition: colvargrid.h:1121
std::istream & read_raw(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:68
std::string get_state_params() const
Write the current grid parameters to a string.
Definition: colvargrid.cpp:37
cvm::real gradient_finite_diff(const std::vector< int > &ix0, int n=0)
Return the gradient of discrete count from finite differences on the same grid for dimension n (colva...
Definition: colvargrid.h:1250
std::ostream & write_restart(std::ostream &os)
Write all grid parameters and data to a formatted stream.
Definition: colvargrid.cpp:58
std::ostream & write_opendx(std::ostream &os) const
Write the grid data without labels, as they are represented in memory.
Definition: colvargrid.cpp:112
std::ostream & write_raw(std::ostream &os, size_t const buf_size=3) const
Definition: colvargrid.cpp:78
int parse_params(std::string const &conf, colvarparse::Parse_Mode const parse_mode=colvarparse::parse_normal)
Read new grid parameters from a string.
Definition: colvargrid.cpp:42
virtual void value_input(std::vector< int > const &ix, size_t const &t, size_t const &imult=0, bool add=false)
Enter or add a value, but also handle parent grid.
Definition: colvargrid.h:1101
std::istream & read_restart(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:48
std::istream & read_multicol(std::istream &is, bool add=false)
Read a grid written by write_multicol(), incrementin if data is true.
Definition: colvargrid.cpp:89
std::ostream & write_multicol(std::ostream &os) const
Write grid in a format which is both human-readable and gnuplot-friendly.
Definition: colvargrid.cpp:101
cvm::real log_gradient_finite_diff(const std::vector< int > &ix0, int n=0, int offset=0)
Return the log-gradient from finite differences on the same grid for dimension n (colvar_grid_count)
Definition: colvargrid.h:1199
size_t const & new_value(std::vector< int > const &ix)
Get the binned count indexed by ix from the newly read data.
Definition: colvargrid.h:1038
virtual ~colvar_grid_count()
Destructor.
Definition: colvargrid.h:1021
void incr_count(std::vector< int > const &ix)
Increment the counter at given position.
Definition: colvargrid.h:1032
Class for accumulating the gradient of a scalar function on a grid.
Definition: colvargrid.h:1610
std::string get_state_params() const
Write the current grid parameters to a string.
Definition: colvargrid.cpp:369
cvm::real smooth_inverse_weight(cvm::real weight)
Definition: colvargrid.h:1761
void vector_value_smoothed(std::vector< int > const &ix, cvm::real *grad, bool smoothed=true)
Obtain the vector value of the function at ix divided by its number of samples (if the count grid is ...
Definition: colvargrid.h:1801
virtual cvm::real value_output_smoothed(std::vector< int > const &ix, bool smoothed=true)
Return the scalar value of the function at ix divided by its number of samples (if the count grid is ...
Definition: colvargrid.h:1779
void acc_value(std::vector< int > const &ix, std::vector< colvarvalue > const &values)
Accumulate the value.
Definition: colvargrid.h:1726
cvm::real average(bool smoothed=false)
Compute and return average value for a 1D gradient grid.
Definition: colvargrid.h:1848
std::shared_ptr< colvar_grid_count > samples
Provide the sample count by which each binned value should be divided.
Definition: colvargrid.h:1615
std::istream & read_multicol(std::istream &is, bool add=false)
Read a grid written by write_multicol(), incrementin if data is true.
Definition: colvargrid.cpp:421
colvar_grid_gradient()
Default constructor.
Definition: colvargrid.cpp:335
std::ostream & write_restart(std::ostream &os)
Write all grid parameters and data to a formatted stream.
Definition: colvargrid.cpp:390
void write_1D_integral(std::ostream &os)
If the grid is 1-dimensional, integrate it and write the integral to a file (DEPRECATED by the colvar...
Definition: colvargrid.cpp:456
int parse_params(std::string const &conf, colvarparse::Parse_Mode const parse_mode=colvarparse::parse_normal)
Read new grid parameters from a string.
Definition: colvargrid.cpp:374
virtual cvm::real value_output(std::vector< int > const &ix, size_t const &imult=0) const override
Return the value of the function at ix divided by its number of samples (if the count grid is defined...
Definition: colvargrid.h:1746
std::istream & read_raw(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:400
virtual ~colvar_grid_gradient()
Destructor.
Definition: colvargrid.h:1621
virtual void value_input(std::vector< int > const &ix, cvm::real const &new_value, size_t const &imult=0, bool add=false) override
Get the value from a formatted output and transform it into the internal representation (it may have ...
Definition: colvargrid.h:1827
void acc_force(std::vector< int > const &ix, cvm::real const *forces)
Accumulate the gradient based on the force (i.e. sums the opposite of the force)
Definition: colvargrid.h:1736
int full_samples
Parameters for smoothing data with low sampling.
Definition: colvargrid.h:1641
std::ostream & write_raw(std::ostream &os, size_t const buf_size=3) const
Definition: colvargrid.cpp:410
std::ostream & write_multicol(std::ostream &os) const
Write grid in a format which is both human-readable and gnuplot-friendly.
Definition: colvargrid.cpp:433
std::istream & read_restart(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:380
cvm::real grid_rmsd(colvar_grid_gradient const &other_grid) const
Return the RMSD between this grid's data and another one Grids must have the same dimensions.
Definition: colvargrid.cpp:513
void vector_value(std::vector< int > const &ix, std::vector< cvm::real > &v) const
Get a vector with the binned value(s) indexed by ix, normalized if applicable.
Definition: colvargrid.h:1702
std::ostream & write_opendx(std::ostream &os) const
Write the grid data without labels, as they are represented in memory.
Definition: colvargrid.cpp:444
Unified base class for grid of values of a function of several collective variables.
Definition: colvargrid.h:24
size_t nd
Number of dimensions.
Definition: colvargrid.h:28
std::vector< int > nxc
Cumulative number of points along each dimension.
Definition: colvargrid.h:34
std::vector< colvarvalue > lower_boundaries
Lower boundaries of the colvars in this grid.
Definition: colvargrid.h:37
std::vector< cvm::real > widths
Widths of the colvars in this grid.
Definition: colvargrid.h:43
std::vector< colvarvalue > upper_boundaries
Upper boundaries of the colvars in this grid.
Definition: colvargrid.h:40
std::vector< int > nx
Number of points along each dimension.
Definition: colvargrid.h:31
Class for accumulating a scalar function on a grid.
Definition: colvargrid.h:1295
void acc_value(std::vector< int > const &ix, cvm::real const &new_value, size_t const &imult=0)
Accumulate the value.
Definition: colvargrid.h:1321
cvm::real minimum_value() const
Return the lowest value.
Definition: colvargrid.cpp:249
cvm::real gradient_finite_diff(const std::vector< int > &ix0, int n=0)
Return the gradient of discrete count from finite differences on the same grid for dimension n (colva...
Definition: colvargrid.h:1498
std::istream & read_restart(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:163
std::string get_state_params() const
Write the current grid parameters to a string.
Definition: colvargrid.cpp:152
virtual ~colvar_grid_scalar()
Destructor.
Definition: colvargrid.cpp:148
cvm::real minimum_pos_value() const
Return the lowest positive value.
Definition: colvargrid.cpp:258
virtual cvm::real value_output(std::vector< int > const &ix, size_t const &imult=0) const override
Return the value of the function at ix divided by its number of samples (if the count grid is defined...
Definition: colvargrid.h:1542
cvm::real grid_rmsd(colvar_grid_scalar const &other_grid) const
Return the RMSD between this grid's data and another one Grids must have the same dimensions.
Definition: colvargrid.cpp:305
std::ostream & write_opendx(std::ostream &os) const
Write the grid data without labels, as they are represented in memory.
Definition: colvargrid.cpp:227
std::ostream & write_restart(std::ostream &os)
Write all grid parameters and data to a formatted stream.
Definition: colvargrid.cpp:173
std::ostream & write_multicol(std::ostream &os) const
Write grid in a format which is both human-readable and gnuplot-friendly.
Definition: colvargrid.cpp:216
std::istream & read_multicol(std::istream &is, bool add=false)
Read a grid written by write_multicol(), incrementin if data is true.
Definition: colvargrid.cpp:204
cvm::real integral() const
Calculates the integral of the map (uses widths if they are defined)
Definition: colvargrid.cpp:274
int parse_params(std::string const &conf, colvarparse::Parse_Mode const parse_mode=colvarparse::parse_normal)
Read new grid parameters from a string.
Definition: colvargrid.cpp:157
std::ostream & write_raw(std::ostream &os, size_t const buf_size=3) const
Definition: colvargrid.cpp:193
virtual void value_input(std::vector< int > const &ix, cvm::real const &new_value, size_t const &imult=0, bool add=false) override
Enter or add value but also deal with count grid.
Definition: colvargrid.h:1561
cvm::real entropy() const
Assuming that the map is a normalized probability density, calculates the entropy (uses widths if the...
Definition: colvargrid.cpp:288
colvar_grid_scalar()
Default constructor.
Definition: colvargrid.cpp:125
cvm::real maximum_value() const
Return the highest value.
Definition: colvargrid.cpp:239
cvm::real log_gradient_finite_diff(const std::vector< int > &ix0, int n=0, int offset=0)
Return the log-gradient from finite differences on the same grid for dimension n (colvar_grid_scalar)
Definition: colvargrid.h:1447
colvar_grid_count * samples
Provide the associated sample count by which each binned value should be divided.
Definition: colvargrid.h:1300
void vector_gradient_finite_diff(const std::vector< int > &ix0, std::vector< cvm::real > &grad)
Return the gradient of the scalar field from finite differences Input coordinates are those of gradie...
Definition: colvargrid.h:1394
std::istream & read_raw(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:183
Grid of values of a function of several collective variables.
Definition: colvargrid.h:52
int setup()
Allocate data (allow initialization also after construction)
Definition: colvargrid.h:200
std::istream & read_restart(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid_def.h:102
void set_value(size_t i, T const &t)
Set the value at the point with linear address i (for speed)
Definition: colvargrid.h:571
void check_consistency()
Check that the grid information inside (boundaries, widths, ...) is consistent with the current setti...
Definition: colvargrid.h:908
std::string get_state_params() const
Write the current grid parameters to a string.
Definition: colvargrid_def.h:203
std::ostream & write_raw(std::ostream &os, size_t const buf_size=3) const
Definition: colvargrid_def.h:170
int current_bin_scalar_bound(int const i) const
Report the bin corresponding to the current value of variable i and assign first or last bin if out o...
Definition: colvargrid.h:491
std::vector< int > const new_index() const
Get the index corresponding to the "first" bin, to be used as the initial value for an index in loopi...
Definition: colvargrid.h:856
void add_constant(T const &t)
Add a constant to all elements (fast loop)
Definition: colvargrid.h:673
std::vector< size_t > new_data
Newly read data (used for count grids, when adding several grids read from disk)
Definition: colvargrid.h:68
cvm::real value_to_bin_scalar_fraction(colvarvalue const &value, const int i) const
Use the lower boundary and the width to report the fraction of bin beyond value_to_bin_scalar() that ...
Definition: colvargrid.h:519
void incr(std::vector< int > &ix) const
Increment the index, in a way that will make it loop over the whole nd-dimensional array.
Definition: colvargrid.h:874
size_t number_of_points(int const icv=-1) const
Definition: colvargrid.h:122
std::vector< bool > hard_upper_boundaries
Whether some colvars have hard upper boundaries.
Definition: colvargrid.h:100
virtual void value_input(std::vector< int > const &ix, T const &t, size_t const &imult=0, bool add=false)
Get the value from a formatted output and transform it into the internal representation (the two may ...
Definition: colvargrid.h:835
T const & value(size_t i) const
Get the binned value indexed by linear address i.
Definition: colvargrid.h:667
std::vector< int > const get_colvars_index_bound() const
Get the bin indices corresponding to the provided values of the colvars and assign first or last bin ...
Definition: colvargrid.h:719
int current_bin_flat_bound() const
Report the flattened bin address corresponding to the current value of all variables and assign first...
Definition: colvargrid.h:480
size_t mult
Multiplicity of each datum (allow the binning of non-scalar types such as atomic gradients)
Definition: colvargrid.h:59
size_t multiplicity() const
Return the multiplicity of the type used.
Definition: colvargrid.h:144
std::vector< int > const & sizes() const
Get the sizes in each direction.
Definition: colvargrid.h:132
void set_value(std::vector< int > const &ix, T const &t, size_t const &imult=0)
Set the value at the point with index ix.
Definition: colvargrid.h:562
colvarvalue bin_to_value_scalar(int const &i_bin, int const i) const
Use the two boundaries and the width to report the central value corresponding to a bin index.
Definition: colvargrid.h:548
std::vector< T > data
Low-level array of values.
Definition: colvargrid.h:65
void multiply_constant(cvm::real const &a)
Multiply all elements by a scalar constant (fast loop)
Definition: colvargrid.h:681
std::vector< int > const & number_of_points_vec() const
Return the numbers of points in all dimensions.
Definition: colvargrid.h:115
bool index_ok(std::vector< int > const &ix) const
Check that the index is within range in each of the dimensions.
Definition: colvargrid.h:863
cvm::real current_bin_scalar_fraction(int const i) const
Report the fraction of bin beyond current_bin_scalar()
Definition: colvargrid.h:512
bool has_data
Whether this grid has been filled with data or is still empty.
Definition: colvargrid.h:106
void add_grid(colvar_grid< T > const &other_grid, cvm::real scale_factor=1.0)
Add data from another grid of the same type, AND identical definition (boundaries,...
Definition: colvargrid.h:804
std::vector< int > const get_colvars_index(std::vector< colvarvalue > const &values) const
Get the bin indices corresponding to the provided values of the colvars.
Definition: colvargrid.h:697
void check_consistency(colvar_grid< T > const &other_grid)
Check that the grid information inside (boundaries, widths, ...) is consistent with that of another g...
Definition: colvargrid.h:927
colvar_grid(std::vector< int > const &nx_i, T const &t=T(), size_t mult_i=1)
Constructor from explicit grid sizes.
Definition: colvargrid.h:247
int parse_params(std::string const &conf, colvarparse::Parse_Mode const parse_mode=colvarparse::parse_normal)
Read new grid parameters from a string.
Definition: colvargrid_def.h:233
size_t nt
Total number of grid points.
Definition: colvargrid.h:62
T get_value(size_t i) const
Get the value at the point with linear address i (for speed)
Definition: colvargrid.h:577
void reset(T const &t=T())
Reset data (in case the grid is being reused)
Definition: colvargrid.h:206
size_t num_variables() const
Return the number of colvar objects.
Definition: colvargrid.h:109
int setup(std::vector< int > const &nx_i, T const &t=T(), size_t const &mult_i=1)
Allocate data.
Definition: colvargrid.h:159
IST & read_restart_template_(IST &is)
Helper method for read_restart.
Definition: colvargrid_def.h:84
colvar_grid(std::vector< colvar * > const &colvars, T const &t=T(), size_t mult_i=1, bool add_extra_bin=false, std::shared_ptr< const colvar_grid_params > params=nullptr, std::string config=std::string())
Constructor from a vector of colvars or an optional grid config string.
Definition: colvargrid.h:258
colvar_grid(colvar_grid< T > const &g)
"Almost copy-constructor": only copies configuration parameters from another grid,...
Definition: colvargrid.h:230
bool has_parent_data
True if this is a count grid related to another grid of data.
Definition: colvargrid.h:103
std::ostream & write_opendx(std::ostream &os) const
Write the grid data without labels, as they are represented in memory.
Definition: colvargrid_def.h:494
bool wrap_to_edge(std::vector< int > &ix, std::vector< int > &edge_bin) const
Definition: colvargrid.h:452
std::vector< int > const get_colvars_index() const
Get the bin indices corresponding to the current values of the colvars.
Definition: colvargrid.h:708
int current_bin_scalar(int const i, int const iv) const
Report the bin corresponding to the current value of item iv in variable i.
Definition: colvargrid.h:497
void delta_grid(colvar_grid< T > const &other_grid)
Get the change from this to other_grid and store the result in this. this_grid := other_grid - this_g...
Definition: colvargrid.h:587
void request_actual_value(bool b=true)
Request grid to use actual values of extended coords.
Definition: colvargrid.h:150
cvm::real bin_distance_from_boundaries(std::vector< colvarvalue > const &values, bool skip_hard_boundaries=false)
Get the minimal distance (in number of bins) from the boundaries; a negative number is returned if th...
Definition: colvargrid.h:731
int value_to_bin_scalar_bound(colvarvalue const &value, const int i) const
Use the lower boundary and the width to report which bin the provided value is in and assign first or...
Definition: colvargrid.h:527
int current_bin_scalar(int const i) const
Report the bin corresponding to the current value of variable i.
Definition: colvargrid.h:473
std::istream & read_raw(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid_def.h:157
std::vector< bool > hard_lower_boundaries
Whether some colvars have hard lower boundaries.
Definition: colvargrid.h:97
T const & value(std::vector< int > const &ix, size_t const &imult=0) const
Get the binned value indexed by ix, or the first of them if the multiplicity is larger than 1.
Definition: colvargrid.h:660
std::vector< bool > use_actual_value
Do we request actual value (for extended-system colvars)?
Definition: colvargrid.h:74
size_t raw_data_num() const
Size of the data as they are represented in memory.
Definition: colvargrid.h:655
size_t address(std::vector< int > const &ix) const
Get the low-level index corresponding to an index.
Definition: colvargrid.h:77
void remove_small_values(cvm::real const &a)
Assign values that are smaller than scalar constant the latter value (fast loop)
Definition: colvargrid.h:688
std::ostream & write_multicol(std::ostream &os) const
Write grid in a format which is both human-readable and gnuplot-friendly.
Definition: colvargrid_def.h:430
virtual ~colvar_grid()
Destructor.
Definition: colvargrid.h:223
int value_to_bin_scalar(colvarvalue const &value, const int i) const
Use the lower boundary and the width to report which bin the provided value is in.
Definition: colvargrid.h:506
IST & read_raw_template_(IST &is)
Helper method for read_raw.
Definition: colvargrid_def.h:129
virtual T value_output(std::vector< int > const &ix, size_t const &imult=0) const
Return the value suitable for output purposes (so that it may be rescaled or manipulated without chan...
Definition: colvargrid.h:826
void set_sizes(std::vector< int > const &new_sizes)
Set the sizes in each direction.
Definition: colvargrid.h:138
void copy_grid(colvar_grid< T > const &other_grid)
Copy data from another grid of the same type, AND identical definition (boundaries,...
Definition: colvargrid.h:612
bool wrap_detect_edge(std::vector< int > &ix) const
Definition: colvargrid.h:437
void raw_data_out(T *out_data) const
Extract the grid data as they are represented in memory. Put the results in "out_data".
Definition: colvargrid.h:635
void map_grid(colvar_grid< T > const &other_grid)
Add data from another grid of the same type.
Definition: colvargrid.h:761
std::istream & read_multicol(std::istream &is, bool add=false)
Read a grid written by write_multicol(), incrementing if add is true.
Definition: colvargrid_def.h:311
std::vector< bool > periodic
Whether some colvars are periodic.
Definition: colvargrid.h:94
int value_to_bin_scalar(colvarvalue const &value, colvarvalue const &new_offset, cvm::real const &new_width) const
Same as the standard version, but uses another grid definition.
Definition: colvargrid.h:539
void wrap(std::vector< int > &ix) const
Definition: colvargrid.h:420
colvarvalue bin_to_value_scalar(int const &i_bin, colvarvalue const &new_offset, cvm::real const &new_width) const
Same as the standard version, but uses different parameters.
Definition: colvargrid.h:554
colvar_grid()
Default constructor.
Definition: colvargrid.h:214
std::vector< colvar * > cv
Colvars collected in this grid.
Definition: colvargrid.h:71
std::ostream & write_restart(std::ostream &os)
Write all grid parameters and data to a formatted stream.
Definition: colvargrid_def.h:112
void raw_data_in(const T *in_data)
Input the data as they are represented in memory.
Definition: colvargrid.h:644
@ f_cv_hard_lower_boundary
The lower boundary is not defined from user's choice.
Definition: colvardeps.h:327
@ f_cv_hard_upper_boundary
The upper boundary is not defined from user's choice.
Definition: colvardeps.h:329
Collective variables module (main class)
Definition: colvarmodule.h:72
static real logn(real const &x)
Definition: colvarmodule.h:220
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:99
static real floor(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:125
static int error_static(std::string const &message, int code=-1)
Definition: colvarmodule.h:770
void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:2102
int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2186
static constexpr size_t cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:724
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:143
static bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:376
static real fabs(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:137
static constexpr size_t cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:726
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2541
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
int check_keywords(std::string &conf, char const *key)
Check that all the keywords within "conf" are in the list of allowed keywords; this will invoke strip...
Definition: colvarparse.cpp:598
Parse_Mode
How a keyword is parsed in a string.
Definition: colvarparse.h:63
@ parse_normal
Alias for old default behavior (should be phased out)
Definition: colvarparse.h:82
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43
@ type_scalar
Scalar number, implemented as colvarmodule::real (default)
Definition: colvarvalue.h:56
cvm::real real_value
Real data member.
Definition: colvarvalue.h:77
Definition: colvars_memstream.h:30
Collective variables main module.
Parsing functions for collective variables.