Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvarscript_commands_colvar.h
1// -*- c++ -*-
2
3// This file is part of the Collective Variables module (Colvars).
4// The original version of Colvars and its updates are located at:
5// https://github.com/Colvars/colvars
6// Please update all Colvars source files before making any changes.
7// If you wish to distribute your changes, please submit them to the
8// Colvars repository at GitHub.
9
10
11CVSCRIPT(colvar_addforce,
12 "Apply the given force onto this colvar (no effects outside run)\n"
13 "force : float or array - Applied force; matches colvar dimensionality",
14 1, 1,
15 "force : float or array - Applied force; must match colvar dimensionality",
16 std::string const f_str(script->obj_to_str(script->get_colvar_cmd_arg(0, objc, objv)));
17 std::istringstream is(f_str);
18 is.width(cvm::cv_width);
19 is.precision(cvm::cv_prec);
20 colvarvalue force(this_colvar->value());
21 force.is_derivative();
22 if (force.from_simple_string(is.str()) != COLVARS_OK) {
23 script->add_error_msg("addforce : error parsing force value");
24 return COLVARSCRIPT_ERROR;
25 }
26 this_colvar->enable(colvardeps::f_cv_apply_force);
27 this_colvar->add_bias_force(force);
28 script->set_result_colvarvalue(force);
29 return COLVARS_OK;
30 )
31
32CVSCRIPT(colvar_communicateforces,
33 "Communicate bias forces from this colvar to atoms",
34 0, 0,
35 "",
36 this_colvar->communicate_forces();
37 return COLVARS_OK;
38 )
39
40CVSCRIPT(colvar_cvcflags,
41 "Enable or disable individual components by setting their active flags",
42 1, 1,
43 "flags : integer array - Zero/nonzero value disables/enables the CVC",
44 std::string const flags_str(script->obj_to_str(script->get_colvar_cmd_arg(0, objc, objv)));
45 std::istringstream is(flags_str);
46 std::vector<bool> flags;
47 int flag;
48 while (is >> flag) {
49 flags.push_back(flag != 0);
50 }
51 int res = this_colvar->set_cvc_flags(flags);
52 if (res != COLVARS_OK) {
53 script->add_error_msg("Error setting CVC flags");
54 return COLVARSCRIPT_ERROR;
55 }
56 script->set_result_str("0");
57 return COLVARS_OK;
58 )
59
60CVSCRIPT(colvar_delete,
61 "Delete this colvar, along with all biases that depend on it",
62 0, 0,
63 "",
64 delete this_colvar;
65 return COLVARS_OK;
66 )
67
68CVSCRIPT(colvar_get,
69 "Get the value of the given feature for this colvar\n"
70 "state : 1/0 - State of the given feature",
71 1, 1,
72 "feature : string - Name of the feature",
73 return script->proc_features(this_colvar, objc, objv);
74 )
75
76CVSCRIPT(colvar_getappliedforce,
77 "Return the total of the forces applied to this colvar\n"
78 "force : float - Applied force; matches the colvar dimensionality",
79 0, 0,
80 "",
81 script->set_result_colvarvalue(this_colvar->applied_force());
82 return COLVARS_OK;
83 )
84
85CVSCRIPT(colvar_resetbiasforce,
86 "Return the total of the forces applied to this colvar",
87 0, 0,
88 "",
89 this_colvar->reset_bias_force();
90 return COLVARS_OK;
91 )
92
93CVSCRIPT(colvar_getatomgroups,
94 "Return the atom indices used by this colvar as a list of lists\n"
95 "groups : array of arrays of ints - Atom indices",
96 0, 0,
97 "",
98 std::string result;
99 std::vector<std::vector<int> > lists = this_colvar->get_atom_lists();
100 std::vector<std::vector<int> >::iterator li = lists.begin();
101 for ( ; li != lists.end(); ++li) {
102 result += "{";
103 std::vector<int>::iterator lj = (*li).begin();
104 for ( ; lj != (*li).end(); ++lj) {
105 result += cvm::to_str(*lj);
106 result += " ";
107 }
108 result += "} ";
109 }
110 script->set_result_str(result);
111 return COLVARS_OK;
112 )
113
114CVSCRIPT(colvar_getatomids,
115 "Return the list of atom indices used by this colvar\n"
116 "indices : array of ints - Atom indices",
117 0, 0,
118 "",
119 script->set_result_int_vec(this_colvar->atom_ids);
120 return COLVARS_OK;
121 )
122
123CVSCRIPT(colvar_getconfig,
124 "Return the configuration string of this colvar\n"
125 "conf : string - Current configuration string",
126 0, 0,
127 "",
128 script->set_result_str(this_colvar->get_config());
129 return COLVARS_OK;
130 )
131
132CVSCRIPT(colvar_getgradients,
133 "Return the atomic gradients of this colvar\n"
134 "gradients : array of arrays of floats - Atomic gradients",
135 0, 0,
136 "",
137 script->set_result_rvector_vec(this_colvar->atomic_gradients);
138 return COLVARS_OK;
139 )
140
141CVSCRIPT(colvar_gettotalforce,
142 "Return the sum of internal and external forces to this colvar\n"
143 "force : float - Total force; matches the colvar dimensionality",
144 0, 0,
145 "",
146 script->set_result_colvarvalue(this_colvar->total_force());
147 return COLVARS_OK;
148 )
149
150CVSCRIPT(colvar_getvolmapids,
151 "Return the list of volumetric map indices used by this colvar",
152 0, 0,
153 "",
154 script->set_result_int_vec(this_colvar->get_volmap_ids());
155 return COLVARS_OK;
156 )
157
158CVSCRIPT(colvar_help,
159 "Get a help summary or the help string of one colvar subcommand\n"
160 "help : string - Help string",
161 0, 1,
162 "command : string - Get the help string of this specific command",
163 unsigned char *const cmdobj =
164 script->get_colvar_cmd_arg(0, objc, objv);
165 if (this_colvar) {
166 }
167 if (cmdobj) {
168 std::string const cmdstr(script->obj_to_str(cmdobj));
169 if (cmdstr.size()) {
170 script->set_result_str(script->get_command_cmdline_help(colvarscript::use_colvar,
171 cmdstr));
172 return cvm::get_error();
173 } else {
174 return COLVARSCRIPT_ERROR;
175 }
176 } else {
177 script->set_result_str(script->get_cmdline_help_summary(colvarscript::use_colvar));
178 return COLVARS_OK;
179 }
180 )
181
182CVSCRIPT(colvar_modifycvcs,
183 "Modify configuration of individual components by passing string arguments",
184 1, 1,
185 "confs : sequence of strings - New configurations; empty strings are skipped",
186 std::vector<std::string> const confs(script->obj_to_str_vector(script->get_colvar_cmd_arg(0, objc, objv)));
188 int res = this_colvar->update_cvc_config(confs);
190 if (res != COLVARS_OK) {
191 script->add_error_msg("Error setting CVC flags");
192 return COLVARSCRIPT_ERROR;
193 }
194 script->set_result_str("0");
195 return COLVARS_OK;
196 )
197
198CVSCRIPT(colvar_run_ave,
199 "Get the current running average of the value of this colvar\n"
200 "value : float or array - Averaged value; matches the colvar dimensionality",
201 0, 0,
202 "",
203 script->set_result_colvarvalue(this_colvar->run_ave());
204 return COLVARS_OK;
205 )
206
207CVSCRIPT(colvar_set,
208 "Set the given feature of this colvar to a new value",
209 2, 2,
210 "feature : string - Name of the feature\n"
211 "value : string - String representation of the new feature value",
212 return script->proc_features(this_colvar, objc, objv);
213 )
214
215CVSCRIPT(colvar_state,
216 "Print a string representation of the feature state of this colvar\n"
217 "state : string - The feature state",
218 0, 0,
219 "",
220 this_colvar->print_state();
221 return COLVARS_OK;
222 )
223
224CVSCRIPT(colvar_type,
225 "Get the type description of this colvar\n"
226 "type : string - Type description",
227 0, 0,
228 "",
229 script->set_result_str(this_colvar->value().type_desc(this_colvar->value().value_type));
230 return COLVARS_OK;
231 )
232
233CVSCRIPT(colvar_update,
234 "Recompute this colvar and return its up-to-date value\n"
235 "value : float or array - Current value; matches the colvar dimensionality",
236 0, 0,
237 "",
238 this_colvar->calc();
239 this_colvar->update_forces_energy();
240 script->set_result_colvarvalue(this_colvar->value());
241 return COLVARS_OK;
242 )
243
244CVSCRIPT(colvar_value,
245 "Get the current value of this colvar\n"
246 "value : float or array - Current value; matches the colvar dimensionality",
247 0, 0,
248 "",
249 script->set_result_colvarvalue(this_colvar->value());
250 return COLVARS_OK;
251 )
252
253CVSCRIPT(colvar_width,
254 "Get the width of this colvar\n"
255 "width : float - Value of the width",
256 0, 0,
257 "",
258 script->set_result_str(cvm::to_str(this_colvar->width, 0,
259 cvm::cv_prec));
260 return COLVARS_OK;
261 )
@ f_cv_apply_force
External force can be applied, either to atoms or to an extended DOF.
Definition: colvardeps.h:270
static void increase_depth()
Increase the depth (number of indentations in the output)
Definition: colvarmodule.cpp:1985
static size_t const cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:664
static size_t const cv_width
Number of characters to represent a collective variables value(s)
Definition: colvarmodule.h:666
static void decrease_depth()
Decrease the depth (number of indentations in the output)
Definition: colvarmodule.cpp:1991
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2392
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43