diff --git a/doc/PDF/colvars-refman-lammps.pdf b/doc/PDF/colvars-refman-lammps.pdf index c3097de645..34593547c7 100644 Binary files a/doc/PDF/colvars-refman-lammps.pdf and b/doc/PDF/colvars-refman-lammps.pdf differ diff --git a/lib/colvars/colvar.cpp b/lib/colvars/colvar.cpp index bc1c192f2d..c5aa80a4f0 100644 --- a/lib/colvars/colvar.cpp +++ b/lib/colvars/colvar.cpp @@ -727,6 +727,7 @@ int colvar::enable(colvar::task const &t) case task_output_value: case task_runave: case task_corrfunc: + case task_ntot: case task_langevin: case task_output_energy: case task_scripted: @@ -1105,44 +1106,6 @@ cvm::real colvar::update() f += fb; - if (tasks[task_lower_wall] || tasks[task_upper_wall]) { - - // wall force - colvarvalue fw(value()); - fw.reset(); - - if (cvm::debug()) - cvm::log("Calculating wall forces for colvar \""+this->name+"\".\n"); - - // if the two walls are applied concurrently, decide which is the - // closer one (on a periodic colvar, both walls may be applicable - // at the same time) - if ( (!tasks[task_upper_wall]) || - (this->dist2(x_reported, lower_wall) < this->dist2(x_reported, upper_wall)) ) { - - cvm::real const grad = this->dist2_lgrad(x_reported, lower_wall); - if (grad < 0.0) { - fw = -0.5 * lower_wall_k * grad; - if (cvm::debug()) - cvm::log("Applying a lower wall force("+ - cvm::to_str(fw)+") to \""+this->name+"\".\n"); - f += fw; - - } - - } else { - - cvm::real const grad = this->dist2_lgrad(x_reported, upper_wall); - if (grad > 0.0) { - fw = -0.5 * upper_wall_k * grad; - if (cvm::debug()) - cvm::log("Applying an upper wall force("+ - cvm::to_str(fw)+") to \""+this->name+"\".\n"); - f += fw; - } - } - } - if (tasks[task_Jacobian_force]) { size_t i; for (i = 0; i < cvcs.size(); i++) { @@ -1177,10 +1140,11 @@ cvm::real colvar::update() // the total force is applied to the fictitious mass, while the // atoms only feel the harmonic force - // fr: extended coordinate force (without harmonic spring), for output in trajectory + // fr: bias force on extended coordinate (without harmonic spring), for output in trajectory // f_ext: total force on extended coordinate (including harmonic spring) // f: - initially, external biasing force - // - after this code block, colvar force to be applied to atomic coordinates, ie. spring force + // - after this code block, colvar force to be applied to atomic coordinates, ie. spring force + // (note: wall potential is added to f after this block) fr = f; f_ext = f + (-0.5 * ext_force_k) * this->dist2_lgrad(xr, x); f = (-0.5 * ext_force_k) * this->dist2_rgrad(xr, x); @@ -1202,6 +1166,44 @@ cvm::real colvar::update() } + // Adding wall potential to "true" colvar force, whether or not an extended coordinate is in use + if (tasks[task_lower_wall] || tasks[task_upper_wall]) { + + // Wall force + colvarvalue fw(x); + fw.reset(); + + if (cvm::debug()) + cvm::log("Calculating wall forces for colvar \""+this->name+"\".\n"); + + // For a periodic colvar, both walls may be applicable at the same time + // in which case we pick the closer one + if ( (!tasks[task_upper_wall]) || + (this->dist2(x, lower_wall) < this->dist2(x, upper_wall)) ) { + + cvm::real const grad = this->dist2_lgrad(x, lower_wall); + if (grad < 0.0) { + fw = -0.5 * lower_wall_k * grad; + f += fw; + if (cvm::debug()) + cvm::log("Applying a lower wall force("+ + cvm::to_str(fw)+") to \""+this->name+"\".\n"); + } + + } else { + + cvm::real const grad = this->dist2_lgrad(x, upper_wall); + if (grad > 0.0) { + fw = -0.5 * upper_wall_k * grad; + f += fw; + if (cvm::debug()) + cvm::log("Applying an upper wall force("+ + cvm::to_str(fw)+") to \""+this->name+"\".\n"); + } + } + } + + if (tasks[task_fdiff_velocity]) { // set it for the next step x_old = x; diff --git a/lib/colvars/colvarmodule.h b/lib/colvars/colvarmodule.h index d9f6a03d7c..ee6ec3ea35 100644 --- a/lib/colvars/colvarmodule.h +++ b/lib/colvars/colvarmodule.h @@ -4,7 +4,7 @@ #define COLVARMODULE_H #ifndef COLVARS_VERSION -#define COLVARS_VERSION "2015-09-03" +#define COLVARS_VERSION "2015-09-16" #endif #ifndef COLVARS_DEBUG @@ -20,19 +20,17 @@ /// shared between all object instances) to be accessed from other /// objects. -// Internal method return codes -#define COLVARS_NOT_IMPLEMENTED -2 -#define COLVARS_ERROR -1 +// Error codes #define COLVARS_OK 0 - -// On error, values of the colvars module error register -#define GENERAL_ERROR 1 -#define FILE_ERROR (1<<1) -#define MEMORY_ERROR (1<<2) -#define BUG_ERROR (1<<3) // Inconsistent state indicating bug -#define INPUT_ERROR (1<<4) // out of bounds or inconsistent input -#define DELETE_COLVARS (1<<5) // Instruct the caller to delete cvm -#define FATAL_ERROR (1<<6) // Should be set, or not, together with other bits +#define COLVARS_ERROR -1 +#define GENERAL_ERROR -1 // TODO this can be simply merged with COLVARS_ERROR +#define COLVARS_NOT_IMPLEMENTED (-1<<1) +#define INPUT_ERROR (-1<<2) // out of bounds or inconsistent input +#define BUG_ERROR (-1<<3) // Inconsistent state indicating bug +#define FILE_ERROR (-1<<4) +#define MEMORY_ERROR (-1<<5) +#define FATAL_ERROR (-1<<6) // Should be set, or not, together with other bits +#define DELETE_COLVARS (-1<<7) // Instruct the caller to delete cvm #include diff --git a/lib/colvars/colvarscript.cpp b/lib/colvars/colvarscript.cpp index 0c23faf519..4c999eee84 100644 --- a/lib/colvars/colvarscript.cpp +++ b/lib/colvars/colvarscript.cpp @@ -388,6 +388,7 @@ Input and output:\n\ list -- return a list of all variables\n\ list biases -- return a list of all biases\n\ load -- load a state file (requires configuration)\n\ + save -- save a state file (requires configuration)\n\ update -- recalculate colvars and biases based\n\ printframe -- return a summary of the current frame\n\ printframelabels -- return labels to annotate printframe's output\n"; @@ -406,6 +407,7 @@ Accessing collective variables:\n\ colvar delete -- delete colvar \n\ colvar addforce -- apply given force on colvar \n\ colvar getconfig -- return config string of colvar \n\ + colvar cvcflags -- enable or disable cvcs according to 0/1 flags\n\ \n\ Accessing biases:\n\ bias energy -- return the current energy of bias \n\