Skip to content

Commit

Permalink
Add scripting functions for output
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenin committed Aug 27, 2024
1 parent 7df9a43 commit 0181ba4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/colvarscript_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,12 @@ CVSCRIPT(cv_resetindexgroups,
)

CVSCRIPT(cv_save,
"Change the prefix of all output files and save them",
"Save the current state to a restart file with the given prefix",
1, 1,
"prefix : string - Output prefix with trailing \".colvars.state\" gets removed)",
"prefix : string - Output prefix (trailing \".colvars.state\" gets removed)",
std::string const prefix =
cvm::state_file_prefix(script->obj_to_str(script->get_module_cmd_arg(0, objc, objv)));
int error_code = script->proxy()->set_output_prefix(prefix);
error_code |= script->module()->setup_output();
error_code |= script->module()->write_restart_file(prefix + ".colvars.state");
error_code |= script->module()->write_output_files();
int error_code = script->module()->write_restart_file(prefix + ".colvars.state");
return error_code;
)

Expand All @@ -590,6 +587,22 @@ CVSCRIPT(cv_savetostring,
return script->module()->write_restart_string(script->modify_str_result());
)

CVSCRIPT(cv_outputprefix,
"Get/set the prefix for all output files",
0, 1,
"prefix : string - Output prefix (trailing \".colvars.state\" gets removed)",
char const *argstr =
script->obj_to_str(script->get_module_cmd_arg(0, objc, objv));
if (argstr) {
std::string const prefix = cvm::state_file_prefix(argstr);
cvm::log("SETTING PREFIX TO " + prefix);
return cvm::proxy->set_output_prefix(prefix);
} else {
script->set_result_str(cvm::output_prefix());
return COLVARS_OK;
}
)

CVSCRIPT(cv_targettemperature,
"Get/set target temperature, overriding internally what the MD engine reports\n"
"T : float - Current target temperature in K",
Expand Down
15 changes: 15 additions & 0 deletions src/colvarscript_commands_bias.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ CVSCRIPT(bias_savetostring,
return this_bias->write_state_string(script->modify_str_result());
)

CVSCRIPT(bias_writeoutput,
"Write output data into files with the given prefix",
1, 1,
"prefix : string - Prefix for the output files of this bias",
std::string const prefix =
cvm::state_file_prefix(script->obj_to_str(script->get_bias_cmd_arg(0, objc, objv)));
std::string prefix_bak = cvm::output_prefix();
cvm::proxy->set_output_prefix(prefix);
this_bias->setup_output();
int error_code = this_bias->write_output_files();
cvm::proxy->set_output_prefix(prefix_bak);
this_bias->setup_output();
return error_code;
)

CVSCRIPT(bias_set,
"Set the given feature of this bias to a new value",
2, 2,
Expand Down
1 change: 1 addition & 0 deletions tests/unittests/embedded_tcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern "C" int main(int argc, char *argv[]) {
return 1;
}

proxy->tcl_run_script("puts \"(Tcl) This is Tcl version [info tclversion]\"");
proxy->tcl_run_script("puts \"(Tcl) Currently defined variables:\n(Tcl) [info vars]\"");
proxy->tcl_run_script("puts \"(Tcl) Currently defined procedures:\n(Tcl) [info procs]\"");

Expand Down

0 comments on commit 0181ba4

Please sign in to comment.