Skip to content

Commit

Permalink
Record max norm of applied force
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang committed Dec 12, 2023
1 parent 158f335 commit 70b72d2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/colvarbias_abf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ colvarbias_abf::colvarbias_abf(char const *key)
czar_gradients(NULL),
czar_pmf(NULL),
last_gradients(NULL),
max_force_norm(NULL),
max_force_sample(NULL),
last_samples(NULL)
{
colvarproxy *proxy = cvm::main()->proxy;
Expand Down Expand Up @@ -190,6 +192,11 @@ int colvarbias_abf::init(std::string const &conf)
gradients->samples = samples;
samples->has_parent_data = true;

max_force_norm = new colvar_grid_scalar(colvars);
max_force_sample = new colvar_grid_count(colvars);
max_force_norm->samples = max_force_sample;
max_force_sample->has_parent_data = true;

// Data for eAB F z-based estimator
if ( b_extended ) {
get_keyval(conf, "CZARestimator", b_CZAR_estimator, true);
Expand Down Expand Up @@ -295,6 +302,16 @@ colvarbias_abf::~colvarbias_abf()
gradients = NULL;
}

if (max_force_norm) {
delete max_force_norm;
max_force_norm = NULL;
}

if (max_force_sample) {
delete max_force_sample;
max_force_sample = NULL;
}

if (pmf) {
delete pmf;
pmf = NULL;
Expand Down Expand Up @@ -356,6 +373,9 @@ int colvarbias_abf::update()
force_bin = bin;
}

if (max_force_sample->index_ok(force_bin))
max_force_norm->acc_value(force_bin, cvm::proxy->max_atoms_applied_force());

if (cvm::step_relative() > 0 || is_enabled(f_cvb_step_zero_data)) {

if (update_bias) {
Expand Down Expand Up @@ -645,6 +665,8 @@ void colvarbias_abf::write_gradients_samples(const std::string &prefix, bool clo
write_grid_to_file<colvar_grid_count>(samples, prefix + ".count", close);
write_grid_to_file<colvar_grid_gradient>(gradients, prefix + ".grad", close);

write_grid_to_file<colvar_grid_scalar>(max_force_norm, prefix + ".mfn", close);

if (b_integrate) {
// Do numerical integration (to high precision) and output a PMF
cvm::real err;
Expand Down
3 changes: 3 additions & 0 deletions src/colvarbias_abf.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class colvarbias_abf : public colvarbias {
/// n-dim grid of CZAR pmf (dimension 1 to 3)
integrate_potential *czar_pmf;

colvar_grid_count *max_force_sample;
colvar_grid_scalar *max_force_norm;

inline int update_system_force(size_t i)
{
if (colvars[i]->is_enabled(f_cv_subtract_applied_force)) {
Expand Down
3 changes: 3 additions & 0 deletions src/colvarmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,8 @@ int colvarmodule::calc()

error_code |= analyze();

proxy->compute_max_atoms_applied_force();

// write trajectory files, if needed
if (cv_traj_freq && cv_traj_name.size()) {
error_code |= write_traj_files();
Expand Down Expand Up @@ -1924,6 +1926,7 @@ std::ostream & colvarmodule::write_traj(std::ostream &os)
bi++) {
(*bi)->write_traj(os);
}
os << " " << proxy->max_atoms_applied_force_id() << ' ' << proxy->max_atoms_applied_force();
os << "\n";

cvm::decrease_depth();
Expand Down
2 changes: 2 additions & 0 deletions src/colvarproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// If you wish to distribute your changes, please submit them to the
// Colvars repository at GitHub.

#include <iostream>

#include <fstream>
#include <list>
#include <utility>
Expand Down

0 comments on commit 70b72d2

Please sign in to comment.