seams-core v2.14.0
libyodaLib, the C++ engine of d-SEAMS
Loading...
Searching...
No Matches
generic.hpp
Go to the documentation of this file.
1//-----------------------------------------------------------------------------------
2// d-SEAMS - Deferred Structural Elucidation Analysis for Molecular Simulations
3//
4// Copyright (c) 2018--present d-SEAMS core team
5//
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the MIT License as published by
8// the Open Source Initiative.
9//
10// A copy of the MIT License is included in the LICENSE file of this repository.
11// You should have received a copy of the MIT License along with this program.
12// If not, see <https://opensource.org/licenses/MIT>.
13//-----------------------------------------------------------------------------------
14
15#ifndef SEAMS_GENERIC_H_
16#define SEAMS_GENERIC_H_
17
18#include <algorithm>
19#include <array>
20#include <cmath>
21#include <cstddef>
22#include <filesystem>
23#include <iostream>
24#include <sstream>
25#include <string>
26#include <vector>
27#include <mol_sys.hpp>
28
29#ifdef SEAMS_HAS_MINIMAGE
30#include <minimage.h>
31#else
32#include <euclidean_mic.hpp>
33#endif
34
35// C++20
36#include <numbers>
37// Eigen
38#include <Eigen/Core>
39#include <Eigen/Dense>
40
44
49
60
61namespace gen {
62
66constexpr double pi = std::numbers::pi;
67
73inline double radDeg(double angle) { return (angle * 180) / gen::pi; }
74
76double eigenVecAngle(std::vector<double> OO, std::vector<double> OH);
77
79double getAverageWithoutOutliers(std::vector<double> inpVec);
80
89inline double calcMedian(std::vector<double> *input) {
90 int n = static_cast<int>((*input).size()); // Number of elements
91 double median; // Output median value
92
93 // Sort a copy (avoid mutating input)
94 std::vector<double> sorted = *input;
95 std::sort(sorted.begin(), sorted.end());
96
97 // Calculate the median
98 // For even values, the median is the average of the two middle values
99 if (n % 2 == 0) {
100 median = 0.5 * (sorted[static_cast<std::size_t>(n / 2)] + sorted[static_cast<std::size_t>(n / 2 - 1)]);
101 } else {
102 median = sorted[static_cast<std::size_t>((n + 1) / 2 - 1)];
103 }
104
105 return median;
106}
107
108#ifdef SEAMS_HAS_MINIMAGE
109// Dump bound spans plus optional tilt onto an mi_cell.
110inline bool pointCloudCell(
111 const molSys::PointCloud<molSys::Point<double>, double> &yCloud,
112 mi_cell *out) {
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;
121 }
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]);
124 out->ox = xlo_b;
125 out->oy = ylo_b;
126 out->oz = zlo_b;
127 return true;
128 }
129 return false;
130}
131#endif
132
133// One dump box, recovered once per frame. Orthorhombic lengths are the
134// bound spans. A tilt dump stores those spans in box[0..2] and xy, xz, yz
135// in box[3..5]; lx, ly, lz are the recovered edge lengths, and wx, wy, wz
136// the separations of opposite faces, which tilt makes shorter.
137struct FracBox {
138 double lx = 0.0;
139 double ly = 0.0;
140 double lz = 0.0;
141 double xy = 0.0;
142 double xz = 0.0;
143 double yz = 0.0;
144 double ox = 0.0;
145 double oy = 0.0;
146 double oz = 0.0;
147 double wx = 0.0;
148 double wy = 0.0;
149 double wz = 0.0;
150 double halfMin = 0.0;
151 bool triclinic = false;
152 bool ok = false;
153};
154
155inline FracBox
157 FracBox b;
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;
173 b.lz = box[2];
174 b.xy = xy;
175 b.xz = xz;
176 b.yz = yz;
177 b.ox -= xmin;
178 b.oy -= ymin;
179 b.triclinic = true;
180 } else if (box.size() >= 3) {
181 b.lx = box[0];
182 b.ly = box[1];
183 b.lz = box[2];
184 } else {
185 return b;
186 }
187 if (!(b.lx > 0.0 && b.ly > 0.0 && b.lz > 0.0)) {
188 return b;
189 }
190 const double bcz = b.xy * b.yz - b.ly * b.xz;
191 b.wx = b.lx * b.ly * b.lz /
192 std::sqrt(b.ly * b.lz * b.ly * b.lz + b.xy * b.lz * b.xy * b.lz +
193 bcz * bcz);
194 b.wy = b.ly * b.lz / std::sqrt(b.lz * b.lz + b.yz * b.yz);
195 b.wz = b.lz;
196 b.halfMin = 0.5 * std::min(b.wx, std::min(b.wy, b.wz));
197 b.ok = true;
198 return b;
199}
200
201// Displacement from (xj, yj, zj) to (xi, yi, zi). Orthorhombic axes wrap
202// independently. A tilt box wraps the fractional difference and maps it
203// back through H. That vector is the Euclidean minimum image while its
204// length stays below half the shortest edge.
205inline std::array<double, 3> fracDelta(const FracBox &b, double xi, double yi,
206 double zi, double xj, double yj,
207 double zj) {
208 if (!b.triclinic) {
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);
214 }
215 return dr;
216 }
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,
230 b.lz * dsz};
231}
232
233inline double fracDistSq(const FracBox &b, double xi, double yi, double zi,
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];
237}
238
239// Smith, CCP5 1989: below half the narrowest face separation the fractional
240// wrap is the only lattice image in the ball, and every image inside that
241// ball is a fractional wrap. An orthorhombic wrap is that image on every
242// axis, including past half an edge.
243inline bool smithInside(const FracBox &b, double r2) {
244 return b.ok && (!b.triclinic || std::sqrt(r2) + 1e-12 < b.halfMin);
245}
246
247#ifdef SEAMS_HAS_MINIMAGE
248inline bool euclideanDelta(
249 const molSys::PointCloud<molSys::Point<double>, double> &yCloud, double xi,
250 double yi, double zi, double xj, double yj, double zj, double dr[3]) {
251 mi_cell cell;
252 if (!pointCloudCell(yCloud, &cell)) {
253 return false;
254 }
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;
258}
259
260// One frame on minimage's cell, built once, with the positions packed for
261// its batch kernels.
262struct CellFrame {
263 mi_cell cell{};
264 std::vector<double> xyz;
265 bool ok = false;
266};
267
268inline CellFrame
269makeCellFrame(const molSys::PointCloud<molSys::Point<double>, double> &yCloud) {
270 CellFrame f;
271 if (!pointCloudCell(yCloud, &f.cell)) {
272 return f;
273 }
274 const std::size_t n = yCloud.pts.size();
275 f.xyz.resize(3 * n);
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;
280 }
281 f.ok = true;
282 return f;
283}
284
285// Squared Euclidean minimum image from j to i on the frame's cell, or -1.
286inline double euclideanDistSq(const CellFrame &f, int i, int j) {
287 double dr[3];
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)],
290 dr) != 0) {
291 return -1.0;
292 }
293 return dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
294}
295#endif
296
297// Recover H (columns a, b, c) and origin from a LAMMPS dump box with the
298// same mapping as nneigh::lammpsBoxToLcCell: box[0..3] are bound spans,
299// box[3..6] are tilt factors xy, xz, yz, boxLow is the bound lo.
300inline std::array<double, 3> triclinicMinImage(
301 const molSys::PointCloud<molSys::Point<double>, double> &yCloud, double xi,
302 double yi, double zi, double xj, double yj, double zj) {
303 const FracBox b = makeFracBox(yCloud);
304 if (b.ok && b.triclinic) {
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];
307 if (smithInside(b, r2)) {
308 return dr;
309 }
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]};
314 }
315#endif
316 return dr;
317 }
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};
352}
353
354// Generic function for getting the unwrapped distance
364inline double
366 const molSys::PointCloud<molSys::Point<double>, double> &yCloud,
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)];
370 if (b.ok) {
371 const auto wrapped = fracDelta(b, atom.x, atom.y, atom.z, pj.x, pj.y, pj.z);
372 const double r2 =
373 wrapped[0] * wrapped[0] + wrapped[1] * wrapped[1] + wrapped[2] * wrapped[2];
374 if (smithInside(b, r2)) {
375 return r2;
376 }
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];
381 }
382 return r2;
383#else
384 const std::array<double, 3> raw = {atom.x - pj.x, atom.y - pj.y, atom.z - pj.z};
385 const auto euc = mic::euclideanIfShorter(b.lx, b.ly, b.lz, b.xy, b.xz, b.yz,
386 raw, wrapped);
387 return euc[0] * euc[0] + euc[1] * euc[1] + euc[2] * euc[2];
388#endif
389 }
390 if (yCloud.box.size() >= 6) {
391 const auto dr =
392 triclinicMinImage(yCloud, atom.x, atom.y, atom.z, pj.x, pj.y, pj.z);
393 return dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
394 }
395 std::array<double, 3> dr;
396 double r2 = 0.0;
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)];
406 }
407 return r2;
408}
409
410inline double
412 int iatom, int jatom) {
413 return periodicDistSq(makeFracBox(yCloud), yCloud, iatom, jatom);
414}
415
425inline double
427 int iatom, int jatom) {
428 return std::sqrt(periodicDistSq(yCloud, iatom, jatom));
429}
430
431// Tilt batches share one mi_cell. mi_dist2_many is the fractional
432// image for every candidate. A result outside the Smith ball is
433// replaced by the Euclidean image. Orthorhombic batches stay on
434// periodicDistSq; the Highway kernel is the ortho difference path.
436 const molSys::PointCloud<molSys::Point<double>, double> &yCloud, int iatom,
437 const int *jatom, std::size_t n, double *distSq) {
438 const FracBox b = makeFracBox(yCloud);
439#ifdef SEAMS_HAS_MINIMAGE
440 if (n > 0 && b.ok && b.triclinic) {
441 mi_cell cell;
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])];
448 qs[3 * k] = pj.x;
449 qs[3 * k + 1] = pj.y;
450 qs[3 * k + 2] = pj.z;
451 }
452 if (mi_dist2_many(&cell, p, qs.data(), n, distSq) == 0) {
453 for (std::size_t k = 0; k < n; ++k) {
454 if (smithInside(b, distSq[k])) {
455 continue;
456 }
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];
461 }
462 }
463 return;
464 }
465 }
466 }
467#endif
468 for (std::size_t k = 0; k < n; k++) {
469 distSq[k] = periodicDistSq(b, yCloud, iatom, jatom[k]);
470 }
471}
472
473// Bound spans, then tilt when box.size() >= 6.
474inline std::string formatDumpBox(const std::vector<double> &box) {
475 std::ostringstream oss;
476 if (box.size() >= 3) {
477 oss << box[0] << ' ' << box[1] << ' ' << box[2];
478 }
479 if (box.size() >= 6) {
480 oss << " xy " << box[3] << " xz " << box[4] << " yz " << box[5];
481 }
482 return oss.str();
483}
484
485// ITEM line plus three bound lines. Tilt is a third field per line.
487 std::ostream &os,
488 const molSys::PointCloud<molSys::Point<double>, double> &yCloud) {
489 const bool tilt = yCloud.box.size() >= 6;
490 if (tilt) {
491 os << "ITEM: BOX BOUNDS xy xz yz pp pp pp\n";
492 } else {
493 os << "ITEM: BOX BOUNDS pp pp pp\n";
494 }
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)]
498 : 0.0;
499 const double len = (static_cast<std::size_t>(k) < yCloud.box.size())
500 ? yCloud.box[static_cast<std::size_t>(k)]
501 : 0.0;
502 os << lo << ' ' << lo + len;
503 if (tilt) {
504 os << ' ' << yCloud.box[static_cast<std::size_t>(k + 3)];
505 }
506 os << '\n';
507 }
508}
509
521inline std::array<double, 3> relDistFromPoint(
522 const FracBox &b,
523 const molSys::PointCloud<molSys::Point<double>, double> &yCloud, int iatom,
524 double xj, double yj, double zj) {
525 if (b.ok) {
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];
529 if (smithInside(b, r2)) {
530 return dr;
531 }
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]};
536 }
537 return dr;
538#else
539 const std::array<double, 3> raw = {atom.x - xj, atom.y - yj, atom.z - zj};
540 return mic::euclideanIfShorter(b.lx, b.ly, b.lz, b.xy, b.xz, b.yz, raw, dr);
541#endif
542 }
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);
546 }
547
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)];
553 }
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)];
556 }
557 }
558 return dr;
559}
560
561inline std::array<double, 3> relDistFromPoint(
562 const molSys::PointCloud<molSys::Point<double>, double> &yCloud, int iatom,
563 double xj, double yj, double zj) {
564 return relDistFromPoint(makeFracBox(yCloud), yCloud, iatom, xj, yj, zj);
565}
566
568 const molSys::PointCloud<molSys::Point<double>, double> &yCloud, int iatom,
569 const std::vector<double> &singlePoint) {
570 const auto dr =
571 relDistFromPoint(yCloud, iatom, singlePoint[0], singlePoint[1],
572 singlePoint[2]);
573 return std::sqrt(dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2]);
574}
575
576// Generic function for getting the distance (no PBCs applied)
586inline double
587distance(const molSys::PointCloud<molSys::Point<double>, double> &yCloud, int iatom,
588 int jatom) {
589 std::array<double, 3> dr;
590 double r2 = 0.0; // Squared absolute distance
591
592 // Get x1-x2 etc
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);
596
597 // Get the squared absolute distance
598 for (int k = 0; k < 3; k++) {
599 r2 += pow(dr[static_cast<std::size_t>(k)], 2.0);
600 }
601
602 return sqrt(r2);
603}
604
605// Generic function for getting the relative coordinates
616inline std::array<double, 3>
617relDist(const molSys::PointCloud<molSys::Point<double>, double> &yCloud, int iatom,
618 int jatom) {
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);
621}
622
623// The image of atom nearest origin. relDist(i, j) is wrap(i - j), so that
624// image is origin - relDist(origin, atom). A ring or cage unwrapped this
625// way keeps one origin, which a per-edge minimum image does not.
626inline std::array<double, 3> unwrappedXYZ(
627 const molSys::PointCloud<molSys::Point<double>, double> &yCloud, int origin,
628 int atom) {
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]};
632}
633
634// Function for sorting according to atom ID
635// Comparator for std::sort
644 const molSys::Point<double> &b) {
645 return a.atomID < b.atomID;
646}
647
649[[nodiscard]] int prettyPrintYoda(const molSys::PointCloud<molSys::Point<double>, double> &yCloud,
650 std::string outFile);
651
653[[nodiscard]] int unwrappedCoordShift(
654 const molSys::PointCloud<molSys::Point<double>, double> &yCloud, int iatomIndex,
655 int jatomIndex, double *x_i, double *y_i, double *z_i, double *x_j,
656 double *y_j, double *z_j);
657
660double angDistDegQuaternions(std::vector<double> quat1,
661 std::vector<double> quat2);
662
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>{}};
672 return tokens;
673}
674
679inline std::vector<double> tokenizerDouble(std::string line) {
680 std::istringstream iss(line);
681 std::vector<double> tokens;
682 double number; // Each number being read in from the line
683 while (iss >> number) {
684 tokens.push_back(number);
685 }
686 return tokens;
687}
688
693inline std::vector<int> tokenizerInt(std::string line) {
694 std::istringstream iss(line);
695 std::vector<int> tokens;
696 int number; // Each number being read in from the line
697 while (iss >> number) {
698 tokens.push_back(number);
699 }
700 return tokens;
701}
702
707inline bool file_exists(const std::string &name) {
708 return std::filesystem::exists(name);
709}
710
719inline std::vector<std::complex<double>>
720avgVector(std::vector<std::complex<double>> v, int l, int neigh) {
721 if (neigh == 0) {
722 return v;
723 }
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)];
726 }
727
728 return v;
729}
730
731} // namespace gen
732
734#endif // SEAMS_GENERIC_H_
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)
Definition generic.hpp:233
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...
Definition generic.hpp:587
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 .
Definition generic.hpp:720
std::array< double, 3 > unwrappedXYZ(const molSys::PointCloud< molSys::Point< double >, double > &yCloud, int origin, int atom)
Definition generic.hpp:626
void writeDumpBoxBounds(std::ostream &os, const molSys::PointCloud< molSys::Point< double >, double > &yCloud)
Definition generic.hpp:486
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...
Definition generic.hpp:521
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...
Definition generic.hpp:617
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,...
Definition generic.hpp:426
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.
Definition generic.hpp:89
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:300
std::string formatDumpBox(const std::vector< double > &box)
Definition generic.hpp:474
FracBox makeFracBox(const molSys::PointCloud< molSys::Point< double >, double > &yCloud)
Definition generic.hpp:156
std::vector< double > tokenizerDouble(std::string line)
Function for tokenizing line strings into a vector of doubles.
Definition generic.hpp:679
constexpr double pi
Uses Boost to get the value of pi.
Definition generic.hpp:66
bool smithInside(const FracBox &b, double r2)
Definition generic.hpp:243
bool file_exists(const std::string &name)
Function for checking if a file exists or not.
Definition generic.hpp:707
std::vector< std::string > tokenizer(std::string line)
Function for tokenizing line strings into words (strings) delimited by whitespace.
Definition generic.hpp:668
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)
Definition generic.hpp:205
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,...
Definition generic.hpp:365
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)
Definition generic.hpp:435
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.
Definition generic.hpp:693
double radDeg(double angle)
Inline function for converting radians->degrees.
Definition generic.hpp:73
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...
Definition generic.hpp:643
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)
Definition generic.hpp:567
double halfMin
Definition generic.hpp:150
This contains a collection of points; contains information for a particular frame.
Definition mol_sys.hpp:173
This contains per-particle information.
Definition mol_sys.hpp:152