seams-core v2.15.0
libyodaLib, the C++ engine of d-SEAMS
Loading...
Searching...
No Matches
smooth_cv.hpp
Go to the documentation of this file.
1//-----------------------------------------------------------------------------------
2// d-SEAMS - Deferred Structural Elucidation Analysis for Molecular Simulations
3//
4// Copyright (c) d-SEAMS developers
5// SPDX-License-Identifier: MIT
6//
7// This program is free software: you can redistribute it and/or modify
8// it under the terms of the MIT License as published by
9// the Open Source Initiative.
10//
11// A copy of the MIT License is included in the LICENSE file of this repository.
12// You should have received a copy of the MIT License along with this program.
13// If not, see <https://opensource.org/licenses/MIT>.
14//-----------------------------------------------------------------------------------
15
16#ifndef SEAMS_SMOOTH_CV_H_
17#define SEAMS_SMOOTH_CV_H_
18
19#include <array>
20#include <cstddef>
21#include <cstdint>
22#include <vector>
23
24#include <mol_sys.hpp>
25
29
34
67namespace smooth {
68
70
74inline constexpr int kMaxSwitchExponent = 4096;
75
78inline constexpr double kFlatEigenRatio = 1e-10;
79
83inline constexpr std::int64_t kMaxRingSearchSteps = 20000000;
84
87inline constexpr int kMaxCandidateRings = 2000000;
88
91inline constexpr std::int64_t kMaxShortcutSearchSteps = 20000000;
92
95inline constexpr int kMaxShortcutPaths = 2000000;
96
110 double r0 = 1.0;
111 double d0 = 0.0;
112 int n = 6;
113 int m = 12;
114 double dOn = 0.0;
115 double dMax = 1.0;
116
121 void validate() const;
122
126 double operator()(double r, double &dsdr) const;
127};
128
131RationalSwitch makeSwitch(double r0, double d0, int n, int m, double dOn,
132 double dMax);
133
144struct Topology {
145 int nAtoms = 0;
146 int maxRing = 0;
147 std::vector<std::array<int, 2>> edges;
148 std::vector<int> adjOff;
149 std::vector<int> adjAtom;
150 std::vector<int> adjEdge;
151 std::vector<int> ringOff{0};
152 std::vector<int> ringAtoms;
153 std::vector<int> ringEdges;
154 std::vector<int> pathOff{0};
155 std::vector<int> pathEdgeOff{0};
156 std::vector<int> pathEdges;
157
161 struct HexPair {
162 int a = 0;
163 int b = 0;
164 std::array<int, 36> bond{};
165 };
166 std::vector<HexPair> hexPairs;
167
168 [[nodiscard]] int ringCount() const { return static_cast<int>(ringOff.size()) - 1; }
169 [[nodiscard]] int ringSize(int k) const {
170 return ringOff[static_cast<std::size_t>(k) + 1] - ringOff[static_cast<std::size_t>(k)];
171 }
172
173 [[nodiscard]] int edgeOf(int i, int j) const;
174};
175
182Topology buildTopology(const std::vector<std::vector<int>> &rows, int maxRing);
183
185std::vector<double> ringWeights(const Topology &topo, const std::vector<double> &s);
186
188void ringWeightsAdjoint(const Topology &topo, const std::vector<double> &s,
189 const std::vector<double> &wbar, std::vector<double> &sbar);
190
194double hexBasalPairs(const Topology &topo, const std::vector<double> &s,
195 const std::vector<double> &w, std::vector<double> *sbar,
196 std::vector<double> *wbar);
197
200std::vector<double> ringParticipation(const Topology &topo, const std::vector<double> &w,
201 int size);
202
204void ringParticipationAdjoint(const Topology &topo, const std::vector<double> &w, int size,
205 const std::vector<double> &pbar, std::vector<double> &wbar);
206
218
229public:
231
238 void rebuild(const Cloud &cloud, std::vector<int> selected, double skin);
239
240 [[nodiscard]] bool built() const { return built_; }
241 [[nodiscard]] bool stale(const Cloud &cloud) const;
242 [[nodiscard]] const Topology &topology() const { return topo_; }
243 [[nodiscard]] const RationalSwitch &switching() const { return sw_; }
244 [[nodiscard]] int maxRing() const { return maxRing_; }
245 [[nodiscard]] int stateCount() const { return static_cast<int>(states_.size()); }
246
249 void checkKind(Kind kind, int arg) const;
250
255 double value(const Cloud &cloud, Kind kind, int arg, double *grad);
256
261 void addClause(int state, Kind kind, int arg, double threshold, double width, bool above);
262
266 void states(const Cloud &cloud, double *chi, double *grad);
267
268private:
269 struct Clause {
270 Kind kind;
271 int arg;
272 double threshold;
273 double width;
274 bool above;
275 };
276
277 void edgeWeights(const Cloud &cloud);
278 double channel(const Cloud &cloud, Kind kind, int arg, std::vector<double> *grad);
279 double gyration(const Cloud &cloud, bool volume, int arg, std::vector<double> *grad);
280 void stateValues(const Cloud &cloud, std::vector<double> &chi,
281 std::vector<std::vector<double>> *grads);
282 void edgesToAtoms(const std::vector<double> &sbar, std::vector<double> &grad) const;
283
284 RationalSwitch sw_;
285 int maxRing_ = 6;
286 bool built_ = false;
287 Topology topo_;
288 std::vector<int> selected_;
289 std::vector<double> reference_;
290 std::vector<int> types_;
291 std::vector<double> box_;
292 std::vector<double> boxLow_;
293 double skin_ = 0.0;
294 std::vector<std::vector<Clause>> states_;
295 std::vector<double> s_;
296 std::vector<double> ds_;
297 std::vector<std::array<double, 3>> unit_;
298};
299
300} // namespace smooth
301
303#endif // SEAMS_SMOOTH_CV_H_
const Topology & topology() const
const RationalSwitch & switching() const
void addClause(int state, Kind kind, int arg, double threshold, double width, bool above)
bool built() const
double value(const Cloud &cloud, Kind kind, int arg, double *grad)
Workspace(const RationalSwitch &sw, int maxRing)
void checkKind(Kind kind, int arg) const
bool stale(const Cloud &cloud) const
int stateCount() const
void rebuild(const Cloud &cloud, std::vector< int > selected, double skin)
void states(const Cloud &cloud, double *chi, double *grad)
int maxRing() const
The main molecular system handler.
Functions for bond-related analyses.
Definition bond.hpp:73
Smooth collective variables on the primitive-ring network.
Definition smooth_cv.hpp:67
RationalSwitch makeSwitch(double r0, double d0, int n, int m, double dOn, double dMax)
constexpr int kMaxSwitchExponent
Definition smooth_cv.hpp:74
constexpr int kMaxShortcutPaths
Definition smooth_cv.hpp:95
std::vector< double > ringParticipation(const Topology &topo, const std::vector< double > &w, int size)
constexpr double kFlatEigenRatio
Definition smooth_cv.hpp:78
Kind
The collective variables of one frame, with their gradients.
void ringParticipationAdjoint(const Topology &topo, const std::vector< double > &w, int size, const std::vector< double > &pbar, std::vector< double > &wbar)
Adds d(sum_i pbar[i] p[i]) / dw to wbar.
constexpr std::int64_t kMaxShortcutSearchSteps
Definition smooth_cv.hpp:91
void ringWeightsAdjoint(const Topology &topo, const std::vector< double > &s, const std::vector< double > &wbar, std::vector< double > &sbar)
Adds d(sum_k wbar[k] w[k]) / ds to sbar.
constexpr std::int64_t kMaxRingSearchSteps
Definition smooth_cv.hpp:83
std::vector< double > ringWeights(const Topology &topo, const std::vector< double > &s)
Ring weights for bond weights s, one per edge.
Topology buildTopology(const std::vector< std::vector< int > > &rows, int maxRing)
double hexBasalPairs(const Topology &topo, const std::vector< double > &s, const std::vector< double > &w, std::vector< double > *sbar, std::vector< double > *wbar)
constexpr int kMaxCandidateRings
Definition smooth_cv.hpp:87
molSys::PointCloud< molSys::Point< double >, double > Cloud
Definition smooth_cv.hpp:69
This contains a collection of points; contains information for a particular frame.
Definition mol_sys.hpp:173
PLUMED RATIONAL switching function times a C2 taper.
double operator()(double r, double &dsdr) const
Two vertex-disjoint candidate hexagons a < b that may pass the HC basal test.
Candidate rings, shortcut paths and hexagon pairs of one graph.
std::vector< int > ringEdges
int ringCount() const
std::vector< int > pathEdgeOff
std::vector< int > ringOff
std::vector< int > adjEdge
std::vector< int > adjAtom
int edgeOf(int i, int j) const
Edge id of the pair (i, j), or -1.
std::vector< int > adjOff
int ringSize(int k) const
std::vector< HexPair > hexPairs
std::vector< int > pathOff
std::vector< int > pathEdges
std::vector< std::array< int, 2 > > edges
std::vector< int > ringAtoms