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#include "colvar_gpu_calc.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 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
119 static inline real pow(real const &x, real const &y)
120 {
121 return ::pow(static_cast<double>(x), static_cast<double>(y));
122 }
123
125 static inline real floor(real const &x)
126 {
127 return ::floor(static_cast<double>(x));
128 }
129
131 static inline real ceil(real const &x)
132 {
133 return ::ceil(static_cast<double>(x));
134 }
135
137 static inline real fabs(real const &x)
138 {
139 return ::fabs(static_cast<double>(x));
140 }
141
143 static inline real sqrt(real const &x)
144 {
145 return ::sqrt(static_cast<double>(x));
146 }
147
149 static inline real sin(real const &x)
150 {
151 return ::sin(static_cast<double>(x));
152 }
153
155 static inline real cos(real const &x)
156 {
157 return ::cos(static_cast<double>(x));
158 }
159
160#ifndef PI
161#define PI 3.14159265358979323846
162#endif
163#ifndef PI_2
164#define PI_2 1.57079632679489661923
165#endif
166
168static inline real asin(real const &x)
169{
170#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
171 if (x <= -1.0) {
172 return -PI_2;
173 } else if (x >= 1.0) {
174 return PI_2;
175 } else {
176 return ::asin(static_cast<double>(x));
177 }
178#else
179 return ::asin(static_cast<double>(x));
180#endif
181}
182
184static inline real acos(real const &x)
185{
186#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
187 if (x <= -1.0) {
188 return PI;
189 } else if (x >= 1.0) {
190 return 0.0;
191 } else {
192 return ::acos(static_cast<double>(x));
193 }
194#else
195 return ::acos(static_cast<double>(x));
196#endif
197}
198
200 static inline real atan2(real const &x, real const &y)
201 {
202 return ::atan2(static_cast<double>(x), static_cast<double>(y));
203 }
204
206 static inline real tanh(real const &x)
207 {
208 return ::tanh(static_cast<double>(x));
209 }
210
212 static inline real exp(real const &x)
213 {
214 return ::exp(static_cast<double>(x));
215 }
216
220 static inline real logn(real const &x)
221 {
222 return ::log(static_cast<double>(x));
223 }
224
225 // Forward declarations
226 class rvector;
227 template <class T> class vector1d;
228 template <class T> class matrix2d;
229 class quaternion;
230 class rotation;
231
232 class usage;
233 class memory_stream;
234
236 typedef int residue_id;
237
241
243 class rmatrix;
244
245 // NOTE: Just here for ensuring the compilation of GROMACS with Colvars
246 struct atom;
247 // class atom_group_base;
248 class atom_group;
249 // class atom_group_gpu;
250 // typedef std::vector<atom>::iterator atom_iter;
251 // typedef std::vector<atom>::const_iterator atom_const_iter;
252
255private:
256
257 int errorCode = 0;
258
259public:
260
261 void set_error_bits(int code);
262
263 bool get_error_bit(int code);
264
265 inline int get_error()
266 {
267 return errorCode;
268 }
269
270 void clear_error();
271
276
279 {
280 return it - it_restart;
281 }
282
286 {
287 return it;
288 }
289
290 bool binary_restart;
291
296
297private:
298
300 std::string cvm_output_prefix;
301
302public:
304 inline std::string &output_prefix()
305 {
306 return this->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 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 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 int backup_file(char const *filename);
572
574 int write_restart_string(std::string &output);
575
577 colvarbias * bias_by_name(std::string const &name);
578
580 colvar * colvar_by_name(std::string const &name);
581
583 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
620 // In a first phase, keep to_str() static
621
623 static std::string to_str(char const *s);
624
626 static std::string to_str(const void* ptr);
627
629 static std::string to_str(std::string const &s);
630
632 static std::string to_str(bool x);
633
635 static std::string to_str(int const &x,
636 size_t width = 0, size_t prec = 0);
637
639 static std::string to_str(size_t const &x,
640 size_t width = 0, size_t prec = 0);
641
643 static std::string to_str(long int const &x,
644 size_t width = 0, size_t prec = 0);
645
647 static std::string to_str(step_number const &x,
648 size_t width = 0, size_t prec = 0);
649
651 static std::string to_str(real const &x,
652 size_t width = 0, size_t prec = 0);
653
655 static std::string to_str(rvector const &x,
656 size_t width = 0, size_t prec = 0);
657
659 static std::string to_str(quaternion const &x,
660 size_t width = 0, size_t prec = 0);
661
663 static std::string to_str(colvarvalue const &x,
664 size_t width = 0, size_t prec = 0);
665
667 static std::string to_str(vector1d<real> const &x,
668 size_t width = 0, size_t prec = 0);
669
671 static std::string to_str(matrix2d<real> const &x,
672 size_t width = 0, size_t prec = 0);
673
674
676 static std::string to_str(std::vector<int> const &x,
677 size_t width = 0, size_t prec = 0);
678
680 static std::string to_str(std::vector<size_t> const &x,
681 size_t width = 0, size_t prec = 0);
682
684 static std::string to_str(std::vector<long int> const &x,
685 size_t width = 0, size_t prec = 0);
686
688 static std::string to_str(std::vector<real> const &x,
689 size_t width = 0, size_t prec = 0);
690
692 static std::string to_str(std::vector<rvector> const &x,
693 size_t width = 0, size_t prec = 0);
694
696 static std::string to_str(std::vector<quaternion> const &x,
697 size_t width = 0, size_t prec = 0);
698
700 static std::string to_str(std::vector<colvarvalue> const &x,
701 size_t width = 0, size_t prec = 0);
702
704 static std::string to_str(std::vector<std::string> const &x,
705 size_t width = 0, size_t prec = 0);
706
707#if ( defined(COLVARS_CUDA) || defined(COLVARS_HIP) )
708 static std::string to_str(std::vector<rvector, colvars_gpu::CudaHostAllocator<rvector>> const &x,
709 size_t width = 0, size_t prec = 0);
710 static std::string to_str(std::vector<real, colvars_gpu::CudaHostAllocator<real>> const &x,
711 size_t width = 0, size_t prec = 0);
712#endif
713
714
716 static std::string wrap_string(std::string const &s,
717 size_t nchars);
718
719 // i/o constants
720
722 static constexpr size_t it_width = 12;
724 static constexpr size_t cv_prec = 14;
726 static constexpr size_t cv_width = 21;
728 static constexpr size_t en_prec = 14;
730 static constexpr size_t en_width = 21;
732 static constexpr const char line_marker[] =
733 "----------------------------------------------------------------------\n";
734
735 // proxy functions
736
738 real dt();
739
741 void request_total_force();
742
744 int cite_feature(std::string const &feature);
745
747 std::string feature_report(int flag = 0);
748
752 void log(std::string const &message, int min_log_level = 10);
753
756 static void log_static(std::string const &message) {
757 if (colvarmodule::main()) {
758 colvarmodule::main()->log(message);
759 } else {
760 std::printf("colvars: %s\n", message.c_str());
761 }
762 }
763
765 int error(std::string const &message, int code = -1);
766
770 static int error_static(std::string const &message, int code = -1) {
771 if (colvarmodule::main()) {
772 code = colvarmodule::main()->error(message, code);
773 } else {
774 std::cerr << "colvars: " << message << std::endl;
775 exit(-1);
776 }
777 return code;
778 }
779
780private:
781
783 int log_level_ = 10;
784
785public:
786
788 inline int log_level()
789 {
790 return log_level_;
791 }
792
794 inline int log_init_messages()
795 {
796 return 1;
797 }
798
800 inline int log_user_params()
801 {
802 return 2;
803 }
804
807 {
808 return 3;
809 }
810
812 inline int log_output_files()
813 {
814 return 4;
815 }
816
818 inline int log_input_files()
819 {
820 return 5;
821 }
822
825 rvector position_distance(atom_pos const &pos1,
826 atom_pos const &pos2);
827
829 std::vector<std::string> index_file_names;
830
832 std::vector<std::string> index_group_names;
833
835 std::vector<std::vector<int> *> index_groups;
836
838 int read_index_file(char const *filename);
839
841 int reset_index_groups();
842
851 int load_coords(char const *filename,
852 std::vector<rvector> *pos,
853 atom_group *atoms,
854 std::string const &pdb_field,
855 double pdb_field_value = 0.0);
856
858 int load_coords_xyz(char const *filename,
859 std::vector<rvector> *pos,
860 atom_group *atoms,
861 bool keep_open = false);
862
864 size_t cv_traj_freq = 0;
865
869 std::string restart_out_name;
870
873
874protected:
875
878
880 std::string cv_traj_name;
881
884
887
890
892 size_t depth_s;
893
895 std::vector<size_t> depth_v;
896
899
902
906
907public:
908
910 inline std::string restart_version() const
911 {
912 return restart_version_str;
913 }
914
916 inline int restart_version_number() const
917 {
918 return restart_version_int;
919 }
920
922 size_t & depth();
923
925 void increase_depth();
926
928 void decrease_depth();
929
930 inline bool scripted_forces()
931 {
932 return use_scripted_forces;
933 }
934
937
940
943
949 }
950
951 real get_max_gradient_error() {
952 return max_gradient_error;
953 }
954
957 colvarproxy *proxy = nullptr;
960
962 static colvarmodule *main();
963
964#if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
965 template <typename T>
967#else
968 template <typename T>
969 using allocator_type = std::allocator<T>;
970#endif
971 using ag_vector_real_t = std::vector<real, allocator_type<real>>;
972
973#if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
974 std::unique_ptr<colvars_gpu::colvarmodule_gpu_calc> gpu_calc;
975#endif
976};
977
980
981
982std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
983std::istream & operator >> (std::istream &is, cvm::rvector &v);
984
985
986namespace {
987 constexpr int32_t COLVARS_OK = 0;
988 constexpr int32_t COLVARS_ERROR = 1;
989 constexpr int32_t COLVARS_NOT_IMPLEMENTED = (1<<1);
990 constexpr int32_t COLVARS_INPUT_ERROR = (1<<2); // out of bounds or inconsistent input
991 constexpr int32_t COLVARS_BUG_ERROR = (1<<3); // Inconsistent state indicating bug
992 constexpr int32_t COLVARS_FILE_ERROR = (1<<4);
993 constexpr int32_t COLVARS_MEMORY_ERROR = (1<<5);
994 constexpr int32_t COLVARS_NO_SUCH_FRAME = (1<<6); // Cannot load the requested frame
995}
996
997
998#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:2692
static constexpr const char line_marker[]
Line separator in the log output.
Definition: colvarmodule.h:732
int log_input_files()
Level at which input-file operations (configuration, state) are logged.
Definition: colvarmodule.h:818
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:240
int write_traj_files()
Write all trajectory files.
Definition: colvarmodule.cpp:1316
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:2360
std::ostream & write_state(std::ostream &os)
Write the state of the module to a formatted (text) file.
Definition: colvarmodule.cpp:2027
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:119
size_t num_biases_feature(int feature_id) const
Return how many biases have this feature enabled.
Definition: colvarmodule.cpp:785
static real asin(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:168
bool cv_traj_write_labels
Write labels at the next iteration.
Definition: colvarmodule.h:883
static std::string to_str(std::vector< quaternion > const &x, size_t width=0, size_t prec=0)
Convert to string for output purposes.
std::vector< std::string > const time_dependent_biases() const
Definition: colvarmodule.cpp:813
static colvarproxy * proxy_static
Temporary static pointer to unique proxy object.
Definition: colvarmodule.h:959
std::string cv_traj_name
Name of the trajectory file.
Definition: colvarmodule.h:880
static real logn(real const &x)
Definition: colvarmodule.h:220
std::ostream & write_traj(std::ostream &os)
Write in the trajectory file.
Definition: colvarmodule.cpp:2077
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:99
step_number it_restart
Starting step number for this run.
Definition: colvarmodule.h:275
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:297
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:125
int log_level()
Level of logging requested by the user.
Definition: colvarmodule.h:788
static void log_static(std::string const &message)
Definition: colvarmodule.h:756
size_t size() const
How many objects (variables and biases) are configured yet?
Definition: colvarmodule.cpp:255
int xyz_reader_use_count
Track how many times the XYZ reader has been used.
Definition: colvarmodule.h:898
std::vector< std::string > index_group_names
Names of groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:832
usage * usage_
Track usage of Colvars features.
Definition: colvarmodule.h:901
int log_default_params()
Level at which a keyword's default value is logged.
Definition: colvarmodule.h:806
int update_colvar_forces()
Integrate bias and restraint forces, send colvar forces to atoms.
Definition: colvarmodule.cpp:1190
std::string restart_version() const
Version of the most recent state file read.
Definition: colvarmodule.h:910
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:336
int write_restart_file(std::string const &out_name)
Write a state file useful to resume the simulation.
Definition: colvarmodule.cpp:1275
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:261
static real exp(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:212
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:229
static real ceil(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:131
int residue_id
Residue identifier.
Definition: colvarmodule.h:236
std::vector< colvarbias * > biases_active_
Array of active collective variable biases.
Definition: colvarmodule.h:368
int end_of_step()
Carry out operations needed before next step is run.
Definition: colvarmodule.cpp:1389
static int error_static(std::string const &message, int code=-1)
Definition: colvarmodule.h:770
size_t num_biases() const
Return how many biases are defined.
Definition: colvarmodule.cpp:779
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:634
std::string feature_report(int flag=0)
Report usage of the Colvars features.
Definition: colvarmodule.cpp:2697
std::vector< int > colvars_smp_items
Indexes of the items to calculate for each colvar.
Definition: colvarmodule.h:321
int backup_file(char const *filename)
Backup a file before writing it.
Definition: colvarmodule.cpp:1887
int calc()
Main worker function.
Definition: colvarmodule.cpp:943
int log_init_messages()
Level at which initialization messages are logged.
Definition: colvarmodule.h:794
static real cos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:155
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:451
step_number step_absolute()
Definition: colvarmodule.h:285
static constexpr size_t it_width
Number of characters to represent a time step.
Definition: colvarmodule.h:722
static real integer_power(real const &x, int const n)
Override the STL pow() with a product for n integer.
Definition: colvarmodule.h:105
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:268
std::vector< std::vector< int > * > index_groups
Groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:835
static real tanh(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:206
int restart_version_number() const
Integer version of the most recent state file read.
Definition: colvarmodule.h:916
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:866
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:829
std::vector< std::string > index_file_names
Names of .ndx files that have been loaded.
Definition: colvarmodule.h:829
int log_level_
Level of logging requested by the user.
Definition: colvarmodule.h:783
std::vector< colvar * > * variables_active()
Collective variables with the active flag on.
Definition: colvarmodule.cpp:217
std::vector< colvarbias * > * biases_active()
Array of active collective variable biases.
Definition: colvarmodule.cpp:249
real dt()
Time step of MD integrator (fs)
Definition: colvarmodule.cpp:2473
int patch_version_int
Patch version number; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:91
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:398
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
size_t num_biases_type(std::string const &type) const
Return how many biases of this type are defined.
Definition: colvarmodule.cpp:799
std::string & output_prefix()
Accessor for the above.
Definition: colvarmodule.h:304
bool use_scripted_forces
Use scripted colvars forces?
Definition: colvarmodule.h:936
int log_output_files()
Level at which output-file operations are logged.
Definition: colvarmodule.h:812
std::istream & read_state(std::istream &is)
Read all objects' state fron a formatted (text) stream.
Definition: colvarmodule.cpp:1730
void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:2102
std::vector< unsigned char > input_state_buffer_
Internal state buffer, to be read as an unformatted stream.
Definition: colvarmodule.h:513
step_number step_relative()
Return the current step number from the beginning of this run.
Definition: colvarmodule.h:278
real rand_gaussian()
Pseudo-random number with Gaussian distribution.
Definition: colvarmodule.cpp:2492
colvarparse * parse
Configuration file parser object.
Definition: colvarmodule.h:877
int calc_component_smp(int i)
Calculate the value of the specified component (to be called in a SMP loop)
Definition: colvarmodule.cpp:235
size_t cv_traj_freq
Frequency for collective variables trajectory output.
Definition: colvarmodule.h:864
size_t & depth()
Get the current object depth in the hierarchy.
Definition: colvarmodule.cpp:2138
real max_gradient_error
Definition: colvarmodule.h:905
static constexpr size_t en_width
Number of characters to represent the collective variables energy.
Definition: colvarmodule.h:730
bool scripting_after_biases
Wait for all biases before calculating scripted forces?
Definition: colvarmodule.h:939
std::string const & get_config() const
Get the configuration string read so far (includes comments)
Definition: colvarmodule.cpp:392
size_t restart_out_freq
Frequency for saving output restarts.
Definition: colvarmodule.h:867
step_number it
Current step number.
Definition: colvarmodule.h:273
int parse_colvars(std::string const &conf)
Parse and initialize collective variables.
Definition: colvarmodule.cpp:585
int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2186
int errorCode
Definition: colvarmodule.h:257
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:200
std::vector< colvar * > * variables_active_smp()
Definition: colvarmodule.cpp:223
static constexpr size_t en_prec
Number of digits to represent the collective variables energy.
Definition: colvarmodule.h:728
std::vector< atom_group * > named_atom_groups_soa
Array of named atom groups.
Definition: colvarmodule.h:324
void increase_depth()
Increase the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2124
colvarmodule()
Cannot initialize the main object without a proxy.
int write_output_files()
Write all other output files.
Definition: colvarmodule.cpp:1893
static constexpr size_t cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:724
static colvarmodule * main()
Access the main instance of the Colvars module.
Definition: colvarmodule.cpp:205
int parse_biases_type(std::string const &conf, char const *keyword)
Parse and initialize collective variable biases of a specific type.
Definition: colvarmodule.cpp:648
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:143
std::string version() const
Get the version string (YYYY-MM-DD format)
Definition: colvarmodule.cpp:38
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:2052
static real acos(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:184
static std::string wrap_string(std::string const &s, size_t nchars)
Reduce the number of characters in a string.
Definition: colvarmodule.cpp:2679
int reset()
Actual function called by the destructor.
Definition: colvarmodule.cpp:1464
int calc_biases()
Calculate biases.
Definition: colvarmodule.cpp:1116
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:1361
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:2320
std::string read_colvar(std::string const &name)
Read a colvar value.
Definition: colvarmodule.cpp:910
size_t num_variables() const
Return how many variables are defined.
Definition: colvarmodule.cpp:759
std::string restart_out_name
Output restart file name.
Definition: colvarmodule.h:869
int version_number() const
Get the version number (higher = more recent)
Definition: colvarmodule.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:1913
size_t depth_s
Counter for the current depth in the object hierarchy (useg e.g. in output)
Definition: colvarmodule.h:892
static bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:376
int log_user_params()
Level at which a keyword's user-provided value is logged.
Definition: colvarmodule.h:800
int change_configuration(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:892
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:886
int restart_version_int
Integer version of the most recent state file read.
Definition: colvarmodule.h:889
int calc_scripted_forces()
Calculate the energy and forces of scripted biases.
Definition: colvarmodule.cpp:1257
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:1304
static std::istream & getline(std::istream &is, std::string &line)
Definition: colvarmodule.cpp:316
int calc_colvars()
Calculate collective variables.
Definition: colvarmodule.cpp:1011
static real fabs(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:137
static constexpr size_t cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:726
std::vector< colvar * > * variables()
Array of collective variables.
Definition: colvarmodule.cpp:211
void decrease_depth()
Decrease the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2130
int update_engine_parameters()
Definition: colvarmodule.cpp:1416
real energy_difference(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:926
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:947
int reset_index_groups()
Clear the index groups loaded so far.
Definition: colvarmodule.cpp:2307
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.
int read_index_file(char const *filename)
Read a Gromacs .ndx file.
Definition: colvarmodule.cpp:2216
size_t num_variables_feature(int feature_id) const
Return how many variables have this feature enabled.
Definition: colvarmodule.cpp:765
static real sin(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:149
~colvarmodule()
Destructor.
Definition: colvarmodule.cpp:1435
rvector position_distance(atom_pos const &pos1, atom_pos const &pos2)
Get the distance between two atomic positions with pbcs handled correctly.
Definition: colvarmodule.cpp:2485
void config_changed()
Signals to the module object that the configuration has changed.
Definition: colvarmodule.cpp:405
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2541
colvar * colvar_by_name(std::string const &name)
Look up a colvar by name; returns NULL if not found.
Definition: colvarmodule.cpp:854
colvarbias * bias_by_name(std::string const &name)
Look up a bias by name; returns NULL if not found.
Definition: colvarmodule.cpp:841
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:300
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:692
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:2042
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:411
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:295
int run_tcl_script(std::string const &filename)
Run provided Tcl script.
Definition: colvarmodule.cpp:573
int close_traj_file()
Close it (note: currently unused)
std::vector< size_t > depth_v
Thread-specific depth.
Definition: colvarmodule.h:895
colvarproxy * proxy
Pointer to the proxy object, used to retrieve atomic data from the hosting program.
Definition: colvarmodule.h:957
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:2479
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:979