seams-core v2.14.0
libyodaLib, the C++ engine of d-SEAMS
Loading...
Searching...
No Matches
seams Namespace Reference

Namespaces

namespace  cfg
namespace  cpu
namespace  detail
namespace  domain
namespace  minimax
namespace  product
namespace  solid
namespace  sphericart_ylm
namespace  steinhardt
namespace  tsan
namespace  wigner
namespace  ylm

Classes

struct  BondOptions
 Knobs for a hydrogen-bond count. More...
class  Brine
 Owned planar ice-front measurement. More...
struct  BrineFronts
 The two planar crossings of an ice slab. More...
struct  BrineOptions
 Knobs for a planar ice front. More...
struct  BrineProfile
 Concentration profile along the brine axis. More...
struct  CageCounts
 Disjoint cage populations. More...
struct  CageOptions
 Knobs for hexagonal and double-diamond cages. More...
class  Cages
 Owned hexagonal and double-diamond membership. More...
struct  ChillOptions
 Knobs for CHILL and CHILL+. More...
struct  ChordlessCycles
 Chordless cycles of one length. More...
struct  Classification
 CHILL or CHILL+ labels and the nine population counts. More...
struct  Contacts
 Mutual nearest unlike contacts of a site table. More...
struct  DensityOptions
 Knobs for the axial number density. More...
struct  DensityProfile
 Number density along one cell axis. More...
struct  Distribution
 Partial radial distribution. More...
struct  DistributionOptions
 Knobs for a partial RDF, its running coordination, or the integral. More...
struct  DomainOptions
 Knobs for a domain search. More...
struct  DomainReport
 Largest polar or apolar domain. More...
struct  EdgeSet
class  Error
 Failure from the C API, or from a rejected argument. More...
struct  FairState
class  FairWidth
class  Fingerprint
 Owned topological fingerprint. More...
struct  FingerprintOptions
 Knobs for a topological fingerprint. More...
struct  KnnOptions
 Knobs for a k-nearest neighbour list. More...
struct  NeighbourOptions
 Knobs for a neighbour list. More...
class  Neighbours
 Owned neighbour list. More...
struct  OrderOptions
 Knobs for q_l on a named graph. More...
struct  Pockets
 Brine pockets trapped in the ice. More...
struct  PrismCensus
 Perfect and imperfect prism counts by ring size. More...
struct  PrismOptions
 Knobs for prism stacks. More...
struct  Q4Q6
 Local q4 and q6 on the cutoff shell. More...
struct  Q6Bar
 Lechner-Dellago q6-bar and the ice count above a cut. More...
struct  Q6BarOptions
 Knobs for the q6-bar ice summary. More...
struct  Rejection
 Molal rejection coefficient. More...
struct  RingOptions
 Knobs for primitive rings. More...
class  Rings
 Owned primitive-ring set. More...
struct  RunningCoordination
 Running coordination number along a partial RDF. More...
struct  SheetOptions
 Knobs for a monolayer ring histogram. More...
struct  SignatureMatch
 Closed cages whose ring census matches a signature. More...
struct  SignatureOptions
 Knobs for a signature cage census. More...
struct  Steinhardt
 Local Steinhardt parameter, and the average when it was asked for. More...
struct  SteinhardtOptions
 Knobs for a local Steinhardt parameter on the cutoff shell. More...
class  System
 One frame: coordinates, a cell, and the analyses that read them. More...
struct  TeamWidth

Enumerations

enum class  Status : int {
  Status::Ok = SEAMS_OK , Status::Null = SEAMS_ERR_NULL , Status::Range = SEAMS_ERR_RANGE , Status::Cell = SEAMS_ERR_BOX ,
  Status::Argument = SEAMS_ERR_ARG , Status::State = SEAMS_ERR_STATE , Status::Memory = SEAMS_ERR_NOMEM , Status::Internal = SEAMS_ERR_INTERNAL
}
 Status codes. More...
enum class  Graph : int { Graph::Cutoff = SEAMS_GRAPH_CUTOFF , Graph::Mutual = SEAMS_GRAPH_MUTUAL , Graph::Seeded = SEAMS_GRAPH_SEEDED }
 Neighbour graph. More...
enum class  ChillRule : int { ChillRule::Published = SEAMS_CHILL_PUBLISHED , ChillRule::Ovito = SEAMS_CHILL_OVITO }
 CHILL+ threshold table. More...
enum class  Label : int {
  Label::Cubic = SEAMS_LABEL_CUBIC , Label::Hexagonal = SEAMS_LABEL_HEXAGONAL , Label::Water = SEAMS_LABEL_WATER , Label::Interfacial = SEAMS_LABEL_INTERFACIAL ,
  Label::Clathrate = SEAMS_LABEL_CLATHRATE , Label::Interclathrate = SEAMS_LABEL_INTERCLATHRATE , Label::Unclassified = SEAMS_LABEL_UNCLASSIFIED , Label::Recubic = SEAMS_LABEL_RECUBIC ,
  Label::Rehex = SEAMS_LABEL_REHEX
}
 CHILL and CHILL+ atom label. More...
enum class  RingSymmetry : int {
  RingSymmetry::Unclassified = SEAMS_RING_UNCLASSIFIED , RingSymmetry::Ddc = SEAMS_RING_DDC , RingSymmetry::HcBasal = SEAMS_RING_HC_BASAL , RingSymmetry::HcPrismatic = SEAMS_RING_HC_PRISMATIC ,
  RingSymmetry::BothBasal = SEAMS_RING_BOTH_BASAL , RingSymmetry::BothPrismatic = SEAMS_RING_BOTH_PRISMATIC , RingSymmetry::Prism = SEAMS_RING_PRISM , RingSymmetry::DeformedPrism = SEAMS_RING_DEFORMED_PRISM ,
  RingSymmetry::MixedPrism = SEAMS_RING_MIXED_PRISM , RingSymmetry::Pentagon = SEAMS_RING_PENTAGON , RingSymmetry::Hexagon = SEAMS_RING_HEXAGON , RingSymmetry::Other = SEAMS_RING_OTHER
}
 Primitive-ring symmetry class. More...
enum class  CageLabel : int { CageLabel::Water = SEAMS_CAGE_WATER , CageLabel::Hex = SEAMS_CAGE_HEX , CageLabel::Cubic = SEAMS_CAGE_CUBIC , CageLabel::Both = SEAMS_CAGE_BOTH }
 Per-atom cage membership. More...
enum class  SiteKind : int {
  SiteKind::Unspecified = SEAMS_SITE_UNSPECIFIED , SiteKind::Cation = SEAMS_SITE_CATION , SiteKind::Anion = SEAMS_SITE_ANION , SiteKind::Tail = SEAMS_SITE_TAIL ,
  SiteKind::DonorH = SEAMS_SITE_DONOR_H , SiteKind::Acceptor = SEAMS_SITE_ACCEPTOR , SiteKind::Polar = SEAMS_SITE_POLAR , SiteKind::Apolar = SEAMS_SITE_APOLAR ,
  SiteKind::WaterO = SEAMS_SITE_WATER_O , SiteKind::WaterH = SEAMS_SITE_WATER_H , SiteKind::Solvent = SEAMS_SITE_SOLVENT
}
 Site-table kind. More...
enum class  Axis : int { Axis::X = 0 , Axis::Y = 1 , Axis::Z = 2 }
 Cell axis. More...
enum class  DomainSubset : int { DomainSubset::Apolar = 0 , DomainSubset::Polar = 1 }
 Domain subset. More...

Functions

EdgeSet edgeSetOf (const std::vector< std::vector< int > > &rows)
bool provenEqual (const EdgeSet &a, const EdgeSet &b)
template<std::integral To, std::integral From>
constexpr To checkedCast (From value)
template<std::integral From>
constexpr std::size_t toIndex (From value)
bool gridFits (int nx, int ny, int nz, int &cells)
void coarsenUntilFits (int &nx, int &ny, int &nz, int floorDim, int maxCells=1<< 22)
bool prefixCounts (const int *counts, int n, std::vector< int > &offsets)
bool parseExactDouble (std::string_view text, double &out)
int teamThreads ()
template<class T>
void exclusiveScan (std::vector< T > &values)
template<class T, class Less>
void parallelStableSort (std::vector< T > &values, Less less)
void BatchPeriodicDistSq (const double *dx, const double *dy, const double *dz, double bx, double by, double bz, double *out, size_t n)
void widenAffinity ()
void releaseTeam ()
void prepareCompute ()
void adoptThreads ()
int teamFor (int n)
FairState & fairState ()
bool fairEnabled ()
std::string version ()
 Library version text, for example 2.14.0.
int abi ()
 ABI number compiled into this library.
void set_num_threads (int n)
 Set the OpenMP width for the next call.
int num_threads ()
 OpenMP width the next call will use.
std::size_t nframes (std::string_view path)
 Count frames in a trajectory path.
std::string_view label_name (Label label)
 Short name of a CHILL+ label.
std::string_view ring_symmetry_name (RingSymmetry symmetry)
 Short name of a ring-symmetry code.

Function Documentation

◆ adoptThreads()

void seams::adoptThreads ( )
inline

Definition at line 97 of file thread_team.hpp.

97 {
98 // Record the Rayon width and leave the OpenMP team running. Pausing
99 // it, or forcing a passive wait, made the next region late by tens of
100 // milliseconds. The pool sleeps on its own condvar between searches.
102#ifdef SEAMS_HAS_OPENMP
103 if (omp_in_parallel()) {
104#ifdef SEAMS_HAS_LINKCELL
106#endif
107 return;
108 }
109 int n = omp_get_max_threads();
110#else
111 int n = 1;
112#endif
113 if (n < 1) {
114 n = 1;
115 }
116#ifdef SEAMS_HAS_LINKCELL
118#else
119 (void)n;
120#endif
121}
void prepareCompute()
void lc_set_threads(int n)

◆ BatchPeriodicDistSq()

void seams::BatchPeriodicDistSq ( const double * dx,
const double * dy,
const double * dz,
double bx,
double by,
double bz,
double * out,
size_t n )
inline

Definition at line 102 of file simd_distance.hpp.

104 {
105#ifdef SEAMS_HAS_MINIMAGE
106 if (mi_dist2_ortho_diffs(dx, dy, dz, bx, by, bz, out, n) == 0) {
107 return;
108 }
109#endif
110 // Matches the vectorised path: one reciprocal per axis for the whole batch
111 const double rbx = 1.0 / bx;
112 const double rby = 1.0 / by;
113 const double rbz = 1.0 / bz;
114 for (size_t i = 0; i < n; i++) {
115 double ddx = std::fabs(dx[i]);
116 double ddy = std::fabs(dy[i]);
117 double ddz = std::fabs(dz[i]);
118 ddx -= bx * std::round(ddx * rbx);
119 ddy -= by * std::round(ddy * rby);
120 ddz -= bz * std::round(ddz * rbz);
121 out[i] = ddx * ddx + ddy * ddy + ddz * ddz;
122 }
123}

◆ checkedCast()

template<std::integral To, std::integral From>
To seams::checkedCast ( From value)
constexpr

Definition at line 18 of file index_cast.hpp.

18 {
19 if (!std::in_range<To>(value)) {
20 throw std::out_of_range("integer value out of range for its target type");
21 }
22 return static_cast<To>(value);
23}

◆ coarsenUntilFits()

void seams::coarsenUntilFits ( int & nx,
int & ny,
int & nz,
int floorDim,
int maxCells = 1 << 22 )
inline

Definition at line 33 of file index_range.hpp.

34 {
35 if (floorDim < 1) {
36 floorDim = 1;
37 }
38 if (maxCells < 1) {
39 maxCells = 1;
40 }
41 int cells = 0;
42 while (!gridFits(nx, ny, nz, cells) || cells > maxCells) {
43 int *axis = &nx;
44 if (ny > *axis) {
45 axis = &ny;
46 }
47 if (nz > *axis) {
48 axis = &nz;
49 }
50 if (*axis <= floorDim) {
51 return;
52 }
53 --(*axis);
54 }
55}
bool gridFits(int nx, int ny, int nz, int &cells)

◆ edgeSetOf()

EdgeSet seams::edgeSetOf ( const std::vector< std::vector< int > > & rows)
inline

Definition at line 80 of file edge_set.hpp.

80 {
81 EdgeSet out;
82 const int nRows = static_cast<int>(rows.size());
83 bool parallel = false;
84#ifdef SEAMS_HAS_OPENMP
85 parallel = nRows >= 4096 && omp_get_max_threads() > 1 && !omp_in_parallel();
86#endif
87 if (parallel) {
88#ifdef SEAMS_HAS_OPENMP
89 const int team = omp_get_max_threads();
90 std::vector<std::vector<std::pair<int, int>>> parts(
91 static_cast<std::size_t>(team));
92#pragma omp parallel
93 {
94 std::vector<std::pair<int, int>> local;
95#pragma omp for schedule(static)
96 for (int i = 0; i < nRows; ++i) {
97 const auto &row = rows[static_cast<std::size_t>(i)];
98 for (std::size_t k = 1; k < row.size(); ++k) {
99 const int j = row[k];
100 if (j < 0 || j == i) {
101 continue;
102 }
103 local.emplace_back(std::min(i, j), std::max(i, j));
104 }
105 }
106 parts[static_cast<std::size_t>(omp_get_thread_num())] = std::move(local);
107 }
108 std::size_t total = 0;
109 for (const auto &part : parts) {
110 total += part.size();
111 }
112 out.edges.reserve(total);
113 for (auto &part : parts) {
114 out.edges.insert(out.edges.end(), part.begin(), part.end());
115 }
116#endif
117 } else {
118 for (int i = 0; i < nRows; ++i) {
119 const auto &row = rows[static_cast<std::size_t>(i)];
120 for (std::size_t k = 1; k < row.size(); ++k) {
121 const int j = row[k];
122 if (j < 0 || j == i) {
123 continue;
124 }
125 out.edges.emplace_back(std::min(i, j), std::max(i, j));
126 }
127 }
128 }
129 sortEdgePairs(out.edges);
130 out.edges.erase(std::unique(out.edges.begin(), out.edges.end()), out.edges.end());
131 hashEdges(out);
132 return out;
133}
std::vector< std::pair< int, int > > edges
Definition edge_set.hpp:21

◆ exclusiveScan()

template<class T>
void seams::exclusiveScan ( std::vector< T > & values)

Definition at line 28 of file par_team.hpp.

28 {
29 const int n = static_cast<int>(values.size());
30 const int threads = teamThreads();
31 if (threads <= 1 || n < threads * 2) {
32 T sum = 0;
33 for (int i = 0; i < n; i++) {
34 const T current = values[static_cast<std::size_t>(i)];
35 values[static_cast<std::size_t>(i)] = sum;
36 sum += current;
37 }
38 return;
39 }
40 const int chunk = (n + threads - 1) / threads;
41 std::vector<T> block(static_cast<std::size_t>(threads), 0);
42#ifdef SEAMS_HAS_OPENMP
43#pragma omp parallel
44#endif
45 {
46#ifdef SEAMS_HAS_OPENMP
47 const int tid = omp_get_thread_num();
48#else
49 const int tid = 0;
50#endif
51 const int lo = tid * chunk;
52 const int hi = std::min(n, lo + chunk);
53 T sum = 0;
54 for (int i = lo; i < hi; i++) {
55 sum += values[static_cast<std::size_t>(i)];
56 }
57 if (tid < threads) {
58 block[static_cast<std::size_t>(tid)] = sum;
59 }
60 }
61 T carried = 0;
62 for (int tid = 0; tid < threads; tid++) {
63 const T sum = block[static_cast<std::size_t>(tid)];
64 block[static_cast<std::size_t>(tid)] = carried;
65 carried += sum;
66 }
67#ifdef SEAMS_HAS_OPENMP
68#pragma omp parallel
69#endif
70 {
71#ifdef SEAMS_HAS_OPENMP
72 const int tid = omp_get_thread_num();
73#else
74 const int tid = 0;
75#endif
76 const int lo = tid * chunk;
77 const int hi = std::min(n, lo + chunk);
78 T sum = block[static_cast<std::size_t>(tid)];
79 for (int i = lo; i < hi; i++) {
80 const T current = values[static_cast<std::size_t>(i)];
81 values[static_cast<std::size_t>(i)] = sum;
82 sum += current;
83 }
84 }
85}
int teamThreads()
Definition par_team.hpp:15

◆ fairEnabled()

bool seams::fairEnabled ( )
inline

Definition at line 238 of file thread_team.hpp.

238 {
239 static const bool on = [] {
240 const char *flag = std::getenv("SEAMS_FAIR_WIDTH");
241 return flag == nullptr || std::strcmp(flag, "0") != 0;
242 }();
243 return on;
244}

◆ fairState()

FairState & seams::fairState ( )
inline

Definition at line 233 of file thread_team.hpp.

233 {
234 static FairState state;
235 return state;
236}

◆ gridFits()

bool seams::gridFits ( int nx,
int ny,
int nz,
int & cells )
inline

Definition at line 15 of file index_range.hpp.

15 {
16 if (nx <= 0 || ny <= 0 || nz <= 0) {
17 return false;
18 }
19 const std::int64_t prod = std::int64_t{nx} * ny * nz;
20 if (prod > std::numeric_limits<int>::max()) {
21 return false;
22 }
23 cells = static_cast<int>(prod);
24 return true;
25}

◆ parallelStableSort()

template<class T, class Less>
void seams::parallelStableSort ( std::vector< T > & values,
Less less )

Definition at line 90 of file par_team.hpp.

90 {
91 const int n = static_cast<int>(values.size());
92 const int threads = teamThreads();
93 if (threads <= 1 || n < threads * 2) {
94 std::stable_sort(values.begin(), values.end(), less);
95 return;
96 }
97 const int chunk = (n + threads - 1) / threads;
98#ifdef SEAMS_HAS_OPENMP
99#pragma omp parallel for schedule(static)
100#endif
101 for (int tid = 0; tid < threads; tid++) {
102 const int lo = tid * chunk;
103 const int hi = std::min(n, lo + chunk);
104 if (hi - lo > 1) {
105 std::stable_sort(values.begin() + lo, values.begin() + hi, less);
106 }
107 }
108 std::vector<T> buffer(values.size());
109 T *src = values.data();
110 T *dst = buffer.data();
111 for (int width = chunk; width < n; width *= 2) {
112#ifdef SEAMS_HAS_OPENMP
113#pragma omp parallel for schedule(static)
114#endif
115 for (int start = 0; start < n; start += width * 2) {
116 const int mid = std::min(n, start + width);
117 const int stop = std::min(n, start + width * 2);
118 int i = start;
119 int j = mid;
120 int k = start;
121 while (i < mid && j < stop) {
122 if (less(src[j], src[i])) {
123 dst[k++] = src[j++];
124 } else {
125 dst[k++] = src[i++];
126 }
127 }
128 while (i < mid) {
129 dst[k++] = src[i++];
130 }
131 while (j < stop) {
132 dst[k++] = src[j++];
133 }
134 }
135 std::swap(src, dst);
136 }
137 if (src != values.data()) {
138 std::copy(src, src + n, values.begin());
139 }
140}

◆ parseExactDouble()

bool seams::parseExactDouble ( std::string_view text,
double & out )
inline

Definition at line 18 of file number_parse.hpp.

18 {
19 if (text.empty() || text.front() == '+') {
20 return false;
21 }
22 for (char raw : text) {
23 const auto c = static_cast<unsigned char>(raw);
24 if (raw == 'x' || raw == 'X' || c == ' ' || c == '\t' || c == '\n' ||
25 c == '\v' || c == '\f' || c == '\r') {
26 return false;
27 }
28 }
29#if defined(_WIN32)
30 // MinGW and MSVC spell the C-locale converter this way. newlocale
31 // is not in their headers. The grammar stays the one strtod_l uses.
32 static const _locale_t loc = _create_locale(LC_ALL, "C");
33 if (loc == nullptr) {
34 return false;
35 }
36#else
37 static const locale_t loc =
38 newlocale(LC_ALL_MASK, "C", static_cast<locale_t>(nullptr));
39 if (loc == static_cast<locale_t>(nullptr)) {
40 return false;
41 }
42#endif
43 const std::string token(text);
44 char *end = nullptr;
45 errno = 0;
46#if defined(_WIN32)
47 const double value = _strtod_l(token.c_str(), &end, loc);
48#else
49 const double value = strtod_l(token.c_str(), &end, loc);
50#endif
51 if (end != token.c_str() + token.size()) {
52 return false;
53 }
54 if (errno == ERANGE && (value == 0.0 || !std::isfinite(value))) {
55 return false;
56 }
57 out = value;
58 return true;
59}

◆ prefixCounts()

bool seams::prefixCounts ( const int * counts,
int n,
std::vector< int > & offsets )
inline

Definition at line 60 of file index_range.hpp.

60 {
61 if (n < 0 || (n > 0 && counts == nullptr)) {
62 return false;
63 }
64 offsets.assign(static_cast<std::size_t>(n) + 1, 0);
65 std::int64_t sum = 0;
66 for (int i = 0; i < n; ++i) {
67 if (counts[i] < 0) {
68 return false;
69 }
70 sum += counts[i];
71 if (sum > std::numeric_limits<int>::max()) {
72 return false;
73 }
74 offsets[static_cast<std::size_t>(i) + 1] = static_cast<int>(sum);
75 }
76 return true;
77}

◆ prepareCompute()

void seams::prepareCompute ( )
inline

Definition at line 86 of file thread_team.hpp.

86 {
87 // Linkcell sleeps between searches. Forcing a passive OpenMP wait
88 // on top of that made the next region late by tens of milliseconds,
89 // which dominated a k-nearest call of about a millisecond. Leave the
90 // wait policy the process was started with.
92#ifdef SEAMS_HAS_OPENMP
93 omp_set_dynamic(0);
94#endif
95}
void widenAffinity()

◆ provenEqual()

bool seams::provenEqual ( const EdgeSet & a,
const EdgeSet & b )
inline

Definition at line 135 of file edge_set.hpp.

135 {
136 if (a.hash != b.hash) {
137 return false;
138 }
139 return a.edges == b.edges;
140}
std::uint64_t hash
Definition edge_set.hpp:20

◆ releaseTeam()

void seams::releaseTeam ( )
inline

Definition at line 75 of file thread_team.hpp.

75 {
76#ifdef SEAMS_HAS_OPENMP
77 omp_pause_resource_all(omp_pause_soft);
78#endif
79}

◆ teamFor()

int seams::teamFor ( int n)
inline

Definition at line 126 of file thread_team.hpp.

126 {
127#ifdef SEAMS_HAS_OPENMP
128 (void)n;
129 return std::max(1, omp_get_max_threads());
130#else
131 (void)n;
132 return 1;
133#endif
134}

◆ teamThreads()

int seams::teamThreads ( )
inline

Definition at line 15 of file par_team.hpp.

15 {
16#ifdef SEAMS_HAS_OPENMP
17 if (omp_in_parallel()) {
18 return 1;
19 }
20 const int n = omp_get_max_threads();
21 return n > 0 ? n : 1;
22#else
23 return 1;
24#endif
25}

◆ toIndex()

template<std::integral From>
std::size_t seams::toIndex ( From value)
constexpr

Definition at line 25 of file index_cast.hpp.

25 {
26 return checkedCast<std::size_t>(value);
27}
constexpr To checkedCast(From value)

◆ widenAffinity()

void seams::widenAffinity ( )
inline

Definition at line 40 of file thread_team.hpp.

40 {
41#if defined(__linux__) && defined(SEAMS_HAS_OPENMP)
42 static std::mutex lock;
43 static bool done = false;
44 if (omp_in_parallel() || omp_get_max_threads() < 2 || omp_get_place_num() < 0) {
45 return;
46 }
47 const std::lock_guard<std::mutex> hold(lock);
48 if (done) {
49 return;
50 }
51 done = true;
52 cpu_set_t mask;
53 CPU_ZERO(&mask);
54 if (sched_getaffinity(0, sizeof(mask), &mask) != 0) {
55 return;
56 }
57 const int places = omp_get_num_places();
58 for (int place = 0; place < places; ++place) {
59 const int count = omp_get_place_num_procs(place);
60 if (count <= 0) {
61 continue;
62 }
63 std::vector<int> ids(static_cast<std::size_t>(count));
64 omp_get_place_proc_ids(place, ids.data());
65 for (const int cpu : ids) {
66 if (cpu >= 0 && cpu < CPU_SETSIZE) {
67 CPU_SET(static_cast<std::size_t>(cpu), &mask);
68 }
69 }
70 }
71 sched_setaffinity(0, sizeof(mask), &mask);
72#endif
73}