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   if (cvm::debug()) 
00094     cvm::log ("Here\n");
00095   return is;
00096 }
00097 
00098 std::ostream & colvar_grid_scalar::write_restart (std::ostream &os)
00099 {
00100   write_params (os);
00101   write_raw (os);
00102   return os;
00103 }
00104 
00105 
00106 
00107 colvar_grid_gradient::colvar_grid_gradient()
00108   : colvar_grid<cvm::real>(), samples (NULL)
00109 {}
00110 
00111 colvar_grid_gradient::colvar_grid_gradient (std::vector<int> const &nx_i)
00112   : colvar_grid<cvm::real> (nx_i, 0.0, nx_i.size()), samples (NULL)
00113 {}
00114 
00115 colvar_grid_gradient::colvar_grid_gradient (std::vector<colvar *> &colvars)
00116   : colvar_grid<cvm::real> (colvars, 0.0, colvars.size()), samples (NULL)
00117 {}
00118 
00119 std::istream & colvar_grid_gradient::read_restart (std::istream &is)
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 }
00134 
00135 std::ostream & colvar_grid_gradient::write_restart (std::ostream &os)
00136 {
00137   write_params (os);
00138   write_raw (os);
00139   return os;
00140 }
00141 
00142 void colvar_grid_gradient::write_1D_integral (std::ostream &os)
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 }
00195 
00196 
00197 
00198 
00199 // quaternion_grid::quaternion_grid (std::vector<colvar *>      const &cv_i,
00200 //                                   std::vector<std::string>   const &grid_str)
00201 // {
00202 //   cv = cv_i;
00203 
00204 //   std::istringstream is (grid_str[0]);
00205 //   is >> grid_size;
00206 
00207 //   min.assign (3, -1.0);
00208 //   max.assign (3,  1.0);
00209 //   np.assign  (3, grid_size);
00210 //   dx.assign  (3, 2.0/(cvm::real (grid_size)));
00211 
00212 //   // assumes a uniform grid in the three directions; change
00213 //   // get_value() if you want to use different sizes
00214 //   cvm::log ("Allocating quaternion grid ("+cvm::to_str (np.size())+" dimensional)...");
00215 //   data.create (np, 0.0);
00216 //   cvm::log ("done.\n");
00217 //   if (cvm::debug()) cvm::log ("Grid size = "+data.size());
00218 // }
00219 

Generated on Mon Nov 23 04:59:18 2009 for NAMD by  doxygen 1.3.9.1