Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvarproxy_namd.h
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_NAMD_H
11#define COLVARPROXY_NAMD_H
12
13#ifndef NAMD_VERSION_NUMBER
14// Assume 2.14b1 for now until the NAMD macro is merged
15#define NAMD_VERSION_NUMBER 34471681
16#endif
17
18#include "colvarproxy_namd_version.h"
19
20#include "Vector.h"
21#include "ResizeArray.h"
22#include "NamdTypes.h"
23#include "SimParameters.h"
24#include "Lattice.h"
25#include "GlobalMaster.h"
26#include "Random.h"
27
28#include "colvarmodule.h"
29#include "colvarproxy.h"
30#include "colvarvalue.h"
31
32#define GLOBAL_MASTER_CKLOOP_CALC_ITEM 2000
33#define GLOBAL_MASTER_CKLOOP_CALC_BIASES 2001
34#define GLOBAL_MASTER_CKLOOP_CALC_SCRIPTED_BIASES 2002
35
38class colvarproxy_namd : public colvarproxy, public GlobalMaster {
39
40protected:
41
44 std::vector<int> atoms_map;
45
47 SimParameters *simparams;
48
50 Random random;
51
52 bool first_timestep;
53 cvm::step_number previous_NAMD_step;
54
56 SubmitReduction *reduction;
57#ifdef NODEGROUP_FORCE_REGISTER
58 NodeReduction *nodeReduction;
59#endif
60
63 cvm::real amd_weight_factor;
64 void update_accelMD_info();
65
66public:
67
68 void init_tcl_pointers() override;
69
70 friend class cvm::atom;
71
74
75 int setup() override;
76 int reset() override;
77
80
83
84 // synchronize the local arrays with requested or forced atoms
85 int update_atoms_map(AtomIDList::const_iterator begin,
86 AtomIDList::const_iterator end);
87
88 void calculate();
89
90 void log(std::string const &message) override;
91 void error(std::string const &message) override;
92 int set_unit_system(std::string const &units_in, bool check_only) override;
93 void add_energy(cvm::real energy) override;
94 void request_total_force(bool yesno) override;
95
96 bool total_forces_enabled() const override
97 {
99 }
100
101 int run_force_callback() override;
102 int run_colvar_callback(std::string const &name,
103 std::vector<const colvarvalue *> const &cvcs,
104 colvarvalue &value) override;
105 int run_colvar_gradient_callback(std::string const &name,
106 std::vector<const colvarvalue *> const &cvcs,
107 std::vector<cvm::matrix2d<cvm::real> > &gradient) override;
108
110 {
111 return random.gaussian();
112 }
113
114 cvm::real get_accelMD_factor() const override {
115 return amd_weight_factor;
116 }
117
118 bool accelMD_enabled() const override {
119 return accelMDOn;
120 }
121
122#if CMK_SMP && USE_CKLOOP
123 int check_smp_enabled() override;
124
125 int smp_colvars_loop() override;
126
127 int smp_biases_loop();
128
130
131 friend void calc_colvars_items_smp(int first, int last, void *result, int paramNum, void *param);
132 friend void calc_cv_biases_smp(int first, int last, void *result, int paramNum, void *param);
133 friend void calc_cv_scripted_forces(int paramNum, void *param);
134
135 int smp_thread_id()
136 {
137 return CkMyRank();
138 }
139
140 int smp_num_threads()
141 {
142 return CkMyNodeSize();
143 }
144
145protected:
146
147 CmiNodeLock charm_lock_state;
148
149public:
150
151 int smp_lock()
152 {
153 charm_lock_state = CmiCreateLock();
154 return COLVARS_OK;
155 }
156
157 int smp_trylock()
158 {
159 return COLVARS_NOT_IMPLEMENTED;
160 }
161
162 int smp_unlock()
163 {
164 CmiDestroyLock(charm_lock_state);
165 return COLVARS_OK;
166 }
167
168#endif // #if CMK_SMP && USE_CKLOOP
169
170 int replica_enabled() override;
171 int replica_index() override;
172 int num_replicas() override;
173 void replica_comm_barrier() override;
174 int replica_comm_recv(char* msg_data, int buf_len, int src_rep) override;
175 int replica_comm_send(char* msg_data, int msg_len, int dest_rep) override;
176
178 int init_atom(int atom_number) override;
179 int check_atom_id(int atom_number) override;
180 int init_atom(cvm::residue_id const &residue,
181 std::string const &atom_name,
182 std::string const &segment_id) override;
183 int check_atom_id(cvm::residue_id const &residue,
184 std::string const &atom_name,
185 std::string const &segment_id) override;
186 void clear_atom(int index) override;
187
188 void update_atom_properties(int index);
189
191 cvm::atom_pos const &pos2) const;
192
193 int load_atoms_pdb(char const *filename,
194 cvm::atom_group &atoms,
195 std::string const &pdb_field,
196 double const pdb_field_value) override;
197
198 int load_coords_pdb(char const *filename,
199 std::vector<cvm::atom_pos> &pos,
200 const std::vector<int> &indices,
201 std::string const &pdb_field,
202 double const pdb_field_value) override;
203
204
205 int scalable_group_coms() override
206 {
207 return COLVARS_OK;
208 }
209 int init_atom_group(std::vector<int> const &atoms_ids) override;
210 void clear_atom_group(int index) override;
211
212 int update_group_properties(int index);
213
214#if NAMD_VERSION_NUMBER >= 34471681
215
217
218 int init_volmap_by_id(int volmap_id) override;
219
220 int init_volmap_by_name(const char *volmap_name) override;
221
222 int check_volmap_by_id(int volmap_id) override;
223
224 int check_volmap_by_name(char const *volmap_name) override;
225
226 int get_volmap_id_from_name(char const *volmap_name) override;
227
228 void clear_volmap(int index) override;
229
230 int compute_volmap(int flags,
231 int volmap_id,
232 cvm::atom_iter atom_begin,
233 cvm::atom_iter atom_end,
234 cvm::real *value,
235 cvm::real *atom_field) override;
236
238 template<class T>
239 void getGridForceGridValue(int flags,
240 T const *grid,
241 cvm::atom_iter atom_begin,
242 cvm::atom_iter atom_end,
243 cvm::real *value,
244 cvm::real *atom_field);
245
247 template<class T, int flags>
248 void GridForceGridLoop(T const *g,
249 cvm::atom_iter atom_begin,
250 cvm::atom_iter atom_end,
251 cvm::real *value,
252 cvm::real *atom_field);
253
254#endif
255
256 std::ostream &output_stream(std::string const &output_name,
257 std::string const description) override;
258
259 int flush_output_stream(std::string const &output_name) override;
260
261 int flush_output_streams() override;
262
263 int close_output_stream(std::string const &output_name) override;
264
265 int close_output_streams() override;
266
267 int backup_file(char const *filename) override;
268
269};
270
271
272#endif
Group of atom objects, mostly used by a colvar::cvc object to gather all atomic data.
Definition: colvaratoms.h:159
Stores numeric id, mass and all mutable data for an atom, mostly used by a colvar::cvc.
Definition: colvaratoms.h:31
Arbitrary size array (two dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:376
vector of real numbers with three components
Definition: colvartypes.h:727
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:95
int residue_id
Residue identifier.
Definition: colvarmodule.h:193
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:92
std::vector< int > atoms_ids
Array of 0-based integers used to uniquely associate atoms within the host program.
Definition: colvarproxy.h:253
Communication between colvars and NAMD (implementation of colvarproxy)
Definition: colvarproxy_namd.h:38
cvm::real get_accelMD_factor() const override
Get weight factor from accelMD.
Definition: colvarproxy_namd.h:114
void init_tcl_pointers() override
Set Tcl pointers.
int init_volmap_by_id(int volmap_id) override
int check_volmap_by_id(int volmap_id) override
int replica_index() override
Index of this replica.
int init_atom(cvm::residue_id const &residue, std::string const &atom_name, std::string const &segment_id) override
bool total_forces_enabled() const override
Are total forces being used?
Definition: colvarproxy_namd.h:96
Random random
NAMD-style PRNG object.
Definition: colvarproxy_namd.h:50
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.
int init_volmap_by_name(const char *volmap_name) override
int replica_comm_send(char *msg_data, int msg_len, int dest_rep) override
Send data to other replica.
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)
void getGridForceGridValue(int flags, T const *grid, cvm::atom_iter atom_begin, cvm::atom_iter atom_end, cvm::real *value, cvm::real *atom_field)
Abstraction of the two types of NAMD volumetric maps.
SimParameters * simparams
Pointer to the NAMD simulation input object.
Definition: colvarproxy_namd.h:47
int replica_enabled() override
Indicate if multi-replica support is available and active.
void init_atoms_map()
Allocate an atoms map with the same size as the NAMD topology.
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 setup() override
(Re)initialize required member data (called after the module)
int backup_file(char const *filename) override
Rename the given file, before overwriting it.
int load_atoms_pdb(char const *filename, cvm::atom_group &atoms, std::string const &pdb_field, double const pdb_field_value) override
Read a selection of atom IDs from a PDB coordinate file.
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.
int compute_volmap(int flags, int volmap_id, cvm::atom_iter atom_begin, cvm::atom_iter atom_end, cvm::real *value, cvm::real *atom_field) override
int get_volmap_id_from_name(char const *volmap_name) override
Get the numeric ID of the given volumetric map (for the MD program)
int check_atom_id(int atom_number) override
std::ostream & output_stream(std::string const &output_name, std::string const description) override
int close_output_stream(std::string const &output_name) override
Closes the given output file/channel.
int flush_output_streams() override
Flushes all output files/channels.
int check_volmap_by_name(char const *volmap_name) override
int check_volmaps_available() override
Test whether this implementation can use volumetric maps as CVs.
cvm::real rand_gaussian() override
Pseudo-random number with Gaussian distribution.
Definition: colvarproxy_namd.h:109
int scalable_group_coms() override
Whether this proxy implementation has capability for scalable groups.
Definition: colvarproxy_namd.h:205
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 replica_comm_barrier() override
Synchronize replica with others.
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 reset() override
Reset proxy state, e.g. requested atoms.
bool accelMDOn
Accelerated MD reweighting factor.
Definition: colvarproxy_namd.h:62
SubmitReduction * reduction
Used to submit restraint energy as MISC.
Definition: colvarproxy_namd.h:56
void clear_volmap(int index) override
Used by the CVC destructors.
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.
cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const
Get the PBC-aware distance vector between two positions.
void GridForceGridLoop(T const *g, cvm::atom_iter atom_begin, cvm::atom_iter atom_end, cvm::real *value, cvm::real *atom_field)
Implementation of inner loop; allows for atom list computation and use.
std::vector< int > atoms_map
Array of atom indices (relative to the colvarproxy arrays), usedfor faster copy of atomic data.
Definition: colvarproxy_namd.h:44
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 int smp_colvars_loop()
Distribute calculation of colvars (and their components) across threads.
Definition: colvarproxy.cpp:282
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:329
virtual int smp_thread_id()
Index of this thread.
Definition: colvarproxy.cpp:358
virtual int smp_trylock()
Attempt to lock the proxy's shared data.
Definition: colvarproxy.cpp:387
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:378
virtual int smp_num_threads()
Number of threads sharing this address space.
Definition: colvarproxy.cpp:368
virtual int check_smp_enabled()
Whether threaded parallelization is available (TODO: make this a cvm::deps feature)
Definition: colvarproxy.cpp:269
virtual int smp_unlock()
Release the lock.
Definition: colvarproxy.cpp:397
virtual int smp_biases_loop()
Distribute calculation of biases across threads.
Definition: colvarproxy.cpp:306
bool total_force_requested
Whether the total forces have been requested.
Definition: colvarproxy_system.h:162
Definition: colvarproxy.h:573
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43
Collective variables main module.
Colvars proxy classes.