Skip to content

Commit

Permalink
Fix classic ABF in Tinker-HP
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenin committed Mar 13, 2024
1 parent c1852b8 commit 833a970
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/colvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ int colvar::calc_colvar_properties()

} else {

if (is_enabled(f_cv_subtract_applied_force)) {
if (is_enabled(f_cv_subtract_applied_force) && !cvm::proxy->total_forces_same_step()) {
// correct the total force only if it has been measured
// TODO add a specific test instead of relying on sq norm
if (ft.norm2() > 0.0) {
Expand Down Expand Up @@ -1839,7 +1839,8 @@ void colvar::update_extended_Lagrangian()
// Integrate with slow timestep (if time_step_factor != 1)
cvm::real dt = cvm::dt() * cvm::real(time_step_factor);

colvarvalue f_ext(fr.type()); // force acting on the extended variable
// Force acting on the extended variable
colvarvalue f_ext(fr.type());
f_ext.reset();

if (is_enabled(f_cv_external)) {
Expand Down
3 changes: 2 additions & 1 deletion src/colvarbias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,9 @@ int colvarbias_ti::update_system_forces(std::vector<colvarvalue> const
if ((cvm::step_relative() > 0) || proxy->total_forces_same_step()) {
if (ti_avg_forces->index_ok(ti_bin)) {
for (i = 0; i < num_variables(); i++) {
if (variables(i)->is_enabled(f_cv_subtract_applied_force)) {
if (variables(i)->is_enabled(f_cv_subtract_applied_force) || proxy->total_forces_same_step()) {
// this colvar is already subtracting all applied forces
// or the "total force" is really a system force at current step
ti_system_forces[i] = variables(i)->total_force();
} else {
ti_system_forces[i] = variables(i)->total_force() -
Expand Down
6 changes: 5 additions & 1 deletion src/colvarbias_abf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,12 @@ int colvarbias_abf::update_system_force()
// System force from atomic forces (or extended Lagrangian if applicable)

for (i = 0; i < num_variables(); i++) {
if (colvars[i]->is_enabled(f_cv_subtract_applied_force)) {
if (colvars[i]->is_enabled(f_cv_subtract_applied_force) ||
(cvm::proxy->total_forces_same_step() && !colvars[i]->is_enabled(f_cv_external))) {
// this colvar is already subtracting the ABF force
// or the "total force" is really a system force at current step
// (For external parameters, the total force contains biasing forces
// unless f_cv_subtract_applied_force is enabled)
system_force[i] = colvars[i]->total_force().real_value;
} else {
system_force[i] = colvars[i]->total_force().real_value
Expand Down
4 changes: 2 additions & 2 deletions src/colvarcomp_alchlambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ void colvar::alch_lambda::calc_value()
{
// By default, follow external parameter
// This might get overwritten by driving extended dynamics
// (in apply_force() below)
cvm::proxy->get_alch_lambda(&x.real_value);

cvm::proxy->get_dE_dlambda(&ft.real_value);
ft.real_value *= -1.0; // Energy derivative to force
ft.real_value *= -1.0; // Convert energy derivative to force

// Include any force due to bias on Flambda
ft.real_value += cvm::proxy->indirect_lambda_biasing_force;
Expand All @@ -75,7 +76,6 @@ void colvar::alch_lambda::apply_force(colvarvalue const & /* force */)
}



colvar::alch_Flambda::alch_Flambda()
{
set_function_type("alch_Flambda");
Expand Down

0 comments on commit 833a970

Please sign in to comment.