Skip to content

Commit f912e55

Browse files
HanatoKjhenin
authored andcommitted
fix: reset the atom group gradients and rerun calc_gradients
Some CVCs, like coordnum and distanceInv, calculate the gradients in calc_value(). The use of debugGradients should avoid changing the gradients. Since cvc::debug_gradients would run calc_value() multiple times, it would be better to reset the gradients buffer and rerun calc_value() and then calc_gradients().
1 parent 5a7978a commit f912e55

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/colvarcomp.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,18 @@ void colvar::cvc::debug_gradients()
745745
for (size_t ig = 0; ig < atom_groups.size(); ig++) {
746746
cvm::atom_group *group = atom_groups[ig];
747747
if (group->b_dummy) continue;
748+
// Clear the gradients, because some CVCs may calculate the gradients in calc_value()
749+
for (size_t ia = 0; ia < group->size(); ia++) {
750+
group->grad_x(ia) = 0;
751+
group->grad_y(ia) = 0;
752+
group->grad_z(ia) = 0;
753+
}
748754
// (re)read original positions
749755
group->read_positions();
750756
group->calc_required_properties();
751-
calc_value();
752757
}
758+
calc_value();
759+
calc_gradients();
753760
return;
754761
}
755762

0 commit comments

Comments
 (0)