10#ifndef COLVARPROXY_NAMD_H
11#define COLVARPROXY_NAMD_H
15#include "colvarproxy_namd_version.h"
24#include "colvarvalue.h"
29class GridforceFullMainGrid;
110#if !defined (NAMD_UNIFIED_REDUCTION)
113#if defined(NODEGROUP_FORCE_REGISTER) && !defined(NAMD_UNIFIED_REDUCTION)
114 NodeReduction *nodeReduction;
120 void update_accelMD_info();
126 void log(std::string
const &message)
override;
127 void error(std::string
const &message)
override;
138 int run_colvar_callback(std::string
const &name,
139 std::vector<const colvarvalue *>
const &cvcs,
141 int run_colvar_gradient_callback(std::string
const &name,
142 std::vector<const colvarvalue *>
const &cvcs,
149 bool accelMD_enabled()
const override;
151#if CMK_SMP && USE_CKLOOP
153 return smp_mode_t::cvcs;
156 std::vector<colvarproxy_smp::smp_mode_t> available_modes{
158 smp_mode_t::inner_loop,
161 return available_modes;
164 int smp_loop(
int n_items, std::function<
int (
int)>
const &worker)
override;
170 friend void calc_colvars_items_smp(
int first,
int last,
void *result,
int paramNum,
void *param);
171 friend void calc_cv_biases_smp(
int first,
int last,
void *result,
int paramNum,
void *param);
172 friend void calc_cv_scripted_forces(
int paramNum,
void *param);
181 return CkMyNodeSize();
186 CmiNodeLock charm_lock_state;
192 CmiLock(charm_lock_state);
198 const int ret = CmiTryLock(charm_lock_state);
199 if (ret == 0)
return COLVARS_OK;
200 else return COLVARS_ERROR;
205 CmiUnlock(charm_lock_state);
222 std::string
const &atom_name,
223 std::string
const &segment_id)
override;
225 std::string
const &atom_name,
226 std::string
const &segment_id)
override;
229 void update_atom_properties(
int index);
231 enum class e_pdb_field {
241 e_pdb_field pdb_field_str2enum(std::string
const &pdb_field_str);
245 std::string
const &pdb_field,
246 double pdb_field_value)
override;
249 std::vector<cvm::atom_pos> &pos,
250 const std::vector<int> &indices,
251 std::string
const &pdb_field,
252 double const pdb_field_value)
override;
260 int update_group_properties(
int index);
302 template<
class T,
int flags>
309 std::string
const description)
override;
Definition: GlobalMasterColvars.h:11
Arbitrary size array (two dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:376
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:99
int residue_id
Residue identifier.
Definition: colvarmodule.h:248
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:96
std::vector< int > atoms_ids
Array of 0-based integers used to uniquely associate atoms within the host program.
Definition: colvarproxy.h:267
Communication between colvars and NAMD (implementation of colvarproxy)
Definition: colvarproxy_namd.h:35
cvm::real get_accelMD_factor() const override
Get weight factor from accelMD.
void init_tcl_pointers() override
Set Tcl pointers.
void send_gm_atom_forces()
Send Colvars forces to GlobalMaster.
int request_alch_energy_freq(int const freq)
Request energy computation every freq steps.
GlobalMasterColvars * globalmaster
Pointer to the parent GlobalMaster object.
Definition: colvarproxy_namd.h:86
int clear_volmap(int index) override
Used by the CVC destructors.
int replica_index() override
Index of this replica.
int request_engine_volmap_by_id(int volmap_id) override
Select a MGridForces map for computation by NAMD.
int init_atom(cvm::residue_id const &residue, std::string const &atom_name, std::string const &segment_id) override
int load_atoms_pdb(char const *filename, cvm::atom_group &atoms, std::string const &pdb_field, double pdb_field_value) override
Read a selection of atom IDs from a PDB coordinate file.
bool total_forces_enabled() const override
Are total forces being used?
Definition: colvarproxy_namd.h:132
void clear_atom(int index) override
Used by the atom class destructor: rather than deleting the array slot (costly) set the corresponding...
int init_atom(int atom_number) override
void error(std::string const &message) override
Print a message to the main log and/or let the host code know about it.
int update_target_temperature()
Get the target temperature from the NAMD thermostats supported so far.
bool first_timestep
Use to distinguish between "run 0" and actual runs.
Definition: colvarproxy_namd.h:101
int replica_comm_send(char *msg_data, int msg_len, int dest_rep) override
Send data to other replica.
int send_alch_lambda(void)
Set value of alchemical lambda parameter in back-end.
void add_energy(cvm::real energy) override
Pass restraint energy value for current timestep to MD engine.
void clear_atom_group(int index) override
Used by the atom_group class destructor.
int init_atom_group(std::vector< int > const &atoms_ids) override
Prepare this group for collective variables calculation, selecting atoms by internal ids (0-based)
SimParameters * simparams
Pointer to the NAMD simulation input object.
Definition: colvarproxy_namd.h:92
void request_globalmaster_volmap(int volmap_id)
Add map to GlobalMaster client (if not already in them)
cvm::step_number NAMD_step
Current NAMD simulation step (promoted from int)
Definition: colvarproxy_namd.h:104
int check_engine_volmaps_available() override
Test whether the engine supports offloaded computation of volumetric maps.
Controller const * controller
Pointer to Controller object.
Definition: colvarproxy_namd.h:95
int load_coords_pdb(char const *filename, std::vector< cvm::atom_pos > &pos, const std::vector< int > &indices, std::string const &pdb_field, double const pdb_field_value) override
Load a set of coordinates from a PDB file.
int init()
Initialize proxy data based on the chosen interface.
int setup() override
(Re)initialize required member data (called after the module)
int load_internal_volmap_from_file(std::string const &filename) override
Load a map internally independent from MGridForces.
int backup_file(char const *filename) override
Rename the given file, before overwriting it.
int set_unit_system(std::string const &units_in, bool check_only) override
Request to set the units used internally by Colvars.
int num_replicas() override
Total number of replicas.
std::vector< int > gm_atoms_map
Map from NAMD atom indices to colvarproxy array indices (used by GlobalMaster)
Definition: colvarproxy_namd.h:89
void init_gm_atoms_map()
Create map from NAMD atom indices to colvarproxy array indices (used by GlobalMaster)
void set_gm_object(GlobalMasterColvars *gm)
Tell the proxy that it will be using the GlobalMaster interface.
int update_gm_atoms_map(AtomIDList::const_iterator begin, AtomIDList::const_iterator end)
Update map to reflect other requested atoms, including other GlobalMaster objects.
int check_atom_id(int atom_number) override
cvm::step_number previous_NAMD_step
Previous NAMD simulation step; used to test if the simulation is advancing.
Definition: colvarproxy_namd.h:107
int check_replicas_enabled() override
Indicate if multi-replica support is available and active.
int request_engine_volmap_by_name(std::string const &volmap_name) override
Select a MGridForces map for computation by NAMD.
std::vector< std::unique_ptr< GridforceFullMainGrid > > internal_gridforce_grids_
Pointers to internally managed maps (set to nullptr for maps loaded by NAMD)
Definition: colvarproxy_namd.h:336
std::ostream & output_stream(std::string const &output_name, std::string const description) override
int setup_gm_atom_group_buffers()
Create and zero out data buffers for atom groups requested through GlobalMaster.
int init_module()
Initialize the module.
int close_output_stream(std::string const &output_name) override
Closes the given output file/channel.
int setup_gm_volmap_buffers()
Create and zero out data buffers for grid objects requested through GlobalMaster.
int get_dE_dlambda(cvm::real *dE_dlambda)
Get energy derivative with respect to lambda.
int flush_output_streams() override
Flushes all output files/channels.
std::unique_ptr< Random > random
NAMD-style PRNG object.
Definition: colvarproxy_namd.h:98
int check_volmaps_available() override
Test whether the engine provides code to load volumetric maps as CVs.
cvm::real rand_gaussian() override
Pseudo-random number with Gaussian distribution.
int run_force_callback() override
Run a user-defined colvar forces script.
void log(std::string const &message) override
Print a message to the main log.
void read_gm_atom_buffers()
Read the current coordinates and total forces.
void replica_comm_barrier() override
Synchronize replica with others.
int setup_gm_atom_buffers()
Create and zero out data buffers for atoms requested through GlobalMaster.
int check_atom_id(cvm::residue_id const &residue, std::string const &atom_name, std::string const &segment_id) override
Check that this atom is valid, but do not initialize it yet.
int compute_volmap(int flags, int index, cvm::atom_group *ag, cvm::real *value, cvm::real *atom_field) override
Re-weigh an atomic field (e.g. a colvar) by the value of a volumetric map.
int reset() override
Reset proxy state, e.g. requested atoms.
void GridForceGridLoop(T const *g, cvm::atom_group *ag, cvm::real *value, cvm::real *atom_field)
Implementation of inner loop; allows for atom list computation and use.
bool accelMDOn
Accelerated MD reweighting factor.
Definition: colvarproxy_namd.h:118
int check_scalable_group_coms() override
Check if this proxy supports offloaded computation of centers of mass (outside Colvars)
SubmitReduction * reduction
Used to submit restraint energy as MISC.
Definition: colvarproxy_namd.h:111
void request_gm_atom_by_id(int aid, int index)
void getGridForceGridValue(int flags, T const *grid, cvm::atom_group *ag, cvm::real *value, cvm::real *atom_field)
Abstraction of the two types of NAMD volumetric maps.
void request_total_force(bool yesno) override
Tell the proxy whether total forces are needed (they may not always be available)
int flush_output_stream(std::string const &output_name) override
Flushes the given output file/channel.
int get_alch_lambda(cvm::real *lambda)
Get value of alchemical lambda parameter from back-end.
int init_internal_volmap_by_id(int volmap_id) override
Select a MGridForces map for internal computation (frontend)
int init_internal_volmap_by_name(std::string const &volmap_name) override
Select a MGridForces map for internal computation (frontend)
int close_output_streams() override
Close all open files/channels to prevent data loss.
int check_atom_name_selections_available() override
Check whether it is possible to select atoms by residue number name.
int replica_comm_recv(char *msg_data, int buf_len, int src_rep) override
Receive data from other replica.
virtual std::vector< smp_mode_t > get_available_smp_modes() const
Get available SMP modes.
Definition: colvarproxy.cpp:285
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:352
virtual int smp_thread_id()
Index of this thread.
Definition: colvarproxy.cpp:380
virtual int smp_trylock()
Attempt to lock the proxy's shared data.
Definition: colvarproxy.cpp:409
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:400
virtual int smp_num_threads()
Number of threads sharing this address space.
Definition: colvarproxy.cpp:390
virtual int smp_unlock()
Release the lock.
Definition: colvarproxy.cpp:419
virtual int smp_biases_loop()
Distribute calculation of biases across threads.
Definition: colvarproxy.cpp:330
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:311
virtual smp_mode_t get_preferred_smp_mode() const
Get the preferred SMP mode.
Definition: colvarproxy.cpp:295
bool total_force_requested
Whether the total forces have been requested.
Definition: colvarproxy_system.h:182
Definition: colvarproxy.h:568
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.