Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvarmodule.h
Go to the documentation of this file.
1// -*- c++ -*-
2
3// This file is part of the Collective Variables module (Colvars).
4// The original version of Colvars and its updates are located at:
5// https://github.com/Colvars/colvars
6// Please update all Colvars source files before making any changes.
7// If you wish to distribute your changes, please submit them to the
8// Colvars repository at GitHub.
9
10#ifndef COLVARMODULE_H
11#define COLVARMODULE_H
12
13#include <cstdint>
14
15#ifndef COLVARS_DEBUG
16#define COLVARS_DEBUG false
17#endif
18
19#if defined(__FAST_MATH__)
20// NOTE: This is used for fixing https://github.com/Colvars/colvars/issues/767
21#define COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
22#endif
23
24#define COLVARS_USE_SOA
25
42
43#include <cmath>
44#include <iosfwd>
45#include <string>
46#include <vector>
47
48#if defined(COLVARS_CUDA)
49#include <cuda_runtime.h>
50#endif
51
52#if defined(COLVARS_HIP)
53#include <hip/hip_runtime.h>
54#define cudaHostAllocMapped hipHostMallocMapped
55#define cudaHostAlloc hipHostMalloc
56#define cudaFreeHost hipHostFree
57#define cudaSuccess hipSuccess
58#endif
59
60class colvarparse;
61class colvar;
62class colvarbias;
63class colvarproxy;
64class colvarvalue;
65
66
77
78public:
79
81 std::string version() const;
82
84 int version_number() const;
85
87 int patch_version_number() const;
88
89#if ( defined(COLVARS_CUDA) || defined(COLVARS_HIP) )
90 template <typename T>
91 class CudaHostAllocator {
92 public:
93 using value_type = T;
94
95 CudaHostAllocator() = default;
96
97 template<typename U>
98 constexpr CudaHostAllocator(const CudaHostAllocator<U>&) noexcept {}
99
100 friend bool operator==(const CudaHostAllocator&, const CudaHostAllocator&) { return true; }
101 friend bool operator!=(const CudaHostAllocator&, const CudaHostAllocator&) { return false; }
102
103 T* allocate(size_t n) {
104 T* ptr;
105 if (cudaHostAlloc(&ptr, n * sizeof(T), cudaHostAllocMapped) != cudaSuccess) {
106 throw std::bad_alloc();
107 }
108 return ptr;
109 }
110 void deallocate(T* ptr, size_t n) noexcept {
111 cudaFreeHost(ptr);
112 }
113 template<typename U, typename... Args>
114 void construct(U* p, Args&&... args) {
115 new(p) U(std::forward<Args>(args)...);
116 }
117
118 template<typename U>
119 void destroy(U* p) noexcept {
120 p->~U();
121 }
122 };
123#endif
124
125private:
126
128 int version_int = 0;
129
132
133public:
134
136 typedef long long step_number;
137
139 typedef double real;
140
141
142 // Math functions
143
145 static inline real integer_power(real const &x, int const n)
146 {
147 // Original code: math_special.h in LAMMPS
148 double yy, ww;
149 if (x == 0.0) return 0.0;
150 int nn = (n > 0) ? n : -n;
151 ww = x;
152 for (yy = 1.0; nn != 0; nn >>= 1, ww *=ww) {
153 if (nn & 1) yy *= ww;
154 }
155 return (n > 0) ? yy : 1.0/yy;
156 }
157
159 static inline real pow(real const &x, real const &y)
160 {
161 return ::pow(static_cast<double>(x), static_cast<double>(y));
162 }
163
165 static inline real floor(real const &x)
166 {
167 return ::floor(static_cast<double>(x));
168 }
169
171 static inline real fabs(real const &x)
172 {
173 return ::fabs(static_cast<double>(x));
174 }
175
177 static inline real sqrt(real const &x)
178 {
179 return ::sqrt(static_cast<double>(x));
180 }
181
183 static inline real sin(real const &x)
184 {
185 return ::sin(static_cast<double>(x));
186 }
187
189 static inline real cos(real const &x)
190 {
191 return ::cos(static_cast<double>(x));
192 }
193
194#ifndef PI
195#define PI 3.14159265358979323846
196#endif
197#ifndef PI_2
198#define PI_2 1.57079632679489661923
199#endif
200
202static inline real asin(real const &x)
203{
204#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
205 if (x <= -1.0) {
206 return -PI_2;
207 } else if (x >= 1.0) {
208 return PI_2;
209 } else {
210 return ::asin(static_cast<double>(x));
211 }
212#else
213 return ::asin(static_cast<double>(x));
214#endif
215}
216
218static inline real acos(real const &x)
219{
220#ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC
221 if (x <= -1.0) {
222 return PI;
223 } else if (x >= 1.0) {
224 return 0.0;
225 } else {
226 return ::acos(static_cast<double>(x));
227 }
228#else
229 return ::acos(static_cast<double>(x));
230#endif
231}
232
234 static inline real atan2(real const &x, real const &y)
235 {
236 return ::atan2(static_cast<double>(x), static_cast<double>(y));
237 }
238
240 static inline real exp(real const &x)
241 {
242 return ::exp(static_cast<double>(x));
243 }
244
248 static inline real logn(real const &x)
249 {
250 return ::log(static_cast<double>(x));
251 }
252
253 // Forward declarations
254 class rvector;
255 template <class T> class vector1d;
256 template <class T> class matrix2d;
257 class quaternion;
258 class rotation;
259
260 class usage;
261 class memory_stream;
262
264 typedef int residue_id;
265
269
271 class rmatrix;
272
273 // allow these classes to access protected data
274 class atom;
275 class atom_group;
276 typedef std::vector<atom>::iterator atom_iter;
277 typedef std::vector<atom>::const_iterator atom_const_iter;
278
281private:
282
283 static int errorCode;
284
285public:
286
287 static void set_error_bits(int code);
288
289 static bool get_error_bit(int code);
290
291 static inline int get_error()
292 {
293 return errorCode;
294 }
295
296 static void clear_error();
297
302
305 {
306 return it - it_restart;
307 }
308
312 {
313 return it;
314 }
315
316 bool binary_restart;
317
322
323private:
324
326 std::string cvm_output_prefix;
327
328public:
330 static inline std::string &output_prefix()
331 {
333 return cv->cvm_output_prefix;
334 }
335
336private:
337
339 std::vector<colvar *> colvars;
340
342 std::vector<colvar *> colvars_active;
343
346 std::vector<colvar *> colvars_smp;
348 std::vector<int> colvars_smp_items;
349
351 std::vector<atom_group *> named_atom_groups_soa;
352
353public:
354
355 void register_named_atom_group_soa(atom_group *ag);
356 void unregister_named_atom_group_soa(atom_group *ag);
357
359 std::vector<colvar *> *variables();
360
361 /* TODO: implement named CVCs
363 static std::vector<cvc *> cvcs;
365 inline void register_cvc(cvc *p) {
366 cvcs.push_back(p);
367 }
368 */
369
371 std::vector<colvar *> *variables_active();
372
375 std::vector<colvar *> *variables_active_smp();
376
378 std::vector<int> *variables_active_smp_items();
379
381 int calc_component_smp(int i);
382
384 std::vector<colvarbias *> biases;
385
388
389private:
390
393
395 std::vector<colvarbias *> biases_active_;
396
397public:
398
400 std::vector<colvarbias *> *biases_active();
401
403 static inline bool debug()
404 {
405 return COLVARS_DEBUG;
406 }
407
409 size_t size() const;
410
414
415private:
416
419
420public:
421
424
427
429 int reset();
430
433 int read_config_file(char const *config_file_name);
434
437 int read_config_string(std::string const &conf);
438
440 int parse_config(std::string &conf);
441
443 std::string const & get_config() const;
444
445 // Parse functions (setup internal data based on a string)
446
449 static std::istream & getline(std::istream &is, std::string &line);
450
452 int parse_global_params(std::string const &conf);
453
455 int parse_colvars(std::string const &conf);
456
458 int run_tcl_script(std::string const &filename);
459
461 int parse_biases(std::string const &conf);
462
466 int append_new_config(std::string const &conf);
467
469 void config_changed();
470
471private:
472
474 std::string config_string;
475
478 std::string extra_conf;
479
481 template <class bias_type>
482 int parse_biases_type(std::string const &conf, char const *keyword);
483
486 bool check_new_bias(std::string &conf, char const *key);
487
489 std::string source_Tcl_script;
490
491public:
492
494 size_t num_variables() const;
495
497 size_t num_variables_feature(int feature_id) const;
498
500 size_t num_biases() const;
501
503 size_t num_biases_feature(int feature_id) const;
504
506 size_t num_biases_type(std::string const &type) const;
507
510 std::vector<std::string> const time_dependent_biases() const;
511
512private:
514 int catch_input_errors(int result);
515
516public:
517
518 // "Setup" functions (change internal data based on related data
519 // from the proxy that may change during program execution)
520 // No additional parsing is done within these functions
521
525
527 int setup_input();
528
530 int setup_output();
531
532private:
533
534 template <typename IST> IST & read_state_template_(IST &is);
535
538
540 std::vector<unsigned char> input_state_buffer_;
541
542public:
543
545 std::istream & read_state(std::istream &is);
546
548 memory_stream & read_state(memory_stream &is);
549
551 int set_input_state_buffer(size_t n, unsigned char *buf);
552
554 int set_input_state_buffer(std::vector<unsigned char> &buf);
555
557 std::istream & read_objects_state(std::istream &is);
558
560 memory_stream & read_objects_state(memory_stream &is);
561
563 int print_total_forces_errning(bool warn_total_forces);
564
565private:
566 template <typename OST> OST &write_state_template_(OST &os);
567
568public:
569
571 std::ostream & write_state(std::ostream &os);
572
574 memory_stream & write_state(memory_stream &os);
575
577 int write_state_buffer(std::vector<unsigned char> &buffer);
578
580 static std::string state_file_prefix(char const *filename);
581
583 int open_traj_file(std::string const &file_name);
587 std::ostream & write_traj(std::ostream &os);
589 std::ostream & write_traj_label(std::ostream &os);
590
592 int write_traj_files();
594 int write_restart_file(std::string const &out_name);
596 int write_output_files();
598 static int backup_file(char const *filename);
599
601 int write_restart_string(std::string &output);
602
604 static colvarbias * bias_by_name(std::string const &name);
605
607 static colvar * colvar_by_name(std::string const &name);
608
610 static atom_group * atom_group_soa_by_name(std::string const& name);
611
614 int change_configuration(std::string const &bias_name, std::string const &conf);
615
617 std::string read_colvar(std::string const &name);
618
621 real energy_difference(std::string const &bias_name, std::string const &conf);
622
624 int calc();
625
627 int calc_colvars();
628
630 int calc_biases();
631
634
636 int analyze();
637
639 int end_of_step();
640
643 int read_traj(char const *traj_filename,
644 long traj_read_begin,
645 long traj_read_end);
646
648 static std::string to_str(char const *s);
649
651 static std::string to_str(std::string const &s);
652
654 static std::string to_str(bool x);
655
657 static std::string to_str(int const &x,
658 size_t width = 0, size_t prec = 0);
659
661 static std::string to_str(size_t const &x,
662 size_t width = 0, size_t prec = 0);
663
665 static std::string to_str(long int const &x,
666 size_t width = 0, size_t prec = 0);
667
669 static std::string to_str(step_number const &x,
670 size_t width = 0, size_t prec = 0);
671
673 static std::string to_str(real const &x,
674 size_t width = 0, size_t prec = 0);
675
677 static std::string to_str(rvector const &x,
678 size_t width = 0, size_t prec = 0);
679
681 static std::string to_str(quaternion const &x,
682 size_t width = 0, size_t prec = 0);
683
685 static std::string to_str(colvarvalue const &x,
686 size_t width = 0, size_t prec = 0);
687
689 static std::string to_str(vector1d<real> const &x,
690 size_t width = 0, size_t prec = 0);
691
693 static std::string to_str(matrix2d<real> const &x,
694 size_t width = 0, size_t prec = 0);
695
696
698 static std::string to_str(std::vector<int> const &x,
699 size_t width = 0, size_t prec = 0);
700
702 static std::string to_str(std::vector<size_t> const &x,
703 size_t width = 0, size_t prec = 0);
704
706 static std::string to_str(std::vector<long int> const &x,
707 size_t width = 0, size_t prec = 0);
708
710 static std::string to_str(std::vector<real> const &x,
711 size_t width = 0, size_t prec = 0);
712
714 static std::string to_str(std::vector<rvector> const &x,
715 size_t width = 0, size_t prec = 0);
716
718 static std::string to_str(std::vector<quaternion> const &x,
719 size_t width = 0, size_t prec = 0);
720
722 static std::string to_str(std::vector<colvarvalue> const &x,
723 size_t width = 0, size_t prec = 0);
724
726 static std::string to_str(std::vector<std::string> const &x,
727 size_t width = 0, size_t prec = 0);
728
729#if ( defined(COLVARS_CUDA) || defined(COLVARS_HIP) )
730 static std::string to_str(std::vector<rvector, CudaHostAllocator<rvector>> const &x,
731 size_t width = 0, size_t prec = 0);
732 static std::string to_str(std::vector<real, CudaHostAllocator<real>> const &x,
733 size_t width = 0, size_t prec = 0);
734#endif
735
736
738 static std::string wrap_string(std::string const &s,
739 size_t nchars);
740
742 static size_t const it_width;
744 static size_t const cv_prec;
746 static size_t const cv_width;
748 static size_t const en_prec;
750 static size_t const en_width;
752 static const char * const line_marker;
753
754
755 // proxy functions
756
758 static real dt();
759
761 static void request_total_force();
762
764 int cite_feature(std::string const &feature);
765
767 std::string feature_report(int flag = 0);
768
772 static void log(std::string const &message, int min_log_level = 10);
773
775 static int error(std::string const &message, int code = -1);
776
777private:
778
780 static int log_level_;
781
782public:
783
785 static inline int log_level()
786 {
787 return log_level_;
788 }
789
791 static inline int log_init_messages()
792 {
793 return 1;
794 }
795
797 static inline int log_user_params()
798 {
799 return 2;
800 }
801
803 static inline int log_default_params()
804 {
805 return 3;
806 }
807
809 static inline int log_output_files()
810 {
811 return 4;
812 }
813
815 static inline int log_input_files()
816 {
817 return 5;
818 }
819
823 atom_pos const &pos2);
824
826 std::vector<std::string> index_file_names;
827
829 std::vector<std::string> index_group_names;
830
832 std::vector<std::vector<int> *> index_groups;
833
835 int read_index_file(char const *filename);
836
838 int reset_index_groups();
839
848 static int load_coords(char const *filename,
849 std::vector<rvector> *pos,
850 atom_group *atoms,
851 std::string const &pdb_field,
852 double pdb_field_value = 0.0);
853
855 int load_coords_xyz(char const *filename,
856 std::vector<rvector> *pos,
857 atom_group *atoms,
858 bool keep_open = false);
859
861 static size_t cv_traj_freq;
862
864 static size_t restart_out_freq;
866 std::string restart_out_name;
867
870
871protected:
872
875
877 std::string cv_traj_name;
878
881
884
887
889 size_t depth_s;
890
892 std::vector<size_t> depth_v;
893
896
899
903
904public:
905
907 inline std::string restart_version() const
908 {
909 return restart_version_str;
910 }
911
913 inline int restart_version_number() const
914 {
915 return restart_version_int;
916 }
917
919 static size_t & depth();
920
922 static void increase_depth();
923
925 static void decrease_depth();
926
927 static inline bool scripted_forces()
928 {
929 return use_scripted_forces;
930 }
931
934
937
940
946 }
947
948 real get_max_gradient_error() {
949 return max_gradient_error;
950 }
951
956
958 static colvarmodule *main();
959
960};
961
962
965
966
967std::ostream & operator << (std::ostream &os, cvm::rvector const &v);
968std::istream & operator >> (std::istream &is, cvm::rvector &v);
969
970
971namespace {
972 constexpr int32_t COLVARS_OK = 0;
973 constexpr int32_t COLVARS_ERROR = 1;
974 constexpr int32_t COLVARS_NOT_IMPLEMENTED = (1<<1);
975 constexpr int32_t COLVARS_INPUT_ERROR = (1<<2); // out of bounds or inconsistent input
976 constexpr int32_t COLVARS_BUG_ERROR = (1<<3); // Inconsistent state indicating bug
977 constexpr int32_t COLVARS_FILE_ERROR = (1<<4);
978 constexpr int32_t COLVARS_MEMORY_ERROR = (1<<5);
979 constexpr int32_t COLVARS_NO_SUCH_FRAME = (1<<6); // Cannot load the requested frame
980}
981
982
983#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
Arbitrary size array (two dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:373
1-dimensional vector of real numbers with four components and a quaternion algebra
Definition: colvartypes.h:955
2-dimensional array of real numbers with three components along each dimension (works with colvarmodu...
Definition: colvartypes.h:892
vector of real numbers with three components
Definition: colvartypes.h:724
Track usage of Colvars features.
Definition: colvarmodule.cpp:55
Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:34
Collective variables module (main class)
Definition: colvarmodule.h:76
int cite_feature(std::string const &feature)
Track usage of the given Colvars feature.
Definition: colvarmodule.cpp:2593
static const char *const line_marker
Line separator in the log output.
Definition: colvarmodule.h:752
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:268
int write_traj_files()
Write all trajectory files.
Definition: colvarmodule.cpp:1236
int load_coords_xyz(char const *filename, std::vector< rvector > *pos, atom_group *atoms, bool keep_open=false)
Load coordinates into an atom group from an XYZ file (assumes Angstroms)
std::ostream & write_state(std::ostream &os)
Write the state of the module to a formatted (text) file.
Definition: colvarmodule.cpp:1944
static std::string state_file_prefix(char const *filename)
Strips .colvars.state from filename and checks that it is not empty.
Definition: colvarmodule.cpp:1574
static real pow(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:159
size_t num_biases_feature(int feature_id) const
Return how many biases have this feature enabled.
Definition: colvarmodule.cpp:715
static real asin(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:202
static step_number it
Current step number.
Definition: colvarmodule.h:299
bool cv_traj_write_labels
Write labels at the next iteration.
Definition: colvarmodule.h:880
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:743
std::string cv_traj_name
Name of the trajectory file.
Definition: colvarmodule.h:877
static real logn(real const &x)
Definition: colvarmodule.h:248
std::ostream & write_traj(std::ostream &os)
Write in the trajectory file.
Definition: colvarmodule.cpp:1994
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:139
static size_t const en_prec
Number of digits to represent the collective variables energy.
Definition: colvarmodule.h:748
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:287
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:165
static std::string wrap_string(std::string const &s, size_t nchars)
Reduce the number of characters in a string.
size_t size() const
How many objects (variables and biases) are configured yet?
Definition: colvarmodule.cpp:245
int xyz_reader_use_count
Track how many times the XYZ reader has been used.
Definition: colvarmodule.h:895
std::vector< std::string > index_group_names
Names of groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:829
usage * usage_
Track usage of Colvars features.
Definition: colvarmodule.h:898
int update_colvar_forces()
Integrate bias and restraint forces, send colvar forces to atoms.
Definition: colvarmodule.cpp:1116
std::string restart_version() const
Version of the most recent state file read.
Definition: colvarmodule.h:907
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:1678
int parse_config(std::string &conf)
Parse a "clean" config string (no comments)
Definition: colvarmodule.cpp:326
int write_restart_file(std::string const &out_name)
Write a state file useful to resume the simulation.
Definition: colvarmodule.cpp:1195
static void request_total_force()
Request calculation of total force from MD engine.
void set_initial_step(step_number it)
Set the initial step number (it is 0 otherwise); may be overridden when reading a state.
Definition: colvarmodule.cpp:251
static real exp(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:240
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:219
int residue_id
Residue identifier.
Definition: colvarmodule.h:264
std::vector< colvarbias * > biases_active_
Array of active collective variable biases.
Definition: colvarmodule.h:395
static int log_output_files()
Level at which output-file operations are logged.
Definition: colvarmodule.h:809
int end_of_step()
Carry out operations needed before next step is run.
Definition: colvarmodule.cpp:1309
size_t num_biases() const
Return how many biases are defined.
Definition: colvarmodule.cpp:709
int setup_output()
(Re)initialize the output trajectory and state file (does not write it yet)
Definition: colvarmodule.cpp:1529
bool check_new_bias(std::string &conf, char const *key)
Definition: colvarmodule.cpp:564
std::string feature_report(int flag=0)
Report usage of the Colvars features.
Definition: colvarmodule.cpp:2598
std::vector< int > colvars_smp_items
Indexes of the items to calculate for each colvar.
Definition: colvarmodule.h:348
static int load_coords(char const *filename, std::vector< rvector > *pos, atom_group *atoms, std::string const &pdb_field, double pdb_field_value=0.0)
Load coordinates for a group of atoms from a file (PDB or XYZ); if "pos" is already allocated,...
static int backup_file(char const *filename)
Backup a file before writing it.
Definition: colvarmodule.cpp:1802
int calc()
Main worker function.
Definition: colvarmodule.cpp:876
static real cos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:189
int patch_version_number() const
Get the patch version number (non-zero only in the patch releases of other packages)
Definition: colvarmodule.cpp:48
std::string extra_conf
Definition: colvarmodule.h:478
static real dt()
Time step of MD integrator (fs)
static step_number it_restart
Starting step number for this run.
Definition: colvarmodule.h:301
static real integer_power(real const &x, int const n)
Override the STL pow() with a product for n integer.
Definition: colvarmodule.h:145
std::string config_string
Configuration string read so far by the module (includes comments)
Definition: colvarmodule.h:474
std::string default_input_state_file_
Default input state file; if given, it is read unless the MD engine provides it.
Definition: colvarmodule.h:537
int read_config_file(char const *config_file_name)
Definition: colvarmodule.cpp:258
std::vector< std::vector< int > * > index_groups
Groups from one or more Gromacs .ndx files.
Definition: colvarmodule.h:832
int restart_version_number() const
Integer version of the most recent state file read.
Definition: colvarmodule.h:913
static atom_group * atom_group_soa_by_name(std::string const &name)
Look up a named atom group by name; returns NULL if not found.
Definition: colvarmodule.cpp:798
void * num_biases_types_used_
Pointer to a map counting how many biases of each type were used.
Definition: colvarmodule.h:392
int catch_input_errors(int result)
Useful wrapper to interrupt parsing if any error occurs.
Definition: colvarmodule.cpp:759
std::vector< std::string > index_file_names
Names of .ndx files that have been loaded.
Definition: colvarmodule.h:826
static int log_level_
Level of logging requested by the user.
Definition: colvarmodule.h:780
std::vector< colvar * > * variables_active()
Collective variables with the active flag on.
Definition: colvarmodule.cpp:207
std::vector< colvarbias * > * biases_active()
Array of active collective variable biases.
Definition: colvarmodule.cpp:239
int patch_version_int
Patch version number; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:131
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:388
std::istream & read_objects_state(std::istream &is)
Read the states of individual objects; allows for changes.
Definition: colvarmodule.cpp:1693
real total_bias_energy
Energy of built-in and scripted biases, summed per time-step.
Definition: colvarmodule.h:387
static rvector position_distance(atom_pos const &pos1, atom_pos const &pos2)
Get the distance between two atomic positions with pbcs handled correctly.
size_t num_biases_type(std::string const &type) const
Return how many biases of this type are defined.
Definition: colvarmodule.cpp:729
static size_t const it_width
Number of characters to represent a time step.
Definition: colvarmodule.h:742
static bool use_scripted_forces
Use scripted colvars forces?
Definition: colvarmodule.h:933
std::istream & read_state(std::istream &is)
Read all objects' state fron a formatted (text) stream.
Definition: colvarmodule.cpp:1652
static void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:2019
std::vector< unsigned char > input_state_buffer_
Internal state buffer, to be read as an unformatted stream.
Definition: colvarmodule.h:540
colvarparse * parse
Configuration file parser object.
Definition: colvarmodule.h:874
int calc_component_smp(int i)
Calculate the value of the specified component (to be called in a SMP loop)
Definition: colvarmodule.cpp:225
static size_t cv_traj_freq
Frequency for collective variables trajectory output.
Definition: colvarmodule.h:861
static size_t & depth()
Get the current object depth in the hierarchy.
Definition: colvarmodule.cpp:2049
real max_gradient_error
Definition: colvarmodule.h:902
static bool scripting_after_biases
Wait for all biases before calculating scripted forces?
Definition: colvarmodule.h:936
std::string const & get_config() const
Get the configuration string read so far (includes comments)
Definition: colvarmodule.cpp:382
static size_t restart_out_freq
Frequency for saving output restarts.
Definition: colvarmodule.h:864
int parse_colvars(std::string const &conf)
Parse and initialize collective variables.
Definition: colvarmodule.cpp:515
static int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2096
static int errorCode
Definition: colvarmodule.h:283
std::vector< colvar * > colvars
Array of collective variables.
Definition: colvarmodule.h:339
static real atan2(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:234
std::vector< colvar * > * variables_active_smp()
Definition: colvarmodule.cpp:213
std::vector< atom_group * > named_atom_groups_soa
Array of named atom groups.
Definition: colvarmodule.h:351
static void increase_depth()
Increase the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2035
static real rand_gaussian()
Pseudo-random number with Gaussian distribution.
colvarmodule()
Cannot initialize the main object without a proxy.
int write_output_files()
Write all other output files.
Definition: colvarmodule.cpp:1808
static size_t const cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:744
static colvarmodule * main()
Access the one instance of the Colvars module.
Definition: colvarmodule.cpp:195
int parse_biases_type(std::string const &conf, char const *keyword)
Parse and initialize collective variable biases of a specific type.
Definition: colvarmodule.cpp:578
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:177
std::string version() const
Get the version string (YYYY-MM-DD format)
Definition: colvarmodule.cpp:36
static int log_level()
Level of logging requested by the user.
Definition: colvarmodule.h:785
int version_int
Integer representing the version string; value will be set in colvarmodule.cpp.
Definition: colvarmodule.h:128
std::ostream & write_traj_label(std::ostream &os)
Write explanatory labels in the trajectory file.
Definition: colvarmodule.cpp:1969
static real acos(real const &x)
Reimplemented to work around compiler issues; return hard-coded values for boundary conditions.
Definition: colvarmodule.h:218
int reset()
Actual function called by the destructor.
Definition: colvarmodule.cpp:1384
int calc_biases()
Calculate biases.
Definition: colvarmodule.cpp:1042
std::vector< colvar * > colvars_smp
Definition: colvarmodule.h:346
std::vector< colvar * > colvars_active
Array of collective variables.
Definition: colvarmodule.h:342
int analyze()
Perform analysis.
Definition: colvarmodule.cpp:1281
std::string read_colvar(std::string const &name)
Read a colvar value.
Definition: colvarmodule.cpp:843
size_t num_variables() const
Return how many variables are defined.
Definition: colvarmodule.cpp:689
std::string restart_out_name
Output restart file name.
Definition: colvarmodule.h:866
int version_number() const
Get the version number (higher = more recent)
Definition: colvarmodule.cpp:42
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:1828
static size_t const cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:746
size_t depth_s
Counter for the current depth in the object hierarchy (useg e.g. in output)
Definition: colvarmodule.h:889
static bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:403
int change_configuration(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:825
std::vector< colvarbias * > biases
Array of collective variable biases.
Definition: colvarmodule.h:384
std::string restart_version_str
Version of the most recent state file read.
Definition: colvarmodule.h:883
int restart_version_int
Integer version of the most recent state file read.
Definition: colvarmodule.h:886
int calc_scripted_forces()
Calculate the energy and forces of scripted biases.
Definition: colvarmodule.cpp:1177
std::string source_Tcl_script
Initialization Tcl script, user-provided.
Definition: colvarmodule.h:489
int write_restart_string(std::string &output)
Write the state into a string.
Definition: colvarmodule.cpp:1224
static std::istream & getline(std::istream &is, std::string &line)
Definition: colvarmodule.cpp:306
static int log_input_files()
Level at which input-file operations (configuration, state) are logged.
Definition: colvarmodule.h:815
int calc_colvars()
Calculate collective variables.
Definition: colvarmodule.cpp:944
static real fabs(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:171
std::vector< colvar * > * variables()
Array of collective variables.
Definition: colvarmodule.cpp:201
static void decrease_depth()
Decrease the depth (number of indentations in the output)
Definition: colvarmodule.cpp:2041
int update_engine_parameters()
Definition: colvarmodule.cpp:1336
real energy_difference(std::string const &bias_name, std::string const &conf)
Definition: colvarmodule.cpp:859
static int log_default_params()
Level at which a keyword's default value is logged.
Definition: colvarmodule.h:803
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:944
int reset_index_groups()
Clear the index groups loaded so far.
Definition: colvarmodule.cpp:2212
static int log_user_params()
Level at which a keyword's user-provided value is logged.
Definition: colvarmodule.h:797
int print_total_forces_errning(bool warn_total_forces)
If needed (old restart file), print the warning that cannot be ignored.
Definition: colvarmodule.cpp:1778
memory_stream & read_objects_state(memory_stream &is)
Read the states of individual objects; allows for changes.
static step_number step_relative()
Return the current step number from the beginning of this run.
Definition: colvarmodule.h:304
int read_index_file(char const *filename)
Read a Gromacs .ndx file.
size_t num_variables_feature(int feature_id) const
Return how many variables have this feature enabled.
Definition: colvarmodule.cpp:695
static real sin(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:183
~colvarmodule()
Destructor.
Definition: colvarmodule.cpp:1355
static std::string & output_prefix()
Accessor for the above.
Definition: colvarmodule.h:330
void config_changed()
Signals to the module object that the configuration has changed.
Definition: colvarmodule.cpp:395
static colvarproxy * proxy
Pointer to the proxy object, used to retrieve atomic data from the hosting program; it is static in o...
Definition: colvarmodule.h:955
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2446
static step_number step_absolute()
Definition: colvarmodule.h:311
static colvar * colvar_by_name(std::string const &name)
Look up a colvar by name; returns NULL if not found.
Definition: colvarmodule.cpp:785
static int log_init_messages()
Level at which initialization messages are logged.
Definition: colvarmodule.h:791
static colvarbias * bias_by_name(std::string const &name)
Look up a bias by name; returns NULL if not found.
Definition: colvarmodule.cpp:771
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:326
int setup_input()
(Re)initialize and (re)read the input state file calling read_restart()
Definition: colvarmodule.cpp:1419
int parse_biases(std::string const &conf)
Parse and initialize collective variable biases.
Definition: colvarmodule.cpp:622
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:1959
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:136
int parse_global_params(std::string const &conf)
Parse the few module's global parameters.
Definition: colvarmodule.cpp:401
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:321
int run_tcl_script(std::string const &filename)
Run provided Tcl script.
Definition: colvarmodule.cpp:503
int close_traj_file()
Close it (note: currently unused)
std::vector< size_t > depth_v
Thread-specific depth.
Definition: colvarmodule.h:892
static size_t const en_width
Number of characters to represent the collective variables energy.
Definition: colvarmodule.h:750
static std::string to_str(std::vector< real > const &x, size_t width=0, size_t prec=0)
Convert to string for output purposes.
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
Definition: colvarproxy.h:559
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43
colvarmodule cvm
Shorthand for the frequently used type prefix.
Definition: colvarmodule.h:964