Collective Variables Module - Developer Documentation
colvarmodule.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 
3 // This file is part of the Collective Variables module (Colvars).
4 // The original version of Colvars and its updates are located at:
5 // https://github.com/Colvars/colvars
6 // Please update all Colvars source files before making any changes.
7 // If you wish to distribute your changes, please submit them to the
8 // Colvars repository at GitHub.
9 
10 #ifndef COLVARMODULE_H
11 #define COLVARMODULE_H
12 
13 #include <cstdint>
14 #include <unordered_map>
15 #include <memory>
16 #include <cstdio>
17 #include <atomic>
18 #include <stdexcept>
19 
20 #include "colvars_version.h"
21 
22 #ifndef COLVARS_DEBUG
23 #define COLVARS_DEBUG false
24 #endif
25 
26 #if defined(__FAST_MATH__)
27 // NOTE: This is used for fixing https://github.com/Colvars/colvars/issues/767
28 #define COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
29 #endif
30 
31 #define COLVARS_USE_SOA
32 
49 
50 #include <cmath>
51 #include <iosfwd>
52 #include <string>
53 #include <vector>
54 #include "colvar_gpu_support.h"
55 
56 class colvarparse;
57 class colvar;
58 class colvarbias;
59 class colvarproxy;
60 class colvarvalue;
61 class colvardeps;
62 
63 
72 class colvars_fatal_error : public std::runtime_error {
73 public:
74  using std::runtime_error::runtime_error;
75 };
76 
77 
87 class colvarmodule {
88 
89 public:
90 
92  std::string version() const;
93 
95  int version_number() const;
96 
98  int patch_version_number() const;
99 
100 private:
101 
103  int version_int = 0;
104 
107 
108 public:
109 
111  typedef long long step_number;
112 
114  typedef double real;
115 
116 
117  // Math functions
118 
120  static COLVARS_HOST_DEVICE inline real integer_power(real const &x, int const n)
121  {
122  // Original code: math_special.h in LAMMPS
123  double yy, ww;
124  if (x == 0.0) return 0.0;
125  int nn = (n > 0) ? n : -n;
126  ww = x;
127  for (yy = 1.0; nn != 0; nn >>= 1, ww *=ww) {
128  if (nn & 1) yy *= ww;
129  }
130  return (n > 0) ? yy : 1.0/yy;
131  }
132 
133  template <int n>
134  static COLVARS_HOST_DEVICE inline real
135  positive_integer_power(real const& x) {
136  static_assert(n > 0, "n must be greater than zero in positive_integer_power.");
137  real y = 1.0;
138  for (int i = 0; i < n; ++i) {
139  y *= x;
140  }
141  return y;
142  }
143 
145  static inline real pow(real const &x, real const &y)
146  {
147  return ::pow(static_cast<double>(x), static_cast<double>(y));
148  }
149 
151  static inline real floor(real const &x)
152  {
153  return ::floor(static_cast<double>(x));
154  }
155 
157  static inline real ceil(real const &x)
158  {
159  return ::ceil(static_cast<double>(x));
160  }
161 
163  static inline real fabs(real const &x)
164  {
165  return ::fabs(static_cast<double>(x));
166  }
167 
169  static inline real sqrt(real const &x)
170  {
171  return ::sqrt(static_cast<double>(x));
172  }
173 
175  static inline real sin(real const &x)
176  {
177  return ::sin(static_cast<double>(x));
178  }
179 
181  static inline real cos(real const &x)
182  {
183  return ::cos(static_cast<double>(x));
184  }
185 
186 #ifndef PI
187 #define PI 3.14159265358979323846
188 #endif
189 #ifndef PI_2
190 #define PI_2 1.57079632679489661923
191 #endif
192 
194 static inline real asin(real const &x)
195 {
196 #ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
197  if (x <= -1.0) {
198  return -PI_2;
199  } else if (x >= 1.0) {
200  return PI_2;
201  } else {
202  return ::asin(static_cast<double>(x));
203  }
204 #else
205  return ::asin(static_cast<double>(x));
206 #endif
207 }
208 
210 static inline real acos(real const &x)
211 {
212 #ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
213  if (x <= -1.0) {
214  return PI;
215  } else if (x >= 1.0) {
216  return 0.0;
217  } else {
218  return ::acos(static_cast<double>(x));
219  }
220 #else
221  return ::acos(static_cast<double>(x));
222 #endif
223 }
224 
226  static inline real atan2(real const &x, real const &y)
227  {
228  return ::atan2(static_cast<double>(x), static_cast<double>(y));
229  }
230 
232  static inline real tanh(real const &x)
233  {
234  return ::tanh(static_cast<double>(x));
235  }
236 
238  static inline real exp(real const &x)
239  {
240  return ::exp(static_cast<double>(x));
241  }
242 
246  static inline real logn(real const &x)
247  {
248  return ::log(static_cast<double>(x));
249  }
250 
251  // Forward declarations
252  class rvector;
253  template <class T> class vector1d;
254  template <class T> class matrix2d;
255  class quaternion;
256  class rotation;
257  class system_boundary_conditions;
258 
259  class usage;
260  class memory_stream;
261 
263  typedef int residue_id;
264 
267  typedef rvector atom_pos;
268 
270  class rmatrix;
271 
272  // NOTE: Just here for ensuring the compilation of GROMACS with Colvars
273  struct atom;
274  // class atom_group_base;
275  class atom_group;
276  // class atom_group_gpu;
277  // typedef std::vector<atom>::iterator atom_iter;
278  // typedef std::vector<atom>::const_iterator atom_const_iter;
279 
282 private:
283 
284  int errorCode = 0;
285 
286 public:
287 
288  void set_error_bits(int code);
289 
290  bool get_error_bit(int code);
291 
292  inline int get_error()
293  {
294  return errorCode;
295  }
296 
297  void clear_error();
298 
303 
306  {
307  return it - it_restart;
308  }
309 
313  {
314  return it;
315  }
316 
317  bool binary_restart;
318 
323 
324 private:
325 
327  std::string cvm_output_prefix;
328 
329 public:
331  inline std::string &output_prefix()
332  {
333  return this->cvm_output_prefix;
334  }
335 
336 private:
337 
339  std::vector<colvar *> colvars;
340 
342  std::vector<colvar *> colvars_active;
343 
346  std::vector<colvar *> colvars_smp;
348  std::vector<int> colvars_smp_items;
349 
351  std::vector<atom_group *> named_atom_groups;
352 
353 public:
354 
355  void register_named_atom_group(atom_group *ag);
356  void unregister_named_atom_group(atom_group *ag);
357 
359  std::vector<colvar *> *variables();
360 
361  /* TODO: implement named CVCs
363  std::vector<cvc *> cvcs;
365  inline void register_cvc(cvc *p) {
366  cvcs.push_back(p);
367  }
368  */
369 
371  std::vector<colvar *> *variables_active();
372 
375  std::vector<colvar *> *variables_active_smp();
376 
378  std::vector<int> *variables_active_smp_items();
379 
381  int calc_component_smp(int i);
382 
384  std::vector<colvarbias *> biases;
385 
388 
389 private:
390 
393 
395  std::vector<colvarbias *> biases_active_;
396 
397 public:
398 
400  std::vector<colvarbias *> *biases_active();
401 
403  static inline bool constexpr debug()
404  {
405 #if (defined(__HIP_DEVICE_COMPILE__)) || (defined(__CUDA_ARCH__))
406  return false;
407 #else
408  return COLVARS_DEBUG;
409 #endif
410  }
411 
413  size_t size() const;
414 
418 
419 private:
420 
423 
424 public:
425 
427  ~colvarmodule();
428 
431 
433  int reset();
434 
437  int read_config_file(char const *config_file_name);
438 
441  int read_config_string(std::string const &conf);
442 
444  int parse_config(std::string &conf);
445 
446 private:
447 
449  int parse_config_impl(std::string &conf);
450  int calc_impl();
451  int setup_input_impl();
452 
453 public:
454 
456  std::string const & get_config() const;
457 
458  // Parse functions (setup internal data based on a string)
459 
462  static std::istream & getline(std::istream &is, std::string &line);
463 
465  int parse_global_params(std::string const &conf);
466 
468  int parse_colvars(std::string const &conf);
469 
471  int run_tcl_script(std::string const &filename);
472 
474  int parse_biases(std::string const &conf);
475 
479  int append_new_config(std::string const &conf);
480 
482  void config_changed();
483 
484 private:
485 
487  std::string config_string;
488 
491  std::string extra_conf;
492 
494  template <class bias_type>
495  int parse_biases_type(std::string const &conf, char const *keyword);
496 
499  bool check_new_bias(std::string &conf, char const *key);
500 
502  std::string source_Tcl_script;
503 
504 public:
505 
507  size_t num_variables() const;
508 
510  size_t num_variables_feature(int feature_id) const;
511 
513  size_t num_biases() const;
514 
516  size_t num_biases_feature(int feature_id) const;
517 
519  size_t num_biases_type(std::string const &type) const;
520 
523  std::vector<std::string> const time_dependent_biases() const;
524 
525 private:
527  int catch_input_errors(int result);
528 
529 public:
530 
531  // "Setup" functions (change internal data based on related data
532  // from the proxy that may change during program execution)
533  // No additional parsing is done within these functions
534 
538 
540  int setup_input();
541 
543  int setup_output();
544 
545 private:
546 
547  template <typename IST> IST & read_state_template_(IST &is);
548 
551 
553  std::vector<unsigned char> input_state_buffer_;
554 
555 public:
556 
558  std::istream & read_state(std::istream &is);
559 
561  memory_stream & read_state(memory_stream &is);
562 
564  int set_input_state_buffer(size_t n, unsigned char *buf);
565 
567  int set_input_state_buffer(std::vector<unsigned char> &buf);
568 
570  std::istream & read_objects_state(std::istream &is);
571 
573  memory_stream & read_objects_state(memory_stream &is);
574 
576  int print_total_forces_errning(bool warn_total_forces);
577 
578 private:
579  template <typename OST> OST &write_state_template_(OST &os);
580 
581 public:
582 
584  std::ostream & write_state(std::ostream &os);
585 
587  memory_stream & write_state(memory_stream &os);
588 
590  int write_state_buffer(std::vector<unsigned char> &buffer);
591 
593  std::string state_file_prefix(char const *filename);
594 
596  int open_traj_file(std::string const &file_name);
600  std::ostream & write_traj(std::ostream &os);
602  std::ostream & write_traj_label(std::ostream &os);
603 
605  int write_traj_files();
607  int write_restart_file(std::string const &out_name);
609  int write_output_files();
611  int backup_file(char const *filename);
612 
614  int write_restart_string(std::string &output);
615 
617  colvarbias * bias_by_name(std::string const &name);
618 
620  colvar * colvar_by_name(std::string const &name);
621 
623  atom_group * atom_group_by_name(std::string const& name);
624 
627  int change_configuration(std::string const &bias_name, std::string const &conf);
628 
630  std::string read_colvar(std::string const &name);
631 
634  real energy_difference(std::string const &bias_name, std::string const &conf);
635 
637  int calc();
638 
640  int calc_colvars();
641 
643  int calc_biases();
644 
646  int update_colvar_forces();
647 
650 
652  int analyze();
653 
655  int end_of_step();
656 
659  int read_traj(char const *traj_filename,
660  long traj_read_begin,
661  long traj_read_end);
662 
663  // In a first phase, keep to_str() static
664 
666  static std::string to_str(char const *s);
667 
669  static std::string to_str(const void* ptr);
670 
672  static std::string to_str(std::string const &s);
673 
675  static std::string to_str(bool x);
676 
678  static std::string to_str(int const &x,
679  size_t width = 0, size_t prec = 0);
680 
682  static std::string to_str(size_t const &x,
683  size_t width = 0, size_t prec = 0);
684 
686  static std::string to_str(long int const &x,
687  size_t width = 0, size_t prec = 0);
688 
690  static std::string to_str(step_number const &x,
691  size_t width = 0, size_t prec = 0);
692 
694  static std::string to_str(real const &x,
695  size_t width = 0, size_t prec = 0);
696 
698  static std::string to_str(rvector const &x,
699  size_t width = 0, size_t prec = 0);
700 
702  static std::string to_str(quaternion const &x,
703  size_t width = 0, size_t prec = 0);
704 
706  static std::string to_str(colvarvalue const &x,
707  size_t width = 0, size_t prec = 0);
708 
710  static std::string to_str(vector1d<real> const &x,
711  size_t width = 0, size_t prec = 0);
712 
714  static std::string to_str(matrix2d<real> const &x,
715  size_t width = 0, size_t prec = 0);
716 
717 
719  static std::string to_str(std::vector<int> const &x,
720  size_t width = 0, size_t prec = 0);
721 
723  static std::string to_str(std::vector<size_t> const &x,
724  size_t width = 0, size_t prec = 0);
725 
727  static std::string to_str(std::vector<long int> const &x,
728  size_t width = 0, size_t prec = 0);
729 
731  static std::string to_str(std::vector<real> const &x,
732  size_t width = 0, size_t prec = 0);
733 
735  static std::string to_str(std::vector<rvector> const &x,
736  size_t width = 0, size_t prec = 0);
737 
739  static std::string to_str(std::vector<quaternion> const &x,
740  size_t width = 0, size_t prec = 0);
741 
743  static std::string to_str(std::vector<colvarvalue> const &x,
744  size_t width = 0, size_t prec = 0);
745 
747  static std::string to_str(std::vector<std::string> const &x,
748  size_t width = 0, size_t prec = 0);
749 
750 #if ( defined(COLVARS_CUDA) || defined(COLVARS_HIP) )
751  static std::string to_str(std::vector<rvector, colvars_gpu::CudaHostAllocator<rvector>> const &x,
752  size_t width = 0, size_t prec = 0);
753  static std::string to_str(std::vector<real, colvars_gpu::CudaHostAllocator<real>> const &x,
754  size_t width = 0, size_t prec = 0);
755 #endif
756 
757 
759  static std::string wrap_string(std::string const &s,
760  size_t nchars);
761 
762  // i/o constants
763 
765  static constexpr size_t it_width = 12;
767  static constexpr size_t cv_prec = 14;
769  static constexpr size_t cv_width = 21;
771  static constexpr size_t en_prec = 14;
773  static constexpr size_t en_width = 21;
775  static constexpr const char line_marker[] =
776  "----------------------------------------------------------------------\n";
777 
778  // proxy functions
779 
781  real dt();
782 
784  void request_total_force();
785 
787  int cite_feature(std::string const &feature);
788 
790  std::string feature_report(int flag = 0);
791 
795  void log(std::string const &message, int min_log_level = 10);
796 
799  static void log_static(colvarmodule* cvmodule, std::string const &message) {
800  if (cvmodule) {
801  cvmodule->log(message);
802  } else {
803  std::printf("colvars: %s\n", message.c_str());
804  }
805  }
806 
808  int error(std::string const &message, int code = -1);
809 
815  static int error_static(colvarmodule* cvmodule, std::string const &message, int code = -1) {
816  if (cvmodule) {
817  return cvmodule->error(message, code);
818  }
819  throw colvars_fatal_error(message);
820  }
821 
822 private:
823 
825  int log_level_ = 10;
826 
827 public:
828 
830  inline int log_level()
831  {
832  return log_level_;
833  }
834 
836  inline int log_init_messages()
837  {
838  return 1;
839  }
840 
842  inline int log_user_params()
843  {
844  return 2;
845  }
846 
848  inline int log_default_params()
849  {
850  return 3;
851  }
852 
854  inline int log_output_files()
855  {
856  return 4;
857  }
858 
860  inline int log_input_files()
861  {
862  return 5;
863  }
864 
866  std::vector<std::string> index_file_names;
867 
869  std::vector<std::string> index_group_names;
870 
872  std::vector<std::vector<int> *> index_groups;
873 
875  int read_index_file(char const *filename);
876 
878  int reset_index_groups();
879 
888  int load_coords(char const *filename,
889  std::vector<rvector> *pos,
890  atom_group *atoms,
891  std::string const &pdb_field,
892  double pdb_field_value = 0.0);
893 
895  int load_coords_xyz(char const *filename,
896  std::vector<rvector> *pos,
897  atom_group *atoms,
898  bool keep_open = false);
899 
901  size_t cv_traj_freq = 0;
902 
904  size_t restart_out_freq = 0;
906  std::string restart_out_name;
907 
910 
911 protected:
912 
915 
917  std::string cv_traj_name;
918 
921 
923  std::string restart_version_str;
924 
927 
929  size_t depth_s;
930 
932  std::vector<size_t> depth_v;
933 
936 
939 
942  std::atomic<real> max_gradient_error{0.};
943 
944 public:
945 
947  inline std::string restart_version() const
948  {
949  return restart_version_str;
950  }
951 
953  inline int restart_version_number() const
954  {
955  return restart_version_int;
956  }
957 
959  size_t & depth();
960 
962  void increase_depth();
963 
965  void decrease_depth();
966 
967  inline bool scripted_forces()
968  {
969  return use_scripted_forces;
970  }
971 
973  bool use_scripted_forces = false;
974 
977 
979  int calc_scripted_forces();
980 
985  real current = max_gradient_error.load(std::memory_order_relaxed);
986  while (error > current &&
987  !max_gradient_error.compare_exchange_weak(current, error, std::memory_order_relaxed)) {
988  }
989  }
990 
991  real get_max_gradient_error() {
992  return max_gradient_error;
993  }
994 
997  colvarproxy *proxy = nullptr;
998 
999 #if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
1000  template <typename T>
1002 #else
1003  template <typename T>
1004  using allocator_type = std::allocator<T>;
1005 #endif
1006  using ag_vector_real_t = std::vector<real, allocator_type<real>>;
1007 
1008 };
1009 
1012 
1013 
1014 std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
1015 std::istream & operator >> (std::istream &is, cvm::rvector &v);
1016 
1017 
1018 namespace {
1019  constexpr int32_t COLVARS_OK = 0;
1020  constexpr int32_t COLVARS_ERROR = 1;
1021  constexpr int32_t COLVARS_NOT_IMPLEMENTED = (1<<1);
1022  constexpr int32_t COLVARS_INPUT_ERROR = (1<<2); // out of bounds or inconsistent input
1023  constexpr int32_t COLVARS_BUG_ERROR = (1<<3); // Inconsistent state indicating bug
1024  constexpr int32_t COLVARS_FILE_ERROR = (1<<4);
1025  constexpr int32_t COLVARS_MEMORY_ERROR = (1<<5);
1026  constexpr int32_t COLVARS_NO_SUCH_FRAME = (1<<6); // Cannot load the requested frame
1027 }
1028 
1029 
1030 #endif
A collective variable (main class); to be defined, it needs at least one object of a derived class of...
Definition: colvar.h:53
Collective variable bias, base class.
Definition: colvarbias.h:23
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:34
Arbitrary size array (two dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:382
1-dimensional vector of real numbers with four components and a quaternion algebra
Definition: colvartypes.h:992
2-dimensional array of real numbers with three components along each dimension (works with colvarmodu...
Definition: colvartypes.h:915
vector of real numbers with three components
Definition: colvartypes.h:740
Track usage of Colvars features.
Definition: colvarmodule.cpp:57
Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:36
Collective variables module (main class)
Definition: colvarmodule.h:87
int cite_feature(std::string const &feature)
Track usage of the given Colvars feature.
Definition: colvarmodule.cpp:2754
static constexpr const char line_marker[]
Line separator in the log output.
Definition: colvarmodule.h:775
memory_stream & write_state(memory_stream &os)
Write the state of the module to an unformatted (binary) file.
int log_input_files()
Level at which input-file operations (configuration, state) are logged.
Definition: colvarmodule.h:860
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:267
int write_traj_files()
Write all trajectory files.
Definition: colvarmodule.cpp:1357
int load_coords_xyz(char const *filename, std::vector< rvector > *pos, atom_group *atoms, bool keep_open=false)
Load coordinates into an atom group from an XYZ file (assumes Angstroms)
Definition: colvarmodule.cpp:2422
std::ostream & write_state(std::ostream &os)
Write the state of the module to a formatted (text) file.
Definition: colvarmodule.cpp:2089
std::string state_file_prefix(char const *filename)
Strips .colvars.state from filename and checks that it is not empty.
Definition: colvarmodule.cpp:1703
static real pow(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:145
size_t num_biases_feature(int feature_id) const
Return how many biases have this feature enabled.
Definition: colvarmodule.cpp:774
static real asin(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:194
bool cv_traj_write_labels
Write labels at the next iteration.
Definition: colvarmodule.h:920
static std::string to_str(std::vector< quaternion > const &x, size_t width=0, size_t prec=0)
Convert to string for output purposes.
std::vector< std::string > const time_dependent_biases() const
Definition: colvarmodule.cpp:802
std::string cv_traj_name
Name of the trajectory file.
Definition: colvarmodule.h:917
static real logn(real const &x)
Definition: colvarmodule.h:246
std::vector< atom_group * > named_atom_groups
Array of named atom groups.
Definition: colvarmodule.h:351
std::ostream & write_traj(std::ostream &os)
Write in the trajectory file.
Definition: colvarmodule.cpp:2139
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:114
int proxy_gpu_buffers_reallocated_done()
Called from proxy when it completes buffers reallocation.
Definition: colvarmodule.cpp:1289
static int error_static(colvarmodule *cvmodule, std::string const &message, int code=-1)
Definition: colvarmodule.h:815
step_number it_restart
Starting step number for this run.
Definition: colvarmodule.h:302
int read_config_string(std::string const &conf)
Parse a config string assuming it is a complete configuration (i.e. calling all parse functions)
Definition: colvarmodule.cpp:288
static std::string to_str(std::vector< rvector > const &x, size_t width=0, size_t prec=0)
Convert to string for output purposes.
static real floor(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:151
int log_level()
Level of logging requested by the user.
Definition: colvarmodule.h:830
size_t size() const
How many objects (variables and biases) are configured yet?
Definition: colvarmodule.cpp:246
int xyz_reader_use_count
Track how many times the XYZ reader has been used.
Definition: colvarmodule.h:935
std::vector< std::string > index_group_names
Names of groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:869
usage * usage_
Track usage of Colvars features.
Definition: colvarmodule.h:938
int log_default_params()
Level at which a keyword's default value is logged.
Definition: colvarmodule.h:848
std::atomic< real > max_gradient_error
Definition: colvarmodule.h:942
int update_colvar_forces()
Integrate bias and restraint forces, send colvar forces to atoms.
Definition: colvarmodule.cpp:1181
std::string restart_version() const
Version of the most recent state file read.
Definition: colvarmodule.h:947
int set_input_state_buffer(size_t n, unsigned char *buf)
Set an internal state buffer, to be read later as an unformatted stream when ready.
Definition: colvarmodule.cpp:1818
int parse_config(std::string &conf)
Parse a "clean" config string (no comments)
Definition: colvarmodule.cpp:327
int write_restart_file(std::string const &out_name)
Write a state file useful to resume the simulation.
Definition: colvarmodule.cpp:1316
void set_initial_step(step_number it)
Set the initial step number (it is 0 otherwise); may be overridden when reading a state.
Definition: colvarmodule.cpp:252
static real exp(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:238
memory_stream & read_objects_state(memory_stream &is)
Read the states of individual objects; allows for changes.
std::vector< int > * variables_active_smp_items()
Indexes of the items to calculate for each colvar.
Definition: colvarmodule.cpp:220
static real ceil(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:157
int residue_id
Residue identifier.
Definition: colvarmodule.h:260
std::vector< colvarbias * > biases_active_
Array of active collective variable biases.
Definition: colvarmodule.h:395
int end_of_step()
Carry out operations needed before next step is run.
Definition: colvarmodule.cpp:1430
size_t num_biases() const
Return how many biases are defined.
Definition: colvarmodule.cpp:768
int setup_output()
(Re)initialize the output trajectory and state file (does not write it yet)
Definition: colvarmodule.cpp:1658
bool check_new_bias(std::string &conf, char const *key)
Definition: colvarmodule.cpp:623
std::string feature_report(int flag=0)
Report usage of the Colvars features.
Definition: colvarmodule.cpp:2759
std::vector< int > colvars_smp_items
Indexes of the items to calculate for each colvar.
Definition: colvarmodule.h:348
int backup_file(char const *filename)
Backup a file before writing it.
Definition: colvarmodule.cpp:1949
int calc()
Main worker function.
Definition: colvarmodule.cpp:932
int log_init_messages()
Level at which initialization messages are logged.
Definition: colvarmodule.h:836
static real cos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:181
int patch_version_number() const
Get the patch version number (non-zero only in the patch releases of other packages)
Definition: colvarmodule.cpp:50
std::string extra_conf
Definition: colvarmodule.h:491
step_number step_absolute()
Definition: colvarmodule.h:312
static constexpr size_t it_width
Number of characters to represent a time step.
Definition: colvarmodule.h:765
std::string config_string
Configuration string read so far by the module (includes comments)
Definition: colvarmodule.h:487
std::string default_input_state_file_
Default input state file; if given, it is read unless the MD engine provides it.
Definition: colvarmodule.h:550
int read_config_file(char const *config_file_name)
Definition: colvarmodule.cpp:259
std::vector< std::vector< int > * > index_groups
Groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:872
static real tanh(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:232
int restart_version_number() const
Integer version of the most recent state file read.
Definition: colvarmodule.h:953
std::string & output_prefix()
Accessor for the above.
Definition: colvarmodule.h:331
void * num_biases_types_used_
Pointer to a map counting how many biases of each type were used.
Definition: colvarmodule.h:392
int catch_input_errors(int result)
Useful wrapper to interrupt parsing if any error occurs.
Definition: colvarmodule.cpp:818
std::vector< std::string > index_file_names
Names of .ndx files that have been loaded.
Definition: colvarmodule.h:866
int log_level_
Level of logging requested by the user.
Definition: colvarmodule.h:825
std::vector< colvar * > * variables_active()
Collective variables with the active flag on.
Definition: colvarmodule.cpp:208
std::vector< colvarbias * > * biases_active()
Array of active collective variable biases.
Definition: colvarmodule.cpp:240
real dt()
Time step of MD integrator (fs)
Definition: colvarmodule.cpp:2542
int patch_version_int
Patch version number; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:106
atom_group * atom_group_by_name(std::string const &name)
Look up a named atom group by name; returns NULL if not found.
Definition: colvarmodule.cpp:855
int append_new_config(std::string const &conf)
Add new configuration during parsing (e.g. to implement back-compatibility); cannot be nested,...
Definition: colvarmodule.cpp:399
std::istream & read_objects_state(std::istream &is)
Read the states of individual objects; allows for changes.
Definition: colvarmodule.cpp:1833
real total_bias_energy
Energy of built-in and scripted biases, summed per time-step.
Definition: colvarmodule.h:387
size_t num_biases_type(std::string const &type) const
Return how many biases of this type are defined.
Definition: colvarmodule.cpp:788
bool use_scripted_forces
Use scripted colvars forces?
Definition: colvarmodule.h:973
int log_output_files()
Level at which output-file operations are logged.
Definition: colvarmodule.h:854
std::istream & read_state(std::istream &is)
Read all objects' state fron a formatted (text) stream.
Definition: colvarmodule.cpp:1792
void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:2164
std::vector< unsigned char > input_state_buffer_
Internal state buffer, to be read as an unformatted stream.
Definition: colvarmodule.h:553
step_number step_relative()
Return the current step number from the beginning of this run.
Definition: colvarmodule.h:305
real rand_gaussian()
Pseudo-random number with Gaussian distribution.
Definition: colvarmodule.cpp:2554
colvarparse * parse
Configuration file parser object.
Definition: colvarmodule.h:914
int calc_component_smp(int i)
Calculate the value of the specified component (to be called in a SMP loop)
Definition: colvarmodule.cpp:226
size_t cv_traj_freq
Frequency for collective variables trajectory output.
Definition: colvarmodule.h:901
size_t & depth()
Get the current object depth in the hierarchy.
Definition: colvarmodule.cpp:2200
static constexpr size_t en_width
Number of characters to represent the collective variables energy.
Definition: colvarmodule.h:773
bool scripting_after_biases
Wait for all biases before calculating scripted forces?
Definition: colvarmodule.h:976
std::string const & get_config() const
Get the configuration string read so far (includes comments)
Definition: colvarmodule.cpp:393
size_t restart_out_freq
Frequency for saving output restarts.
Definition: colvarmodule.h:904
step_number it
Current step number.
Definition: colvarmodule.h:300
int parse_colvars(std::string const &conf)
Parse and initialize collective variables.
Definition: colvarmodule.cpp:574
int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2248
int errorCode
Definition: colvarmodule.h:284
std::vector< colvar * > colvars
Array of collective variables.
Definition: colvarmodule.h:339
static real atan2(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:226
std::vector< colvar * > * variables_active_smp()
Definition: colvarmodule.cpp:214
static constexpr size_t en_prec
Number of digits to represent the collective variables energy.
Definition: colvarmodule.h:771
void increase_depth()
Increase the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2186
colvarmodule()
Cannot initialize the main object without a proxy.
int parse_config_impl(std::string &conf)
Implementations of the entry points that catch colvars_fatal_error.
Definition: colvarmodule.cpp:337
static constexpr bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:403
int write_output_files()
Write all other output files.
Definition: colvarmodule.cpp:1955
static constexpr size_t cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:767
int parse_biases_type(std::string const &conf, char const *keyword)
Parse and initialize collective variable biases of a specific type.
Definition: colvarmodule.cpp:637
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:169
std::string version() const
Get the version string (YYYY-MM-DD format)
Definition: colvarmodule.cpp:38
static COLVARS_HOST_DEVICE real integer_power(real const &x, int const n)
Override the STL pow() with a product for n integer.
Definition: colvarmodule.h:120
int version_int
Integer representing the version string; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:103
std::ostream & write_traj_label(std::ostream &os)
Write explanatory labels in the trajectory file.
Definition: colvarmodule.cpp:2114
static real acos(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:210
static std::string wrap_string(std::string const &s, size_t nchars)
Reduce the number of characters in a string.
Definition: colvarmodule.cpp:2741
int reset()
Actual function called by the destructor.
Definition: colvarmodule.cpp:1505
int calc_biases()
Calculate biases.
Definition: colvarmodule.cpp:1107
std::vector< colvar * > colvars_smp
Definition: colvarmodule.h:346
std::vector< colvar * > colvars_active
Array of collective variables.
Definition: colvarmodule.h:342
int analyze()
Perform analysis.
Definition: colvarmodule.cpp:1402
int load_coords(char const *filename, std::vector< rvector > *pos, atom_group *atoms, std::string const &pdb_field, double pdb_field_value=0.0)
Load coordinates for a group of atoms from a file (PDB or XYZ); if "pos" is already allocated,...
Definition: colvarmodule.cpp:2382
std::string read_colvar(std::string const &name)
Read a colvar value.
Definition: colvarmodule.cpp:899
size_t num_variables() const
Return how many variables are defined.
Definition: colvarmodule.cpp:748
std::string restart_out_name
Output restart file name.
Definition: colvarmodule.h:906
int version_number() const
Get the version number (higher = more recent)
Definition: colvarmodule.cpp:44
int read_traj(char const *traj_filename, long traj_read_begin, long traj_read_end)
Read a collective variable trajectory (post-processing only, not called at runtime)
Definition: colvarmodule.cpp:1975
size_t depth_s
Counter for the current depth in the object hierarchy (useg e.g. in output)
Definition: colvarmodule.h:929
int log_user_params()
Level at which a keyword's user-provided value is logged.
Definition: colvarmodule.h:842
int change_configuration(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:881
std::vector< colvarbias * > biases
Array of collective variable biases.
Definition: colvarmodule.h:384
std::string restart_version_str
Version of the most recent state file read.
Definition: colvarmodule.h:923
int restart_version_int
Integer version of the most recent state file read.
Definition: colvarmodule.h:926
int calc_scripted_forces()
Calculate the energy and forces of scripted biases.
Definition: colvarmodule.cpp:1298
std::string source_Tcl_script
Initialization Tcl script, user-provided.
Definition: colvarmodule.h:502
int write_restart_string(std::string &output)
Write the state into a string.
Definition: colvarmodule.cpp:1345
static std::istream & getline(std::istream &is, std::string &line)
Definition: colvarmodule.cpp:307
int calc_colvars()
Calculate collective variables.
Definition: colvarmodule.cpp:1010
static real fabs(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:163
static constexpr size_t cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:769
std::vector< colvar * > * variables()
Array of collective variables.
Definition: colvarmodule.cpp:202
void decrease_depth()
Decrease the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2192
int update_engine_parameters()
Definition: colvarmodule.cpp:1457
real energy_difference(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:915
memory_stream & read_state(memory_stream &is)
Read all objects' state fron an unformatted (binary) stream.
void record_gradient_error(real error)
Definition: colvarmodule.h:984
int reset_index_groups()
Clear the index groups loaded so far.
Definition: colvarmodule.cpp:2369
static void log_static(colvarmodule *cvmodule, std::string const &message)
Definition: colvarmodule.h:799
int print_total_forces_errning(bool warn_total_forces)
If needed (old restart file), print the warning that cannot be ignored.
Definition: colvarmodule.cpp:1925
int read_index_file(char const *filename)
Read a Gromacs .ndx file.
Definition: colvarmodule.cpp:2278
size_t num_variables_feature(int feature_id) const
Return how many variables have this feature enabled.
Definition: colvarmodule.cpp:754
static real sin(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:175
~colvarmodule()
Destructor.
Definition: colvarmodule.cpp:1476
void config_changed()
Signals to the module object that the configuration has changed.
Definition: colvarmodule.cpp:406
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2603
colvar * colvar_by_name(std::string const &name)
Look up a colvar by name; returns NULL if not found.
Definition: colvarmodule.cpp:843
colvarbias * bias_by_name(std::string const &name)
Look up a bias by name; returns NULL if not found.
Definition: colvarmodule.cpp:830
int open_traj_file(std::string const &file_name)
Open a trajectory file if requested (and leave it open)
std::string cvm_output_prefix
Prefix for all output files for this run.
Definition: colvarmodule.h:327
int setup_input()
(Re)initialize and (re)read the input state file calling read_restart()
Definition: colvarmodule.cpp:1538
int parse_biases(std::string const &conf)
Parse and initialize collective variable biases.
Definition: colvarmodule.cpp:681
int write_state_buffer(std::vector< unsigned char > &buffer)
Write the state of the module to an array of bytes (wrapped as a memory_stream object)
Definition: colvarmodule.cpp:2104
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:111
int parse_global_params(std::string const &conf)
Parse the few module's global parameters.
Definition: colvarmodule.cpp:412
static real debug_gradients_step_size
Finite difference step size (if there is no dynamics, or if gradients need to be tested independently...
Definition: colvarmodule.h:322
int run_tcl_script(std::string const &filename)
Run provided Tcl script.
Definition: colvarmodule.cpp:562
int close_traj_file()
Close it (note: currently unused)
std::vector< size_t > depth_v
Thread-specific depth.
Definition: colvarmodule.h:932
colvarproxy * proxy
Pointer to the proxy object, used to retrieve atomic data from the hosting program.
Definition: colvarmodule.h:997
static std::string to_str(std::vector< real > const &x, size_t width=0, size_t prec=0)
Convert to string for output purposes.
void request_total_force()
Request calculation of total force from MD engine.
Definition: colvarmodule.cpp:2548
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
Definition: colvarproxy.h:70
Exception thrown by colvarmodule::error_static() when no module pointer is available.
Definition: colvarmodule.h:72
Allocator for pinned host memory using cudaHostAlloc.
Definition: colvar_gpu_support.h:360
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43
colvarmodule cvm
Shorthand for the frequently used type prefix.
Definition: colvarmodule.h:1011