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
18#include "colvars_version.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 COLVARS_HOST_DEVICE 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
117 template <int n>
118 static COLVARS_HOST_DEVICE inline real
119 positive_integer_power(real const& x) {
120 static_assert(n > 0, "n must be greater than zero in positive_integer_power.");
121 real y = 1.0;
122 for (int i = 0; i < n; ++i) {
123 y *= x;
124 }
125 return y;
126 }
127
129 static inline real pow(real const &x, real const &y)
130 {
131 return ::pow(static_cast<double>(x), static_cast<double>(y));
132 }
133
135 static inline real floor(real const &x)
136 {
137 return ::floor(static_cast<double>(x));
138 }
139
141 static inline real ceil(real const &x)
142 {
143 return ::ceil(static_cast<double>(x));
144 }
145
147 static inline real fabs(real const &x)
148 {
149 return ::fabs(static_cast<double>(x));
150 }
151
153 static inline real sqrt(real const &x)
154 {
155 return ::sqrt(static_cast<double>(x));
156 }
157
159 static inline real sin(real const &x)
160 {
161 return ::sin(static_cast<double>(x));
162 }
163
165 static inline real cos(real const &x)
166 {
167 return ::cos(static_cast<double>(x));
168 }
169
170#ifndef PI
171#define PI 3.14159265358979323846
172#endif
173#ifndef PI_2
174#define PI_2 1.57079632679489661923
175#endif
176
178static inline real asin(real const &x)
179{
180#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
181 if (x <= -1.0) {
182 return -PI_2;
183 } else if (x >= 1.0) {
184 return PI_2;
185 } else {
186 return ::asin(static_cast<double>(x));
187 }
188#else
189 return ::asin(static_cast<double>(x));
190#endif
191}
192
194static inline real acos(real const &x)
195{
196#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
197 if (x <= -1.0) {
198 return PI;
199 } else if (x >= 1.0) {
200 return 0.0;
201 } else {
202 return ::acos(static_cast<double>(x));
203 }
204#else
205 return ::acos(static_cast<double>(x));
206#endif
207}
208
210 static inline real atan2(real const &x, real const &y)
211 {
212 return ::atan2(static_cast<double>(x), static_cast<double>(y));
213 }
214
216 static inline real tanh(real const &x)
217 {
218 return ::tanh(static_cast<double>(x));
219 }
220
222 static inline real exp(real const &x)
223 {
224 return ::exp(static_cast<double>(x));
225 }
226
230 static inline real logn(real const &x)
231 {
232 return ::log(static_cast<double>(x));
233 }
234
235 // Forward declarations
236 class rvector;
237 template <class T> class vector1d;
238 template <class T> class matrix2d;
239 class quaternion;
240 class rotation;
241 class system_boundary_conditions;
242
243 class usage;
244 class memory_stream;
245
247 typedef int residue_id;
248
252
254 class rmatrix;
255
256 // NOTE: Just here for ensuring the compilation of GROMACS with Colvars
257 struct atom;
258 // class atom_group_base;
259 class atom_group;
260 // class atom_group_gpu;
261 // typedef std::vector<atom>::iterator atom_iter;
262 // typedef std::vector<atom>::const_iterator atom_const_iter;
263
266private:
267
268 int errorCode = 0;
269
270public:
271
272 void set_error_bits(int code);
273
274 bool get_error_bit(int code);
275
276 inline int get_error()
277 {
278 return errorCode;
279 }
280
281 void clear_error();
282
287
290 {
291 return it - it_restart;
292 }
293
297 {
298 return it;
299 }
300
301 bool binary_restart;
302
307
308private:
309
311 std::string cvm_output_prefix;
312
313public:
315 inline std::string &output_prefix()
316 {
317 return this->cvm_output_prefix;
318 }
319
320private:
321
323 std::vector<colvar *> colvars;
324
326 std::vector<colvar *> colvars_active;
327
330 std::vector<colvar *> colvars_smp;
332 std::vector<int> colvars_smp_items;
333
335 std::vector<atom_group *> named_atom_groups;
336
337public:
338
339 void register_named_atom_group(atom_group *ag);
340 void unregister_named_atom_group(atom_group *ag);
341
343 std::vector<colvar *> *variables();
344
345 /* TODO: implement named CVCs
347 std::vector<cvc *> cvcs;
349 inline void register_cvc(cvc *p) {
350 cvcs.push_back(p);
351 }
352 */
353
355 std::vector<colvar *> *variables_active();
356
359 std::vector<colvar *> *variables_active_smp();
360
362 std::vector<int> *variables_active_smp_items();
363
365 int calc_component_smp(int i);
366
368 std::vector<colvarbias *> biases;
369
372
373private:
374
377
379 std::vector<colvarbias *> biases_active_;
380
381public:
382
384 std::vector<colvarbias *> *biases_active();
385
387 static inline bool constexpr debug()
388 {
389#if (defined(__HIP_DEVICE_COMPILE__)) || (defined(__CUDA_ARCH__))
390 return false;
391#else
392 return COLVARS_DEBUG;
393#endif
394 }
395
397 size_t size() const;
398
402
403private:
404
407
408public:
409
412
415
417 int reset();
418
421 int read_config_file(char const *config_file_name);
422
425 int read_config_string(std::string const &conf);
426
428 int parse_config(std::string &conf);
429
431 std::string const & get_config() const;
432
433 // Parse functions (setup internal data based on a string)
434
437 static std::istream & getline(std::istream &is, std::string &line);
438
440 int parse_global_params(std::string const &conf);
441
443 int parse_colvars(std::string const &conf);
444
446 int run_tcl_script(std::string const &filename);
447
449 int parse_biases(std::string const &conf);
450
454 int append_new_config(std::string const &conf);
455
457 void config_changed();
458
459private:
460
462 std::string config_string;
463
466 std::string extra_conf;
467
469 template <class bias_type>
470 int parse_biases_type(std::string const &conf, char const *keyword);
471
474 bool check_new_bias(std::string &conf, char const *key);
475
477 std::string source_Tcl_script;
478
479public:
480
482 size_t num_variables() const;
483
485 size_t num_variables_feature(int feature_id) const;
486
488 size_t num_biases() const;
489
491 size_t num_biases_feature(int feature_id) const;
492
494 size_t num_biases_type(std::string const &type) const;
495
498 std::vector<std::string> const time_dependent_biases() const;
499
500private:
502 int catch_input_errors(int result);
503
504public:
505
506 // "Setup" functions (change internal data based on related data
507 // from the proxy that may change during program execution)
508 // No additional parsing is done within these functions
509
513
515 int setup_input();
516
518 int setup_output();
519
520private:
521
522 template <typename IST> IST & read_state_template_(IST &is);
523
526
528 std::vector<unsigned char> input_state_buffer_;
529
530public:
531
533 std::istream & read_state(std::istream &is);
534
536 memory_stream & read_state(memory_stream &is);
537
539 int set_input_state_buffer(size_t n, unsigned char *buf);
540
542 int set_input_state_buffer(std::vector<unsigned char> &buf);
543
545 std::istream & read_objects_state(std::istream &is);
546
548 memory_stream & read_objects_state(memory_stream &is);
549
551 int print_total_forces_errning(bool warn_total_forces);
552
553private:
554 template <typename OST> OST &write_state_template_(OST &os);
555
556public:
557
559 std::ostream & write_state(std::ostream &os);
560
562 memory_stream & write_state(memory_stream &os);
563
565 int write_state_buffer(std::vector<unsigned char> &buffer);
566
568 std::string state_file_prefix(char const *filename);
569
571 int open_traj_file(std::string const &file_name);
575 std::ostream & write_traj(std::ostream &os);
577 std::ostream & write_traj_label(std::ostream &os);
578
580 int write_traj_files();
582 int write_restart_file(std::string const &out_name);
584 int write_output_files();
586 int backup_file(char const *filename);
587
589 int write_restart_string(std::string &output);
590
592 colvarbias * bias_by_name(std::string const &name);
593
595 colvar * colvar_by_name(std::string const &name);
596
598 atom_group * atom_group_by_name(std::string const& name);
599
602 int change_configuration(std::string const &bias_name, std::string const &conf);
603
605 std::string read_colvar(std::string const &name);
606
609 real energy_difference(std::string const &bias_name, std::string const &conf);
610
612 int calc();
613
615 int calc_colvars();
616
618 int calc_biases();
619
622
625
627 int analyze();
628
630 int end_of_step();
631
634 int read_traj(char const *traj_filename,
635 long traj_read_begin,
636 long traj_read_end);
637
638 // In a first phase, keep to_str() static
639
641 static std::string to_str(char const *s);
642
644 static std::string to_str(const void* ptr);
645
647 static std::string to_str(std::string const &s);
648
650 static std::string to_str(bool x);
651
653 static std::string to_str(int const &x,
654 size_t width = 0, size_t prec = 0);
655
657 static std::string to_str(size_t const &x,
658 size_t width = 0, size_t prec = 0);
659
661 static std::string to_str(long int const &x,
662 size_t width = 0, size_t prec = 0);
663
665 static std::string to_str(step_number const &x,
666 size_t width = 0, size_t prec = 0);
667
669 static std::string to_str(real const &x,
670 size_t width = 0, size_t prec = 0);
671
673 static std::string to_str(rvector const &x,
674 size_t width = 0, size_t prec = 0);
675
677 static std::string to_str(quaternion const &x,
678 size_t width = 0, size_t prec = 0);
679
681 static std::string to_str(colvarvalue const &x,
682 size_t width = 0, size_t prec = 0);
683
685 static std::string to_str(vector1d<real> const &x,
686 size_t width = 0, size_t prec = 0);
687
689 static std::string to_str(matrix2d<real> const &x,
690 size_t width = 0, size_t prec = 0);
691
692
694 static std::string to_str(std::vector<int> const &x,
695 size_t width = 0, size_t prec = 0);
696
698 static std::string to_str(std::vector<size_t> const &x,
699 size_t width = 0, size_t prec = 0);
700
702 static std::string to_str(std::vector<long int> const &x,
703 size_t width = 0, size_t prec = 0);
704
706 static std::string to_str(std::vector<real> const &x,
707 size_t width = 0, size_t prec = 0);
708
710 static std::string to_str(std::vector<rvector> const &x,
711 size_t width = 0, size_t prec = 0);
712
714 static std::string to_str(std::vector<quaternion> const &x,
715 size_t width = 0, size_t prec = 0);
716
718 static std::string to_str(std::vector<colvarvalue> const &x,
719 size_t width = 0, size_t prec = 0);
720
722 static std::string to_str(std::vector<std::string> const &x,
723 size_t width = 0, size_t prec = 0);
724
725#if ( defined(COLVARS_CUDA) || defined(COLVARS_HIP) )
726 static std::string to_str(std::vector<rvector, colvars_gpu::CudaHostAllocator<rvector>> const &x,
727 size_t width = 0, size_t prec = 0);
728 static std::string to_str(std::vector<real, colvars_gpu::CudaHostAllocator<real>> const &x,
729 size_t width = 0, size_t prec = 0);
730#endif
731
732
734 static std::string wrap_string(std::string const &s,
735 size_t nchars);
736
737 // i/o constants
738
740 static constexpr size_t it_width = 12;
742 static constexpr size_t cv_prec = 14;
744 static constexpr size_t cv_width = 21;
746 static constexpr size_t en_prec = 14;
748 static constexpr size_t en_width = 21;
750 static constexpr const char line_marker[] =
751 "----------------------------------------------------------------------\n";
752
753 // proxy functions
754
756 real dt();
757
759 void request_total_force();
760
762 int cite_feature(std::string const &feature);
763
765 std::string feature_report(int flag = 0);
766
770 void log(std::string const &message, int min_log_level = 10);
771
774 static void log_static(std::string const &message) {
775 if (colvarmodule::main()) {
776 colvarmodule::main()->log(message);
777 } else {
778 std::printf("colvars: %s\n", message.c_str());
779 }
780 }
781
783 int error(std::string const &message, int code = -1);
784
788 static int error_static(std::string const &message, int code = -1) {
789 if (colvarmodule::main()) {
790 code = colvarmodule::main()->error(message, code);
791 } else {
792 std::cerr << "colvars: " << message << std::endl;
793 exit(-1);
794 }
795 return code;
796 }
797
798private:
799
801 int log_level_ = 10;
802
803public:
804
806 inline int log_level()
807 {
808 return log_level_;
809 }
810
812 inline int log_init_messages()
813 {
814 return 1;
815 }
816
818 inline int log_user_params()
819 {
820 return 2;
821 }
822
825 {
826 return 3;
827 }
828
830 inline int log_output_files()
831 {
832 return 4;
833 }
834
836 inline int log_input_files()
837 {
838 return 5;
839 }
840
842 std::vector<std::string> index_file_names;
843
845 std::vector<std::string> index_group_names;
846
848 std::vector<std::vector<int> *> index_groups;
849
851 int read_index_file(char const *filename);
852
854 int reset_index_groups();
855
864 int load_coords(char const *filename,
865 std::vector<rvector> *pos,
866 atom_group *atoms,
867 std::string const &pdb_field,
868 double pdb_field_value = 0.0);
869
871 int load_coords_xyz(char const *filename,
872 std::vector<rvector> *pos,
873 atom_group *atoms,
874 bool keep_open = false);
875
877 size_t cv_traj_freq = 0;
878
882 std::string restart_out_name;
883
886
887protected:
888
891
893 std::string cv_traj_name;
894
897
900
903
905 size_t depth_s;
906
908 std::vector<size_t> depth_v;
909
912
915
919
920public:
921
923 inline std::string restart_version() const
924 {
925 return restart_version_str;
926 }
927
929 inline int restart_version_number() const
930 {
931 return restart_version_int;
932 }
933
935 size_t & depth();
936
938 void increase_depth();
939
941 void decrease_depth();
942
943 inline bool scripted_forces()
944 {
945 return use_scripted_forces;
946 }
947
950
953
956
962 }
963
964 real get_max_gradient_error() {
965 return max_gradient_error;
966 }
967
970 colvarproxy *proxy = nullptr;
973
975 static colvarmodule *main();
976
977#if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
978 template <typename T>
980#else
981 template <typename T>
982 using allocator_type = std::allocator<T>;
983#endif
984 using ag_vector_real_t = std::vector<real, allocator_type<real>>;
985
986};
987
990
991
992std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
993std::istream & operator >> (std::istream &is, cvm::rvector &v);
994
995
996namespace {
997 constexpr int32_t COLVARS_OK = 0;
998 constexpr int32_t COLVARS_ERROR = 1;
999 constexpr int32_t COLVARS_NOT_IMPLEMENTED = (1<<1);
1000 constexpr int32_t COLVARS_INPUT_ERROR = (1<<2); // out of bounds or inconsistent input
1001 constexpr int32_t COLVARS_BUG_ERROR = (1<<3); // Inconsistent state indicating bug
1002 constexpr int32_t COLVARS_FILE_ERROR = (1<<4);
1003 constexpr int32_t COLVARS_MEMORY_ERROR = (1<<5);
1004 constexpr int32_t COLVARS_NO_SUCH_FRAME = (1<<6); // Cannot load the requested frame
1005}
1006
1007
1008#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:71
int cite_feature(std::string const &feature)
Track usage of the given Colvars feature.
Definition: colvarmodule.cpp:2712
static constexpr const char line_marker[]
Line separator in the log output.
Definition: colvarmodule.h:750
int log_input_files()
Level at which input-file operations (configuration, state) are logged.
Definition: colvarmodule.h:836
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:251
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:2387
std::ostream & write_state(std::ostream &os)
Write the state of the module to a formatted (text) file.
Definition: colvarmodule.cpp:2054
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:129
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:178
bool cv_traj_write_labels
Write labels at the next iteration.
Definition: colvarmodule.h:896
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:972
std::string cv_traj_name
Name of the trajectory file.
Definition: colvarmodule.h:893
static real logn(real const &x)
Definition: colvarmodule.h:230
std::vector< atom_group * > named_atom_groups
Array of named atom groups.
Definition: colvarmodule.h:335
std::ostream & write_traj(std::ostream &os)
Write in the trajectory file.
Definition: colvarmodule.cpp:2104
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:98
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:286
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:387
static real floor(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:135
int log_level()
Level of logging requested by the user.
Definition: colvarmodule.h:806
static void log_static(std::string const &message)
Definition: colvarmodule.h:774
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:911
std::vector< std::string > index_group_names
Names of groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:845
usage * usage_
Track usage of Colvars features.
Definition: colvarmodule.h:914
int log_default_params()
Level at which a keyword's default value is logged.
Definition: colvarmodule.h:824
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:923
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:1783
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:222
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:141
int residue_id
Residue identifier.
Definition: colvarmodule.h:247
std::vector< colvarbias * > biases_active_
Array of active collective variable biases.
Definition: colvarmodule.h:379
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:788
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:2717
std::vector< int > colvars_smp_items
Indexes of the items to calculate for each colvar.
Definition: colvarmodule.h:332
int backup_file(char const *filename)
Backup a file before writing it.
Definition: colvarmodule.cpp:1914
int calc()
Main worker function.
Definition: colvarmodule.cpp:928
int log_init_messages()
Level at which initialization messages are logged.
Definition: colvarmodule.h:812
static real cos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:165
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:466
step_number step_absolute()
Definition: colvarmodule.h:296
static constexpr size_t it_width
Number of characters to represent a time step.
Definition: colvarmodule.h:740
std::string config_string
Configuration string read so far by the module (includes comments)
Definition: colvarmodule.h:462
std::string default_input_state_file_
Default input state file; if given, it is read unless the MD engine provides it.
Definition: colvarmodule.h:525
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:848
static real tanh(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:216
int restart_version_number() const
Integer version of the most recent state file read.
Definition: colvarmodule.h:929
void * num_biases_types_used_
Pointer to a map counting how many biases of each type were used.
Definition: colvarmodule.h:376
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:842
int log_level_
Level of logging requested by the user.
Definition: colvarmodule.h:801
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:2500
int patch_version_int
Patch version number; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:90
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:1798
real total_bias_energy
Energy of built-in and scripted biases, summed per time-step.
Definition: colvarmodule.h:371
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:315
bool use_scripted_forces
Use scripted colvars forces?
Definition: colvarmodule.h:949
int log_output_files()
Level at which output-file operations are logged.
Definition: colvarmodule.h:830
std::istream & read_state(std::istream &is)
Read all objects' state fron a formatted (text) stream.
Definition: colvarmodule.cpp:1757
void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:2129
std::vector< unsigned char > input_state_buffer_
Internal state buffer, to be read as an unformatted stream.
Definition: colvarmodule.h:528
step_number step_relative()
Return the current step number from the beginning of this run.
Definition: colvarmodule.h:289
real rand_gaussian()
Pseudo-random number with Gaussian distribution.
Definition: colvarmodule.cpp:2512
colvarparse * parse
Configuration file parser object.
Definition: colvarmodule.h:890
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:877
size_t & depth()
Get the current object depth in the hierarchy.
Definition: colvarmodule.cpp:2165
real max_gradient_error
Definition: colvarmodule.h:918
static constexpr size_t en_width
Number of characters to represent the collective variables energy.
Definition: colvarmodule.h:748
bool scripting_after_biases
Wait for all biases before calculating scripted forces?
Definition: colvarmodule.h:952
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:880
step_number it
Current step number.
Definition: colvarmodule.h:284
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:2213
int errorCode
Definition: colvarmodule.h:268
std::vector< colvar * > colvars
Array of collective variables.
Definition: colvarmodule.h:323
static real atan2(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:210
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:746
void increase_depth()
Increase the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2151
colvarmodule()
Cannot initialize the main object without a proxy.
int write_output_files()
Write all other output files.
Definition: colvarmodule.cpp:1920
static constexpr size_t cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:742
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:153
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:104
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:2079
static real acos(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:194
static std::string wrap_string(std::string const &s, size_t nchars)
Reduce the number of characters in a string.
Definition: colvarmodule.cpp:2699
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:330
std::vector< colvar * > colvars_active
Array of collective variables.
Definition: colvarmodule.h:326
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:2347
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:882
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:1940
size_t depth_s
Counter for the current depth in the object hierarchy (useg e.g. in output)
Definition: colvarmodule.h:905
int log_user_params()
Level at which a keyword's user-provided value is logged.
Definition: colvarmodule.h:818
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:368
std::string restart_version_str
Version of the most recent state file read.
Definition: colvarmodule.h:899
int restart_version_int
Integer version of the most recent state file read.
Definition: colvarmodule.h:902
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:477
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:147
static constexpr size_t cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:744
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:2157
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:960
int reset_index_groups()
Clear the index groups loaded so far.
Definition: colvarmodule.cpp:2334
int print_total_forces_errning(bool warn_total_forces)
If needed (old restart file), print the warning that cannot be ignored.
Definition: colvarmodule.cpp:1890
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:2243
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:159
~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:2561
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:311
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:2069
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: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:306
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:908
colvarproxy * proxy
Pointer to the proxy object, used to retrieve atomic data from the hosting program.
Definition: colvarmodule.h:970
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:2506
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: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:989