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

colvarmodule.h

Go to the documentation of this file.
00001 #ifndef COLVARMODULE_H
00002 #define COLVARMODULE_H
00003 
00004 #ifndef COLVARS_VERSION
00005 #define COLVARS_VERSION "2012-03-23"
00006 #endif
00007 
00008 #ifndef COLVARS_DEBUG
00009 #define COLVARS_DEBUG false
00010 #endif
00011 
00020 
00021 
00022 #include <iostream>
00023 #include <iomanip>
00024 #include <string>
00025 #include <sstream>
00026 #include <fstream>
00027 #include <cmath>
00028 #include <vector>
00029 #include <list>
00030 
00031 
00032 class colvarparse;
00033 class colvar;
00034 class colvarbias;
00035 class colvarproxy;
00036 
00037 
00047 class colvarmodule {
00048 
00049 private:
00050 
00052   colvarmodule();
00053 
00054 public:
00055 
00056   friend class colvarproxy;
00057   
00059   typedef  double    real;
00061   typedef  int       residue_id;
00062 
00063   class rvector;
00064   template <class T,
00065             size_t const length> class vector1d;
00066   template <class T,
00067             size_t const outer_length,
00068             size_t const inner_length> class matrix2d;
00069   class quaternion;
00070   class rotation;
00071 
00074   typedef rvector atom_pos;
00075 
00077   class rmatrix;
00078 
00079   // allow these classes to access protected data
00080   class atom;
00081   class atom_group;
00082   friend class atom;
00083   friend class atom_group;
00084   typedef std::vector<atom>::iterator       atom_iter;
00085   typedef std::vector<atom>::const_iterator atom_const_iter;
00086 
00088   static size_t it;
00090   static size_t it_restart;
00091 
00093   static inline size_t step_relative()
00094   {
00095     return it - it_restart;
00096   }
00097 
00100   static inline size_t step_absolute()
00101   {
00102     return it;
00103   }
00104 
00107   bool it_restart_from_state_file;
00108 
00112   static real debug_gradients_step_size;
00113 
00115   static std::string output_prefix;
00116 
00118   static std::string input_prefix;
00119 
00121   static std::string restart_in_name;
00122 
00123 
00125   static std::vector<colvar *>     colvars;
00126 
00127   /* TODO: implement named CVCs
00129   static std::vector<cvc *>     cvcs;
00131   inline void register_cvc (cvc *p) {
00132     cvcs.push_back(p);
00133   }
00134   */
00135 
00137   static std::vector<colvarbias *> biases;
00140   static size_t n_abf_biases;
00143   static size_t n_meta_biases;
00146   static size_t n_harm_biases;
00149   static size_t n_histo_biases;
00150    
00152   static inline bool debug()
00153   {
00154     return COLVARS_DEBUG;
00155   }
00156 
00157 
00160   colvarmodule (char const *config_name, 
00161                 colvarproxy *proxy_in);
00163   ~colvarmodule();
00164 
00166   void init_colvars (std::string const &conf);
00167 
00169   void init_biases (std::string const &conf);
00170 
00172   void change_configuration(std::string const &name, std::string const &conf);
00173 
00175   real energy_difference(std::string const &name, std::string const &conf);
00176 
00178   void calc();
00180   std::istream & read_restart (std::istream &is);
00182   std::ostream & write_restart (std::ostream &os);
00184   void write_output_files();
00186   static void backup_file (char const *filename);
00187 
00189   void analyze();
00192   bool read_traj (char const *traj_filename,
00193                   size_t      traj_read_begin,
00194                   size_t      traj_read_end);
00195  
00197   static colvar * colvar_p (std::string const &name);
00198 
00200   template<typename T> static std::string to_str (T const &x, 
00201                                                   size_t const &width = 0,
00202                                                   size_t const &prec = 0);
00204   template<typename T> static std::string to_str (std::vector<T> const &x, 
00205                                                   size_t const &width = 0,
00206                                                   size_t const &prec = 0);
00207 
00209   static inline std::string wrap_string (std::string const &s,
00210                                          size_t const &nchars)
00211   {
00212     if (!s.size())
00213       return std::string (nchars, ' ');
00214     else
00215       return ( (s.size() <= size_t (nchars)) ?
00216                (s+std::string (nchars-s.size(), ' ')) :
00217                (std::string (s, 0, nchars)) );
00218   }
00219 
00221   static size_t const it_width;
00223   static size_t const cv_prec;
00225   static size_t const cv_width;
00227   static size_t const en_prec;
00229   static size_t const en_width;
00231   static std::string const line_marker;
00232 
00233 
00234   // proxy functions
00235 
00238   static real unit_angstrom();
00239 
00241   static real boltzmann();
00242 
00244   static real temperature();
00245 
00247   static real dt();
00248   
00250   static void request_system_force();
00251   
00253   static void log (std::string const &message);
00254 
00256   static void fatal_error (std::string const &message);
00257 
00259   static void exit (std::string const &message);
00260 
00261 
00264   static rvector position_distance (atom_pos const &pos1,
00265                                     atom_pos const &pos2);
00266 
00267 
00274   static real position_dist2 (atom_pos const &pos1,
00275                               atom_pos const &pos2);
00276 
00280   static void select_closest_image (atom_pos &pos,
00281                                     atom_pos const &ref_pos);
00282 
00287   static void select_closest_images (std::vector<atom_pos> &pos,
00288                                      atom_pos const &ref_pos);
00289 
00290 
00295   static void load_atoms (char const *filename,
00296                           std::vector<atom> &atoms,
00297                           std::string const &pdb_field,
00298                           double const pdb_field_value = 0.0);
00299 
00303   static void load_coords (char const *filename,
00304                            std::vector<atom_pos> &pos,
00305                            const std::vector<int> &indices,
00306                            std::string const &pdb_field,
00307                            double const pdb_field_value = 0.0);
00308 
00309 
00311   static size_t cv_traj_freq;
00312 
00314   static bool   b_analysis;
00315 
00317   static size_t restart_out_freq;
00319   std::string   restart_out_name;
00320 
00322   static real rand_gaussian (void);
00323 protected:
00324 
00326   std::ifstream config_s;
00327 
00329   colvarparse *parse;
00330 
00332   std::string   cv_traj_name;
00333 
00335   std::ofstream cv_traj_os;
00336 
00338   bool          cv_traj_append;
00339 
00341   std::ofstream restart_out_os;
00342 
00346   static colvarproxy *proxy;
00347 
00349   static size_t depth;
00350 
00351 public:
00352 
00354   static void increase_depth();
00355 
00357   static void decrease_depth();
00358 };
00359 
00360 
00362 typedef colvarmodule cvm;
00363 
00364 
00365 #include "colvartypes.h"
00366 
00367 
00368 std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
00369 std::istream & operator >> (std::istream &is, cvm::rvector &v);
00370 
00371 
00372 template<typename T> std::string cvm::to_str (T const &x, 
00373                                               size_t const &width,
00374                                               size_t const &prec) {
00375   std::ostringstream os;
00376   if (width) os.width (width);
00377   if (prec) {
00378     os.setf (std::ios::scientific, std::ios::floatfield);
00379     os.precision (prec);
00380   }
00381   os << x;
00382   return os.str();
00383 }
00384 
00385 template<typename T> std::string cvm::to_str (std::vector<T> const &x, 
00386                                               size_t const &width,
00387                                               size_t const &prec) {
00388   if (!x.size()) return std::string ("");
00389   std::ostringstream os;
00390   if (prec) {
00391     os.setf (std::ios::scientific, std::ios::floatfield);
00392   }
00393   os << "{ ";
00394   if (width) os.width (width);
00395   if (prec) os.precision (prec);
00396   os << x[0];
00397   for (size_t i = 1; i < x.size(); i++) {
00398     os << ", ";
00399     if (width) os.width (width);
00400     if (prec) os.precision (prec);
00401     os << x[i];
00402   }
00403   os << " }";
00404   return os.str();
00405 }
00406 
00407 
00408 #include "colvarproxy.h"
00409 
00410 
00411 inline cvm::real cvm::unit_angstrom()
00412 {
00413   return proxy->unit_angstrom();
00414 }
00415 
00416 inline cvm::real cvm::boltzmann()
00417 {
00418   return proxy->boltzmann();
00419 }
00420 
00421 inline cvm::real cvm::temperature()
00422 {
00423   return proxy->temperature();
00424 }
00425 
00426 inline cvm::real cvm::dt()
00427 {
00428   return proxy->dt();
00429 }
00430 
00431 inline void cvm::request_system_force()
00432 {
00433   proxy->request_system_force (true);
00434 }
00435   
00436 inline void cvm::select_closest_image (atom_pos &pos,
00437                                        atom_pos const &ref_pos)
00438 {
00439   proxy->select_closest_image (pos, ref_pos);
00440 }
00441 
00442 inline void cvm::select_closest_images (std::vector<atom_pos> &pos,
00443                                         atom_pos const &ref_pos)
00444 {
00445   proxy->select_closest_images (pos, ref_pos);
00446 }
00447 
00448 inline cvm::rvector cvm::position_distance (atom_pos const &pos1,
00449                                             atom_pos const &pos2)
00450 {
00451   return proxy->position_distance (pos1, pos2);
00452 }
00453 
00454 inline cvm::real cvm::position_dist2 (cvm::atom_pos const &pos1,
00455                                       cvm::atom_pos const &pos2)
00456 {
00457   return proxy->position_dist2 (pos1, pos2);
00458 }
00459 
00460 inline void cvm::load_atoms (char const *file_name,
00461                              std::vector<cvm::atom> &atoms,
00462                              std::string const &pdb_field,
00463                              double const pdb_field_value)
00464 {
00465   proxy->load_atoms (file_name, atoms, pdb_field, pdb_field_value);
00466 }
00467 
00468 inline void cvm::load_coords (char const *file_name,
00469                               std::vector<cvm::atom_pos> &pos,
00470                               const std::vector<int> &indices,
00471                               std::string const &pdb_field,
00472                               double const pdb_field_value)
00473 {
00474   proxy->load_coords (file_name, pos, indices, pdb_field, pdb_field_value);
00475 }
00476 
00477 inline void cvm::backup_file (char const *filename)
00478 {
00479   proxy->backup_file (filename);
00480 }
00481 
00482 inline cvm::real cvm::rand_gaussian (void)
00483 {
00484   return proxy->rand_gaussian();
00485 }
00486 
00487 #endif
00488 
00489 
00490 // Emacs
00491 // Local Variables:
00492 // mode: C++
00493 // End:

Generated on Fri May 25 04:07:13 2012 for NAMD by  doxygen 1.3.9.1