15#ifndef SEAMS_GENERIC_H_
16#define SEAMS_GENERIC_H_
60constexpr double pi = std::numbers::pi;
84 int n = (*input).size();
88 std::vector<double> sorted = *input;
89 std::sort(sorted.begin(), sorted.end());
94 median = 0.5 * (sorted[n / 2] + sorted[n / 2 - 1]);
96 median = sorted[(n + 1) / 2 - 1];
109 double yi,
double zi,
double xj,
double yj,
double zj) {
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;
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};
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};
161 int iatom,
int jatom) {
162 if (yCloud.box.size() >= 6) {
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];
169 std::array<double, 3> dr;
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);
178 for (
int k = 0; k < 3; k++) {
179 dr[k] -= yCloud.box[k] * std::round(dr[k] / yCloud.box[k]);
197 int iatom,
int jatom) {
205 const int *jatom, std::size_t n,
double *distSq) {
206 for (std::size_t k = 0; k < n; k++) {
213 std::ostringstream oss;
214 if (box.size() >= 3) {
215 oss << box[0] <<
' ' << box[1] <<
' ' << box[2];
217 if (box.size() >= 6) {
218 oss <<
" xy " << box[3] <<
" xz " << box[4] <<
" yz " << box[5];
227 const bool tilt = yCloud.box.size() >= 6;
229 os <<
"ITEM: BOX BOUNDS xy xz yz pp pp pp\n";
231 os <<
"ITEM: BOX BOUNDS pp pp pp\n";
233 for (
int k = 0; k < 3; k++) {
234 const double lo = (
static_cast<std::size_t
>(k) < yCloud.boxLow.size())
237 const double len = (
static_cast<std::size_t
>(k) < yCloud.box.size())
240 os << lo <<
' ' << lo + len;
242 os <<
' ' << yCloud.box[
static_cast<std::size_t
>(k + 3)];
260 double xj,
double yj,
double zj) {
261 if (yCloud.box.size() >= 6) {
263 yCloud.pts[iatom].z, xj, yj, zj);
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];
272 if (dr[k] >= yCloud.box[k] * 0.5) {
273 dr[k] -= yCloud.box[k];
281 const std::vector<double> &singlePoint) {
285 return std::sqrt(dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2]);
301 std::array<double, 3> dr;
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);
310 for (
int k = 0; k < 3; k++) {
311 r2 += pow(dr[k], 2.0);
328inline std::array<double, 3>
332 yCloud.pts[jatom].y, yCloud.pts[jatom].z);
351 std::string outFile);
356 int jatomIndex,
double *x_i,
double *y_i,
double *z_i,
double *x_j,
357 double *y_j,
double *z_j);
362 std::vector<double> quat2);
369inline std::vector<std::string>
tokenizer(std::string line) {
370 std::istringstream iss(line);
371 std::vector<std::string> tokens{std::istream_iterator<std::string>{iss},
372 std::istream_iterator<std::string>{}};
381 std::istringstream iss(line);
382 std::vector<double> tokens;
384 while (iss >> number) {
385 tokens.push_back(number);
395 std::istringstream iss(line);
396 std::vector<int> tokens;
398 while (iss >> number) {
399 tokens.push_back(number);
409 return std::filesystem::exists(name);
420inline std::vector<std::complex<double>>
421avgVector(std::vector<std::complex<double>> v,
int l,
int neigh) {
425 for (
int m = 0; m < 2 * l + 1; m++) {
426 v[m] = (1.0 /
static_cast<double>(neigh)) * v[m];
double 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 PBC...
std::vector< std::complex< double > > avgVector(std::vector< std::complex< double > > v, int l, int neigh)
Calculates the complex vector, normalized by the number of nearest neighbours, of length .
void writeDumpBoxBounds(std::ostream &os, const molSys::PointCloud< molSys::Point< double >, double > &yCloud)
std::array< double, 3 > 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 di...
double 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,...
double 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 calcMedian(std::vector< double > *input)
Inline generic function for calculating the median given a vector of the values.
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)
std::string formatDumpBox(const std::vector< double > &box)
std::vector< double > tokenizerDouble(std::string line)
Function for tokenizing line strings into a vector of doubles.
constexpr double pi
Uses Boost to get the value of pi.
bool file_exists(const std::string &name)
Function for checking if a file exists or not.
std::vector< std::string > tokenizer(std::string line)
Function for tokenizing line strings into words (strings) delimited by whitespace.
int prettyPrintYoda(const molSys::PointCloud< molSys::Point< double >, double > &yCloud, std::string outFile)
Generic function for printing all the struct information.
double angDistDegQuaternions(std::vector< double > quat1, std::vector< double > quat2)
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...
void batchPeriodicDistSq(const molSys::PointCloud< molSys::Point< double >, double > &yCloud, int iatom, const int *jatom, std::size_t n, double *distSq)
int 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).
std::vector< int > tokenizerInt(std::string line)
Function for tokenizing line strings into a vector of ints.
double radDeg(double angle)
Inline function for converting radians->degrees.
bool 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 ent...
double getAverageWithoutOutliers(std::vector< double > inpVec)
Get the average, after excluding the outliers, using quartiles.
double unWrappedDistFromPoint(const molSys::PointCloud< molSys::Point< double >, double > &yCloud, int iatom, const std::vector< double > &singlePoint)
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,...
The main molecular system handler.
Small generic functions that are shared by all namespaces.
This contains a collection of points; contains information for a particular frame.
This contains per-particle information.