Skip to content

Commit

Permalink
Add missing rotation in orientation component
Browse files Browse the repository at this point in the history
Issue identified by @HanatoK (#713 (comment))
  • Loading branch information
giacomofiorin committed Sep 16, 2024
1 parent a3a1c8c commit aa268d8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/colvarcomp_rotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,25 @@ void colvar::orientation::calc_gradients()
void colvar::orientation::apply_force(colvarvalue const &force)
{
cvm::quaternion const &FQ = force.quaternion_value;
auto const rot_inv = atoms->rot.inverse().matrix();

if (!atoms->noforce) {
rot_deriv_impl->prepare_derivative(rotation_derivative_dldq::use_dq);
cvm::vector1d<cvm::rvector> dq0_2;
for (size_t ia = 0; ia < atoms->size(); ia++) {
rot_deriv_impl->calc_derivative_wrt_group2(ia, nullptr, &dq0_2);
for (size_t i = 0; i < 4; i++) {
(*atoms)[ia].apply_force(FQ[i] * dq0_2[i]);

if (atoms->is_enabled(f_ag_rotate)) {
for (size_t ia = 0; ia < atoms->size(); ia++) {
rot_deriv_impl->calc_derivative_wrt_group2(ia, nullptr, &dq0_2);
for (size_t i = 0; i < 4; i++) {
(*atoms)[ia].apply_force(rot_inv * (FQ[i] * dq0_2[i]));
}
}
} else {
for (size_t ia = 0; ia < atoms->size(); ia++) {
rot_deriv_impl->calc_derivative_wrt_group2(ia, nullptr, &dq0_2);
for (size_t i = 0; i < 4; i++) {
(*atoms)[ia].apply_force(FQ[i] * dq0_2[i]);
}
}
}
}
Expand Down

0 comments on commit aa268d8

Please sign in to comment.