-
Notifications
You must be signed in to change notification settings - Fork 59
Loop over replicas when computing well-tempered metadynamics scaling factor #820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -537,6 +537,7 @@ int colvarbias_meta::update_grid_params() | |
|
||
int colvarbias_meta::update_bias() | ||
{ | ||
int error_code = COLVARS_OK; | ||
colvarproxy *proxy = cvm::main()->proxy; | ||
// add a new hill if the required time interval has passed | ||
if (((cvm::step_absolute() % new_hill_freq) == 0) && | ||
|
@@ -548,7 +549,8 @@ int colvarbias_meta::update_bias() | |
": adding a new hill at step "+cvm::to_str(cvm::step_absolute())+".\n"); | ||
} | ||
|
||
cvm::real hills_scale=1.0; | ||
// Scaling factor, optionally used by EB-metadynamics or well-tempered metadynamics | ||
cvm::real hills_scale = 1.0; | ||
|
||
if (ebmeta) { | ||
hills_scale *= 1.0/target_dist->value(target_dist->get_colvars_index()); | ||
|
@@ -561,36 +563,40 @@ int colvarbias_meta::update_bias() | |
} | ||
|
||
if (well_tempered) { | ||
|
||
cvm::real hills_energy_sum_here = 0.0; | ||
if (use_grids) { | ||
std::vector<int> curr_bin = hills_energy->get_colvars_index(); | ||
const bool index_ok = hills_energy->index_ok(curr_bin); | ||
if (index_ok) { | ||
// TODO: Should I sum the energies from other replicas? | ||
hills_energy_sum_here = hills_energy->value(curr_bin); | ||
} else { | ||
if (!keep_hills) { | ||
// TODO: Should I sum the off-grid hills from other replicas? | ||
calc_hills(hills_off_grid.begin(), | ||
hills_off_grid.end(), | ||
hills_energy_sum_here, | ||
&colvar_values); | ||
|
||
for (size_t ir = 0; ir < replicas.size(); ir++) { | ||
if (use_grids) { | ||
std::vector<int> curr_bin = hills_energy->get_colvars_index(); | ||
const bool index_ok = hills_energy->index_ok(curr_bin); | ||
|
||
if (index_ok) { | ||
hills_energy_sum_here += replicas[ir]->hills_energy->value(curr_bin); | ||
} else { | ||
// TODO: Is it better to compute the energy from all historic hills | ||
// when keepHills is on? | ||
calc_hills(hills.begin(), | ||
hills.end(), | ||
hills_energy_sum_here, | ||
&colvar_values); | ||
if (!keep_hills) { | ||
calc_hills(replicas[ir]->hills_off_grid.begin(), replicas[ir]->hills_off_grid.end(), | ||
hills_energy_sum_here, &colvar_values); | ||
} else { | ||
// TODO: Is it better to compute the energy from all historic hills | ||
// when keepHills is on? | ||
Comment on lines
+581
to
+582
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HanatoK I didn't understand this comment before, and forgot to ask you about it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand, without With |
||
calc_hills(replicas[ir]->hills.begin(), replicas[ir]->hills.end(), | ||
hills_energy_sum_here, &colvar_values); | ||
} | ||
// cvm::log("WARNING: computing bias factor for off-grid hills. Hills energy: " + | ||
// cvm::to_str(hills_energy_sum_here) + "\n"); | ||
} | ||
// cvm::log("WARNING: computing bias factor for off-grid hills. Hills energy: " + cvm::to_str(hills_energy_sum_here) + "\n"); | ||
} else { | ||
calc_hills(replicas[ir]->hills.begin(), replicas[ir]->hills.end(), hills_energy_sum_here, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I feel the old code summing the hills starting from |
||
nullptr); | ||
} | ||
} else { | ||
calc_hills(new_hills_begin, hills.end(), hills_energy_sum_here, NULL); | ||
} | ||
hills_scale *= cvm::exp(-1.0*hills_energy_sum_here/(bias_temperature*proxy->boltzmann())); | ||
|
||
hills_scale *= | ||
cvm::exp(-1.0 * hills_energy_sum_here / (bias_temperature * proxy->boltzmann())); | ||
} | ||
|
||
|
||
switch (comm) { | ||
|
||
case single_replica: | ||
|
@@ -608,15 +614,17 @@ int colvarbias_meta::update_bias() | |
if (replica_hills_os) { | ||
write_hill(replica_hills_os, hills.back()); | ||
} else { | ||
return cvm::error("Error: in metadynamics bias \""+this->name+"\""+ | ||
((comm != single_replica) ? ", replica \""+replica_id+"\"" : "")+ | ||
" while writing hills for the other replicas.\n", COLVARS_FILE_ERROR); | ||
error_code |= | ||
cvm::error("Error: in metadynamics bias \"" + this->name + "\"" + | ||
((comm != single_replica) ? ", replica \"" + replica_id + "\"" : "") + | ||
" while writing hills for the other replicas.\n", | ||
COLVARS_FILE_ERROR); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
return COLVARS_OK; | ||
return error_code; | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to move the checking out of the for loop, just like
colvarbias_meta::calc_energy
?