update colvars to version of 2016-04-20
This commit is contained in:
@ -26,7 +26,12 @@ colvar::cvc::cvc(std::string const &conf)
|
||||
|
||||
init_cvc_requires();
|
||||
|
||||
get_keyval(conf, "name", this->name, std::string(""), parse_silent);
|
||||
if (get_keyval(conf, "name", this->name, std::string(""), parse_silent)) {
|
||||
// Temporary description until child object is initialized
|
||||
description = "cvc " + name;
|
||||
} else {
|
||||
description = "uninitialized cvc";
|
||||
}
|
||||
|
||||
get_keyval(conf, "componentCoeff", sup_coeff, 1.0);
|
||||
get_keyval(conf, "componentExp", sup_np, 1);
|
||||
@ -34,15 +39,14 @@ colvar::cvc::cvc(std::string const &conf)
|
||||
get_keyval(conf, "period", period, 0.0);
|
||||
get_keyval(conf, "wrapAround", wrap_center, 0.0);
|
||||
|
||||
{
|
||||
bool b_debug_gradient;
|
||||
get_keyval(conf, "debugGradients", b_debug_gradient, false, parse_silent);
|
||||
if (b_debug_gradient) enable(f_cvc_debug_gradient);
|
||||
}
|
||||
get_keyval(conf, "debugGradients", b_debug_gradient, false, parse_silent);
|
||||
|
||||
// Attempt scalable calculations when in parallel? (By default yes, if available)
|
||||
get_keyval(conf, "scalable", b_try_scalable, true);
|
||||
|
||||
// All cvcs implement this
|
||||
provide(f_cvc_debug_gradient);
|
||||
|
||||
if (cvm::debug())
|
||||
cvm::log("Done initializing cvc base object.\n");
|
||||
}
|
||||
@ -103,6 +107,7 @@ int colvar::cvc::setup()
|
||||
if (b_try_scalable && is_available(f_cvc_scalable)) {
|
||||
enable(f_cvc_scalable);
|
||||
}
|
||||
if (b_debug_gradient) enable(f_cvc_debug_gradient);
|
||||
|
||||
return COLVARS_OK;
|
||||
}
|
||||
@ -157,6 +162,8 @@ void colvar::cvc::debug_gradients(cvm::atom_group *group)
|
||||
{
|
||||
// this function should work for any scalar variable:
|
||||
// the only difference will be the name of the atom group (here, "group")
|
||||
// NOTE: this assumes that groups for this cvc are non-overlapping,
|
||||
// since atom coordinates are modified only within the current group
|
||||
|
||||
if (group->b_dummy) return;
|
||||
|
||||
@ -168,25 +175,36 @@ void colvar::cvc::debug_gradients(cvm::atom_group *group)
|
||||
|
||||
// cvm::log("gradients = "+cvm::to_str (gradients)+"\n");
|
||||
|
||||
// it only makes sense to debug the fit gradients
|
||||
// when the fitting group is the same as this group
|
||||
if (group->b_rotate || group->b_center)
|
||||
if (group->b_fit_gradients && (group->ref_pos_group == NULL)) {
|
||||
group->calc_fit_gradients();
|
||||
cvm::atom_group *group_for_fit = group->ref_pos_group ? group->ref_pos_group : group;
|
||||
|
||||
// print the values of the fit gradients
|
||||
if (group->b_rotate || group->b_center) {
|
||||
if (group->b_fit_gradients) {
|
||||
|
||||
size_t j;
|
||||
|
||||
// fit_gradients are in the original frame: we should print them in the rotated frame
|
||||
if (group->b_rotate) {
|
||||
// fit_gradients are in the original frame, we should print them in the rotated frame
|
||||
for (size_t j = 0; j < group->fit_gradients.size(); j++) {
|
||||
group->fit_gradients[j] = rot_0.rotate(group->fit_gradients[j]);
|
||||
for (j = 0; j < group_for_fit->fit_gradients.size(); j++) {
|
||||
group_for_fit->fit_gradients[j] = rot_0.rotate(group_for_fit->fit_gradients[j]);
|
||||
}
|
||||
}
|
||||
cvm::log("fit_gradients = "+cvm::to_str(group->fit_gradients)+"\n");
|
||||
|
||||
cvm::log("Fit gradients:\n");
|
||||
for (j = 0; j < group_for_fit->fit_gradients.size(); j++) {
|
||||
cvm::log((group->ref_pos_group ? std::string("refPosGroup") : group->key) +
|
||||
"[" + cvm::to_str(j) + "] = " + cvm::to_str(group_for_fit->fit_gradients[j]));
|
||||
}
|
||||
|
||||
if (group->b_rotate) {
|
||||
for (size_t j = 0; j < group->fit_gradients.size(); j++) {
|
||||
group->fit_gradients[j] = rot_inv.rotate(group->fit_gradients[j]);
|
||||
for (j = 0; j < group_for_fit->fit_gradients.size(); j++) {
|
||||
group_for_fit->fit_gradients[j] = rot_inv.rotate(group_for_fit->fit_gradients[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// debug the gradients
|
||||
for (size_t ia = 0; ia < group->size(); ia++) {
|
||||
|
||||
// tests are best conducted in the unrotated (simulation) frame
|
||||
@ -205,55 +223,55 @@ void colvar::cvc::debug_gradients(cvm::atom_group *group)
|
||||
if ((x.type() == colvarvalue::type_vector) && (x.size() == 1)) x_1 = x[0];
|
||||
cvm::log("Atom "+cvm::to_str(ia)+", component "+cvm::to_str(id)+":\n");
|
||||
cvm::log("dx(actual) = "+cvm::to_str(x_1 - x_0,
|
||||
21, 14)+"\n");
|
||||
//cvm::real const dx_pred = (group->fit_gradients.size() && (group->ref_pos_group == NULL)) ?
|
||||
21, 14)+"\n");
|
||||
cvm::real const dx_pred = (group->fit_gradients.size()) ?
|
||||
(cvm::debug_gradients_step_size * (atom_grad[id] + group->fit_gradients[ia][id])) :
|
||||
(cvm::debug_gradients_step_size * atom_grad[id]);
|
||||
cvm::log("dx(interp) = "+cvm::to_str(dx_pred,
|
||||
21, 14)+"\n");
|
||||
21, 14)+"\n");
|
||||
cvm::log("|dx(actual) - dx(interp)|/|dx(actual)| = "+
|
||||
cvm::to_str(std::fabs(x_1 - x_0 - dx_pred) /
|
||||
std::fabs(x_1 - x_0), 12, 5)+"\n");
|
||||
std::fabs(x_1 - x_0), 12, 5)+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The code below is WIP
|
||||
*/
|
||||
// if (group->ref_pos_group != NULL) {
|
||||
// cvm::atom_group &ref = *group->ref_pos_group;
|
||||
// group->calc_fit_gradients();
|
||||
//
|
||||
// for (size_t ia = 0; ia < ref.size(); ia++) {
|
||||
//
|
||||
// for (size_t id = 0; id < 3; id++) {
|
||||
// // (re)read original positions
|
||||
// group->read_positions();
|
||||
// ref.read_positions();
|
||||
// // change one coordinate
|
||||
// ref[ia].pos[id] += cvm::debug_gradients_step_size;
|
||||
// group->update();
|
||||
// calc_value();
|
||||
// cvm::real const x_1 = x.real_value;
|
||||
// cvm::log("refPosGroup atom "+cvm::to_str(ia)+", component "+cvm::to_str (id)+":\n");
|
||||
// cvm::log("dx(actual) = "+cvm::to_str (x_1 - x_0,
|
||||
// 21, 14)+"\n");
|
||||
// //cvm::real const dx_pred = (group->fit_gradients.size() && (group->ref_pos_group == NULL)) ?
|
||||
// // cvm::real const dx_pred = (group->fit_gradients.size()) ?
|
||||
// // (cvm::debug_gradients_step_size * (atom_grad[id] + group->fit_gradients[ia][id])) :
|
||||
// // (cvm::debug_gradients_step_size * atom_grad[id]);
|
||||
// cvm::real const dx_pred = cvm::debug_gradients_step_size * ref.fit_gradients[ia][id];
|
||||
// cvm::log("dx(interp) = "+cvm::to_str (dx_pred,
|
||||
// 21, 14)+"\n");
|
||||
// cvm::log ("|dx(actual) - dx(interp)|/|dx(actual)| = "+
|
||||
// cvm::to_str(std::fabs (x_1 - x_0 - dx_pred) /
|
||||
// std::fabs (x_1 - x_0),
|
||||
// 12, 5)+
|
||||
// ".\n");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if ((group->b_fit_gradients) && (group->ref_pos_group != NULL)) {
|
||||
cvm::atom_group *ref_group = group->ref_pos_group;
|
||||
group->read_positions();
|
||||
group->calc_required_properties();
|
||||
|
||||
for (size_t ia = 0; ia < ref_group->size(); ia++) {
|
||||
|
||||
// tests are best conducted in the unrotated (simulation) frame
|
||||
cvm::rvector const atom_grad = ref_group->fit_gradients[ia];
|
||||
|
||||
for (size_t id = 0; id < 3; id++) {
|
||||
// (re)read original positions
|
||||
group->read_positions();
|
||||
ref_group->read_positions();
|
||||
|
||||
// change one coordinate
|
||||
(*ref_group)[ia].pos[id] += cvm::debug_gradients_step_size;
|
||||
|
||||
group->calc_required_properties();
|
||||
|
||||
calc_value();
|
||||
|
||||
cvm::real const x_1 = x.real_value;
|
||||
cvm::log("refPosGroup atom "+cvm::to_str(ia)+", component "+cvm::to_str (id)+":\n");
|
||||
cvm::log("dx(actual) = "+cvm::to_str (x_1 - x_0,
|
||||
21, 14)+"\n");
|
||||
cvm::real const dx_pred = cvm::debug_gradients_step_size * atom_grad[id];
|
||||
cvm::log("dx(interp) = "+cvm::to_str (dx_pred,
|
||||
21, 14)+"\n");
|
||||
cvm::log ("|dx(actual) - dx(interp)|/|dx(actual)| = "+
|
||||
cvm::to_str(std::fabs (x_1 - x_0 - dx_pred) /
|
||||
std::fabs (x_1 - x_0),
|
||||
12, 5)+
|
||||
".\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user