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);
234 unsigned char *obj = NULL);
241 unsigned char *obj = NULL);
248 unsigned char *obj = NULL);
257 char const *name,
char const *help,
258 int n_args_min,
int n_args_max,
char const *arghelp,
259 int (*fn)(
void *,
int,
unsigned char *
const *));
265 int argc,
unsigned char *
const argv[]);
297 std::vector<int (*)(
void *, int,
unsigned char *
const *)>
cmd_fns;
302 unsigned char *
const *)
311 template <
typename T>
315 template <
typename T>
333inline static colvar *colvar_obj(
void *pobj)
335 return reinterpret_cast<colvar *
>(pobj);
340inline static colvarbias *colvarbias_obj(
void *pobj)
347template<colvarscript::Object_type T>
350 unsigned char *
const objv[])
352 int const shift = cmd_arg_shift<T>();
353 return (shift+iarg < objc) ? objv[shift+iarg] : NULL;
358 unsigned char *
const objv[])
360 return get_cmd_arg<use_module>(iarg, objc, objv);
365 unsigned char *
const objv[])
367 return get_cmd_arg<use_colvar>(iarg, objc, objv);
372 unsigned char *
const objv[])
374 return get_cmd_arg<use_bias>(iarg, objc, objv);
378template<colvarscript::Object_type T>
384 int const shift = cmd_arg_shift<T>();
385 if (objc < shift+n_args_min) {
387 ") for script function \""+std::string(cmd)+
389 return COLVARSCRIPT_ERROR;
391 if (objc > shift+n_args_max) {
393 ") for script function \""+std::string(cmd)+
395 return COLVARSCRIPT_ERROR;
397 return COLVARSCRIPT_OK;
406 return check_cmd_nargs<use_module>(cmd, objc, n_args_min, n_args_max);
415 return check_cmd_nargs<use_colvar>(cmd, objc, n_args_min, n_args_max);
424 return check_cmd_nargs<use_bias>(cmd, objc, n_args_min, n_args_max);
428template<colvarscript::Object_type T>
432 if (T == use_module) {
435 }
else if (T == use_colvar) {
438 }
else if (T == use_bias) {
448 int run_colvarscript_command(
int objc,
unsigned char *
const objv[]);
451 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:727
Collective variables module (main class)
Definition: colvarmodule.h:59
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:95
static colvarmodule * main()
Access the one instance of the Colvars module.
Definition: colvarmodule.cpp:185
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:860
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2392
colvarscript * script
Definition: colvarproxy.h:508
Definition: colvarproxy.h:542
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:883
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:893
char const * get_command_arghelp(char const *cmd, int i)
Definition: colvarscript.cpp:211
int set_result_rvector_vec(std::vector< 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:907
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:887
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
int pack_vector_elements_text(std::vector< T > const &x, std::string &x_str)
Code reused by instances of set_result_text()
Definition: colvarscript.cpp:787
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:913
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:270
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_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:873
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:401
char * obj_to_str(unsigned char *obj)
Get the string representation of an object (by default, a simple cast)
Definition: colvarscript.cpp:452
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:410
int cmd_arg_shift()
Number of positional arguments to shift for each object type.
Definition: colvarscript.h:429
std::vector< size_t > cmd_n_args_max
Maximum number of arguments for each command.
Definition: colvarscript.h:288
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:364
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:282
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:419
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:285
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:348
char const ** cmd_names
Inverse of cmd_str_map (to be exported outside this class)
Definition: colvarscript.h:276
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:918
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:903
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:371
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:357
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:877
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:291
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:300
std::string cmdline_main_cmd_
Main command used in command line ("cv" by default)
Definition: colvarscript.h:273
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:379
std::vector< std::string > cmd_help
Help strings for each command.
Definition: colvarscript.h:279
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
int set_result_real_vec(std::vector< 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:897
std::vector< std::string > cmd_full_help
Full help strings for each command.
Definition: colvarscript.h:294
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:297
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.