Skip to content

Commit ffb677b

Browse files
committed
Control when hills are added at the same step in metadynamics
1 parent 6e7559f commit ffb677b

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/colvarbias_meta.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,17 @@ int colvarbias_meta::clear_state_data()
739739
// **********************************************************************
740740

741741
std::list<colvarbias_meta::hill>::const_iterator
742-
colvarbias_meta::add_hill(colvarbias_meta::hill const &h)
742+
colvarbias_meta::add_hill(colvarbias_meta::hill const &h,
743+
bool check_same_step)
743744
{
744745
hill_iter const hills_end = hills.end();
746+
if (hills.size()) {
747+
if (hills.end()->it == h.it && check_same_step) {
748+
// Prevent adding multiple hills from repeated calls to update()
749+
return hills.end();
750+
}
751+
}
752+
745753
hills.push_back(h);
746754
if (new_hills_begin == hills_end) {
747755
// if new_hills_begin is unset, set it for the first time
@@ -902,12 +910,12 @@ int colvarbias_meta::reflect_hill_multid(cvm::real const &h_scale)
902910

903911
case single_replica:
904912

905-
add_hill(hill(cvm::step_absolute(), hill_weight*h_scale, curr_cv_values, colvar_sigmas));
913+
add_hill(hill(cvm::step_absolute(), hill_weight*h_scale, curr_cv_values, colvar_sigmas), false);
906914

907915
break;
908916

909917
case multiple_replicas:
910-
add_hill(hill(cvm::step_absolute(), hill_weight*h_scale, curr_cv_values, colvar_sigmas, replica_id));
918+
add_hill(hill(cvm::step_absolute(), hill_weight*h_scale, curr_cv_values, colvar_sigmas, replica_id), false);
911919
std::ostream &replica_hills_os =
912920
cvm::proxy->output_stream(replica_hills_file);
913921
if (replica_hills_os) {

src/colvarbias_meta.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ class colvarbias_meta
112112
/// Read a hill from a file
113113
std::istream & read_hill(std::istream &is);
114114

115-
/// \brief Add a new hill; if a .hills trajectory is written,
116-
/// write it there; if there is more than one replica, communicate
117-
/// it to the others
118-
std::list<hill>::const_iterator add_hill(hill const &h);
115+
/// Add a new hill (also outputs to .hills trajectory if open)
116+
/// \param h New Gaussian hill object
117+
/// \param check_same_step Check if a hill was just added
118+
std::list<hill>::const_iterator add_hill(hill const &h,
119+
bool check_same_step = true);
119120

120121
/// \brief Remove a previously saved hill (returns an iterator for
121122
/// the next hill in the list)

0 commit comments

Comments
 (0)