Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-2019 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 :
34 : /// \ingroup TOOLBOX
35 : /// A class that implements neighbor lists from two lists or a single list of atoms
36 : class NeighborList
37 : {
38 : bool reduced;
39 : bool do_pair_,do_pbc_,twolists_;
40 : const PLMD::Pbc* pbc_;
41 : std::vector<PLMD::AtomNumber> fullatomlist_,requestlist_;
42 : std::vector<std::pair<unsigned,unsigned> > neighbors_;
43 : double distance_;
44 : unsigned stride_,nlist0_,nlist1_,nallpairs_,lastupdate_;
45 : /// Initialize the neighbor list with all possible pairs
46 : void initialize();
47 : /// Return the pair of indexes in the positions array
48 : /// of the two atoms forming the i-th pair among all possible pairs
49 : std::pair<unsigned,unsigned> getIndexPair(unsigned i);
50 : /// Extract the list of atoms from the current list of close pairs
51 : void setRequestList();
52 : public:
53 : NeighborList(const std::vector<PLMD::AtomNumber>& list0,
54 : const std::vector<PLMD::AtomNumber>& list1,
55 : const bool& do_pair, const bool& do_pbc, const PLMD::Pbc& pbc,
56 : const double& distance=1.0e+30, const unsigned& stride=0);
57 : NeighborList(const std::vector<PLMD::AtomNumber>& list0, const bool& do_pbc,
58 : const PLMD::Pbc& pbc, const double& distance=1.0e+30,
59 : const unsigned& stride=0);
60 : /// Return the list of all atoms. These are needed to rebuild the neighbor list.
61 : std::vector<PLMD::AtomNumber>& getFullAtomList();
62 : /// Update the indexes in the neighbor list to match the
63 : /// ordering in the new positions array
64 : /// and return the new list of atoms that must be requested to the main code
65 : std::vector<PLMD::AtomNumber>& getReducedAtomList();
66 : /// Update the neighbor list and prepare the new
67 : /// list of atoms that will be requested to the main code
68 : void update(const std::vector<PLMD::Vector>& positions);
69 : /// Get the update stride of the neighbor list
70 : unsigned getStride() const;
71 : /// Get the last step in which the neighbor list was updated
72 : unsigned getLastUpdate() const;
73 : /// Set the step of the last update
74 : void setLastUpdate(unsigned step);
75 : /// Get the size of the neighbor list
76 : unsigned size() const;
77 : /// Get the i-th pair of the neighbor list
78 : std::pair<unsigned,unsigned> getClosePair(unsigned i) const;
79 : /// Get the list of neighbors of the i-th atom
80 : std::vector<unsigned> getNeighbors(unsigned i);
81 356 : ~NeighborList() {}
82 : };
83 :
84 : }
85 :
86 : #endif
|