Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-2023 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : plumed is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : #ifndef __PLUMED_tools_NeighborList_h 23 : #define __PLUMED_tools_NeighborList_h 24 : 25 : #include "Vector.h" 26 : #include "AtomNumber.h" 27 : 28 : #include <vector> 29 : 30 : namespace PLMD { 31 : 32 : class Pbc; 33 : class Communicator; 34 : 35 : /// \ingroup TOOLBOX 36 : /// A class that implements neighbor lists from two lists or a single list of atoms 37 : class NeighborList { 38 : bool reduced; 39 : bool serial_; 40 : bool do_pair_,do_pbc_,twolists_; 41 : const PLMD::Pbc* pbc_; 42 : Communicator& comm; 43 : std::vector<PLMD::AtomNumber> fullatomlist_,requestlist_; 44 : std::vector<std::pair<unsigned,unsigned> > neighbors_; 45 : double distance_; 46 : unsigned stride_,nlist0_,nlist1_,nallpairs_,lastupdate_; 47 : /// Initialize the neighbor list with all possible pairs 48 : void initialize(); 49 : /// Return the pair of indexes in the positions array 50 : /// of the two atoms forming the i-th pair among all possible pairs 51 : std::pair<unsigned,unsigned> getIndexPair(unsigned i); 52 : /// Extract the list of atoms from the current list of close pairs 53 : void setRequestList(); 54 : public: 55 : NeighborList(const std::vector<PLMD::AtomNumber>& list0, 56 : const std::vector<PLMD::AtomNumber>& list1, 57 : const bool& serial, 58 : const bool& do_pair, const bool& do_pbc, const PLMD::Pbc& pbc, Communicator &cm, 59 408 : const double& distance=1.0e+30, const unsigned& stride=0); 60 : NeighborList(const std::vector<PLMD::AtomNumber>& list0, 61 : const bool& serial, 62 : const bool& do_pbc, 63 22 : const PLMD::Pbc& pbc, Communicator &cm, const double& distance=1.0e+30, 64 22 : const unsigned& stride=0); 65 : /// Return the list of all atoms. These are needed to rebuild the neighbor list. 66 : std::vector<PLMD::AtomNumber>& getFullAtomList(); 67 : /// Update the indexes in the neighbor list to match the 68 : /// ordering in the new positions array 69 : /// and return the new list of atoms that must be requested to the main code 70 : std::vector<PLMD::AtomNumber>& getReducedAtomList(); 71 : /// Update the neighbor list and prepare the new 72 : /// list of atoms that will be requested to the main code 73 : void update(const std::vector<PLMD::Vector>& positions); 74 : /// Get the update stride of the neighbor list 75 : unsigned getStride() const; 76 : /// Get the last step in which the neighbor list was updated 77 : unsigned getLastUpdate() const; 78 : /// Set the step of the last update 79 : void setLastUpdate(unsigned step); 80 : /// Get the size of the neighbor list 81 : unsigned size() const; 82 : /// Get the i-th pair of the neighbor list 83 : std::pair<unsigned,unsigned> getClosePair(unsigned i) const; 84 : /// Get the list of neighbors of the i-th atom 85 : std::vector<unsigned> getNeighbors(unsigned i); 86 294 : ~NeighborList() {} 87 : /// Get the i-th pair of AtomNumbers from the neighbor list 88 : std::pair<AtomNumber,AtomNumber> getClosePairAtomNumber(unsigned i) const; 89 : }; 90 : 91 : } 92 : 93 : #endif