15#ifndef SEAMS_GENERIC_H_
16#define SEAMS_GENERIC_H_
29#ifdef SEAMS_HAS_MINIMAGE
66constexpr double pi = std::numbers::pi;
90 int n =
static_cast<int>((*input).size());
94 std::vector<double> sorted = *input;
95 std::sort(sorted.begin(), sorted.end());
100 median = 0.5 * (sorted[
static_cast<std::size_t
>(n / 2)] + sorted[
static_cast<std::size_t
>(n / 2 - 1)]);
102 median = sorted[
static_cast<std::size_t
>((n + 1) / 2 - 1)];
108#ifdef SEAMS_HAS_MINIMAGE
110inline bool pointCloudCell(
113 const auto &box = yCloud.box;
114 const auto &boxLow = yCloud.boxLow;
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 if (box.size() >= 6) {
119 return mi_cell_from_lammps_bounds(box[0], box[1], box[2], box[3], box[4],
120 box[5], xlo_b, ylo_b, zlo_b, out) == 0;
122 if (box.size() >= 3 && box[0] > 0.0 && box[1] > 0.0 && box[2] > 0.0) {
123 *out = mi_cell_ortho(box[0], box[1], box[2]);
158 const auto &box = yCloud.box;
159 const auto &boxLow = yCloud.boxLow;
160 b.
ox = boxLow.size() > 0 ? boxLow[0] : 0.0;
161 b.
oy = boxLow.size() > 1 ? boxLow[1] : 0.0;
162 b.
oz = boxLow.size() > 2 ? boxLow[2] : 0.0;
163 if (box.size() >= 6) {
164 const double xy = box[3];
165 const double xz = box[4];
166 const double yz = box[5];
167 const double xmin = std::min(std::min(0.0, xy), std::min(xz, xy + xz));
168 const double xmax = std::max(std::max(0.0, xy), std::max(xz, xy + xz));
169 const double ymin = std::min(0.0, yz);
170 const double ymax = std::max(0.0, yz);
171 b.
lx = box[0] - xmax + xmin;
172 b.
ly = box[1] - ymax + ymin;
180 }
else if (box.size() >= 3) {
187 if (!(b.
lx > 0.0 && b.
ly > 0.0 && b.
lz > 0.0)) {
190 const double bcz = b.
xy * b.
yz - b.
ly * b.
xz;
206 double zi,
double xj,
double yj,
209 std::array<double, 3> dr = {xi - xj, yi - yj, zi - zj};
210 const double len[3] = {b.
lx, b.
ly, b.
lz};
211 for (
int k = 0; k < 3; k++) {
212 dr[
static_cast<std::size_t
>(k)] -=
213 len[k] * std::floor(dr[
static_cast<std::size_t
>(k)] / len[k] + 0.5);
217 const double sz_i = (zi - b.
oz) / b.
lz;
218 const double sy_i = (yi - b.
oy - b.
yz * sz_i) / b.
ly;
219 const double sx_i = (xi - b.
ox - b.
xy * sy_i - b.
xz * sz_i) / b.
lx;
220 const double sz_j = (zj - b.
oz) / b.
lz;
221 const double sy_j = (yj - b.
oy - b.
yz * sz_j) / b.
ly;
222 const double sx_j = (xj - b.
ox - b.
xy * sy_j - b.
xz * sz_j) / b.
lx;
223 double dsx = sx_i - sx_j;
224 double dsy = sy_i - sy_j;
225 double dsz = sz_i - sz_j;
226 dsx -= std::round(dsx);
227 dsy -= std::round(dsy);
228 dsz -= std::round(dsz);
229 return {b.
lx * dsx + b.
xy * dsy + b.
xz * dsz, b.
ly * dsy + b.
yz * dsz,
234 double xj,
double yj,
double zj) {
235 const auto dr =
fracDelta(b, xi, yi, zi, xj, yj, zj);
236 return dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
247#ifdef SEAMS_HAS_MINIMAGE
248inline bool euclideanDelta(
250 double yi,
double zi,
double xj,
double yj,
double zj,
double dr[3]) {
252 if (!pointCloudCell(yCloud, &cell)) {
255 const double p[3] = {xj, yj, zj};
256 const double q[3] = {xi, yi, zi};
257 return mi_displacement_euclidean(&cell, p, q, dr) == 0;
264 std::vector<double> xyz;
269makeCellFrame(
const molSys::PointCloud<molSys::Point<double>,
double> &yCloud) {
271 if (!pointCloudCell(yCloud, &f.cell)) {
274 const std::size_t n = yCloud.pts.size();
276 for (std::size_t i = 0; i < n; i++) {
277 f.xyz[3 * i] = yCloud.pts[i].x;
278 f.xyz[3 * i + 1] = yCloud.pts[i].y;
279 f.xyz[3 * i + 2] = yCloud.pts[i].z;
286inline double euclideanDistSq(
const CellFrame &f,
int i,
int j) {
288 if (mi_displacement_euclidean(&f.cell, &f.xyz[3 *
static_cast<std::size_t
>(j)],
289 &f.xyz[3 *
static_cast<std::size_t
>(i)],
293 return dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
302 double yi,
double zi,
double xj,
double yj,
double zj) {
305 const auto dr =
fracDelta(b, xi, yi, zi, xj, yj, zj);
306 const double r2 = dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
310#ifdef SEAMS_HAS_MINIMAGE
311 double ed[3] = {0.0, 0.0, 0.0};
312 if (euclideanDelta(yCloud, xi, yi, zi, xj, yj, zj, ed)) {
313 return {ed[0], ed[1], ed[2]};
318 const auto &box = yCloud.box;
319 const auto &boxLow = yCloud.boxLow;
320 const double xspan = box[0];
321 const double yspan = box[1];
322 const double zspan = box[2];
323 const double xlo_b = boxLow.size() > 0 ? boxLow[0] : 0.0;
324 const double ylo_b = boxLow.size() > 1 ? boxLow[1] : 0.0;
325 const double zlo_b = boxLow.size() > 2 ? boxLow[2] : 0.0;
326 const double xy = box[3];
327 const double xz = box[4];
328 const double yz = box[5];
329 const double xmin = std::min(std::min(0.0, xy), std::min(xz, xy + xz));
330 const double xmax = std::max(std::max(0.0, xy), std::max(xz, xy + xz));
331 const double ymin = std::min(0.0, yz);
332 const double ymax = std::max(0.0, yz);
333 const double lx = xspan - xmax + xmin;
334 const double ly = yspan - ymax + ymin;
335 const double lz = zspan;
336 const double ox = xlo_b - xmin;
337 const double oy = ylo_b - ymin;
338 const double oz = zlo_b;
339 const double sz_i = (zi - oz) / lz;
340 const double sy_i = (yi - oy - yz * sz_i) / ly;
341 const double sx_i = (xi - ox - xy * sy_i - xz * sz_i) / lx;
342 const double sz_j = (zj - oz) / lz;
343 const double sy_j = (yj - oy - yz * sz_j) / ly;
344 const double sx_j = (xj - ox - xy * sy_j - xz * sz_j) / lx;
345 double dsx = sx_i - sx_j;
346 double dsy = sy_i - sy_j;
347 double dsz = sz_i - sz_j;
348 dsx -= std::round(dsx);
349 dsy -= std::round(dsy);
350 dsz -= std::round(dsz);
351 return {lx * dsx + xy * dsy + xz * dsz, ly * dsy + yz * dsz, lz * dsz};
367 int iatom,
int jatom) {
368 const auto &atom = yCloud.pts[
static_cast<std::size_t
>(iatom)];
369 const auto &pj = yCloud.pts[
static_cast<std::size_t
>(jatom)];
371 const auto wrapped =
fracDelta(b, atom.x, atom.y, atom.z, pj.x, pj.y, pj.z);
373 wrapped[0] * wrapped[0] + wrapped[1] * wrapped[1] + wrapped[2] * wrapped[2];
377#ifdef SEAMS_HAS_MINIMAGE
378 double ed[3] = {0.0, 0.0, 0.0};
379 if (euclideanDelta(yCloud, atom.x, atom.y, atom.z, pj.x, pj.y, pj.z, ed)) {
380 return ed[0] * ed[0] + ed[1] * ed[1] + ed[2] * ed[2];
384 const std::array<double, 3> raw = {atom.x - pj.x, atom.y - pj.y, atom.z - pj.z};
387 return euc[0] * euc[0] + euc[1] * euc[1] + euc[2] * euc[2];
390 if (yCloud.box.size() >= 6) {
393 return dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
395 std::array<double, 3> dr;
397 dr[0] = std::fabs(atom.x - pj.x);
398 dr[1] = std::fabs(atom.y - pj.y);
399 dr[2] = std::fabs(atom.z - pj.z);
400 for (
int k = 0; k < 3; k++) {
401 dr[
static_cast<std::size_t
>(k)] -=
402 yCloud.box[
static_cast<std::size_t
>(k)] *
403 std::round(dr[
static_cast<std::size_t
>(k)] /
404 yCloud.box[
static_cast<std::size_t
>(k)]);
405 r2 += dr[
static_cast<std::size_t
>(k)] * dr[
static_cast<std::size_t
>(k)];
412 int iatom,
int jatom) {
427 int iatom,
int jatom) {
437 const int *jatom, std::size_t n,
double *distSq) {
439#ifdef SEAMS_HAS_MINIMAGE
442 if (pointCloudCell(yCloud, &cell)) {
443 const auto &atom = yCloud.pts[
static_cast<std::size_t
>(iatom)];
444 const double p[3] = {atom.x, atom.y, atom.z};
445 std::vector<double> qs(n * 3);
446 for (std::size_t k = 0; k < n; ++k) {
447 const auto &pj = yCloud.pts[
static_cast<std::size_t
>(jatom[k])];
449 qs[3 * k + 1] = pj.y;
450 qs[3 * k + 2] = pj.z;
452 if (mi_dist2_many(&cell, p, qs.data(), n, distSq) == 0) {
453 for (std::size_t k = 0; k < n; ++k) {
457 const double q[3] = {qs[3 * k], qs[3 * k + 1], qs[3 * k + 2]};
458 double ed[3] = {0.0, 0.0, 0.0};
459 if (mi_displacement_euclidean(&cell, q, p, ed) == 0) {
460 distSq[k] = ed[0] * ed[0] + ed[1] * ed[1] + ed[2] * ed[2];
468 for (std::size_t k = 0; k < n; k++) {
475 std::ostringstream oss;
476 if (box.size() >= 3) {
477 oss << box[0] <<
' ' << box[1] <<
' ' << box[2];
479 if (box.size() >= 6) {
480 oss <<
" xy " << box[3] <<
" xz " << box[4] <<
" yz " << box[5];
489 const bool tilt = yCloud.box.size() >= 6;
491 os <<
"ITEM: BOX BOUNDS xy xz yz pp pp pp\n";
493 os <<
"ITEM: BOX BOUNDS pp pp pp\n";
495 for (
int k = 0; k < 3; k++) {
496 const double lo = (
static_cast<std::size_t
>(k) < yCloud.boxLow.size())
497 ? yCloud.boxLow[
static_cast<std::size_t
>(k)]
499 const double len = (
static_cast<std::size_t
>(k) < yCloud.box.size())
500 ? yCloud.box[
static_cast<std::size_t
>(k)]
502 os << lo <<
' ' << lo + len;
504 os <<
' ' << yCloud.box[
static_cast<std::size_t
>(k + 3)];
524 double xj,
double yj,
double zj) {
526 const auto &atom = yCloud.pts[
static_cast<std::size_t
>(iatom)];
527 const auto dr =
fracDelta(b, atom.x, atom.y, atom.z, xj, yj, zj);
528 const double r2 = dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
532#ifdef SEAMS_HAS_MINIMAGE
533 double ed[3] = {0.0, 0.0, 0.0};
534 if (euclideanDelta(yCloud, atom.x, atom.y, atom.z, xj, yj, zj, ed)) {
535 return {ed[0], ed[1], ed[2]};
539 const std::array<double, 3> raw = {atom.x - xj, atom.y - yj, atom.z - zj};
543 if (yCloud.box.size() >= 6) {
544 return triclinicMinImage(yCloud, yCloud.pts[
static_cast<std::size_t
>(iatom)].x, yCloud.pts[
static_cast<std::size_t
>(iatom)].y,
545 yCloud.pts[
static_cast<std::size_t
>(iatom)].z, xj, yj, zj);
548 std::array<double, 3> dr = {yCloud.pts[
static_cast<std::size_t
>(iatom)].x - xj, yCloud.pts[
static_cast<std::size_t
>(iatom)].y - yj,
549 yCloud.pts[
static_cast<std::size_t
>(iatom)].z - zj};
550 for (
int k = 0; k < 3; k++) {
551 if (dr[
static_cast<std::size_t
>(k)] < -yCloud.box[
static_cast<std::size_t
>(k)] * 0.5) {
552 dr[
static_cast<std::size_t
>(k)] += yCloud.box[
static_cast<std::size_t
>(k)];
554 if (dr[
static_cast<std::size_t
>(k)] >= yCloud.box[
static_cast<std::size_t
>(k)] * 0.5) {
555 dr[
static_cast<std::size_t
>(k)] -= yCloud.box[
static_cast<std::size_t
>(k)];
563 double xj,
double yj,
double zj) {
569 const std::vector<double> &singlePoint) {
573 return std::sqrt(dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2]);
589 std::array<double, 3> dr;
593 dr[0] = fabs(yCloud.pts[
static_cast<std::size_t
>(iatom)].x - yCloud.pts[
static_cast<std::size_t
>(jatom)].x);
594 dr[1] = fabs(yCloud.pts[
static_cast<std::size_t
>(iatom)].y - yCloud.pts[
static_cast<std::size_t
>(jatom)].y);
595 dr[2] = fabs(yCloud.pts[
static_cast<std::size_t
>(iatom)].z - yCloud.pts[
static_cast<std::size_t
>(jatom)].z);
598 for (
int k = 0; k < 3; k++) {
599 r2 += pow(dr[
static_cast<std::size_t
>(k)], 2.0);
616inline std::array<double, 3>
619 return relDistFromPoint(yCloud, iatom, yCloud.pts[
static_cast<std::size_t
>(jatom)].x,
620 yCloud.pts[
static_cast<std::size_t
>(jatom)].y, yCloud.pts[
static_cast<std::size_t
>(jatom)].z);
629 const auto dr =
relDist(yCloud, origin, atom);
630 const auto &o = yCloud.pts[
static_cast<std::size_t
>(origin)];
631 return {o.x - dr[0], o.y - dr[1], o.z - dr[2]};
650 std::string outFile);
655 int jatomIndex,
double *x_i,
double *y_i,
double *z_i,
double *x_j,
656 double *y_j,
double *z_j);
661 std::vector<double> quat2);
668inline std::vector<std::string>
tokenizer(std::string line) {
669 std::istringstream iss(line);
670 std::vector<std::string> tokens{std::istream_iterator<std::string>{iss},
671 std::istream_iterator<std::string>{}};
680 std::istringstream iss(line);
681 std::vector<double> tokens;
683 while (iss >> number) {
684 tokens.push_back(number);
694 std::istringstream iss(line);
695 std::vector<int> tokens;
697 while (iss >> number) {
698 tokens.push_back(number);
708 return std::filesystem::exists(name);
719inline std::vector<std::complex<double>>
720avgVector(std::vector<std::complex<double>> v,
int l,
int neigh) {
724 for (
int m = 0; m < 2 * l + 1; m++) {
725 v[
static_cast<std::size_t
>(m)] = (1.0 /
static_cast<double>(neigh)) * v[
static_cast<std::size_t
>(m)];
The main molecular system handler.
std::array< double, 3 > euclideanIfShorter(double lx, double ly, double lz, double xy, double xz, double yz, const std::array< double, 3 > &raw, const std::array< double, 3 > &wrapped)
Small generic functions that are shared by all namespaces.
double fracDistSq(const FracBox &b, double xi, double yi, double zi, double xj, double yj, double zj)
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 .
std::array< double, 3 > unwrappedXYZ(const molSys::PointCloud< molSys::Point< double >, double > &yCloud, int origin, int atom)
void writeDumpBoxBounds(std::ostream &os, const molSys::PointCloud< molSys::Point< double >, double > &yCloud)
std::array< double, 3 > relDistFromPoint(const FracBox &b, 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...
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)
FracBox makeFracBox(const molSys::PointCloud< molSys::Point< double >, double > &yCloud)
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 smithInside(const FracBox &b, double r2)
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.
std::array< double, 3 > fracDelta(const FracBox &b, double xi, double yi, double zi, double xj, double yj, double zj)
double periodicDistSq(const FracBox &b, 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 angDistDegQuaternions(std::vector< double > quat1, std::vector< double > quat2)
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)
This contains a collection of points; contains information for a particular frame.
This contains per-particle information.