18#include "colvarvalue.h"
54 std::vector<colvar *>
cv;
60 inline size_t address(std::vector<int>
const &ix)
const
63 for (
size_t i = 0; i <
nd; i++) {
64 addr += ix[i]*
static_cast<size_t>(
nxc[i]);
67 cvm::error(
"Error: exceeding bounds in colvar_grid.\n", COLVARS_BUG_ERROR);
125 inline std::vector<int>
const &
sizes()
const
131 inline void set_sizes(std::vector<int>
const &new_sizes)
152 int setup(std::vector<int>
const &nx_i,
154 size_t const &mult_i = 1)
172 for (
int i =
nd-1; i >= 0; i--) {
174 cvm::error(
"Error: providing an invalid number of grid points, "+
176 return COLVARS_ERROR;
195 return setup(this->nx, T(), this->mult);
247 this->
setup(nx_i, t, mult_i);
256 bool add_extra_bin =
false)
260 this->init_from_colvars(colvars, mult_i, add_extra_bin);
263 int init_from_colvars(std::vector<colvar *>
const &colvars,
265 bool add_extra_bin =
false)
268 cvm::log(
"Reading grid configuration from collective variables.\n");
279 " collective variables, multiplicity = "+
cvm::to_str(mult_i)+
".\n");
282 for (i = 0; i <
cv.size(); i++) {
285 cvm::error(
"Colvar grids can only be automatically "
286 "constructed for scalar variables. "
287 "ABF and histogram can not be used; metadynamics "
288 "can be used with useGrids disabled.\n", COLVARS_INPUT_ERROR);
289 return COLVARS_ERROR;
292 if (
cv[i]->width <= 0.0) {
294 "variable with negative or zero width.\n", COLVARS_INPUT_ERROR);
295 return COLVARS_ERROR;
301 periodic.push_back(
cv[i]->periodic_boundaries());
309 if (i > 0 &&
cv[i-1] ==
cv[i]) {
329 this->init_from_boundaries();
330 return this->
setup();
333 int init_from_boundaries()
336 cvm::log(
"Configuring grid dimensions from colvars boundaries.\n");
351 int nbins_round = (int)(nbins+0.5);
357 ") is not commensurate to its bin width("+
360 (nbins_round *
widths[i]);
367 nx.push_back(nbins_round);
375 inline void wrap(std::vector<int> & ix)
const
377 for (
size_t i = 0; i <
nd; i++) {
379 ix[i] = (ix[i] +
nx[i]) %
nx[i];
381 if (ix[i] < 0 || ix[i] >=
nx[i]) {
382 cvm::error(
"Trying to wrap illegal index vector (non-PBC) for a grid point: "
395 for (
size_t i = 0; i <
nd; i++) {
397 ix[i] = (ix[i] +
nx[i]) %
nx[i];
398 }
else if (ix[i] < 0 || ix[i] >=
nx[i]) {
407 inline bool wrap_to_edge(std::vector<int> & ix, std::vector<int> & edge_bin)
const
411 for (
size_t i = 0; i <
nd; i++) {
413 ix[i] = (ix[i] +
nx[i]) %
nx[i];
415 }
else if (ix[i] < 0) {
418 }
else if (ix[i] >=
nx[i]) {
420 edge_bin[i] =
nx[i] - 1;
438 for (
size_t i = 0; i <
nd; i++) {
455 cv[i]->actual_value().vector1d_value[iv] :
456 cv[i]->
value().vector1d_value[iv], i);
488 if (bin_index < 0) bin_index=0;
489 if (bin_index >=
int(
nx[i])) bin_index=int(
nx[i])-1;
490 return (
int) bin_index;
513 return new_offset.
real_value + new_width * (0.5 + i_bin);
519 size_t const &imult = 0)
545 if (other_grid.
multiplicity() != this->multiplicity()) {
546 cvm::error(
"Error: trying to subtract two grids with "
547 "different multiplicity.\n");
551 if (other_grid.
data.size() != this->data.size()) {
552 cvm::error(
"Error: trying to subtract two grids with "
553 "different size.\n");
557 for (
size_t i = 0; i <
data.size(); i++) {
569 if (other_grid.
multiplicity() != this->multiplicity()) {
570 cvm::error(
"Error: trying to copy two grids with "
571 "different multiplicity.\n");
575 if (other_grid.
data.size() != this->data.size()) {
576 cvm::error(
"Error: trying to copy two grids with "
577 "different size.\n");
582 for (
size_t i = 0; i <
data.size(); i++) {
592 for (
size_t i = 0; i <
data.size(); i++) out_data[i] =
data[i];
601 for (
size_t i = 0; i <
data.size(); i++)
data[i] = in_data[i];
615 inline T
const &
value(std::vector<int>
const &ix,
616 size_t const &imult = 0)
const
622 inline T
const &
value(
size_t i)
const
630 for (
size_t i = 0; i <
nt; i++)
638 for (
size_t i = 0; i <
nt; i++)
645 for (
size_t i = 0; i <
nt; i++)
655 for (
size_t i = 0; i <
nd; i++) {
666 for (
size_t i = 0; i <
nd; i++) {
677 for (
size_t i = 0; i <
nd; i++) {
687 bool skip_hard_boundaries =
false)
690 for (
size_t i = 0; i <
nd; i++) {
718 if (other_grid.
multiplicity() != this->multiplicity()) {
719 cvm::error(
"Error: trying to merge two grids with values of "
720 "different multiplicity.\n");
725 std::vector<cvm::real>
const &gw = this->
widths;
727 std::vector<cvm::real>
const &ogw = other_grid.
widths;
730 std::vector<int> oix = other_grid.
new_index();
736 for (
size_t i = 0; i <
nd; i++) {
747 for (
size_t im = 0; im <
mult; im++) {
762 if (other_grid.
multiplicity() != this->multiplicity()) {
763 cvm::error(
"Error: trying to sum togetehr two grids with values of "
764 "different multiplicity.\n");
767 if (scale_factor != 1.0)
768 for (
size_t i = 0; i <
data.size(); i++) {
769 data[i] +=
static_cast<T
>(scale_factor * other_grid.
data[i]);
773 for (
size_t i = 0; i <
data.size(); i++) {
782 size_t const &imult = 0)
const
784 return value(ix, imult);
792 size_t const &imult = 0,
813 return std::vector<int> (
nd, 0);
818 inline bool index_ok(std::vector<int>
const &ix)
const
820 for (
size_t i = 0; i <
nd; i++) {
821 if ( (ix[i] < 0) || (ix[i] >=
int(
nx[i])) )
829 inline void incr(std::vector<int> &ix)
const
831 for (
int i = ix.size()-1; i >= 0; i--) {
835 if (ix[i] >=
nx[i]) {
865 for (
size_t i = 0; i <
nd; i++) {
871 widths[i])) > 1.0E-10) ) {
872 cvm::error(
"Error: restart information for a grid is "
873 "inconsistent with that of its colvars.\n");
884 for (
size_t i = 0; i <
nd; i++) {
894 (
data.size() != other_grid.
data.size()) ) {
896 "two grids that are supposed to be equal, "
897 "aside from the data stored.\n");
916 std::istream &
read_raw(std::istream &is);
924 std::ostream &
write_raw(std::ostream &os,
size_t const buf_size = 3)
const;
932 std::istream &
read_multicol(std::istream &is,
bool add =
false);
936 std::string description =
"grid file",
944 std::string description =
"grid file")
const;
951 std::string description =
"grid file")
const;
971 size_t const &def_count = 0);
975 size_t const &def_count = 0,
976 bool add_extra_bin =
false);
985 inline size_t const &
new_value(std::vector<int>
const &ix)
1010 std::istream &
read_raw(std::istream &is);
1018 std::ostream &
write_raw(std::ostream &os,
size_t const buf_size = 3)
const;
1026 std::istream &
read_multicol(std::istream &is,
bool add =
false);
1030 std::string description =
"grid file",
1038 std::string description =
"grid file")
const;
1045 std::string description =
"grid file")
const;
1050 size_t const &imult = 0,
1056 if (this->has_parent_data) {
1073 for (
size_t i = 0; i <
nd; i++) {
1092 for (i = -radius; i <= radius; i++) {
1102 for (i = -radius; i <= radius; i++) {
1104 for (j = -radius; j <= radius; j++) {
1115 for (i = -radius; i <= radius; i++) {
1117 for (j = -radius; j <= radius; j++) {
1119 for (k = -radius; k <= radius; k++) {
1131 cvm::error(
"Error: local_sample_count is not implemented for grids of dimension > 3", COLVARS_NOT_IMPLEMENTED);
1137 return count / nbins;
1147 int n = 0,
int offset = 0)
1150 std::vector<int> ix = ix0;
1155 A0 =
value(ix) + offset;
1158 A1 =
value(ix) + offset;
1165 }
else if (ix[n] > 0 && ix[n] <
nx[n]-1) {
1167 A0 =
value(ix) + offset;
1170 A1 =
value(ix) + offset;
1179 int increment = (ix[n] == 0 ? 1 : -1);
1181 A0 =
value(ix) + offset;
1182 ix[n] += increment; A1 =
value(ix) + offset;
1183 ix[n] += increment; A2 =
value(ix) + offset;
1184 if (A0 * A1 * A2 == 0) {
1201 std::vector<int> ix = ix0;
1213 return (A1 - A0) / (
widths[n] * 2.);
1215 }
else if (ix[n] > 0 && ix[n] <
nx[n]-1) {
1224 return (A1 - A0) / (
widths[n] * 2.);
1228 int increment = (ix[n] == 0 ? 1 : -1);
1231 ix[n] += increment; A1 =
value(ix);
1232 ix[n] += increment; A2 =
value(ix);
1233 return (-1.5 * A0 + 2. * A1
1234 - 0.5 * A2) * increment /
widths[n];
1263 bool add_extra_bin =
false);
1268 size_t const &imult = 0)
1298 std::istream &
read_raw(std::istream &is);
1306 std::ostream &
write_raw(std::ostream &os,
size_t const buf_size = 3)
const;
1314 std::istream &
read_multicol(std::istream &is,
bool add =
false);
1318 std::string description =
"grid file",
1326 std::string description =
"grid file")
const;
1333 std::string description =
"grid file")
const;
1342 std::vector<int> ix;
1346 for (n = 0; n < 2; n++) {
1351 ix[1-n]++;
wrap(ix);
1355 grad[n] = 0.5 * (A1 - A0) /
widths[n];
1357 }
else if (
nd == 3) {
1362 for (i = 0; i<2; i++) {
1364 for (j = 0; j<2; j++) {
1366 for (k = 0; k<2; k++) {
1368 p[index++] =
value(ix);
1378 grad[0] = 0.25 * ((p[4] + p[5] + p[6] + p[7]) - (p[0] + p[1] + p[2] + p[3])) /
widths[0];
1380 grad[1] = 0.25 * ((p[2] + p[3] + p[6] + p[7]) - (p[0] + p[1] + p[4] + p[5])) /
widths[1];
1382 grad[2] = 0.25 * ((p[1] + p[3] + p[5] + p[7]) - (p[0] + p[2] + p[4] + p[6])) /
widths[2];
1384 cvm::error(
"Finite differences available in dimension 2 and 3 only.");
1393 int n = 0,
int offset = 0)
1396 std::vector<int> ix = ix0;
1401 A0 =
value(ix) + offset;
1404 A1 =
value(ix) + offset;
1411 }
else if (ix[n] > 0 && ix[n] <
nx[n]-1) {
1413 A0 =
value(ix) + offset;
1416 A1 =
value(ix) + offset;
1425 int increment = (ix[n] == 0 ? 1 : -1);
1427 A0 =
value(ix) + offset;
1428 ix[n] += increment; A1 =
value(ix) + offset;
1429 ix[n] += increment; A2 =
value(ix) + offset;
1430 if (A0 * A1 * A2 == 0) {
1447 std::vector<int> ix = ix0;
1459 return (A1 - A0) / (
widths[n] * 2.);
1461 }
else if (ix[n] > 0 && ix[n] <
nx[n]-1) {
1474 int increment = (ix[n] == 0 ? 1 : -1);
1477 ix[n] += increment; A1 =
value(ix);
1478 ix[n] += increment; A2 =
value(ix);
1488 size_t const &imult = 0)
const override
1492 cvm::error(
"Error: trying to access a component "
1493 "larger than 1 in a scalar data grid.\n");
1508 size_t const &imult = 0,
1509 bool add =
false)
override
1512 cvm::error(
"Error: trying to access a component "
1513 "larger than 1 in a scalar data grid.\n");
1579 colvar_grid_gradient(std::vector<colvar *> &colvars, std::shared_ptr<colvar_grid_count> samples_in);
1605 std::istream &
read_raw(std::istream &is);
1613 std::ostream &
write_raw(std::ostream &os,
size_t const buf_size = 3)
const;
1621 std::istream &
read_multicol(std::istream &is,
bool add =
false);
1625 std::string description =
"grid file",
1633 std::string description =
"grid file")
const;
1640 std::string description =
"grid file")
const;
1643 inline void vector_value(std::vector<int>
const &ix, std::vector<cvm::real> &v)
const
1647 int count =
samples->value(ix);
1650 for (
size_t i = 0; i <
mult; i++) {
1651 v[i] = invcount * p[i];
1654 for (
size_t i = 0; i <
mult; i++) {
1659 for (
size_t i = 0; i <
mult; i++) {
1667 inline void acc_value(std::vector<int>
const &ix, std::vector<colvarvalue>
const &values) {
1668 for (
size_t imult = 0; imult <
mult; imult++) {
1669 data[
address(ix) + imult] += values[imult].real_value;
1678 for (
size_t imult = 0; imult <
mult; imult++) {
1688 size_t const &imult = 0)
const override
1692 return ( (s =
samples->value(ix)) > 0) ?
1705 if ( weight <= min_samples ) {
1710 fact = 1.0 / weight;
1733 fact = weight > 0. ? 1. / weight : 0.;
1755 fact = weight > 0. ? 1. / weight : 0.;
1761 #ifdef __clang_analyzer__
1765 for (
size_t imult = 0; imult <
mult; imult++) {
1766 grad[imult] = fact * p[imult];
1775 size_t const &imult = 0,
1776 bool add =
false)
override
1796 if (
nd != 1 ||
nx[0] == 0) {
1832 integrate_potential(std::vector<colvar *> &colvars, std::shared_ptr<colvar_grid_gradient> gradients);
1865 std::shared_ptr<colvar_grid_gradient> gradients;
1878 void nr_linbcg_sym(
const std::vector<cvm::real> &b, std::vector<cvm::real> &x,
1885 void atimes(
const std::vector<cvm::real> &x, std::vector<cvm::real> &r);
Colvar_grid derived class to hold counters in discrete n-dim colvar space.
Definition: colvargrid.h:959
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:1068
std::istream & read_raw(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:69
std::string get_state_params() const
Write the current grid parameters to a string.
Definition: colvargrid.cpp:38
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:1197
std::ostream & write_restart(std::ostream &os)
Write all grid parameters and data to a formatted stream.
Definition: colvargrid.cpp:59
std::ostream & write_opendx(std::ostream &os) const
Write the grid data without labels, as they are represented in memory.
Definition: colvargrid.cpp:113
std::ostream & write_raw(std::ostream &os, size_t const buf_size=3) const
Definition: colvargrid.cpp:79
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:43
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:1048
std::istream & read_restart(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:49
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:90
std::ostream & write_multicol(std::ostream &os) const
Write grid in a format which is both human-readable and gnuplot-friendly.
Definition: colvargrid.cpp:102
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:1146
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:985
virtual ~colvar_grid_count()
Destructor.
Definition: colvargrid.h:966
void incr_count(std::vector< int > const &ix)
Increment the counter at given position.
Definition: colvargrid.h:979
Class for accumulating the gradient of a scalar function on a grid.
Definition: colvargrid.h:1555
std::string get_state_params() const
Write the current grid parameters to a string.
Definition: colvargrid.cpp:418
cvm::real smooth_inverse_weight(cvm::real weight)
Definition: colvargrid.h:1702
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:1742
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:1720
void acc_value(std::vector< int > const &ix, std::vector< colvarvalue > const &values)
Accumulate the value.
Definition: colvargrid.h:1667
cvm::real average(bool smoothed=false)
Compute and return average value for a 1D gradient grid.
Definition: colvargrid.h:1794
std::shared_ptr< colvar_grid_count > samples
Provide the sample count by which each binned value should be divided.
Definition: colvargrid.h:1560
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:470
colvar_grid_gradient()
Default constructor.
Definition: colvargrid.cpp:332
std::ostream & write_restart(std::ostream &os)
Write all grid parameters and data to a formatted stream.
Definition: colvargrid.cpp:439
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 integr...
Definition: colvargrid.cpp:505
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:423
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:1687
std::istream & read_raw(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:449
virtual ~colvar_grid_gradient()
Destructor.
Definition: colvargrid.h:1566
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:1773
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:1677
int full_samples
Parameters for smoothing data with low sampling.
Definition: colvargrid.h:1582
std::ostream & write_raw(std::ostream &os, size_t const buf_size=3) const
Definition: colvargrid.cpp:459
std::ostream & write_multicol(std::ostream &os) const
Write grid in a format which is both human-readable and gnuplot-friendly.
Definition: colvargrid.cpp:482
std::istream & read_restart(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:429
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:562
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:1643
std::ostream & write_opendx(std::ostream &os) const
Write the grid data without labels, as they are represented in memory.
Definition: colvargrid.cpp:493
Class for accumulating a scalar function on a grid.
Definition: colvargrid.h:1242
void acc_value(std::vector< int > const &ix, cvm::real const &new_value, size_t const &imult=0)
Accumulate the value.
Definition: colvargrid.h:1266
cvm::real minimum_value() const
Return the lowest value.
Definition: colvargrid.cpp:246
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:1443
std::istream & read_restart(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:160
std::string get_state_params() const
Write the current grid parameters to a string.
Definition: colvargrid.cpp:149
virtual ~colvar_grid_scalar()
Destructor.
Definition: colvargrid.cpp:145
cvm::real minimum_pos_value() const
Return the lowest positive value.
Definition: colvargrid.cpp:255
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:1487
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:302
std::ostream & write_opendx(std::ostream &os) const
Write the grid data without labels, as they are represented in memory.
Definition: colvargrid.cpp:224
std::ostream & write_restart(std::ostream &os)
Write all grid parameters and data to a formatted stream.
Definition: colvargrid.cpp:170
std::ostream & write_multicol(std::ostream &os) const
Write grid in a format which is both human-readable and gnuplot-friendly.
Definition: colvargrid.cpp:213
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:201
cvm::real integral() const
Calculates the integral of the map (uses widths if they are defined)
Definition: colvargrid.cpp:271
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:154
std::ostream & write_raw(std::ostream &os, size_t const buf_size=3) const
Definition: colvargrid.cpp:190
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:1506
cvm::real entropy() const
Assuming that the map is a normalized probability density, calculates the entropy (uses widths if the...
Definition: colvargrid.cpp:285
colvar_grid_scalar()
Default constructor.
Definition: colvargrid.cpp:126
cvm::real maximum_value() const
Return the highest value.
Definition: colvargrid.cpp:236
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:1392
colvar_grid_count * samples
Provide the associated sample count by which each binned value should be divided.
Definition: colvargrid.h:1247
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:1339
std::istream & read_raw(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid.cpp:180
Grid of values of a function of several collective variables.
Definition: colvargrid.h:26
std::vector< colvarvalue > upper_boundaries
Upper boundaries of the colvars in this grid.
Definition: colvargrid.h:81
int setup()
Allocate data (allow initialization also after construction)
Definition: colvargrid.h:193
std::istream & read_restart(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid_def.h:44
void set_value(size_t i, T const &t)
Set the value at the point with linear address i (for speed)
Definition: colvargrid.h:526
void check_consistency()
Check that the grid information inside (boundaries, widths, ...) is consistent with the current setti...
Definition: colvargrid.h:863
std::string get_state_params() const
Write the current grid parameters to a string.
Definition: colvargrid_def.h:146
std::ostream & write_raw(std::ostream &os, size_t const buf_size=3) const
Definition: colvargrid_def.h:113
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:446
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:811
void add_constant(T const &t)
Add a constant to all elements (fast loop)
Definition: colvargrid.h:628
std::vector< size_t > new_data
Newly read data (used for count grids, when adding several grids read from disk)
Definition: colvargrid.h:51
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:474
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:829
size_t number_of_points(int const icv=-1) const
Definition: colvargrid.h:115
std::vector< bool > hard_upper_boundaries
Whether some colvars have hard upper boundaries.
Definition: colvargrid.h:90
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:790
T const & value(size_t i) const
Get the binned value indexed by linear address i.
Definition: colvargrid.h:622
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:674
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:435
size_t mult
Multiplicity of each datum (allow the binning of non-scalar types such as atomic gradients)
Definition: colvargrid.h:42
size_t multiplicity() const
Return the multiplicity of the type used.
Definition: colvargrid.h:137
std::vector< int > const & sizes() const
Get the sizes in each direction.
Definition: colvargrid.h:125
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:517
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:503
std::vector< T > data
Low-level array of values.
Definition: colvargrid.h:48
void multiply_constant(cvm::real const &a)
Multiply all elements by a scalar constant (fast loop)
Definition: colvargrid.h:636
std::vector< int > const & number_of_points_vec() const
Return the numbers of points in all dimensions.
Definition: colvargrid.h:108
bool index_ok(std::vector< int > const &ix) const
Check that the index is within range in each of the dimensions.
Definition: colvargrid.h:818
cvm::real current_bin_scalar_fraction(int const i) const
Report the fraction of bin beyond current_bin_scalar()
Definition: colvargrid.h:467
bool has_data
Whether this grid has been filled with data or is still empty.
Definition: colvargrid.h:99
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:759
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:652
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:882
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:242
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:176
size_t nt
Total number of grid points.
Definition: colvargrid.h:45
T get_value(size_t i) const
Get the value at the point with linear address i (for speed)
Definition: colvargrid.h:532
void reset(T const &t=T())
Reset data (in case the grid is being reused)
Definition: colvargrid.h:199
size_t num_variables() const
Return the number of colvar objects.
Definition: colvargrid.h:102
int setup(std::vector< int > const &nx_i, T const &t=T(), size_t const &mult_i=1)
Allocate data.
Definition: colvargrid.h:152
colvar_grid(std::vector< colvar * > const &colvars, T const &t=T(), size_t mult_i=1, bool add_extra_bin=false)
Constructor from a vector of colvars.
Definition: colvargrid.h:253
colvar_grid(colvar_grid< T > const &g)
"Almost copy-constructor": only copies configuration parameters from another grid,...
Definition: colvargrid.h:221
std::vector< cvm::real > widths
Widths of the colvars in this grid.
Definition: colvargrid.h:93
bool has_parent_data
True if this is a count grid related to another grid of data.
Definition: colvargrid.h:96
std::ostream & write_opendx(std::ostream &os) const
Write the grid data without labels, as they are represented in memory.
Definition: colvargrid_def.h:435
bool wrap_to_edge(std::vector< int > &ix, std::vector< int > &edge_bin) const
Definition: colvargrid.h:407
std::vector< int > const get_colvars_index() const
Get the bin indices corresponding to the current values of the colvars.
Definition: colvargrid.h:663
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:452
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:542
void request_actual_value(bool b=true)
Request grid to use actual values of extended coords.
Definition: colvargrid.h:143
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:686
std::vector< int > nxc
Cumulative number of points along each dimension.
Definition: colvargrid.h:38
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:482
int current_bin_scalar(int const i) const
Report the bin corresponding to the current value of variable i.
Definition: colvargrid.h:428
std::istream & read_raw(std::istream &is)
Read all grid parameters and data from a formatted stream.
Definition: colvargrid_def.h:100
std::vector< bool > hard_lower_boundaries
Whether some colvars have hard lower boundaries.
Definition: colvargrid.h:87
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:615
std::vector< bool > use_actual_value
Do we request actual value (for extended-system colvars)?
Definition: colvargrid.h:57
size_t raw_data_num() const
Size of the data as they are represented in memory.
Definition: colvargrid.h:610
size_t address(std::vector< int > const &ix) const
Get the low-level index corresponding to an index.
Definition: colvargrid.h:60
void remove_small_values(cvm::real const &a)
Assign values that are smaller than scalar constant the latter value (fast loop)
Definition: colvargrid.h:643
std::vector< int > nx
Number of points along each dimension.
Definition: colvargrid.h:35
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:371
virtual ~colvar_grid()
Destructor.
Definition: colvargrid.h:215
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:461
size_t nd
Number of dimensions.
Definition: colvargrid.h:32
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:781
void set_sizes(std::vector< int > const &new_sizes)
Set the sizes in each direction.
Definition: colvargrid.h:131
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:567
bool wrap_detect_edge(std::vector< int > &ix) const
Definition: colvargrid.h:392
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:590
void map_grid(colvar_grid< T > const &other_grid)
Add data from another grid of the same type.
Definition: colvargrid.h:716
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:252
std::vector< bool > periodic
Whether some colvars are periodic.
Definition: colvargrid.h:84
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:494
std::vector< colvarvalue > lower_boundaries
Lower boundaries of the colvars in this grid.
Definition: colvargrid.h:78
void wrap(std::vector< int > &ix) const
Definition: colvargrid.h:375
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:509
colvar_grid()
Default constructor.
Definition: colvargrid.h:206
std::vector< colvar * > cv
Colvars collected in this grid.
Definition: colvargrid.h:54
std::ostream & write_restart(std::ostream &os)
Write all grid parameters and data to a formatted stream.
Definition: colvargrid_def.h:56
void raw_data_in(const T *in_data)
Input the data as they are represented in memory.
Definition: colvargrid.h:599
@ f_cv_hard_lower_boundary
The lower boundary is not defined from user's choice.
Definition: colvardeps.h:314
@ f_cv_hard_upper_boundary
The upper boundary is not defined from user's choice.
Definition: colvardeps.h:316
static real logn(real const &x)
Definition: colvarmodule.h:177
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:95
static real floor(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:121
static void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:1969
static int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2046
static size_t const cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:664
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:133
static size_t const cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:666
static bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:330
static real fabs(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:127
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2392
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
Parse_Mode
How a keyword is parsed in a string.
Definition: colvarparse.h:53
@ parse_normal
Alias for old default behavior (should be phased out)
Definition: colvarparse.h:72
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
Integrate (1D, 2D or 3D) gradients.
Definition: colvargrid.h:1823
void set_zero_minimum()
Add constant to potential so that its minimum value is zero Useful e.g. for output.
Definition: colvargrid.h:1854
void update_div_local(const std::vector< int > &ix)
Update matrix containing divergence and boundary conditions called by update_div_neighbors and by col...
Definition: colvargrid.cpp:747
std::vector< cvm::real > divergence
Array holding divergence + boundary terms (modified Neumann) if not periodic.
Definition: colvargrid.h:1868
void set_div()
Set matrix containing divergence and boundary conditions based on complete gradient grid.
Definition: colvargrid.cpp:684
void update_div_neighbors(const std::vector< int > &ix)
Update matrix containing divergence and boundary conditions based on new gradient point value,...
Definition: colvargrid.cpp:693
cvm::real l2norm(const std::vector< cvm::real > &x)
l2 norm of a vector
Definition: colvargrid.cpp:1268
bool b_smoothed
Flag requesting the use of a smoothed version of the gradient (default: false)
Definition: colvargrid.h:1859
int integrate(const int itmax, const cvm::real &tol, cvm::real &err, bool verbose=true)
Calculate potential from divergence (in 2D); return number of steps.
Definition: colvargrid.cpp:644
void get_grad(cvm::real *g, std::vector< int > &ix)
Definition: colvargrid.cpp:731
void nr_linbcg_sym(const std::vector< cvm::real > &b, std::vector< cvm::real > &x, const cvm::real &tol, const int itmax, int &iter, cvm::real &err)
Solve linear system based on CG, valid for symmetric matrices only.
Definition: colvargrid.cpp:1215
void atimes(const std::vector< cvm::real > &x, std::vector< cvm::real > &r)
Multiplication by sparse matrix representing Lagrangian (or its transpose)
Definition: colvargrid.cpp:799
Collective variables main module.
Parsing functions for collective variables.