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

colvarmodule.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 COLVARMODULE_H
00011 #define COLVARMODULE_H
00012 
00013 #include <cmath>
00014 
00015 #include "colvars_version.h"
00016 
00017 #ifndef COLVARS_DEBUG
00018 #define COLVARS_DEBUG false
00019 #endif
00020 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 #define COLVARS_OK 0
00037 #define COLVARS_ERROR   1
00038 #define COLVARS_NOT_IMPLEMENTED (1<<1)
00039 #define COLVARS_INPUT_ERROR     (1<<2) // out of bounds or inconsistent input
00040 #define COLVARS_BUG_ERROR       (1<<3) // Inconsistent state indicating bug
00041 #define COLVARS_FILE_ERROR      (1<<4)
00042 #define COLVARS_MEMORY_ERROR    (1<<5)
00043 #define COLVARS_NO_SUCH_FRAME   (1<<6) // Cannot load the requested frame
00044 
00045 #include <sstream>
00046 #include <string>
00047 #include <vector>
00048 #include <list>
00049 #include <iosfwd>
00050 
00051 class colvarparse;
00052 class colvar;
00053 class colvarbias;
00054 class colvarproxy;
00055 class colvarscript;
00056 class colvarvalue;
00057 
00058 
00068 class colvarmodule {
00069 
00070 private:
00071 
00073   colvarmodule();
00074 
00076   int version_int;
00077 
00078 public:
00079 
00081   std::string version() const
00082   {
00083     return std::string(COLVARS_VERSION);
00084   }
00085 
00087   int version_number() const
00088   {
00089     return version_int;
00090   }
00091 
00092   friend class colvarproxy;
00093   // TODO colvarscript should be unaware of colvarmodule's internals
00094   friend class colvarscript;
00095 
00097   typedef long long step_number;
00098 
00100   typedef  double    real;
00101 
00102 
00103   // Math functions
00104 
00106   static inline real integer_power(real const &x, int const n)
00107   {
00108     // Original code: math_special.h in LAMMPS
00109     double yy, ww;
00110     if (x == 0.0) return 0.0;
00111     int nn = (n > 0) ? n : -n;
00112     ww = x;
00113     for (yy = 1.0; nn != 0; nn >>= 1, ww *=ww) {
00114       if (nn & 1) yy *= ww;
00115     }
00116     return (n > 0) ? yy : 1.0/yy;
00117   }
00118 
00120   static inline real pow(real const &x, real const &y)
00121   {
00122     return ::pow(static_cast<double>(x), static_cast<double>(y));
00123   }
00124 
00126   static inline real floor(real const &x)
00127   {
00128     return ::floor(static_cast<double>(x));
00129   }
00130 
00132   static inline real fabs(real const &x)
00133   {
00134     return ::fabs(static_cast<double>(x));
00135   }
00136 
00138   static inline real sqrt(real const &x)
00139   {
00140     return ::sqrt(static_cast<double>(x));
00141   }
00142 
00144   static inline real sin(real const &x)
00145   {
00146     return ::sin(static_cast<double>(x));
00147   }
00148 
00150   static inline real cos(real const &x)
00151   {
00152     return ::cos(static_cast<double>(x));
00153   }
00154 
00156   static inline real asin(real const &x)
00157   {
00158     return ::asin(static_cast<double>(x));
00159   }
00160 
00162   static inline real acos(real const &x)
00163   {
00164     return ::acos(static_cast<double>(x));
00165   }
00166 
00168   static inline real atan2(real const &x, real const &y)
00169   {
00170     return ::atan2(static_cast<double>(x), static_cast<double>(y));
00171   }
00172 
00174   static inline real exp(real const &x)
00175   {
00176     return ::exp(static_cast<double>(x));
00177   }
00178 
00182   static inline real logn(real const &x)
00183   {
00184     return ::log(static_cast<double>(x));
00185   }
00186 
00187   // Forward declarations
00188   class rvector;
00189   template <class T> class vector1d;
00190   template <class T> class matrix2d;
00191   class quaternion;
00192   class rotation;
00193   class usage;
00194 
00196   typedef int residue_id;
00197 
00200   typedef rvector atom_pos;
00201 
00203   class rmatrix;
00204 
00205   // allow these classes to access protected data
00206   class atom;
00207   class atom_group;
00208   friend class atom;
00209   friend class atom_group;
00210   typedef std::vector<atom>::iterator       atom_iter;
00211   typedef std::vector<atom>::const_iterator atom_const_iter;
00212 
00215 private:
00216 
00217   static int errorCode;
00218 
00219 public:
00220 
00221   static void set_error_bits(int code);
00222 
00223   static bool get_error_bit(int code);
00224 
00225   static inline int get_error()
00226   {
00227     return errorCode;
00228   }
00229 
00230   static void clear_error();
00231 
00233   static step_number it;
00235   static step_number it_restart;
00236 
00238   static inline step_number step_relative()
00239   {
00240     return it - it_restart;
00241   }
00242 
00245   static inline step_number step_absolute()
00246   {
00247     return it;
00248   }
00249 
00253   static real debug_gradients_step_size;
00254 
00255 private:
00256 
00258   std::string cvm_output_prefix;
00259 
00260 public:
00262   static inline std::string &output_prefix()
00263   {
00264     colvarmodule *cv = colvarmodule::main();
00265     return cv->cvm_output_prefix;
00266   }
00267 
00268 private:
00269 
00271   std::vector<colvar *> colvars;
00272 
00274   std::vector<colvar *> colvars_active;
00275 
00278   std::vector<colvar *> colvars_smp;
00280   std::vector<int> colvars_smp_items;
00281 
00283   std::vector<atom_group *> named_atom_groups;
00284 public:
00286   void register_named_atom_group(atom_group *ag);
00287 
00289   void unregister_named_atom_group(atom_group *ag);
00290 
00292   std::vector<colvar *> *variables();
00293 
00294   /* TODO: implement named CVCs
00296   static std::vector<cvc *>     cvcs;
00298   inline void register_cvc(cvc *p) {
00299     cvcs.push_back(p);
00300   }
00301   */
00302 
00304   std::vector<colvar *> *variables_active();
00305 
00308   std::vector<colvar *> *variables_active_smp();
00309 
00311   std::vector<int> *variables_active_smp_items();
00312 
00314   std::vector<colvarbias *> biases;
00315 
00317   real total_bias_energy;
00318 
00319 private:
00320 
00322   void *num_biases_types_used_;
00323 
00325   std::vector<colvarbias *> biases_active_;
00326 
00327 public:
00328 
00330   std::vector<colvarbias *> *biases_active();
00331 
00333   static inline bool debug()
00334   {
00335     return COLVARS_DEBUG;
00336   }
00337 
00339   size_t size() const;
00340 
00343   colvarmodule(colvarproxy *proxy);
00344 
00346   ~colvarmodule();
00347 
00349   int reset();
00350 
00353   int read_config_file(char const *config_file_name);
00354 
00357   int read_config_string(std::string const &conf);
00358 
00360   int parse_config(std::string &conf);
00361 
00363   std::string const & get_config() const;
00364 
00365   // Parse functions (setup internal data based on a string)
00366 
00369   static std::istream & getline(std::istream &is, std::string &line);
00370 
00372   int parse_global_params(std::string const &conf);
00373 
00375   int parse_colvars(std::string const &conf);
00376 
00378   int run_tcl_script(std::string const &filename);
00379 
00381   int parse_biases(std::string const &conf);
00382 
00386   int append_new_config(std::string const &conf);
00387 
00389   void config_changed();
00390 
00391 private:
00392 
00394   std::string config_string;
00395 
00398   std::string extra_conf;
00399 
00401   template <class bias_type>
00402   int parse_biases_type(std::string const &conf, char const *keyword);
00403 
00406   bool check_new_bias(std::string &conf, char const *key);
00407 
00409   std::string source_Tcl_script;
00410 
00411 public:
00412 
00414   size_t num_variables() const;
00415 
00417   size_t num_variables_feature(int feature_id) const;
00418 
00420   size_t num_biases() const;
00421 
00423   size_t num_biases_feature(int feature_id) const;
00424 
00426   size_t num_biases_type(std::string const &type) const;
00427 
00430   std::vector<std::string> const time_dependent_biases() const;
00431 
00432 private:
00434   int catch_input_errors(int result);
00435 
00436 public:
00437 
00438   // "Setup" functions (change internal data based on related data
00439   // from the proxy that may change during program execution)
00440   // No additional parsing is done within these functions
00441 
00444   int update_engine_parameters();
00445 
00447   int setup_input();
00448 
00450   int setup_output();
00451 
00453   std::istream & read_restart(std::istream &is);
00454 
00456   std::istream & read_objects_state(std::istream &is);
00457 
00459   int print_total_forces_errning(bool warn_total_forces);
00460 
00462   std::ostream & write_restart(std::ostream &os);
00463 
00465   static std::string state_file_prefix(char const *filename);
00466 
00468   int open_traj_file(std::string const &file_name);
00470   int close_traj_file();
00472   std::ostream & write_traj(std::ostream &os);
00474   std::ostream & write_traj_label(std::ostream &os);
00475 
00477   int write_traj_files();
00479   int write_restart_file(std::string const &out_name);
00481   int write_output_files();
00483   static int backup_file(char const *filename);
00484 
00486   int write_restart_string(std::string &output);
00487 
00489   static colvarbias * bias_by_name(std::string const &name);
00490 
00492   static colvar * colvar_by_name(std::string const &name);
00493 
00495   static atom_group * atom_group_by_name(std::string const &name);
00496 
00499   int change_configuration(std::string const &bias_name, std::string const &conf);
00500 
00502   std::string read_colvar(std::string const &name);
00503 
00506   real energy_difference(std::string const &bias_name, std::string const &conf);
00507 
00509   int calc();
00510 
00512   int calc_colvars();
00513 
00515   int calc_biases();
00516 
00518   int update_colvar_forces();
00519 
00521   int analyze();
00522 
00524   int end_of_step();
00525 
00528   int read_traj(char const *traj_filename,
00529                 long        traj_read_begin,
00530                 long        traj_read_end);
00531 
00533   static std::string to_str(char const *s);
00534 
00536   static std::string to_str(std::string const &s);
00537 
00539   static std::string to_str(bool x);
00540 
00542   static std::string to_str(int const &x,
00543                             size_t width = 0, size_t prec = 0);
00544 
00546   static std::string to_str(size_t const &x,
00547                             size_t width = 0, size_t prec = 0);
00548 
00550   static std::string to_str(long int const &x,
00551                             size_t width = 0, size_t prec = 0);
00552 
00554   static std::string to_str(step_number const &x,
00555                             size_t width = 0, size_t prec = 0);
00556 
00558   static std::string to_str(real const &x,
00559                             size_t width = 0, size_t prec = 0);
00560 
00562   static std::string to_str(rvector const &x,
00563                             size_t width = 0, size_t prec = 0);
00564 
00566   static std::string to_str(quaternion const &x,
00567                             size_t width = 0, size_t prec = 0);
00568 
00570   static std::string to_str(colvarvalue const &x,
00571                             size_t width = 0, size_t prec = 0);
00572 
00574   static std::string to_str(vector1d<real> const &x,
00575                             size_t width = 0, size_t prec = 0);
00576 
00578   static std::string to_str(matrix2d<real> const &x,
00579                             size_t width = 0, size_t prec = 0);
00580 
00581 
00583   static std::string to_str(std::vector<int> const &x,
00584                             size_t width = 0, size_t prec = 0);
00585 
00587   static std::string to_str(std::vector<size_t> const &x,
00588                             size_t width = 0, size_t prec = 0);
00589 
00591   static std::string to_str(std::vector<long int> const &x,
00592                             size_t width = 0, size_t prec = 0);
00593 
00595   static std::string to_str(std::vector<real> const &x,
00596                             size_t width = 0, size_t prec = 0);
00597 
00599   static std::string to_str(std::vector<rvector> const &x,
00600                             size_t width = 0, size_t prec = 0);
00601 
00603   static std::string to_str(std::vector<quaternion> const &x,
00604                             size_t width = 0, size_t prec = 0);
00605 
00607   static std::string to_str(std::vector<colvarvalue> const &x,
00608                             size_t width = 0, size_t prec = 0);
00609 
00611   static std::string to_str(std::vector<std::string> const &x,
00612                             size_t width = 0, size_t prec = 0);
00613 
00614 
00616   static std::string wrap_string(std::string const &s,
00617                                  size_t nchars);
00618 
00620   static size_t const it_width;
00622   static size_t const cv_prec;
00624   static size_t const cv_width;
00626   static size_t const en_prec;
00628   static size_t const en_width;
00630   static const char * const line_marker;
00631 
00632 
00633   // proxy functions
00634 
00636   static real dt();
00637 
00639   static void request_total_force();
00640 
00642   int cite_feature(std::string const &feature);
00643 
00645   std::string feature_report(int flag = 0);
00646 
00650   static void log(std::string const &message, int min_log_level = 10);
00651 
00653   static int error(std::string const &message, int code = COLVARS_ERROR);
00654 
00655 private:
00656 
00658   static int log_level_;
00659 
00660 public:
00661 
00663   static inline int log_level()
00664   {
00665     return log_level_;
00666   }
00667 
00669   static inline int log_init_messages()
00670   {
00671     return 1;
00672   }
00673 
00675   static inline int log_user_params()
00676   {
00677     return 2;
00678   }
00679 
00681   static inline int log_default_params()
00682   {
00683     return 3;
00684   }
00685 
00687   static inline int log_output_files()
00688   {
00689     return 4;
00690   }
00691 
00693   static inline int log_input_files()
00694   {
00695     return 5;
00696   }
00697 
00700   static rvector position_distance(atom_pos const &pos1,
00701                                    atom_pos const &pos2);
00702 
00704   std::vector<std::string> index_file_names;
00705 
00707   std::vector<std::string> index_group_names;
00708 
00710   std::vector<std::vector<int> *> index_groups;
00711 
00713   int read_index_file(char const *filename);
00714 
00716   int reset_index_groups();
00717 
00724   static int load_atoms(char const *filename,
00725                         atom_group &atoms,
00726                         std::string const &pdb_field,
00727                         double pdb_field_value = 0.0);
00728 
00737   static int load_coords(char const *filename,
00738                          std::vector<rvector> *pos,
00739                          atom_group *atoms,
00740                          std::string const &pdb_field,
00741                          double pdb_field_value = 0.0);
00742 
00744   int load_coords_xyz(char const *filename,
00745                       std::vector<rvector> *pos,
00746                       atom_group *atoms);
00747 
00749   static size_t cv_traj_freq;
00750 
00752   static size_t restart_out_freq;
00754   std::string   restart_out_name;
00755 
00757   static real rand_gaussian(void);
00758 
00759 protected:
00760 
00762   colvarparse *parse;
00763 
00765   std::string cv_traj_name;
00766 
00768   bool cv_traj_write_labels;
00769 
00771   std::string restart_version_str;
00772 
00774   int restart_version_int;
00775 
00777   size_t depth_s;
00778 
00780   std::vector<size_t> depth_v;
00781 
00783   int xyz_reader_use_count;
00784 
00786   usage *usage_;
00787 
00788 public:
00789 
00791   inline std::string restart_version() const
00792   {
00793     return restart_version_str;
00794   }
00795 
00797   inline int restart_version_number() const
00798   {
00799     return restart_version_int;
00800   }
00801 
00803   static size_t & depth();
00804 
00806   static void increase_depth();
00807 
00809   static void decrease_depth();
00810 
00811   static inline bool scripted_forces()
00812   {
00813     return use_scripted_forces;
00814   }
00815 
00817   static bool use_scripted_forces;
00818 
00820   static bool scripting_after_biases;
00821 
00823   int calc_scripted_forces();
00824 
00828   static colvarproxy *proxy;
00829 
00831   static colvarmodule *main();
00832 
00833 };
00834 
00835 
00837 typedef colvarmodule cvm;
00838 
00839 
00840 
00841 std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
00842 std::istream & operator >> (std::istream &is, cvm::rvector &v);
00843 
00844 
00845 #endif

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