Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

colvarbias_meta.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 
00003 // This file is part of the Collective Variables module (Colvars).
00004 // The original version of Colvars and its updates are located at:
00005 // https://github.com/Colvars/colvars
00006 // Please update all Colvars source files before making any changes.
00007 // If you wish to distribute your changes, please submit them to the
00008 // Colvars repository at GitHub.
00009 
00010 #ifndef COLVARBIAS_META_H
00011 #define COLVARBIAS_META_H
00012 
00013 #include <vector>
00014 #include <list>
00015 #include <iosfwd>
00016 
00017 #include "colvarbias.h"
00018 #include "colvargrid.h"
00019 
00021 class colvarbias_meta
00022   : public virtual colvarbias,
00023     public virtual colvarbias_ti
00024 {
00025 
00026 public:
00027 
00029   enum Communication {
00031     single_replica,
00033     multiple_replicas
00034   };
00035 
00037   Communication comm;
00038 
00039   colvarbias_meta(char const *key);
00040   virtual ~colvarbias_meta();
00041 
00042   virtual int init(std::string const &conf);
00043   virtual int init_replicas_params(std::string const &conf);
00044   virtual int init_well_tempered_params(std::string const &conf);
00045   virtual int init_ebmeta_params(std::string const &conf);
00046 
00047   virtual int clear_state_data();
00048 
00049   virtual int update();
00050   virtual int update_grid_params();
00051   virtual int update_bias();
00052   virtual int update_grid_data();
00053   virtual int replica_share();
00054 
00055   virtual int calc_energy(std::vector<colvarvalue> const *values);
00056   virtual int calc_forces(std::vector<colvarvalue> const *values);
00057 
00058   virtual std::string const get_state_params() const;
00059   virtual int set_state_params(std::string const &state_conf);
00060   virtual std::ostream & write_state_data(std::ostream &os);
00061   virtual std::istream & read_state_data(std::istream &os);
00062 
00063   virtual int setup_output();
00064   virtual int write_output_files();
00065   virtual void write_pmf();
00066   virtual int write_state_to_replicas();
00067 
00068   class hill;
00069   typedef std::list<hill>::iterator hill_iter;
00070 
00071 protected:
00072 
00077   cvm::real hill_width;
00078 
00080   std::vector<cvm::real> colvar_sigmas;
00081 
00083   size_t     new_hill_freq;
00084 
00086   bool b_hills_traj;
00087 
00089   std::string const hills_traj_file_name() const;
00090 
00093   std::list<hill> hills;
00094 
00097   hill_iter new_hills_begin;
00098 
00101   std::list<hill> hills_off_grid;
00102 
00104   hill_iter new_hills_off_grid_begin;
00105 
00107   void recount_hills_off_grid(hill_iter h_first, hill_iter h_last,
00108                                colvar_grid_scalar *ge);
00109 
00111   std::istream & read_hill(std::istream &is);
00112 
00116   std::list<hill>::const_iterator add_hill(hill const &h);
00117 
00120   std::list<hill>::const_iterator delete_hill(hill_iter &h);
00121 
00124   virtual void calc_hills(hill_iter  h_first,
00125                           hill_iter  h_last,
00126                           cvm::real &energy,
00127                           std::vector<colvarvalue> const *values);
00128 
00132   virtual void calc_hills_force(size_t const &i,
00133                                 hill_iter h_first,
00134                                 hill_iter h_last,
00135                                 std::vector<colvarvalue> &forces,
00136                                 std::vector<colvarvalue> const *values);
00137 
00138 
00140   cvm::real  hill_weight;
00141 
00144   bool       use_grids;
00145 
00147   bool       rebin_grids;
00148 
00150   bool       expand_grids;
00151 
00153   size_t     grids_freq;
00154 
00156   bool       keep_hills;
00157 
00159   bool restart_keep_hills;
00160 
00162   bool       dump_fes;
00163 
00166   bool       dump_replica_fes;
00167 
00170   bool       dump_fes_save;
00171 
00173   bool       well_tempered;
00174 
00176   cvm::real  bias_temperature;
00177 
00179   bool       ebmeta;
00180 
00182   colvar_grid_scalar* target_dist;
00183 
00185   cvm::step_number ebmeta_equil_steps;
00186 
00187 
00191   bool       safely_read_restart;
00192 
00194   colvar_grid_scalar    *hills_energy;
00195 
00197   colvar_grid_gradient  *hills_energy_gradients;
00198 
00200   void project_hills(hill_iter h_first, hill_iter h_last,
00201                       colvar_grid_scalar *ge, colvar_grid_gradient *gf,
00202                       bool print_progress = false);
00203 
00204 
00205   // Multiple Replicas variables and functions
00206 
00208   std::string            replica_id;
00209 
00211   std::string            replica_file_name;
00212 
00214   virtual int update_replicas_registry();
00215 
00217   virtual int read_replica_files();
00218 
00220   virtual int write_replica_state_file();
00221 
00223   virtual int reopen_replica_buffer_file();
00224 
00230   std::vector<colvarbias_meta *> replicas;
00231 
00233   size_t                 replica_update_freq;
00234 
00237   std::string            replicas_registry_file;
00239   std::string            replicas_registry;
00241   std::string            replica_list_file;
00242 
00245   std::string            replica_state_file;
00247   bool                   replica_state_file_in_sync;
00248 
00251   size_t                 update_status;
00252 
00256   std::string            replica_hills_file;
00257 
00259   std::streampos         replica_hills_file_pos;
00260 
00261 };
00262 
00263 
00264 
00265 
00267 class colvarbias_meta::hill {
00268 
00269 protected:
00270 
00272   cvm::step_number it;
00273 
00275   cvm::real hill_value;
00276 
00278   cvm::real sW;
00279 
00281   cvm::real W;
00282 
00284   std::vector<colvarvalue> centers;
00285 
00287   std::vector<cvm::real> sigmas;
00288 
00290   std::string replica;
00291 
00292 public:
00293 
00294   friend class colvarbias_meta;
00295 
00302   hill(cvm::step_number it, cvm::real W,
00303        std::vector<colvarvalue> const &cv_values,
00304        std::vector<cvm::real> const &cv_sigmas,
00305        std::string const &replica = "");
00306 
00308   hill(colvarbias_meta::hill const &h);
00309 
00311   ~hill();
00312 
00314   hill & operator = (colvarbias_meta::hill const &h);
00315 
00317   inline cvm::real energy()
00318   {
00319     return W * sW * hill_value;
00320   }
00321 
00323   inline cvm::real energy(cvm::real const &new_weight)
00324   {
00325     return new_weight * sW * hill_value;
00326   }
00327 
00329   inline cvm::real const &value()
00330   {
00331     return hill_value;
00332   }
00333 
00335   inline void value(cvm::real const &new_value)
00336   {
00337     hill_value = new_value;
00338   }
00339 
00341   inline cvm::real weight()
00342   {
00343     return W * sW;
00344   }
00345 
00347   inline void scale(cvm::real const &new_scale_fac)
00348   {
00349     sW = new_scale_fac;
00350   }
00351 
00353   inline std::vector<colvarvalue> & center()
00354   {
00355     return centers;
00356   }
00357 
00359   inline colvarvalue & center(size_t const &i)
00360   {
00361     return centers[i];
00362   }
00363 
00365   inline friend bool operator < (hill const &h1, hill const &h2)
00366   {
00367     if (h1.it < h2.it) return true;
00368     else return false;
00369   }
00370 
00372   inline friend bool operator <= (hill const &h1, hill const &h2)
00373   {
00374     if (h1.it <= h2.it) return true;
00375     else return false;
00376   }
00377 
00379   inline friend bool operator > (hill const &h1, hill const &h2)
00380   {
00381     if (h1.it > h2.it) return true;
00382     else return false;
00383   }
00384 
00386   inline friend bool operator >= (hill const &h1, hill const &h2)
00387   {
00388     if (h1.it >= h2.it) return true;
00389     else return false;
00390   }
00391 
00393   inline friend bool operator == (hill const &h1, hill const &h2)
00394   {
00395     if ( (h1.it >= h2.it) && (h1.replica == h2.replica) ) return true;
00396     else return false;
00397   }
00398 
00400   std::string output_traj();
00401 
00403   friend std::ostream & operator << (std::ostream &os, hill const &h);
00404 
00405 };
00406 
00407 
00408 #endif

Generated on Fri Nov 8 02:44:09 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002