Update Colvars to version 2017-10-11
Notable features are the umbrella-integration based free energy estimator for eABF, and the traditional thermodynamic integration estimator now available for umbrella sampling, SMD, metadynamics. Also included are several small fixes. Below is a list of relevant commits in the Colvars repository since the last update. 321d06a 2017-10-10 Add macros to manage colvarscript commands [Giacomo Fiorin] 26c3bec 2017-10-09 Document coming availability of Lepton in LAMMPS [Giacomo Fiorin] cc8f249 2017-10-04 Clarify that SMP depends on code build [Giacomo Fiorin] 0b2ffac 2017-10-04 Summarize colvar definition options, clarify some details [Giacomo Fiorin] 28002e0 2017-10-01 Separate writing of restart file from other output (e.g. PMFs) [Giacomo Fiorin] 92f7c1d 2017-10-01 Deprecate colvarsTrajAppend [Giacomo Fiorin] 12a707f 2017-09-26 Accurate Jacobian calculation for RMSD variants [Jérôme Hénin] fe389c9 2017-09-21 Allow subtractAppliedForce with extended-L again [Jérôme Hénin] c050ce0 2017-09-18 Silence compiler warnings, remove Tabs [Giacomo Fiorin] cb41905 2017-01-11 Add base class for TI estimator in other biases than ABF [Giacomo Fiorin] a1bc676 2017-09-14 Avoid writing to unopened traj file [Jérôme Hénin] b58d8cd 2017-09-08 Function to check for overlapping groups [Jérôme Hénin] 1e5efec 2017-09-07 Check for overlapping groups in coordNum [Jérôme Hénin] 03a61a4 2017-04-06 Add UI-based estimator [fhh2626] ae43754 2017-08-17 Fix outputCenters parsing [Josh Vermaas] 1619e0e 2017-08-14 Delete static feature arrays in cvm destructor [Jérôme Hénin]
This commit is contained in:
@ -10,6 +10,7 @@
|
||||
#include "colvarmodule.h"
|
||||
#include "colvarvalue.h"
|
||||
#include "colvarbias.h"
|
||||
#include "colvargrid.h"
|
||||
|
||||
|
||||
colvarbias::colvarbias(char const *key)
|
||||
@ -31,12 +32,14 @@ int colvarbias::init(std::string const &conf)
|
||||
{
|
||||
colvarparse::init(conf);
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
if (name.size() == 0) {
|
||||
|
||||
// first initialization
|
||||
|
||||
cvm::log("Initializing a new \""+bias_type+"\" instance.\n");
|
||||
rank = cvm::num_biases_type(bias_type);
|
||||
rank = cvm::main()->num_biases_type(bias_type);
|
||||
get_keyval(conf, "name", name, bias_type+cvm::to_str(rank));
|
||||
|
||||
{
|
||||
@ -62,7 +65,7 @@ int colvarbias::init(std::string const &conf)
|
||||
INPUT_ERROR);
|
||||
return INPUT_ERROR;
|
||||
}
|
||||
for (size_t i = 0; i < colvar_names.size(); i++) {
|
||||
for (i = 0; i < colvar_names.size(); i++) {
|
||||
add_colvar(colvar_names[i]);
|
||||
}
|
||||
}
|
||||
@ -148,6 +151,13 @@ int colvarbias::clear()
|
||||
}
|
||||
|
||||
|
||||
int colvarbias::clear_state_data()
|
||||
{
|
||||
// no mutable content to delete for base class
|
||||
return COLVARS_OK;
|
||||
}
|
||||
|
||||
|
||||
int colvarbias::add_colvar(std::string const &cv_name)
|
||||
{
|
||||
if (colvar *cv = cvm::colvar_by_name(cv_name)) {
|
||||
@ -164,6 +174,8 @@ int colvarbias::add_colvar(std::string const &cv_name)
|
||||
colvar_forces.back().is_derivative(); // colvar constraints are not applied to the force
|
||||
colvar_forces.back().reset();
|
||||
|
||||
previous_colvar_forces.push_back(colvar_forces.back());
|
||||
|
||||
cv->biases.push_back(this); // add back-reference to this bias to colvar
|
||||
|
||||
if (is_enabled(f_cvb_apply_force)) {
|
||||
@ -204,7 +216,8 @@ int colvarbias::update()
|
||||
|
||||
void colvarbias::communicate_forces()
|
||||
{
|
||||
for (size_t i = 0; i < num_variables(); i++) {
|
||||
size_t i = 0;
|
||||
for (i = 0; i < num_variables(); i++) {
|
||||
if (cvm::debug()) {
|
||||
cvm::log("Communicating a force to colvar \""+
|
||||
variables(i)->name+"\".\n");
|
||||
@ -216,6 +229,9 @@ void colvarbias::communicate_forces()
|
||||
// aware of this bias' time_step_factor
|
||||
variables(i)->add_bias_force(cvm::real(time_step_factor) * colvar_forces[i]);
|
||||
}
|
||||
for (i = 0; i < num_variables(); i++) {
|
||||
previous_colvar_forces[i] = colvar_forces[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -389,6 +405,248 @@ std::ostream & colvarbias::write_traj(std::ostream &os)
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
colvarbias_ti::colvarbias_ti(char const *key)
|
||||
: colvarbias(key)
|
||||
{
|
||||
provide(f_cvb_calc_ti_samples);
|
||||
ti_avg_forces = NULL;
|
||||
ti_count = NULL;
|
||||
}
|
||||
|
||||
|
||||
colvarbias_ti::~colvarbias_ti()
|
||||
{
|
||||
colvarbias_ti::clear_state_data();
|
||||
}
|
||||
|
||||
|
||||
int colvarbias_ti::clear_state_data()
|
||||
{
|
||||
if (ti_avg_forces != NULL) {
|
||||
delete ti_avg_forces;
|
||||
ti_avg_forces = NULL;
|
||||
}
|
||||
if (ti_count != NULL) {
|
||||
delete ti_count;
|
||||
ti_count = NULL;
|
||||
}
|
||||
return COLVARS_OK;
|
||||
}
|
||||
|
||||
|
||||
int colvarbias_ti::init(std::string const &conf)
|
||||
{
|
||||
int error_code = COLVARS_OK;
|
||||
|
||||
get_keyval_feature(this, conf, "writeTISamples",
|
||||
f_cvb_write_ti_samples,
|
||||
is_enabled(f_cvb_write_ti_samples));
|
||||
|
||||
get_keyval_feature(this, conf, "writeTIPMF",
|
||||
f_cvb_write_ti_pmf,
|
||||
is_enabled(f_cvb_write_ti_pmf));
|
||||
|
||||
if ((num_variables() > 1) && is_enabled(f_cvb_write_ti_pmf)) {
|
||||
return cvm::error("Error: only 1-dimensional PMFs can be written "
|
||||
"on the fly.\n"
|
||||
"Consider using writeTISamples instead and "
|
||||
"post-processing the sampled free-energy gradients.\n",
|
||||
COLVARS_NOT_IMPLEMENTED);
|
||||
} else {
|
||||
error_code |= init_grids();
|
||||
}
|
||||
|
||||
if (is_enabled(f_cvb_write_ti_pmf)) {
|
||||
enable(f_cvb_write_ti_samples);
|
||||
}
|
||||
|
||||
if (is_enabled(f_cvb_calc_ti_samples)) {
|
||||
std::vector<std::string> const time_biases =
|
||||
cvm::main()->time_dependent_biases();
|
||||
if (time_biases.size() > 0) {
|
||||
if ((time_biases.size() > 1) || (time_biases[0] != this->name)) {
|
||||
for (size_t i = 0; i < num_variables(); i++) {
|
||||
if (! variables(i)->is_enabled(f_cv_subtract_applied_force)) {
|
||||
return cvm::error("Error: cannot collect TI samples while other "
|
||||
"time-dependent biases are active and not all "
|
||||
"variables have subtractAppliedForces on.\n",
|
||||
INPUT_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return error_code;
|
||||
}
|
||||
|
||||
|
||||
int colvarbias_ti::init_grids()
|
||||
{
|
||||
if (is_enabled(f_cvb_calc_ti_samples)) {
|
||||
if (ti_avg_forces == NULL) {
|
||||
ti_bin.resize(num_variables());
|
||||
ti_system_forces.resize(num_variables());
|
||||
for (size_t icv = 0; icv < num_variables(); icv++) {
|
||||
ti_system_forces[icv].type(variables(icv)->value());
|
||||
ti_system_forces[icv].is_derivative();
|
||||
ti_system_forces[icv].reset();
|
||||
}
|
||||
ti_avg_forces = new colvar_grid_gradient(colvars);
|
||||
ti_count = new colvar_grid_count(colvars);
|
||||
ti_avg_forces->samples = ti_count;
|
||||
ti_count->has_parent_data = true;
|
||||
}
|
||||
}
|
||||
|
||||
return COLVARS_OK;
|
||||
}
|
||||
|
||||
|
||||
int colvarbias_ti::update()
|
||||
{
|
||||
return update_system_forces(NULL);
|
||||
}
|
||||
|
||||
|
||||
int colvarbias_ti::update_system_forces(std::vector<colvarvalue> const
|
||||
*subtract_forces)
|
||||
{
|
||||
if (! is_enabled(f_cvb_calc_ti_samples)) {
|
||||
return COLVARS_OK;
|
||||
}
|
||||
|
||||
has_data = true;
|
||||
|
||||
if (cvm::debug()) {
|
||||
cvm::log("Updating system forces for bias "+this->name+"\n");
|
||||
}
|
||||
|
||||
// Collect total colvar forces from the previous step
|
||||
size_t i;
|
||||
if (cvm::step_relative() > 0) {
|
||||
if (ti_avg_forces->index_ok(ti_bin)) {
|
||||
for (i = 0; i < num_variables(); i++) {
|
||||
if (variables(i)->is_enabled(f_cv_subtract_applied_force)) {
|
||||
// this colvar is already subtracting all applied forces
|
||||
ti_system_forces[i] = variables(i)->total_force();
|
||||
} else {
|
||||
ti_system_forces[i] = variables(i)->total_force() -
|
||||
((subtract_forces != NULL) ?
|
||||
(*subtract_forces)[i] : previous_colvar_forces[i]);
|
||||
}
|
||||
}
|
||||
ti_avg_forces->acc_value(ti_bin, ti_system_forces);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the index to be used in the next iteration, when total forces come in
|
||||
for (i = 0; i < num_variables(); i++) {
|
||||
ti_bin[i] = ti_avg_forces->current_bin_scalar(i);
|
||||
}
|
||||
|
||||
return COLVARS_OK;
|
||||
}
|
||||
|
||||
|
||||
std::string const colvarbias_ti::get_state_params() const
|
||||
{
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
|
||||
int colvarbias_ti::set_state_params(std::string const &state_conf)
|
||||
{
|
||||
return COLVARS_OK;
|
||||
}
|
||||
|
||||
|
||||
std::ostream & colvarbias_ti::write_state_data(std::ostream &os)
|
||||
{
|
||||
if (! is_enabled(f_cvb_calc_ti_samples)) {
|
||||
return os;
|
||||
}
|
||||
os << "\nhistogram\n";
|
||||
ti_count->write_raw(os);
|
||||
os << "\nsystem_forces\n";
|
||||
ti_avg_forces->write_raw(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
std::istream & colvarbias_ti::read_state_data(std::istream &is)
|
||||
{
|
||||
if (! is_enabled(f_cvb_calc_ti_samples)) {
|
||||
return is;
|
||||
}
|
||||
if (cvm::debug()) {
|
||||
cvm::log("Reading state data for the TI estimator.\n");
|
||||
}
|
||||
if (! read_state_data_key(is, "histogram")) {
|
||||
return is;
|
||||
}
|
||||
if (! ti_count->read_raw(is)) {
|
||||
return is;
|
||||
}
|
||||
if (! read_state_data_key(is, "system_forces")) {
|
||||
return is;
|
||||
}
|
||||
if (! ti_avg_forces->read_raw(is)) {
|
||||
return is;
|
||||
}
|
||||
if (cvm::debug()) {
|
||||
cvm::log("Done reading state data for the TI estimator.\n");
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
int colvarbias_ti::write_output_files()
|
||||
{
|
||||
if (!has_data) {
|
||||
// nothing to write
|
||||
return COLVARS_OK;
|
||||
}
|
||||
|
||||
std::string const ti_output_prefix = cvm::output_prefix()+"."+this->name;
|
||||
|
||||
std::ostream *os = NULL;
|
||||
|
||||
if (is_enabled(f_cvb_write_ti_samples)) {
|
||||
std::string const ti_count_file_name(ti_output_prefix+".ti.count");
|
||||
os = cvm::proxy->output_stream(ti_count_file_name);
|
||||
if (os) {
|
||||
ti_count->write_multicol(*os);
|
||||
cvm::proxy->close_output_stream(ti_count_file_name);
|
||||
}
|
||||
|
||||
std::string const ti_grad_file_name(ti_output_prefix+".ti.grad");
|
||||
os = cvm::proxy->output_stream(ti_grad_file_name);
|
||||
if (os) {
|
||||
ti_avg_forces->write_multicol(*os);
|
||||
cvm::proxy->close_output_stream(ti_grad_file_name);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_enabled(f_cvb_write_ti_pmf)) {
|
||||
std::string const pmf_file_name(ti_output_prefix+".ti.pmf");
|
||||
cvm::log("Writing TI PMF to file \""+pmf_file_name+"\".\n");
|
||||
os = cvm::proxy->output_stream(pmf_file_name);
|
||||
if (os) {
|
||||
// get the FE gradient
|
||||
ti_avg_forces->multiply_constant(-1.0);
|
||||
ti_avg_forces->write_1D_integral(*os);
|
||||
ti_avg_forces->multiply_constant(-1.0);
|
||||
cvm::proxy->close_output_stream(pmf_file_name);
|
||||
}
|
||||
}
|
||||
|
||||
return COLVARS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Static members
|
||||
|
||||
std::vector<colvardeps::feature *> colvarbias::cvb_features;
|
||||
|
||||
Reference in New Issue
Block a user