#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 969 of file colvargrid.h.
|
|
Default constructor.
Definition at line 107 of file colvargrid.C. References cvm. 00108 : colvar_grid<cvm::real>(), samples (NULL) 00109 {}
|
|
|
Destructor.
Definition at line 981 of file colvargrid.h. 00982 {}
|
|
|
Constructor from specific sizes arrays.
Definition at line 111 of file colvargrid.C. References cvm. 00112 : colvar_grid<cvm::real> (nx_i, 0.0, nx_i.size()), samples (NULL) 00113 {}
|
|
|
Constructor from a vector of colvars.
Definition at line 115 of file colvargrid.C. References cvm. 00116 : colvar_grid<cvm::real> (colvars, 0.0, colvars.size()), samples (NULL) 00117 {}
|
|
||||||||||||
|
Accumulate the gradient based on the force (i.e. sums the opposite of the force).
Definition at line 1001 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(). 01001 {
01002 for (size_t imult = 0; imult < mult; imult++) {
01003 data[address (ix) + imult] -= forces[imult];
01004 }
01005 if (samples)
01006 samples->incr_count (ix);
01007 }
|
|
||||||||||||
|
Accumulate the gradient.
Definition at line 991 of file colvargrid.h. References colvar_grid< cvm::real >::address(), colvar_grid_count::incr_count(), and samples. 00991 {
00992 for (size_t imult = 0; imult < mult; imult++) {
00993 data[address (ix) + imult] += grads[imult];
00994 }
00995 if (samples)
00996 samples->incr_count (ix);
00997 }
|
|
|
Compute and return average value for a 1D gradient grid.
Definition at line 1051 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(). 01052 {
01053 size_t n = 0;
01054
01055 if (nd != 1 || nx[0] == 0) {
01056 return 0.0;
01057 }
01058
01059 cvm::real sum = 0.0;
01060 std::vector<int> ix = new_index();
01061 if (samples) {
01062 for ( ; index_ok (ix); incr (ix)) {
01063 if ( (n = samples->value (ix)) )
01064 sum += value (ix) / n;
01065 }
01066 } else {
01067 for ( ; index_ok (ix); incr (ix)) {
01068 sum += value (ix);
01069 }
01070 }
01071 return (sum / cvm::real (nx[0]));
01072 }
|
|
|
Read the grid from a restart.
Definition at line 119 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(). 00120 {
00121 size_t const start_pos = is.tellg();
00122 std::string key, conf;
00123 if ((is >> key) && (key == std::string ("grid_parameters"))) {
00124 is.seekg (start_pos, std::ios::beg);
00125 is >> colvarparse::read_block ("grid_parameters", conf);
00126 parse_params (conf);
00127 } else {
00128 cvm::log ("Grid parameters are missing in the restart file, using those from the configuration.\n");
00129 is.seekg (start_pos, std::ios::beg);
00130 }
00131 read_raw (is);
00132 return is;
00133 }
|
|
||||||||||||||||||||
|
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 1025 of file colvargrid.h. References colvar_grid< cvm::real >::address(), colvar_grid_count::new_count(), samples, and colvar_grid< T >::value(). 01029 {
01030 if (add) {
01031 if (samples)
01032 data[address (ix) + imult] += new_value * samples->new_count (ix);
01033 else
01034 data[address (ix) + imult] += new_value;
01035 } else {
01036 if (samples)
01037 data[address (ix) + imult] = new_value * samples->value (ix);
01038 else
01039 data[address (ix) + imult] = new_value;
01040 }
01041 }
|
|
||||||||||||
|
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 1011 of file colvargrid.h. References colvar_grid< cvm::real >::address(), colvarmodule::real, samples, and colvar_grid< T >::value(). 01013 {
01014 if (samples)
01015 return (samples->value (ix) > 0) ?
01016 (data[address (ix) + imult] / cvm::real (samples->value (ix))) :
01017 0.0;
01018 else
01019 return data[address (ix) + imult];
01020 }
|
|
|
If the grid is 1-dimensional, integrate it and write the integral to a file.
Definition at line 142 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(). 00143 {
00144 cvm::real bin, min, integral;
00145 std::vector<cvm::real> int_vals;
00146
00147 os << "# xi A(xi)\n";
00148
00149 if ( cv.size() != 1 ) {
00150 cvm::fatal_error ("Cannot write integral for multi-dimensional gradient grids.");
00151 }
00152
00153 integral = 0.0;
00154 int_vals.push_back ( 0.0 );
00155 bin = 0.0;
00156 min = 0.0;
00157
00158 // correction for periodic colvars, so that the PMF is periodic
00159 cvm::real corr;
00160 if ( periodic[0] ) {
00161 corr = average();
00162 } else {
00163 corr = 0.0;
00164 }
00165
00166 for (std::vector<int> ix = new_index(); index_ok (ix); incr (ix), bin += 1.0 ) {
00167
00168 if (samples) {
00169 size_t const samples_here = samples->value (ix);
00170 if (samples_here)
00171 integral += (value (ix) / cvm::real (samples_here) - corr) * cv[0]->width;
00172 } else {
00173 integral += (value (ix) - corr) * cv[0]->width;
00174 }
00175
00176 if ( integral < min ) min = integral;
00177 int_vals.push_back ( integral );
00178 }
00179
00180 bin = 0.0;
00181 for ( int i = 0; i < nx[0]; i++, bin += 1.0 ) {
00182 os << std::setw (10) << cv[0]->lower_boundary.real_value + cv[0]->width * bin << " "
00183 << std::setw (cvm::cv_width)
00184 << std::setprecision (cvm::cv_prec)
00185 << int_vals[i] - min << "\n";
00186 }
00187
00188 os << std::setw (10) << cv[0]->lower_boundary.real_value + cv[0]->width * bin << " "
00189 << std::setw (cvm::cv_width)
00190 << std::setprecision (cvm::cv_prec)
00191 << int_vals[nx[0]] - min << "\n";
00192
00193 return;
00194 }
|
|
|
Write the grid to a restart.
Definition at line 135 of file colvargrid.C. References colvar_grid< cvm::real >::write_params(), and colvar_grid< cvm::real >::write_raw(). Referenced by colvarbias_meta::write_restart(). 00136 {
00137 write_params (os);
00138 write_raw (os);
00139 return os;
00140 }
|
|
|
Provide the sample count by which each binned value should be divided.
Definition at line 975 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