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

colvarbias_meta.h

Go to the documentation of this file.
00001 #ifndef COLVARBIAS_META_H
00002 #define COLVARBIAS_META_H
00003 
00004 #include <vector>
00005 #include <list>
00006 #include <sstream>
00007 #include <fstream>
00008 
00009 #include "colvarbias.h"
00010 #include "colvargrid.h"
00011 
00013 class colvarbias_meta : public colvarbias {
00014 
00015 public:
00016 
00018   enum Communication {
00020     single_replica,
00022     multiple_replicas
00023   };
00024 
00026   Communication comm;
00027 
00029   colvarbias_meta (std::string const &conf, char const *key);
00030 
00032   virtual ~colvarbias_meta();
00033   
00034   virtual void update();
00035 
00037   virtual void analyse();
00038 
00039   virtual std::istream & read_restart (std::istream &is);
00040 
00041   virtual std::ostream & write_restart (std::ostream &os);
00042 
00043   class hill;
00044   typedef std::list<hill>::iterator hill_iter;
00045 
00046 protected:
00047 
00049 //   virtual void parse_analysis (std::string const &conf);
00050 
00053   std::list<hill> hills;
00054 
00057   hill_iter new_hills_begin;
00058 
00061   std::list<hill> hills_off_grid;
00062 
00064   hill_iter new_hills_off_grid_begin;
00065 
00067   void recount_hills_off_grid (hill_iter h_first, hill_iter h_last,
00068                                colvar_grid_scalar *ge);
00069 
00071   std::istream & read_hill (std::istream &is);
00072 
00076   virtual std::list<hill>::const_iterator create_hill (hill const &h);
00077 
00080   virtual std::list<hill>::const_iterator delete_hill (std::list<hill>::iterator &h);
00081 
00084   virtual void calc_hills (hill_iter  h_first,
00085                            hill_iter  h_last,
00086                            cvm::real &energy,
00087                            std::vector<colvarvalue> const &values = std::vector<colvarvalue> (0));
00088 
00092   virtual void calc_hills_force (size_t const &i,
00093                                  hill_iter h_first,
00094                                  hill_iter h_last,
00095                                  std::vector<colvarvalue> &forces,
00096                                  std::vector<colvarvalue> const &values = std::vector<colvarvalue> (0));
00097 
00099   cvm::real  hill_weight;
00100 
00103   bool       use_grids;
00104 
00106   bool       rebin_grids;
00107 
00109   bool       expand_grids;
00110 
00112   size_t     grids_freq;
00113 
00116   bool       keep_hills;
00117 
00119   bool       dump_fes;
00120 
00123   bool       dump_fes_save;
00124 
00126   colvar_grid_scalar    *hills_energy;
00127 
00129   colvar_grid_gradient  *hills_energy_gradients;
00130 
00132   void project_hills (hill_iter h_first, hill_iter h_last,
00133                       colvar_grid_scalar *ge, colvar_grid_gradient *gf,
00134                       cvm::real const scale_factor = 1.0);
00135 
00136 
00137 
00142   cvm::real  hill_width;
00143 
00145   size_t     new_hill_freq;
00146 
00148   bool           b_hills_traj;
00150   std::ofstream  hills_traj_os;
00151 
00152 
00154   std::string    replica;
00155 
00158   virtual void register_replica_file (std::string const &new_file);
00159 
00164   virtual void update_replica_files_registry();
00165 
00169   virtual void read_replica_files();
00170 
00173   size_t                 replica_update_freq;
00174 
00176   std::string            replica_files_registry;
00177 
00179   std::list<std::string> replica_files;
00180 
00182   std::list<size_t>      replica_files_pos;
00183 
00185   std::ofstream          replica_out_file;
00186 
00188   std::string            replica_out_file_name;
00189 
00190 
00191   // Analysis
00192 
00194   size_t                 free_energy_begin;
00195 
00197   size_t                 free_energy_end;
00198 
00200   bool                   shift_fes;
00201 
00203   cvm::real              free_energy_offset;
00204 
00206   std::string            free_energy_file;
00207 
00209   std::string            free_energy_gradients_file;
00210 
00212   std::string            boltzmann_weights_file;
00213 
00220   std::string            boltzmann_counts_file;
00221 
00222   // weight = scale * exp (-(fe-offset)/(kB*temp))
00223 
00225   cvm::real              boltzmann_weights_scale;
00226 
00228   cvm::real              boltzmann_weights_temp;
00229 
00231   colvar_grid_scalar    *free_energy;
00232 
00234   colvar_grid_gradient  *free_energy_gradients;
00235 
00237   colvar_grid_scalar    *boltzmann_weights;
00238 
00240   colvar_grid_count     *boltzmann_counts;
00241 
00242 };
00243 
00244 
00245 
00246 
00248 class colvarbias_meta::hill {
00249 
00250 protected:
00251 
00253   cvm::real hill_value;
00254 
00256   cvm::real sW;
00257 
00259   cvm::real W;
00260 
00262   std::vector<colvarvalue>  centers;
00263 
00265   std::vector<cvm::real>    widths;
00266 
00267 public:
00268 
00269   friend class colvarbias_meta;
00270 
00272   size_t      it;
00273 
00275   std::string replica;
00276 
00282   inline hill (cvm::real             const &W_in,
00283                std::vector<colvar *>       &cv,
00284                cvm::real             const &hill_width,
00285                std::string           const &replica_in = "")
00286     : sW (1.0),
00287       W (W_in),
00288       centers (cv.size()),
00289       widths (cv.size()),
00290       it (cvm::it),
00291       replica (replica_in)
00292   {
00293     for (size_t i = 0; i < cv.size(); i++) {
00294       centers[i].type (cv[i]->type());
00295       centers[i] = cv[i]->value();
00296       widths[i] = cv[i]->width * hill_width;
00297     }
00298     if (cvm::debug()) 
00299       cvm::log ("New hill, applied to "+cvm::to_str (cv.size())+
00300                 " collective variables, with reference values "+
00301                 cvm::to_str (centers)+", widths "+
00302                 cvm::to_str (widths)+" and weight "+
00303                 cvm::to_str (W)+".\n");
00304   }
00305 
00312   inline hill (size_t                    const &it_in,
00313                cvm::real                 const &W_in,
00314                std::vector<colvarvalue>  const &centers_in,
00315                std::vector<cvm::real>    const &widths_in,
00316                std::string               const &replica_in = "")
00317     : sW (1.0),
00318       W (W_in),
00319       centers (centers_in),
00320       widths (widths_in),
00321       it (it_in),
00322       replica (replica_in)
00323   {}
00324 
00326   inline hill (colvarbias_meta::hill const &h)
00327     : sW (1.0),
00328       W (h.W),
00329       centers (h.centers),
00330       widths (h.widths),
00331       it (h.it),
00332       replica (h.replica)
00333   {}
00334 
00336   inline ~hill()
00337   {}
00338   
00340   inline cvm::real energy()
00341   {
00342     return W * sW * hill_value;
00343   }
00344 
00346   inline cvm::real energy (cvm::real const &new_weight)
00347   {
00348     return new_weight * sW * hill_value;
00349   }
00350 
00352   inline cvm::real const &value()
00353   {
00354     return hill_value;
00355   }
00356 
00358   inline void value (cvm::real const &new_value)
00359   {
00360     hill_value = new_value;
00361   }
00362 
00364   inline cvm::real weight()
00365   {
00366     return W * sW;
00367   }
00368 
00370   inline void scale (cvm::real const &new_scale_fac)
00371   {
00372     sW = new_scale_fac;
00373   }
00374 
00376   inline std::vector<colvarvalue> & center()
00377   {
00378     return centers;
00379   }
00380 
00382   inline colvarvalue & center (size_t const &i)
00383   {
00384     return centers[i];
00385   }
00386 
00388   inline friend bool operator < (hill const &h1, hill const &h2)
00389   {
00390     if (h1.it < h2.it) return true;
00391     else return false;
00392   }
00393 
00395   inline friend bool operator <= (hill const &h1, hill const &h2)
00396   {
00397     if (h1.it <= h2.it) return true;
00398     else return false;
00399   }
00400 
00402   inline friend bool operator > (hill const &h1, hill const &h2)
00403   {
00404     if (h1.it > h2.it) return true;
00405     else return false;
00406   }
00407 
00409   inline friend bool operator >= (hill const &h1, hill const &h2)
00410   {
00411     if (h1.it >= h2.it) return true;
00412     else return false;
00413   }
00414 
00416   inline friend bool operator == (hill const &h1, hill const &h2)
00417   {
00418     if ( (h1.it >= h2.it) && (h1.replica == h2.replica) ) return true;
00419     else return false;
00420   }
00421 
00423   std::string output_traj();
00424 
00426   inline friend std::ostream & operator << (std::ostream &os,
00427                                             hill const &h);
00428 
00429 };
00430 
00431 
00432 #endif
00433 
00434 
00435 // Emacs
00436 // Local Variables:
00437 // mode: C++
00438 // End:

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