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#include <unordered_map>
15#include <memory>
16
17#include "colvars_version.h"
18#include "colvar_gpu_calc.h"
19
20#ifndef COLVARS_DEBUG
21#define COLVARS_DEBUG false
22#endif
23
24#if defined(__FAST_MATH__)
25// NOTE: This is used for fixing https://github.com/Colvars/colvars/issues/767
26#define COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
27#endif
28
29#define COLVARS_USE_SOA
30
47
48#include <cmath>
49#include <iosfwd>
50#include <string>
51#include <vector>
52#include "colvar_gpu_support.h"
53
54class colvarparse;
55class colvar;
56class colvarbias;
57class colvarproxy;
58class colvarvalue;
59class colvardeps;
60
61
72
73public:
74
76 std::string version() const;
77
79 int version_number() const;
80
82 int patch_version_number() const;
83
84private:
85
87 int version_int = 0;
88
91
92public:
93
95 typedef long long step_number;
96
98 typedef double real;
99
100
101 // Math functions
102
104 static inline real integer_power(real const &x, int const n)
105 {
106 // Original code: math_special.h in LAMMPS
107 double yy, ww;
108 if (x == 0.0) return 0.0;
109 int nn = (n > 0) ? n : -n;
110 ww = x;
111 for (yy = 1.0; nn != 0; nn >>= 1, ww *=ww) {
112 if (nn & 1) yy *= ww;
113 }
114 return (n > 0) ? yy : 1.0/yy;
115 }
116
118 static inline real pow(real const &x, real const &y)
119 {
120 return ::pow(static_cast<double>(x), static_cast<double>(y));
121 }
122
124 static inline real floor(real const &x)
125 {
126 return ::floor(static_cast<double>(x));
127 }
128
130 static inline real ceil(real const &x)
131 {
132 return ::ceil(static_cast<double>(x));
133 }
134
136 static inline real fabs(real const &x)
137 {
138 return ::fabs(static_cast<double>(x));
139 }
140
142 static inline real sqrt(real const &x)
143 {
144 return ::sqrt(static_cast<double>(x));
145 }
146
148 static inline real sin(real const &x)
149 {
150 return ::sin(static_cast<double>(x));
151 }
152
154 static inline real cos(real const &x)
155 {
156 return ::cos(static_cast<double>(x));
157 }
158
159#ifndef PI
160#define PI 3.14159265358979323846
161#endif
162#ifndef PI_2
163#define PI_2 1.57079632679489661923
164#endif
165
167static inline real asin(real const &x)
168{
169#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
170 if (x <= -1.0) {
171 return -PI_2;
172 } else if (x >= 1.0) {
173 return PI_2;
174 } else {
175 return ::asin(static_cast<double>(x));
176 }
177#else
178 return ::asin(static_cast<double>(x));
179#endif
180}
181
183static inline real acos(real const &x)
184{
185#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
186 if (x <= -1.0) {
187 return PI;
188 } else if (x >= 1.0) {
189 return 0.0;
190 } else {
191 return ::acos(static_cast<double>(x));
192 }
193#else
194 return ::acos(static_cast<double>(x));
195#endif
196}
197
199 static inline real atan2(real const &x, real const &y)
200 {
201 return ::atan2(static_cast<double>(x), static_cast<double>(y));
202 }
203
205 static inline real tanh(real const &x)
206 {
207 return ::tanh(static_cast<double>(x));
208 }
209
211 static inline real exp(real const &x)
212 {
213 return ::exp(static_cast<double>(x));
214 }
215
219 static inline real logn(real const &x)
220 {
221 return ::log(static_cast<double>(x));
222 }
223
224 // Forward declarations
225 class rvector;
226 template <class T> class vector1d;
227 template <class T> class matrix2d;
228 class quaternion;
229 class rotation;
230
231 class usage;
232 class memory_stream;
233
235 typedef int residue_id;
236
240
242 class rmatrix;
243
244 // NOTE: Just here for ensuring the compilation of GROMACS with Colvars
245 struct atom;
246 // class atom_group_base;
247 class atom_group;
248 // class atom_group_gpu;
249 // typedef std::vector<atom>::iterator atom_iter;
250 // typedef std::vector<atom>::const_iterator atom_const_iter;
251
254private:
255
256 static int errorCode;
257
258public:
259
260 static void set_error_bits(int code);
261
262 static bool get_error_bit(int code);
263
264 static inline int get_error()
265 {
266 return errorCode;
267 }
268
269 static void clear_error();
270
275
278 {
279 return it - it_restart;
280 }
281
285 {
286 return it;
287 }
288
289 bool binary_restart;
290
295
296private:
297
299 std::string cvm_output_prefix;
300
301public:
303 static inline std::string &output_prefix()
304 {
306 return cv->cvm_output_prefix;
307 }
308
309private:
310
312 std::vector<colvar *> colvars;
313
315 std::vector<colvar *> colvars_active;
316
319 std::vector<colvar *> colvars_smp;
321 std::vector<int> colvars_smp_items;
322
324 std::vector<atom_group *> named_atom_groups_soa;
325
326public:
327
328 void register_named_atom_group_soa(atom_group *ag);
329 void unregister_named_atom_group_soa(atom_group *ag);
330
332 std::vector<colvar *> *variables();
333
334 /* TODO: implement named CVCs
336 static std::vector<cvc *> cvcs;
338 inline void register_cvc(cvc *p) {
339 cvcs.push_back(p);
340 }
341 */
342
344 std::vector<colvar *> *variables_active();
345
348 std::vector<colvar *> *variables_active_smp();
349
351 std::vector<int> *variables_active_smp_items();
352
354 int calc_component_smp(int i);
355
357 std::vector<colvarbias *> biases;
358
361
362private:
363
366
368 std::vector<colvarbias *> biases_active_;
369
370public:
371
373 std::vector<colvarbias *> *biases_active();
374
376 static inline bool debug()
377 {
378 return COLVARS_DEBUG;
379 }
380
382 size_t size() const;
383
387
388private:
389
392
393public:
394
397
400
402 int reset();
403
406 int read_config_file(char const *config_file_name);
407
410 int read_config_string(std::string const &conf);
411
413 int parse_config(std::string &conf);
414
416 std::string const & get_config() const;
417
418 // Parse functions (setup internal data based on a string)
419
422 static std::istream & getline(std::istream &is, std::string &line);
423
425 int parse_global_params(std::string const &conf);
426
428 int parse_colvars(std::string const &conf);
429
431 int run_tcl_script(std::string const &filename);
432
434 int parse_biases(std::string const &conf);
435
439 int append_new_config(std::string const &conf);
440
442 void config_changed();
443
444private:
445
447 std::string config_string;
448
451 std::string extra_conf;
452
454 template <class bias_type>
455 int parse_biases_type(std::string const &conf, char const *keyword);
456
459 bool check_new_bias(std::string &conf, char const *key);
460
462 std::string source_Tcl_script;
463
464public:
465
467 size_t num_variables() const;
468
470 size_t num_variables_feature(int feature_id) const;
471
473 size_t num_biases() const;
474
476 size_t num_biases_feature(int feature_id) const;
477
479 size_t num_biases_type(std::string const &type) const;
480
483 std::vector<std::string> const time_dependent_biases() const;
484
485private:
487 int catch_input_errors(int result);
488
489public:
490
491 // "Setup" functions (change internal data based on related data
492 // from the proxy that may change during program execution)
493 // No additional parsing is done within these functions
494
498
500 int setup_input();
501
503 int setup_output();
504
505private:
506
507 template <typename IST> IST & read_state_template_(IST &is);
508
511
513 std::vector<unsigned char> input_state_buffer_;
514
515public:
516
518 std::istream & read_state(std::istream &is);
519
521 memory_stream & read_state(memory_stream &is);
522
524 int set_input_state_buffer(size_t n, unsigned char *buf);
525
527 int set_input_state_buffer(std::vector<unsigned char> &buf);
528
530 std::istream & read_objects_state(std::istream &is);
531
533 memory_stream & read_objects_state(memory_stream &is);
534
536 int print_total_forces_errning(bool warn_total_forces);
537
538private:
539 template <typename OST> OST &write_state_template_(OST &os);
540
541public:
542
544 std::ostream & write_state(std::ostream &os);
545
547 memory_stream & write_state(memory_stream &os);
548
550 int write_state_buffer(std::vector<unsigned char> &buffer);
551
553 static std::string state_file_prefix(char const *filename);
554
556 int open_traj_file(std::string const &file_name);
560 std::ostream & write_traj(std::ostream &os);
562 std::ostream & write_traj_label(std::ostream &os);
563
565 int write_traj_files();
567 int write_restart_file(std::string const &out_name);
569 int write_output_files();
571 static int backup_file(char const *filename);
572
574 int write_restart_string(std::string &output);
575
577 static colvarbias * bias_by_name(std::string const &name);
578
580 static colvar * colvar_by_name(std::string const &name);
581
583 static atom_group * atom_group_soa_by_name(std::string const& name);
584
587 int change_configuration(std::string const &bias_name, std::string const &conf);
588
590 std::string read_colvar(std::string const &name);
591
594 real energy_difference(std::string const &bias_name, std::string const &conf);
595
597 int calc();
598
600 int calc_colvars();
601
603 int calc_biases();
604
607
609 int analyze();
610
612 int end_of_step();
613
616 int read_traj(char const *traj_filename,
617 long traj_read_begin,
618 long traj_read_end);
619
621 static std::string to_str(char const *s);
622
624 static std::string to_str(const void* ptr);
625
627 static std::string to_str(std::string const &s);
628
630 static std::string to_str(bool x);
631
633 static std::string to_str(int const &x,
634 size_t width = 0, size_t prec = 0);
635
637 static std::string to_str(size_t const &x,
638 size_t width = 0, size_t prec = 0);
639
641 static std::string to_str(long int const &x,
642 size_t width = 0, size_t prec = 0);
643
645 static std::string to_str(step_number const &x,
646 size_t width = 0, size_t prec = 0);
647
649 static std::string to_str(real const &x,
650 size_t width = 0, size_t prec = 0);
651
653 static std::string to_str(rvector const &x,
654 size_t width = 0, size_t prec = 0);
655
657 static std::string to_str(quaternion const &x,
658 size_t width = 0, size_t prec = 0);
659
661 static std::string to_str(colvarvalue const &x,
662 size_t width = 0, size_t prec = 0);
663
665 static std::string to_str(vector1d<real> const &x,
666 size_t width = 0, size_t prec = 0);
667
669 static std::string to_str(matrix2d<real> const &x,
670 size_t width = 0, size_t prec = 0);
671
672
674 static std::string to_str(std::vector<int> const &x,
675 size_t width = 0, size_t prec = 0);
676
678 static std::string to_str(std::vector<size_t> const &x,
679 size_t width = 0, size_t prec = 0);
680
682 static std::string to_str(std::vector<long int> const &x,
683 size_t width = 0, size_t prec = 0);
684
686 static std::string to_str(std::vector<real> const &x,
687 size_t width = 0, size_t prec = 0);
688
690 static std::string to_str(std::vector<rvector> const &x,
691 size_t width = 0, size_t prec = 0);
692
694 static std::string to_str(std::vector<quaternion> const &x,
695 size_t width = 0, size_t prec = 0);
696
698 static std::string to_str(std::vector<colvarvalue> const &x,
699 size_t width = 0, size_t prec = 0);
700
702 static std::string to_str(std::vector<std::string> const &x,
703 size_t width = 0, size_t prec = 0);
704
705#if ( defined(COLVARS_CUDA) || defined(COLVARS_HIP) )
706 static std::string to_str(std::vector<rvector, colvars_gpu::CudaHostAllocator<rvector>> const &x,
707 size_t width = 0, size_t prec = 0);
708 static std::string to_str(std::vector<real, colvars_gpu::CudaHostAllocator<real>> const &x,
709 size_t width = 0, size_t prec = 0);
710#endif
711
712
714 static std::string wrap_string(std::string const &s,
715 size_t nchars);
716
718 static size_t const it_width;
720 static size_t const cv_prec;
722 static size_t const cv_width;
724 static size_t const en_prec;
726 static size_t const en_width;
728 static const char * const line_marker;
729
730
731 // proxy functions
732
734 static real dt();
735
737 static void request_total_force();
738
740 int cite_feature(std::string const &feature);
741
743 std::string feature_report(int flag = 0);
744
748 static void log(std::string const &message, int min_log_level = 10);
749
751 static int error(std::string const &message, int code = -1);
752
753private:
754
756 static int log_level_;
757
758public:
759
761 static inline int log_level()
762 {
763 return log_level_;
764 }
765
767 static inline int log_init_messages()
768 {
769 return 1;
770 }
771
773 static inline int log_user_params()
774 {
775 return 2;
776 }
777
779 static inline int log_default_params()
780 {
781 return 3;
782 }
783
785 static inline int log_output_files()
786 {
787 return 4;
788 }
789
791 static inline int log_input_files()
792 {
793 return 5;
794 }
795
799 atom_pos const &pos2);
800
802 std::vector<std::string> index_file_names;
803
805 std::vector<std::string> index_group_names;
806
808 std::vector<std::vector<int> *> index_groups;
809
811 int read_index_file(char const *filename);
812
814 int reset_index_groups();
815
824 static int load_coords(char const *filename,
825 std::vector<rvector> *pos,
826 atom_group *atoms,
827 std::string const &pdb_field,
828 double pdb_field_value = 0.0);
829
831 int load_coords_xyz(char const *filename,
832 std::vector<rvector> *pos,
833 atom_group *atoms,
834 bool keep_open = false);
835
837 static size_t cv_traj_freq;
838
840 static size_t restart_out_freq;
842 std::string restart_out_name;
843
846
847protected:
848
851
853 std::string cv_traj_name;
854
857
860
863
865 size_t depth_s;
866
868 std::vector<size_t> depth_v;
869
872
875
879
880public:
881
883 inline std::string restart_version() const
884 {
885 return restart_version_str;
886 }
887
889 inline int restart_version_number() const
890 {
891 return restart_version_int;
892 }
893
895 static size_t & depth();
896
898 static void increase_depth();
899
901 static void decrease_depth();
902
903 static inline bool scripted_forces()
904 {
905 return use_scripted_forces;
906 }
907
910
913
916
922 }
923
924 real get_max_gradient_error() {
925 return max_gradient_error;
926 }
927
932
934 static colvarmodule *main();
935
936#if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
937 template <typename T>
939#else
940 template <typename T>
941 using allocator_type = std::allocator<T>;
942#endif
943 using ag_vector_real_t = std::vector<real, allocator_type<real>>;
944
945#if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
946 std::unique_ptr<colvars_gpu::colvarmodule_gpu_calc> gpu_calc;
947#endif
948};
949
952
953
954std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
955std::istream & operator >> (std::istream &is, cvm::rvector &v);
956
957
958namespace {
959 constexpr int32_t COLVARS_OK = 0;
960 constexpr int32_t COLVARS_ERROR = 1;
961 constexpr int32_t COLVARS_NOT_IMPLEMENTED = (1<<1);
962 constexpr int32_t COLVARS_INPUT_ERROR = (1<<2); // out of bounds or inconsistent input
963 constexpr int32_t COLVARS_BUG_ERROR = (1<<3); // Inconsistent state indicating bug
964 constexpr int32_t COLVARS_FILE_ERROR = (1<<4);
965 constexpr int32_t COLVARS_MEMORY_ERROR = (1<<5);
966 constexpr int32_t COLVARS_NO_SUCH_FRAME = (1<<6); // Cannot load the requested frame
967}
968
969
970#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:375
1-dimensional vector of real numbers with four components and a quaternion algebra
Definition: colvartypes.h:978
2-dimensional array of real numbers with three components along each dimension (works with colvarmodu...
Definition: colvartypes.h:901
vector of real numbers with three components
Definition: colvartypes.h:726
Track usage of Colvars features.
Definition: colvarmodule.cpp:56
Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:36
Collective variables module (main class)
Definition: colvarmodule.h:71
int cite_feature(std::string const &feature)
Track usage of the given Colvars feature.
Definition: colvarmodule.cpp:2694
static const char *const line_marker
Line separator in the log output.
Definition: colvarmodule.h:728
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:239
int write_traj_files()
Write all trajectory files.
Definition: colvarmodule.cpp:1314
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:2029
static std::string state_file_prefix(char const *filename)
Strips .colvars.state from filename and checks that it is not empty.
Definition: colvarmodule.cpp:1652
static real pow(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:118
size_t num_biases_feature(int feature_id) const
Return how many biases have this feature enabled.
Definition: colvarmodule.cpp:780
static real asin(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:167
static step_number it
Current step number.
Definition: colvarmodule.h:272
bool cv_traj_write_labels
Write labels at the next iteration.
Definition: colvarmodule.h:856
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:808
std::string cv_traj_name
Name of the trajectory file.
Definition: colvarmodule.h:853
static real logn(real const &x)
Definition: colvarmodule.h:219
std::ostream & write_traj(std::ostream &os)
Write in the trajectory file.
Definition: colvarmodule.cpp:2079
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:98
static size_t const en_prec
Number of digits to represent the collective variables energy.
Definition: colvarmodule.h:724
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:292
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:124
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:250
int xyz_reader_use_count
Track how many times the XYZ reader has been used.
Definition: colvarmodule.h:871
std::vector< std::string > index_group_names
Names of groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:805
usage * usage_
Track usage of Colvars features.
Definition: colvarmodule.h:874
int update_colvar_forces()
Integrate bias and restraint forces, send colvar forces to atoms.
Definition: colvarmodule.cpp:1188
std::string restart_version() const
Version of the most recent state file read.
Definition: colvarmodule.h:883
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:1756
int parse_config(std::string &conf)
Parse a "clean" config string (no comments)
Definition: colvarmodule.cpp:331
int write_restart_file(std::string const &out_name)
Write a state file useful to resume the simulation.
Definition: colvarmodule.cpp:1273
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:256
static real exp(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:211
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:224
static real ceil(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:130
int residue_id
Residue identifier.
Definition: colvarmodule.h:235
std::vector< colvarbias * > biases_active_
Array of active collective variable biases.
Definition: colvarmodule.h:368
static int log_output_files()
Level at which output-file operations are logged.
Definition: colvarmodule.h:785
int end_of_step()
Carry out operations needed before next step is run.
Definition: colvarmodule.cpp:1387
size_t num_biases() const
Return how many biases are defined.
Definition: colvarmodule.cpp:774
int setup_output()
(Re)initialize the output trajectory and state file (does not write it yet)
Definition: colvarmodule.cpp:1607
bool check_new_bias(std::string &conf, char const *key)
Definition: colvarmodule.cpp:629
std::string feature_report(int flag=0)
Report usage of the Colvars features.
Definition: colvarmodule.cpp:2699
std::vector< int > colvars_smp_items
Indexes of the items to calculate for each colvar.
Definition: colvarmodule.h:321
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:1887
int calc()
Main worker function.
Definition: colvarmodule.cpp:941
static real cos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:154
int patch_version_number() const
Get the patch version number (non-zero only in the patch releases of other packages)
Definition: colvarmodule.cpp:49
std::string extra_conf
Definition: colvarmodule.h:451
static real dt()
Time step of MD integrator (fs)
static step_number it_restart
Starting step number for this run.
Definition: colvarmodule.h:274
static real integer_power(real const &x, int const n)
Override the STL pow() with a product for n integer.
Definition: colvarmodule.h:104
std::string config_string
Configuration string read so far by the module (includes comments)
Definition: colvarmodule.h:447
std::string default_input_state_file_
Default input state file; if given, it is read unless the MD engine provides it.
Definition: colvarmodule.h:510
int read_config_file(char const *config_file_name)
Definition: colvarmodule.cpp:263
std::vector< std::vector< int > * > index_groups
Groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:808
static real tanh(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:205
int restart_version_number() const
Integer version of the most recent state file read.
Definition: colvarmodule.h:889
static atom_group * atom_group_soa_by_name(std::string const &name)
Look up a named atom group by name; returns NULL if not found.
Definition: colvarmodule.cpp:863
void * num_biases_types_used_
Pointer to a map counting how many biases of each type were used.
Definition: colvarmodule.h:365
int catch_input_errors(int result)
Useful wrapper to interrupt parsing if any error occurs.
Definition: colvarmodule.cpp:824
std::vector< std::string > index_file_names
Names of .ndx files that have been loaded.
Definition: colvarmodule.h:802
static int log_level_
Level of logging requested by the user.
Definition: colvarmodule.h:756
std::vector< colvar * > * variables_active()
Collective variables with the active flag on.
Definition: colvarmodule.cpp:212
std::vector< colvarbias * > * biases_active()
Array of active collective variable biases.
Definition: colvarmodule.cpp:244
int patch_version_int
Patch version number; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:90
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:393
std::istream & read_objects_state(std::istream &is)
Read the states of individual objects; allows for changes.
Definition: colvarmodule.cpp:1771
real total_bias_energy
Energy of built-in and scripted biases, summed per time-step.
Definition: colvarmodule.h:360
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:794
static size_t const it_width
Number of characters to represent a time step.
Definition: colvarmodule.h:718
static bool use_scripted_forces
Use scripted colvars forces?
Definition: colvarmodule.h:909
std::istream & read_state(std::istream &is)
Read all objects' state fron a formatted (text) stream.
Definition: colvarmodule.cpp:1730
static void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:2104
std::vector< unsigned char > input_state_buffer_
Internal state buffer, to be read as an unformatted stream.
Definition: colvarmodule.h:513
colvarparse * parse
Configuration file parser object.
Definition: colvarmodule.h:850
int calc_component_smp(int i)
Calculate the value of the specified component (to be called in a SMP loop)
Definition: colvarmodule.cpp:230
static size_t cv_traj_freq
Frequency for collective variables trajectory output.
Definition: colvarmodule.h:837
static size_t & depth()
Get the current object depth in the hierarchy.
Definition: colvarmodule.cpp:2139
real max_gradient_error
Definition: colvarmodule.h:878
static bool scripting_after_biases
Wait for all biases before calculating scripted forces?
Definition: colvarmodule.h:912
std::string const & get_config() const
Get the configuration string read so far (includes comments)
Definition: colvarmodule.cpp:387
static size_t restart_out_freq
Frequency for saving output restarts.
Definition: colvarmodule.h:840
int parse_colvars(std::string const &conf)
Parse and initialize collective variables.
Definition: colvarmodule.cpp:580
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:2188
static int errorCode
Definition: colvarmodule.h:256
std::vector< colvar * > colvars
Array of collective variables.
Definition: colvarmodule.h:312
static real atan2(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:199
std::vector< colvar * > * variables_active_smp()
Definition: colvarmodule.cpp:218
std::vector< atom_group * > named_atom_groups_soa
Array of named atom groups.
Definition: colvarmodule.h:324
static void increase_depth()
Increase the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2125
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:1893
static size_t const cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:720
static colvarmodule * main()
Access the one instance of the Colvars module.
Definition: colvarmodule.cpp:200
int parse_biases_type(std::string const &conf, char const *keyword)
Parse and initialize collective variable biases of a specific type.
Definition: colvarmodule.cpp:643
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:142
std::string version() const
Get the version string (YYYY-MM-DD format)
Definition: colvarmodule.cpp:37
static int log_level()
Level of logging requested by the user.
Definition: colvarmodule.h:761
int version_int
Integer representing the version string; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:87
std::ostream & write_traj_label(std::ostream &os)
Write explanatory labels in the trajectory file.
Definition: colvarmodule.cpp:2054
static real acos(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:183
int reset()
Actual function called by the destructor.
Definition: colvarmodule.cpp:1462
int calc_biases()
Calculate biases.
Definition: colvarmodule.cpp:1114
std::vector< colvar * > colvars_smp
Definition: colvarmodule.h:319
std::vector< colvar * > colvars_active
Array of collective variables.
Definition: colvarmodule.h:315
int analyze()
Perform analysis.
Definition: colvarmodule.cpp:1359
std::string read_colvar(std::string const &name)
Read a colvar value.
Definition: colvarmodule.cpp:908
size_t num_variables() const
Return how many variables are defined.
Definition: colvarmodule.cpp:754
std::string restart_out_name
Output restart file name.
Definition: colvarmodule.h:842
int version_number() const
Get the version number (higher = more recent)
Definition: colvarmodule.cpp:43
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:1913
static size_t const cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:722
size_t depth_s
Counter for the current depth in the object hierarchy (useg e.g. in output)
Definition: colvarmodule.h:865
static bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:376
int change_configuration(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:890
std::vector< colvarbias * > biases
Array of collective variable biases.
Definition: colvarmodule.h:357
std::string restart_version_str
Version of the most recent state file read.
Definition: colvarmodule.h:859
int restart_version_int
Integer version of the most recent state file read.
Definition: colvarmodule.h:862
int calc_scripted_forces()
Calculate the energy and forces of scripted biases.
Definition: colvarmodule.cpp:1255
std::string source_Tcl_script
Initialization Tcl script, user-provided.
Definition: colvarmodule.h:462
int write_restart_string(std::string &output)
Write the state into a string.
Definition: colvarmodule.cpp:1302
static std::istream & getline(std::istream &is, std::string &line)
Definition: colvarmodule.cpp:311
static int log_input_files()
Level at which input-file operations (configuration, state) are logged.
Definition: colvarmodule.h:791
int calc_colvars()
Calculate collective variables.
Definition: colvarmodule.cpp:1009
static real fabs(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:136
std::vector< colvar * > * variables()
Array of collective variables.
Definition: colvarmodule.cpp:206
static void decrease_depth()
Decrease the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2131
int update_engine_parameters()
Definition: colvarmodule.cpp:1414
real energy_difference(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:924
static int log_default_params()
Level at which a keyword's default value is logged.
Definition: colvarmodule.h:779
memory_stream & write_state(memory_stream &os)
Write the state of the module to an unformatted (binary) file.
void record_gradient_error(real error)
Definition: colvarmodule.h:920
int reset_index_groups()
Clear the index groups loaded so far.
Definition: colvarmodule.cpp:2309
static int log_user_params()
Level at which a keyword's user-provided value is logged.
Definition: colvarmodule.h:773
int print_total_forces_errning(bool warn_total_forces)
If needed (old restart file), print the warning that cannot be ignored.
Definition: colvarmodule.cpp:1863
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:277
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:760
static real sin(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:148
~colvarmodule()
Destructor.
Definition: colvarmodule.cpp:1433
static std::string & output_prefix()
Accessor for the above.
Definition: colvarmodule.h:303
void config_changed()
Signals to the module object that the configuration has changed.
Definition: colvarmodule.cpp:400
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:931
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2543
static step_number step_absolute()
Definition: colvarmodule.h:284
static colvar * colvar_by_name(std::string const &name)
Look up a colvar by name; returns NULL if not found.
Definition: colvarmodule.cpp:850
static int log_init_messages()
Level at which initialization messages are logged.
Definition: colvarmodule.h:767
static colvarbias * bias_by_name(std::string const &name)
Look up a bias by name; returns NULL if not found.
Definition: colvarmodule.cpp:836
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:299
int setup_input()
(Re)initialize and (re)read the input state file calling read_restart()
Definition: colvarmodule.cpp:1497
int parse_biases(std::string const &conf)
Parse and initialize collective variable biases.
Definition: colvarmodule.cpp:687
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:2044
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:95
int parse_global_params(std::string const &conf)
Parse the few module's global parameters.
Definition: colvarmodule.cpp:406
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:294
int run_tcl_script(std::string const &filename)
Run provided Tcl script.
Definition: colvarmodule.cpp:568
int close_traj_file()
Close it (note: currently unused)
std::vector< size_t > depth_v
Thread-specific depth.
Definition: colvarmodule.h:868
static size_t const en_width
Number of characters to represent the collective variables energy.
Definition: colvarmodule.h:726
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:564
Allocator for pinned host memory using cudaHostAlloc.
Definition: colvar_gpu_support.h:202
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43
Declaration of the class for GPU calculation of CVCs.
colvarmodule cvm
Shorthand for the frequently used type prefix.
Definition: colvarmodule.h:951