synchronize with the colvars git repo again

This commit is contained in:
Axel Kohlmeyer
2014-10-22 10:38:06 -04:00
parent ff0d7028fe
commit c47c1428c2
7 changed files with 125 additions and 144 deletions

Binary file not shown.

View File

@ -187,39 +187,19 @@ colvar::colvar (std::string const &conf)
for (j = 0; j < cvcs.size(); j++) { for (j = 0; j < cvcs.size(); j++) {
sorted_cvc_values.push_back(cvcs[j]->p_value()); sorted_cvc_values.push_back(cvcs[j]->p_value());
} }
}
if (!tasks[task_scripted]) { b_homogeneous = false;
// this is set false if any of the components has an exponent // Scripted functions are deemed non-periodic
// different from 1 in the polynomial
b_linear = true;
// these will be set to false if any of the cvcs has them false
b_inverse_gradients = true;
b_Jacobian_force = true;
}
// Test whether this is a single-component variable
// Decide whether the colvar is periodic
// Used to wrap extended DOF if extendedLagrangian is on
if (cvcs.size() == 1 && (cvcs[0])->sup_np == 1
&& (cvcs[0])->sup_coeff == 1.0
&& !tasks[task_scripted]) {
b_single_cvc = true;
b_periodic = (cvcs[0])->b_periodic;
period = (cvcs[0])->period;
// TODO write explicit wrap() function for colvars to allow for
// sup_coeff different from 1
// this->period = (cvcs[0])->period * (cvcs[0])->sup_coeff;
} else {
b_single_cvc = false;
b_periodic = false; b_periodic = false;
period = 0.0; period = 0.0;
b_inverse_gradients = false;
b_Jacobian_force = false;
} }
// check the available features of each cvc // check for linear combinations
for (i = 0; i < cvcs.size(); i++) {
b_linear = !tasks[task_scripted];
for (i = 0; i < cvcs.size(); i++) {
if ((cvcs[i])->b_debug_gradients) if ((cvcs[i])->b_debug_gradients)
enable (task_gradients); enable (task_gradients);
@ -237,7 +217,41 @@ colvar::colvar (std::string const &conf)
(cvcs[i])->function_type+"\" approaches zero.\n"); (cvcs[i])->function_type+"\" approaches zero.\n");
} }
} }
}
// Colvar is homogeneous iff:
// - it is not scripted
// - it is linear
// - all cvcs have coefficient 1 or -1
// i.e. sum or difference of cvcs
b_homogeneous = !tasks[task_scripted] && b_linear;
for (i = 0; i < cvcs.size(); i++) {
if ((std::fabs(cvcs[i]->sup_coeff) - 1.0) > 1.0e-10) {
b_homogeneous = false;
}
}
// Colvar is deemed periodic iff:
// - it is homogeneous
// - all cvcs are periodic
// - all cvcs have the same period
b_periodic = cvcs[0]->b_periodic && b_homogeneous;
period = cvcs[0]->period;
for (i = 1; i < cvcs.size(); i++) {
if (!cvcs[i]->b_periodic || cvcs[i]->period != period) {
b_periodic = false;
period = 0.0;
}
}
// these will be set to false if any of the cvcs has them false
b_inverse_gradients = !tasks[task_scripted];
b_Jacobian_force = !tasks[task_scripted];
// check the available features of each cvc
for (i = 0; i < cvcs.size(); i++) {
if ((cvcs[i])->b_periodic && !b_periodic) { if ((cvcs[i])->b_periodic && !b_periodic) {
cvm::log ("Warning: although this component is periodic, the colvar will " cvm::log ("Warning: although this component is periodic, the colvar will "
"not be treated as periodic, either because the exponent is not " "not be treated as periodic, either because the exponent is not "
@ -251,22 +265,17 @@ colvar::colvar (std::string const &conf)
if (! (cvcs[i])->b_Jacobian_derivative) if (! (cvcs[i])->b_Jacobian_derivative)
b_Jacobian_force = false; b_Jacobian_force = false;
if (!tasks[task_scripted]) { // components may have different types only for scripted functions
// If the combination of components is a scripted function, if (!tasks[task_scripted] && (cvcs[i])->type() != (cvcs[0])->type() ) {
// the components may have different types cvm::error("ERROR: you are definining this collective variable "
for (size_t j = i; j < cvcs.size(); j++) {
if ( (cvcs[i])->type() != (cvcs[j])->type() ) {
cvm::log ("ERROR: you are definining this collective variable "
"by using components of different types, \""+ "by using components of different types, \""+
colvarvalue::type_desc[(cvcs[i])->type()]+ colvarvalue::type_desc[(cvcs[0])->type()]+
"\" and \""+ "\" and \""+
colvarvalue::type_desc[(cvcs[j])->type()]+ colvarvalue::type_desc[(cvcs[i])->type()]+
"\". " "\". "
"You must use the same type in order to " "You must use the same type in order to "
" sum them together.\n"); " sum them together.\n", INPUT_ERROR);
cvm::set_error_bits(INPUT_ERROR); return;
}
}
} }
} }
@ -1235,7 +1244,7 @@ bool colvar::periodic_boundaries() const
cvm::real colvar::dist2 (colvarvalue const &x1, cvm::real colvar::dist2 (colvarvalue const &x1,
colvarvalue const &x2) const colvarvalue const &x2) const
{ {
if (b_single_cvc) { if (b_homogeneous) {
return (cvcs[0])->dist2(x1, x2); return (cvcs[0])->dist2(x1, x2);
} else { } else {
return x1.dist2(x2); return x1.dist2(x2);
@ -1245,7 +1254,7 @@ cvm::real colvar::dist2 (colvarvalue const &x1,
colvarvalue colvar::dist2_lgrad (colvarvalue const &x1, colvarvalue colvar::dist2_lgrad (colvarvalue const &x1,
colvarvalue const &x2) const colvarvalue const &x2) const
{ {
if (b_single_cvc) { if (b_homogeneous) {
return (cvcs[0])->dist2_lgrad (x1, x2); return (cvcs[0])->dist2_lgrad (x1, x2);
} else { } else {
return x1.dist2_grad(x2); return x1.dist2_grad(x2);
@ -1255,7 +1264,7 @@ colvarvalue colvar::dist2_lgrad (colvarvalue const &x1,
colvarvalue colvar::dist2_rgrad (colvarvalue const &x1, colvarvalue colvar::dist2_rgrad (colvarvalue const &x1,
colvarvalue const &x2) const colvarvalue const &x2) const
{ {
if (b_single_cvc) { if (b_homogeneous) {
return (cvcs[0])->dist2_rgrad (x1, x2); return (cvcs[0])->dist2_rgrad (x1, x2);
} else { } else {
return x2.dist2_grad(x1); return x2.dist2_grad(x1);
@ -1264,7 +1273,7 @@ colvarvalue colvar::dist2_rgrad (colvarvalue const &x1,
void colvar::wrap (colvarvalue &x) const void colvar::wrap (colvarvalue &x) const
{ {
if (b_single_cvc) { if (b_homogeneous) {
(cvcs[0])->wrap (x); (cvcs[0])->wrap (x);
} }
return; return;

View File

@ -83,9 +83,9 @@ public:
/// combination of \link cvc \endlink elements /// combination of \link cvc \endlink elements
bool b_linear; bool b_linear;
/// \brief True if this \link colvar \endlink is equal to /// \brief True if this \link colvar \endlink is a linear
/// its only constituent cvc /// combination of cvcs with coefficients 1 or -1
bool b_single_cvc; bool b_homogeneous;
/// \brief True if all \link cvc \endlink objects are capable /// \brief True if all \link cvc \endlink objects are capable
/// of calculating inverse gradients /// of calculating inverse gradients

View File

@ -472,100 +472,73 @@ cvm::real colvarmodule::read_width(std::string const &name)
return width; return width;
} }
size_t colvarmodule::bias_current_bin (std::string const &bias_name) int colvarmodule::bias_current_bin (std::string const &bias_name)
{ {
cvm::increase_depth(); cvm::increase_depth();
int found = 0; int ret;
size_t ret = 0; // N.B.: size_t is unsigned, so returning -1 would be a problem. colvarbias *b = bias_by_name(bias_name);
for (std::vector<colvarbias *>::iterator bi = biases.begin(); if (b != NULL) {
bi != biases.end(); ret = b->current_bin();
bi++) {
if ( (*bi)->name == bias_name ) {
++found;
ret = (*bi)->current_bin ();
}
}
if (found < 1) {
cvm::error ("Error: bias not found.\n");
} else if (found > 1) {
cvm::error ("Error: duplicate bias name.\n");
} else { } else {
cvm::decrease_depth(); cvm::error ("Error: bias not found.\n");
ret = COLVARS_ERROR;
} }
cvm::decrease_depth();
return ret; return ret;
} }
size_t colvarmodule::bias_bin_num (std::string const &bias_name) int colvarmodule::bias_bin_num (std::string const &bias_name)
{ {
cvm::increase_depth(); cvm::increase_depth();
int found = 0; int ret;
size_t ret = 0; // N.B.: size_t is unsigned, so returning -1 would be a problem. colvarbias *b = bias_by_name(bias_name);
for (std::vector<colvarbias *>::iterator bi = biases.begin(); if (b != NULL) {
bi != biases.end(); ret = b->bin_num();
bi++) {
if ( (*bi)->name == bias_name ) {
++found;
ret = (*bi)->bin_num ();
}
}
if (found < 1) {
cvm::error ("Error: bias not found.\n");
} else if (found > 1) {
cvm::error ("Error: duplicate bias name.\n");
} else { } else {
cvm::decrease_depth(); cvm::error ("Error: bias not found.\n");
ret = COLVARS_ERROR;
} }
cvm::decrease_depth();
return ret; return ret;
} }
size_t colvarmodule::bias_bin_count (std::string const &bias_name, size_t bin_index) int colvarmodule::bias_bin_count (std::string const &bias_name, size_t bin_index)
{ {
cvm::increase_depth(); cvm::increase_depth();
int found = 0; int ret;
size_t ret = 0; // N.B.: size_t is unsigned, so returning -1 would be a problem. colvarbias *b = bias_by_name(bias_name);
for (std::vector<colvarbias *>::iterator bi = biases.begin(); if (b != NULL) {
bi != biases.end(); ret = b->bin_count(bin_index);
bi++) {
if ( (*bi)->name == bias_name ) {
++found;
ret = (*bi)->bin_count (bin_index);
}
}
if (found < 1) {
cvm::error ("Error: bias not found.\n");
} else if (found > 1) {
cvm::error ("Error: duplicate bias name.\n");
} else { } else {
cvm::decrease_depth(); cvm::error ("Error: bias not found.\n");
ret = COLVARS_ERROR;
} }
cvm::decrease_depth();
return ret; return ret;
} }
void colvarmodule::bias_share (std::string const &bias_name) int colvarmodule::bias_share (std::string const &bias_name)
{ {
cvm::increase_depth(); cvm::increase_depth();
int found = 0; int ret;
colvarbias *b = bias_by_name(bias_name);
for (std::vector<colvarbias *>::iterator bi = biases.begin(); if (b != NULL) {
bi != biases.end(); b->replica_share();
bi++) { ret = COLVARS_OK;
if ( (*bi)->name == bias_name ) { } else {
++found;
(*bi)->replica_share ();
}
}
if (found < 1) {
cvm::error ("Error: bias not found.\n"); cvm::error ("Error: bias not found.\n");
return; ret = COLVARS_ERROR;
}
if (found > 1) {
cvm::error ("Error: duplicate bias name.\n");
return;
} }
cvm::decrease_depth(); cvm::decrease_depth();
return ret;
} }

View File

@ -4,7 +4,7 @@
#define COLVARMODULE_H #define COLVARMODULE_H
#ifndef COLVARS_VERSION #ifndef COLVARS_VERSION
#define COLVARS_VERSION "2014-10-21" #define COLVARS_VERSION "2014-10-22"
#endif #endif
#ifndef COLVARS_DEBUG #ifndef COLVARS_DEBUG
@ -21,6 +21,7 @@
/// objects. /// objects.
// Internal method return codes // Internal method return codes
#define COLVARS_NOT_IMPLEMENTED -2
#define COLVARS_ERROR -1 #define COLVARS_ERROR -1
#define COLVARS_OK 0 #define COLVARS_OK 0
@ -276,13 +277,13 @@ public:
/// Give the bin width in the units of the colvar. /// Give the bin width in the units of the colvar.
real read_width(std::string const &name); real read_width(std::string const &name);
/// Give the total number of bins for a given bias. /// Give the total number of bins for a given bias.
size_t bias_bin_num(std::string const &bias_name); int bias_bin_num(std::string const &bias_name);
/// Calculate the bin index for a given bias. /// Calculate the bin index for a given bias.
size_t bias_current_bin(std::string const &bias_name); int bias_current_bin(std::string const &bias_name);
//// Give the count at a given bin index. //// Give the count at a given bin index.
size_t bias_bin_count(std::string const &bias_name, size_t bin_index); int bias_bin_count(std::string const &bias_name, size_t bin_index);
//// Share among replicas. //// Share among replicas.
void bias_share(std::string const &bias_name); int bias_share(std::string const &bias_name);
/// Calculate collective variables and biases /// Calculate collective variables and biases
int calc(); int calc();

View File

@ -12,10 +12,8 @@
#include "colvarmodule.h" #include "colvarmodule.h"
#include "colvarvalue.h" #include "colvarvalue.h"
// return values for the frame() routine // return values for the frame() routine
#define COLVARS_NO_SUCH_FRAME -1 #define COLVARS_NO_SUCH_FRAME -1
#define COLVARS_NOT_IMPLEMENTED -2
// forward declarations // forward declarations
class colvarscript; class colvarscript;