Unverified Commit 35294daf authored by Steve Plimpton's avatar Steve Plimpton Committed by GitHub
Browse files

Merge pull request #883 from giacomofiorin/colvars-update

Fixes to Colvars library (version 2018-04-29)
parents 83f5c331 0c005f5c
Loading
Loading
Loading
Loading
−19.1 KiB (575 KiB)

File changed.

No diff preview for this file type.

+38 −15
Original line number Diff line number Diff line
@@ -7,6 +7,10 @@
// If you wish to distribute your changes, please submit them to the
// Colvars repository at GitHub.

#include <list>
#include <vector>
#include <algorithm>

#include "colvarmodule.h"
#include "colvarvalue.h"
#include "colvarparse.h"
@@ -14,15 +18,6 @@
#include "colvarcomp.h"
#include "colvarscript.h"

// used in build_atom_list()
#include <algorithm>


/// Compare two cvcs using their names
/// Used to sort CVC array in scripted coordinates
bool compare(colvar::cvc *i, colvar::cvc *j) {
  return i->name < j->name;
}


colvar::colvar()
@@ -34,6 +29,15 @@ colvar::colvar()
}


namespace {
  /// Compare two cvcs using their names
  /// Used to sort CVC array in scripted coordinates
  bool compare(colvar::cvc *i, colvar::cvc *j)
  {
    return i->name < j->name;
  }
}

int colvar::init(std::string const &conf)
{
  cvm::log("Initializing a new collective variable.\n");
@@ -143,6 +147,9 @@ int colvar::init(std::string const &conf)
    x.type(cvc_value);
    x_reported.type(cvc_value);
  }

  set_enabled(f_cv_scalar, (value().type() == colvarvalue::type_scalar));

  // If using scripted biases, any colvar may receive bias forces
  // and will need its gradient
  if (cvm::scripted_forces()) {
@@ -198,6 +205,7 @@ int colvar::init(std::string const &conf)
  if (is_enabled(f_cv_homogeneous) && cvcs[0]->b_periodic) { // TODO make this a CVC feature
    bool b_periodic = true;
    period = cvcs[0]->period;
    wrap_center = cvcs[0]->wrap_center;
    for (i = 1; i < cvcs.size(); i++) {
      if (!cvcs[i]->b_periodic || cvcs[i]->period != period) {
        b_periodic = false;
@@ -211,6 +219,14 @@ int colvar::init(std::string const &conf)
    set_enabled(f_cv_periodic, b_periodic);
  }

  // Allow scripted/custom functions to be defined as periodic
  if ( (is_enabled(f_cv_scripted) || is_enabled(f_cv_custom_function)) && is_enabled(f_cv_scalar) ) {
    if (get_keyval(conf, "period", period, 0.)) {
      set_enabled(f_cv_periodic, true);
      get_keyval(conf, "wrapAround", wrap_center, 0.);
    }
  }

  // check that cvcs are compatible

  for (i = 0; i < cvcs.size(); i++) {
@@ -443,8 +459,6 @@ int colvar::init_grid_parameters(std::string const &conf)
  upper_boundary.type(value());
  upper_wall.type(value());

  set_enabled(f_cv_scalar, (value().type() == colvarvalue::type_scalar));

  if (is_enabled(f_cv_scalar)) {

    if (get_keyval(conf, "lowerBoundary", lower_boundary, lower_boundary)) {
@@ -1503,7 +1517,7 @@ cvm::real colvar::update_forces_energy()
    vr  += (0.5 * dt) * f_ext / ext_mass;
    xr  += dt * vr;
    xr.apply_constraints();
    if (this->is_enabled(f_cv_periodic)) this->wrap(xr);
    this->wrap(xr);
  }

  // Now adding the force on the actual colvar (for those biases that
@@ -1714,9 +1728,18 @@ colvarvalue colvar::dist2_rgrad(colvarvalue const &x1,

void colvar::wrap(colvarvalue &x) const
{
  if (is_enabled(f_cv_homogeneous)) {
    (cvcs[0])->wrap(x);
  if ( !is_enabled(f_cv_periodic) ) {
    return;
  }

  if ( is_enabled(f_cv_scripted) || is_enabled(f_cv_custom_function) ) {
    // Scripted functions do their own wrapping, as cvcs might not be periodic
    cvm::real shift = std::floor((x.real_value - wrap_center) / period + 0.5);
    x.real_value -= shift * period;
  } else {
    cvcs[0]->wrap(x);
  }

  return;
}

@@ -2244,7 +2267,7 @@ void colvar::calc_runave()
    runave.type(value().type());
    runave.reset();

    // first-step operations
    // first-step operationsf

    if (cvm::debug())
      cvm::log("Colvar \""+this->name+
+1 −0
Original line number Diff line number Diff line
@@ -216,6 +216,7 @@ public:

  /// Period, if this variable is periodic
  cvm::real period;
  cvm::real wrap_center;


  /// \brief Expand the boundaries of multiples of width, to keep the
+34 −27
Original line number Diff line number Diff line
@@ -7,6 +7,10 @@
// If you wish to distribute your changes, please submit them to the
// Colvars repository at GitHub.

#include <list>
#include <vector>
#include <algorithm>

#include "colvarmodule.h"
#include "colvarproxy.h"
#include "colvarparse.h"
@@ -436,7 +440,7 @@ int cvm::atom_group::parse(std::string const &group_conf)
  }

  bool b_print_atom_ids = false;
  get_keyval(group_conf, "printAtomIDs", b_print_atom_ids, false, colvarparse::parse_silent);
  get_keyval(group_conf, "printAtomIDs", b_print_atom_ids, false);

  // Calculate all required properties (such as total mass)
  setup();
@@ -715,13 +719,10 @@ int cvm::atom_group::parse_fitting_options(std::string const &group_conf)
                     "if provided, must be non-zero.\n", INPUT_ERROR);
          return COLVARS_ERROR;
        }
      } else {
        // if not, rely on existing atom indices for the group
        group_for_fit->create_sorted_ids();
        ref_pos.resize(group_for_fit->size());
      }

      cvm::load_coords(ref_pos_file.c_str(), ref_pos, group_for_fit->sorted_ids,
      ref_pos.resize(group_for_fit->size());
      cvm::load_coords(ref_pos_file.c_str(), &ref_pos, group_for_fit,
                       ref_pos_col, ref_pos_col_value);
    }

@@ -789,33 +790,39 @@ void cvm::atom_group::do_feature_side_effects(int id)
}


int cvm::atom_group::create_sorted_ids(void)
int cvm::atom_group::create_sorted_ids()
{
  // Only do the work if the vector is not yet populated
  if (sorted_ids.size())
  if (sorted_atoms_ids.size())
    return COLVARS_OK;

  std::list<int> temp_id_list;
  for (cvm::atom_iter ai = this->begin(); ai != this->end(); ai++) {
    temp_id_list.push_back(ai->id);
  // Sort the internal IDs
  std::list<int> sorted_atoms_ids_list;
  for (size_t i = 0; i < this->size(); i++) {
    sorted_atoms_ids_list.push_back(atoms_ids[i]);
  }
  temp_id_list.sort();
  temp_id_list.unique();
  if (temp_id_list.size() != this->size()) {
    cvm::error("Error: duplicate atom IDs in atom group? (found " +
               cvm::to_str(temp_id_list.size()) +
  sorted_atoms_ids_list.sort();
  sorted_atoms_ids_list.unique();
  if (sorted_atoms_ids_list.size() != this->size()) {
    return cvm::error("Error: duplicate atom IDs in atom group? (found " +
                      cvm::to_str(sorted_atoms_ids_list.size()) +
                      " unique atom IDs instead of " +
               cvm::to_str(this->size()) + ").\n");
    return COLVARS_ERROR;
                      cvm::to_str(this->size()) + ").\n", BUG_ERROR);
  }
  sorted_ids = std::vector<int> (temp_id_list.size());
  unsigned int id_i = 0;
  std::list<int>::iterator li;
  for (li = temp_id_list.begin(); li != temp_id_list.end(); ++li) {
    sorted_ids[id_i] = *li;
    id_i++;

  // Compute map between sorted and unsorted elements
  sorted_atoms_ids.resize(this->size());
  sorted_atoms_ids_map.resize(this->size());
  std::list<int>::iterator lsii = sorted_atoms_ids_list.begin();
  size_t ii = 0;
  for ( ; ii < this->size(); lsii++, ii++) {
    sorted_atoms_ids[ii] = *lsii;
    size_t const pos = std::find(atoms_ids.begin(), atoms_ids.end(), *lsii) -
      atoms_ids.begin();
    sorted_atoms_ids_map[ii] = pos;
  }
  return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK);

  return COLVARS_OK;
}


+30 −8
Original line number Diff line number Diff line
@@ -227,9 +227,16 @@ protected:
  /// \brief Array of atom objects
  std::vector<cvm::atom> atoms;

  /// \brief Array of atom identifiers for the MD program (0-based)
  /// \brief Internal atom IDs for host code
  std::vector<int> atoms_ids;

  /// Sorted list of internal atom IDs (populated on-demand by
  /// create_sorted_ids); used to read coordinate files
  std::vector<int> sorted_atoms_ids;

  /// Map entries of sorted_atoms_ids onto the original positions in the group
  std::vector<int> sorted_atoms_ids_map;

  /// \brief Dummy atom position
  cvm::atom_pos dummy_atom_pos;

@@ -273,19 +280,34 @@ public:
    return atoms.size();
  }

  std::string const print_atom_ids() const;

  /// \brief If this option is on, this group merely acts as a wrapper
  /// for a fixed position; any calls to atoms within or to
  /// functions that return disaggregated data will fail
  bool b_dummy;

  /// Sorted list of zero-based (internal) atom ids
  /// (populated on-demand by create_sorted_ids)
  std::vector<int> sorted_ids;
  /// Internal atom IDs (populated during initialization)
  inline std::vector<int> const &ids() const
  {
    return atoms_ids;
  }

  std::string const print_atom_ids() const;

  /// Allocates and populates sorted_ids and sorted_ids_map
  int create_sorted_ids();

  /// Allocates and populates the sorted list of atom ids
  int create_sorted_ids(void);
  /// Sorted internal atom IDs (populated on-demand by create_sorted_ids);
  /// used to read coordinate files
  inline std::vector<int> const &sorted_ids() const
  {
    return sorted_atoms_ids;
  }

  /// Map entries of sorted_atoms_ids onto the original positions in the group
  inline std::vector<int> const &sorted_ids_map() const
  {
    return sorted_atoms_ids_map;
  }

  /// Detect whether two groups share atoms
  /// If yes, returns 1-based number of a common atom; else, returns 0
Loading