19 #include "colvartypes.h"
20 #include "colvar_gpu_support.h"
21 #include "colvars_system.h"
49 typedef MPI_Comm replicas_mpi_comm_t;
51 typedef void * replicas_mpi_comm_t;
54 #if defined(NAMD_TCL) || defined(VMDTCL)
62 typedef void Tcl_Interp;
114 inline double dt()
const
193 "is not yet implemented in the MD engine.\n",
194 COLVARS_NOT_IMPLEMENTED);
197 virtual bool accelMD_enabled()
const {
201 #if ( defined(COLVARS_CUDA) || defined(COLVARS_HIP) )
202 template <
typename T>
205 template <
typename T>
206 using allocator_type = std::allocator<T>;
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>>;
226 std::string
const &atom_name,
227 std::string
const &segment_id);
231 std::string
const &atom_name,
232 std::string
const &segment_id);
295 "is not yet implemented.\n",
296 COLVARS_NOT_IMPLEMENTED);
300 inline std::vector<int>
const *get_atom_ids()
const
308 inline atom_buffer_real_t
const *get_atom_masses()
const
313 inline atom_buffer_real_t *modify_atom_masses()
320 inline atom_buffer_real_t
const *get_atom_charges()
325 inline atom_buffer_real_t *modify_atom_charges()
328 updated_charges_ =
true;
332 inline atom_buffer_rvector_t
const *get_atom_positions()
const
337 inline atom_buffer_rvector_t *modify_atom_positions()
342 inline atom_buffer_rvector_t
const *get_atom_total_forces()
const
347 inline atom_buffer_rvector_t *modify_atom_total_forces()
352 inline atom_buffer_rvector_t
const *get_atom_applied_forces()
const
357 inline atom_buffer_rvector_t *modify_atom_applied_forces()
407 return updated_charges_;
462 COLVARS_NOT_IMPLEMENTED);
466 inline std::vector<int>
const *get_atom_group_ids()
const
474 inline std::vector<cvm::real> *modify_atom_group_masses()
480 inline std::vector<cvm::real> *modify_atom_group_charges()
486 inline std::vector<cvm::rvector> *modify_atom_group_positions()
491 inline std::vector<cvm::rvector> *modify_atom_group_total_forces()
496 inline std::vector<cvm::rvector> *modify_atom_group_applied_forces()
592 volmap_flag_null = 0,
593 volmap_flag_gradients = 1,
594 volmap_flag_use_atom_field = (1<<8)
603 enum class smp_mode_t {cvcs, inner_loop, gpu, none};
618 virtual int smp_loop(
int n_items, std::function<
int (
int)>
const &worker);
669 virtual int run_colvar_callback(
670 std::string
const &name,
671 std::vector<const colvarvalue *>
const &cvcs,
674 virtual int run_colvar_gradient_callback(
675 std::string
const &name,
676 std::vector<const colvarvalue *>
const &cvcs,
681 #if defined(COLVARS_TCL)
691 int tcl_run_script(std::string
const &
script);
693 int tcl_run_file(std::string
const &fileName);
700 std::string
const &name,
701 std::vector<const colvarvalue *>
const &cvcs,
706 std::string
const &name,
707 std::vector<const colvarvalue *>
const &cvcs,
740 std::string
join_paths(std::string
const &path1, std::string
const &path2)
const;
761 virtual int rename_file(
char const *filename,
char const *newfilename);
765 std::string
const &newfilename)
767 return rename_file(filename.c_str(), newfilename.c_str());
813 std::istream &
input_stream(std::string
const &input_name,
814 std::string
const description =
"file/channel",
815 bool error_on_fail =
true);
822 std::string
const &content,
823 std::string
const description =
"string");
843 virtual std::ostream &
output_stream(std::string
const &output_name,
844 std::string
const description);
875 #if defined (COLVARS_CUDA) || defined (COLVARS_HIP) || defined (COLVARS_SYCL)
896 template <
typename T>
907 template <
typename T>
909 return deallocate_host_T((
void **)pp);
919 template <
typename T>
921 return allocate_device_T((
void **)pp, len,
sizeof(T));
934 template <
typename T>
936 int error_code = COLVARS_OK;
938 error_code |= allocate_device_T((
void **)pp, len,
sizeof(T));
952 template <
typename T>
954 int error_code = COLVARS_OK;
968 template <
typename T>
970 return allocate_device_T_async((
void **)pp, len,
sizeof(T), stream);
979 template <
typename T>
981 return deallocate_device_T((
void **)pp);
991 template <
typename T>
993 return deallocate_device_T_async((
void **)pp, stream);
1003 template <
typename T>
1005 return clear_device_array_T(data, ndata,
sizeof(T));
1016 template <
typename T>
1018 return clear_device_array_T_async(data, ndata,
sizeof(T), stream);
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));
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);
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));
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);
1083 template <
typename T>
1085 return copy_DtoD_T(d_src, d_dst, array_len,
sizeof(T));
1097 template <
typename T>
1099 return copy_DtoD_T_async(d_src, d_dst, array_len,
sizeof(T), stream);
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);
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;}
1140 inline std::string
const &engine_name()
const
1157 virtual int reset();
1169 std::string
const &pdb_field,
double pdb_field_value);
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);
1184 virtual int setup();
1205 void add_config(std::string
const &cmd, std::string
const &conf);
1219 virtual void log(std::string
const &message);
1222 virtual void error(std::string
const &message);
1438 #if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
1439 std::array<cudaEvent_t, static_cast<int>(event_type::num_event_types)> events = {};
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.