159
192
/// \brief Constructor \param config_name Configuration file name
160
193
/// \param restart_name (optional) Restart file name
161
colvarmodule (char const *config_name,
162
colvarproxy *proxy_in);
194
colvarmodule(colvarproxy *proxy);
167
/// Initialize collective variables
168
void init_colvars (std::string const &conf);
170
/// Initialize collective variable biases
171
void init_biases (std::string const &conf);
173
/// Re-initialize data at the beginning of a run. For use with
174
/// MD codes that can change system parameters like atom masses
175
/// between run commands.
199
/// Actual function called by the destructor
202
/// Open a config file, load its contents, and pass it to config_string()
203
int read_config_file(char const *config_file_name);
205
/// \brief Parse a config string assuming it is a complete configuration
206
/// (i.e. calling all parse functions)
207
int read_config_string(std::string const &conf);
209
/// \brief Parse a "clean" config string (no comments)
210
int parse_config(std::string &conf);
213
// Parse functions (setup internal data based on a string)
215
/// Parse the few module's global parameters
216
int parse_global_params(std::string const &conf);
218
/// Parse and initialize collective variables
219
int parse_colvars(std::string const &conf);
221
/// Parse and initialize collective variable biases
222
int parse_biases(std::string const &conf);
224
/// Parse and initialize collective variable biases of a specific type
225
template <class bias_type>
226
int parse_biases_type(std::string const &conf, char const *keyword, size_t &bias_count);
228
/// Test error condition and keyword parsing
229
/// on error, delete new bias
230
bool check_new_bias(std::string &conf, char const *key);
232
// "Setup" functions (change internal data based on related data
233
// from the proxy that may change during program execution)
234
// No additional parsing is done within these functions
236
/// (Re)initialize internal data (currently used by LAMMPS)
237
/// Also calls setup() member functions of colvars and biases
240
/// (Re)initialize and (re)read the input state file calling read_restart()
243
/// (Re)initialize the output trajectory and state file (does not write it yet)
247
typedef ofstream_namd ofstream;
249
typedef std::ofstream ofstream;
252
/// Read the input restart file
253
std::istream & read_restart(std::istream &is);
254
/// Write the output restart file
255
std::ostream & write_restart(std::ostream &os);
257
/// Open a trajectory file if requested (and leave it open)
258
int open_traj_file(std::string const &file_name);
260
int close_traj_file();
261
/// Write in the trajectory file
262
std::ostream & write_traj(std::ostream &os);
263
/// Write explanatory labels in the trajectory file
264
std::ostream & write_traj_label(std::ostream &os);
266
/// Write all FINAL output files
267
int write_output_files();
268
/// Backup a file before writing it
269
static int backup_file(char const *filename);
271
/// Look up a bias by name; returns NULL if not found
272
static colvarbias * bias_by_name(std::string const &name);
274
/// Look up a colvar by name; returns NULL if not found
275
static colvar * colvar_by_name(std::string const &name);
178
277
/// Load new configuration for the given bias -
179
278
/// currently works for harmonic (force constant and/or centers)
180
void change_configuration (std::string const &bias_name, std::string const &conf);
279
int change_configuration(std::string const &bias_name, std::string const &conf);
182
281
/// Read a colvar value
183
282
std::string read_colvar(std::string const &name);
185
284
/// Calculate change in energy from using alt. config. for the given bias -
186
285
/// currently works for harmonic (force constant and/or centers)
187
real energy_difference (std::string const &bias_name, std::string const &conf);
286
real energy_difference(std::string const &bias_name, std::string const &conf);
288
/// Give the total number of bins for a given bias.
289
int bias_bin_num(std::string const &bias_name);
290
/// Calculate the bin index for a given bias.
291
int bias_current_bin(std::string const &bias_name);
292
//// Give the count at a given bin index.
293
int bias_bin_count(std::string const &bias_name, size_t bin_index);
294
//// Share among replicas.
295
int bias_share(std::string const &bias_name);
189
297
/// Calculate collective variables and biases
191
/// Read the input restart file
192
std::istream & read_restart (std::istream &is);
193
/// Write the output restart file
194
std::ostream & write_restart (std::ostream &os);
195
/// Write all output files (called by the proxy)
196
void write_output_files();
197
/// \brief Call colvarproxy::backup_file()
198
static void backup_file (char const *filename);
200
300
/// Perform analysis
202
302
/// \brief Read a collective variable trajectory (post-processing
203
303
/// only, not called at runtime)
204
bool read_traj (char const *traj_filename,
304
int read_traj(char const *traj_filename,
205
305
size_t traj_read_begin,
206
306
size_t traj_read_end);
208
/// Get the pointer of a colvar from its name (returns NULL if not found)
209
static colvar * colvar_p (std::string const &name);
211
308
/// Quick conversion of an object to a string
212
template<typename T> static std::string to_str (T const &x,
309
template<typename T> static std::string to_str(T const &x,
213
310
size_t const &width = 0,
214
311
size_t const &prec = 0);
215
312
/// Quick conversion of a vector of objects to a string
216
template<typename T> static std::string to_str (std::vector<T> const &x,
313
template<typename T> static std::string to_str(std::vector<T> const &x,
217
314
size_t const &width = 0,
218
315
size_t const &prec = 0);
220
317
/// Reduce the number of characters in a string
221
static inline std::string wrap_string (std::string const &s,
318
static inline std::string wrap_string(std::string const &s,
222
319
size_t const &nchars)
225
return std::string (nchars, ' ');
322
return std::string(nchars, ' ');
227
return ( (s.size() <= size_t (nchars)) ?
228
(s+std::string (nchars-s.size(), ' ')) :
229
(std::string (s, 0, nchars)) );
324
return ( (s.size() <= size_t(nchars)) ?
325
(s+std::string(nchars-s.size(), ' ')) :
326
(std::string(s, 0, nchars)) );
232
329
/// Number of characters to represent a time step
262
359
static void request_system_force();
264
361
/// Print a message to the main log
265
static void log (std::string const &message);
362
static void log(std::string const &message);
267
364
/// Print a message to the main log and exit with error code
268
static void fatal_error (std::string const &message);
365
static void fatal_error(std::string const &message);
367
/// Print a message to the main log and set global error code
368
static void error(std::string const &message, int code = GENERAL_ERROR);
270
370
/// Print a message to the main log and exit normally
271
static void exit (std::string const &message);
371
static void exit(std::string const &message);
373
// Replica exchange commands.
374
static bool replica_enabled();
375
static int replica_index();
376
static int replica_num();
377
static void replica_comm_barrier();
378
static int replica_comm_recv(char* msg_data, int buf_len, int src_rep);
379
static int replica_comm_send(char* msg_data, int msg_len, int dest_rep);
274
381
/// \brief Get the distance between two atomic positions with pbcs handled
276
static rvector position_distance (atom_pos const &pos1,
383
static rvector position_distance(atom_pos const &pos1,
277
384
atom_pos const &pos2);
307
414
static std::list<std::vector<int> > index_groups;
309
416
/// \brief Read a Gromacs .ndx file
310
static void read_index_file (char const *filename);
417
static int read_index_file(char const *filename);
313
420
/// \brief Create atoms from a file \param filename name of the file
314
421
/// (usually a PDB) \param atoms array of the atoms to be allocated
315
422
/// \param pdb_field (optiona) if "filename" is a PDB file, use this
316
423
/// field to determine which are the atoms to be set
317
static void load_atoms (char const *filename,
424
static int load_atoms(char const *filename,
318
425
std::vector<atom> &atoms,
319
426
std::string const &pdb_field,
320
427
double const pdb_field_value = 0.0);
322
429
/// \brief Load the coordinates for a group of atoms from a file
324
static void load_coords (char const *filename,
431
static int load_coords(char const *filename,
325
432
std::vector<atom_pos> &pos,
326
433
const std::vector<int> &indices,
327
434
std::string const &pdb_field,
355
463
colvarparse *parse;
357
465
/// Name of the trajectory file
358
std::string cv_traj_name;
466
std::string cv_traj_name;
360
468
/// Collective variables output trajectory file
361
std::ofstream cv_traj_os;
469
colvarmodule::ofstream cv_traj_os;
363
471
/// Appending to the existing trajectory file?
366
474
/// Output restart file
367
std::ofstream restart_out_os;
475
colvarmodule::ofstream restart_out_os;
477
/// \brief Counter for the current depth in the object hierarchy (useg e.g. in output
480
/// Use scripted colvars forces?
481
static bool use_scripted_forces;
369
485
/// \brief Pointer to the proxy object, used to retrieve atomic data
370
486
/// from the hosting program; it is static in order to be accessible
371
487
/// from static functions in the colvarmodule class
372
488
static colvarproxy *proxy;
374
/// \brief Counter for the current depth in the object hierarchy (useg e.g. in outpu
379
490
/// Increase the depth (number of indentations in the output)
380
491
static void increase_depth();
382
493
/// Decrease the depth (number of indentations in the output)
383
494
static void decrease_depth();
496
static inline bool scripted_forces() { return use_scripted_forces; }
395
508
std::istream & operator >> (std::istream &is, cvm::rvector &v);
398
template<typename T> std::string cvm::to_str (T const &x,
511
template<typename T> std::string cvm::to_str(T const &x,
399
512
size_t const &width,
400
513
size_t const &prec) {
401
514
std::ostringstream os;
402
if (width) os.width (width);
515
if (width) os.width(width);
404
os.setf (std::ios::scientific, std::ios::floatfield);
517
os.setf(std::ios::scientific, std::ios::floatfield);
411
template<typename T> std::string cvm::to_str (std::vector<T> const &x,
524
template<typename T> std::string cvm::to_str(std::vector<T> const &x,
412
525
size_t const &width,
413
526
size_t const &prec) {
414
if (!x.size()) return std::string ("");
527
if (!x.size()) return std::string("");
415
528
std::ostringstream os;
417
os.setf (std::ios::scientific, std::ios::floatfield);
530
os.setf(std::ios::scientific, std::ios::floatfield);
420
if (width) os.width (width);
421
if (prec) os.precision (prec);
533
if (width) os.width(width);
534
if (prec) os.precision(prec);
423
536
for (size_t i = 1; i < x.size(); i++) {
425
if (width) os.width (width);
426
if (prec) os.precision (prec);
538
if (width) os.width(width);
539
if (prec) os.precision(prec);
454
567
return proxy->dt();
570
// Replica exchange commands
571
inline bool cvm::replica_enabled() {
572
return proxy->replica_enabled();
574
inline int cvm::replica_index() {
575
return proxy->replica_index();
577
inline int cvm::replica_num() {
578
return proxy->replica_num();
580
inline void cvm::replica_comm_barrier() {
581
return proxy->replica_comm_barrier();
583
inline int cvm::replica_comm_recv(char* msg_data, int buf_len, int src_rep) {
584
return proxy->replica_comm_recv(msg_data,buf_len,src_rep);
586
inline int cvm::replica_comm_send(char* msg_data, int msg_len, int dest_rep) {
587
return proxy->replica_comm_send(msg_data,msg_len,dest_rep);
457
591
inline void cvm::request_system_force()
459
proxy->request_system_force (true);
593
proxy->request_system_force(true);
462
inline void cvm::select_closest_image (atom_pos &pos,
596
inline void cvm::select_closest_image(atom_pos &pos,
463
597
atom_pos const &ref_pos)
465
proxy->select_closest_image (pos, ref_pos);
599
proxy->select_closest_image(pos, ref_pos);
468
inline void cvm::select_closest_images (std::vector<atom_pos> &pos,
602
inline void cvm::select_closest_images(std::vector<atom_pos> &pos,
469
603
atom_pos const &ref_pos)
471
proxy->select_closest_images (pos, ref_pos);
605
proxy->select_closest_images(pos, ref_pos);
474
inline cvm::rvector cvm::position_distance (atom_pos const &pos1,
608
inline cvm::rvector cvm::position_distance(atom_pos const &pos1,
475
609
atom_pos const &pos2)
477
return proxy->position_distance (pos1, pos2);
611
return proxy->position_distance(pos1, pos2);
480
inline cvm::real cvm::position_dist2 (cvm::atom_pos const &pos1,
614
inline cvm::real cvm::position_dist2(cvm::atom_pos const &pos1,
481
615
cvm::atom_pos const &pos2)
483
return proxy->position_dist2 (pos1, pos2);
617
return proxy->position_dist2(pos1, pos2);
486
inline cvm::real cvm::rand_gaussian (void)
620
inline cvm::real cvm::rand_gaussian(void)
488
622
return proxy->rand_gaussian();