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