18#include "colvarvalue.h"
23#define COLVARSCRIPT_ERROR -1
24#define COLVARSCRIPT_OK 0
50 int run(
int objc,
unsigned char *
const objv[]);
75#define CVSCRIPT_ENUM_COMM(COMM) COMM,
77#define CVSCRIPT(COMM,HELP,N_ARGS_MIN,N_ARGS_MAX,ARGS,FN_BODY) \
78 CVSCRIPT_ENUM_COMM(COMM)
79#ifdef COLVARSCRIPT_COMMANDS_H
80#undef COLVARSCRIPT_COMMANDS_H
82#include "colvarscript_commands.h"
83#undef COLVARSCRIPT_COMMANDS_H
85#undef CVSCRIPT_ENUM_COMM
100 template<Object_type T>
101 unsigned char *
get_cmd_arg(
int iarg,
int objc,
unsigned char *
const objv[]);
105 unsigned char *
const objv[]);
109 unsigned char *
const objv[]);
113 unsigned char *
const objv[]);
116 template<Object_type T>
118 int n_args_min,
int n_args_max);
122 int n_args_min,
int n_args_max);
126 int n_args_min,
int n_args_max);
130 int n_args_min,
int n_args_max);
133 template<colvarscript::Object_type T>
194 return this->colvars;
227 unsigned char *obj = NULL);
233 template <
typename T>
235 unsigned char *obj = NULL);
241 template <
typename T>
243 unsigned char *obj = NULL);
250 unsigned char *obj = NULL);
259 char const *name,
char const *help,
260 int n_args_min,
int n_args_max,
char const *arghelp,
261 int (*fn)(
void *,
int,
unsigned char *
const *));
267 int argc,
unsigned char *
const argv[]);
299 std::vector<int (*)(
void *, int,
unsigned char *
const *)>
cmd_fns;
304 unsigned char *
const *)
313 template <
typename T>
317 template <
typename T>
335inline static colvar *colvar_obj(
void *pobj)
337 return reinterpret_cast<colvar *
>(pobj);
342inline static colvarbias *colvarbias_obj(
void *pobj)
349template<colvarscript::Object_type T>
352 unsigned char *
const objv[])
354 int const shift = cmd_arg_shift<T>();
355 return (shift+iarg < objc) ? objv[shift+iarg] : NULL;
360 unsigned char *
const objv[])
362 return get_cmd_arg<use_module>(iarg, objc, objv);
367 unsigned char *
const objv[])
369 return get_cmd_arg<use_colvar>(iarg, objc, objv);
374 unsigned char *
const objv[])
376 return get_cmd_arg<use_bias>(iarg, objc, objv);
380template<colvarscript::Object_type T>
386 int const shift = cmd_arg_shift<T>();
387 if (objc < shift+n_args_min) {
389 ") for script function \""+std::string(cmd)+
391 return COLVARSCRIPT_ERROR;
393 if (objc > shift+n_args_max) {
395 ") for script function \""+std::string(cmd)+
397 return COLVARSCRIPT_ERROR;
399 return COLVARSCRIPT_OK;
408 return check_cmd_nargs<use_module>(cmd, objc, n_args_min, n_args_max);
417 return check_cmd_nargs<use_colvar>(cmd, objc, n_args_min, n_args_max);
426 return check_cmd_nargs<use_bias>(cmd, objc, n_args_min, n_args_max);
430template<colvarscript::Object_type T>
434 if (T == use_module) {
437 }
else if (T == use_colvar) {
440 }
else if (T == use_bias) {
450 int run_colvarscript_command(
int objc,
unsigned char *
const objv[]);
453 const char * get_colvarscript_result();
A collective variable (main class); to be defined, it needs at least one object of a derived class of...
Definition: colvar.h:53
Collective variable bias, base class.
Definition: colvarbias.h:23
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:34
vector of real numbers with three components
Definition: colvartypes.h:723
Collective variables module (main class)
Definition: colvarmodule.h:69
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:141
static colvarmodule * main()
Access the one instance of the Colvars module.
Definition: colvarmodule.cpp:175
static colvarproxy * proxy
Pointer to the proxy object, used to retrieve atomic data from the hosting program; it is static in o...
Definition: colvarmodule.h:943
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2416
colvarscript * script
Definition: colvarproxy.h:525
Definition: colvarproxy.h:559
Definition: colvarscript.h:29
int clear_str_result()
Clear the string result.
Definition: colvarscript.cpp:606
int set_result_long_int(long int const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
Definition: colvarscript.cpp:904
int set_result_real(cvm::real const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
Definition: colvarscript.cpp:914
char const * get_command_arghelp(char const *cmd, int i)
Definition: colvarscript.cpp:211
int proc_features(colvardeps *obj, int argc, unsigned char *const argv[])
Run subcommands on base colvardeps object (colvar, bias, ...)
Definition: colvarscript.cpp:506
void add_error_msg(std::string const &s)
Add the given string to the error message of the script interface.
Definition: colvarscript.cpp:596
int run(int objc, unsigned char *const objv[])
Run a script command with space-separated positional arguments (objects)
Definition: colvarscript.cpp:347
int set_result_str(std::string const &s)
Set the return value to the given string.
Definition: colvarscript.cpp:584
std::string & modify_str_result()
Modify the string result of the current scripting call.
Definition: colvarscript.h:59
char const * get_command_rethelp(char const *cmd)
Definition: colvarscript.cpp:199
std::string const & str_result() const
Get the string result of the current scripting call.
Definition: colvarscript.h:53
int set_result_long_int_vec(std::vector< long int > const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
Definition: colvarscript.cpp:908
void set_cmdline_main_cmd(std::string const &cmd)
Set the main command for the CLI, when it is not "cv" (e.g. LAMMPS)
Definition: colvarscript.h:166
int set_result_text(T const &x, unsigned char *obj)
Set obj equal to x, using its string representation.
Definition: colvarscript.cpp:780
command
Commands available.
Definition: colvarscript.h:74
std::vector< std::string > obj_to_str_vector(unsigned char *obj)
Get a list of strings from an object (does not work with a simple cast)
Definition: colvarscript.cpp:463
int set_result_colvarvalue(colvarvalue const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
Definition: colvarscript.cpp:948
int unsupported_op()
Set error code for unsupported script operation.
Definition: colvarscript.cpp:577
std::map< std::string, command > cmd_str_map
Internal identifiers of command strings.
Definition: colvarscript.h:272
int set_result_text_from_str(std::string const &x_str, unsigned char *obj)
Code reused by all instances of set_result_text()
Definition: colvarscript.cpp:767
int set_result_real_vec(T const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
int set_result_int(int const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
Definition: colvarscript.cpp:894
int check_module_cmd_nargs(char const *cmd, int objc, int n_args_min, int n_args_max)
Instantiation of check_cmd_nargs<> for module-level commands.
Definition: colvarscript.h:403
char * obj_to_str(unsigned char *obj)
Get the string representation of an object (by default, a simple cast)
Definition: colvarscript.cpp:452
int set_result_rvector_vec(T const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
char const * get_command_help(char const *cmd)
Definition: colvarscript.cpp:187
int init_command(colvarscript::command const &comm, char const *name, char const *help, int n_args_min, int n_args_max, char const *arghelp, int(*fn)(void *, int, unsigned char *const *))
Set up a single script API function.
Definition: colvarscript.cpp:104
int check_colvar_cmd_nargs(char const *cmd, int objc, int n_args_min, int n_args_max)
Instantiation of check_cmd_nargs<> for colvar-level commands.
Definition: colvarscript.h:412
int cmd_arg_shift()
Number of positional arguments to shift for each object type.
Definition: colvarscript.h:431
std::vector< size_t > cmd_n_args_max
Maximum number of arguments for each command.
Definition: colvarscript.h:290
char const * get_command_full_help(char const *cmd)
Definition: colvarscript.cpp:247
int get_command_n_args_min(char const *cmd)
Definition: colvarscript.cpp:223
unsigned char * get_colvar_cmd_arg(int iarg, int objc, unsigned char *const objv[])
Instantiation of get_cmd_arg<> for colvar-level commands.
Definition: colvarscript.h:366
int pack_vector_elements_text(T const &x, std::string &x_str)
Code reused by instances of set_result_text()
Definition: colvarscript.cpp:787
colvarmodule * module()
Pointer to the Colvars main object.
Definition: colvarscript.h:192
std::vector< std::string > cmd_rethelp
Description of the return values of each command (may be empty)
Definition: colvarscript.h:284
int check_bias_cmd_nargs(char const *cmd, int objc, int n_args_min, int n_args_max)
Instantiation of get_cmd_arg<> for bias-level commands.
Definition: colvarscript.h:421
char const ** get_command_names() const
Get names of all commands.
Definition: colvarscript.h:137
std::vector< size_t > cmd_n_args_min
Minimum number of arguments for each command.
Definition: colvarscript.h:287
unsigned char * get_cmd_arg(int iarg, int objc, unsigned char *const objv[])
Get a pointer to the i-th argument of the command (NULL if not given)
Definition: colvarscript.h:350
char const ** cmd_names
Inverse of cmd_str_map (to be exported outside this class)
Definition: colvarscript.h:278
int set_result_colvarvalue_vec(std::vector< colvarvalue > const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
Definition: colvarscript.cpp:953
int set_result_rvector(cvm::rvector const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
Definition: colvarscript.cpp:924
unsigned char * get_bias_cmd_arg(int iarg, int objc, unsigned char *const objv[])
Instantiation of get_cmd_arg<> for bias-level commands.
Definition: colvarscript.h:373
Object_type
Type of object handling a script command.
Definition: colvarscript.h:90
int get_command_n_args_max(char const *cmd)
Definition: colvarscript.cpp:235
colvarproxy * proxy()
Pointer to the colvarproxy object (interface with host engine)
Definition: colvarscript.h:198
unsigned char * get_module_cmd_arg(int iarg, int objc, unsigned char *const objv[])
Instantiation of get_cmd_arg<> for module-level commands.
Definition: colvarscript.h:359
int set_result_int_vec(std::vector< int > const &x, unsigned char *obj=NULL)
Copy x into obj if not NULL, or into the script object's result otherwise.
Definition: colvarscript.cpp:898
int init_commands()
Set up all script API functions.
Definition: colvarscript.cpp:65
std::string get_command_cmdline_syntax(Object_type t, command c)
Definition: colvarscript.cpp:259
std::vector< std::vector< std::string > > cmd_arghelp
Help strings for each command argument.
Definition: colvarscript.h:293
int(*)(void *, int, unsigned char *const *) get_cmd_fn(std::string const &cmd_key)
Get a pointer to the implementation of the given command.
Definition: colvarscript.h:302
std::string cmdline_main_cmd_
Main command used in command line ("cv" by default)
Definition: colvarscript.h:275
std::string get_cmdline_help_summary(Object_type t)
Definition: colvarscript.cpp:301
int check_cmd_nargs(char const *cmd, int objc, int n_args_min, int n_args_max)
Check the argument count of the command.
Definition: colvarscript.h:381
std::vector< std::string > cmd_help
Help strings for each command.
Definition: colvarscript.h:281
std::string get_cmd_prefix(Object_type t)
Return the prefix of the individual command for each object function.
Definition: colvarscript.cpp:170
std::string get_command_cmdline_help(Object_type t, std::string const &cmd)
Definition: colvarscript.cpp:333
std::vector< std::string > cmd_full_help
Full help strings for each command.
Definition: colvarscript.h:296
std::string str_result_
String representation of the result of a script call.
Definition: colvarscript.h:47
std::vector< int(*)(void *, int, unsigned char *const *)> cmd_fns
Implementations of each command.
Definition: colvarscript.h:299
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.