#include <colvargrid.h>
Inheritance diagram for colvar_grid_gradient:

Public Member Functions | |
| colvar_grid_gradient () | |
| Default constructor. | |
| virtual | ~colvar_grid_gradient () |
| Destructor. | |
| colvar_grid_gradient (std::vector< int > const &nx_i) | |
| Constructor from specific sizes arrays. | |
| colvar_grid_gradient (std::vector< colvar * > &colvars) | |
| Constructor from a vector of colvars. | |
| void | acc_grad (std::vector< int > const &ix, cvm::real const *grads) |
| Accumulate the gradient. | |
| 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). | |
| virtual cvm::real | value_output (std::vector< int > const &ix, size_t const &imult=0) |
| Return the value of the function at ix divided by its number of samples (if the count grid is defined). | |
| virtual void | value_input (std::vector< int > const &ix, cvm::real const &new_value, size_t const &imult=0, bool add=false) |
| Get the value from a formatted output and transform it into the internal representation (it may have been rescaled or manipulated). | |
| std::istream & | read_restart (std::istream &is) |
| Read the grid from a restart. | |
| std::ostream & | write_restart (std::ostream &os) |
| Write the grid to a restart. | |
| cvm::real | average () |
| Compute and return average value for a 1D gradient grid. | |
| void | write_1D_integral (std::ostream &os) |
| If the grid is 1-dimensional, integrate it and write the integral to a file. | |
Public Attributes | |
| colvar_grid_count * | samples |
| Provide the sample count by which each binned value should be divided. | |
Definition at line 1049 of file colvargrid.h.
|
|
Default constructor.
Definition at line 105 of file colvargrid.C. References cvm. 00106 : colvar_grid<cvm::real>(), samples (NULL) 00107 {}
|
|
|
Destructor.
Definition at line 1061 of file colvargrid.h. 01062 {}
|
|
|
Constructor from specific sizes arrays.
Definition at line 109 of file colvargrid.C. References cvm. 00110 : colvar_grid<cvm::real> (nx_i, 0.0, nx_i.size()), samples (NULL) 00111 {}
|
|
|
Constructor from a vector of colvars.
Definition at line 113 of file colvargrid.C. References cvm. 00114 : colvar_grid<cvm::real> (colvars, 0.0, colvars.size()), samples (NULL) 00115 {}
|
|
||||||||||||
|
Accumulate the gradient based on the force (i.e. sums the opposite of the force).
Definition at line 1081 of file colvargrid.h. References colvar_grid< cvm::real >::address(), colvar_grid_count::incr_count(), and samples. Referenced by colvarbias_meta::project_hills(), and colvarbias_abf::update(). 01081 {
01082 for (size_t imult = 0; imult < mult; imult++) {
01083 data[address (ix) + imult] -= forces[imult];
01084 }
01085 if (samples)
01086 samples->incr_count (ix);
01087 }
|
|
||||||||||||
|
Accumulate the gradient.
Definition at line 1071 of file colvargrid.h. References colvar_grid< cvm::real >::address(), colvar_grid_count::incr_count(), and samples. 01071 {
01072 for (size_t imult = 0; imult < mult; imult++) {
01073 data[address (ix) + imult] += grads[imult];
01074 }
01075 if (samples)
01076 samples->incr_count (ix);
01077 }
|
|
|
Compute and return average value for a 1D gradient grid.
Definition at line 1132 of file colvargrid.h. References colvar_grid< cvm::real >::incr(), colvar_grid< cvm::real >::index_ok(), colvar_grid< cvm::real >::new_index(), colvarmodule::real, samples, colvar_grid< cvm::real >::value(), and colvar_grid< T >::value(). Referenced by colvarbias_abf::update(), and write_1D_integral(). 01133 {
01134 size_t n = 0;
01135
01136 if (nd != 1 || nx[0] == 0) {
01137 return 0.0;
01138 }
01139
01140 cvm::real sum = 0.0;
01141 std::vector<int> ix = new_index();
01142 if (samples) {
01143 for ( ; index_ok (ix); incr (ix)) {
01144 if ( (n = samples->value (ix)) )
01145 sum += value (ix) / n;
01146 }
01147 } else {
01148 for ( ; index_ok (ix); incr (ix)) {
01149 sum += value (ix);
01150 }
01151 }
01152 return (sum / cvm::real (nx[0]));
01153 }
|
|
|
Read the grid from a restart.
Definition at line 117 of file colvargrid.C. References colvarmodule::log(), colvar_grid< cvm::real >::parse_params(), and colvar_grid< cvm::real >::read_raw(). Referenced by colvarbias_meta::read_restart(). 00118 {
00119 size_t const start_pos = is.tellg();
00120 std::string key, conf;
00121 if ((is >> key) && (key == std::string ("grid_parameters"))) {
00122 is.seekg (start_pos, std::ios::beg);
00123 is >> colvarparse::read_block ("grid_parameters", conf);
00124 parse_params (conf);
00125 } else {
00126 cvm::log ("Grid parameters are missing in the restart file, using those from the configuration.\n");
00127 is.seekg (start_pos, std::ios::beg);
00128 }
00129 read_raw (is);
00130 return is;
00131 }
|
|
||||||||||||||||||||
|
Get the value from a formatted output and transform it into the internal representation (it may have been rescaled or manipulated).
Reimplemented from colvar_grid< cvm::real >. Definition at line 1105 of file colvargrid.h. References colvar_grid< cvm::real >::address(), colvar_grid_count::new_count(), samples, and colvar_grid< T >::value(). 01109 {
01110 if (add) {
01111 if (samples)
01112 data[address (ix) + imult] += new_value * samples->new_count (ix);
01113 else
01114 data[address (ix) + imult] += new_value;
01115 } else {
01116 if (samples)
01117 data[address (ix) + imult] = new_value * samples->value (ix);
01118 else
01119 data[address (ix) + imult] = new_value;
01120 }
01121 has_data = true;
01122 }
|
|
||||||||||||
|
Return the value of the function at ix divided by its number of samples (if the count grid is defined).
Reimplemented from colvar_grid< cvm::real >. Definition at line 1091 of file colvargrid.h. References colvar_grid< cvm::real >::address(), colvarmodule::real, samples, and colvar_grid< T >::value(). 01093 {
01094 if (samples)
01095 return (samples->value (ix) > 0) ?
01096 (data[address (ix) + imult] / cvm::real (samples->value (ix))) :
01097 0.0;
01098 else
01099 return data[address (ix) + imult];
01100 }
|
|
|
If the grid is 1-dimensional, integrate it and write the integral to a file.
Definition at line 140 of file colvargrid.C. References average(), colvarmodule::fatal_error(), colvar_grid< cvm::real >::incr(), colvar_grid< cvm::real >::index_ok(), colvar_grid< cvm::real >::new_index(), colvarmodule::real, samples, colvar_grid< cvm::real >::value(), and colvar_grid< T >::value(). 00141 {
00142 cvm::real bin, min, integral;
00143 std::vector<cvm::real> int_vals;
00144
00145 os << "# xi A(xi)\n";
00146
00147 if ( cv.size() != 1 ) {
00148 cvm::fatal_error ("Cannot write integral for multi-dimensional gradient grids.");
00149 }
00150
00151 integral = 0.0;
00152 int_vals.push_back ( 0.0 );
00153 bin = 0.0;
00154 min = 0.0;
00155
00156 // correction for periodic colvars, so that the PMF is periodic
00157 cvm::real corr;
00158 if ( periodic[0] ) {
00159 corr = average();
00160 } else {
00161 corr = 0.0;
00162 }
00163
00164 for (std::vector<int> ix = new_index(); index_ok (ix); incr (ix), bin += 1.0 ) {
00165
00166 if (samples) {
00167 size_t const samples_here = samples->value (ix);
00168 if (samples_here)
00169 integral += (value (ix) / cvm::real (samples_here) - corr) * cv[0]->width;
00170 } else {
00171 integral += (value (ix) - corr) * cv[0]->width;
00172 }
00173
00174 if ( integral < min ) min = integral;
00175 int_vals.push_back ( integral );
00176 }
00177
00178 bin = 0.0;
00179 for ( int i = 0; i < nx[0]; i++, bin += 1.0 ) {
00180 os << std::setw (10) << cv[0]->lower_boundary.real_value + cv[0]->width * bin << " "
00181 << std::setw (cvm::cv_width)
00182 << std::setprecision (cvm::cv_prec)
00183 << int_vals[i] - min << "\n";
00184 }
00185
00186 os << std::setw (10) << cv[0]->lower_boundary.real_value + cv[0]->width * bin << " "
00187 << std::setw (cvm::cv_width)
00188 << std::setprecision (cvm::cv_prec)
00189 << int_vals[nx[0]] - min << "\n";
00190
00191 return;
00192 }
|
|
|
Write the grid to a restart.
Definition at line 133 of file colvargrid.C. References colvar_grid< cvm::real >::write_params(), and colvar_grid< cvm::real >::write_raw(). Referenced by colvarbias_meta::write_replica_state_file(), and colvarbias_meta::write_restart(). 00134 {
00135 write_params (os);
00136 write_raw (os);
00137 return os;
00138 }
|
|
|
Provide the sample count by which each binned value should be divided.
Definition at line 1055 of file colvargrid.h. Referenced by acc_force(), acc_grad(), average(), colvarbias_abf::colvarbias_abf(), value_input(), value_output(), and write_1D_integral(). |
1.3.9.1