Loading...
Searching...
No Matches
Gen

Topics

 Ring
 

Namespaces

namespace  gen
 Small generic functions that are shared by all namespaces.

Functions

double gen::radDeg (double angle)
 Inline function for converting radians->degrees.
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.
double gen::getAverageWithoutOutliers (std::vector< double > inpVec)
 Get the average, after excluding the outliers, using quartiles.
double gen::calcMedian (std::vector< double > *input)
 Inline generic function for calculating the median given a vector of the values.
std::array< double, 3 > gen::triclinicMinImage (const molSys::PointCloud< molSys::Point< double >, double > &yCloud, double xi, double yi, double zi, double xj, double yj, double zj)
double gen::periodicDistSq (const 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.
double gen::periodicDist (const 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.
void gen::batchPeriodicDistSq (const molSys::PointCloud< molSys::Point< double >, double > &yCloud, int iatom, const int *jatom, std::size_t n, double *distSq)
std::string gen::formatDumpBox (const std::vector< double > &box)
void gen::writeDumpBoxBounds (std::ostream &os, const molSys::PointCloud< molSys::Point< double >, double > &yCloud)
std::array< double, 3 > gen::relDistFromPoint (const molSys::PointCloud< molSys::Point< double >, double > &yCloud, int iatom, double xj, double yj, double zj)
 Inline generic function for obtaining the unwrapped periodic distance between one particle and another point, whose index has been given.
double gen::unWrappedDistFromPoint (const molSys::PointCloud< molSys::Point< double >, double > &yCloud, int iatom, const std::vector< double > &singlePoint)
double gen::distance (const 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.
std::array< double, 3 > gen::relDist (const molSys::PointCloud< molSys::Point< double >, double > &yCloud, int iatom, int jatom)
 Inline generic function for getting the relative unwrapped distance between two particles for each dimension.
bool gen::compareByAtomID (const molSys::Point< double > &a, const molSys::Point< double > &b)
 Inline generic function for sorting or comparing two particles, according to the atom ID when the entire Point objects have been passed.
int gen::prettyPrintYoda (const molSys::PointCloud< molSys::Point< double >, double > &yCloud, std::string outFile)
 Generic function for printing all the struct information.
int gen::unwrappedCoordShift (const 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).
double gen::angDistDegQuaternions (std::vector< double > quat1, std::vector< double > quat2)
std::vector< std::string > gen::tokenizer (std::string line)
 Function for tokenizing line strings into words (strings) delimited by whitespace.
std::vector< double > gen::tokenizerDouble (std::string line)
 Function for tokenizing line strings into a vector of doubles.
std::vector< int > gen::tokenizerInt (std::string line)
 Function for tokenizing line strings into a vector of ints.
bool gen::file_exists (const std::string &name)
 Function for checking if a file exists or not.
std::vector< std::complex< double > > gen::avgVector (std::vector< std::complex< double > > v, int l, int neigh)
 Calculates the complex vector, normalized by the number of nearest neighbours, of length \(2l+1\).

Variables

constexpr double gen::pi = std::numbers::pi
 Uses Boost to get the value of pi.

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

◆ 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 478 of file generic.hpp.

478 {
479 if (neigh == 0) {
480 return v;
481 }
482 for (int m = 0; m < 2 * l + 1; m++) {
483 v[m] = (1.0 / static_cast<double>(neigh)) * v[m];
484 }
485
486 return v;
487}

◆ batchPeriodicDistSq()

void gen::batchPeriodicDistSq ( const molSys::PointCloud< molSys::Point< double >, double > & yCloud,
int iatom,
const int * jatom,
std::size_t n,
double * distSq )
inline

Definition at line 250 of file generic.hpp.

252 {
253 for (std::size_t k = 0; k < n; k++) {
254 distSq[k] = periodicDistSq(yCloud, iatom, jatom[k]);
255 }
256}
double periodicDistSq(const 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:196

◆ 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 87 of file generic.hpp.

87 {
88 int n = (*input).size(); // Number of elements
89 double median; // Output median value
90
91 // Sort a copy (avoid mutating input)
92 std::vector<double> sorted = *input;
93 std::sort(sorted.begin(), sorted.end());
94
95 // Calculate the median
96 // For even values, the median is the average of the two middle values
97 if (n % 2 == 0) {
98 median = 0.5 * (sorted[n / 2] + sorted[n / 2 - 1]);
99 } else {
100 median = sorted[(n + 1) / 2 - 1];
101 }
102
103 return median;
104}

◆ 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 401 of file generic.hpp.

402 {
403 return a.atomID < b.atomID;
404}

◆ distance()

double gen::distance ( const 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 356 of file generic.hpp.

357 {
358 std::array<double, 3> dr;
359 double r2 = 0.0; // Squared absolute distance
360
361 // Get x1-x2 etc
362 dr[0] = fabs(yCloud.pts[iatom].x - yCloud.pts[jatom].x);
363 dr[1] = fabs(yCloud.pts[iatom].y - yCloud.pts[jatom].y);
364 dr[2] = fabs(yCloud.pts[iatom].z - yCloud.pts[jatom].z);
365
366 // Get the squared absolute distance
367 for (int k = 0; k < 3; k++) {
368 r2 += pow(dr[k], 2.0);
369 }
370
371 return sqrt(r2);
372}
std::vector< S > pts
Definition mol_sys.hpp:174

◆ 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.

◆ 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 465 of file generic.hpp.

465 {
466 return std::filesystem::exists(name);
467}

◆ formatDumpBox()

std::string gen::formatDumpBox ( const std::vector< double > & box)
inline

Definition at line 259 of file generic.hpp.

259 {
260 std::ostringstream oss;
261 if (box.size() >= 3) {
262 oss << box[0] << ' ' << box[1] << ' ' << box[2];
263 }
264 if (box.size() >= 6) {
265 oss << " xy " << box[3] << " xz " << box[4] << " yz " << box[5];
266 }
267 return oss.str();
268}

◆ getAverageWithoutOutliers()

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

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

◆ periodicDist()

double gen::periodicDist ( const 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 243 of file generic.hpp.

244 {
245 return std::sqrt(periodicDistSq(yCloud, iatom, jatom));
246}

◆ periodicDistSq()

double gen::periodicDistSq ( const 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 196 of file generic.hpp.

197 {
198#ifdef SEAMS_HAS_MINIMAGE
199 const mi_cell cell = pointCloudCell(yCloud);
200 const double p[3] = {yCloud.pts[iatom].x, yCloud.pts[iatom].y,
201 yCloud.pts[iatom].z};
202 const double q[3] = {yCloud.pts[jatom].x, yCloud.pts[jatom].y,
203 yCloud.pts[jatom].z};
204 double out = 0.0;
205 mi_dist2(&cell, p, q, &out);
206 return out;
207#else
208 if (yCloud.box.size() >= 6) {
209 const auto dr = triclinicMinImage(
210 yCloud, yCloud.pts[iatom].x, yCloud.pts[iatom].y, yCloud.pts[iatom].z,
211 yCloud.pts[jatom].x, yCloud.pts[jatom].y, yCloud.pts[jatom].z);
212 return dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
213 }
214
215 std::array<double, 3> dr;
216 double r2 = 0.0; // Squared absolute distance
217
218 // Get x1-x2 etc
219 dr[0] = std::fabs(yCloud.pts[iatom].x - yCloud.pts[jatom].x);
220 dr[1] = std::fabs(yCloud.pts[iatom].y - yCloud.pts[jatom].y);
221 dr[2] = std::fabs(yCloud.pts[iatom].z - yCloud.pts[jatom].z);
222
223 // Three-axis wrap for an orthorhombic length-3 box
224 for (int k = 0; k < 3; k++) {
225 dr[k] -= yCloud.box[k] * std::round(dr[k] / yCloud.box[k]);
226 r2 += dr[k] * dr[k];
227 }
228
229 return r2;
230#endif
231}
std::array< double, 3 > triclinicMinImage(const molSys::PointCloud< molSys::Point< double >, double > &yCloud, double xi, double yi, double zi, double xj, double yj, double zj)
Definition generic.hpp:134
std::vector< T > box
Number of atoms.
Definition mol_sys.hpp:177

◆ prettyPrintYoda()

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

Generic function for printing all the struct information.

◆ 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 71 of file generic.hpp.

71{ return (angle * 180) / gen::pi; }
constexpr double pi
Uses Boost to get the value of pi.
Definition generic.hpp:64

◆ relDist()

std::array< double, 3 > gen::relDist ( const 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 386 of file generic.hpp.

387 {
388 return relDistFromPoint(yCloud, iatom, yCloud.pts[jatom].x,
389 yCloud.pts[jatom].y, yCloud.pts[jatom].z);
390}
std::array< double, 3 > relDistFromPoint(const molSys::PointCloud< molSys::Point< double >, double > &yCloud, int iatom, double xj, double yj, double zj)
Inline generic function for obtaining the unwrapped periodic distance between one particle and anothe...
Definition generic.hpp:305

◆ relDistFromPoint()

std::array< double, 3 > gen::relDistFromPoint ( const molSys::PointCloud< molSys::Point< double >, double > & yCloud,
int iatom,
double xj,
double yj,
double zj )
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 305 of file generic.hpp.

307 {
308#ifdef SEAMS_HAS_MINIMAGE
309 const mi_cell cell = pointCloudCell(yCloud);
310 const double p[3] = {xj, yj, zj};
311 const double q[3] = {yCloud.pts[iatom].x, yCloud.pts[iatom].y,
312 yCloud.pts[iatom].z};
313 double dr[3] = {0.0, 0.0, 0.0};
314 mi_displacement(&cell, p, q, dr);
315 return {dr[0], dr[1], dr[2]};
316#else
317 if (yCloud.box.size() >= 6) {
318 return triclinicMinImage(yCloud, yCloud.pts[iatom].x, yCloud.pts[iatom].y,
319 yCloud.pts[iatom].z, xj, yj, zj);
320 }
321
322 std::array<double, 3> dr = {yCloud.pts[iatom].x - xj, yCloud.pts[iatom].y - yj,
323 yCloud.pts[iatom].z - zj};
324 for (int k = 0; k < 3; k++) {
325 if (dr[k] < -yCloud.box[k] * 0.5) {
326 dr[k] += yCloud.box[k];
327 }
328 if (dr[k] >= yCloud.box[k] * 0.5) {
329 dr[k] -= yCloud.box[k];
330 }
331 }
332 return dr;
333#endif
334}

◆ 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 426 of file generic.hpp.

426 {
427 std::istringstream iss(line);
428 std::vector<std::string> tokens{std::istream_iterator<std::string>{iss},
429 std::istream_iterator<std::string>{}};
430 return tokens;
431}

◆ 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 437 of file generic.hpp.

437 {
438 std::istringstream iss(line);
439 std::vector<double> tokens;
440 double number; // Each number being read in from the line
441 while (iss >> number) {
442 tokens.push_back(number);
443 }
444 return tokens;
445}

◆ 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 451 of file generic.hpp.

451 {
452 std::istringstream iss(line);
453 std::vector<int> tokens;
454 int number; // Each number being read in from the line
455 while (iss >> number) {
456 tokens.push_back(number);
457 }
458 return tokens;
459}

◆ triclinicMinImage()

std::array< double, 3 > gen::triclinicMinImage ( const molSys::PointCloud< molSys::Point< double >, double > & yCloud,
double xi,
double yi,
double zi,
double xj,
double yj,
double zj )
inline

Definition at line 134 of file generic.hpp.

136 {
137#ifdef SEAMS_HAS_MINIMAGE
138 const mi_cell cell = pointCloudCell(yCloud);
139 const double p[3] = {xj, yj, zj};
140 const double q[3] = {xi, yi, zi};
141 double dr[3] = {0.0, 0.0, 0.0};
142 mi_displacement(&cell, p, q, dr);
143 return {dr[0], dr[1], dr[2]};
144#else
145 const auto &box = yCloud.box;
146 const auto &boxLow = yCloud.boxLow;
147 const double xspan = box[0];
148 const double yspan = box[1];
149 const double zspan = box[2];
150 const double xlo_b = boxLow.size() > 0 ? boxLow[0] : 0.0;
151 const double ylo_b = boxLow.size() > 1 ? boxLow[1] : 0.0;
152 const double zlo_b = boxLow.size() > 2 ? boxLow[2] : 0.0;
153 const double xy = box[3];
154 const double xz = box[4];
155 const double yz = box[5];
156 const double xmin = std::min(std::min(0.0, xy), std::min(xz, xy + xz));
157 const double xmax = std::max(std::max(0.0, xy), std::max(xz, xy + xz));
158 const double ymin = std::min(0.0, yz);
159 const double ymax = std::max(0.0, yz);
160 const double lx = xspan - xmax + xmin;
161 const double ly = yspan - ymax + ymin;
162 const double lz = zspan;
163 const double ox = xlo_b - xmin;
164 const double oy = ylo_b - ymin;
165 const double oz = zlo_b;
166
167 auto toFrac = [&](double x, double y, double z) {
168 const double sz = (z - oz) / lz;
169 const double sy = (y - oy - yz * sz) / ly;
170 const double sx = (x - ox - xy * sy - xz * sz) / lx;
171 return std::array<double, 3>{sx, sy, sz};
172 };
173 const auto si = toFrac(xi, yi, zi);
174 const auto sj = toFrac(xj, yj, zj);
175 double dsx = si[0] - sj[0];
176 double dsy = si[1] - sj[1];
177 double dsz = si[2] - sj[2];
178 dsx -= std::round(dsx);
179 dsy -= std::round(dsy);
180 dsz -= std::round(dsz);
181 return {lx * dsx + xy * dsy + xz * dsz, ly * dsy + yz * dsz, lz * dsz};
182#endif
183}
std::vector< T > boxLow
Periodic box lengths.
Definition mol_sys.hpp:178

◆ unwrappedCoordShift()

int gen::unwrappedCoordShift ( const 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 )
nodiscard

Shift particles (unwrapped coordinates).

◆ unWrappedDistFromPoint()

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

Definition at line 336 of file generic.hpp.

338 {
339 const auto dr =
340 relDistFromPoint(yCloud, iatom, singlePoint[0], singlePoint[1],
341 singlePoint[2]);
342 return std::sqrt(dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2]);
343}

◆ writeDumpBoxBounds()

void gen::writeDumpBoxBounds ( std::ostream & os,
const molSys::PointCloud< molSys::Point< double >, double > & yCloud )
inline

Definition at line 271 of file generic.hpp.

273 {
274 const bool tilt = yCloud.box.size() >= 6;
275 if (tilt) {
276 os << "ITEM: BOX BOUNDS xy xz yz pp pp pp\n";
277 } else {
278 os << "ITEM: BOX BOUNDS pp pp pp\n";
279 }
280 for (int k = 0; k < 3; k++) {
281 const double lo = (static_cast<std::size_t>(k) < yCloud.boxLow.size())
282 ? yCloud.boxLow[k]
283 : 0.0;
284 const double len = (static_cast<std::size_t>(k) < yCloud.box.size())
285 ? yCloud.box[k]
286 : 0.0;
287 os << lo << ' ' << lo + len;
288 if (tilt) {
289 os << ' ' << yCloud.box[static_cast<std::size_t>(k + 3)];
290 }
291 os << '\n';
292 }
293}

Variable Documentation

◆ pi

double gen::pi = std::numbers::pi
constexpr

Uses Boost to get the value of pi.

Definition at line 64 of file generic.hpp.