Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
colvarscript Class Reference
Collaboration diagram for colvarscript:
Collaboration graph
[legend]

Public Types

enum  command { cv_n_commands }
 Commands available.
 
enum  Object_type { use_module , use_colvar , use_bias }
 Type of object handling a script command.
 

Public Member Functions

 colvarscript (colvarproxy *p, colvarmodule *m)
 
int run (int objc, unsigned char *const objv[])
 Run a script command with space-separated positional arguments (objects)
 
std::string const & str_result () const
 Get the string result of the current scripting call.
 
std::string & modify_str_result ()
 Modify the string result of the current scripting call.
 
int set_result_str (std::string const &s)
 Set the return value to the given string.
 
int clear_str_result ()
 Clear the string result.
 
void add_error_msg (std::string const &s)
 Add the given string to the error message of the script interface.
 
std::string get_cmd_prefix (Object_type t)
 Return the prefix of the individual command for each object function.
 
template<Object_type T>
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)
 
unsigned char * get_module_cmd_arg (int iarg, int objc, unsigned char *const objv[])
 Instantiation of get_cmd_arg<> for module-level commands.
 
unsigned char * get_colvar_cmd_arg (int iarg, int objc, unsigned char *const objv[])
 Instantiation of get_cmd_arg<> for colvar-level commands.
 
unsigned char * get_bias_cmd_arg (int iarg, int objc, unsigned char *const objv[])
 Instantiation of get_cmd_arg<> for bias-level commands.
 
template<Object_type T>
int check_cmd_nargs (char const *cmd, int objc, int n_args_min, int n_args_max)
 Check the argument count of the command.
 
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.
 
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.
 
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.
 
template<colvarscript::Object_type T>
int cmd_arg_shift ()
 Number of positional arguments to shift for each object type.
 
char const ** get_command_names () const
 Get names of all commands.
 
char const * get_command_help (char const *cmd)
 
char const * get_command_rethelp (char const *cmd)
 
char const * get_command_arghelp (char const *cmd, int i)
 
int get_command_n_args_min (char const *cmd)
 
int get_command_n_args_max (char const *cmd)
 
void set_cmdline_main_cmd (std::string const &cmd)
 Set the main command for the CLI, when it is not "cv" (e.g. LAMMPS)
 
char const * get_command_full_help (char const *cmd)
 
std::string get_cmdline_help_summary (Object_type t)
 
std::string get_command_cmdline_syntax (Object_type t, command c)
 
std::string get_command_cmdline_help (Object_type t, std::string const &cmd)
 
int unsupported_op ()
 Set error code for unsupported script operation.
 
colvarmodulemodule ()
 Pointer to the Colvars main object.
 
colvarproxyproxy ()
 Pointer to the colvarproxy object (interface with host engine)
 
char * obj_to_str (unsigned char *obj)
 Get the string representation of an object (by default, a simple cast)
 
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)
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
int proc_features (colvardeps *obj, int argc, unsigned char *const argv[])
 Run subcommands on base colvardeps object (colvar, bias, ...)
 
template<>
int set_result_text (int const &x, unsigned char *obj)
 
template<>
int set_result_text (std::vector< int > const &x, unsigned char *obj)
 
template<>
int set_result_text (long int const &x, unsigned char *obj)
 
template<>
int set_result_text (std::vector< long int > const &x, unsigned char *obj)
 
template<>
int set_result_text (cvm::real const &x, unsigned char *obj)
 
template<>
int set_result_text (std::vector< cvm::real > const &x, unsigned char *obj)
 
template<>
int set_result_text (std::vector< cvm::rvector > const &x, unsigned char *obj)
 
template<>
int set_result_text (std::vector< colvarvalue > const &x, unsigned char *obj)
 

Public Attributes

std::string str_result_
 String representation of the result of a script call.
 

Private Member Functions

int init_commands ()
 Set up all script API functions.
 
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.
 
template<typename T >
int set_result_text (T const &x, unsigned char *obj)
 Set obj equal to x, using its string representation.
 
template<typename T >
int pack_vector_elements_text (std::vector< T > const &x, std::string &x_str)
 Code reused by instances of set_result_text()
 
int set_result_text_from_str (std::string const &x_str, unsigned char *obj)
 Code reused by all instances of set_result_text()
 

Private Attributes

colvarproxyproxy_
 
colvarmodulecolvars
 
std::map< std::string, commandcmd_str_map
 Internal identifiers of command strings.
 
std::string cmdline_main_cmd_
 Main command used in command line ("cv" by default)
 
char const ** cmd_names
 Inverse of cmd_str_map (to be exported outside this class)
 
std::vector< std::string > cmd_help
 Help strings for each command.
 
std::vector< std::string > cmd_rethelp
 Description of the return values of each command (may be empty)
 
std::vector< size_t > cmd_n_args_min
 Minimum number of arguments for each command.
 
std::vector< size_t > cmd_n_args_max
 Maximum number of arguments for each command.
 
std::vector< std::vector< std::string > > cmd_arghelp
 Help strings for each command argument.
 
std::vector< std::string > cmd_full_help
 Full help strings for each command.
 
std::vector< int(*)(void *, int, unsigned char *const *)> cmd_fns
 Implementations of each command.
 
int(*)(void *, int, unsigned char *const *) get_cmd_fn (std::string const &cmd_key)
 Get a pointer to the implementation of the given command.
 

Friends

class colvarproxy
 

Member Function Documentation

◆ get_cmdline_help_summary()

std::string colvarscript::get_cmdline_help_summary ( colvarscript::Object_type  t)

Get summary of command line syntax for all commands of a given context

Parameters
tOne of use_module, use_colvar or use_bias

◆ get_command_arghelp()

char const * colvarscript::get_command_arghelp ( char const *  cmd,
int  i 
)

Get description of the argument of a command (excluding prefix)

Parameters
cmdName of the command's function (e.g. "cv_units")
iIndex of the argument; 0 is the first argument after the prefix, e.g. "value" has an index of 0 in the array of arguments: { "cv", "colvar", "xi", "value" }

◆ get_command_cmdline_help()

std::string colvarscript::get_command_cmdline_help ( colvarscript::Object_type  t,
std::string const &  cmd 
)

Get the command line syntax following by the help string

Parameters
tOne of use_module, use_colvar or use_bias
cmdName of the subcommand (e.g. "units")

◆ get_command_cmdline_syntax()

std::string colvarscript::get_command_cmdline_syntax ( colvarscript::Object_type  t,
colvarscript::command  cmd 
)

Get a description of how the command should be used in a command line

Parameters
tOne of use_module, use_colvar or use_bias
cValue of the command enum

◆ get_command_full_help()

char const * colvarscript::get_command_full_help ( char const *  cmd)

Get help string for a command (does not specify how it is launched)

Parameters
cmdName of the command's function (e.g. "cv_units")

◆ get_command_help()

char const * colvarscript::get_command_help ( char const *  cmd)

Get one-line help summary for a command

Parameters
cmdName of the command's function (e.g. "cv_units")

◆ get_command_n_args_max()

int colvarscript::get_command_n_args_max ( char const *  cmd)

Get number of total arguments (excluding prefix)

Parameters
cmdName of the command's function (e.g. "cv_units")

◆ get_command_n_args_min()

int colvarscript::get_command_n_args_min ( char const *  cmd)

Get number of required arguments (excluding prefix)

Parameters
cmdName of the command's function (e.g. "cv_units")

◆ get_command_rethelp()

char const * colvarscript::get_command_rethelp ( char const *  cmd)

Get description of the return value of a command

Parameters
cmdName of the command's function (e.g. "cv_units")

The documentation for this class was generated from the following files: