Collective Variables Module - Developer Documentation
colvarproxy.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 COLVARPROXY_H
11 #define COLVARPROXY_H
12 
13 #include <array>
14 #include <functional>
15 #include <list>
16 #include <map>
17 
18 #include "colvarmodule.h"
19 #include "colvartypes.h"
20 #include "colvar_gpu_support.h"
21 #include "colvars_system.h"
22 
36 
37 
38 // forward declarations
39 class colvarscript;
40 
41 #if defined(_OPENMP)
42 #include <omp.h>
43 #else
44 struct omp_lock_t;
45 #endif
46 
47 #ifdef COLVARS_MPI
48 #include <mpi.h>
49 typedef MPI_Comm replicas_mpi_comm_t;
50 #else
51 typedef void * replicas_mpi_comm_t;
52 #endif
53 
54 #if defined(NAMD_TCL) || defined(VMDTCL)
55 #define COLVARS_TCL
56 #endif
57 
58 #ifdef COLVARS_TCL
59 #include <tcl.h>
60 #else
61 // Allow for placeholders Tcl_Interp* variables
62 typedef void Tcl_Interp;
63 #endif
64 
65 
70 {
71 
72 public:
73 
81  std::string units;
82 
84  virtual int set_unit_system(std::string const &units, bool check_only);
85 
88  {
89  return l * angstrom_value_;
90  }
91 
94  {
95  return l / angstrom_value_;
96  }
97 
99  inline cvm::real boltzmann() const
100  {
101  return boltzmann_;
102  }
103 
106  {
107  return target_temperature_;
108  }
109 
111  virtual int set_target_temperature(cvm::real T);
112 
114  inline double dt() const
115  {
116  return timestep_;
117  }
118 
121 
123  inline int time_step_factor() const
124  {
125  return time_step_factor_;
126  }
127 
129  virtual int set_time_step_factor(int fact);
130 
132  virtual cvm::real rand_gaussian(void);
133 
135  virtual void add_energy(cvm::real energy);
136 
138  inline bool & use_internal_pbc() { return use_internal_pbc_; }
139 
141  virtual cvm::rvector position_distance(cvm::atom_pos const &pos1,
142  cvm::atom_pos const &pos2) const;
143 
146  return boundaries_;
147  }
148 
151  virtual void request_total_force(bool yesno);
152 
154  virtual bool total_forces_enabled() const;
155 
158  virtual bool total_forces_same_step() const;
159 
162  virtual int get_molid(int &molid);
163 
165  virtual int get_alch_lambda(cvm::real* lambda);
166 
168  void set_alch_lambda(cvm::real lambda);
169 
171  virtual int send_alch_lambda();
172 
174  virtual int request_alch_energy_freq(int const /* freq */) {
175  return COLVARS_OK;
176  }
177 
179  virtual int get_dE_dlambda(cvm::real* dE_dlambda);
180 
182  virtual int apply_force_dE_dlambda(cvm::real* force);
183 
185  virtual int get_d2E_dlambda2(cvm::real* d2E_dlambda2);
186 
189 
191  virtual cvm::real get_accelMD_factor() const {
192  cvm::error_static(cvmodule, "Error: accessing the reweighting factor of accelerated MD "
193  "is not yet implemented in the MD engine.\n",
194  COLVARS_NOT_IMPLEMENTED);
195  return 1.0;
196  }
197  virtual bool accelMD_enabled() const {
198  return false;
199  }
200 
201 #if ( defined(COLVARS_CUDA) || defined(COLVARS_HIP) )
202  template <typename T>
203  using allocator_type = colvars_gpu::CudaHostAllocator<T>;
204 #else
205  template <typename T>
206  using allocator_type = std::allocator<T>;
207 #endif
208  using atom_buffer_real_t = std::vector<cvm::real, allocator_type<cvm::real>>;
209  using atom_buffer_rvector_t = std::vector<cvm::rvector, allocator_type<cvm::rvector>>;
210 
213  virtual int init_atom(int atom_number);
214 
217  virtual int check_atom_id(int atom_number);
218 
221 
225  virtual int init_atom(cvm::residue_id const &residue,
226  std::string const &atom_name,
227  std::string const &segment_id);
228 
230  virtual int check_atom_id(cvm::residue_id const &residue,
231  std::string const &atom_name,
232  std::string const &segment_id);
233 
236  virtual void clear_atom(int index);
237 
239  int reset_atoms();
240 
243  inline int get_atom_id(int index) const
244  {
245  return atoms_ids[index];
246  }
247 
250  inline cvm::real get_atom_mass(int index) const
251  {
252  return atoms_masses[index];
253  }
254 
257  inline void increase_refcount(int index)
258  {
259  atoms_refcount[index] += 1;
260  }
261 
264  inline cvm::real get_atom_charge(int index) const
265  {
266  return atoms_charges[index];
267  }
268 
271  inline cvm::rvector get_atom_position(int index) const
272  {
273  return atoms_positions[index];
274  }
275 
278  inline cvm::rvector get_atom_total_force(int index) const
279  {
280  return atoms_total_forces[index];
281  }
282 
286  inline void apply_atom_force(int index, cvm::rvector const &new_force)
287  {
288  atoms_new_colvar_forces[index] += new_force;
289  }
290 
292  inline cvm::rvector get_atom_velocity(int /* index */)
293  {
294  cvm::error_static(cvmodule, "Error: reading the current velocity of an atom "
295  "is not yet implemented.\n",
296  COLVARS_NOT_IMPLEMENTED);
297  return cvm::rvector(0.0);
298  }
299 
300  inline std::vector<int> const *get_atom_ids() const
301  {
302  return &atoms_ids;
303  }
304 
306  size_t get_num_active_atoms() const;
307 
308  inline atom_buffer_real_t const *get_atom_masses() const
309  {
310  return &atoms_masses;
311  }
312 
313  inline atom_buffer_real_t *modify_atom_masses()
314  {
315  // assume that we are requesting masses to change them
316  updated_masses_ = true;
317  return &atoms_masses;
318  }
319 
320  inline atom_buffer_real_t const *get_atom_charges()
321  {
322  return &atoms_charges;
323  }
324 
325  inline atom_buffer_real_t *modify_atom_charges()
326  {
327  // assume that we are requesting charges to change them
328  updated_charges_ = true;
329  return &atoms_charges;
330  }
331 
332  inline atom_buffer_rvector_t const *get_atom_positions() const
333  {
334  return &atoms_positions;
335  }
336 
337  inline atom_buffer_rvector_t *modify_atom_positions()
338  {
339  return &atoms_positions;
340  }
341 
342  inline atom_buffer_rvector_t const *get_atom_total_forces() const
343  {
344  return &atoms_total_forces;
345  }
346 
347  inline atom_buffer_rvector_t *modify_atom_total_forces()
348  {
349  return &atoms_total_forces;
350  }
351 
352  inline atom_buffer_rvector_t const *get_atom_applied_forces() const
353  {
354  return &atoms_new_colvar_forces;
355  }
356 
357  inline atom_buffer_rvector_t *modify_atom_applied_forces()
358  {
359  return &atoms_new_colvar_forces;
360  }
361 
364 
367 
370  {
372  }
373 
376  {
378  }
379 
381  inline int max_atoms_applied_force_id() const
382  {
384  }
385 
387  inline bool modified_atom_list() const
388  {
389  return modified_atom_list_;
390  }
391 
394  {
395  modified_atom_list_ = false;
396  }
397 
399  inline bool updated_masses() const
400  {
401  return updated_masses_;
402  }
403 
405  inline bool updated_charges() const
406  {
407  return updated_charges_;
408  }
409 
411  int reset_atom_groups();
412 
414  virtual int check_scalable_group_coms();
415 
417  virtual int init_atom_group(std::vector<int> const &atoms_ids);
418 
420  virtual void clear_atom_group(int index);
421 
423  inline int get_atom_group_id(int index) const
424  {
425  return atom_groups_ids[index];
426  }
427 
429  inline cvm::real get_atom_group_mass(int index) const
430  {
431  return atom_groups_masses[index];
432  }
433 
435  inline cvm::real get_atom_group_charge(int index) const
436  {
437  return atom_groups_charges[index];
438  }
439 
441  inline cvm::rvector get_atom_group_com(int index) const
442  {
443  return atom_groups_coms[index];
444  }
445 
447  inline cvm::rvector get_atom_group_total_force(int index) const
448  {
449  return atom_groups_total_forces[index];
450  }
451 
453  inline void apply_atom_group_force(int index, cvm::rvector const &new_force)
454  {
455  atom_groups_new_colvar_forces[index] += new_force;
456  }
457 
459  inline cvm::rvector get_atom_group_velocity(int /* index */)
460  {
461  cvm::error_static(cvmodule, "Error: reading the current velocity of an atom group is not yet implemented.\n",
462  COLVARS_NOT_IMPLEMENTED);
463  return cvm::rvector(0.0);
464  }
465 
466  inline std::vector<int> const *get_atom_group_ids() const
467  {
468  return &atom_groups_ids;
469  }
470 
472  size_t get_num_active_atom_groups() const;
473 
474  inline std::vector<cvm::real> *modify_atom_group_masses()
475  {
476  // TODO updated_masses
477  return &atom_groups_masses;
478  }
479 
480  inline std::vector<cvm::real> *modify_atom_group_charges()
481  {
482  // TODO updated masses
483  return &atom_groups_charges;
484  }
485 
486  inline std::vector<cvm::rvector> *modify_atom_group_positions()
487  {
488  return &atom_groups_coms;
489  }
490 
491  inline std::vector<cvm::rvector> *modify_atom_group_total_forces()
492  {
493  return &atom_groups_total_forces;
494  }
495 
496  inline std::vector<cvm::rvector> *modify_atom_group_applied_forces()
497  {
499  }
500 
503 
506 
509  {
511  }
512 
515  {
517  }
518 
520  int reset_volmaps();
521 
523  virtual int check_volmaps_available();
524 
526  virtual int check_engine_volmaps_available();
527 
529  int add_volmap_slot(int volmap_id);
530 
534  virtual int request_engine_volmap_by_id(int volmap_id);
535 
539  virtual int request_engine_volmap_by_name(std::string const &volmap_name);
540 
544  virtual int init_internal_volmap_by_id(int volmap_id);
545 
549  virtual int init_internal_volmap_by_name(std::string const &filename);
550 
554  virtual int load_internal_volmap_from_file(std::string const &filename);
555 
557  virtual int clear_volmap(int index);
558 
560  inline int get_volmap_id(int index) const
561  {
562  return volmaps_ids[index];
563  }
564 
566  inline cvm::real get_engine_volmap_value(int index) const
567  {
568  return volmaps_values[index];
569  }
570 
572  inline void apply_engine_volmap_force(int index, cvm::real const &new_force)
573  {
574  volmaps_new_colvar_forces[index] += new_force;
575  }
576 
578 
584  virtual int compute_volmap(int flags,
585  int volmap_index,
586  cvm::atom_group* ag,
587  cvm::real *value,
588  cvm::real *atom_field);
589 
591  enum {
592  volmap_flag_null = 0,
593  volmap_flag_gradients = 1,
594  volmap_flag_use_atom_field = (1<<8)
595  };
596 
599 
602 
603  enum class smp_mode_t {cvcs, inner_loop, gpu, none};
604 
606  virtual smp_mode_t get_smp_mode() const;
607 
609  virtual std::vector<smp_mode_t> get_available_smp_modes() const;
610 
612  virtual smp_mode_t get_preferred_smp_mode() const;
613 
615  virtual int set_smp_mode(smp_mode_t mode);
616 
618  virtual int smp_loop(int n_items, std::function<int (int)> const &worker);
619 
621  virtual int smp_biases_loop();
622 
624  virtual int smp_biases_script_loop();
625 
627  virtual int smp_thread_id();
628 
630  virtual int smp_num_threads();
631 
633  virtual int smp_lock();
634 
636  virtual int smp_trylock();
637 
639  virtual int smp_unlock();
640 
642  virtual void set_replicas_mpi_communicator(replicas_mpi_comm_t comm);
643 
645  virtual int check_replicas_enabled();
646 
648  virtual int replica_index();
649 
651  virtual int num_replicas();
652 
654  virtual void replica_comm_barrier();
655 
657  virtual int replica_comm_recv(char* msg_data, int buf_len, int src_rep);
658 
660  virtual int replica_comm_send(char* msg_data, int msg_len, int dest_rep);
661 
664  colvarscript *script = nullptr;
665 
667  virtual int run_force_callback();
668 
669  virtual int run_colvar_callback(
670  std::string const &name,
671  std::vector<const colvarvalue *> const &cvcs,
672  colvarvalue &value);
673 
674  virtual int run_colvar_gradient_callback(
675  std::string const &name,
676  std::vector<const colvarvalue *> const &cvcs,
677  std::vector<cvm::matrix2d<cvm::real> > &gradient);
678 
680  inline bool tcl_available() {
681 #if defined(COLVARS_TCL)
682  return true;
683 #else
684  return false;
685 #endif
686  }
687 
689  char const *tcl_get_str(void *obj);
690 
691  int tcl_run_script(std::string const &script);
692 
693  int tcl_run_file(std::string const &fileName);
694 
697 
700  std::string const &name,
701  std::vector<const colvarvalue *> const &cvcs,
702  colvarvalue &value);
703 
706  std::string const &name,
707  std::vector<const colvarvalue *> const &cvcs,
708  std::vector<cvm::matrix2d<cvm::real> > &gradient);
709 
711  inline Tcl_Interp *get_tcl_interp()
712  {
713  return tcl_interp_;
714  }
715 
717  inline void set_tcl_interp(Tcl_Interp *interp)
718  {
719  tcl_interp_ = interp;
720  }
721 
723  virtual void init_tcl_pointers();
724 
726  virtual bool io_available();
727 
729  // Returns error code
730  virtual int get_frame(long int &);
731 
733  // Returns error code
734  virtual int set_frame(long int);
735 
737  std::string get_current_work_dir() const;
738 
740  std::string join_paths(std::string const &path1, std::string const &path2) const;
741 
743  virtual int backup_file(char const *filename);
744 
746  inline int backup_file(std::string const &filename)
747  {
748  return backup_file(filename.c_str());
749  }
750 
752  virtual int remove_file(char const *filename);
753 
755  inline int remove_file(std::string const &filename)
756  {
757  return remove_file(filename.c_str());
758  }
759 
761  virtual int rename_file(char const *filename, char const *newfilename);
762 
764  inline int rename_file(std::string const &filename,
765  std::string const &newfilename)
766  {
767  return rename_file(filename.c_str(), newfilename.c_str());
768  }
769 
771  inline std::string const & input_prefix() const
772  {
773  return input_prefix_str;
774  }
775 
777  virtual int set_input_prefix(std::string const &prefix);
778 
780  inline std::string const & output_prefix() const
781  {
782  return output_prefix_str;
783  }
784 
786  virtual int set_output_prefix(std::string const &prefix);
787 
789  inline std::string const & restart_output_prefix() const
790  {
792  }
793 
795  virtual int set_restart_output_prefix(std::string const &prefix);
796 
798  inline int default_restart_frequency() const
799  {
801  }
802 
804  virtual int set_default_restart_frequency(int freq);
805 
806  // The input stream functions below are not virtual, because they currently
807  // rely on the fact that either std::ifstream or std::istringstream is used
808 
813  std::istream & input_stream(std::string const &input_name,
814  std::string const description = "file/channel",
815  bool error_on_fail = true);
816 
821  std::istream & input_stream_from_string(std::string const &input_name,
822  std::string const &content,
823  std::string const description = "string");
824 
826  bool input_stream_exists(std::string const &input_name);
827 
829  int close_input_stream(std::string const &input_name);
830 
832  int close_input_streams();
833 
835  int delete_input_stream(std::string const &input_name);
836 
838  std::list<std::string> list_input_stream_names() const;
839 
843  virtual std::ostream &output_stream(std::string const &output_name,
844  std::string const description);
845 
847  virtual bool output_stream_exists(std::string const &output_name);
848 
850  virtual int flush_output_stream(std::string const &output_name);
851 
853  virtual int flush_output_streams();
854 
856  virtual int close_output_stream(std::string const &output_name);
857 
859  virtual int close_output_streams();
860 
862  bool has_gpu_support() const {
863  return support_gpu;
864  }
866  std::string gpu_name() const;
868  std::string gpu_bus_id() const;
870  int gpu_device_id() const;
872  std::string gpu_platform() const;
874  int gpu_warp_size() const;
875 #if defined (COLVARS_CUDA) || defined (COLVARS_HIP) || defined (COLVARS_SYCL)
877  virtual cudaStream_t get_default_stream() {return (cudaStream_t)0;}
879  int init_gpu();
881  enum class event_type {
882  copy_atoms,
883  update_lattice,
884  num_event_types,
885  };
887  cudaEvent_t get_event(event_type type) const {return events[static_cast<int>(type)];}
896  template <typename T>
897  int allocate_host(T **pp, const size_t len) {
898  return allocate_host_T((void **)pp, len, sizeof(T));
899  }
907  template <typename T>
908  int deallocate_host(T **pp) {
909  return deallocate_host_T((void **)pp);
910  }
919  template <typename T>
920  int allocate_device(T **pp, const size_t len) {
921  return allocate_device_T((void **)pp, len, sizeof(T));
922  }
934  template <typename T>
935  int reallocate_device(T **pp, const size_t len) {
936  int error_code = COLVARS_OK;
937  error_code |= deallocate_device(pp);
938  error_code |= allocate_device_T((void **)pp, len, sizeof(T));
939  return error_code;
940  }
952  template <typename T>
953  int reallocate_host(T **pp, const size_t len) {
954  int error_code = COLVARS_OK;
955  error_code |= deallocate_host(pp);
956  error_code |= allocate_host_T((void **)pp, len, sizeof(T));
957  return error_code;
958  }
968  template <typename T>
969  int allocate_device_async(T **pp, const size_t len, cudaStream_t stream) {
970  return allocate_device_T_async((void **)pp, len, sizeof(T), stream);
971  }
979  template <typename T>
980  int deallocate_device(T **pp) {
981  return deallocate_device_T((void **)pp);
982  }
991  template <typename T>
992  int deallocate_device_async(T **pp, cudaStream_t stream) {
993  return deallocate_device_T_async((void **)pp, stream);
994  }
1003  template <typename T>
1004  int clear_device_array(T *data, const size_t ndata) {
1005  return clear_device_array_T(data, ndata, sizeof(T));
1006  }
1016  template <typename T>
1017  int clear_device_array_async(T *data, const size_t ndata, cudaStream_t stream) {
1018  return clear_device_array_T_async(data, ndata, sizeof(T), stream);
1019  }
1029  template <typename T>
1030  int copy_HtoD(const T *h_array, T *d_array, size_t array_len) {
1031  return copy_HtoD_T(h_array, d_array, array_len, sizeof(T));
1032  }
1043  template <typename T>
1044  int copy_HtoD_async(const T *h_array, T *d_array, size_t array_len, cudaStream_t stream) {
1045  return copy_HtoD_T_async(h_array, d_array, array_len, sizeof(T), stream);
1046  }
1056  template <typename T>
1057  int copy_DtoH(const T *d_array, T *h_array, size_t array_len) {
1058  return copy_DtoH_T(d_array, h_array, array_len, sizeof(T));
1059  }
1070  template <typename T>
1071  int copy_DtoH_async(const T *d_array, T *h_array, size_t array_len, cudaStream_t stream) {
1072  return copy_DtoH_T_async(d_array, h_array, array_len, sizeof(T), stream);
1073  }
1083  template <typename T>
1084  int copy_DtoD(const T *d_src, T *d_dst, size_t array_len) {
1085  return copy_DtoD_T(d_src, d_dst, array_len, sizeof(T));
1086  }
1097  template <typename T>
1098  int copy_DtoD_async(const T *d_src, T *d_dst, size_t array_len, cudaStream_t stream) {
1099  return copy_DtoD_T_async(d_src, d_dst, array_len, sizeof(T), stream);
1100  }
1103  virtual int allocate_host_T(void **pp, const size_t len, const size_t sizeofT);
1104  virtual int deallocate_host_T(void **pp);
1105  virtual int allocate_device_T(void **pp, const size_t len, const size_t sizeofT);
1106  virtual int deallocate_device_T(void **pp);
1107  virtual int clear_device_array_T(void *data, const size_t ndata, const size_t sizeofT);
1108  virtual int allocate_device_T_async(void **pp, const size_t len, const size_t sizeofT, cudaStream_t stream);
1109  virtual int deallocate_device_T_async(void **pp, cudaStream_t stream);
1110  virtual int clear_device_array_T_async(void *data, const size_t ndata, const size_t sizeofT, cudaStream_t stream);
1111  virtual int copy_HtoD_T(const void *h_array, void *d_array, size_t array_len, const size_t sizeofT);
1112  virtual int copy_HtoD_T_async(const void *h_array, void *d_array, size_t array_len, const size_t sizeofT, cudaStream_t stream);
1113  virtual int copy_DtoH_T(const void *d_array, void *h_array, size_t array_len, const size_t sizeofT);
1114  virtual int copy_DtoH_T_async(const void *d_array, void *h_array, size_t array_len, const size_t sizeofT, cudaStream_t stream);
1115  virtual int copy_DtoD_T(const void *d_src, void *d_dst, size_t array_len, const size_t sizeofT);
1116  virtual int copy_DtoD_T_async(const void *d_src, void *d_dst, size_t array_len, const size_t sizeofT, cudaStream_t stream);
1121  virtual float* proxy_atoms_masses_gpu_float() {return nullptr;}
1122  virtual float* proxy_atoms_charges_gpu_float() {return nullptr;}
1123  virtual cvm::real* proxy_atoms_masses_gpu() {return nullptr;}
1124  virtual cvm::real* proxy_atoms_charges_gpu() {return nullptr;}
1125  virtual cvm::real* proxy_atoms_positions_gpu() {return nullptr;}
1126  virtual cvm::real* proxy_atoms_total_forces_gpu() {return nullptr;}
1127  virtual cvm::real* proxy_atoms_new_colvar_forces_gpu() {return nullptr;}
1129 #endif // defined (COLVARS_CUDA) || defined (COLVARS_HIP)
1130 
1133 
1135  colvarproxy();
1136 
1138  virtual ~colvarproxy();
1139 
1140  inline std::string const &engine_name() const
1141  {
1142  return engine_name_;
1143  }
1144 
1145  // bool io_available() override;
1146 
1148  virtual int request_deletion();
1149 
1151  inline bool delete_requested() const
1152  {
1153  return b_delete_requested;
1154  }
1155 
1157  virtual int reset();
1158 
1160  virtual int parse_module_config();
1161 
1168  virtual int load_atoms_pdb(char const *filename, cvm::atom_group &atoms,
1169  std::string const &pdb_field, double pdb_field_value);
1170 
1171 
1179  virtual int load_coords_pdb(char const *filename, std::vector<cvm::atom_pos> &pos,
1180  std::vector<int> const &sorted_ids, std::string const &pdb_field,
1181  double pdb_field_value);
1182 
1184  virtual int setup();
1185 
1187  inline bool engine_ready() const
1188  {
1189  return engine_ready_;
1190  }
1191 
1193  inline bool total_forces_valid() const
1194  {
1195  return total_forces_valid_;
1196  }
1197 
1199  void set_total_forces_invalid();
1200 
1202  void set_total_forces_valid();
1203 
1205  void add_config(std::string const &cmd, std::string const &conf);
1206 
1210  virtual int update_input();
1211 
1213  virtual int update_output();
1214 
1216  int end_of_step();
1217 
1219  virtual void log(std::string const &message);
1220 
1222  virtual void error(std::string const &message);
1223 
1225  void add_error_msg(std::string const &message);
1226 
1228  std::string const & get_error_msgs();
1229 
1231  void clear_error_msgs();
1232 
1234  inline bool simulation_running() const
1235  {
1236  return b_simulation_running;
1237  }
1238 
1242  inline bool simulation_continuing() const
1243  {
1244  return b_simulation_continuing;
1245  }
1246 
1248  int post_run();
1249 
1251  void print_input_atomic_data();
1252 
1254  void print_output_atomic_data();
1255 
1257  int get_version_from_string(char const *version_string);
1258 
1260  int version_number() const
1261  {
1262  return version_int;
1263  }
1264 
1265 protected:
1266 
1269 
1272 
1275 
1278 
1280  double timestep_;
1281 
1284 
1290 
1293 
1296 
1298  bool use_internal_pbc_ = false;
1299 
1302 
1305  std::vector<int> atoms_ids;
1307  std::vector<size_t> atoms_refcount;
1309  std::vector<cvm::real, allocator_type<cvm::real>> atoms_masses;
1311  std::vector<cvm::real, allocator_type<cvm::real>> atoms_charges;
1313  std::vector<cvm::rvector, allocator_type<cvm::rvector>> atoms_positions;
1315  std::vector<cvm::rvector, allocator_type<cvm::rvector>> atoms_total_forces;
1317  std::vector<cvm::rvector, allocator_type<cvm::rvector>> atoms_new_colvar_forces;
1318 
1321 
1324 
1327 
1330 
1332  bool updated_masses_, updated_charges_;
1333 
1336  int add_atom_slot(int atom_id);
1337 
1341  int find_atom_by_id(int atom_id);
1342 
1345  std::vector<int> atom_groups_ids;
1347  std::vector<size_t> atom_groups_refcount;
1349  std::vector<cvm::real> atom_groups_masses;
1351  std::vector<cvm::real> atom_groups_charges;
1353  std::vector<cvm::rvector> atom_groups_coms;
1355  std::vector<cvm::rvector> atom_groups_total_forces;
1357  std::vector<cvm::rvector> atom_groups_new_colvar_forces;
1358 
1361 
1364 
1366  int add_atom_group_slot(int atom_group_id);
1367 
1369  std::vector<int> volmaps_ids;
1370 
1372  std::vector<size_t> volmaps_refcount;
1373 
1375  std::vector<cvm::real> volmaps_values;
1376 
1378  std::vector<cvm::real> volmaps_new_colvar_forces;
1379 
1381  std::vector<std::string> volmaps_filenames;
1382 
1385 
1388 
1390  omp_lock_t *omp_lock_state;
1391 
1394  smp_mode_t smp_mode;
1395 
1397  replicas_mpi_comm_t replicas_mpi_comm;
1398 
1401 
1404 
1406  Tcl_Interp *tcl_interp_;
1407 
1409  std::string input_prefix_str;
1410 
1412  std::string output_prefix_str;
1413 
1416 
1419 
1421  std::map<std::string, std::istream *> input_streams_;
1422 
1424  std::istream *input_stream_error_;
1425 
1427  std::map<std::string, std::ostream *> output_streams_;
1428 
1430  std::ostream *output_stream_error_;
1431 
1434 
1437 
1438 #if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
1439  std::array<cudaEvent_t, static_cast<int>(event_type::num_event_types)> events = {};
1440 #endif
1441 
1444 
1446  bool total_forces_valid_ = false;
1447 
1449  std::string error_output;
1450 
1453 
1458 
1461 
1464 
1467 
1469  std::string engine_name_ = "standalone";
1470 
1473 
1474 };
1475 
1476 #endif
Arbitrary size array (two dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:382
vector of real numbers with three components
Definition: colvartypes.h:740
Class to store the system's boundary conditions.
Definition: colvars_system.h:16
Collective variables module (main class)
Definition: colvarmodule.h:87
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:114
static int error_static(colvarmodule *cvmodule, std::string const &message, int code=-1)
Definition: colvarmodule.h:815
int residue_id
Residue identifier.
Definition: colvarmodule.h:260
Definition: colvarproxy.h:70
virtual int check_replicas_enabled()
Indicate if multi-replica support is available and active.
Definition: colvarproxy_replicas.cpp:29
std::vector< cvm::real > volmaps_new_colvar_forces
Forces applied from colvars, to be communicated to the MD engine.
Definition: colvarproxy.h:1378
virtual int update_input()
Definition: colvarproxy.cpp:609
int default_restart_frequency() const
Default restart frequency (as set by the simulation engine)
Definition: colvarproxy.h:798
int tcl_run_force_callback()
Tcl implementation of run_force_callback()
Definition: colvarproxy_tcl.cpp:83
int allocate_host(T **pp, const size_t len)
Template function to allocate host-pinned memory.
Definition: colvarproxy.h:897
colvarproxy()
Constructor.
Definition: colvarproxy.cpp:403
virtual int check_engine_volmaps_available()
Test whether the engine supports offloaded computation of volumetric maps.
Definition: colvarproxy_volmaps.cpp:21
virtual int set_unit_system(std::string const &units, bool check_only)
Request to set the units used internally by Colvars.
Definition: colvarproxy_system.cpp:17
void compute_max_atom_groups_applied_force()
Compute the maximum norm among all applied forces.
Definition: colvarproxy.cpp:224
cvm::rvector get_atom_group_com(int index) const
Read the current position of the center of mass given atom group.
Definition: colvarproxy.h:441
virtual ~colvarproxy()
Destructor.
Definition: colvarproxy.cpp:461
int copy_HtoD_async(const T *h_array, T *d_array, size_t array_len, cudaStream_t stream)
Template function to copy data from host to device asynchronously.
Definition: colvarproxy.h:1044
std::vector< cvm::rvector > atom_groups_new_colvar_forces
Forces applied from colvars, to be communicated to the MD integrator.
Definition: colvarproxy.h:1357
virtual int num_replicas()
Total number of replicas.
Definition: colvarproxy_replicas.cpp:48
std::string error_output
Collected error messages.
Definition: colvarproxy.h:1449
void set_total_forces_valid()
Mark the total forces as up to date.
Definition: colvarproxy.cpp:663
virtual int update_output()
Update data based on the results of a Colvars call (e.g. send forces)
Definition: colvarproxy.cpp:615
std::vector< int > atom_groups_ids
Array of 0-based integers used to uniquely associate atom groups within the host program.
Definition: colvarproxy.h:1345
virtual int request_engine_volmap_by_name(std::string const &volmap_name)
Definition: colvarproxy_volmaps.cpp:59
virtual int check_volmaps_available()
Test whether the engine provides code to load volumetric maps as CVs.
Definition: colvarproxy_volmaps.cpp:15
cvm::rvector get_atom_position(int index) const
Definition: colvarproxy.h:271
int init_gpu()
Initialize the GPU data (called by colvarproxy::setup)
Definition: colvarproxy_gpu.cpp:100
int add_atom_group_slot(int atom_group_id)
Used by all init_atom_group() functions: create a slot for an atom group not requested yet.
Definition: colvarproxy.cpp:166
virtual void clear_atom_group(int index)
Used by the atom_group class destructor.
Definition: colvarproxy.cpp:194
virtual int init_atom_group(std::vector< int > const &atoms_ids)
Prepare this group for collective variables calculation, selecting atoms by internal ids (0-based)
Definition: colvarproxy.cpp:185
virtual bool io_available()
Ensure that we're on the main thread (derived class will do actual check)
Definition: colvarproxy.cpp:510
int close_input_stream(std::string const &input_name)
Closes the given input stream.
Definition: colvarproxy_io.cpp:315
cvm::real rms_atom_groups_applied_force() const
Get the root-mean-square of the applied forces.
Definition: colvarproxy.h:508
void add_config(std::string const &cmd, std::string const &conf)
Enqueue new configuration text, to be parsed as soon as possible.
Definition: colvarproxy.cpp:540
virtual cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const
Get the PBC-aware distance vector between two positions (using Colvars internal boundary handling)
Definition: colvarproxy_system.cpp:73
cvm::real rms_atoms_applied_force() const
Get the root-mean-square of the applied forces.
Definition: colvarproxy.h:369
virtual int get_molid(int &molid)
Definition: colvarproxy_system.cpp:80
int copy_DtoH(const T *d_array, T *h_array, size_t array_len)
Template function to copy data from device to host.
Definition: colvarproxy.h:1057
virtual int set_integration_timestep(cvm::real dt)
Set the current integration timestep of the simulation (fs units)
Definition: colvarproxy_system.cpp:31
bool tcl_available()
Is Tcl available? (trigger initialization if needed)
Definition: colvarproxy.h:680
std::vector< cvm::rvector, allocator_type< cvm::rvector > > atoms_positions
Current three-dimensional positions of the atoms.
Definition: colvarproxy.h:1313
virtual int smp_lock()
Lock the proxy's shared data for access by a thread, if threads are implemented; if not implemented,...
Definition: colvarproxy.cpp:350
virtual int request_deletion()
Request deallocation of the module (currently only implemented by VMD)
Definition: colvarproxy.cpp:532
cvm::rvector get_atom_velocity(int)
Read the current velocity of the given atom.
Definition: colvarproxy.h:292
std::vector< size_t > atoms_refcount
Keep track of how many times each atom is used by a separate colvar object.
Definition: colvarproxy.h:1307
void set_tcl_interp(Tcl_Interp *interp)
Set the pointer to the Tcl interpreter.
Definition: colvarproxy.h:717
std::string join_paths(std::string const &path1, std::string const &path2) const
Join two paths using the operating system's path separation.
Definition: colvarproxy_io.cpp:88
void compute_rms_volmaps_applied_force()
Compute the root-mean-square of the applied forces.
Definition: colvarproxy_volmaps.cpp:108
bool simulation_continuing() const
Definition: colvarproxy.h:1242
void reset_modified_atom_list()
Reset the modified atom list flag.
Definition: colvarproxy.h:393
virtual int replica_comm_send(char *msg_data, int msg_len, int dest_rep)
Send data to other replica.
Definition: colvarproxy_replicas.cpp:82
int delete_input_stream(std::string const &input_name)
Same as close_input_stream(), but also removes the corresponding entry from memory.
Definition: colvarproxy_io.cpp:338
void clear_error_msgs()
As the name says.
Definition: colvarproxy.cpp:799
double timestep_
Current integration timestep (engine units); default to 1.0 if undefined.
Definition: colvarproxy.h:1280
void add_error_msg(std::string const &message)
Record error message (used by VMD to collect them after a script call)
Definition: colvarproxy.cpp:789
virtual int set_time_step_factor(int fact)
Set the current integration timestep of the simulation (fs units)
Definition: colvarproxy_system.cpp:37
cvm::real volmaps_max_applied_force_
Maximum norm among all applied forces.
Definition: colvarproxy.h:1387
int version_int
Integer representing the version string (allows comparisons)
Definition: colvarproxy.h:1463
std::string const & get_error_msgs()
Retrieve accumulated error messages.
Definition: colvarproxy.cpp:805
virtual int allocate_host_T(void **pp, const size_t len, const size_t sizeofT)
Memory management and data transfer implementations.
Definition: colvarproxy_gpu.cpp:7
int replicas_mpi_num
Number of replicas in the MPI implementation.
Definition: colvarproxy.h:1403
int clear_device_array(T *data, const size_t ndata)
Template function to clear a device array to zero.
Definition: colvarproxy.h:1004
std::string input_prefix_str
Prefix of the input state file to be read next.
Definition: colvarproxy.h:1409
std::map< std::string, std::ostream * > output_streams_
Currently open output files/channels.
Definition: colvarproxy.h:1427
int reallocate_device(T **pp, const size_t len)
Template function to reallocate device memory.
Definition: colvarproxy.h:935
bool use_internal_pbc_
Use the PBC functions from the Colvars library (as opposed to MD engine)
Definition: colvarproxy.h:1298
cvm::real atoms_max_applied_force_
Maximum norm among all applied forces.
Definition: colvarproxy.h:1323
int restart_frequency_engine
How often the simulation engine will write its own restart.
Definition: colvarproxy.h:1418
cvm::real target_temperature_
Most up to date target temperature (K units); default to 0.0 if undefined.
Definition: colvarproxy.h:1277
int end_of_step()
Carry out operations needed before next simulation step is run.
Definition: colvarproxy.cpp:621
std::vector< cvm::real, allocator_type< cvm::real > > atoms_charges
Charges of the atoms (allow redefinition during a run, as done e.g. in LAMMPS)
Definition: colvarproxy.h:1311
int time_step_factor() const
Time step of the simulation (fs units)
Definition: colvarproxy.h:123
std::string const & input_prefix() const
Prefix of the input state file to be read next.
Definition: colvarproxy.h:771
int deallocate_device_async(T **pp, cudaStream_t stream)
Template function to deallocate device memory asynchronously.
Definition: colvarproxy.h:992
std::string restart_output_prefix_str
Prefix of the restart (checkpoint) file to be written next.
Definition: colvarproxy.h:1415
std::list< std::string > list_input_stream_names() const
List all input streams that were opened at some point.
Definition: colvarproxy_io.cpp:371
virtual int set_output_prefix(std::string const &prefix)
Set default output prefix.
Definition: colvarproxy_io.cpp:208
virtual void log(std::string const &message)
Print a message to the main log.
Definition: colvarproxy.cpp:776
int rename_file(std::string const &filename, std::string const &newfilename)
Rename the given file.
Definition: colvarproxy.h:764
virtual int flush_output_stream(std::string const &output_name)
Flushes the given output file/channel.
Definition: colvarproxy_io.cpp:419
int get_atom_group_id(int index) const
Get the numeric ID of the given atom group (for the MD program)
Definition: colvarproxy.h:423
virtual bool output_stream_exists(std::string const &output_name)
Check if the file/channel is open (without opening it if not)
Definition: colvarproxy_io.cpp:413
cvm::real get_atom_group_charge(int index) const
Get the charge of the given atom group.
Definition: colvarproxy.h:435
void set_alch_lambda(cvm::real lambda)
Set value of alchemical lambda parameter to be sent to back-end at end of timestep.
Definition: colvarproxy_system.cpp:95
std::istream * input_stream_error_
Object whose reference is returned when read errors occur.
Definition: colvarproxy.h:1424
cvm::real boltzmann() const
Boltzmann constant, with unit the same as energy / K.
Definition: colvarproxy.h:99
bool b_delete_requested
Whether the entire module should be deallocated by the host engine.
Definition: colvarproxy.h:1460
double dt() const
Time step of the simulation (fs units)
Definition: colvarproxy.h:114
int clear_device_array_async(T *data, const size_t ndata, cudaStream_t stream)
Template function to clear a device array to zero asynchronously.
Definition: colvarproxy.h:1017
cvm::system_boundary_conditions boundaries_
Current system boundary conditions.
Definition: colvarproxy.h:1301
cvm::rvector get_atom_group_total_force(int index) const
Read the current total force of the given atom group.
Definition: colvarproxy.h:447
std::vector< cvm::real > atom_groups_charges
Total charges of the atom groups (allow redefinition during a run, as done e.g. in LAMMPS)
Definition: colvarproxy.h:1351
std::string engine_name_
Name of the simulation engine that the derived proxy object supports.
Definition: colvarproxy.h:1469
virtual void request_total_force(bool yesno)
Tell the proxy whether total forces are needed (they may not always be available)
Definition: colvarproxy_system.cpp:53
cvm::real max_atom_groups_applied_force() const
Get the maximum norm among all applied forces.
Definition: colvarproxy.h:514
int gpu_warp_size() const
CUDA warp size or HIP wave front size.
Definition: colvarproxy_gpu.cpp:160
virtual int init_internal_volmap_by_name(std::string const &filename)
Definition: colvarproxy_volmaps.cpp:71
virtual int get_alch_lambda(cvm::real *lambda)
Get value of alchemical lambda parameter from back-end (if available)
Definition: colvarproxy_system.cpp:88
cvm::real internal_to_angstrom(cvm::real l) const
Convert a length from internal to Angstrom.
Definition: colvarproxy.h:93
virtual int set_smp_mode(smp_mode_t mode)
Set the current SMP mode.
Definition: colvarproxy.cpp:250
cvm::rvector get_atom_total_force(int index) const
Definition: colvarproxy.h:278
virtual int backup_file(char const *filename)
Rename the given file, before overwriting it.
Definition: colvarproxy_io.cpp:107
cudaEvent_t get_event(event_type type) const
Get the default CUDA event from the proxy.
Definition: colvarproxy.h:887
void print_input_atomic_data()
Print a full list of all input atomic arrays for debug purposes.
Definition: colvarproxy.cpp:669
int tcl_run_colvar_callback(std::string const &name, std::vector< const colvarvalue * > const &cvcs, colvarvalue &value)
Tcl implementation of run_colvar_callback()
Definition: colvarproxy_tcl.cpp:108
virtual int request_alch_energy_freq(int const)
Request energy computation every freq steps (necessary for NAMD3, not all back-ends)
Definition: colvarproxy.h:174
std::vector< cvm::rvector, allocator_type< cvm::rvector > > atoms_new_colvar_forces
Forces applied from colvars, to be communicated to the MD integrator.
Definition: colvarproxy.h:1317
virtual int parse_module_config()
(Re)initialize the module
Definition: colvarproxy.cpp:563
virtual cvm::system_boundary_conditions get_system_boundaries()
Get the current system boundary conditions.
Definition: colvarproxy.h:145
cvm::rvector get_atom_group_velocity(int)
Read the current velocity of the given atom group.
Definition: colvarproxy.h:459
colvarscript * script
Definition: colvarproxy.h:664
int allocate_device(T **pp, const size_t len)
Template function to allocate device memory.
Definition: colvarproxy.h:920
bool engine_ready() const
Whether the engine allows to fully initialize Colvars immediately.
Definition: colvarproxy.h:1187
std::vector< int > volmaps_ids
Array of numeric IDs of volumetric maps (-1 if loaded internally)
Definition: colvarproxy.h:1369
int gpu_device_id() const
Get the GPU device number.
Definition: colvarproxy_gpu.cpp:116
virtual int request_engine_volmap_by_id(int volmap_id)
Definition: colvarproxy_volmaps.cpp:53
std::string get_current_work_dir() const
Get the current working directory of this process.
Definition: colvarproxy_io.cpp:60
virtual int get_d2E_dlambda2(cvm::real *d2E_dlambda2)
Get energy second derivative with respect to lambda (if available)
Definition: colvarproxy_system.cpp:123
void compute_max_volmaps_applied_force()
Compute the maximum norm among all applied forces.
Definition: colvarproxy_volmaps.cpp:115
int copy_DtoH_async(const T *d_array, T *h_array, size_t array_len, cudaStream_t stream)
Template function to copy data from device to host asynchronously.
Definition: colvarproxy.h:1071
virtual void set_replicas_mpi_communicator(replicas_mpi_comm_t comm)
Set the multiple replicas communicator.
Definition: colvarproxy_replicas.cpp:15
std::string gpu_name() const
Get the GPU name.
Definition: colvarproxy_gpu.cpp:126
std::string units
Name of the unit system used internally by Colvars (by default, that of the back-end)....
Definition: colvarproxy.h:81
virtual int load_coords_pdb(char const *filename, std::vector< cvm::atom_pos > &pos, std::vector< int > const &sorted_ids, std::string const &pdb_field, double pdb_field_value)
Load a set of coordinates from a PDB file.
Definition: colvarproxy.cpp:596
virtual int set_default_restart_frequency(int freq)
Communicate/set the restart frequency of the simulation engine.
Definition: colvarproxy_io.cpp:232
int get_version_from_string(char const *version_string)
Convert a version string "YYYY-MM-DD" into an integer.
Definition: colvarproxy.cpp:811
std::vector< int > atoms_ids
Array of 0-based integers used to uniquely associate atoms within the host program.
Definition: colvarproxy.h:1305
virtual int set_frame(long int)
Set the current frame number (as well as cvmodule->it)
Definition: colvarproxy_io.cpp:54
int replicas_mpi_rank
Index (rank) of this replica in the MPI implementation.
Definition: colvarproxy.h:1400
int close_input_streams()
Closes all input streams.
Definition: colvarproxy_io.cpp:358
int max_atoms_applied_force_id() const
Get the atom ID with the largest applied force.
Definition: colvarproxy.h:381
bool simulation_running() const
Whether a simulation is running (warn against irrecovarable errors)
Definition: colvarproxy.h:1234
Tcl_Interp * get_tcl_interp()
Get a pointer to the Tcl interpreter.
Definition: colvarproxy.h:711
virtual int close_output_stream(std::string const &output_name)
Closes the given output file/channel.
Definition: colvarproxy_io.cpp:451
cvm::real get_engine_volmap_value(int index) const
Read the current value of the volumetric map.
Definition: colvarproxy.h:566
virtual int load_internal_volmap_from_file(std::string const &filename)
Definition: colvarproxy_volmaps.cpp:77
virtual int replica_comm_recv(char *msg_data, int buf_len, int src_rep)
Receive data from other replica.
Definition: colvarproxy_replicas.cpp:62
virtual int remove_file(char const *filename)
Remove the given file (on Windows only, rename to filename.old)
Definition: colvarproxy_io.cpp:139
virtual int apply_force_dE_dlambda(cvm::real *force)
Apply a scalar force on dE_dlambda (back-end distributes it onto atoms)
Definition: colvarproxy_system.cpp:116
int backup_file(std::string const &filename)
Rename the given file, before overwriting it.
Definition: colvarproxy.h:746
virtual cudaStream_t get_default_stream()
Get the default CUDA stream from the proxy.
Definition: colvarproxy.h:877
virtual int reset()
Reset proxy state, e.g. requested atoms.
Definition: colvarproxy.cpp:518
int atoms_max_applied_force_id_
ID of the atom with the maximum norm among all applied forces.
Definition: colvarproxy.h:1326
std::string gpu_platform() const
Get the GPU platform (CUDA, HIP or SYCL)
Definition: colvarproxy_gpu.cpp:148
cvm::real kcal_mol_value_
Value of 1 kcal/mol in the internal Colvars unit for energy.
Definition: colvarproxy.h:1292
int add_volmap_slot(int volmap_id)
Create a slot for a volumetric map not requested yet.
Definition: colvarproxy_volmaps.cpp:42
void apply_engine_volmap_force(int index, cvm::real const &new_force)
Request that this force is applied to the given volumetric map by the engine.
Definition: colvarproxy.h:572
std::vector< cvm::rvector, allocator_type< cvm::rvector > > atoms_total_forces
Most recent total forces on each atom.
Definition: colvarproxy.h:1315
bool has_gpu_support() const
Whether the proxy supports GPU.
Definition: colvarproxy.h:862
char const * tcl_get_str(void *obj)
Get a string representation of the Tcl object pointed to by obj.
Definition: colvarproxy_tcl.cpp:36
void * config_queue_
Queue of config strings or files to be fed to the module.
Definition: colvarproxy.h:1472
int post_run()
Called at the end of a simulation segment (i.e. "run" command)
Definition: colvarproxy.cpp:642
bool updated_charges() const
Record whether masses have been updated.
Definition: colvarproxy.h:405
virtual int set_target_temperature(cvm::real T)
Set the current target temperature of the simulation (K units)
Definition: colvarproxy_system.cpp:24
cvm::real max_atoms_applied_force() const
Get the maximum norm among all applied forces.
Definition: colvarproxy.h:375
bool b_simulation_continuing
Definition: colvarproxy.h:1457
virtual int set_restart_output_prefix(std::string const &prefix)
Set default restart state file prefix.
Definition: colvarproxy_io.cpp:220
bool engine_ready_
Whether the engine allows to fully initialize Colvars immediately.
Definition: colvarproxy.h:1443
bool delete_requested() const
Whether deallocation was requested.
Definition: colvarproxy.h:1151
cvm::real get_atom_group_mass(int index) const
Get the mass of the given atom group.
Definition: colvarproxy.h:429
virtual void clear_atom(int index)
Used by the atom class destructor: rather than deleting the array slot (costly) set the corresponding...
Definition: colvarproxy.cpp:103
cvm::real target_temperature() const
Current target temperature of the simulation (K units)
Definition: colvarproxy.h:105
int deallocate_device(T **pp)
Template function to deallocate device memory.
Definition: colvarproxy.h:980
std::string const & restart_output_prefix() const
Prefix of the restart (checkpoint) file to be written next.
Definition: colvarproxy.h:789
virtual int init_atom(int atom_number)
Definition: colvarproxy.cpp:66
virtual int get_frame(long int &)
Save the current frame number in the argument given.
Definition: colvarproxy_io.cpp:48
std::vector< size_t > atom_groups_refcount
Keep track of how many times each group is used by a separate cvc.
Definition: colvarproxy.h:1347
int allocate_device_async(T **pp, const size_t len, cudaStream_t stream)
Template function to allocate device memory asynchronously.
Definition: colvarproxy.h:969
size_t features_hash
Track which features have been acknowledged during the last run.
Definition: colvarproxy.h:1466
bool updated_masses_
Whether the masses and charges have been updated from the host code.
Definition: colvarproxy.h:1332
int copy_DtoD(const T *d_src, T *d_dst, size_t array_len)
Template function to copy data from device to device.
Definition: colvarproxy.h:1084
int remove_file(std::string const &filename)
Remove the given file (on Windows only, rename to filename.old)
Definition: colvarproxy.h:755
virtual int smp_unlock()
Release the lock.
Definition: colvarproxy.cpp:369
virtual int flush_output_streams()
Flushes all output files/channels.
Definition: colvarproxy_io.cpp:435
int get_volmap_id(int index) const
Get the numeric ID of the given volumetric map (for the MD program)
Definition: colvarproxy.h:560
bool total_force_requested
Whether the total forces have been requested.
Definition: colvarproxy.h:1295
void increase_refcount(int index)
Definition: colvarproxy.h:257
virtual int smp_biases_script_loop()
Distribute calculation of biases across threads 2nd through last, with all scripted biased on 1st thr...
Definition: colvarproxy.cpp:304
virtual std::vector< smp_mode_t > get_available_smp_modes() const
Get available SMP modes.
Definition: colvarproxy.cpp:236
virtual int check_scalable_group_coms()
Check if this proxy supports offloaded computation of centers of mass (outside Colvars)
Definition: colvarproxy.cpp:179
virtual int check_atom_name_selections_available()
Check whether it is possible to select atoms by residue number name.
Definition: colvarproxy.cpp:78
virtual float * proxy_atoms_masses_gpu_float()
Functions to get device pointers for atom properties This functions should be overridden in derived p...
Definition: colvarproxy.h:1121
virtual int rename_file(char const *filename, char const *newfilename)
Rename the given file.
Definition: colvarproxy_io.cpp:172
cvm::real cached_alch_lambda
Next value of lambda to be sent to back-end.
Definition: colvarproxy.h:1268
bool input_stream_exists(std::string const &input_name)
Check if the file/channel is open (without opening it if not)
Definition: colvarproxy_io.cpp:309
virtual int smp_num_threads()
Number of threads sharing this address space.
Definition: colvarproxy.cpp:340
virtual smp_mode_t get_preferred_smp_mode() const
Get the preferred SMP mode.
Definition: colvarproxy.cpp:246
void compute_rms_atoms_applied_force()
Compute the root-mean-square of the applied forces.
Definition: colvarproxy.cpp:125
std::map< std::string, std::istream * > input_streams_
Container of input files/channels indexed by path name.
Definition: colvarproxy.h:1421
void apply_atom_group_force(int index, cvm::rvector const &new_force)
Request that this force is applied to the given atom group.
Definition: colvarproxy.h:453
virtual int check_atom_id(int atom_number)
Definition: colvarproxy.cpp:72
event_type
Available CUDA event types.
Definition: colvarproxy.h:881
bool updated_masses() const
Record whether masses have been updated.
Definition: colvarproxy.h:399
bool modified_atom_list_
Whether the atom list has been modified internally.
Definition: colvarproxy.h:1329
bool cached_alch_lambda_changed
Whether lambda has been set and needs to be updated in backend.
Definition: colvarproxy.h:1271
virtual int init_internal_volmap_by_id(int volmap_id)
Definition: colvarproxy_volmaps.cpp:65
void print_output_atomic_data()
Print a full list of all applied forces for debug purposes.
Definition: colvarproxy.cpp:751
int version_number() const
Get the version number (higher = more recent)
Definition: colvarproxy.h:1260
int copy_DtoD_async(const T *d_src, T *d_dst, size_t array_len, cudaStream_t stream)
Template function to copy data from device to device asynchronously.
Definition: colvarproxy.h:1098
virtual int clear_volmap(int index)
Used by the CVC destructors.
Definition: colvarproxy_volmaps.cpp:83
int get_atom_id(int index) const
Definition: colvarproxy.h:243
int warp_size
Warp size.
Definition: colvarproxy.h:1436
void compute_max_atoms_applied_force()
Compute the maximum norm among all applied forces.
Definition: colvarproxy.cpp:132
virtual int set_input_prefix(std::string const &prefix)
Initialize input_prefix (NOTE: it will be erased after state file is read)
Definition: colvarproxy_io.cpp:196
int find_atom_by_id(int atom_id)
Find the index of an atom by its ID.
Definition: colvarproxy.cpp:54
std::vector< cvm::real, allocator_type< cvm::real > > atoms_masses
Masses of the atoms (allow redefinition during a run, as done e.g. in LAMMPS)
Definition: colvarproxy.h:1309
std::istream & input_stream_from_string(std::string const &input_name, std::string const &content, std::string const description="string")
Definition: colvarproxy_io.cpp:275
virtual int smp_biases_loop()
Distribute calculation of biases across threads.
Definition: colvarproxy.cpp:281
void apply_atom_force(int index, cvm::rvector const &new_force)
Definition: colvarproxy.h:286
virtual int setup()
(Re)initialize required member data (called after the module)
Definition: colvarproxy.cpp:546
virtual int compute_volmap(int flags, int volmap_index, cvm::atom_group *ag, cvm::real *value, cvm::real *atom_field)
Re-weigh an atomic field (e.g. a colvar) by the value of a volumetric map.
Definition: colvarproxy_volmaps.cpp:98
cvm::real volmaps_rms_applied_force_
Root-mean-square of the the applied forces.
Definition: colvarproxy.h:1384
std::vector< cvm::rvector > atom_groups_total_forces
Most recently updated total forces on the com of each group.
Definition: colvarproxy.h:1355
int reallocate_host(T **pp, const size_t len)
Template function to reallocate host-pinned memory.
Definition: colvarproxy.h:953
std::vector< cvm::real > volmaps_values
Current total values of the volmaps (when computed by the MD engine)
Definition: colvarproxy.h:1375
size_t get_num_active_atoms() const
Return number of atoms with positive reference count.
Definition: colvarproxy.cpp:115
bool total_forces_valid() const
Are total forces currently valid? (They would not be right after configuration change)
Definition: colvarproxy.h:1193
smp_mode_t smp_mode
Definition: colvarproxy.h:1394
cvm::real get_atom_charge(int index) const
Definition: colvarproxy.h:264
std::vector< std::string > volmaps_filenames
Names of files containing maps (empty when maps are loaded by MD engine)
Definition: colvarproxy.h:1381
virtual cvm::real get_accelMD_factor() const
Get weight factor from accelMD.
Definition: colvarproxy.h:191
virtual int load_atoms_pdb(char const *filename, cvm::atom_group &atoms, std::string const &pdb_field, double pdb_field_value)
Read a selection of atom IDs from a PDB coordinate file.
Definition: colvarproxy.cpp:585
std::istream & input_stream(std::string const &input_name, std::string const description="file/channel", bool error_on_fail=true)
Definition: colvarproxy_io.cpp:241
virtual smp_mode_t get_smp_mode() const
Get the current SMP mode.
Definition: colvarproxy.cpp:232
replicas_mpi_comm_t replicas_mpi_comm
MPI communicator containint 1 root proc from each world.
Definition: colvarproxy.h:1397
std::string gpu_bus_id() const
Get the GPU PCI bus ID.
Definition: colvarproxy_gpu.cpp:137
virtual void error(std::string const &message)
Print a message to the main log and/or let the host code know about it.
Definition: colvarproxy.cpp:782
int time_step_factor_
Current timestep multiplier, if Colvars is only called once every n MD timesteps.
Definition: colvarproxy.h:1283
bool modified_atom_list() const
Whether the atom list has been modified internally.
Definition: colvarproxy.h:387
void set_total_forces_invalid()
Mark the total forces as invalid (due to e.g. a configuration change)
Definition: colvarproxy.cpp:654
cvm::real angstrom_value_
Value of 1 Angstrom in the internal (front-end) Colvars unit for atomic coordinates.
Definition: colvarproxy.h:1289
int deallocate_host(T **pp)
Template function to deallocate host-pinned memory.
Definition: colvarproxy.h:908
cvm::real get_atom_mass(int index) const
Definition: colvarproxy.h:250
bool & use_internal_pbc()
Account for system boundaries within the Colvars library (as opposed to using the MD engine)
Definition: colvarproxy.h:138
virtual bool total_forces_same_step() const
Definition: colvarproxy_system.cpp:67
cvm::real atom_groups_rms_applied_force_
Root-mean-square of the applied group forces.
Definition: colvarproxy.h:1360
cvm::real atoms_rms_applied_force_
Root-mean-square of the applied forces.
Definition: colvarproxy.h:1320
std::string output_prefix_str
Default prefix to be used for all output files (final configuration)
Definition: colvarproxy.h:1412
int copy_HtoD(const T *h_array, T *d_array, size_t array_len)
Template function to copy data from host to device.
Definition: colvarproxy.h:1030
virtual int smp_loop(int n_items, std::function< int(int)> const &worker)
Distribute computation over threads using OpenMP, unless overridden in the backend (e....
Definition: colvarproxy.cpp:262
cvm::real atom_groups_max_applied_force_
Maximum norm among all applied group forces.
Definition: colvarproxy.h:1363
virtual int close_output_streams()
Close all open files/channels to prevent data loss.
Definition: colvarproxy_io.cpp:468
bool b_simulation_running
Whether a simulation is running (warn against irrecovarable errors)
Definition: colvarproxy.h:1452
std::string const & output_prefix() const
Default prefix to be used for all output files (final configuration)
Definition: colvarproxy.h:780
colvarmodule * cvmodule
Pointer to the associated colvarmodule object.
Definition: colvarproxy.h:1132
int tcl_run_colvar_gradient_callback(std::string const &name, std::vector< const colvarvalue * > const &cvcs, std::vector< cvm::matrix2d< cvm::real > > &gradient)
Tcl implementation of run_colvar_gradient_callback()
Definition: colvarproxy_tcl.cpp:155
omp_lock_t * omp_lock_state
Lock state for OpenMP.
Definition: colvarproxy.h:1390
bool total_forces_valid_
Whether the total forces are currently valid.
Definition: colvarproxy.h:1446
Tcl_Interp * tcl_interp_
Pointer to Tcl interpreter object.
Definition: colvarproxy.h:1406
virtual int send_alch_lambda()
Send cached value of alchemical lambda parameter to back-end (if available)
Definition: colvarproxy_system.cpp:102
std::vector< cvm::real > atom_groups_masses
Total masses of the atom groups.
Definition: colvarproxy.h:1349
std::ostream * output_stream_error_
Object whose reference is returned when write errors occur.
Definition: colvarproxy.h:1430
void compute_rms_atom_groups_applied_force()
Compute the root-mean-square of the applied forces.
Definition: colvarproxy.cpp:217
std::vector< cvm::rvector > atom_groups_coms
Current centers of mass of the atom groups.
Definition: colvarproxy.h:1353
virtual cvm::real rand_gaussian(void)
Pseudo-random number with Gaussian distribution.
Definition: colvarproxy_system.cpp:43
std::vector< size_t > volmaps_refcount
Keep track of how many times each vol map is used by a separate colvar object.
Definition: colvarproxy.h:1372
bool support_gpu
Whether the proxy supports GPU.
Definition: colvarproxy.h:1433
virtual int run_force_callback()
Run a user-defined colvar forces script.
Definition: colvarproxy.cpp:380
cvm::real indirect_lambda_biasing_force
Force to be applied onto alch. lambda, propagated from biasing forces on dE_dlambda.
Definition: colvarproxy.h:188
virtual int smp_trylock()
Attempt to lock the proxy's shared data.
Definition: colvarproxy.cpp:359
cvm::real boltzmann_
Boltzmann constant in internal Colvars units.
Definition: colvarproxy.h:1274
virtual int get_dE_dlambda(cvm::real *dE_dlambda)
Get energy derivative with respect to lambda (if available)
Definition: colvarproxy_system.cpp:109
virtual void add_energy(cvm::real energy)
Pass restraint energy value for current timestep to MD engine.
Definition: colvarproxy_system.cpp:50
virtual void replica_comm_barrier()
Synchronize replica with others.
Definition: colvarproxy_replicas.cpp:54
int reset_atoms()
Clear atomic data.
Definition: colvarproxy.cpp:27
virtual void init_tcl_pointers()
Set Tcl pointers.
Definition: colvarproxy_tcl.cpp:18
virtual int smp_thread_id()
Index of this thread.
Definition: colvarproxy.cpp:330
virtual bool total_forces_enabled() const
Are total forces being used?
Definition: colvarproxy_system.cpp:61
int add_atom_slot(int atom_id)
Definition: colvarproxy.cpp:40
int reset_volmaps()
Clear volumetric map data.
Definition: colvarproxy_volmaps.cpp:27
virtual int replica_index()
Index of this replica.
Definition: colvarproxy_replicas.cpp:42
virtual std::ostream & output_stream(std::string const &output_name, std::string const description)
Definition: colvarproxy_io.cpp:384
cvm::real angstrom_to_internal(cvm::real l) const
Convert a length from Angstrom to internal.
Definition: colvarproxy.h:87
size_t get_num_active_atom_groups() const
Return number of atom groups with positive reference count.
Definition: colvarproxy.cpp:207
int reset_atom_groups()
Clear atom group data.
Definition: colvarproxy.cpp:153
Allocator for pinned host memory using cudaHostAlloc.
Definition: colvar_gpu_support.h:360
Definition: colvarscript.h:30
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43
Store the information of a group of atoms in a structure-of-arrays (SoA) style.
Definition: colvaratoms.h:52
Collective variables main module.