Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create abf::setup_output() for consistency #687

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions doc/cvscript-fix-modify.tex
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@
\begin{mdexampleinput}{}
\texttt{\textbf{fix\_modify Colvars save <prefix>}}
\\
\-~~~~\texttt{Change the prefix of all output files and save them}
\-~~~~\texttt{Save the current state to a restart file with the given prefix}
\\
\-~~~~\texttt{\textbf{Parameters}}
\\
\-~~~~\texttt{prefix : string - Output prefix with trailing ".colvars.state" gets removed)}
\-~~~~\texttt{prefix : string - Output prefix (trailing ".colvars.state" gets removed)}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{fix\_modify Colvars savetostring}}
Expand All @@ -342,6 +342,15 @@
\-~~~~\texttt{state : string - The saved state}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{fix\_modify Colvars outputprefix [prefix]}}
\\
\-~~~~\texttt{Get/set the prefix for all output files}
\\
\-~~~~\texttt{\textbf{Parameters}}
\\
\-~~~~\texttt{prefix : string - Output prefix (trailing ".colvars.state" gets removed) (optional)}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{fix\_modify Colvars targettemperature [T]}}
\\
\-~~~~\texttt{Get/set target temperature, overriding internally what the MD engine reports}
Expand Down Expand Up @@ -718,6 +727,15 @@
\-~~~~\texttt{state : string - The bias state}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{fix\_modify Colvars bias name writeoutput <prefix>}}
\\
\-~~~~\texttt{Write output data into files with the given prefix}
\\
\-~~~~\texttt{\textbf{Parameters}}
\\
\-~~~~\texttt{prefix : string - Prefix for the output files of this bias}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{fix\_modify Colvars bias name set <feature> <value>}}
\\
\-~~~~\texttt{Set the given feature of this bias to a new value}
Expand Down
22 changes: 20 additions & 2 deletions doc/cvscript-tcl.tex
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@
\begin{mdexampleinput}{}
\texttt{\textbf{cv save <prefix>}}
\\
\-~~~~\texttt{Change the prefix of all output files and save them}
\-~~~~\texttt{Save the current state to a restart file with the given prefix}
\\
\-~~~~\texttt{\textbf{Parameters}}
\\
\-~~~~\texttt{prefix : string - Output prefix with trailing ".colvars.state" gets removed)}
\-~~~~\texttt{prefix : string - Output prefix (trailing ".colvars.state" gets removed)}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{cv savetostring}}
Expand All @@ -342,6 +342,15 @@
\-~~~~\texttt{state : string - The saved state}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{cv outputprefix [prefix]}}
\\
\-~~~~\texttt{Get/set the prefix for all output files}
\\
\-~~~~\texttt{\textbf{Parameters}}
\\
\-~~~~\texttt{prefix : string - Output prefix (trailing ".colvars.state" gets removed) (optional)}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{cv targettemperature [T]}}
\\
\-~~~~\texttt{Get/set target temperature, overriding internally what the MD engine reports}
Expand Down Expand Up @@ -718,6 +727,15 @@
\-~~~~\texttt{state : string - The bias state}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{cv bias name writeoutput <prefix>}}
\\
\-~~~~\texttt{Write output data into files with the given prefix}
\\
\-~~~~\texttt{\textbf{Parameters}}
\\
\-~~~~\texttt{prefix : string - Prefix for the output files of this bias}
\end{mdexampleinput}
\begin{mdexampleinput}{}
\texttt{\textbf{cv bias name set <feature> <value>}}
\\
\-~~~~\texttt{Set the given feature of this bias to a new value}
Expand Down
3 changes: 3 additions & 0 deletions namd/src/colvarproxy_namd.C
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ void colvarproxy_namd::calculate()
b_simulation_continuing = true;

// Update NAMD output and restart prefixes
// FIXME: this overrides any change done via cv scripting
// should the cv outputprefix be disabled in NAMD?
// Should we detect a manual setting?
colvarproxy_io::set_output_prefix(std::string(simparams->outputFilename));
colvarproxy_io::set_restart_output_prefix(std::string(simparams->restartFilename));
colvarproxy_io::set_default_restart_frequency(simparams->restartFrequency);
Expand Down
23 changes: 14 additions & 9 deletions src/colvarbias_abf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,6 @@ int colvarbias_abf::update()
// *********************************


// update the output prefix; TODO: move later to setup_output() function
if (cvm::main()->num_biases_feature(colvardeps::f_cvb_calc_pmf) == 1) {
// This is the only bias computing PMFs
output_prefix = cvm::output_prefix();
} else {
output_prefix = cvm::output_prefix() + "." + this->name;
}


// update UI estimator every step
if (b_UI_estimator)
Expand All @@ -430,7 +422,6 @@ int colvarbias_abf::update()
x[i] = colvars[i]->actual_value();
y[i] = colvars[i]->value();
}
eabf_UI.update_output_filename(output_prefix);
eabf_UI.update(cvm::step_absolute(), x, y);
}

Expand Down Expand Up @@ -720,6 +711,20 @@ size_t colvarbias_abf::replica_share_freq() const
return shared_freq;
}

int colvarbias_abf::setup_output()
{
// update the output prefix
if (cvm::main()->num_biases_feature(colvardeps::f_cvb_calc_pmf) == 1) {
// This is the only bias computing PMFs
output_prefix = cvm::output_prefix();
} else {
output_prefix = cvm::output_prefix() + "." + this->name;
}
if (b_UI_estimator)
eabf_UI.update_output_filename(output_prefix);

return COLVARS_OK;
}

template <class T> int colvarbias_abf::write_grid_to_file(T const *grid,
std::string const &filename,
Expand Down
1 change: 1 addition & 0 deletions src/colvarbias_abf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class colvarbias_abf : public colvarbias {
~colvarbias_abf() override;
/// Per-timestep update of ABF bias
int update() override;
int setup_output() override;

private:

Expand Down
3 changes: 3 additions & 0 deletions src/colvarproxy_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class colvarproxy_io {
/// Default prefix to be used for all output files (final configuration)
std::string output_prefix_str;

/// The output prefix obtained from the backend was overridden manually via scripting
bool b_override_output_prefix = false;

/// Prefix of the restart (checkpoint) file to be written next
std::string restart_output_prefix_str;

Expand Down
28 changes: 21 additions & 7 deletions src/colvarscript_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +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 @@ -591,6 +587,24 @@ 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 output prefix to " + prefix);
int error = cvm::proxy->set_output_prefix(prefix);
error |= script->module()->setup_output();
return error;
} 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
Loading