00001 #ifndef COLVARMODULE_H
00002 #define COLVARMODULE_H
00003
00004 #ifndef COLVARS_DEBUG
00005 #define COLVARS_DEBUG false
00006 #endif
00007
00008 #ifndef COLVARS_VERSION
00009 #define COLVARS_VERSION "20090807"
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
00065 typedef int atom_id;
00066
00067 class rvector;
00068 template <class T,
00069 size_t const length> class vector1d;
00070 template <class T,
00071 size_t const outer_length,
00072 size_t const inner_length> class matrix2d;
00073 class quaternion;
00074 class rotation;
00075
00078 typedef rvector atom_pos;
00079
00081 class rmatrix;
00082
00083
00084 class atom;
00085 class atom_group;
00086 friend class atom;
00087 friend class atom_group;
00088 typedef std::vector<atom>::iterator atom_iter;
00089 typedef std::vector<atom>::const_iterator atom_const_iter;
00090
00092 static size_t it;
00094 static size_t it_restart;
00095
00097 static inline size_t step_relative()
00098 {
00099 return it - it_restart;
00100 }
00101
00104 static inline size_t step_absolute()
00105 {
00106 return it;
00107 }
00108
00110 static real dt;
00111
00115 static real debug_gradients_step_size;
00116
00118 static std::string output_prefix;
00119
00121 static std::string input_prefix;
00122
00124 static std::string restart_in_name;
00125
00126
00128 static std::vector<colvar *> colvars;
00130 static std::vector<colvarbias *> biases;
00133 static size_t n_abf_biases;
00136 static size_t n_meta_biases;
00139 static size_t n_harm_biases;
00142 static size_t n_histo_biases;
00143
00145 static inline bool debug()
00146 {
00147 return COLVARS_DEBUG;
00148 }
00149
00150
00153 colvarmodule (char const *config_name,
00154 colvarproxy *proxy_in);
00156 ~colvarmodule();
00157
00159 void init_colvars (std::string const &conf);
00160
00162 void init_biases (std::string const &conf);
00163
00165 void calc();
00167 std::istream & read_restart (std::istream &is);
00169 std::ostream & write_restart (std::ostream &os);
00171 void finalise();
00172
00174 void analyse();
00176 bool read_traj (char const *cv_traj_filename);
00177
00179 static colvar * colvar_p (std::string const &name);
00180
00182 template<typename T> static std::string to_str (T const &x,
00183 size_t const &width = 0,
00184 size_t const &prec = 0);
00186 template<typename T> static std::string to_str (std::vector<T> const &x,
00187 size_t const &width = 0,
00188 size_t const &prec = 0);
00189
00191 static inline std::string wrap_string (std::string const &s,
00192 size_t const &nchars)
00193 {
00194 if (!s.size())
00195 return std::string (nchars, ' ');
00196 else
00197 return ( (s.size() <= size_t (nchars)) ?
00198 (s+std::string (nchars-s.size(), ' ')) :
00199 (std::string (s, 0, nchars)) );
00200 }
00201
00203 static size_t const it_width;
00205 static size_t const cv_prec;
00207 static size_t const cv_width;
00209 static size_t const en_prec;
00211 static size_t const en_width;
00213 static std::string const line_marker;
00214
00215
00216
00217
00220 static real unit_angstrom();
00221
00223 static real boltzmann();
00224
00226 static real temperature();
00227
00229 static void log (std::string const &message);
00230
00232 static void fatal_error (std::string const &message);
00233
00235 static void exit (std::string const &message);
00236
00237
00240 static rvector position_distance (atom_pos const &pos1,
00241 atom_pos const &pos2);
00242
00243
00250 static real position_dist2 (atom_pos const &pos1,
00251 atom_pos const &pos2);
00252
00256 static void select_closest_image (atom_pos &pos,
00257 atom_pos const &ref_pos);
00258
00263 static void select_closest_images (std::vector<atom_pos> &pos,
00264 atom_pos const &ref_pos);
00265
00266
00271 static void load_atoms (char const *filename,
00272 std::vector<atom> &atoms,
00273 std::string const &pdb_field = "O",
00274 double const pdb_field_value = 0.0);
00275
00279 static void load_coords (char const *filename,
00280 std::vector<atom_pos> &pos,
00281 std::string const &pdb_field = "O",
00282 double const pdb_field_value = 0.0);
00283
00285 static size_t cv_traj_freq;
00286
00288 static bool b_analysis;
00289
00291 std::string cv_traj_read_name;
00293 size_t cv_traj_read_begin, cv_traj_read_end;
00294
00296 static size_t restart_out_freq;
00298 std::string restart_out_name;
00299
00300 protected:
00301
00303 std::ifstream config_s;
00304
00306 colvarparse *parse;
00307
00309 std::ofstream cv_traj_os;
00310
00312 std::ofstream restart_out_os;
00313
00317 static colvarproxy *proxy;
00318
00320 static size_t depth;
00321
00322 public:
00323
00325 static void increase_depth();
00326
00328 static void decrease_depth();
00329 };
00330
00331
00333 typedef colvarmodule cvm;
00334
00335
00336 #include "colvartypes.h"
00337
00338
00339 std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
00340 std::istream & operator >> (std::istream &is, cvm::rvector &v);
00341
00342
00343 template<typename T> std::string cvm::to_str (T const &x,
00344 size_t const &width,
00345 size_t const &prec) {
00346 std::ostringstream os;
00347 if (width) os.width (width);
00348 if (prec) {
00349 os.setf (std::ios::scientific, std::ios::floatfield);
00350 os.precision (prec);
00351 }
00352 os << x;
00353 return os.str();
00354 }
00355
00356 template<typename T> std::string cvm::to_str (std::vector<T> const &x,
00357 size_t const &width,
00358 size_t const &prec) {
00359 if (!x.size()) return std::string ("");
00360 std::ostringstream os;
00361 if (prec) {
00362 os.setf (std::ios::scientific, std::ios::floatfield);
00363 }
00364 os << "{ ";
00365 if (width) os.width (width);
00366 if (prec) os.precision (prec);
00367 os << x[0];
00368 for (size_t i = 1; i < x.size(); i++) {
00369 os << ", ";
00370 if (width) os.width (width);
00371 if (prec) os.precision (prec);
00372 os << x[i];
00373 }
00374 os << " }";
00375 return os.str();
00376 }
00377
00378
00379 #include "colvarproxy.h"
00380
00381
00382 inline cvm::real cvm::unit_angstrom()
00383 {
00384 return proxy->unit_angstrom();
00385 }
00386
00387 inline cvm::real cvm::boltzmann()
00388 {
00389 return proxy->boltzmann();
00390 }
00391
00392 inline cvm::real cvm::temperature()
00393 {
00394 return proxy->temperature();
00395 }
00396
00397 inline void cvm::select_closest_image (atom_pos &pos,
00398 atom_pos const &ref_pos)
00399 {
00400 proxy->select_closest_image (pos, ref_pos);
00401 }
00402
00403 inline void cvm::select_closest_images (std::vector<atom_pos> &pos,
00404 atom_pos const &ref_pos)
00405 {
00406 proxy->select_closest_images (pos, ref_pos);
00407 }
00408
00409 inline cvm::rvector cvm::position_distance (atom_pos const &pos1,
00410 atom_pos const &pos2)
00411 {
00412 return proxy->position_distance (pos1, pos2);
00413 }
00414
00415 inline cvm::real cvm::position_dist2 (cvm::atom_pos const &pos1,
00416 cvm::atom_pos const &pos2)
00417 {
00418 return proxy->position_dist2 (pos1, pos2);
00419 }
00420
00421 inline void cvm::load_atoms (char const *file_name,
00422 std::vector<cvm::atom> &atoms,
00423 std::string const &pdb_field,
00424 double const pdb_field_value)
00425 {
00426 proxy->load_atoms (file_name, atoms, pdb_field, pdb_field_value);
00427 }
00428
00429 inline void cvm::load_coords (char const *file_name,
00430 std::vector<cvm::atom_pos> &pos,
00431 std::string const &pdb_field,
00432 double const pdb_field_value)
00433 {
00434 proxy->load_coords (file_name, pos, pdb_field, pdb_field_value);
00435 }
00436
00437
00438 #endif
00439
00440
00441
00442
00443
00444