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

421 {
422 if (neigh == 0) {
423 return v;
424 }
425 for (int m = 0; m < 2 * l + 1; m++) {
426 v[m] = (1.0 / static_cast<double>(neigh)) * v[m];
427 }
428
429 return v;
430}

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

205 {
206 for (std::size_t k = 0; k < n; k++) {
207 distSq[k] = periodicDistSq(yCloud, iatom, jatom[k]);
208 }
209}
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:160

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

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

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

345 {
346 return a.atomID < b.atomID;
347}

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

300 {
301 std::array<double, 3> dr;
302 double r2 = 0.0; // Squared absolute distance
303
304 // Get x1-x2 etc
305 dr[0] = fabs(yCloud.pts[iatom].x - yCloud.pts[jatom].x);
306 dr[1] = fabs(yCloud.pts[iatom].y - yCloud.pts[jatom].y);
307 dr[2] = fabs(yCloud.pts[iatom].z - yCloud.pts[jatom].z);
308
309 // Get the squared absolute distance
310 for (int k = 0; k < 3; k++) {
311 r2 += pow(dr[k], 2.0);
312 }
313
314 return sqrt(r2);
315}
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 408 of file generic.hpp.

408 {
409 return std::filesystem::exists(name);
410}

◆ formatDumpBox()

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

Definition at line 212 of file generic.hpp.

212 {
213 std::ostringstream oss;
214 if (box.size() >= 3) {
215 oss << box[0] << ' ' << box[1] << ' ' << box[2];
216 }
217 if (box.size() >= 6) {
218 oss << " xy " << box[3] << " xz " << box[4] << " yz " << box[5];
219 }
220 return oss.str();
221}

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

197 {
198 return std::sqrt(periodicDistSq(yCloud, iatom, jatom));
199}

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

161 {
162 if (yCloud.box.size() >= 6) {
163 const auto dr = triclinicMinImage(
164 yCloud, yCloud.pts[iatom].x, yCloud.pts[iatom].y, yCloud.pts[iatom].z,
165 yCloud.pts[jatom].x, yCloud.pts[jatom].y, yCloud.pts[jatom].z);
166 return dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
167 }
168
169 std::array<double, 3> dr;
170 double r2 = 0.0; // Squared absolute distance
171
172 // Get x1-x2 etc
173 dr[0] = std::fabs(yCloud.pts[iatom].x - yCloud.pts[jatom].x);
174 dr[1] = std::fabs(yCloud.pts[iatom].y - yCloud.pts[jatom].y);
175 dr[2] = std::fabs(yCloud.pts[iatom].z - yCloud.pts[jatom].z);
176
177 // Three-axis wrap for an orthorhombic length-3 box
178 for (int k = 0; k < 3; k++) {
179 dr[k] -= yCloud.box[k] * std::round(dr[k] / yCloud.box[k]);
180 r2 += dr[k] * dr[k];
181 }
182
183 return r2;
184}
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:107
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 67 of file generic.hpp.

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

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

330 {
331 return relDistFromPoint(yCloud, iatom, yCloud.pts[jatom].x,
332 yCloud.pts[jatom].y, yCloud.pts[jatom].z);
333}
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:258

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

260 {
261 if (yCloud.box.size() >= 6) {
262 return triclinicMinImage(yCloud, yCloud.pts[iatom].x, yCloud.pts[iatom].y,
263 yCloud.pts[iatom].z, xj, yj, zj);
264 }
265
266 std::array<double, 3> dr = {yCloud.pts[iatom].x - xj, yCloud.pts[iatom].y - yj,
267 yCloud.pts[iatom].z - zj};
268 for (int k = 0; k < 3; k++) {
269 if (dr[k] < -yCloud.box[k] * 0.5) {
270 dr[k] += yCloud.box[k];
271 }
272 if (dr[k] >= yCloud.box[k] * 0.5) {
273 dr[k] -= yCloud.box[k];
274 }
275 }
276 return dr;
277}

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

369 {
370 std::istringstream iss(line);
371 std::vector<std::string> tokens{std::istream_iterator<std::string>{iss},
372 std::istream_iterator<std::string>{}};
373 return tokens;
374}

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

380 {
381 std::istringstream iss(line);
382 std::vector<double> tokens;
383 double number; // Each number being read in from the line
384 while (iss >> number) {
385 tokens.push_back(number);
386 }
387 return tokens;
388}

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

394 {
395 std::istringstream iss(line);
396 std::vector<int> tokens;
397 int number; // Each number being read in from the line
398 while (iss >> number) {
399 tokens.push_back(number);
400 }
401 return tokens;
402}

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

109 {
110 const auto &box = yCloud.box;
111 const auto &boxLow = yCloud.boxLow;
112 const double xspan = box[0];
113 const double yspan = box[1];
114 const double zspan = box[2];
115 const double xlo_b = boxLow.size() > 0 ? boxLow[0] : 0.0;
116 const double ylo_b = boxLow.size() > 1 ? boxLow[1] : 0.0;
117 const double zlo_b = boxLow.size() > 2 ? boxLow[2] : 0.0;
118 const double xy = box[3];
119 const double xz = box[4];
120 const double yz = box[5];
121 const double xmin = std::min(std::min(0.0, xy), std::min(xz, xy + xz));
122 const double xmax = std::max(std::max(0.0, xy), std::max(xz, xy + xz));
123 const double ymin = std::min(0.0, yz);
124 const double ymax = std::max(0.0, yz);
125 const double lx = xspan - xmax + xmin;
126 const double ly = yspan - ymax + ymin;
127 const double lz = zspan;
128 const double ox = xlo_b - xmin;
129 const double oy = ylo_b - ymin;
130 const double oz = zlo_b;
131
132 auto toFrac = [&](double x, double y, double z) {
133 const double sz = (z - oz) / lz;
134 const double sy = (y - oy - yz * sz) / ly;
135 const double sx = (x - ox - xy * sy - xz * sz) / lx;
136 return std::array<double, 3>{sx, sy, sz};
137 };
138 const auto si = toFrac(xi, yi, zi);
139 const auto sj = toFrac(xj, yj, zj);
140 double dsx = si[0] - sj[0];
141 double dsy = si[1] - sj[1];
142 double dsz = si[2] - sj[2];
143 dsx -= std::round(dsx);
144 dsy -= std::round(dsy);
145 dsz -= std::round(dsz);
146 return {lx * dsx + xy * dsy + xz * dsz, ly * dsy + yz * dsz, lz * dsz};
147}
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 279 of file generic.hpp.

281 {
282 const auto dr =
283 relDistFromPoint(yCloud, iatom, singlePoint[0], singlePoint[1],
284 singlePoint[2]);
285 return std::sqrt(dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2]);
286}

◆ writeDumpBoxBounds()

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

Definition at line 224 of file generic.hpp.

226 {
227 const bool tilt = yCloud.box.size() >= 6;
228 if (tilt) {
229 os << "ITEM: BOX BOUNDS xy xz yz pp pp pp\n";
230 } else {
231 os << "ITEM: BOX BOUNDS pp pp pp\n";
232 }
233 for (int k = 0; k < 3; k++) {
234 const double lo = (static_cast<std::size_t>(k) < yCloud.boxLow.size())
235 ? yCloud.boxLow[k]
236 : 0.0;
237 const double len = (static_cast<std::size_t>(k) < yCloud.box.size())
238 ? yCloud.box[k]
239 : 0.0;
240 os << lo << ' ' << lo + len;
241 if (tilt) {
242 os << ' ' << yCloud.box[static_cast<std::size_t>(k + 3)];
243 }
244 os << '\n';
245 }
246}

Variable Documentation

◆ pi

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

Uses Boost to get the value of pi.

Definition at line 60 of file generic.hpp.