Update Colvars to version 2017-10-11
Notable features are the umbrella-integration based free energy estimator for eABF, and the traditional thermodynamic integration estimator now available for umbrella sampling, SMD, metadynamics. Also included are several small fixes. Below is a list of relevant commits in the Colvars repository since the last update. 321d06a 2017-10-10 Add macros to manage colvarscript commands [Giacomo Fiorin] 26c3bec 2017-10-09 Document coming availability of Lepton in LAMMPS [Giacomo Fiorin] cc8f249 2017-10-04 Clarify that SMP depends on code build [Giacomo Fiorin] 0b2ffac 2017-10-04 Summarize colvar definition options, clarify some details [Giacomo Fiorin] 28002e0 2017-10-01 Separate writing of restart file from other output (e.g. PMFs) [Giacomo Fiorin] 92f7c1d 2017-10-01 Deprecate colvarsTrajAppend [Giacomo Fiorin] 12a707f 2017-09-26 Accurate Jacobian calculation for RMSD variants [Jérôme Hénin] fe389c9 2017-09-21 Allow subtractAppliedForce with extended-L again [Jérôme Hénin] c050ce0 2017-09-18 Silence compiler warnings, remove Tabs [Giacomo Fiorin] cb41905 2017-01-11 Add base class for TI estimator in other biases than ABF [Giacomo Fiorin] a1bc676 2017-09-14 Avoid writing to unopened traj file [Jérôme Hénin] b58d8cd 2017-09-08 Function to check for overlapping groups [Jérôme Hénin] 1e5efec 2017-09-07 Check for overlapping groups in coordNum [Jérôme Hénin] 03a61a4 2017-04-06 Add UI-based estimator [fhh2626] ae43754 2017-08-17 Fix outputCenters parsing [Josh Vermaas] 1619e0e 2017-08-14 Delete static feature arrays in cvm destructor [Jérôme Hénin]
This commit is contained in:
@ -8,21 +8,27 @@
|
||||
// Colvars repository at GitHub.
|
||||
|
||||
#ifndef COLVARSCRIPT_H
|
||||
#define COLVARSCRIPT_H
|
||||
//#define COLVARSCRIPT_H // Delay definition until later
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "colvarmodule.h"
|
||||
#include "colvarvalue.h"
|
||||
#include "colvarbias.h"
|
||||
#include "colvarproxy.h"
|
||||
|
||||
|
||||
// Only these error values are part of the scripting interface
|
||||
#define COLVARSCRIPT_ERROR -1
|
||||
#define COLVARSCRIPT_OK 0
|
||||
|
||||
|
||||
class colvarscript {
|
||||
|
||||
private:
|
||||
|
||||
colvarproxy *proxy;
|
||||
colvarmodule *colvars;
|
||||
|
||||
@ -35,16 +41,93 @@ public:
|
||||
colvarscript(colvarproxy * p);
|
||||
inline ~colvarscript() {}
|
||||
|
||||
/// If an error is caught by the proxy through fatal_error(), this is set to COLVARSCRIPT_ERROR
|
||||
/// If an error is caught by the proxy through fatal_error(), this is set to
|
||||
/// COLVARSCRIPT_ERROR
|
||||
int proxy_error;
|
||||
|
||||
/// If an error is returned by one of the methods, it should set this to the error message
|
||||
/// If an error is returned by one of the methods, it should set this to the
|
||||
/// error message
|
||||
std::string result;
|
||||
|
||||
/// Run script command with given positional arguments (objects)
|
||||
int run(int objc, unsigned char *const objv[]);
|
||||
|
||||
/// Set the return value of the script command to the given string
|
||||
inline void set_str_result(std::string const &s)
|
||||
{
|
||||
result = s;
|
||||
}
|
||||
|
||||
/// Build and return a short help
|
||||
std::string help_string(void) const;
|
||||
|
||||
/// Use scripting language to get the string representation of an object
|
||||
inline char const *obj_to_str(unsigned char *const obj)
|
||||
{
|
||||
return cvm::proxy->script_obj_to_str(obj);
|
||||
}
|
||||
|
||||
enum command {
|
||||
cv_help,
|
||||
cv_version,
|
||||
cv_config,
|
||||
cv_configfile,
|
||||
cv_reset,
|
||||
cv_delete,
|
||||
cv_list,
|
||||
cv_list_biases,
|
||||
cv_load,
|
||||
cv_save,
|
||||
cv_update,
|
||||
cv_addenergy,
|
||||
cv_getenergy,
|
||||
cv_printframe,
|
||||
cv_printframelabels,
|
||||
cv_frame,
|
||||
cv_colvar,
|
||||
cv_colvar_value,
|
||||
cv_colvar_update,
|
||||
cv_colvar_type,
|
||||
cv_colvar_delete,
|
||||
cv_colvar_addforce,
|
||||
cv_colvar_getappliedforce,
|
||||
cv_colvar_gettotalforce,
|
||||
cv_colvar_cvcflags,
|
||||
cv_colvar_getconfig,
|
||||
cv_colvar_get,
|
||||
cv_colvar_set,
|
||||
cv_bias,
|
||||
cv_bias_energy,
|
||||
cv_bias_update,
|
||||
cv_bias_delete,
|
||||
cv_bias_getconfig,
|
||||
cv_bias_get,
|
||||
cv_bias_set,
|
||||
cv_n_commands
|
||||
};
|
||||
|
||||
/// Execute a script command
|
||||
inline int exec_command(command c,
|
||||
void *pobj,
|
||||
int objc, unsigned char * const *objv)
|
||||
{
|
||||
return (*(comm_fns[c]))(pobj, objc, objv);
|
||||
}
|
||||
|
||||
/// Get help for a command (TODO reformat for each language?)
|
||||
inline std::string command_help(colvarscript::command c) const
|
||||
{
|
||||
return comm_help[c];
|
||||
}
|
||||
|
||||
/// Clear all object results
|
||||
inline void clear_results()
|
||||
{
|
||||
result.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/// Run subcommands on colvar
|
||||
int proc_colvar(colvar *cv, int argc, unsigned char *const argv[]);
|
||||
|
||||
@ -55,17 +138,146 @@ private:
|
||||
int proc_features(colvardeps *obj,
|
||||
int argc, unsigned char *const argv[]);
|
||||
|
||||
/// Build and return a short help
|
||||
std::string help_string(void);
|
||||
/// Internal identifiers of command strings
|
||||
std::map<std::string, command> comm_str_map;
|
||||
|
||||
public:
|
||||
/// Help strings for each command
|
||||
std::vector<std::string> comm_help;
|
||||
|
||||
inline char const *obj_to_str(unsigned char *const obj)
|
||||
{
|
||||
return cvm::proxy->script_obj_to_str(obj);
|
||||
}
|
||||
/// Number of arguments for each command
|
||||
std::vector<size_t> comm_n_args;
|
||||
|
||||
/// Arguments for each command
|
||||
std::vector< std::vector<std::string> > comm_args;
|
||||
|
||||
/// Implementations of each command
|
||||
std::vector<int (*)(void *, int, unsigned char * const *)> comm_fns;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/// Get a pointer to the main colvarscript object
|
||||
inline static colvarscript *colvarscript_obj()
|
||||
{
|
||||
return cvm::main()->proxy->script;
|
||||
}
|
||||
|
||||
/// Get a pointer to the colvar object pointed to by pobj
|
||||
inline static colvar *colvar_obj(void *pobj)
|
||||
{
|
||||
return reinterpret_cast<colvar *>(pobj);
|
||||
}
|
||||
|
||||
/// Get a pointer to the colvarbias object pointed to by pobj
|
||||
inline static colvarbias *colvarbias_obj(void *pobj)
|
||||
{
|
||||
return reinterpret_cast<colvarbias *>(pobj);
|
||||
}
|
||||
|
||||
|
||||
#define CVSCRIPT_COMM_FNAME(COMM) cvscript_ ## COMM
|
||||
|
||||
#define CVSCRIPT_COMM_PROTO(COMM) \
|
||||
int CVSCRIPT_COMM_FNAME(COMM)(void *, int, unsigned char *const *);
|
||||
|
||||
#define CVSCRIPT(COMM,HELP,N_ARGS_MIN,N_ARGS_MAX,ARGS,FN_BODY) \
|
||||
CVSCRIPT_COMM_PROTO(COMM)
|
||||
|
||||
#undef COLVARSCRIPT_H
|
||||
#endif // #ifndef COLVARSCRIPT_H
|
||||
|
||||
|
||||
#ifdef COLVARSCRIPT_CPP
|
||||
#define CVSCRIPT_COMM_FN(COMM,N_ARGS_MIN,N_ARGS_MAX,ARGS,FN_BODY) \
|
||||
int CVSCRIPT_COMM_FNAME(COMM)(void *pobj, \
|
||||
int objc, unsigned char *const objv[]) \
|
||||
{ \
|
||||
colvarscript *script = colvarscript_obj(); \
|
||||
script->clear_results(); \
|
||||
if (objc < 2+N_ARGS_MIN) /* "cv" and "COMM" are 1st and 2nd */ { \
|
||||
script->set_str_result("Missing arguments\n" + \
|
||||
script->command_help(colvarscript::COMM)); \
|
||||
return COLVARSCRIPT_ERROR; \
|
||||
} \
|
||||
if (objc > 2+N_ARGS_MAX) { \
|
||||
script->set_str_result("Too many arguments\n" + \
|
||||
script->command_help(colvarscript::COMM)); \
|
||||
return COLVARSCRIPT_ERROR; \
|
||||
} \
|
||||
FN_BODY; \
|
||||
}
|
||||
#undef CVSCRIPT
|
||||
#define CVSCRIPT(COMM,HELP,N_ARGS_MIN,N_ARGS_MAX,ARGS,FN_BODY) \
|
||||
CVSCRIPT_COMM_FN(COMM,N_ARGS_MIN,N_ARGS_MAX,ARGS,FN_BODY)
|
||||
#endif // #ifdef COLVARSCRIPT_CPP
|
||||
|
||||
|
||||
#ifdef COLVARSCRIPT_INIT_FN
|
||||
#define CVSCRIPT_COMM_INIT(COMM,HELP,ARGS) { \
|
||||
comm_str_map[#COMM] = COMM; \
|
||||
comm_help[COMM] = HELP; \
|
||||
comm_fns[COMM] = &(CVSCRIPT_COMM_FNAME(COMM)); \
|
||||
}
|
||||
#undef CVSCRIPT
|
||||
#define CVSCRIPT(COMM,HELP,N_ARGS_MIN,N_ARGS_MAX,ARGS,FN_BODY) \
|
||||
CVSCRIPT_COMM_INIT(COMM,HELP,ARGS)
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(COLVARSCRIPT_H) || defined(COLVARSCRIPT_INIT_FN)
|
||||
#define COLVARSCRIPT_H
|
||||
|
||||
#ifndef COLVARSCRIPT_INIT_FN
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Add optional arguments for command-specific help?
|
||||
CVSCRIPT(cv_help,
|
||||
"Print the help message",
|
||||
0, 0,
|
||||
{},
|
||||
script->set_str_result(script->help_string());
|
||||
return COLVARS_OK;
|
||||
)
|
||||
|
||||
CVSCRIPT(cv_config,
|
||||
"Read configuration from the given string",
|
||||
1, 1,
|
||||
{ "conf (str) - Configuration string" },
|
||||
std::string const conf(script->obj_to_str(objv[2]));
|
||||
if (cvm::main()->read_config_string(conf) == COLVARS_OK) {
|
||||
return COLVARS_OK;
|
||||
}
|
||||
script->set_str_result("Error parsing configuration string");
|
||||
return COLVARSCRIPT_ERROR;
|
||||
)
|
||||
|
||||
CVSCRIPT(cv_addenergy,
|
||||
"Add an energy to the MD engine",
|
||||
1, 1,
|
||||
{ "E (float) - Amount of energy to add" },
|
||||
cvm::main()->total_bias_energy +=
|
||||
strtod(script->obj_to_str(objv[2]), NULL);
|
||||
return COLVARS_OK;
|
||||
)
|
||||
|
||||
CVSCRIPT(cv_getenergy,
|
||||
"Get the current Colvars energy",
|
||||
1, 1,
|
||||
{ "E (float) - Store the energy in this variable" },
|
||||
double *energy = reinterpret_cast<double *>(objv[2]);
|
||||
*energy = cvm::main()->total_bias_energy;
|
||||
return COLVARS_OK;
|
||||
)
|
||||
|
||||
#ifndef COLVARSCRIPT_INIT_FN
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef CVSCRIPT
|
||||
|
||||
#endif // #ifndef COLVARSCRIPT_H
|
||||
|
||||
Reference in New Issue
Block a user