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#include <cstdio>
17#include <atomic>
18
19#include "colvars_version.h"
20
21#ifndef COLVARS_DEBUG
22#define COLVARS_DEBUG false
23#endif
24
25#if defined(__FAST_MATH__)
26// NOTE: This is used for fixing https://github.com/Colvars/colvars/issues/767
27#define COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
28#endif
29
30#define COLVARS_USE_SOA
31
48
49#include <cmath>
50#include <iosfwd>
51#include <string>
52#include <vector>
53#include "colvar_gpu_support.h"
54
55class colvarparse;
56class colvar;
57class colvarbias;
58class colvarproxy;
59class colvarvalue;
60class colvardeps;
61
62
73
74public:
75
77 std::string version() const;
78
80 int version_number() const;
81
83 int patch_version_number() const;
84
85private:
86
88 int version_int = 0;
89
92
93public:
94
96 typedef long long step_number;
97
99 typedef double real;
100
101
102 // Math functions
103
105 static COLVARS_HOST_DEVICE inline real integer_power(real const &x, int const n)
106 {
107 // Original code: math_special.h in LAMMPS
108 double yy, ww;
109 if (x == 0.0) return 0.0;
110 int nn = (n > 0) ? n : -n;
111 ww = x;
112 for (yy = 1.0; nn != 0; nn >>= 1, ww *=ww) {
113 if (nn & 1) yy *= ww;
114 }
115 return (n > 0) ? yy : 1.0/yy;
116 }
117
118 template <int n>
119 static COLVARS_HOST_DEVICE inline real
120 positive_integer_power(real const& x) {
121 static_assert(n > 0, "n must be greater than zero in positive_integer_power.");
122 real y = 1.0;
123 for (int i = 0; i < n; ++i) {
124 y *= x;
125 }
126 return y;
127 }
128
130 static inline real pow(real const &x, real const &y)
131 {
132 return ::pow(static_cast<double>(x), static_cast<double>(y));
133 }
134
136 static inline real floor(real const &x)
137 {
138 return ::floor(static_cast<double>(x));
139 }
140
142 static inline real ceil(real const &x)
143 {
144 return ::ceil(static_cast<double>(x));
145 }
146
148 static inline real fabs(real const &x)
149 {
150 return ::fabs(static_cast<double>(x));
151 }
152
154 static inline real sqrt(real const &x)
155 {
156 return ::sqrt(static_cast<double>(x));
157 }
158
160 static inline real sin(real const &x)
161 {
162 return ::sin(static_cast<double>(x));
163 }
164
166 static inline real cos(real const &x)
167 {
168 return ::cos(static_cast<double>(x));
169 }
170
171#ifndef PI
172#define PI 3.14159265358979323846
173#endif
174#ifndef PI_2
175#define PI_2 1.57079632679489661923
176#endif
177
179static inline real asin(real const &x)
180{
181#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
182 if (x <= -1.0) {
183 return -PI_2;
184 } else if (x >= 1.0) {
185 return PI_2;
186 } else {
187 return ::asin(static_cast<double>(x));
188 }
189#else
190 return ::asin(static_cast<double>(x));
191#endif
192}
193
195static inline real acos(real const &x)
196{
197#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
198 if (x <= -1.0) {
199 return PI;
200 } else if (x >= 1.0) {
201 return 0.0;
202 } else {
203 return ::acos(static_cast<double>(x));
204 }
205#else
206 return ::acos(static_cast<double>(x));
207#endif
208}
209
211 static inline real atan2(real const &x, real const &y)
212 {
213 return ::atan2(static_cast<double>(x), static_cast<double>(y));
214 }
215
217 static inline real tanh(real const &x)
218 {
219 return ::tanh(static_cast<double>(x));
220 }
221
223 static inline real exp(real const &x)
224 {
225 return ::exp(static_cast<double>(x));
226 }
227
231 static inline real logn(real const &x)
232 {
233 return ::log(static_cast<double>(x));
234 }
235
236 // Forward declarations
237 class rvector;
238 template <class T> class vector1d;
239 template <class T> class matrix2d;
240 class quaternion;
241 class rotation;
242 class system_boundary_conditions;
243
244 class usage;
245 class memory_stream;
246
248 typedef int residue_id;
249
253
255 class rmatrix;
256
257 // NOTE: Just here for ensuring the compilation of GROMACS with Colvars
258 struct atom;
259 // class atom_group_base;
260 class atom_group;
261 // class atom_group_gpu;
262 // typedef std::vector<atom>::iterator atom_iter;
263 // typedef std::vector<atom>::const_iterator atom_const_iter;
264
267private:
268
269 int errorCode = 0;
270
271public:
272
273 void set_error_bits(int code);
274
275 bool get_error_bit(int code);
276
277 inline int get_error()
278 {
279 return errorCode;
280 }
281
282 void clear_error();
283
288
291 {
292 return it - it_restart;
293 }
294
298 {
299 return it;
300 }
301
302 bool binary_restart;
303
308
309private:
310
312 std::string cvm_output_prefix;
313
314public:
316 inline std::string &output_prefix()
317 {
318 return this->cvm_output_prefix;
319 }
320
321private:
322
324 std::vector<colvar *> colvars;
325
327 std::vector<colvar *> colvars_active;
328
331 std::vector<colvar *> colvars_smp;
333 std::vector<int> colvars_smp_items;
334
336 std::vector<atom_group *> named_atom_groups;
337
338public:
339
340 void register_named_atom_group(atom_group *ag);
341 void unregister_named_atom_group(atom_group *ag);
342
344 std::vector<colvar *> *variables();
345
346 /* TODO: implement named CVCs
348 std::vector<cvc *> cvcs;
350 inline void register_cvc(cvc *p) {
351 cvcs.push_back(p);
352 }
353 */
354
356 std::vector<colvar *> *variables_active();
357
360 std::vector<colvar *> *variables_active_smp();
361
363 std::vector<int> *variables_active_smp_items();
364
366 int calc_component_smp(int i);
367
369 std::vector<colvarbias *> biases;
370
373
374private:
375
378
380 std::vector<colvarbias *> biases_active_;
381
382public:
383
385 std::vector<colvarbias *> *biases_active();
386
388 static inline bool constexpr debug()
389 {
390#if (defined(__HIP_DEVICE_COMPILE__)) || (defined(__CUDA_ARCH__))
391 return false;
392#else
393 return COLVARS_DEBUG;
394#endif
395 }
396
398 size_t size() const;
399
403
404private:
405
408
409public:
410
413
416
418 int reset();
419
422 int read_config_file(char const *config_file_name);
423
426 int read_config_string(std::string const &conf);
427
429 int parse_config(std::string &conf);
430
432 std::string const & get_config() const;
433
434 // Parse functions (setup internal data based on a string)
435
438 static std::istream & getline(std::istream &is, std::string &line);
439
441 int parse_global_params(std::string const &conf);
442
444 int parse_colvars(std::string const &conf);
445
447 int run_tcl_script(std::string const &filename);
448
450 int parse_biases(std::string const &conf);
451
455 int append_new_config(std::string const &conf);
456
458 void config_changed();
459
460private:
461
463 std::string config_string;
464
467 std::string extra_conf;
468
470 template <class bias_type>
471 int parse_biases_type(std::string const &conf, char const *keyword);
472
475 bool check_new_bias(std::string &conf, char const *key);
476
478 std::string source_Tcl_script;
479
480public:
481
483 size_t num_variables() const;
484
486 size_t num_variables_feature(int feature_id) const;
487
489 size_t num_biases() const;
490
492 size_t num_biases_feature(int feature_id) const;
493
495 size_t num_biases_type(std::string const &type) const;
496
499 std::vector<std::string> const time_dependent_biases() const;
500
501private:
503 int catch_input_errors(int result);
504
505public:
506
507 // "Setup" functions (change internal data based on related data
508 // from the proxy that may change during program execution)
509 // No additional parsing is done within these functions
510
514
516 int setup_input();
517
519 int setup_output();
520
521private:
522
523 template <typename IST> IST & read_state_template_(IST &is);
524
527
529 std::vector<unsigned char> input_state_buffer_;
530
531public:
532
534 std::istream & read_state(std::istream &is);
535
537 memory_stream & read_state(memory_stream &is);
538
540 int set_input_state_buffer(size_t n, unsigned char *buf);
541
543 int set_input_state_buffer(std::vector<unsigned char> &buf);
544
546 std::istream & read_objects_state(std::istream &is);
547
549 memory_stream & read_objects_state(memory_stream &is);
550
552 int print_total_forces_errning(bool warn_total_forces);
553
554private:
555 template <typename OST> OST &write_state_template_(OST &os);
556
557public:
558
560 std::ostream & write_state(std::ostream &os);
561
563 memory_stream & write_state(memory_stream &os);
564
566 int write_state_buffer(std::vector<unsigned char> &buffer);
567
569 std::string state_file_prefix(char const *filename);
570
572 int open_traj_file(std::string const &file_name);
576 std::ostream & write_traj(std::ostream &os);
578 std::ostream & write_traj_label(std::ostream &os);
579
581 int write_traj_files();
583 int write_restart_file(std::string const &out_name);
585 int write_output_files();
587 int backup_file(char const *filename);
588
590 int write_restart_string(std::string &output);
591
593 colvarbias * bias_by_name(std::string const &name);
594
596 colvar * colvar_by_name(std::string const &name);
597
599 atom_group * atom_group_by_name(std::string const& name);
600
603 int change_configuration(std::string const &bias_name, std::string const &conf);
604
606 std::string read_colvar(std::string const &name);
607
610 real energy_difference(std::string const &bias_name, std::string const &conf);
611
613 int calc();
614
616 int calc_colvars();
617
619 int calc_biases();
620
623
626
628 int analyze();
629
631 int end_of_step();
632
635 int read_traj(char const *traj_filename,
636 long traj_read_begin,
637 long traj_read_end);
638
639 // In a first phase, keep to_str() static
640
642 static std::string to_str(char const *s);
643
645 static std::string to_str(const void* ptr);
646
648 static std::string to_str(std::string const &s);
649
651 static std::string to_str(bool x);
652
654 static std::string to_str(int const &x,
655 size_t width = 0, size_t prec = 0);
656
658 static std::string to_str(size_t const &x,
659 size_t width = 0, size_t prec = 0);
660
662 static std::string to_str(long int const &x,
663 size_t width = 0, size_t prec = 0);
664
666 static std::string to_str(step_number const &x,
667 size_t width = 0, size_t prec = 0);
668
670 static std::string to_str(real const &x,
671 size_t width = 0, size_t prec = 0);
672
674 static std::string to_str(rvector const &x,
675 size_t width = 0, size_t prec = 0);
676
678 static std::string to_str(quaternion const &x,
679 size_t width = 0, size_t prec = 0);
680
682 static std::string to_str(colvarvalue const &x,
683 size_t width = 0, size_t prec = 0);
684
686 static std::string to_str(vector1d<real> const &x,
687 size_t width = 0, size_t prec = 0);
688
690 static std::string to_str(matrix2d<real> const &x,
691 size_t width = 0, size_t prec = 0);
692
693
695 static std::string to_str(std::vector<int> const &x,
696 size_t width = 0, size_t prec = 0);
697
699 static std::string to_str(std::vector<size_t> const &x,
700 size_t width = 0, size_t prec = 0);
701
703 static std::string to_str(std::vector<long int> const &x,
704 size_t width = 0, size_t prec = 0);
705
707 static std::string to_str(std::vector<real> const &x,
708 size_t width = 0, size_t prec = 0);
709
711 static std::string to_str(std::vector<rvector> const &x,
712 size_t width = 0, size_t prec = 0);
713
715 static std::string to_str(std::vector<quaternion> const &x,
716 size_t width = 0, size_t prec = 0);
717
719 static std::string to_str(std::vector<colvarvalue> const &x,
720 size_t width = 0, size_t prec = 0);
721
723 static std::string to_str(std::vector<std::string> const &x,
724 size_t width = 0, size_t prec = 0);
725
726#if ( defined(COLVARS_CUDA) || defined(COLVARS_HIP) )
727 static std::string to_str(std::vector<rvector, colvars_gpu::CudaHostAllocator<rvector>> const &x,
728 size_t width = 0, size_t prec = 0);
729 static std::string to_str(std::vector<real, colvars_gpu::CudaHostAllocator<real>> const &x,
730 size_t width = 0, size_t prec = 0);
731#endif
732
733
735 static std::string wrap_string(std::string const &s,
736 size_t nchars);
737
738 // i/o constants
739
741 static constexpr size_t it_width = 12;
743 static constexpr size_t cv_prec = 14;
745 static constexpr size_t cv_width = 21;
747 static constexpr size_t en_prec = 14;
749 static constexpr size_t en_width = 21;
751 static constexpr const char line_marker[] =
752 "----------------------------------------------------------------------\n";
753
754 // proxy functions
755
757 real dt();
758
760 void request_total_force();
761
763 int cite_feature(std::string const &feature);
764
766 std::string feature_report(int flag = 0);
767
771 void log(std::string const &message, int min_log_level = 10);
772
775 static void log_static(std::string const &message) {
776 if (colvarmodule::main()) {
777 colvarmodule::main()->log(message);
778 } else {
779 std::printf("colvars: %s\n", message.c_str());
780 }
781 }
782
784 int error(std::string const &message, int code = -1);
785
789 static int error_static(std::string const &message, int code = -1) {
790 if (colvarmodule::main()) {
791 code = colvarmodule::main()->error(message, code);
792 } else {
793 std::cerr << "colvars: " << message << std::endl;
794 exit(-1);
795 }
796 return code;
797 }
798
799private:
800
802 int log_level_ = 10;
803
804public:
805
807 inline int log_level()
808 {
809 return log_level_;
810 }
811
813 inline int log_init_messages()
814 {
815 return 1;
816 }
817
819 inline int log_user_params()
820 {
821 return 2;
822 }
823
826 {
827 return 3;
828 }
829
831 inline int log_output_files()
832 {
833 return 4;
834 }
835
837 inline int log_input_files()
838 {
839 return 5;
840 }
841
843 std::vector<std::string> index_file_names;
844
846 std::vector<std::string> index_group_names;
847
849 std::vector<std::vector<int> *> index_groups;
850
852 int read_index_file(char const *filename);
853
855 int reset_index_groups();
856
865 int load_coords(char const *filename,
866 std::vector<rvector> *pos,
867 atom_group *atoms,
868 std::string const &pdb_field,
869 double pdb_field_value = 0.0);
870
872 int load_coords_xyz(char const *filename,
873 std::vector<rvector> *pos,
874 atom_group *atoms,
875 bool keep_open = false);
876
878 size_t cv_traj_freq = 0;
879
883 std::string restart_out_name;
884
887
888protected:
889
892
894 std::string cv_traj_name;
895
898
901
904
906 size_t depth_s;
907
909 std::vector<size_t> depth_v;
910
913
916
919 std::atomic<real> max_gradient_error{0.};
920
921public:
922
924 inline std::string restart_version() const
925 {
926 return restart_version_str;
927 }
928
930 inline int restart_version_number() const
931 {
932 return restart_version_int;
933 }
934
936 size_t & depth();
937
939 void increase_depth();
940
942 void decrease_depth();
943
944 inline bool scripted_forces()
945 {
946 return use_scripted_forces;
947 }
948
951
954
957
962 real current = max_gradient_error.load(std::memory_order_relaxed);
963 while (error > current &&
964 !max_gradient_error.compare_exchange_weak(current, error, std::memory_order_relaxed)) {
965 }
966 }
967
968 real get_max_gradient_error() {
969 return max_gradient_error;
970 }
971
974 colvarproxy *proxy = nullptr;
977
979 static colvarmodule *main();
980
981#if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
982 template <typename T>
984#else
985 template <typename T>
986 using allocator_type = std::allocator<T>;
987#endif
988 using ag_vector_real_t = std::vector<real, allocator_type<real>>;
989
990};
991
994
995
996std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
997std::istream & operator >> (std::istream &is, cvm::rvector &v);
998
999
1000namespace {
1001 constexpr int32_t COLVARS_OK = 0;
1002 constexpr int32_t COLVARS_ERROR = 1;
1003 constexpr int32_t COLVARS_NOT_IMPLEMENTED = (1<<1);
1004 constexpr int32_t COLVARS_INPUT_ERROR = (1<<2); // out of bounds or inconsistent input
1005 constexpr int32_t COLVARS_BUG_ERROR = (1<<3); // Inconsistent state indicating bug
1006 constexpr int32_t COLVARS_FILE_ERROR = (1<<4);
1007 constexpr int32_t COLVARS_MEMORY_ERROR = (1<<5);
1008 constexpr int32_t COLVARS_NO_SUCH_FRAME = (1<<6); // Cannot load the requested frame
1009}
1010
1011
1012#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:376
1-dimensional vector of real numbers with four components and a quaternion algebra
Definition: colvartypes.h:980
2-dimensional array of real numbers with three components along each dimension (works with colvarmodu...
Definition: colvartypes.h:903
vector of real numbers with three components
Definition: colvartypes.h:728
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:72
int cite_feature(std::string const &feature)
Track usage of the given Colvars feature.
Definition: colvarmodule.cpp:2723
static constexpr const char line_marker[]
Line separator in the log output.
Definition: colvarmodule.h:751
int log_input_files()
Level at which input-file operations (configuration, state) are logged.
Definition: colvarmodule.h:837
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:252
int write_traj_files()
Write all trajectory files.
Definition: colvarmodule.cpp:1343
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:2398
std::ostream & write_state(std::ostream &os)
Write the state of the module to a formatted (text) file.
Definition: colvarmodule.cpp:2065
std::string state_file_prefix(char const *filename)
Strips .colvars.state from filename and checks that it is not empty.
Definition: colvarmodule.cpp:1679
static real pow(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:130
size_t num_biases_feature(int feature_id) const
Return how many biases have this feature enabled.
Definition: colvarmodule.cpp:770
static real asin(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:179
bool cv_traj_write_labels
Write labels at the next iteration.
Definition: colvarmodule.h:897
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:798
static colvarproxy * proxy_static
Temporary static pointer to unique proxy object.
Definition: colvarmodule.h:976
std::string cv_traj_name
Name of the trajectory file.
Definition: colvarmodule.h:894
static real logn(real const &x)
Definition: colvarmodule.h:231
std::vector< atom_group * > named_atom_groups
Array of named atom groups.
Definition: colvarmodule.h:336
std::ostream & write_traj(std::ostream &os)
Write in the trajectory file.
Definition: colvarmodule.cpp:2115
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:99
int proxy_gpu_buffers_reallocated_done()
Called from proxy when it completes buffers reallocation.
Definition: colvarmodule.cpp:1275
step_number it_restart
Starting step number for this run.
Definition: colvarmodule.h:287
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:294
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 bool constexpr debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:388
static real floor(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:136
int log_level()
Level of logging requested by the user.
Definition: colvarmodule.h:807
static void log_static(std::string const &message)
Definition: colvarmodule.h:775
size_t size() const
How many objects (variables and biases) are configured yet?
Definition: colvarmodule.cpp:252
int xyz_reader_use_count
Track how many times the XYZ reader has been used.
Definition: colvarmodule.h:912
std::vector< std::string > index_group_names
Names of groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:846
usage * usage_
Track usage of Colvars features.
Definition: colvarmodule.h:915
int log_default_params()
Level at which a keyword's default value is logged.
Definition: colvarmodule.h:825
std::atomic< real > max_gradient_error
Definition: colvarmodule.h:919
int update_colvar_forces()
Integrate bias and restraint forces, send colvar forces to atoms.
Definition: colvarmodule.cpp:1167
std::string restart_version() const
Version of the most recent state file read.
Definition: colvarmodule.h:924
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:1794
int parse_config(std::string &conf)
Parse a "clean" config string (no comments)
Definition: colvarmodule.cpp:333
int write_restart_file(std::string const &out_name)
Write a state file useful to resume the simulation.
Definition: colvarmodule.cpp:1302
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:258
static real exp(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:223
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:226
static real ceil(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:142
int residue_id
Residue identifier.
Definition: colvarmodule.h:248
std::vector< colvarbias * > biases_active_
Array of active collective variable biases.
Definition: colvarmodule.h:380
int end_of_step()
Carry out operations needed before next step is run.
Definition: colvarmodule.cpp:1416
static int error_static(std::string const &message, int code=-1)
Definition: colvarmodule.h:789
size_t num_biases() const
Return how many biases are defined.
Definition: colvarmodule.cpp:764
int setup_output()
(Re)initialize the output trajectory and state file (does not write it yet)
Definition: colvarmodule.cpp:1634
bool check_new_bias(std::string &conf, char const *key)
Definition: colvarmodule.cpp:619
std::string feature_report(int flag=0)
Report usage of the Colvars features.
Definition: colvarmodule.cpp:2728
std::vector< int > colvars_smp_items
Indexes of the items to calculate for each colvar.
Definition: colvarmodule.h:333
int backup_file(char const *filename)
Backup a file before writing it.
Definition: colvarmodule.cpp:1925
int calc()
Main worker function.
Definition: colvarmodule.cpp:928
int log_init_messages()
Level at which initialization messages are logged.
Definition: colvarmodule.h:813
static real cos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:166
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:467
step_number step_absolute()
Definition: colvarmodule.h:297
static constexpr size_t it_width
Number of characters to represent a time step.
Definition: colvarmodule.h:741
std::string config_string
Configuration string read so far by the module (includes comments)
Definition: colvarmodule.h:463
std::string default_input_state_file_
Default input state file; if given, it is read unless the MD engine provides it.
Definition: colvarmodule.h:526
int read_config_file(char const *config_file_name)
Definition: colvarmodule.cpp:265
std::vector< std::vector< int > * > index_groups
Groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:849
static real tanh(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:217
int restart_version_number() const
Integer version of the most recent state file read.
Definition: colvarmodule.h:930
void * num_biases_types_used_
Pointer to a map counting how many biases of each type were used.
Definition: colvarmodule.h:377
int catch_input_errors(int result)
Useful wrapper to interrupt parsing if any error occurs.
Definition: colvarmodule.cpp:814
std::vector< std::string > index_file_names
Names of .ndx files that have been loaded.
Definition: colvarmodule.h:843
int log_level_
Level of logging requested by the user.
Definition: colvarmodule.h:802
std::vector< colvar * > * variables_active()
Collective variables with the active flag on.
Definition: colvarmodule.cpp:214
std::vector< colvarbias * > * biases_active()
Array of active collective variable biases.
Definition: colvarmodule.cpp:246
real dt()
Time step of MD integrator (fs)
Definition: colvarmodule.cpp:2511
int patch_version_int
Patch version number; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:91
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:851
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:395
std::istream & read_objects_state(std::istream &is)
Read the states of individual objects; allows for changes.
Definition: colvarmodule.cpp:1809
real total_bias_energy
Energy of built-in and scripted biases, summed per time-step.
Definition: colvarmodule.h:372
size_t num_biases_type(std::string const &type) const
Return how many biases of this type are defined.
Definition: colvarmodule.cpp:784
std::string & output_prefix()
Accessor for the above.
Definition: colvarmodule.h:316
bool use_scripted_forces
Use scripted colvars forces?
Definition: colvarmodule.h:950
int log_output_files()
Level at which output-file operations are logged.
Definition: colvarmodule.h:831
std::istream & read_state(std::istream &is)
Read all objects' state fron a formatted (text) stream.
Definition: colvarmodule.cpp:1768
void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:2140
std::vector< unsigned char > input_state_buffer_
Internal state buffer, to be read as an unformatted stream.
Definition: colvarmodule.h:529
step_number step_relative()
Return the current step number from the beginning of this run.
Definition: colvarmodule.h:290
real rand_gaussian()
Pseudo-random number with Gaussian distribution.
Definition: colvarmodule.cpp:2523
colvarparse * parse
Configuration file parser object.
Definition: colvarmodule.h:891
int calc_component_smp(int i)
Calculate the value of the specified component (to be called in a SMP loop)
Definition: colvarmodule.cpp:232
size_t cv_traj_freq
Frequency for collective variables trajectory output.
Definition: colvarmodule.h:878
size_t & depth()
Get the current object depth in the hierarchy.
Definition: colvarmodule.cpp:2176
static constexpr size_t en_width
Number of characters to represent the collective variables energy.
Definition: colvarmodule.h:749
bool scripting_after_biases
Wait for all biases before calculating scripted forces?
Definition: colvarmodule.h:953
std::string const & get_config() const
Get the configuration string read so far (includes comments)
Definition: colvarmodule.cpp:389
size_t restart_out_freq
Frequency for saving output restarts.
Definition: colvarmodule.h:881
step_number it
Current step number.
Definition: colvarmodule.h:285
int parse_colvars(std::string const &conf)
Parse and initialize collective variables.
Definition: colvarmodule.cpp:570
int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2224
int errorCode
Definition: colvarmodule.h:269
std::vector< colvar * > colvars
Array of collective variables.
Definition: colvarmodule.h:324
static real atan2(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:211
std::vector< colvar * > * variables_active_smp()
Definition: colvarmodule.cpp:220
static constexpr size_t en_prec
Number of digits to represent the collective variables energy.
Definition: colvarmodule.h:747
void increase_depth()
Increase the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2162
colvarmodule()
Cannot initialize the main object without a proxy.
int write_output_files()
Write all other output files.
Definition: colvarmodule.cpp:1931
static constexpr size_t cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:743
static colvarmodule * main()
Access the main instance of the Colvars module.
Definition: colvarmodule.cpp:202
int parse_biases_type(std::string const &conf, char const *keyword)
Parse and initialize collective variable biases of a specific type.
Definition: colvarmodule.cpp:633
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:154
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:105
int version_int
Integer representing the version string; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:88
std::ostream & write_traj_label(std::ostream &os)
Write explanatory labels in the trajectory file.
Definition: colvarmodule.cpp:2090
static real acos(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:195
static std::string wrap_string(std::string const &s, size_t nchars)
Reduce the number of characters in a string.
Definition: colvarmodule.cpp:2710
int reset()
Actual function called by the destructor.
Definition: colvarmodule.cpp:1491
int calc_biases()
Calculate biases.
Definition: colvarmodule.cpp:1093
std::vector< colvar * > colvars_smp
Definition: colvarmodule.h:331
std::vector< colvar * > colvars_active
Array of collective variables.
Definition: colvarmodule.h:327
int analyze()
Perform analysis.
Definition: colvarmodule.cpp:1388
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:2358
std::string read_colvar(std::string const &name)
Read a colvar value.
Definition: colvarmodule.cpp:895
size_t num_variables() const
Return how many variables are defined.
Definition: colvarmodule.cpp:744
std::string restart_out_name
Output restart file name.
Definition: colvarmodule.h:883
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:1951
size_t depth_s
Counter for the current depth in the object hierarchy (useg e.g. in output)
Definition: colvarmodule.h:906
int log_user_params()
Level at which a keyword's user-provided value is logged.
Definition: colvarmodule.h:819
int change_configuration(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:877
std::vector< colvarbias * > biases
Array of collective variable biases.
Definition: colvarmodule.h:369
std::string restart_version_str
Version of the most recent state file read.
Definition: colvarmodule.h:900
int restart_version_int
Integer version of the most recent state file read.
Definition: colvarmodule.h:903
int calc_scripted_forces()
Calculate the energy and forces of scripted biases.
Definition: colvarmodule.cpp:1284
std::string source_Tcl_script
Initialization Tcl script, user-provided.
Definition: colvarmodule.h:478
int write_restart_string(std::string &output)
Write the state into a string.
Definition: colvarmodule.cpp:1331
static std::istream & getline(std::istream &is, std::string &line)
Definition: colvarmodule.cpp:313
int calc_colvars()
Calculate collective variables.
Definition: colvarmodule.cpp:996
static real fabs(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:148
static constexpr size_t cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:745
std::vector< colvar * > * variables()
Array of collective variables.
Definition: colvarmodule.cpp:208
void decrease_depth()
Decrease the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2168
int update_engine_parameters()
Definition: colvarmodule.cpp:1443
real energy_difference(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:911
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:961
int reset_index_groups()
Clear the index groups loaded so far.
Definition: colvarmodule.cpp:2345
int print_total_forces_errning(bool warn_total_forces)
If needed (old restart file), print the warning that cannot be ignored.
Definition: colvarmodule.cpp:1901
memory_stream & read_objects_state(memory_stream &is)
Read the states of individual objects; allows for changes.
int read_index_file(char const *filename)
Read a Gromacs .ndx file.
Definition: colvarmodule.cpp:2254
size_t num_variables_feature(int feature_id) const
Return how many variables have this feature enabled.
Definition: colvarmodule.cpp:750
static real sin(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:160
~colvarmodule()
Destructor.
Definition: colvarmodule.cpp:1462
void config_changed()
Signals to the module object that the configuration has changed.
Definition: colvarmodule.cpp:402
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2572
colvar * colvar_by_name(std::string const &name)
Look up a colvar by name; returns NULL if not found.
Definition: colvarmodule.cpp:839
colvarbias * bias_by_name(std::string const &name)
Look up a bias by name; returns NULL if not found.
Definition: colvarmodule.cpp:826
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:312
int setup_input()
(Re)initialize and (re)read the input state file calling read_restart()
Definition: colvarmodule.cpp:1524
int parse_biases(std::string const &conf)
Parse and initialize collective variable biases.
Definition: colvarmodule.cpp:677
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:2080
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:96
int parse_global_params(std::string const &conf)
Parse the few module's global parameters.
Definition: colvarmodule.cpp:408
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:307
int run_tcl_script(std::string const &filename)
Run provided Tcl script.
Definition: colvarmodule.cpp:558
int close_traj_file()
Close it (note: currently unused)
std::vector< size_t > depth_v
Thread-specific depth.
Definition: colvarmodule.h:909
colvarproxy * proxy
Pointer to the proxy object, used to retrieve atomic data from the hosting program.
Definition: colvarmodule.h:974
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:2517
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
Definition: colvarproxy.h:568
Allocator for pinned host memory using cudaHostAlloc.
Definition: colvar_gpu_support.h:358
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:993