From 86b6e039dab1a393b5975f5d57a012b156281851 Mon Sep 17 00:00:00 2001 From: Giacomo Fiorin Date: Mon, 16 Sep 2024 08:51:35 -0400 Subject: [PATCH] Add missing rotation in orientation component Issue identified by @HanatoK (https://github.com/Colvars/colvars/pull/713#issuecomment-2346452299) --- src/colvarcomp_rotations.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/colvarcomp_rotations.cpp b/src/colvarcomp_rotations.cpp index a04ace851..9f401a5f2 100644 --- a/src/colvarcomp_rotations.cpp +++ b/src/colvarcomp_rotations.cpp @@ -137,10 +137,21 @@ void colvar::orientation::apply_force(colvarvalue const &force) if (!atoms->noforce) { rot_deriv_impl->prepare_derivative(rotation_derivative_dldq::use_dq); cvm::vector1d 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)) { + auto const rot_inv = atoms->rot.inverse().matrix(); + 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]); + } } } }