Small fixes to Colvars library

Primarily a list of small fixes, combined with cosmetic changes and cleanups
in several files.

6d0c917 2018-04-29 Fix missing deallocation of output stream object (reported by HanatoK) [Giacomo Fiorin]
c92d369 2018-04-17 Do not test for atom group size [Jérôme Hénin]
431e52a 2018-04-06 Allow scripted/custom colvars to be periodic [Jérôme Hénin]
81d391f 2018-04-05 Split colvarcomp constructor into POD constructor + init() function [Giacomo Fiorin]
9b85d5f 2018-03-13 Fix issue with out-of-order atom selections; clarify format for ref positions [Giacomo Fiorin]
0e0ed37 2018-03-07 Support triclinic unit cells in VMD, clean up PBC functions [Giacomo Fiorin]
eed97c9 2018-02-24 Obtain integer version number from version string [Giacomo Fiorin]
c17f3cd 2018-02-23 Write trajectory labels only when needed [Giacomo Fiorin]
This commit is contained in:
Giacomo Fiorin
2018-05-02 14:57:41 -04:00
parent d5ec76290b
commit 0c005f5cb0
21 changed files with 605 additions and 452 deletions

View File

@ -7,6 +7,10 @@
// If you wish to distribute your changes, please submit them to the
// Colvars repository at GitHub.
#include <list>
#include <vector>
#include <algorithm>
#include "colvarmodule.h"
#include "colvarvalue.h"
#include "colvarparse.h"
@ -14,15 +18,6 @@
#include "colvarcomp.h"
#include "colvarscript.h"
// used in build_atom_list()
#include <algorithm>
/// Compare two cvcs using their names
/// Used to sort CVC array in scripted coordinates
bool compare(colvar::cvc *i, colvar::cvc *j) {
return i->name < j->name;
}
colvar::colvar()
@ -34,6 +29,15 @@ colvar::colvar()
}
namespace {
/// Compare two cvcs using their names
/// Used to sort CVC array in scripted coordinates
bool compare(colvar::cvc *i, colvar::cvc *j)
{
return i->name < j->name;
}
}
int colvar::init(std::string const &conf)
{
cvm::log("Initializing a new collective variable.\n");
@ -143,6 +147,9 @@ int colvar::init(std::string const &conf)
x.type(cvc_value);
x_reported.type(cvc_value);
}
set_enabled(f_cv_scalar, (value().type() == colvarvalue::type_scalar));
// If using scripted biases, any colvar may receive bias forces
// and will need its gradient
if (cvm::scripted_forces()) {
@ -198,6 +205,7 @@ int colvar::init(std::string const &conf)
if (is_enabled(f_cv_homogeneous) && cvcs[0]->b_periodic) { // TODO make this a CVC feature
bool b_periodic = true;
period = cvcs[0]->period;
wrap_center = cvcs[0]->wrap_center;
for (i = 1; i < cvcs.size(); i++) {
if (!cvcs[i]->b_periodic || cvcs[i]->period != period) {
b_periodic = false;
@ -211,6 +219,14 @@ int colvar::init(std::string const &conf)
set_enabled(f_cv_periodic, b_periodic);
}
// Allow scripted/custom functions to be defined as periodic
if ( (is_enabled(f_cv_scripted) || is_enabled(f_cv_custom_function)) && is_enabled(f_cv_scalar) ) {
if (get_keyval(conf, "period", period, 0.)) {
set_enabled(f_cv_periodic, true);
get_keyval(conf, "wrapAround", wrap_center, 0.);
}
}
// check that cvcs are compatible
for (i = 0; i < cvcs.size(); i++) {
@ -443,8 +459,6 @@ int colvar::init_grid_parameters(std::string const &conf)
upper_boundary.type(value());
upper_wall.type(value());
set_enabled(f_cv_scalar, (value().type() == colvarvalue::type_scalar));
if (is_enabled(f_cv_scalar)) {
if (get_keyval(conf, "lowerBoundary", lower_boundary, lower_boundary)) {
@ -1503,7 +1517,7 @@ cvm::real colvar::update_forces_energy()
vr += (0.5 * dt) * f_ext / ext_mass;
xr += dt * vr;
xr.apply_constraints();
if (this->is_enabled(f_cv_periodic)) this->wrap(xr);
this->wrap(xr);
}
// Now adding the force on the actual colvar (for those biases that
@ -1714,9 +1728,18 @@ colvarvalue colvar::dist2_rgrad(colvarvalue const &x1,
void colvar::wrap(colvarvalue &x) const
{
if (is_enabled(f_cv_homogeneous)) {
(cvcs[0])->wrap(x);
if ( !is_enabled(f_cv_periodic) ) {
return;
}
if ( is_enabled(f_cv_scripted) || is_enabled(f_cv_custom_function) ) {
// Scripted functions do their own wrapping, as cvcs might not be periodic
cvm::real shift = std::floor((x.real_value - wrap_center) / period + 0.5);
x.real_value -= shift * period;
} else {
cvcs[0]->wrap(x);
}
return;
}
@ -2244,7 +2267,7 @@ void colvar::calc_runave()
runave.type(value().type());
runave.reset();
// first-step operations
// first-step operationsf
if (cvm::debug())
cvm::log("Colvar \""+this->name+