Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
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
15#include "colvars_version.h"
16
17#ifndef COLVARS_DEBUG
18#define COLVARS_DEBUG false
19#endif
20
21#if defined(__FAST_MATH__)
22// NOTE: This is used for fixing https://github.com/Colvars/colvars/issues/767
23#define COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
24#endif
25
42
43#include <cmath>
44#include <iosfwd>
45#include <string>
46#include <vector>
47
48#if defined(COLVARS_CUDA)
49#include <iostream>
50#include <cuda_runtime.h>
51#endif
52
53class colvarparse;
54class colvar;
55class colvarbias;
56class colvarproxy;
57class colvarvalue;
58
59
70
71public:
72
74 std::string version() const
75 {
76 return std::string(COLVARS_VERSION);
77 }
78
80 int version_number() const
81 {
82 return version_int;
83 }
84
87 {
88 return patch_version_int;
89 }
90
91#if defined(COLVARS_CUDA)
92 template <typename T>
93 class CudaHostAllocator {
94 public:
95 using value_type = T;
96
97 CudaHostAllocator() = default;
98
99 template<typename U>
100 constexpr CudaHostAllocator(const CudaHostAllocator<U>&) noexcept {}
101
102 friend bool operator==(const CudaHostAllocator&, const CudaHostAllocator&) { return true; }
103 friend bool operator!=(const CudaHostAllocator&, const CudaHostAllocator&) { return false; }
104
105 T* allocate(size_t n) {
106 T* ptr;
107 if (cudaHostAlloc(&ptr, n * sizeof(T), cudaHostAllocMapped) != cudaSuccess) {
108 throw std::bad_alloc();
109 }
110 return ptr;
111 }
112 void deallocate(T* ptr, size_t n) noexcept {
113 cudaFreeHost(ptr);
114 }
115 template<typename U, typename... Args>
116 void construct(U* p, Args&&... args) {
117 new(p) U(std::forward<Args>(args)...);
118 }
119
120 template<typename U>
121 void destroy(U* p) noexcept {
122 p->~U();
123 }
124 };
125#endif
126
127private:
128
130 int version_int = 0;
131
134
135public:
136
138 typedef long long step_number;
139
141 typedef double real;
142
143
144 // Math functions
145
147 static inline real integer_power(real const &x, int const n)
148 {
149 // Original code: math_special.h in LAMMPS
150 double yy, ww;
151 if (x == 0.0) return 0.0;
152 int nn = (n > 0) ? n : -n;
153 ww = x;
154 for (yy = 1.0; nn != 0; nn >>= 1, ww *=ww) {
155 if (nn & 1) yy *= ww;
156 }
157 return (n > 0) ? yy : 1.0/yy;
158 }
159
161 static inline real pow(real const &x, real const &y)
162 {
163 return ::pow(static_cast<double>(x), static_cast<double>(y));
164 }
165
167 static inline real floor(real const &x)
168 {
169 return ::floor(static_cast<double>(x));
170 }
171
173 static inline real fabs(real const &x)
174 {
175 return ::fabs(static_cast<double>(x));
176 }
177
179 static inline real sqrt(real const &x)
180 {
181 return ::sqrt(static_cast<double>(x));
182 }
183
185 static inline real sin(real const &x)
186 {
187 return ::sin(static_cast<double>(x));
188 }
189
191 static inline real cos(real const &x)
192 {
193 return ::cos(static_cast<double>(x));
194 }
195
196#ifndef PI
197#define PI 3.14159265358979323846
198#endif
199#ifndef PI_2
200#define PI_2 1.57079632679489661923
201#endif
202
204static inline real asin(real const &x)
205{
206#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
207 if (x <= -1.0) {
208 return -PI_2;
209 } else if (x >= 1.0) {
210 return PI_2;
211 } else {
212 return ::asin(static_cast<double>(x));
213 }
214#else
215 return ::asin(static_cast<double>(x));
216#endif
217}
218
220static inline real acos(real const &x)
221{
222#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
223 if (x <= -1.0) {
224 return PI;
225 } else if (x >= 1.0) {
226 return 0.0;
227 } else {
228 return ::acos(static_cast<double>(x));
229 }
230#else
231 return ::acos(static_cast<double>(x));
232#endif
233}
234
236 static inline real atan2(real const &x, real const &y)
237 {
238 return ::atan2(static_cast<double>(x), static_cast<double>(y));
239 }
240
242 static inline real exp(real const &x)
243 {
244 return ::exp(static_cast<double>(x));
245 }
246
250 static inline real logn(real const &x)
251 {
252 return ::log(static_cast<double>(x));
253 }
254
255 // Forward declarations
256 class rvector;
257 template <class T> class vector1d;
258 template <class T> class matrix2d;
259 class quaternion;
260 class rotation;
261
262 class usage;
263 class memory_stream;
264
266 typedef int residue_id;
267
271
273 class rmatrix;
274
275 // allow these classes to access protected data
276 class atom;
277 class atom_group;
278 typedef std::vector<atom>::iterator atom_iter;
279 typedef std::vector<atom>::const_iterator atom_const_iter;
280
283private:
284
285 static int errorCode;
286
287public:
288
289 static void set_error_bits(int code);
290
291 static bool get_error_bit(int code);
292
293 static inline int get_error()
294 {
295 return errorCode;
296 }
297
298 static void clear_error();
299
304
307 {
308 return it - it_restart;
309 }
310
314 {
315 return it;
316 }
317
318 bool binary_restart;
319
324
325private:
326
328 std::string cvm_output_prefix;
329
330public:
332 static inline std::string &output_prefix()
333 {
335 return cv->cvm_output_prefix;
336 }
337
338private:
339
341 std::vector<colvar *> colvars;
342
344 std::vector<colvar *> colvars_active;
345
348 std::vector<colvar *> colvars_smp;
350 std::vector<int> colvars_smp_items;
351
353 std::vector<atom_group *> named_atom_groups;
354public:
357
360
362 std::vector<colvar *> *variables();
363
364 /* TODO: implement named CVCs
366 static std::vector<cvc *> cvcs;
368 inline void register_cvc(cvc *p) {
369 cvcs.push_back(p);
370 }
371 */
372
374 std::vector<colvar *> *variables_active();
375
378 std::vector<colvar *> *variables_active_smp();
379
381 std::vector<int> *variables_active_smp_items();
382
384 int calc_component_smp(int i);
385
387 std::vector<colvarbias *> biases;
388
391
392private:
393
396
398 std::vector<colvarbias *> biases_active_;
399
400public:
401
403 std::vector<colvarbias *> *biases_active();
404
406 static inline bool debug()
407 {
408 return COLVARS_DEBUG;
409 }
410
412 size_t size() const;
413
417
418private:
419
422
423public:
424
427
430
432 int reset();
433
436 int read_config_file(char const *config_file_name);
437
440 int read_config_string(std::string const &conf);
441
443 int parse_config(std::string &conf);
444
446 std::string const & get_config() const;
447
448 // Parse functions (setup internal data based on a string)
449
452 static std::istream & getline(std::istream &is, std::string &line);
453
455 int parse_global_params(std::string const &conf);
456
458 int parse_colvars(std::string const &conf);
459
461 int run_tcl_script(std::string const &filename);
462
464 int parse_biases(std::string const &conf);
465
469 int append_new_config(std::string const &conf);
470
472 void config_changed();
473
474private:
475
477 std::string config_string;
478
481 std::string extra_conf;
482
484 template <class bias_type>
485 int parse_biases_type(std::string const &conf, char const *keyword);
486
489 bool check_new_bias(std::string &conf, char const *key);
490
492 std::string source_Tcl_script;
493
494public:
495
497 size_t num_variables() const;
498
500 size_t num_variables_feature(int feature_id) const;
501
503 size_t num_biases() const;
504
506 size_t num_biases_feature(int feature_id) const;
507
509 size_t num_biases_type(std::string const &type) const;
510
513 std::vector<std::string> const time_dependent_biases() const;
514
515private:
517 int catch_input_errors(int result);
518
519public:
520
521 // "Setup" functions (change internal data based on related data
522 // from the proxy that may change during program execution)
523 // No additional parsing is done within these functions
524
528
530 int setup_input();
531
533 int setup_output();
534
535private:
536
537 template <typename IST> IST & read_state_template_(IST &is);
538
541
543 std::vector<unsigned char> input_state_buffer_;
544
545public:
546
548 std::istream & read_state(std::istream &is);
549
551 memory_stream & read_state(memory_stream &is);
552
554 int set_input_state_buffer(size_t n, unsigned char *buf);
555
557 int set_input_state_buffer(std::vector<unsigned char> &buf);
558
560 std::istream & read_objects_state(std::istream &is);
561
563 memory_stream & read_objects_state(memory_stream &is);
564
566 int print_total_forces_errning(bool warn_total_forces);
567
568private:
569 template <typename OST> OST &write_state_template_(OST &os);
570
571public:
572
574 std::ostream & write_state(std::ostream &os);
575
577 memory_stream & write_state(memory_stream &os);
578
580 int write_state_buffer(std::vector<unsigned char> &buffer);
581
583 static std::string state_file_prefix(char const *filename);
584
586 int open_traj_file(std::string const &file_name);
590 std::ostream & write_traj(std::ostream &os);
592 std::ostream & write_traj_label(std::ostream &os);
593
595 int write_traj_files();
597 int write_restart_file(std::string const &out_name);
599 int write_output_files();
601 static int backup_file(char const *filename);
602
604 int write_restart_string(std::string &output);
605
607 static colvarbias * bias_by_name(std::string const &name);
608
610 static colvar * colvar_by_name(std::string const &name);
611
613 static atom_group * atom_group_by_name(std::string const &name);
614
617 int change_configuration(std::string const &bias_name, std::string const &conf);
618
620 std::string read_colvar(std::string const &name);
621
624 real energy_difference(std::string const &bias_name, std::string const &conf);
625
627 int calc();
628
630 int calc_colvars();
631
633 int calc_biases();
634
637
639 int analyze();
640
642 int end_of_step();
643
646 int read_traj(char const *traj_filename,
647 long traj_read_begin,
648 long traj_read_end);
649
651 static std::string to_str(char const *s);
652
654 static std::string to_str(std::string const &s);
655
657 static std::string to_str(bool x);
658
660 static std::string to_str(int const &x,
661 size_t width = 0, size_t prec = 0);
662
664 static std::string to_str(size_t const &x,
665 size_t width = 0, size_t prec = 0);
666
668 static std::string to_str(long int const &x,
669 size_t width = 0, size_t prec = 0);
670
672 static std::string to_str(step_number const &x,
673 size_t width = 0, size_t prec = 0);
674
676 static std::string to_str(real const &x,
677 size_t width = 0, size_t prec = 0);
678
680 static std::string to_str(rvector const &x,
681 size_t width = 0, size_t prec = 0);
682
684 static std::string to_str(quaternion const &x,
685 size_t width = 0, size_t prec = 0);
686
688 static std::string to_str(colvarvalue const &x,
689 size_t width = 0, size_t prec = 0);
690
692 static std::string to_str(vector1d<real> const &x,
693 size_t width = 0, size_t prec = 0);
694
696 static std::string to_str(matrix2d<real> const &x,
697 size_t width = 0, size_t prec = 0);
698
699
701 static std::string to_str(std::vector<int> const &x,
702 size_t width = 0, size_t prec = 0);
703
705 static std::string to_str(std::vector<size_t> const &x,
706 size_t width = 0, size_t prec = 0);
707
709 static std::string to_str(std::vector<long int> const &x,
710 size_t width = 0, size_t prec = 0);
711
713 static std::string to_str(std::vector<real> const &x,
714 size_t width = 0, size_t prec = 0);
715
717 static std::string to_str(std::vector<rvector> const &x,
718 size_t width = 0, size_t prec = 0);
719
721 static std::string to_str(std::vector<quaternion> const &x,
722 size_t width = 0, size_t prec = 0);
723
725 static std::string to_str(std::vector<colvarvalue> const &x,
726 size_t width = 0, size_t prec = 0);
727
729 static std::string to_str(std::vector<std::string> const &x,
730 size_t width = 0, size_t prec = 0);
731
732#if defined(COLVARS_CUDA)
733 static std::string to_str(std::vector<rvector, CudaHostAllocator<rvector>> const &x,
734 size_t width = 0, size_t prec = 0);
735 static std::string to_str(std::vector<real, CudaHostAllocator<real>> const &x,
736 size_t width = 0, size_t prec = 0);
737#endif
738
739
741 static std::string wrap_string(std::string const &s,
742 size_t nchars);
743
745 static size_t const it_width;
747 static size_t const cv_prec;
749 static size_t const cv_width;
751 static size_t const en_prec;
753 static size_t const en_width;
755 static const char * const line_marker;
756
757
758 // proxy functions
759
761 static real dt();
762
764 static void request_total_force();
765
767 int cite_feature(std::string const &feature);
768
770 std::string feature_report(int flag = 0);
771
775 static void log(std::string const &message, int min_log_level = 10);
776
778 static int error(std::string const &message, int code = -1);
779
780private:
781
783 static int log_level_;
784
785public:
786
788 static inline int log_level()
789 {
790 return log_level_;
791 }
792
794 static inline int log_init_messages()
795 {
796 return 1;
797 }
798
800 static inline int log_user_params()
801 {
802 return 2;
803 }
804
806 static inline int log_default_params()
807 {
808 return 3;
809 }
810
812 static inline int log_output_files()
813 {
814 return 4;
815 }
816
818 static inline int log_input_files()
819 {
820 return 5;
821 }
822
826 atom_pos const &pos2);
827
829 std::vector<std::string> index_file_names;
830
832 std::vector<std::string> index_group_names;
833
835 std::vector<std::vector<int> *> index_groups;
836
838 int read_index_file(char const *filename);
839
841 int reset_index_groups();
842
851 static int load_coords(char const *filename,
852 std::vector<rvector> *pos,
853 atom_group *atoms,
854 std::string const &pdb_field,
855 double pdb_field_value = 0.0);
856
858 int load_coords_xyz(char const *filename,
859 std::vector<rvector> *pos,
860 atom_group *atoms,
861 bool keep_open = false);
862
864 static size_t cv_traj_freq;
865
867 static size_t restart_out_freq;
869 std::string restart_out_name;
870
873
874protected:
875
878
880 std::string cv_traj_name;
881
884
887
890
892 size_t depth_s;
893
895 std::vector<size_t> depth_v;
896
899
902
903public:
904
906 inline std::string restart_version() const
907 {
908 return restart_version_str;
909 }
910
912 inline int restart_version_number() const
913 {
914 return restart_version_int;
915 }
916
918 static size_t & depth();
919
921 static void increase_depth();
922
924 static void decrease_depth();
925
926 static inline bool scripted_forces()
927 {
928 return use_scripted_forces;
929 }
930
933
936
939
944
946 static colvarmodule *main();
947
948};
949
950
953
954
955std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
956std::istream & operator >> (std::istream &is, cvm::rvector &v);
957
958
959namespace {
960 constexpr int32_t COLVARS_OK = 0;
961 constexpr int32_t COLVARS_ERROR = 1;
962 constexpr int32_t COLVARS_NOT_IMPLEMENTED = (1<<1);
963 constexpr int32_t COLVARS_INPUT_ERROR = (1<<2); // out of bounds or inconsistent input
964 constexpr int32_t COLVARS_BUG_ERROR = (1<<3); // Inconsistent state indicating bug
965 constexpr int32_t COLVARS_FILE_ERROR = (1<<4);
966 constexpr int32_t COLVARS_MEMORY_ERROR = (1<<5);
967 constexpr int32_t COLVARS_NO_SUCH_FRAME = (1<<6); // Cannot load the requested frame
968}
969
970
971#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
Group of atom objects, mostly used by a colvar::cvc object to gather all atomic data.
Definition: colvaratoms.h:159
Stores numeric id, mass and all mutable data for an atom, mostly used by a colvar::cvc.
Definition: colvaratoms.h:31
Arbitrary size array (two dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:372
1-dimensional vector of real numbers with four components and a quaternion algebra
Definition: colvartypes.h:954
2-dimensional array of real numbers with three components along each dimension (works with colvarmodu...
Definition: colvartypes.h:891
vector of real numbers with three components
Definition: colvartypes.h:723
Track usage of Colvars features.
Definition: colvarmodule.cpp:35
Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:33
Collective variables module (main class)
Definition: colvarmodule.h:69
int cite_feature(std::string const &feature)
Track usage of the given Colvars feature.
Definition: colvarmodule.cpp:2564
static const char *const line_marker
Line separator in the log output.
Definition: colvarmodule.h:755
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:270
int write_traj_files()
Write all trajectory files.
Definition: colvarmodule.cpp:1211
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)
std::ostream & write_state(std::ostream &os)
Write the state of the module to a formatted (text) file.
Definition: colvarmodule.cpp:1919
static std::string state_file_prefix(char const *filename)
Strips .colvars.state from filename and checks that it is not empty.
Definition: colvarmodule.cpp:1549
static real pow(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:161
size_t num_biases_feature(int feature_id) const
Return how many biases have this feature enabled.
Definition: colvarmodule.cpp:684
static real asin(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:204
static step_number it
Current step number.
Definition: colvarmodule.h:301
bool cv_traj_write_labels
Write labels at the next iteration.
Definition: colvarmodule.h:883
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:712
std::string cv_traj_name
Name of the trajectory file.
Definition: colvarmodule.h:880
static real logn(real const &x)
Definition: colvarmodule.h:250
std::vector< atom_group * > named_atom_groups
Array of named atom groups.
Definition: colvarmodule.h:353
std::ostream & write_traj(std::ostream &os)
Write in the trajectory file.
Definition: colvarmodule.cpp:1969
void register_named_atom_group(atom_group *ag)
Register a named atom group into named_atom_groups.
Definition: colvarmodule.cpp:782
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:141
static size_t const en_prec
Number of digits to represent the collective variables energy.
Definition: colvarmodule.h:751
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:267
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:167
static std::string wrap_string(std::string const &s, size_t nchars)
Reduce the number of characters in a string.
size_t size() const
How many objects (variables and biases) are configured yet?
Definition: colvarmodule.cpp:225
int xyz_reader_use_count
Track how many times the XYZ reader has been used.
Definition: colvarmodule.h:898
std::vector< std::string > index_group_names
Names of groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:832
usage * usage_
Track usage of Colvars features.
Definition: colvarmodule.h:901
int update_colvar_forces()
Integrate bias and restraint forces, send colvar forces to atoms.
Definition: colvarmodule.cpp:1091
std::string restart_version() const
Version of the most recent state file read.
Definition: colvarmodule.h:906
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:1653
int parse_config(std::string &conf)
Parse a "clean" config string (no comments)
Definition: colvarmodule.cpp:306
int write_restart_file(std::string const &out_name)
Write a state file useful to resume the simulation.
Definition: colvarmodule.cpp:1170
static void request_total_force()
Request calculation of total force from MD engine.
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:231
static real exp(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:242
memory_stream & read_state(memory_stream &is)
Read all objects' state fron an unformatted (binary) stream.
std::vector< int > * variables_active_smp_items()
Indexes of the items to calculate for each colvar.
Definition: colvarmodule.cpp:199
int residue_id
Residue identifier.
Definition: colvarmodule.h:266
std::vector< colvarbias * > biases_active_
Array of active collective variable biases.
Definition: colvarmodule.h:398
static int log_output_files()
Level at which output-file operations are logged.
Definition: colvarmodule.h:812
int end_of_step()
Carry out operations needed before next step is run.
Definition: colvarmodule.cpp:1284
size_t num_biases() const
Return how many biases are defined.
Definition: colvarmodule.cpp:678
int setup_output()
(Re)initialize the output trajectory and state file (does not write it yet)
Definition: colvarmodule.cpp:1504
bool check_new_bias(std::string &conf, char const *key)
Definition: colvarmodule.cpp:533
std::string feature_report(int flag=0)
Report usage of the Colvars features.
Definition: colvarmodule.cpp:2569
std::vector< int > colvars_smp_items
Indexes of the items to calculate for each colvar.
Definition: colvarmodule.h:350
static 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,...
static int backup_file(char const *filename)
Backup a file before writing it.
Definition: colvarmodule.cpp:1777
int calc()
Main worker function.
Definition: colvarmodule.cpp:851
static real cos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:191
int patch_version_number() const
Get the patch version number (non-zero in patch releases of other packages)
Definition: colvarmodule.h:86
std::string extra_conf
Definition: colvarmodule.h:481
static real dt()
Time step of MD integrator (fs)
static step_number it_restart
Starting step number for this run.
Definition: colvarmodule.h:303
static real integer_power(real const &x, int const n)
Override the STL pow() with a product for n integer.
Definition: colvarmodule.h:147
std::string config_string
Configuration string read so far by the module (includes comments)
Definition: colvarmodule.h:477
std::string default_input_state_file_
Default input state file; if given, it is read unless the MD engine provides it.
Definition: colvarmodule.h:540
int read_config_file(char const *config_file_name)
Definition: colvarmodule.cpp:238
std::vector< std::vector< int > * > index_groups
Groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:835
int restart_version_number() const
Integer version of the most recent state file read.
Definition: colvarmodule.h:912
void * num_biases_types_used_
Pointer to a map counting how many biases of each type were used.
Definition: colvarmodule.h:395
int catch_input_errors(int result)
Useful wrapper to interrupt parsing if any error occurs.
Definition: colvarmodule.cpp:728
std::vector< std::string > index_file_names
Names of .ndx files that have been loaded.
Definition: colvarmodule.h:829
static int log_level_
Level of logging requested by the user.
Definition: colvarmodule.h:783
std::vector< colvar * > * variables_active()
Collective variables with the active flag on.
Definition: colvarmodule.cpp:187
std::vector< colvarbias * > * biases_active()
Array of active collective variable biases.
Definition: colvarmodule.cpp:219
int patch_version_int
Patch version number (non-zero in patch releases of other packages)
Definition: colvarmodule.h:133
static 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:768
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:368
std::istream & read_objects_state(std::istream &is)
Read the states of individual objects; allows for changes.
Definition: colvarmodule.cpp:1668
real total_bias_energy
Energy of built-in and scripted biases, summed per time-step.
Definition: colvarmodule.h:390
static rvector position_distance(atom_pos const &pos1, atom_pos const &pos2)
Get the distance between two atomic positions with pbcs handled correctly.
size_t num_biases_type(std::string const &type) const
Return how many biases of this type are defined.
Definition: colvarmodule.cpp:698
static size_t const it_width
Number of characters to represent a time step.
Definition: colvarmodule.h:745
static bool use_scripted_forces
Use scripted colvars forces?
Definition: colvarmodule.h:932
std::istream & read_state(std::istream &is)
Read all objects' state fron a formatted (text) stream.
Definition: colvarmodule.cpp:1627
static void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:1994
std::vector< unsigned char > input_state_buffer_
Internal state buffer, to be read as an unformatted stream.
Definition: colvarmodule.h:543
colvarparse * parse
Configuration file parser object.
Definition: colvarmodule.h:877
int calc_component_smp(int i)
Calculate the value of the specified component (to be called in a SMP loop)
Definition: colvarmodule.cpp:205
static size_t cv_traj_freq
Frequency for collective variables trajectory output.
Definition: colvarmodule.h:864
static size_t & depth()
Get the current object depth in the hierarchy.
Definition: colvarmodule.cpp:2024
static bool scripting_after_biases
Wait for all biases before calculating scripted forces?
Definition: colvarmodule.h:935
std::string const & get_config() const
Get the configuration string read so far (includes comments)
Definition: colvarmodule.cpp:362
static size_t restart_out_freq
Frequency for saving output restarts.
Definition: colvarmodule.h:867
int parse_colvars(std::string const &conf)
Parse and initialize collective variables.
Definition: colvarmodule.cpp:484
static int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2071
static int errorCode
Definition: colvarmodule.h:285
std::vector< colvar * > colvars
Array of collective variables.
Definition: colvarmodule.h:341
static real atan2(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:236
std::vector< colvar * > * variables_active_smp()
Definition: colvarmodule.cpp:193
static void increase_depth()
Increase the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2010
static real rand_gaussian()
Pseudo-random number with Gaussian distribution.
colvarmodule()
Cannot initialize the main object without a proxy.
int write_output_files()
Write all other output files.
Definition: colvarmodule.cpp:1783
static size_t const cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:747
static colvarmodule * main()
Access the one instance of the Colvars module.
Definition: colvarmodule.cpp:175
int parse_biases_type(std::string const &conf, char const *keyword)
Parse and initialize collective variable biases of a specific type.
Definition: colvarmodule.cpp:547
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:179
std::string version() const
Get the version string (YYYY-MM-DD format)
Definition: colvarmodule.h:74
static int log_level()
Level of logging requested by the user.
Definition: colvarmodule.h:788
int version_int
Integer representing the version string (allows comparisons)
Definition: colvarmodule.h:130
std::ostream & write_traj_label(std::ostream &os)
Write explanatory labels in the trajectory file.
Definition: colvarmodule.cpp:1944
static real acos(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:220
int reset()
Actual function called by the destructor.
Definition: colvarmodule.cpp:1359
int calc_biases()
Calculate biases.
Definition: colvarmodule.cpp:1017
std::vector< colvar * > colvars_smp
Definition: colvarmodule.h:348
std::vector< colvar * > colvars_active
Array of collective variables.
Definition: colvarmodule.h:344
int analyze()
Perform analysis.
Definition: colvarmodule.cpp:1256
std::string read_colvar(std::string const &name)
Read a colvar value.
Definition: colvarmodule.cpp:818
size_t num_variables() const
Return how many variables are defined.
Definition: colvarmodule.cpp:658
std::string restart_out_name
Output restart file name.
Definition: colvarmodule.h:869
int version_number() const
Get the version number (higher = more recent)
Definition: colvarmodule.h:80
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:1803
static size_t const cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:749
size_t depth_s
Counter for the current depth in the object hierarchy (useg e.g. in output)
Definition: colvarmodule.h:892
static bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:406
int change_configuration(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:800
std::vector< colvarbias * > biases
Array of collective variable biases.
Definition: colvarmodule.h:387
std::string restart_version_str
Version of the most recent state file read.
Definition: colvarmodule.h:886
int restart_version_int
Integer version of the most recent state file read.
Definition: colvarmodule.h:889
int calc_scripted_forces()
Calculate the energy and forces of scripted biases.
Definition: colvarmodule.cpp:1152
std::string source_Tcl_script
Initialization Tcl script, user-provided.
Definition: colvarmodule.h:492
int write_restart_string(std::string &output)
Write the state into a string.
Definition: colvarmodule.cpp:1199
static std::istream & getline(std::istream &is, std::string &line)
Definition: colvarmodule.cpp:286
static int log_input_files()
Level at which input-file operations (configuration, state) are logged.
Definition: colvarmodule.h:818
int calc_colvars()
Calculate collective variables.
Definition: colvarmodule.cpp:919
static real fabs(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:173
std::vector< colvar * > * variables()
Array of collective variables.
Definition: colvarmodule.cpp:181
static void decrease_depth()
Decrease the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2016
int update_engine_parameters()
Definition: colvarmodule.cpp:1311
real energy_difference(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:834
static int log_default_params()
Level at which a keyword's default value is logged.
Definition: colvarmodule.h:806
memory_stream & write_state(memory_stream &os)
Write the state of the module to an unformatted (binary) file.
int reset_index_groups()
Clear the index groups loaded so far.
Definition: colvarmodule.cpp:2179
static int log_user_params()
Level at which a keyword's user-provided value is logged.
Definition: colvarmodule.h:800
int print_total_forces_errning(bool warn_total_forces)
If needed (old restart file), print the warning that cannot be ignored.
Definition: colvarmodule.cpp:1753
memory_stream & read_objects_state(memory_stream &is)
Read the states of individual objects; allows for changes.
static step_number step_relative()
Return the current step number from the beginning of this run.
Definition: colvarmodule.h:306
int read_index_file(char const *filename)
Read a Gromacs .ndx file.
size_t num_variables_feature(int feature_id) const
Return how many variables have this feature enabled.
Definition: colvarmodule.cpp:664
static real sin(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:185
~colvarmodule()
Destructor.
Definition: colvarmodule.cpp:1330
static std::string & output_prefix()
Accessor for the above.
Definition: colvarmodule.h:332
void config_changed()
Signals to the module object that the configuration has changed.
Definition: colvarmodule.cpp:375
static colvarproxy * proxy
Pointer to the proxy object, used to retrieve atomic data from the hosting program; it is static in o...
Definition: colvarmodule.h:943
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2417
static step_number step_absolute()
Definition: colvarmodule.h:313
static colvar * colvar_by_name(std::string const &name)
Look up a colvar by name; returns NULL if not found.
Definition: colvarmodule.cpp:754
void unregister_named_atom_group(atom_group *ag)
Remove a named atom group from named_atom_groups.
Definition: colvarmodule.cpp:787
static int log_init_messages()
Level at which initialization messages are logged.
Definition: colvarmodule.h:794
static colvarbias * bias_by_name(std::string const &name)
Look up a bias by name; returns NULL if not found.
Definition: colvarmodule.cpp:740
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:328
int setup_input()
(Re)initialize and (re)read the input state file calling read_restart()
Definition: colvarmodule.cpp:1394
int parse_biases(std::string const &conf)
Parse and initialize collective variable biases.
Definition: colvarmodule.cpp:591
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:1934
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:138
int parse_global_params(std::string const &conf)
Parse the few module's global parameters.
Definition: colvarmodule.cpp:381
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:323
int run_tcl_script(std::string const &filename)
Run provided Tcl script.
Definition: colvarmodule.cpp:472
int close_traj_file()
Close it (note: currently unused)
std::vector< size_t > depth_v
Thread-specific depth.
Definition: colvarmodule.h:895
static size_t const en_width
Number of characters to represent the collective variables energy.
Definition: colvarmodule.h:753
static std::string to_str(std::vector< real > const &x, size_t width=0, size_t prec=0)
Convert to string for output purposes.
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
Definition: colvarproxy.h:559
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:952