diff --git a/src/NeighborList.cpp b/src/NeighborList.cpp index 9b0107151cd230d1d939d7e2574ba507459f9363..c1535d88b908a53bfa9c4c20f46dee6d01502ec7 100644 --- a/src/NeighborList.cpp +++ b/src/NeighborList.cpp @@ -20,9 +20,11 @@ NeighborList::NeighborList(vector<unsigned> list0, vector<unsigned> list1, bool if(!do_pair){ nallpairs_=nlist0_*nlist1_; }else{ - // if(nlist0_!=nlist1_) error +// if(nlist0_!=nlist1_) error nallpairs_=nlist0_; } +// initialize neighborlist + initialize(); } NeighborList::NeighborList(vector<unsigned> list0, Pbc *pbc=NULL, @@ -34,6 +36,16 @@ NeighborList::NeighborList(vector<unsigned> list0, Pbc *pbc=NULL, nlist0_=list0.size(); twolists_=false; nallpairs_=nlist0_*(nlist0_-1)/2; + // initialize neighborlist + initialize(); +} + +void NeighborList::initialize() +{ + neighbors_.clear(); + for(unsigned int i=0;i<nallpairs_;++i){ + neighbors_.push_back(getIndexPair(i)); + } } // this method should be called at the end of the step @@ -43,8 +55,8 @@ vector<unsigned> NeighborList::getFullAtomList() const return fullatomlist_; } -// this method return the pair of indexes in the array of positions -// of a given pair "ipair" from the complete list +// this method returns the pair of indexes of the positions array +// of a given pair (ipair) from the list of all possible pairs pair<unsigned,unsigned> NeighborList::getIndexPair(unsigned ipair) { pair<unsigned,unsigned> index; @@ -53,7 +65,7 @@ pair<unsigned,unsigned> NeighborList::getIndexPair(unsigned ipair) }else if (twolists_ && !do_pair_){ index=pair<unsigned,unsigned>(ipair/nlist1_,ipair%nlist1_+nlist0_); }else if (!twolists_){ -// still to fix the map between mono and multi index +// still to fix the map between mono and multi index here index=pair<unsigned,unsigned>(ipair/nlist1_,ipair%nlist1_+nlist0_); } return index; diff --git a/src/NeighborList.h b/src/NeighborList.h index e2f1be3382d915867dc833476d35be74502b60a5..caabcc1ef24ee4467e44b91755ec1357500dfae4 100644 --- a/src/NeighborList.h +++ b/src/NeighborList.h @@ -14,6 +14,7 @@ class NeighborList std::vector< std::pair<unsigned,unsigned> > neighbors_; double distance_; unsigned stride_,nlist0_,nlist1_,nallpairs_; + void initialize(); std::pair<unsigned,unsigned> getIndexPair(unsigned ipair); std::vector<unsigned> createIndexes(std::vector<unsigned> request); template<typename T> @@ -35,5 +36,4 @@ public: ~NeighborList(){}; }; -#endif - +#endif \ No newline at end of file