Commit 260bbc6f authored by Steve Plimpton's avatar Steve Plimpton Committed by GitHub
Browse files

Merge pull request #702 from giacomofiorin/colvars-fix-the-fix

Fix a Colvars error that was hidden by the previous segfault
parents e368acda f479f025
Loading
Loading
Loading
Loading
−143 B (586 KiB)

File changed.

No diff preview for this file type.

+5 −5
Original line number Diff line number Diff line
@@ -1145,7 +1145,7 @@ int colvar::collect_cvc_values()
      if (!cvcs[i]->is_enabled()) continue;
      x += (cvcs[i])->sup_coeff *
      ( ((cvcs[i])->sup_np != 1) ?
        std::pow((cvcs[i])->value().real_value, (cvcs[i])->sup_np) :
        cvm::integer_power((cvcs[i])->value().real_value, (cvcs[i])->sup_np) :
        (cvcs[i])->value().real_value );
    }
  } else {
@@ -1226,7 +1226,7 @@ int colvar::collect_cvc_gradients()
      if (!cvcs[i]->is_enabled()) continue;
      // Coefficient: d(a * x^n) = a * n * x^(n-1) * dx
      cvm::real coeff = (cvcs[i])->sup_coeff * cvm::real((cvcs[i])->sup_np) *
        std::pow((cvcs[i])->value().real_value, (cvcs[i])->sup_np-1);
        cvm::integer_power((cvcs[i])->value().real_value, (cvcs[i])->sup_np-1);

      for (size_t j = 0; j < cvcs[i]->atom_groups.size(); j++) {

@@ -1594,7 +1594,7 @@ void colvar::communicate_forces()
      if (!cvcs[i]->is_enabled()) continue;
      (cvcs[i])->apply_force(f * (cvcs[i])->sup_coeff *
                             cvm::real((cvcs[i])->sup_np) *
                              (std::pow((cvcs[i])->value().real_value,
                             (cvm::integer_power((cvcs[i])->value().real_value,
                                                 (cvcs[i])->sup_np-1)) );
    }

+2 −2
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ namespace UIestimator {
            this->width = width;
            this->dimension = lowerboundary.size();
            this->y_size = y_size;     // keep in mind the internal (spare) matrix is stored in diagonal form
            this->y_total_size = int(pow(y_size, dimension) + EPSILON);
            this->y_total_size = int(pow(double(y_size), dimension) + EPSILON);

            // the range of the matrix is [lowerboundary, upperboundary]
            x_total_size = 1;
@@ -121,7 +121,7 @@ namespace UIestimator {
            int index = 0;
            for (i = 0; i < dimension; i++) {
                if (i + 1 < dimension)
                    index += temp[i] * int(pow(y_size, dimension - i - 1) + EPSILON);
                    index += temp[i] * int(pow(double(y_size), dimension - i - 1) + EPSILON);
                else
                    index += temp[i];
            }
+16 −5
Original line number Diff line number Diff line
@@ -524,9 +524,18 @@ int colvarbias_ti::update_system_forces(std::vector<colvarvalue> const
    cvm::log("Updating system forces for bias "+this->name+"\n");
  }

  // Collect total colvar forces from the previous step
  colvarproxy *proxy = cvm::main()->proxy;

  size_t i;
  if (cvm::step_relative() > 0) {

  if (proxy->total_forces_same_step()) {
    for (i = 0; i < num_variables(); i++) {
      ti_bin[i] = ti_avg_forces->current_bin_scalar(i);
    }
  }

  // Collect total colvar forces
  if ((cvm::step_relative() > 0) || proxy->total_forces_same_step()) {
    if (ti_avg_forces->index_ok(ti_bin)) {
      for (i = 0; i < num_variables(); i++) {
        if (variables(i)->is_enabled(f_cv_subtract_applied_force)) {
@@ -542,10 +551,12 @@ int colvarbias_ti::update_system_forces(std::vector<colvarvalue> const
    }
  }

  // Set the index to be used in the next iteration, when total forces come in
  if (!proxy->total_forces_same_step()) {
    // Set the index for use in the next iteration, when total forces come in
    for (i = 0; i < num_variables(); i++) {
      ti_bin[i] = ti_avg_forces->current_bin_scalar(i);
    }
  }

  return COLVARS_OK;
}
+9 −2
Original line number Diff line number Diff line
@@ -304,6 +304,10 @@ int colvarbias_abf::update()
        // and subtract previous ABF force if necessary
        update_system_force(i);
      }
      if (cvm::proxy->total_forces_same_step()) {
        // e.g. in LAMMPS, total forces are current
        force_bin = bin;
      }
      gradients->acc_force(force_bin, system_force);
    }
    if ( z_gradients && update_bias ) {
@@ -321,8 +325,11 @@ int colvarbias_abf::update()
    }
  }

  // save bin for next timestep
  if (!cvm::proxy->total_forces_same_step()) {
    // e.g. in NAMD, total forces will be available for next timestep
    // hence we store the current colvar bin
    force_bin = bin;
  }

  // Reset biasing forces from previous timestep
  for (size_t i = 0; i < colvars.size(); i++) {
Loading