00001
00002
00003 #include "colvarmodule.h"
00004 #include "colvarvalue.h"
00005 #include "colvarparse.h"
00006 #include "colvar.h"
00007 #include "colvarcomp.h"
00008 #include "colvargrid.h"
00009
00010
00011 colvar_grid_count::colvar_grid_count()
00012 : colvar_grid<size_t>()
00013 {}
00014
00015 colvar_grid_count::colvar_grid_count (std::vector<int> const &nx_i,
00016 size_t const &def_count)
00017 : colvar_grid<size_t> (nx_i, def_count)
00018 {}
00019
00020 colvar_grid_count::colvar_grid_count (std::vector<colvar *> &colvars,
00021 size_t const &def_count)
00022 : colvar_grid<size_t> (colvars, def_count)
00023 {}
00024
00025 std::istream & colvar_grid_count::read_restart (std::istream &is)
00026 {
00027 size_t const start_pos = is.tellg();
00028 std::string key, conf;
00029 if ((is >> key) && (key == std::string ("grid_parameters"))) {
00030 is.seekg (start_pos, std::ios::beg);
00031 is >> colvarparse::read_block ("grid_parameters", conf);
00032 parse_params (conf);
00033 } else {
00034 cvm::log ("Grid parameters are missing in the restart file, using those from the configuration.\n");
00035 is.seekg (start_pos, std::ios::beg);
00036 }
00037 read_raw (is);
00038 return is;
00039 }
00040
00041 std::ostream & colvar_grid_count::write_restart (std::ostream &os)
00042 {
00043 write_params (os);
00044 write_raw (os);
00045 return os;
00046 }
00047
00048
00049
00050 colvar_grid_scalar::colvar_grid_scalar()
00051 : colvar_grid<cvm::real>(), samples (NULL), grad (NULL)
00052 {}
00053
00054 colvar_grid_scalar::colvar_grid_scalar (colvar_grid_scalar const &g)
00055 : colvar_grid<cvm::real> (g), samples (NULL), grad (NULL)
00056 {
00057 grad = new cvm::real[nd];
00058 }
00059
00060 colvar_grid_scalar::colvar_grid_scalar (std::vector<int> const &nx_i)
00061 : colvar_grid<cvm::real> (nx_i, 0.0, 1), samples (NULL)
00062 {
00063 grad = new cvm::real[nd];
00064 }
00065
00066 colvar_grid_scalar::colvar_grid_scalar (std::vector<colvar *> &colvars, bool margin)
00067 : colvar_grid<cvm::real> (colvars, 0.0, 1, margin), samples (NULL)
00068 {
00069 grad = new cvm::real[nd];
00070 }
00071
00072 colvar_grid_scalar::~colvar_grid_scalar()
00073 {
00074 if (grad) {
00075 delete [] grad;
00076 grad = NULL;
00077 }
00078 }
00079
00080 std::istream & colvar_grid_scalar::read_restart (std::istream &is)
00081 {
00082 size_t const start_pos = is.tellg();
00083 std::string key, conf;
00084 if ((is >> key) && (key == std::string ("grid_parameters"))) {
00085 is.seekg (start_pos, std::ios::beg);
00086 is >> colvarparse::read_block ("grid_parameters", conf);
00087 parse_params (conf);
00088 } else {
00089 cvm::log ("Grid parameters are missing in the restart file, using those from the configuration.\n");
00090 is.seekg (start_pos, std::ios::beg);
00091 }
00092 read_raw (is);
00093 return is;
00094 }
00095
00096 std::ostream & colvar_grid_scalar::write_restart (std::ostream &os)
00097 {
00098 write_params (os);
00099 write_raw (os);
00100 return os;
00101 }
00102
00103
00104
00105 colvar_grid_gradient::colvar_grid_gradient()
00106 : colvar_grid<cvm::real>(), samples (NULL)
00107 {}
00108
00109 colvar_grid_gradient::colvar_grid_gradient (std::vector<int> const &nx_i)
00110 : colvar_grid<cvm::real> (nx_i, 0.0, nx_i.size()), samples (NULL)
00111 {}
00112
00113 colvar_grid_gradient::colvar_grid_gradient (std::vector<colvar *> &colvars)
00114 : colvar_grid<cvm::real> (colvars, 0.0, colvars.size()), samples (NULL)
00115 {}
00116
00117 std::istream & colvar_grid_gradient::read_restart (std::istream &is)
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 }
00132
00133 std::ostream & colvar_grid_gradient::write_restart (std::ostream &os)
00134 {
00135 write_params (os);
00136 write_raw (os);
00137 return os;
00138 }
00139
00140 void colvar_grid_gradient::write_1D_integral (std::ostream &os)
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
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 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217