Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

colvargrid.C

Go to the documentation of this file.
00001 // -*- c++ -*-
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   // 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 }
00193 
00194 
00195 
00196 
00197 // quaternion_grid::quaternion_grid (std::vector<colvar *>      const &cv_i,
00198 //                                   std::vector<std::string>   const &grid_str)
00199 // {
00200 //   cv = cv_i;
00201 
00202 //   std::istringstream is (grid_str[0]);
00203 //   is >> grid_size;
00204 
00205 //   min.assign (3, -1.0);
00206 //   max.assign (3,  1.0);
00207 //   np.assign  (3, grid_size);
00208 //   dx.assign  (3, 2.0/(cvm::real (grid_size)));
00209 
00210 //   // assumes a uniform grid in the three directions; change
00211 //   // get_value() if you want to use different sizes
00212 //   cvm::log ("Allocating quaternion grid ("+cvm::to_str (np.size())+" dimensional)...");
00213 //   data.create (np, 0.0);
00214 //   cvm::log ("done.\n");
00215 //   if (cvm::debug()) cvm::log ("Grid size = "+data.size());
00216 // }
00217 

Generated on Sun Feb 12 04:07:53 2012 for NAMD by  doxygen 1.3.9.1