Update Colvars to version 2022-05-09

This update includes one new feature (neural-network based collective
variables), several small enhancements (including an automatic definition of
grid boundaries for angle-based CVs, and a normalization option for
eigenvector-based CVs), bugfixes and documentation improvements.

Usage information for specific features included in the Colvars library
(i.e. not just the library as a whole) is now also reported to the screen or
LAMMPS logfile (as is done already in other LAMMPS classes).

Notable to LAMMPS code development are the removals of duplicated code and of
ambiguously-named preprocessor defines in the Colvars headers.  Since the
last PR, the existing regression tests have also been running automatically
via GitHub Actions.

The following pull requests in the Colvars repository are relevant to LAMMPS:

- 475 Remove fatal error condition
  https://github.com/Colvars/colvars/pull/475 (@jhenin, @giacomofiorin)

- 474 Allow normalizing eigenvector vector components to deal with unit change
  https://github.com/Colvars/colvars/pull/474 (@giacomofiorin, @jhenin)

- 470 Better error handling in the initialization of NeuralNetwork CV
  https://github.com/Colvars/colvars/pull/470 (@HanatoK)

- 468 Add examples of histogram configuration, with and without explicit grid parameters
  https://github.com/Colvars/colvars/pull/468 (@giacomofiorin)

- 464 Fix #463 using more fine-grained features
  https://github.com/Colvars/colvars/pull/464 (@jhenin, @giacomofiorin)

- 447 [RFC] New option "scaledBiasingForce" for colvarbias
  https://github.com/Colvars/colvars/pull/447 (@HanatoK, @jhenin)

- 444 [RFC] Implementation of dense neural network as CV
  https://github.com/Colvars/colvars/pull/444 (@HanatoK, @giacomofiorin, @jhenin)

- 443 Fix explicit gradient dependency of sub-CVs
  https://github.com/Colvars/colvars/pull/443 (@HanatoK, @jhenin)

- 442 Persistent bias count
  https://github.com/Colvars/colvars/pull/442 (@jhenin, @giacomofiorin)

- 437 Return type of bias from scripting interface
  https://github.com/Colvars/colvars/pull/437 (@giacomofiorin)

- 434 More flexible use of boundaries from colvars by grids
  https://github.com/Colvars/colvars/pull/434 (@jhenin)

- 433 Prevent double-free in linearCombination
  https://github.com/Colvars/colvars/pull/433 (@HanatoK)

- 428 More complete documentation for index file format (NDX)
  https://github.com/Colvars/colvars/pull/428 (@giacomofiorin)

- 426 Integrate functional version of backup_file() into base proxy class
  https://github.com/Colvars/colvars/pull/426 (@giacomofiorin)

- 424 Track CVC inheritance when documenting feature usage
  https://github.com/Colvars/colvars/pull/424 (@giacomofiorin)

- 419 Generate citation report while running computations
  https://github.com/Colvars/colvars/pull/419 (@giacomofiorin, @jhenin)

- 415 Rebin metadynamics bias from explicit hills when available
  https://github.com/Colvars/colvars/pull/415 (@giacomofiorin)

- 312 Ignore a keyword if it has content to the left of it (regardless of braces)
  https://github.com/Colvars/colvars/pull/312 (@giacomofiorin)

Authors: @giacomofiorin, @HanatoK, @jhenin
This commit is contained in:
Giacomo Fiorin
2022-05-10 11:24:54 -04:00
parent 4737b9efb7
commit 1220bea011
66 changed files with 4040 additions and 1221 deletions

View File

@ -19,11 +19,6 @@
#include "colvar.h"
#include "colvarcomp.h"
bool compareColvarComponent(colvar::cvc *i, colvar::cvc *j)
{
return i->name < j->name;
}
colvar::CartesianBasedPath::CartesianBasedPath(std::string const &conf): cvc(conf), atoms(nullptr), reference_frames(0) {
// Parse selected atoms
atoms = parse_group(conf, "atoms");
@ -79,7 +74,6 @@ colvar::CartesianBasedPath::CartesianBasedPath(std::string const &conf): cvc(con
cvm::atom_group* tmp_fitting_atoms = new cvm::atom_group(fitting_group_name.c_str());
tmp_fitting_atoms->parse(fitting_conf);
tmp_fitting_atoms->disable(f_ag_scalable);
tmp_fitting_atoms->disable(f_ag_scalable_com);
tmp_fitting_atoms->fit_gradients.assign(tmp_fitting_atoms->size(), cvm::atom_pos(0.0, 0.0, 0.0));
std::string reference_position_file_lookup = "refPositionsFile" + cvm::to_str(i_frame + 1);
std::string reference_position_filename;
@ -91,7 +85,6 @@ colvar::CartesianBasedPath::CartesianBasedPath(std::string const &conf): cvc(con
tmp_atoms->enable(f_ag_rotate);
tmp_atoms->b_user_defined_fit = true;
tmp_atoms->disable(f_ag_scalable);
tmp_atoms->disable(f_ag_scalable_com);
tmp_atoms->ref_pos = reference_fitting_position;
tmp_atoms->center_ref_pos();
tmp_atoms->enable(f_ag_fit_gradients);
@ -115,6 +108,7 @@ colvar::CartesianBasedPath::~CartesianBasedPath() {
(*it_comp_atoms) = nullptr;
}
}
// Avoid double-freeing due to CVC-in-CVC construct
atom_groups.clear();
}
@ -131,7 +125,7 @@ void colvar::CartesianBasedPath::computeDistanceToReferenceFrames(std::vector<cv
}
colvar::gspath::gspath(std::string const &conf): CartesianBasedPath(conf) {
function_type = "gspath";
set_function_type("gspath");
get_keyval(conf, "useSecondClosestFrame", use_second_closest_frame, true);
if (use_second_closest_frame == true) {
cvm::log(std::string("Geometric path s(σ) will use the second closest frame to compute s_(m-1)\n"));
@ -146,6 +140,7 @@ colvar::gspath::gspath(std::string const &conf): CartesianBasedPath(conf) {
}
if (total_reference_frames < 2) {
cvm::error("Error: you have specified " + cvm::to_str(total_reference_frames) + " reference frames, but gspath requires at least 2 frames.\n");
return;
}
GeometricPathCV::GeometricPathBase<cvm::atom_pos, cvm::real, GeometricPathCV::path_sz::S>::initialize(atoms->size(), cvm::atom_pos(), total_reference_frames, use_second_closest_frame, use_third_closest_frame);
cvm::log(std::string("Geometric pathCV(s) is initialized.\n"));
@ -170,8 +165,8 @@ void colvar::gspath::prepareVectors() {
reference_cog_1 += reference_frames[min_frame_index_1][i_atom];
reference_cog_2 += reference_frames[min_frame_index_2][i_atom];
}
reference_cog_1 /= reference_frames[min_frame_index_1].size();
reference_cog_2 /= reference_frames[min_frame_index_2].size();
reference_cog_1 /= cvm::real(reference_frames[min_frame_index_1].size());
reference_cog_2 /= cvm::real(reference_frames[min_frame_index_2].size());
std::vector<cvm::atom_pos> tmp_reference_frame_1(reference_frames[min_frame_index_1].size());
std::vector<cvm::atom_pos> tmp_reference_frame_2(reference_frames[min_frame_index_2].size());
for (i_atom = 0; i_atom < atoms->size(); ++i_atom) {
@ -184,8 +179,8 @@ void colvar::gspath::prepareVectors() {
reference_fitting_cog_1 += reference_fitting_frames[min_frame_index_1][i_atom];
reference_fitting_cog_2 += reference_fitting_frames[min_frame_index_2][i_atom];
}
reference_fitting_cog_1 /= reference_fitting_frames[min_frame_index_1].size();
reference_fitting_cog_2 /= reference_fitting_frames[min_frame_index_2].size();
reference_fitting_cog_1 /= cvm::real(reference_fitting_frames[min_frame_index_1].size());
reference_fitting_cog_2 /= cvm::real(reference_fitting_frames[min_frame_index_2].size());
std::vector<cvm::atom_pos> tmp_reference_fitting_frame_1(reference_fitting_frames[min_frame_index_1].size());
std::vector<cvm::atom_pos> tmp_reference_fitting_frame_2(reference_fitting_frames[min_frame_index_2].size());
for (i_atom = 0; i_atom < reference_fitting_frames[min_frame_index_1].size(); ++i_atom) {
@ -205,8 +200,8 @@ void colvar::gspath::prepareVectors() {
reference_cog_1 += reference_frames[min_frame_index_1][i_atom];
reference_cog_3 += reference_frames[min_frame_index_3][i_atom];
}
reference_cog_1 /= reference_frames[min_frame_index_1].size();
reference_cog_3 /= reference_frames[min_frame_index_3].size();
reference_cog_1 /= cvm::real(reference_frames[min_frame_index_1].size());
reference_cog_3 /= cvm::real(reference_frames[min_frame_index_3].size());
std::vector<cvm::atom_pos> tmp_reference_frame_1(reference_frames[min_frame_index_1].size());
std::vector<cvm::atom_pos> tmp_reference_frame_3(reference_frames[min_frame_index_3].size());
for (i_atom = 0; i_atom < atoms->size(); ++i_atom) {
@ -219,8 +214,8 @@ void colvar::gspath::prepareVectors() {
reference_fitting_cog_1 += reference_fitting_frames[min_frame_index_1][i_atom];
reference_fitting_cog_3 += reference_fitting_frames[min_frame_index_3][i_atom];
}
reference_fitting_cog_1 /= reference_fitting_frames[min_frame_index_1].size();
reference_fitting_cog_3 /= reference_fitting_frames[min_frame_index_3].size();
reference_fitting_cog_1 /= cvm::real(reference_fitting_frames[min_frame_index_1].size());
reference_fitting_cog_3 /= cvm::real(reference_fitting_frames[min_frame_index_3].size());
std::vector<cvm::atom_pos> tmp_reference_fitting_frame_1(reference_fitting_frames[min_frame_index_1].size());
std::vector<cvm::atom_pos> tmp_reference_fitting_frame_3(reference_fitting_frames[min_frame_index_3].size());
for (i_atom = 0; i_atom < reference_fitting_frames[min_frame_index_1].size(); ++i_atom) {
@ -272,7 +267,7 @@ void colvar::gspath::apply_force(colvarvalue const &force) {
}
colvar::gzpath::gzpath(std::string const &conf): CartesianBasedPath(conf) {
function_type = "gzpath";
set_function_type("gzpath");
get_keyval(conf, "useSecondClosestFrame", use_second_closest_frame, true);
if (use_second_closest_frame == true) {
cvm::log(std::string("Geometric path z(σ) will use the second closest frame to compute s_(m-1)\n"));
@ -292,6 +287,7 @@ colvar::gzpath::gzpath(std::string const &conf): CartesianBasedPath(conf) {
}
if (total_reference_frames < 2) {
cvm::error("Error: you have specified " + cvm::to_str(total_reference_frames) + " reference frames, but gzpath requires at least 2 frames.\n");
return;
}
GeometricPathCV::GeometricPathBase<cvm::atom_pos, cvm::real, GeometricPathCV::path_sz::Z>::initialize(atoms->size(), cvm::atom_pos(), total_reference_frames, use_second_closest_frame, use_third_closest_frame, b_use_z_square);
// Logging
@ -310,8 +306,8 @@ void colvar::gzpath::prepareVectors() {
reference_cog_1 += reference_frames[min_frame_index_1][i_atom];
reference_cog_2 += reference_frames[min_frame_index_2][i_atom];
}
reference_cog_1 /= reference_frames[min_frame_index_1].size();
reference_cog_2 /= reference_frames[min_frame_index_2].size();
reference_cog_1 /= cvm::real(reference_frames[min_frame_index_1].size());
reference_cog_2 /= cvm::real(reference_frames[min_frame_index_2].size());
std::vector<cvm::atom_pos> tmp_reference_frame_1(reference_frames[min_frame_index_1].size());
std::vector<cvm::atom_pos> tmp_reference_frame_2(reference_frames[min_frame_index_2].size());
for (i_atom = 0; i_atom < atoms->size(); ++i_atom) {
@ -326,8 +322,8 @@ void colvar::gzpath::prepareVectors() {
reference_fitting_cog_1 += reference_fitting_frames[min_frame_index_1][i_atom];
reference_fitting_cog_2 += reference_fitting_frames[min_frame_index_2][i_atom];
}
reference_fitting_cog_1 /= reference_fitting_frames[min_frame_index_1].size();
reference_fitting_cog_2 /= reference_fitting_frames[min_frame_index_2].size();
reference_fitting_cog_1 /= cvm::real(reference_fitting_frames[min_frame_index_1].size());
reference_fitting_cog_2 /= cvm::real(reference_fitting_frames[min_frame_index_2].size());
tmp_reference_fitting_frame_1.resize(reference_fitting_frames[min_frame_index_1].size());
tmp_reference_fitting_frame_2.resize(reference_fitting_frames[min_frame_index_2].size());
for (i_atom = 0; i_atom < reference_fitting_frames[min_frame_index_1].size(); ++i_atom) {
@ -352,7 +348,7 @@ void colvar::gzpath::prepareVectors() {
for (i_atom = 0; i_atom < atoms->size(); ++i_atom) {
reference_cog_3 += reference_frames[min_frame_index_3][i_atom];
}
reference_cog_3 /= reference_frames[min_frame_index_3].size();
reference_cog_3 /= cvm::real(reference_frames[min_frame_index_3].size());
std::vector<cvm::atom_pos> tmp_reference_frame_3(reference_frames[min_frame_index_3].size());
for (i_atom = 0; i_atom < atoms->size(); ++i_atom) {
tmp_reference_frame_3[i_atom] = reference_frames[min_frame_index_3][i_atom] - reference_cog_3;
@ -362,7 +358,7 @@ void colvar::gzpath::prepareVectors() {
for (i_atom = 0; i_atom < reference_fitting_frames[min_frame_index_3].size(); ++i_atom) {
reference_fitting_cog_3 += reference_fitting_frames[min_frame_index_3][i_atom];
}
reference_fitting_cog_3 /= reference_fitting_frames[min_frame_index_3].size();
reference_fitting_cog_3 /= cvm::real(reference_fitting_frames[min_frame_index_3].size());
std::vector<cvm::atom_pos> tmp_reference_fitting_frame_3(reference_fitting_frames[min_frame_index_3].size());
for (i_atom = 0; i_atom < reference_fitting_frames[min_frame_index_3].size(); ++i_atom) {
tmp_reference_fitting_frame_3[i_atom] = reference_fitting_frames[min_frame_index_3][i_atom] - reference_fitting_cog_3;
@ -401,104 +397,6 @@ void colvar::gzpath::apply_force(colvarvalue const &force) {
(*(comp_atoms[min_frame_index_2])).apply_colvar_force(F);
}
colvar::linearCombination::linearCombination(std::string const &conf): cvc(conf) {
// Lookup all available sub-cvcs
for (auto it_cv_map = colvar::get_global_cvc_map().begin(); it_cv_map != colvar::get_global_cvc_map().end(); ++it_cv_map) {
if (key_lookup(conf, it_cv_map->first.c_str())) {
std::vector<std::string> sub_cvc_confs;
get_key_string_multi_value(conf, it_cv_map->first.c_str(), sub_cvc_confs);
for (auto it_sub_cvc_conf = sub_cvc_confs.begin(); it_sub_cvc_conf != sub_cvc_confs.end(); ++it_sub_cvc_conf) {
cv.push_back((it_cv_map->second)(*(it_sub_cvc_conf)));
}
}
}
// Sort all sub CVs by their names
std::sort(cv.begin(), cv.end(), compareColvarComponent);
for (auto it_sub_cv = cv.begin(); it_sub_cv != cv.end(); ++it_sub_cv) {
for (auto it_atom_group = (*it_sub_cv)->atom_groups.begin(); it_atom_group != (*it_sub_cv)->atom_groups.end(); ++it_atom_group) {
register_atom_group(*it_atom_group);
}
}
x.type(cv[0]->value());
x.reset();
use_explicit_gradients = true;
for (size_t i_cv = 0; i_cv < cv.size(); ++i_cv) {
if (!cv[i_cv]->is_enabled(f_cvc_explicit_gradient)) {
use_explicit_gradients = false;
}
}
if (!use_explicit_gradients) {
disable(f_cvc_explicit_gradient);
}
}
cvm::real colvar::linearCombination::getPolynomialFactorOfCVGradient(size_t i_cv) const {
cvm::real factor_polynomial = 1.0;
if (cv[i_cv]->value().type() == colvarvalue::type_scalar) {
factor_polynomial = cv[i_cv]->sup_coeff * cv[i_cv]->sup_np * cvm::pow(cv[i_cv]->value().real_value, cv[i_cv]->sup_np - 1);
} else {
factor_polynomial = cv[i_cv]->sup_coeff;
}
return factor_polynomial;
}
colvar::linearCombination::~linearCombination() {
for (auto it = cv.begin(); it != cv.end(); ++it) {
delete (*it);
}
}
void colvar::linearCombination::calc_value() {
x.reset();
for (size_t i_cv = 0; i_cv < cv.size(); ++i_cv) {
cv[i_cv]->calc_value();
colvarvalue current_cv_value(cv[i_cv]->value());
// polynomial combination allowed
if (current_cv_value.type() == colvarvalue::type_scalar) {
x += cv[i_cv]->sup_coeff * (cvm::pow(current_cv_value.real_value, cv[i_cv]->sup_np));
} else {
x += cv[i_cv]->sup_coeff * current_cv_value;
}
}
}
void colvar::linearCombination::calc_gradients() {
for (size_t i_cv = 0; i_cv < cv.size(); ++i_cv) {
cv[i_cv]->calc_gradients();
if ( cv[i_cv]->is_enabled(f_cvc_explicit_gradient) &&
!cv[i_cv]->is_enabled(f_cvc_scalable) &&
!cv[i_cv]->is_enabled(f_cvc_scalable_com)) {
cvm::real factor_polynomial = getPolynomialFactorOfCVGradient(i_cv);
for (size_t j_elem = 0; j_elem < cv[i_cv]->value().size(); ++j_elem) {
for (size_t k_ag = 0 ; k_ag < cv[i_cv]->atom_groups.size(); ++k_ag) {
for (size_t l_atom = 0; l_atom < (cv[i_cv]->atom_groups)[k_ag]->size(); ++l_atom) {
(*(cv[i_cv]->atom_groups)[k_ag])[l_atom].grad = factor_polynomial * (*(cv[i_cv]->atom_groups)[k_ag])[l_atom].grad;
}
}
}
}
}
}
void colvar::linearCombination::apply_force(colvarvalue const &force) {
for (size_t i_cv = 0; i_cv < cv.size(); ++i_cv) {
// If this CV us explicit gradients, then atomic gradients is already calculated
// We can apply the force to atom groups directly
if ( cv[i_cv]->is_enabled(f_cvc_explicit_gradient) &&
!cv[i_cv]->is_enabled(f_cvc_scalable) &&
!cv[i_cv]->is_enabled(f_cvc_scalable_com)
) {
for (size_t k_ag = 0 ; k_ag < cv[i_cv]->atom_groups.size(); ++k_ag) {
(cv[i_cv]->atom_groups)[k_ag]->apply_colvar_force(force.real_value);
}
} else {
// Compute factors for polynomial combinations
cvm::real factor_polynomial = getPolynomialFactorOfCVGradient(i_cv);
colvarvalue cv_force = force.real_value * factor_polynomial;
cv[i_cv]->apply_force(cv_force);
}
}
}
colvar::CVBasedPath::CVBasedPath(std::string const &conf): cvc(conf) {
// Lookup all available sub-cvcs
@ -512,7 +410,7 @@ colvar::CVBasedPath::CVBasedPath(std::string const &conf): cvc(conf) {
}
}
// Sort all sub CVs by their names
std::sort(cv.begin(), cv.end(), compareColvarComponent);
std::sort(cv.begin(), cv.end(), colvar::compare_cvc);
// Register atom groups and determine the colvar type for reference
std::vector<colvarvalue> tmp_cv;
for (auto it_sub_cv = cv.begin(); it_sub_cv != cv.end(); ++it_sub_cv) {
@ -531,6 +429,7 @@ colvar::CVBasedPath::CVBasedPath(std::string const &conf): cvc(conf) {
std::ifstream ifs_path(path_filename);
if (!ifs_path.is_open()) {
cvm::error("Error: failed to open path file.\n");
return;
}
std::string line;
const std::string token(" ");
@ -552,6 +451,7 @@ colvar::CVBasedPath::CVBasedPath(std::string const &conf): cvc(conf) {
}
} else {
cvm::error("Error: incorrect format of path file.\n");
return;
}
}
if (!fields.empty()) {
@ -561,6 +461,12 @@ colvar::CVBasedPath::CVBasedPath(std::string const &conf): cvc(conf) {
}
if (total_reference_frames <= 1) {
cvm::error("Error: there is only 1 or 0 reference frame, which doesn't constitute a path.\n");
return;
}
if (cv.size() == 0) {
cvm::error("Error: the CV " + name +
" expects one or more nesting components.\n");
return;
}
x.type(colvarvalue::type_scalar);
use_explicit_gradients = true;
@ -622,14 +528,27 @@ cvm::real colvar::CVBasedPath::getPolynomialFactorOfCVGradient(size_t i_cv) cons
}
colvar::CVBasedPath::~CVBasedPath() {
// Recall the steps we initialize the sub-CVCs:
// 1. Lookup all sub-CVCs and then register the atom groups for sub-CVCs
// in their constructors;
// 2. Iterate over all sub-CVCs, get the pointers of their atom groups
// groups, and register again in the parent (current) CVC.
// That being said, the atom groups become children of the sub-CVCs at
// first, and then become children of the parent CVC.
// So, to destruct this class (parent CVC class), we need to remove the
// dependencies of the atom groups to the parent CVC at first.
remove_all_children();
// Then we remove the dependencies of the atom groups to the sub-CVCs
// in their destructors.
for (auto it = cv.begin(); it != cv.end(); ++it) {
delete (*it);
}
// The last step is cleaning up the list of atom groups.
atom_groups.clear();
}
colvar::gspathCV::gspathCV(std::string const &conf): CVBasedPath(conf) {
function_type = "gspathCV";
set_function_type("gspathCV");
cvm::log(std::string("Total number of frames: ") + cvm::to_str(total_reference_frames) + std::string("\n"));
// Initialize variables for future calculation
get_keyval(conf, "useSecondClosestFrame", use_second_closest_frame, true);
@ -646,19 +565,10 @@ colvar::gspathCV::gspathCV(std::string const &conf): CVBasedPath(conf) {
}
if (total_reference_frames < 2) {
cvm::error("Error: you have specified " + cvm::to_str(total_reference_frames) + " reference frames, but gspathCV requires at least 2 frames.\n");
return;
}
GeometricPathCV::GeometricPathBase<colvarvalue, cvm::real, GeometricPathCV::path_sz::S>::initialize(cv.size(), ref_cv[0], total_reference_frames, use_second_closest_frame, use_third_closest_frame);
x.type(colvarvalue::type_scalar);
use_explicit_gradients = true;
for (size_t i_cv = 0; i_cv < cv.size(); ++i_cv) {
if (!cv[i_cv]->is_enabled(f_cvc_explicit_gradient)) {
use_explicit_gradients = false;
}
}
if (!use_explicit_gradients) {
cvm::log("Geometric path s(σ) will use implicit gradients.\n");
disable(f_cvc_explicit_gradient);
}
}
colvar::gspathCV::~gspathCV() {}
@ -710,9 +620,7 @@ void colvar::gspathCV::calc_gradients() {
// No matter whether the i-th cv uses implicit gradient, compute it first.
cv[i_cv]->calc_gradients();
// If the gradient is not implicit, then add the gradients to its atom groups
if ( cv[i_cv]->is_enabled(f_cvc_explicit_gradient) &&
!cv[i_cv]->is_enabled(f_cvc_scalable) &&
!cv[i_cv]->is_enabled(f_cvc_scalable_com)) {
if (cv[i_cv]->is_enabled(f_cvc_explicit_gradient)) {
// Temporary variables storing gradients
colvarvalue tmp_cv_grad_v1(cv[i_cv]->value());
colvarvalue tmp_cv_grad_v2(cv[i_cv]->value());
@ -741,10 +649,7 @@ void colvar::gspathCV::apply_force(colvarvalue const &force) {
for (size_t i_cv = 0; i_cv < cv.size(); ++i_cv) {
// If this CV us explicit gradients, then atomic gradients is already calculated
// We can apply the force to atom groups directly
if ( cv[i_cv]->is_enabled(f_cvc_explicit_gradient) &&
!cv[i_cv]->is_enabled(f_cvc_scalable) &&
!cv[i_cv]->is_enabled(f_cvc_scalable_com)
) {
if (cv[i_cv]->is_enabled(f_cvc_explicit_gradient)) {
for (size_t k_ag = 0 ; k_ag < cv[i_cv]->atom_groups.size(); ++k_ag) {
(cv[i_cv]->atom_groups)[k_ag]->apply_colvar_force(force.real_value);
}
@ -766,7 +671,7 @@ void colvar::gspathCV::apply_force(colvarvalue const &force) {
}
colvar::gzpathCV::gzpathCV(std::string const &conf): CVBasedPath(conf) {
function_type = "gzpathCV";
set_function_type("gzpathCV");
cvm::log(std::string("Total number of frames: ") + cvm::to_str(total_reference_frames) + std::string("\n"));
// Initialize variables for future calculation
M = cvm::real(total_reference_frames - 1);
@ -790,19 +695,10 @@ colvar::gzpathCV::gzpathCV(std::string const &conf): CVBasedPath(conf) {
}
if (total_reference_frames < 2) {
cvm::error("Error: you have specified " + cvm::to_str(total_reference_frames) + " reference frames, but gzpathCV requires at least 2 frames.\n");
return;
}
GeometricPathCV::GeometricPathBase<colvarvalue, cvm::real, GeometricPathCV::path_sz::Z>::initialize(cv.size(), ref_cv[0], total_reference_frames, use_second_closest_frame, use_third_closest_frame, b_use_z_square);
x.type(colvarvalue::type_scalar);
use_explicit_gradients = true;
for (size_t i_cv = 0; i_cv < cv.size(); ++i_cv) {
if (!cv[i_cv]->is_enabled(f_cvc_explicit_gradient)) {
use_explicit_gradients = false;
}
}
if (!use_explicit_gradients) {
cvm::log("Geometric path z(σ) will use implicit gradients.\n");
disable(f_cvc_explicit_gradient);
}
}
colvar::gzpathCV::~gzpathCV() {
@ -857,9 +753,7 @@ void colvar::gzpathCV::calc_gradients() {
// No matter whether the i-th cv uses implicit gradient, compute it first.
cv[i_cv]->calc_gradients();
// If the gradient is not implicit, then add the gradients to its atom groups
if ( cv[i_cv]->is_enabled(f_cvc_explicit_gradient) &&
!cv[i_cv]->is_enabled(f_cvc_scalable) &&
!cv[i_cv]->is_enabled(f_cvc_scalable_com)) {
if (cv[i_cv]->is_enabled(f_cvc_explicit_gradient)) {
// Temporary variables storing gradients
colvarvalue tmp_cv_grad_v1 = -1.0 * dzdv1[i_cv];
colvarvalue tmp_cv_grad_v2 = 1.0 * dzdv2[i_cv];
@ -884,14 +778,11 @@ void colvar::gzpathCV::apply_force(colvarvalue const &force) {
for (size_t i_cv = 0; i_cv < cv.size(); ++i_cv) {
// If this CV us explicit gradients, then atomic gradients is already calculated
// We can apply the force to atom groups directly
if ( cv[i_cv]->is_enabled(f_cvc_explicit_gradient) &&
!cv[i_cv]->is_enabled(f_cvc_scalable) &&
!cv[i_cv]->is_enabled(f_cvc_scalable_com)) {
if (cv[i_cv]->is_enabled(f_cvc_explicit_gradient)) {
for (size_t k_ag = 0 ; k_ag < cv[i_cv]->atom_groups.size(); ++k_ag) {
(cv[i_cv]->atom_groups)[k_ag]->apply_colvar_force(force.real_value);
}
}
else {
} else {
colvarvalue tmp_cv_grad_v1 = -1.0 * dzdv1[i_cv];
colvarvalue tmp_cv_grad_v2 = 1.0 * dzdv2[i_cv];
// Temporary variables storing gradients