Skip to content

Commit ec89df1

Browse files
HanatoKgiacomofiorin
authored andcommitted
fix: fix the calculation of bias factor with off-grid hills
When the hill to be deposited is off-grid, we cannot obtain the energy from the grid as that would be an out-of-bound memory access. This commit sums all off-grid hills to get the bias energy to compute the bias factor for WT.
1 parent 8cc2ec1 commit ec89df1

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/colvarbias_meta.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,27 @@ int colvarbias_meta::update_bias()
564564
cvm::real hills_energy_sum_here = 0.0;
565565
if (use_grids) {
566566
std::vector<int> curr_bin = hills_energy->get_colvars_index();
567-
hills_energy_sum_here = hills_energy->value(curr_bin);
567+
const bool index_ok = hills_energy->index_ok(curr_bin);
568+
if (index_ok) {
569+
// TODO: Should I sum the energies from other replicas?
570+
hills_energy_sum_here = hills_energy->value(curr_bin);
571+
} else {
572+
if (!keep_hills) {
573+
// TODO: Should I sum the off-grid hills from other replicas?
574+
calc_hills(hills_off_grid.begin(),
575+
hills_off_grid.end(),
576+
hills_energy_sum_here,
577+
&colvar_values);
578+
} else {
579+
// TODO: Is it better to compute the energy from all historic hills
580+
// when keepHills is on?
581+
calc_hills(hills.begin(),
582+
hills.end(),
583+
hills_energy_sum_here,
584+
&colvar_values);
585+
}
586+
// cvm::log("WARNING: computing bias factor for off-grid hills. Hills energy: " + cvm::to_str(hills_energy_sum_here) + "\n");
587+
}
568588
} else {
569589
calc_hills(new_hills_begin, hills.end(), hills_energy_sum_here, NULL);
570590
}

0 commit comments

Comments
 (0)