Nneigh

Functions

std::vector< std::vector< int > > nneigh::neighList (double rcutoff, molSys::PointCloud< molSys::Point< double >, double > *yCloud, int typeI, int typeJ)
 All these functions use atom IDs and not indices. More...
 
std::vector< std::vector< int > > nneigh::neighListO (double rcutoff, molSys::PointCloud< molSys::Point< double >, double > *yCloud, int typeI)
 
std::vector< std::vector< int > > nneigh::halfNeighList (double rcutoff, molSys::PointCloud< molSys::Point< double >, double > *yCloud, int typeI=1)
 
std::vector< std::vector< int > > nneigh::neighbourListByIndex (molSys::PointCloud< molSys::Point< double >, double > *yCloud, std::vector< std::vector< int >> nList)
 
std::vector< std::vector< int > > nneigh::getNewNeighbourListByIndex (molSys::PointCloud< molSys::Point< double >, double > *yCloud, double cutoff)
 
int nneigh::clearNeighbourList (std::vector< std::vector< int >> &nList)
 Erases memory for a vector of vectors for the neighbour list. More...
 

Detailed Description

Function Documentation

◆ clearNeighbourList()

int nneigh::clearNeighbourList ( std::vector< std::vector< int >> &  nList)

Erases memory for a vector of vectors for the neighbour list.

Deletes the memory of a vector of vectors. Call this before creating the neighbour list for a new frame.

Parameters
[in,out]nListVector of vectors, of the neighbour list to be erased.

Definition at line 387 of file neighbours.cpp.

387  {
388  //
389  std::vector<std::vector<int>> tempEmpty;
390 
391  nList.swap(tempEmpty);
392 
393  return 0;
394 }
T swap(T... args)

◆ getNewNeighbourListByIndex()

std::vector< std::vector< int > > nneigh::getNewNeighbourListByIndex ( molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
double  cutoff 
)

Gets a neighbour list by index, according to a pointCloud given as the input. Assume no slices or other skullduggery

Function for creating a neighbour list by index (from scratch) instead of by atom ID. The ordering is with respect to the pointCloud with the coordinates.The first element is the atom for which the other atom indices are neighbours For example, if the neighbours of 1 are 2, 3, 4 the sub-vector would have 1 2 3 4

Parameters
[in]yCloudThe input molSys::PointCloud
[in]cutoffDistance cutoff, within which two atoms are neighbours.
Returns
Row-ordered full neighbour list, by index, NOT atom ID.

Definition at line 290 of file neighbours.cpp.

291  {
292  //
294  double r_ij; // Distance between iatom and jatom
295  std::vector<int> tempListIatom;
296 
297  // Initialize and fill the first element with the current atom ID whose
298  // neighbour list will be filled
299  for (int iatom = 0; iatom < yCloud->nop; iatom++) {
300  //
301  nList.push_back(std::vector<int>()); // Empty vector for the index iatom
302  // Fill the first element with the atom ID of iatom itself
303  nList[iatom].push_back(iatom);
304  } // end of init
305  // -------------------------------------------------------
306  // Loop through every iatom and find nearest neighbours within rcutoff
307  for (int iatom = 0; iatom < yCloud->nop - 1; iatom++) {
308  // Loop through the other atoms
309  for (int jatom = iatom + 1; jatom < yCloud->nop; jatom++) {
310  // If the distance is greater than rcutoff, continue
311  r_ij = gen::periodicDist(yCloud, iatom, jatom);
312  if (r_ij > cutoff) {
313  continue;
314  }
315 
316  // Update the neighbour indices with atom IDs for iatom and jatom both
317  // (full list)
318  nList[iatom].push_back(jatom);
319  nList[jatom].push_back(iatom);
320 
321  } // End of loop through jatom
322  } // End of loop for iatom
323 
324  return nList;
325 } // end of function
double periodicDist(molSys::PointCloud< molSys::Point< double >, double > *yCloud, int iatom, int jatom)
Inline generic function for obtaining the unwrapped periodic distance between two particles,...
Definition: generic.hpp:104
int nop
Current frame number.
Definition: mol_sys.hpp:169
T push_back(T... args)

◆ halfNeighList()

std::vector< std::vector< int > > nneigh::halfNeighList ( double  rcutoff,
molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
int  typeI = 1 
)

Inefficient \(O(n^2)\) implementation of neighbour lists You can only use this for neighbour lists with one type

Function for building neighbour lists for each particle of only one type. Inefficient brute-force \( O(n^2) \) implementation. This generates the half neighbour list, by ID. This function will only work for building a neighbour list between one type of particles.

Parameters
[in]rcutoffDistance cutoff, within which two atoms are neighbours.
[in]yCloudThe input molSys::PointCloud
[in]typeIType ID of the \( i^{th} \) particle type.
Returns
Row-ordered half neighbour list, by atom ID.

Definition at line 203 of file neighbours.cpp.

205  {
207  nList; // Vector of vectors of the neighbour list
208  double r_ij; // Distance between iatom and jatom
209  int iatomIndex; // Atomic ID of the atom with index iatom
210  int jatomIndex; // Atomic ID of the atom with index jatom
211  int indexYay;
212  std::vector<int> tempListIatom;
213 
214  // Initialize and fill the first element with the current atom ID whose
215  // neighbour list will be filled
216  for (int iatom = 0; iatom < yCloud->nop; iatom++) {
217  // Find the atom ID (key) given the index or iatom (value)
218  auto itr = std::find_if(
219  yCloud->idIndexMap.begin(), yCloud->idIndexMap.end(),
220  [&iatom](const std::pair<int, int> &p) { return p.second == iatom; });
221  // If found:
222  if (itr == yCloud->idIndexMap.end()) {
223  std::cerr << "Something is wrong with your idIndexMap!\n";
224  continue;
225  } else {
226  iatomIndex = itr->first;
227  } // End of finding the atom ID to fill as the first element in the
228  // neighbour list
229  nList.push_back(std::vector<int>()); // Empty vector for the index iatom
230  // Fill the first element with the atom ID of iatom itself
231  nList[iatom].push_back(iatomIndex);
232  } // end of init
233 
234  // Loop through every iatom and find nearest neighbours within rcutoff
235  for (int iatom = 0; iatom < yCloud->nop - 1; iatom++) {
236  if (yCloud->pts[iatom].type != typeI) {
237  continue;
238  }
239  // Loop through the other atoms
240  for (int jatom = iatom + 1; jatom < yCloud->nop; jatom++) {
241  if (yCloud->pts[jatom].type != typeI) {
242  continue;
243  }
244  // If the distance is greater than rcutoff, continue
245  r_ij = gen::periodicDist(yCloud, iatom, jatom);
246  if (r_ij > rcutoff) {
247  continue;
248  }
249 
250  // Get the atom IDs for iatom and jatom
251  auto gotI = std::find_if(
252  yCloud->idIndexMap.begin(), yCloud->idIndexMap.end(),
253  [&iatom](const std::pair<int, int> &p) { return p.second == iatom; });
254  if (gotI == yCloud->idIndexMap.end()) {
255  std::cerr << "Something is wrong with your idIndexMap!\n";
256  return nList;
257  } else {
258  iatomIndex = gotI->first;
259  } // End of finding the atom ID for iatom
260  // Find the atom ID of jatom
261  auto gotJ = std::find_if(
262  yCloud->idIndexMap.begin(), yCloud->idIndexMap.end(),
263  [&jatom](const std::pair<int, int> &p) { return p.second == jatom; });
264  if (gotJ == yCloud->idIndexMap.end()) {
265  std::cerr << "Something is wrong with your idIndexMap!\n";
266  return nList;
267  } else {
268  jatomIndex = gotJ->first;
269  } // End of finding the atom ID for jatom
270  // Update the neighbour indices with atom IDs for iatom and jatom both
271  // (full list)
272  nList[iatom].push_back(jatomIndex);
273 
274  } // End of loop through jatom
275  } // End of loop for iatom
276 
277  return nList;
278 }
T begin(T... args)
T end(T... args)
T find_if(T... args)
std::vector< S > pts
Definition: mol_sys.hpp:167
std::unordered_map< int, int > idIndexMap
xlo, ylo, zlo
Definition: mol_sys.hpp:172

◆ neighbourListByIndex()

std::vector< std::vector< int > > nneigh::neighbourListByIndex ( molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
std::vector< std::vector< int >>  nList 
)

The following function outputs a neighbour list using indices and NOT atom IDs Converts the neighbour list build with atom IDs into a neighbour list of atom indices, according to the pointCloud

Function for getting the neighbour list by index instead of by atom ID from a previously constructed input neighbour list by ID. The ordering is with respect to the pointCloud with the coordinates.The first element is the atom for which the other atom indices are neighbours For example, if the neighbours of 1 are 2, 3, 4 the sub-vector would have 1 2 3 4

Parameters
[in]yCloudThe input molSys::PointCloud
[in]nListFull neighbour list, by atom ID.
Returns
Row-ordered full neighbour list, by index, NOT atom ID.

Definition at line 337 of file neighbours.cpp.

339  {
340  //
341  std::vector<std::vector<int>> indexNlist; // Desired neighbour list of indices
342  int iatomID, jatomID; // Atom IDs
343  int iatomIndex, jatomIndex; // Indices of iatom and jatom
344  int nnumNeighbours; // Number of nearest neighbours
345 
346  // Loop through every atom whose neighbours are contained in the neighbour
347  // list
348  for (int iatom = 0; iatom < nList.size(); iatom++) {
349  iatomID = nList[iatom][0]; // Atom ID
350  // Get the index of iatom
351  auto gotI = yCloud->idIndexMap.find(iatomID);
352  if (gotI != yCloud->idIndexMap.end()) {
353  iatomIndex = gotI->second;
354  } // found iatomIndex
355  //
356  nnumNeighbours = nList[iatomIndex].size() - 1;
357  // Update the new neighbour list
358  indexNlist.push_back(
359  std::vector<int>()); // Empty vector for the index iatom
360  // Fill the first element with the atom ID of iatom itself
361  indexNlist[iatom].push_back(iatomIndex);
362  //
363  // Loop through the neighbours of iatom
364  for (int jatom = 1; jatom <= nnumNeighbours; jatom++) {
365  jatomID = nList[iatomIndex][jatom]; // Atom ID of neighbour
366  //
367  // Get the index of the j^th atom
368  auto gotJ = yCloud->idIndexMap.find(jatomID);
369  if (gotJ != yCloud->idIndexMap.end()) {
370  jatomIndex = gotJ->second;
371  } // found jatomIndex
372  // Add to the neighbour list
373  indexNlist[iatom].push_back(jatomIndex);
374  } // end of loop through neighbours
375  } // end of loop through every atom
376 
377  // Return the new neighbour list
378  return indexNlist;
379 }
T size(T... args)

◆ neighList()

std::vector< std::vector< int > > nneigh::neighList ( double  rcutoff,
molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
int  typeI,
int  typeJ 
)

All these functions use atom IDs and not indices.

Inefficient \(O(n^2)\) implementation of neighbour lists when there are two different types of atoms The neighbour list does not differentiate between the types of atoms

Function for building neighbour lists for each particle. Inefficient brute-force \( O(n^2) \) implementation. This generates the full neighbour list, by ID.

Parameters
[in]rcutoffDistance cutoff, within which two atoms are neighbours.
[in]yCloudThe input molSys::PointCloud
[in]typeIType ID of particles of type I.
[in]typeJType ID of particles of type J.
Returns
Row-ordered full neighbour list, by atom ID.

Definition at line 26 of file neighbours.cpp.

28  {
29  std::vector<std::vector<int>> nList; // Vector of vector of ints
30  int jatomIndex; // Atom ID corresponding to jatom
31  int iatomIndex; // Atom ID corresponding to iatom
32  double r_ij; // cutoff
33 
34  // Initialize with nop (irrespective of type)
35  // Initialize and fill the first element with the current atom ID whose
36  // neighbour list will be filled
37  for (int iatom = 0; iatom < yCloud->nop; iatom++) {
38  // Find the atom ID (key) given the index or iatom (value)
39  auto itr = std::find_if(
40  yCloud->idIndexMap.begin(), yCloud->idIndexMap.end(),
41  [&iatom](const std::pair<int, int> &p) { return p.second == iatom; });
42  // If found:
43  if (itr == yCloud->idIndexMap.end()) {
44  std::cerr << "Something is wrong with your idIndexMap!\n";
45  continue;
46  } else {
47  iatomIndex = itr->first;
48  } // End of finding the atom ID to fill as the first element in the
49  // neighbour list
50  nList.push_back(std::vector<int>()); // Empty vector for the index iatom
51  // Fill the first element with the atom ID of iatom itself
52  nList[iatom].push_back(iatomIndex);
53  } // end of init
54 
55  // pairs of atoms of type I and J
56  // Loop through every iatom and find nearest neighbours within rcutoff
57  for (int iatom = 0; iatom < yCloud->nop; iatom++) {
58  if (yCloud->pts[iatom].type != typeI) {
59  continue;
60  }
61  // Loop through the other atoms
62  for (int jatom = 0; jatom < yCloud->nop; jatom++) {
63  if (yCloud->pts[jatom].type != typeJ) {
64  continue;
65  }
66  // If the distance is greater than rcutoff, continue
67  r_ij = gen::periodicDist(yCloud, iatom, jatom);
68  if (r_ij > rcutoff) {
69  continue;
70  }
71 
72  // Get the atom IDs for iatom and jatom
73  auto gotI = std::find_if(
74  yCloud->idIndexMap.begin(), yCloud->idIndexMap.end(),
75  [&iatom](const std::pair<int, int> &p) { return p.second == iatom; });
76  if (gotI == yCloud->idIndexMap.end()) {
77  std::cerr << "Something is wrong with your idIndexMap!\n";
78  return nList;
79  } else {
80  iatomIndex = gotI->first;
81  } // End of finding the atom ID for iatom
82  // Find the atom ID of jatom
83  auto gotJ = std::find_if(
84  yCloud->idIndexMap.begin(), yCloud->idIndexMap.end(),
85  [&jatom](const std::pair<int, int> &p) { return p.second == jatom; });
86  if (gotJ == yCloud->idIndexMap.end()) {
87  std::cerr << "Something is wrong with your idIndexMap!\n";
88  return nList;
89  } else {
90  jatomIndex = gotJ->first;
91  } // End of finding the atom ID for jatom
92  // Update the neighbour indices with atom IDs for iatom and jatom both
93  // (full list)
94  nList[iatom].push_back(jatomIndex);
95  nList[jatom].push_back(iatomIndex);
96 
97  } // End of loop through jatom
98  } // End of loop for iatom
99 
100  return nList;
101 }

◆ neighListO()

std::vector< std::vector< int > > nneigh::neighListO ( double  rcutoff,
molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
int  typeI 
)

Inefficient \(O(n^2)\) implementation of neighbour lists You can only use this for neighbour lists with one type

Function for building neighbour lists for each particle of only one type. Inefficient brute-force \( O(n^2) \) implementation. This generates the full neighbour list, by ID. This function will only work for building a neighbour list between one type of particles.

Parameters
[in]rcutoffDistance cutoff, within which two atoms are neighbours.
[in]yCloudThe input molSys::PointCloud
[in]typeIType ID of the \( i^{th} \) particle type.
Returns
Row-ordered full neighbour list, by atom ID.

Definition at line 114 of file neighbours.cpp.

116  {
118  nList; // Vector of vectors of the neighbour list
119  double r_ij; // Distance between iatom and jatom
120  int iatomIndex; // Atomic ID of the atom with index iatom
121  int jatomIndex; // Atomic ID of the atom with index jatom
122  int indexYay;
123  std::vector<int> tempListIatom;
124 
125  // Initialize and fill the first element with the current atom ID whose
126  // neighbour list will be filled
127  for (int iatom = 0; iatom < yCloud->nop; iatom++) {
128  // Find the atom ID (key) given the index or iatom (value)
129  auto itr = std::find_if(
130  yCloud->idIndexMap.begin(), yCloud->idIndexMap.end(),
131  [&iatom](const std::pair<int, int> &p) { return p.second == iatom; });
132  // If found:
133  if (itr == yCloud->idIndexMap.end()) {
134  std::cerr << "Something is wrong with your idIndexMap!\n";
135  continue;
136  } else {
137  iatomIndex = itr->first;
138  } // End of finding the atom ID to fill as the first element in the
139  // neighbour list
140  nList.push_back(std::vector<int>()); // Empty vector for the index iatom
141  // Fill the first element with the atom ID of iatom itself
142  nList[iatom].push_back(iatomIndex);
143  } // end of init
144 
145  // Loop through every iatom and find nearest neighbours within rcutoff
146  for (int iatom = 0; iatom < yCloud->nop - 1; iatom++) {
147  if (yCloud->pts[iatom].type != typeI) {
148  continue;
149  }
150  // Loop through the other atoms
151  for (int jatom = iatom + 1; jatom < yCloud->nop; jatom++) {
152  if (yCloud->pts[jatom].type != typeI) {
153  continue;
154  }
155  // If the distance is greater than rcutoff, continue
156  r_ij = gen::periodicDist(yCloud, iatom, jatom);
157  if (r_ij > rcutoff) {
158  continue;
159  }
160 
161  // Get the atom IDs for iatom and jatom
162  auto gotI = std::find_if(
163  yCloud->idIndexMap.begin(), yCloud->idIndexMap.end(),
164  [&iatom](const std::pair<int, int> &p) { return p.second == iatom; });
165  if (gotI == yCloud->idIndexMap.end()) {
166  std::cerr << "Something is wrong with your idIndexMap!\n";
167  return nList;
168  } else {
169  iatomIndex = gotI->first;
170  } // End of finding the atom ID for iatom
171  // Find the atom ID of jatom
172  auto gotJ = std::find_if(
173  yCloud->idIndexMap.begin(), yCloud->idIndexMap.end(),
174  [&jatom](const std::pair<int, int> &p) { return p.second == jatom; });
175  if (gotJ == yCloud->idIndexMap.end()) {
176  std::cerr << "Something is wrong with your idIndexMap!\n";
177  return nList;
178  } else {
179  jatomIndex = gotJ->first;
180  } // End of finding the atom ID for jatom
181  // Update the neighbour indices with atom IDs for iatom and jatom both
182  // (full list)
183  nList[iatom].push_back(jatomIndex);
184  nList[jatom].push_back(iatomIndex);
185 
186  } // End of loop through jatom
187  } // End of loop for iatom
188 
189  return nList;
190 }