Skip to content

Commit

Permalink
Add function to report when biases need to communicate with replicas
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomofiorin committed Dec 1, 2023
1 parent 57e01e0 commit 50d3b7d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/colvarbias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,18 @@ int colvarbias::bin_count(int /* bin_index */)
cvm::error("Error: bin_count() not implemented.\n");
return COLVARS_NOT_IMPLEMENTED;
}

int colvarbias::replica_share()
{
cvm::error("Error: replica_share() not implemented.\n");
return COLVARS_NOT_IMPLEMENTED;
}

size_t colvarbias::replica_share_freq() const
{
return 0;
}


std::string const colvarbias::get_state_params() const
{
Expand Down
4 changes: 4 additions & 0 deletions src/colvarbias.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ class colvarbias
//// Give the count at a given bin index.
// FIXME this is currently 1D only
virtual int bin_count(int bin_index);

//// Share information between replicas, whatever it may be.
virtual int replica_share();

/// Report the frequency at which this bias needs to communicate with replicas
virtual size_t replica_share_freq() const;

/// Perform analysis tasks
virtual void analyze() {}

Expand Down
6 changes: 6 additions & 0 deletions src/colvarbias_abf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,12 @@ int colvarbias_abf::replica_share() {
}


size_t colvarbias_abf::replica_share_freq() const
{
return shared_freq;
}


template <class T> int colvarbias_abf::write_grid_to_file(T const *grid,
std::string const &filename,
bool close) {
Expand Down
3 changes: 3 additions & 0 deletions src/colvarbias_abf.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ class colvarbias_abf : public colvarbias {
bool shared_on;
size_t shared_freq;
cvm::step_number shared_last_step;

// Share between replicas -- may be called independently of update
virtual int replica_share();

virtual size_t replica_share_freq() const;

// Store the last set for shared ABF
colvar_grid_gradient *last_gradients;
colvar_grid_count *last_samples;
Expand Down
9 changes: 7 additions & 2 deletions src/colvarbias_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ colvarbias_meta::colvarbias_meta(char const *key)

ebmeta_equil_steps = 0L;

replica_update_freq = 0;
replica_id.clear();
}

Expand Down Expand Up @@ -985,9 +984,9 @@ void colvarbias_meta::recount_hills_off_grid(colvarbias_meta::hill_iter h_first
int colvarbias_meta::replica_share()
{
int error_code = COLVARS_OK;
colvarproxy *proxy = cvm::proxy;
// sync with the other replicas (if needed)
if (comm == multiple_replicas) {
colvarproxy *proxy = cvm::main()->proxy;
// reread the replicas registry
error_code |= update_replicas_registry();
// empty the output buffer
Expand All @@ -998,6 +997,12 @@ int colvarbias_meta::replica_share()
}


size_t colvarbias_meta::replica_share_freq() const
{
return replica_update_freq;
}


int colvarbias_meta::update_replicas_registry()
{
int error_code = COLVARS_OK;
Expand Down
3 changes: 2 additions & 1 deletion src/colvarbias_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class colvarbias_meta
virtual int update_bias();
virtual int update_grid_data();
virtual int replica_share();
virtual size_t replica_share_freq();

virtual int calc_energy(std::vector<colvarvalue> const *values);
virtual int calc_forces(std::vector<colvarvalue> const *values);
Expand Down Expand Up @@ -261,7 +262,7 @@ class colvarbias_meta
std::vector<colvarbias_meta *> replicas;

/// \brief Frequency at which data the "mirror" biases are updated
size_t replica_update_freq;
size_t replica_update_freq = 0;

/// List of replicas (and their output list files): contents are
/// copied into replicas_registry for convenience
Expand Down

0 comments on commit 50d3b7d

Please sign in to comment.