Gen

Functions

double gen::radDeg (double angle)
 
double gen::eigenVecAngle (std::vector< double > OO, std::vector< double > OH)
 Eigen function for getting the angle (in radians) between the O–O and O-H vectors. More...
 
double gen::getAverageWithoutOutliers (std::vector< double > inpVec)
 Get the average, after excluding the outliers, using quartiles. More...
 
double gen::calcMedian (std::vector< double > *input)
 Inline generic function for calculating the median given a vector of the values. More...
 
double gen::periodicDist (molSys::PointCloud< molSys::Point< double >, double > *yCloud, int iatom, int jatom)
 Inline generic function for obtaining the unwrapped periodic distance between two particles, whose indices (not IDs) have been given. More...
 
double gen::unWrappedDistFromPoint (molSys::PointCloud< molSys::Point< double >, double > *yCloud, int iatom, std::vector< double > singlePoint)
 
double gen::distance (molSys::PointCloud< molSys::Point< double >, double > *yCloud, int iatom, int jatom)
 Inline generic function for obtaining the wrapped distance between two particles WITHOUT applying PBCs, whose indices (not IDs) have been given. More...
 
std::array< double, 3 > gen::relDist (molSys::PointCloud< molSys::Point< double >, double > *yCloud, int iatom, int jatom)
 
bool gen::compareByAtomID (const molSys::Point< double > &a, const molSys::Point< double > &b)
 
int gen::prettyPrintYoda (molSys::PointCloud< molSys::Point< double >, double > *yCloud, std::string outFile)
 Generic function for printing all the struct information. More...
 
int gen::unwrappedCoordShift (molSys::PointCloud< molSys::Point< double >, double > *yCloud, int iatomIndex, int jatomIndex, double *x_i, double *y_i, double *z_i, double *x_j, double *y_j, double *z_j)
 Shift particles (unwrapped coordinates) More...
 
double gen::angDistDegQuaternions (std::vector< double > quat1, std::vector< double > quat2)
 
std::vector< std::stringgen::tokenizer (std::string line)
 Function for tokenizing line strings into words (strings) delimited by whitespace. This returns a vector with the words in it. More...
 
std::vector< double > gen::tokenizerDouble (std::string line)
 Function for tokenizing line strings into a vector of doubles. More...
 
std::vector< int > gen::tokenizerInt (std::string line)
 Function for tokenizing line strings into a vector of ints. More...
 
bool gen::file_exists (const std::string &name)
 Function for checking if a file exists or not. More...
 
std::vector< std::complex< double > > gen::avgVector (std::vector< std::complex< double >> v, int l, int neigh)
 

Variables

const double gen::pi = boost::math::constants::pi<double>()
 

Detailed Description

Function Documentation

◆ angDistDegQuaternions()

double gen::angDistDegQuaternions ( std::vector< double >  quat1,
std::vector< double >  quat2 
)

Function for getting the angular distance between two quaternions. Returns the result in degrees

Function for getting the angular distance between two quaternions. Returns the result in degrees.

Parameters
[in]quat1The first quaternion
[in]quat2The second quaternion
Returns
The output angle between the input quaternions, in degrees

Definition at line 262 of file generic.cpp.

263  {
264  //
265  double prod; // Product of quat1 and conjugate of quat2
266  // The angular distance is
267  // angularDistance = 2*cosInverse(quat1*conj(quat2))
268  prod = quat1[0] * quat2[0] - quat1[1] * quat2[1] - quat1[2] * quat2[2] -
269  quat1[3] * quat2[3];
270  // The angular distance is:
271  double angDist = 2 * acos(prod) * 180.0 / (gen::pi);
272  // Return the angular distance
273  return angDist;
274 }
T acos(T... args)
const double pi
Definition: generic.hpp:50

◆ avgVector()

std::vector<std::complex<double> > gen::avgVector ( std::vector< std::complex< double >>  v,
int  l,
int  neigh 
)
inline

Calculates the complex vector, normalized by the number of nearest neighbours, of length \(2l+1\).

Parameters
[in]vThe complex vector to be normalized, of length \(2l+1\)
[in]lA free integer parameter
[in]neighThe number of nearest neighbours
Returns
length \(2l+1\), normalized by the number of nearest neighbours

Definition at line 309 of file generic.hpp.

309  {
310  if (neigh == 0) {
311  return v;
312  }
313  for (int m = 0; m < 2 * l + 1; m++) {
314  v[m] = (1.0 / (double)neigh) * v[m];
315  }
316 
317  return v;
318 }

◆ calcMedian()

double gen::calcMedian ( std::vector< double > *  input)
inline

Inline generic function for calculating the median given a vector of the values.

Parameters
[in]yCloudThe input PointCloud, which contains the particle coordinates, simulation box lengths etc.
[in]inputThe input vector with the values
Returns
The median value

Definition at line 73 of file generic.hpp.

73  {
74  int n = (*input).size(); // Number of elements
75  double median; // Output median value
76 
77  // Sort the vector
78  std::sort((*input).begin(), (*input).end());
79 
80  // Calculate the median
81  // For even values, the median is the average of the two middle values
82  if (n % 2 == 0) {
83  median = 0.5 * ((*input)[n / 2] + (*input)[n / 2 - 1]); // n/2+n/2-1
84  } // median is average of middle values
85  else {
86  median = (*input)[(n + 1) / 2 -
87  1]; // middle value of 7 elements is the 4th element
88  } // if odd, it is the middle value
89 
90  return median;
91 }
T sort(T... args)

◆ compareByAtomID()

bool gen::compareByAtomID ( const molSys::Point< double > &  a,
const molSys::Point< double > &  b 
)
inline

Inline generic function for sorting or comparing two particles, according to the atom ID when the entire Point objects have been passed.

Parameters
[in]aThe input Point for A.
[in]bThe input Point for B.
Returns
True if the atom ID of A is less than the atom ID of B

Definition at line 230 of file generic.hpp.

231  {
232  return a.atomID < b.atomID;
233 }

◆ distance()

double gen::distance ( molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
int  iatom,
int  jatom 
)
inline

Inline generic function for obtaining the wrapped distance between two particles WITHOUT applying PBCs, whose indices (not IDs) have been given.

Parameters
[in]yCloudThe input PointCloud, which contains the particle coordinates, simulation box lengths etc.
[in]iatomThe index of the \( i^{th} \) atom.
[in]jatomThe index of the \( j^{th} \) atom.
Returns
The wrapped distance.

Definition at line 166 of file generic.hpp.

167  {
169  double r2 = 0.0; // Squared absolute distance
170 
171  // Get x1-x2 etc
172  dr[0] = fabs(yCloud->pts[iatom].x - yCloud->pts[jatom].x);
173  dr[1] = fabs(yCloud->pts[iatom].y - yCloud->pts[jatom].y);
174  dr[2] = fabs(yCloud->pts[iatom].z - yCloud->pts[jatom].z);
175 
176  // Get the squared absolute distance
177  for (int k = 0; k < 3; k++) {
178  r2 += pow(dr[k], 2.0);
179  }
180 
181  return sqrt(r2);
182 }
T fabs(T... args)
std::vector< S > pts
Definition: mol_sys.hpp:167
T pow(T... args)
T sqrt(T... args)

◆ eigenVecAngle()

double gen::eigenVecAngle ( std::vector< double >  OO,
std::vector< double >  OH 
)

Eigen function for getting the angle (in radians) between the O–O and O-H vectors.

Function for obtaining the angle between two input vectors (std::vector). Internally, the vectors are converted to Eigen vectors. The dot product between the input vectors is used to calculate the angle between them.

Parameters
[in]OOThe O–O vector (but can be any vector, in general).
[in]OHThe O-H vector (but can be any vector, in general).
Returns
The output angle between the input vectors, in radians

Definition at line 150 of file generic.cpp.

150  {
151  Eigen::Vector3d eigOO = Eigen::Map<Eigen::Vector3d>(OO.data(), OO.size());
152  Eigen::Vector3d eigOH = Eigen::Map<Eigen::Vector3d>(OH.data(), OH.size());
153  double angle;
154  angle = acos(eigOO.dot(eigOH) / (eigOO.norm() * eigOH.norm()));
155  return angle;
156 }
T data(T... args)
T size(T... args)

◆ file_exists()

bool gen::file_exists ( const std::string name)
inline

Function for checking if a file exists or not.

Parameters
[in]nameThe name of the file

Definition at line 294 of file generic.hpp.

294  {
295  // Replace by boost function later
296  struct stat buffer;
297  return (stat(name.c_str(), &buffer) == 0);
298 }
T c_str(T... args)

◆ getAverageWithoutOutliers()

double gen::getAverageWithoutOutliers ( std::vector< double >  inpVec)

Get the average, after excluding the outliers, using quartiles.

Get the average, after excluding the outliers, using quartiles

Parameters
[in]inpVecThe vector containing values whose average is desired
Returns
The desired average value

Definition at line 164 of file generic.cpp.

164  {
165  //
166  double avgVal = 0.0; // Average value, excluding the outliers
167  double median; // Median value
168  int n = inpVec.size(); // Number of values
169  std::vector<double> lowerRange,
170  upperRange; // n/2 smallest and n/2 largest numbers
171  double firstQuartile, thirdQuartile; // First and third quartiles
172  double iqr; // Interquartile range
173  double outlierLimLow, outlierLimHigh; // Outliers limit
174  int numOfObservations = 0; // Number of observations used for the average
175  // ----------------------
176  // Calculate the median (the vector is sorted inside the function)
177  median = calcMedian(&inpVec);
178  // ----------------------
179  // Get the n/2 smallest and largest numbers
180  //
181  if (n % 2 == 0) {
182  for (int i = 0; i < n / 2; i++) {
183  // n/2 smallest numbers
184  lowerRange.push_back(inpVec[i]);
185  // n/2 largest numbers
186  upperRange.push_back(inpVec[n / 2 + i]);
187  } // end of loop to fill up the n/2 smallest and n/2 largest
188  } // even
189  else {
190  //
191  int halfN = (n + 1) / 2;
192  // Exclude the median
193  for (int i = 0; i < halfN; i++) {
194  // (n+1)/2 smallest numbers
195  lowerRange.push_back(inpVec[i]);
196  // (n+1)/2 largest numbers
197  upperRange.push_back(inpVec[halfN + i]);
198  } // end of filling up the smallest and largest half-ranges
199  } // for odd numbers
200  // ----------------------
201  // Calculate the first and third quartiles, and interquartile range
202  //
203  // First quartile
204  firstQuartile = calcMedian(&lowerRange);
205  // Third quartile
206  thirdQuartile = calcMedian(&upperRange);
207  // Interquartile range
208  iqr = thirdQuartile - firstQuartile;
209  // ----------------------
210  // Calculate the average without outliers
211  // Outliers are defined as values which
212  // are less than Q1 - 1.5IQR
213  // or greater than Q3 + 1.5IQR
214  //
215  // Get the limits for the outliers
216  outlierLimLow = firstQuartile - 1.5 * iqr;
217  outlierLimHigh = thirdQuartile + 1.5 * iqr;
218  //
219  // Loop through the values in inpVec to get the average, excluding outliers
220  for (int i = 0; i < n; i++) {
221  //
222  if (inpVec[i] < outlierLimLow) {
223  continue;
224  } // lower limit outlier
225  else if (inpVec[i] > outlierLimHigh) {
226  continue;
227  } // higher limit outlier
228  else {
229  // Number of observations added
230  numOfObservations++;
231  // Add to the average
232  avgVal += inpVec[i];
233  } // take the average
234  } // end of loop for getting the average
235  //
236  // Divide by the number of observations used
237  avgVal /= numOfObservations;
238  // ----------------------
239  // This fails if there are not enough observations (ring size = 3)
240  if (numOfObservations == 0) {
241  double sumVal = 0.0;
242  // Loop through all the values and sum
243  for (int i = 0; i <= n; i++) {
244  sumVal += inpVec[i];
245  } // end of sum
246  // Normalize
247  avgVal = sumVal / n;
248  return avgVal;
249  } // for triangular prism blocks
250  // ----------------------
251 
252  return avgVal;
253 }
double calcMedian(std::vector< double > *input)
Inline generic function for calculating the median given a vector of the values.
Definition: generic.hpp:73
T push_back(T... args)

◆ periodicDist()

double gen::periodicDist ( molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
int  iatom,
int  jatom 
)
inline

Inline generic function for obtaining the unwrapped periodic distance between two particles, whose indices (not IDs) have been given.

Parameters
[in]yCloudThe input PointCloud, which contains the particle coordinates, simulation box lengths etc.
[in]iatomThe index of the \( i^{th} \) atom.
[in]jatomThe index of the \( j^{th} \) atom.
Returns
The unwrapped periodic distance.

Definition at line 104 of file generic.hpp.

105  {
107  double r2 = 0.0; // Squared absolute distance
108 
109  // Get x1-x2 etc
110  dr[0] = fabs(yCloud->pts[iatom].x - yCloud->pts[jatom].x);
111  dr[1] = fabs(yCloud->pts[iatom].y - yCloud->pts[jatom].y);
112  dr[2] = fabs(yCloud->pts[iatom].z - yCloud->pts[jatom].z);
113 
114  // Get the squared absolute distance
115  for (int k = 0; k < 3; k++) {
116  // Correct for periodicity
117  dr[k] -= yCloud->box[k] * round(dr[k] / yCloud->box[k]);
118  r2 += pow(dr[k], 2.0);
119  }
120 
121  return sqrt(r2);
122 }
std::vector< T > box
Number of atoms.
Definition: mol_sys.hpp:170
T round(T... args)

◆ prettyPrintYoda()

int gen::prettyPrintYoda ( molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
std::string  outFile 
)

Generic function for printing all the struct information.

Function for printing out info in a PointCloud object.

Parameters
[in]yCloudThe input PointCloud to be printed.
[in]outFileThe name of the output file to which the information will be printed.

Definition at line 21 of file generic.cpp.

23  {
24  std::ofstream outputFile;
25  // Create a new file in the output directory
26  outputFile.open(outFile);
27 
28  if (outputFile.is_open()) {
29  // First line
30  outputFile << "# Frame\tAtomID\tx\ty\tz\tcij\ticeType\n";
31  // Write out all the information out line by line
32  for (int i = 0; i < yCloud->nop; i++) {
33  outputFile << yCloud->currentFrame << "\t" << yCloud->pts[i].atomID
34  << "\t" << yCloud->pts[i].x << "\t" << yCloud->pts[i].y << "\t"
35  << yCloud->pts[i].z << "\t";
36  // Print out cij
37  // for(int c=0; c<yCloud->pts[i].c_ij.size(); c++){outputFile <<
38  // yCloud->pts[i].c_ij[c]<<"\t";} Print out the classifier
39  outputFile << yCloud->pts[i].iceType << "\n";
40  }
41  }
42  // Close the file
43  outputFile.close();
44  return 0;
45 }
T close(T... args)
int nop
Current frame number.
Definition: mol_sys.hpp:169
int currentFrame
Collection of points.
Definition: mol_sys.hpp:168
T is_open(T... args)
T open(T... args)

◆ radDeg()

double gen::radDeg ( double  angle)
inline

Inline function for converting radians->degrees.

Parameters
[in]angleThe input angle, in radians
Returns
The input angle, in degrees

Definition at line 57 of file generic.hpp.

57 { return (angle * 180) / gen::pi; }

◆ relDist()

std::array<double, 3> gen::relDist ( molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
int  iatom,
int  jatom 
)
inline

Inline generic function for getting the relative unwrapped distance between two particles for each dimension. The indices (not IDs) of the particles have been given.

Parameters
[in]yCloudThe input PointCloud, which contains the particle coordinates, simulation box lengths etc.
[in]iatomThe index of the \( i^{th} \) atom.
[in]jatomThe index of the \( j^{th} \) atom.
Returns
The unwrapped relative distances for each dimension.

Definition at line 196 of file generic.hpp.

197  {
199  std::array<double, 3> box = {yCloud->box[0], yCloud->box[1], yCloud->box[2]};
200  double r2 = 0.0; // Squared absolute distance
201 
202  // Get x1-x2 etc
203  dr[0] = yCloud->pts[iatom].x - yCloud->pts[jatom].x;
204  dr[1] = yCloud->pts[iatom].y - yCloud->pts[jatom].y;
205  dr[2] = yCloud->pts[iatom].z - yCloud->pts[jatom].z;
206 
207  // Get the relative distance
208  for (int k = 0; k < 3; k++) {
209  //
210  if (dr[k] < -box[k] * 0.5) {
211  dr[k] = dr[k] + box[k];
212  }
213  if (dr[k] >= box[k] * 0.5) {
214  dr[k] = dr[k] - box[k];
215  }
216  }
217 
218  return dr;
219 }

◆ tokenizer()

std::vector<std::string> gen::tokenizer ( std::string  line)
inline

Function for tokenizing line strings into words (strings) delimited by whitespace. This returns a vector with the words in it.

Parameters
[in]lineThe string containing the line to be tokenized

Definition at line 255 of file generic.hpp.

◆ tokenizerDouble()

std::vector<double> gen::tokenizerDouble ( std::string  line)
inline

Function for tokenizing line strings into a vector of doubles.

Parameters
[in]lineThe string containing the line to be tokenized

Definition at line 266 of file generic.hpp.

266  {
267  std::istringstream iss(line);
268  std::vector<double> tokens;
269  double number; // Each number being read in from the line
270  while (iss >> number) {
271  tokens.push_back(number);
272  }
273  return tokens;
274 }

◆ tokenizerInt()

std::vector<int> gen::tokenizerInt ( std::string  line)
inline

Function for tokenizing line strings into a vector of ints.

Parameters
[in]lineThe string containing the line to be tokenized

Definition at line 280 of file generic.hpp.

280  {
281  std::istringstream iss(line);
282  std::vector<int> tokens;
283  int number; // Each number being read in from the line
284  while (iss >> number) {
285  tokens.push_back(number);
286  }
287  return tokens;
288 }

◆ unwrappedCoordShift()

int gen::unwrappedCoordShift ( molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
int  iatomIndex,
int  jatomIndex,
double *  x_i,
double *  y_i,
double *  z_i,
double *  x_j,
double *  y_j,
double *  z_j 
)

Shift particles (unwrapped coordinates)

Function for getting the unwrapped coordinates of a pair of atoms.

Parameters
[in]yCloudThe input PointCloud to be printed.
[in]iatomIndexIndex of the \( i^{th} \) atom.
[in]jatomIndexIndex of the \( j^{th} \) atom.
[in,out]x_iX Coordinate of the \( i^{th} \) atom corresponding to the unwrapped distance.
[in,out]y_iY Coordinate of the \( i^{th} \) atom corresponding to the unwrapped distance.
[in,out]z_iZ Coordinate of the \( i^{th} \) atom corresponding to the unwrapped distance.
[in,out]x_jX Coordinate of the \( j^{th} \) atom corresponding to the unwrapped distance.
[in,out]y_jY Coordinate of the \( j^{th} \) atom corresponding to the unwrapped distance.
[in,out]z_jZ Coordinate of the \( j^{th} \) atom corresponding to the unwrapped distance.

Definition at line 66 of file generic.cpp.

69  {
70  //
71  double x_iatom, y_iatom, z_iatom;
72  double x_jatom, y_jatom, z_jatom;
73  double x_ij, y_ij, z_ij; // Relative distance
74  std::vector<double> box = yCloud->box;
75  double xPBC, yPBC, zPBC; // Actual unwrapped distance
76 
77  // ----------------------------------------------------------------------
78  // INIT
79  // iatom
80  x_iatom = yCloud->pts[iatomIndex].x;
81  y_iatom = yCloud->pts[iatomIndex].y;
82  z_iatom = yCloud->pts[iatomIndex].z;
83  // jatom
84  x_jatom = yCloud->pts[jatomIndex].x;
85  y_jatom = yCloud->pts[jatomIndex].y;
86  z_jatom = yCloud->pts[jatomIndex].z;
87  // ----------------------------------------------------------------------
88  // GET RELATIVE DISTANCE
89  x_ij = x_iatom - x_jatom;
90  y_ij = y_iatom - y_jatom;
91  z_ij = z_iatom - z_jatom;
92  // ----------------------------------------------------------------------
93  // SHIFT COORDINATES IF REQUIRED
94  // Shift x
95  if (fabs(x_ij) > 0.5 * box[0]) {
96  // Get the actual distance
97  xPBC = box[0] - fabs(x_ij);
98  if (x_ij < 0) {
99  x_jatom = x_iatom - xPBC;
100  } // To the -x side of currentIndex
101  else {
102  x_jatom = x_iatom + xPBC;
103  } // Add to the + side
104  } // Shift nextElement
105  //
106  // Shift y
107  if (fabs(y_ij) > 0.5 * box[1]) {
108  // Get the actual distance
109  yPBC = box[1] - fabs(y_ij);
110  if (y_ij < 0) {
111  y_jatom = y_iatom - yPBC;
112  } // To the -y side of currentIndex
113  else {
114  y_jatom = y_iatom + yPBC;
115  } // Add to the + side
116  } // Shift nextElement
117  //
118  // Shift z
119  if (fabs(z_ij) > 0.5 * box[2]) {
120  // Get the actual distance
121  zPBC = box[2] - fabs(z_ij);
122  if (z_ij < 0) {
123  z_jatom = z_iatom - zPBC;
124  } // To the -z side of currentIndex
125  else {
126  z_jatom = z_iatom + zPBC;
127  } // Add to the + side
128  } // Shift nextElement
129  // ----------------------------------------------------------------------
130  // Assign values
131  *x_i = x_iatom;
132  *y_i = y_iatom;
133  *z_i = z_iatom;
134  *x_j = x_jatom;
135  *y_j = y_jatom;
136  *z_j = z_jatom;
137 
138  return 0;
139 }

◆ unWrappedDistFromPoint()

double gen::unWrappedDistFromPoint ( molSys::PointCloud< molSys::Point< double >, double > *  yCloud,
int  iatom,
std::vector< double >  singlePoint 
)
inline

Inline generic function for obtaining the unwrapped periodic distance between one particle and another point, whose index has been given.

Parameters
[in]yCloudThe input PointCloud, which contains the particle coordinates, simulation box lengths etc.
[in]iatomThe index of the \( i^{th} \) atom.
[in]singlePointVector containing coordinate values
Returns
The unwrapped periodic distance.

Definition at line 134 of file generic.hpp.

136  {
138  double r2 = 0.0; // Squared absolute distance
139 
140  // Get x1-x2 etc
141  dr[0] = fabs(yCloud->pts[iatom].x - singlePoint[0]);
142  dr[1] = fabs(yCloud->pts[iatom].y - singlePoint[1]);
143  dr[2] = fabs(yCloud->pts[iatom].z - singlePoint[2]);
144 
145  // Get the squared absolute distance
146  for (int k = 0; k < 3; k++) {
147  // Correct for periodicity
148  dr[k] -= yCloud->box[k] * round(dr[k] / yCloud->box[k]);
149  r2 += pow(dr[k], 2.0);
150  }
151 
152  return sqrt(r2);
153 }

Variable Documentation

◆ pi

const double gen::pi = boost::math::constants::pi<double>()

Uses Boost to get the value of pi.

Definition at line 50 of file generic.hpp.