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 : public: 39 : using pairIDs=std::pair<unsigned,unsigned>; 40 : using pairAtomNumbers=std::pair<PLMD::AtomNumber,PLMD::AtomNumber>; 41 : private: 42 : bool reduced=false; 43 : bool serial_; 44 : bool do_pair_; 45 : bool do_pbc_; 46 : bool twolists_; 47 : const PLMD::Pbc* pbc_; 48 : Communicator& comm; 49 : std::vector<PLMD::AtomNumber> fullatomlist_{}; 50 : std::vector<PLMD::AtomNumber> requestlist_{}; 51 : std::vector<pairIDs > neighbors_{}; 52 : double distance_; 53 : size_t nlist0_=0; 54 : size_t nlist1_=0; 55 : size_t nallpairs_; 56 : unsigned stride_=0; 57 : unsigned lastupdate_=0; 58 : /// Initialize the neighbor list with all possible pairs 59 : void initialize(); 60 : /// Return the pair of indexes in the positions array 61 : /// of the two atoms forming the i-th pair among all possible pairs 62 : pairIDs getIndexPair(unsigned i); 63 : /// Extract the list of atoms from the current list of close pairs 64 : void setRequestList(); 65 : public: 66 : NeighborList(const std::vector<PLMD::AtomNumber>& list0, 67 : const std::vector<PLMD::AtomNumber>& list1, 68 : const bool& serial, 69 : const bool& do_pair, 70 : const bool& do_pbc, 71 : const PLMD::Pbc& pbc, 72 : Communicator &cm, 73 456 : const double& distance=1.0e+30, 74 456 : const unsigned& stride=0); 75 : NeighborList(const std::vector<PLMD::AtomNumber>& list0, 76 : const bool& serial, 77 : const bool& do_pbc, 78 : const PLMD::Pbc& pbc, 79 : Communicator &cm, 80 22 : const double& distance=1.0e+30, 81 22 : const unsigned& stride=0); 82 : ~NeighborList(); 83 : /// Return the list of all atoms. These are needed to rebuild the neighbor list. 84 : std::vector<PLMD::AtomNumber>& getFullAtomList(); 85 : /// Update the indexes in the neighbor list to match the 86 : /// ordering in the new positions array 87 : /// and return the new list of atoms that must be requested to the main code 88 : std::vector<PLMD::AtomNumber>& getReducedAtomList(); 89 : /// Update the neighbor list and prepare the new 90 : /// list of atoms that will be requested to the main code 91 : void update(const std::vector<PLMD::Vector>& positions); 92 : /// Get the update stride of the neighbor list 93 : unsigned getStride() const; 94 : /// Get the last step in which the neighbor list was updated 95 : unsigned getLastUpdate() const; 96 : /// Set the step of the last update 97 : void setLastUpdate(unsigned step); 98 : /// Get the size of the neighbor list 99 : unsigned size() const; 100 : /// Get the distance used to create the neighbor list 101 : double distance() const; 102 : /// Get the i-th pair of the neighbor list 103 : pairIDs getClosePair(unsigned i) const; 104 : /// Get the list of neighbors of the i-th atom 105 : std::vector<unsigned> getNeighbors(unsigned i); 106 : /// Get the i-th pair of AtomNumbers from the neighbor list 107 : pairAtomNumbers getClosePairAtomNumber(unsigned i) const; 108 : }; 109 : 110 : } // namespace PLMD 111 : 112 : #endif //__PLUMED_tools_NeighborList_h }