Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvarscript_commands_bias.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(bias_bin,
12 "Get the current grid bin index (flattened if more than 1d)\n"
13 "bin : integer - Bin index",
14 0, 0,
15 "",
16 script->set_result_int(this_bias->current_bin());
17 return COLVARS_OK;
18 )
19
20
22CVSCRIPT(bias_bincount,
23 "Get the number of samples at the given grid bin (1D ABF only for now)\n"
24 "samples : integer - Number of samples",
25 0, 1,
26 "index : integer - Grid index; defaults to current bin",
27 int index = this_bias->current_bin();
28 char const *indexarg =
29 script->obj_to_str(script->get_bias_cmd_arg(0, objc, objv));
30 if (indexarg) {
31 std::string const param(indexarg);
32 if (!(std::istringstream(param) >> index)) {
33 script->add_error_msg("bincount: error parsing bin index");
34 return COLVARSCRIPT_ERROR;
35 }
36 }
37 script->set_result_int(this_bias->bin_count(index));
38 return COLVARS_OK;
39 )
40
41CVSCRIPT(bias_local_sample_count,
42 "Get the number of samples around the current bin"
43 "samples : integer - Number of samples",
44 0, 1,
45 "radius : integer - Sum over radius bins around current bin",
46 int radius = 0;
47 char const *arg =
48 script->obj_to_str(script->get_bias_cmd_arg(0, objc, objv));
49 if (arg) {
50 std::string const param(arg);
51 if (!(std::istringstream(param) >> radius)) {
52 script->add_error_msg("local_sample_count: error parsing radius");
53 return COLVARSCRIPT_ERROR;
54 }
55 }
56 script->set_result_str(cvm::to_str(this_bias->local_sample_count(radius)));
57 return COLVARS_OK;
58 )
59
60CVSCRIPT(bias_binnum,
61 "Get the total number of grid points of this bias (1D ABF only for now)\n"
62 "Bins : integer - Number of grid points",
63 0, 0,
64 "",
65 int r = this_bias->bin_num();
66 if (r < 0) {
67 script->add_error_msg("Error: calling bin_num() for bias " +
68 this_bias->name);
69 return COLVARSCRIPT_ERROR;
70 }
71 script->set_result_int(r);
72 return COLVARS_OK;
73 )
74
75CVSCRIPT(bias_delete,
76 "Delete this bias",
77 0, 0,
78 "",
79 delete this_bias;
80 return COLVARS_OK;
81 )
82
83CVSCRIPT(bias_energy,
84 "Get the current energy of this bias\n"
85 "E : float - Energy value",
86 0, 0,
87 "",
88 script->set_result_real(this_bias->get_energy());
89 return COLVARS_OK;
90 )
91
92CVSCRIPT(bias_get,
93 "Get the value of the given feature for this bias\n"
94 "state : 1/0 - State of the given feature",
95 1, 1,
96 "feature : string - Name of the feature",
97 return script->proc_features(this_bias, objc, objv);
98 )
99
100CVSCRIPT(bias_getconfig,
101 "Return the configuration string of this bias\n"
102 "conf : string - Current configuration string",
103 0, 0,
104 "",
105 script->set_result_str(this_bias->get_config());
106 return COLVARS_OK;
107 )
108
109CVSCRIPT(bias_help,
110 "Get a help summary or the help string of one bias subcommand\n"
111 "help : string - Help string",
112 0, 1,
113 "command : string - Get the help string of this specific command",
114 unsigned char *const cmdobj =
115 script->get_colvar_cmd_arg(0, objc, objv);
116 if (this_bias) {
117 }
118 if (cmdobj) {
119 std::string const cmdstr(script->obj_to_str(cmdobj));
120 if (cmdstr.size()) {
121 script->set_result_str(script->get_command_cmdline_help(colvarscript::use_bias,
122 cmdstr));
123 return cvm::get_error();
124 } else {
125 return COLVARSCRIPT_ERROR;
126 }
127 } else {
128 script->set_result_str(script->get_cmdline_help_summary(colvarscript::use_bias));
129 return COLVARS_OK;
130 }
131 )
132
133CVSCRIPT(bias_load,
134 "Load data into this bias",
135 1, 1,
136 "prefix : string - Read from a file with this name or prefix",
137 char const *arg =
138 script->obj_to_str(script->get_bias_cmd_arg(0, objc, objv));
139 return this_bias->read_state_prefix(std::string(arg));
140 )
141
142CVSCRIPT(bias_loadfromstring,
143 "Load state data into this bias from a string",
144 1, 1,
145 "buffer : string - String buffer containing the state information",
146 char const *buffer = script->obj_to_str(script->get_bias_cmd_arg(0, objc, objv));
147 return this_bias->read_state_string(buffer);
148 )
149
150CVSCRIPT(bias_save,
151 "Save data from this bias into a file with the given prefix",
152 1, 1,
153 "prefix : string - Prefix for the state file of this bias",
154 std::string const prefix =
155 cvm::state_file_prefix(script->obj_to_str(script->get_bias_cmd_arg(0, objc, objv)));
156 return this_bias->write_state_prefix(prefix);
157 )
158
159CVSCRIPT(bias_savetostring,
160 "Save data from this bias into a string and return it\n"
161 "state : string - The bias state",
162 0, 0,
163 "",
164 return this_bias->write_state_string(script->modify_str_result());
165 )
166
167CVSCRIPT(bias_set,
168 "Set the given feature of this bias to a new value",
169 2, 2,
170 "feature : string - Name of the feature\n"
171 "value : string - String representation of the new feature value",
172 return script->proc_features(this_bias, objc, objv);
173 )
174
175CVSCRIPT(bias_share,
176 "Share bias information with other replicas (multiple-walker scheme)",
177 0, 0,
178 "",
179 if (this_bias->replica_share() != COLVARS_OK) {
180 script->add_error_msg("Error: calling replica_share() for bias " +
181 this_bias->name);
182 return COLVARSCRIPT_ERROR;
183 }
184 return COLVARS_OK;
185 )
186
187CVSCRIPT(bias_state,
188 "Print a string representation of the feature state of this bias\n"
189 "state : string - String representation of the bias features",
190 0, 0,
191 "",
192 this_bias->print_state();
193 return COLVARS_OK;
194 )
195
196CVSCRIPT(bias_type,
197 "Print the type of this bias object\n"
198 "type : string - Type of this bias object (e.g. metadynamics)",
199 0, 0,
200 "",
201 script->set_result_str(this_bias->bias_type);
202 return COLVARS_OK;
203 )
204
205CVSCRIPT(bias_update,
206 "Recompute this bias and return its up-to-date energy\n"
207 "E : float - Energy value",
208 0, 0,
209 "",
210 this_bias->update();
211 script->set_result_colvarvalue(this_bias->get_energy());
212 return COLVARS_OK;
213 )
static std::string state_file_prefix(char const *filename)
Strips .colvars.state from filename and checks that it is not empty.
Definition: colvarmodule.cpp:1505
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2373