From 2bf30f5daf7c5f42911716ee019a661f106af08d Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Tue, 18 Jun 2013 10:06:34 +0200 Subject: [PATCH] Fixed neighborlist Now getReducedList can be called more than once returning the same list I also updated a regtest. The previous test was only testing stride=2 (or, equivalently, stride=20 into a trajectory with stride 10). --- regtest/multicolvar/rt20/plumed.dat | 5 +++++ src/tools/NeighborList.cpp | 8 +++++--- src/tools/NeighborList.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/regtest/multicolvar/rt20/plumed.dat b/regtest/multicolvar/rt20/plumed.dat index af25f7458..de57ea5c6 100644 --- a/regtest/multicolvar/rt20/plumed.dat +++ b/regtest/multicolvar/rt20/plumed.dat @@ -4,7 +4,12 @@ c1: ... COORDINATION GROUPA=1 GROUPB=2-100 NLIST NL_CUTOFF=2.5 NL_STRIDE=20 SWITCH={RATIONAL NN=6 MM=12 R_0=1.0} ... +c1x: ... + COORDINATION GROUPA=1 GROUPB=2-100 NLIST NL_CUTOFF=2.5 NL_STRIDE=30 + SWITCH={RATIONAL NN=6 MM=12 R_0=1.0} +... PRINT ARG=d1.*,d2.*,c1 FILE=colvar FMT=%8.5f STRIDE=1 +PRINT ARG=c1x FILE=colvarx COORDINATIONNUMBER SPECIES=1-5 SWITCH={RATIONAL R_0=0.5} MORE_THAN={EXP R_0=4.0} LABEL=c2 COORDINATIONNUMBER SPECIES=1-5 SWITCH={RATIONAL R_0=0.5} MORE_THAN={EXP R_0=4.0} NUMERICAL_DERIVATIVES LABEL=c2n DUMPDERIVATIVES ARG=c2.*,c2n.* FILE=derivatives FMT=%8.4f diff --git a/src/tools/NeighborList.cpp b/src/tools/NeighborList.cpp index 318e980ce..d34681a67 100644 --- a/src/tools/NeighborList.cpp +++ b/src/tools/NeighborList.cpp @@ -32,7 +32,7 @@ using namespace std; NeighborList::NeighborList(const vector<AtomNumber>& list0, const vector<AtomNumber>& list1, const bool& do_pair, const bool& do_pbc, const Pbc& pbc, - const double& distance, const unsigned& stride): + const double& distance, const unsigned& stride): reduced(false), do_pair_(do_pair), do_pbc_(do_pbc), pbc_(&pbc), distance_(distance), stride_(stride) { @@ -54,7 +54,7 @@ NeighborList::NeighborList(const vector<AtomNumber>& list0, const vector<AtomNum NeighborList::NeighborList(const vector<AtomNumber>& list0, const bool& do_pbc, const Pbc& pbc, const double& distance, - const unsigned& stride): + const unsigned& stride): reduced(false), do_pbc_(do_pbc), pbc_(&pbc), distance_(distance), stride_(stride){ fullatomlist_=list0; @@ -119,10 +119,11 @@ void NeighborList::setRequestList() { requestlist_.push_back(fullatomlist_[neighbors_[i].second]); } Tools::removeDuplicates(requestlist_); + reduced=false; } vector<AtomNumber>& NeighborList::getReducedAtomList() { - for(unsigned int i=0;i<size();++i){ + if(!reduced)for(unsigned int i=0;i<size();++i){ unsigned newindex0=0,newindex1=0; AtomNumber index0=fullatomlist_[neighbors_[i].first]; AtomNumber index1=fullatomlist_[neighbors_[i].second]; @@ -132,6 +133,7 @@ vector<AtomNumber>& NeighborList::getReducedAtomList() { p = std::find(requestlist_.begin(), requestlist_.end(), index1); plumed_assert(p!=requestlist_.end()); newindex1=p-requestlist_.begin(); neighbors_[i]=pair<unsigned,unsigned>(newindex0,newindex1); } + reduced=true; return requestlist_; } diff --git a/src/tools/NeighborList.h b/src/tools/NeighborList.h index 4b15457a2..7a26cd4c2 100644 --- a/src/tools/NeighborList.h +++ b/src/tools/NeighborList.h @@ -35,6 +35,7 @@ class Pbc; /// A class that implements neighbor lists from two lists or a single list of atoms class NeighborList { + bool reduced; bool do_pair_,do_pbc_,twolists_; const PLMD::Pbc* pbc_; std::vector<PLMD::AtomNumber> fullatomlist_,requestlist_; -- GitLab