seams-core v2.15.0
libyodaLib, the C++ engine of d-SEAMS
Loading...
Searching...
No Matches
Smooth collective variables

Soft ring counts, hexagon-pair counts, gyration and states, with gradients. More...

Functions

SEAMS_API seams_status seams_switch_rational (double r, double r0, double d0, int n, int m, double d_on, double d_max, double *s, double *dsdr)
 PLUMED RATIONAL switching function with a C2 taper to zero.
SEAMS_API seams_status seams_cv_create (double r0, double d0, int n, int m, double d_on, double d_max, int max_ring, seams_cv **out)
 Create a smooth collective-variable workspace.
SEAMS_API void seams_cv_destroy (seams_cv *cv)
 Free a collective-variable workspace.
SEAMS_API seams_status seams_cv_rebuild (seams_cv *cv, const seams_system *sys, int type, const int *atoms, size_t n_atoms, double skin)
 List the graph and fix the candidate rings for the next frames.
SEAMS_API seams_status seams_cv_needs_rebuild (const seams_cv *cv, const seams_system *sys, int *stale)
 Whether a frame needs seams_cv_rebuild() before the next value.
SEAMS_API seams_status seams_cv_topology (const seams_cv *cv, size_t *n_edges, size_t *n_rings, size_t *n_pairs)
 Sizes of the fixed topology.
SEAMS_API seams_status seams_cv_value (seams_cv *cv, const seams_system *sys, int kind, int arg, double *value, double *grad, size_t grad_len)
 Value and gradient of one collective variable.
SEAMS_API seams_status seams_cv_state_clause (seams_cv *cv, int state, int kind, int arg, double threshold, double width, int above)
 Add a soft threshold factor to a state.
SEAMS_API seams_status seams_cv_states (seams_cv *cv, const seams_system *sys, double *chi, size_t chi_len, size_t *n_states, double *grad, size_t grad_len)
 Soft indicator of every state, with gradients on request.

Detailed Description

Soft ring counts, hexagon-pair counts, gyration and states, with gradients.

Every bond within d_max carries the weight s(r) of seams_switch_rational(). A candidate ring is any simple cycle of at most max_ring members in the graph at d_max + skin. Its weight is the product of its bond weights times (1 - W_P) for every shortcut path P between two of its members, W_P the product of the path's bond weights. With bond weights 0 and 1 the rings of weight one are the primitive rings of seams_rings_find(). The ring counts, ring-atom counts and hexagon pairs are fixed polynomials in the pair weights, so they are as smooth as s(r) also where a bond crosses the list cutoff or a ring gains or loses a shortcut. The weights are twice continuously differentiable in the coordinates for n >= 3, and for n = 2 with d0 = 0. At d0 > 0 the weight is only C^(n-1) at r = d0; with d0 = 0 and n = 1 it has a cone, s = 1 - r / r0 to first order, where two atoms coincide.

The gyration values are not polynomials in the weights. They are as smooth as the weights for a compact selection, one whose atoms are all closer to each other than half the narrowest cell width in some periodic image, while the total weight is positive. Otherwise the unwrapped positions can jump by a cell vector, and with ring weights the value drops to 0 where the total weight reaches 0. The volume is a square root of det G: continuous where G is, but in general not differentiable where the cluster becomes flat, det G = 0. It has a kink there, like the distance of one atom from the plane of the others.

Gradients are d value / d x, 3 * natoms doubles in frame order, x0 y0 z0 x1 ..., zero for atoms outside the selection. The force of a bias V(value) on atom i is -dV/dvalue times its three entries.

Function Documentation

◆ seams_cv_create()

SEAMS_API seams_status seams_cv_create ( double r0,
double d0,
int n,
int m,
double d_on,
double d_max,
int max_ring,
seams_cv ** out )

Create a smooth collective-variable workspace.

Parameters
r0Switching length scale, Angstrom. See seams_switch_rational().
d0Switching plateau radius, Angstrom.
nSwitching numerator exponent, from 1 through 4096.
mSwitching denominator exponent, greater than n and at most 4096. Zero selects 2 * n, which needs 2 * n <= 4096.
d_onTaper start, Angstrom.
d_maxRadius where every bond weight reaches zero, Angstrom.
max_ringLargest candidate ring, from 3 through 10.
outReceives a new handle. On failure *out is NULL.
Returns
SEAMS_OK, or SEAMS_ERR_NULL, SEAMS_ERR_RANGE, SEAMS_ERR_NOMEM.
Ownership
The caller frees *out with seams_cv_destroy(). The handle holds no frame until seams_cv_rebuild().
Thread safety
The new handle is private to the caller.
Example
seams_cv *cv = NULL;
if (seams_cv_create(0.5, 2.5, 6, 0, 3.3, 3.5, 6, &cv) == SEAMS_OK) {
}
SEAMS_API seams_status seams_cv_create(double r0, double d0, int n, int m, double d_on, double d_max, int max_ring, seams_cv **out)
Create a smooth collective-variable workspace.
SEAMS_API void seams_cv_destroy(seams_cv *cv)
Free a collective-variable workspace.
struct seams_cv seams_cv
Smooth collective-variable workspace.
Definition seams.h:286
@ SEAMS_OK
The call succeeded.
Definition seams.h:155

◆ seams_cv_destroy()

SEAMS_API void seams_cv_destroy ( seams_cv * cv)

Free a collective-variable workspace.

Parameters
cvHandle from seams_cv_create(), or NULL. NULL is ignored.
Ownership
Releases the handle, its topology and its state clauses.
Thread safety
The caller must not use cv after this returns.
Example
seams_cv *cv = NULL;
seams_cv_create(0.3, 2.8, 6, 0, 2.9, 3.0, 6, &cv);

◆ seams_cv_needs_rebuild()

SEAMS_API seams_status seams_cv_needs_rebuild ( const seams_cv * cv,
const seams_system * sys,
int * stale )

Whether a frame needs seams_cv_rebuild() before the next value.

It compares state only and does not bin the cell. A too-fine mesh is reported by seams_cv_rebuild() as SEAMS_ERR_RANGE. stale is written only on SEAMS_OK and left unchanged on any error. With skin 0.1, the atoms (0, 0, 0) and (1, 0, 0) in an orthorhombic cell of edge 30 with origin (0, 0, 0) rebuild, and moving the first atom to (30 * 2^52, 0, 0) on that same cell returns SEAMS_ERR_RANGE and leaves a pre-set stale of 7 unchanged.

Parameters
cvWorkspace handle.
sysFrame handle that holds a frame.
staleWritten only on SEAMS_OK. Then 1 when the workspace has not been rebuilt, the atom count, cell, or origin differs, an atom type differs, or a selected atom's squared minimum-image displacement is greater than (skin / 2)^2, and 0 when none of those holds. Left unchanged on any error.
Returns
SEAMS_OK, or SEAMS_ERR_NULL, SEAMS_ERR_STATE, SEAMS_ERR_RANGE.
Ownership
The caller owns stale.
Thread safety
Read-only: may run alongside other const calls on cv and sys.
Example
seams_cv *cv = NULL;
seams_cv_create(0.3, 2.8, 6, 0, 2.9, 3.0, 6, &cv);
seams_cv_rebuild(cv, sys, 0, NULL, 0, 0.1);
int stale = 0;
seams_cv_needs_rebuild(cv, sys, &stale);
SEAMS_API seams_status seams_cv_needs_rebuild(const seams_cv *cv, const seams_system *sys, int *stale)
Whether a frame needs seams_cv_rebuild() before the next value.
SEAMS_API seams_status seams_cv_rebuild(seams_cv *cv, const seams_system *sys, int type, const int *atoms, size_t n_atoms, double skin)
List the graph and fix the candidate rings for the next frames.

◆ seams_cv_rebuild()

SEAMS_API seams_status seams_cv_rebuild ( seams_cv * cv,
const seams_system * sys,
int type,
const int * atoms,
size_t n_atoms,
double skin )

List the graph and fix the candidate rings for the next frames.

Bonds are the selected pairs within d_max + skin, from linkcell. The candidate rings, their shortcut paths and the hexagon pairs are fixed until the next rebuild. A ring, ring-atom or hexagon-pair value computed from this topology equals the value from a fresh rebuild while no selected atom has moved more than skin / 2 from its position here, the cell is unchanged, and every atom type is unchanged; so does a gyration value of a compact selection (see seams_cv_value()). A type change marks the selection stale. The ring and shortcut searches are bounded by the ring size. A graph that would pass 20000000 ring-search steps, 2000000 candidate rings, 20000000 shortcut-search steps, or 2000000 shortcut paths is SEAMS_ERR_RANGE and the message names that limit; rings and paths are not dropped. seams_cv_needs_rebuild() reports when the topology no longer matches the frame, and seams_cv_value() then refuses the frame.

Parameters
cvWorkspace handle.
sysFrame handle that holds a frame.
typeSpecies to select. Zero and negative select every atom.
atomsFrame indices to select, or NULL for every atom of type.
n_atomsLength of atoms. Ignored when atoms is NULL.
skinVerlet skin, Angstrom, at least zero. d_max + skin must be below half the narrowest width of the cell.
Returns
SEAMS_OK, or SEAMS_ERR_NULL, SEAMS_ERR_STATE, SEAMS_ERR_RANGE, SEAMS_ERR_ARG, SEAMS_ERR_BOX, SEAMS_ERR_NOMEM, SEAMS_ERR_INTERNAL.
Handle access
Writes the topology into cv. Reads sys.
Ownership
The caller owns atoms. The workspace keeps a copy of the selection and of the coordinates and cell of this frame.
Thread safety
Exclusive use of cv. Read-only use of sys.
Example
seams_cv *cv = NULL;
seams_cv_create(0.3, 2.8, 6, 0, 2.9, 3.0, 6, &cv);
seams_cv_rebuild(cv, sys, 0, NULL, 0, 0.1);

◆ seams_cv_state_clause()

SEAMS_API seams_status seams_cv_state_clause ( seams_cv * cv,
int state,
int kind,
int arg,
double threshold,
double width,
int above )

Add a soft threshold factor to a state.

A state is the product of its factors. A factor on a collective variable v is sigma((v - threshold) / width) when above is nonzero and 1 - sigma((v - threshold) / width) otherwise, sigma(z) = 1 / (1 + e^-z). A factor of kind SEAMS_CV_STATE reads an earlier state chi; with width zero it is chi itself, or 1 - chi when above is zero, so states compose by product (and), complement (not), and 1 - (1 - a)(1 - b) (or).

Parameters
cvWorkspace handle.
stateIndex of the state to extend, or the current number of states to open a new one.
kindA seams_cv_kind code.
argArgument of kind, as for seams_cv_value(); for SEAMS_CV_STATE an index below state.
thresholdThreshold, in the unit of the variable.
widthPositive logistic width, in the unit of the variable. Zero only for SEAMS_CV_STATE.
aboveNonzero for a factor that rises through the threshold.
Returns
SEAMS_OK, or SEAMS_ERR_NULL, SEAMS_ERR_RANGE, SEAMS_ERR_NOMEM.
Handle access
Appends to the state list of cv.
Ownership
The workspace keeps the clause until it is destroyed.
Thread safety
Exclusive use of cv.
Example
seams_cv *cv = NULL;
seams_cv_create(0.3, 2.8, 6, 0, 2.9, 3.0, 6, &cv);
seams_cv_state_clause(cv, 0, SEAMS_CV_RING_COUNT, 6, 40.0, 4.0, 1);
SEAMS_API seams_status seams_cv_state_clause(seams_cv *cv, int state, int kind, int arg, double threshold, double width, int above)
Add a soft threshold factor to a state.
@ SEAMS_CV_RING_COUNT
Sum of soft ring weights of size arg; as smooth as the switch.
Definition seams.h:259

◆ seams_cv_states()

SEAMS_API seams_status seams_cv_states ( seams_cv * cv,
const seams_system * sys,
double * chi,
size_t chi_len,
size_t * n_states,
double * grad,
size_t grad_len )

Soft indicator of every state, with gradients on request.

Parameters
cvWorkspace handle after seams_cv_rebuild().
sysFrame with the atom count and cell of the rebuild.
chiCaller buffer of one double per state, each in [0, 1], or NULL to query n_states.
chi_lenLength of chi. Ignored when chi is NULL.
n_statesReceives the number of states.
gradCaller buffer of n_states rows of 3 * natoms doubles, d chi / d x in 1/Angstrom, or NULL to skip it.
grad_lenLength of grad. Ignored when grad is NULL.
Returns
SEAMS_OK, or SEAMS_ERR_NULL, SEAMS_ERR_STATE when cv needs a rebuild for sys, SEAMS_ERR_RANGE, also when a chi or a gradient entry is outside double range and neither chi nor grad is written, SEAMS_ERR_NOMEM, SEAMS_ERR_INTERNAL.
Handle access
Non-const because the evaluation keeps bond-weight scratch on cv.
Ownership
The caller owns chi, n_states and grad.
Thread safety
Exclusive use of cv. Read-only use of sys.
Example
seams_cv *cv = NULL;
seams_cv_create(0.3, 2.8, 6, 0, 2.9, 3.0, 6, &cv);
seams_cv_rebuild(cv, sys, 0, NULL, 0, 0.1);
seams_cv_state_clause(cv, 0, SEAMS_CV_RING_COUNT, 6, 40.0, 4.0, 1);
seams_cv_state_clause(cv, 1, SEAMS_CV_STATE, 0, 0.0, 0.0, 0);
double chi[2];
size_t n_states = 0;
seams_cv_states(cv, sys, chi, 2, &n_states, NULL, 0);
SEAMS_API seams_status seams_cv_states(seams_cv *cv, const seams_system *sys, double *chi, size_t chi_len, size_t *n_states, double *grad, size_t grad_len)
Soft indicator of every state, with gradients on request.
@ SEAMS_CV_STATE
Soft indicator of state arg from seams_cv_state_clause(); as smooth as its clauses.
Definition seams.h:264

◆ seams_cv_topology()

SEAMS_API seams_status seams_cv_topology ( const seams_cv * cv,
size_t * n_edges,
size_t * n_rings,
size_t * n_pairs )

Sizes of the fixed topology.

Parameters
cvWorkspace handle.
n_edgesReceives the number of listed bonds, or NULL.
n_ringsReceives the number of candidate rings, or NULL.
n_pairsReceives the number of candidate hexagon pairs, or NULL.
Returns
SEAMS_OK, or SEAMS_ERR_NULL, SEAMS_ERR_STATE before the first rebuild.
Ownership
The caller owns the three outputs.
Thread safety
Read-only: may run alongside other const calls on cv.
Example
seams_cv *cv = NULL;
seams_cv_create(0.3, 2.8, 6, 0, 2.9, 3.0, 6, &cv);
seams_cv_rebuild(cv, sys, 0, NULL, 0, 0.1);
size_t edges = 0, rings = 0, pairs = 0;
seams_cv_topology(cv, &edges, &rings, &pairs);
SEAMS_API seams_status seams_cv_topology(const seams_cv *cv, size_t *n_edges, size_t *n_rings, size_t *n_pairs)
Sizes of the fixed topology.

◆ seams_cv_value()

SEAMS_API seams_status seams_cv_value ( seams_cv * cv,
const seams_system * sys,
int kind,
int arg,
double * value,
double * grad,
size_t grad_len )

Value and gradient of one collective variable.

SEAMS_CV_RING_COUNT sums the ring weights of size arg. SEAMS_CV_RING_ATOMS sums 1 - prod (1 - w) over the rings of size arg through each selected atom. SEAMS_CV_HEX_BASAL_PAIRS sums w_a w_b B over vertex-disjoint hexagon pairs, B the soft form of the hexagonal-cage basal test of either ring against the other; arg is 0. These three are as smooth as the switch. SEAMS_CV_GYRATION_RG2 and SEAMS_CV_GYRATION_VOLUME use the gyration tensor G of the selected atoms, unwrapped along bonds, with weight 1 when arg is -1 and the ring participation of size arg otherwise; the volume is (4 pi / 3) 5^(3/2) sqrt(det G), the volume of the uniform ellipsoid with that tensor. A part of the selection that no bond reaches is placed by its minimum image from the first selected atom. Both are smooth while the selection is compact, its atoms all closer to each other than half the narrowest cell width in some periodic image, and its total weight is positive. With total weight 0 both values and gradients are 0, so with ring weights they jump to 0 as the last ring breaks. The volume is in general not differentiable where the cluster becomes flat, det G = 0; there it and its gradient are 0. The same 0 value and 0 gradient are returned when the smallest eigenvalue of G is at most 1e-10 times the largest, so a coplanar cloud whose determinant rounds positive stays flat. SEAMS_CV_STATE returns state arg, as smooth as the variables its clauses read. A value or gradient entry outside double range, from switch parameters near the smallest doubles or coordinates near the largest, is SEAMS_ERR_RANGE, and neither value nor grad is written.

Parameters
cvWorkspace handle after seams_cv_rebuild().
sysFrame with the atom count and cell of the rebuild.
kindA seams_cv_kind code.
argRing size, weight choice, or state index, as above.
valueReceives the value.
gradCaller buffer of 3 * natoms doubles for d value / d x in 1/Angstrom times the unit of value, or NULL to skip it.
grad_lenLength of grad. Ignored when grad is NULL.
Returns
SEAMS_OK, or SEAMS_ERR_NULL, SEAMS_ERR_STATE when cv needs a rebuild for sys, SEAMS_ERR_RANGE, SEAMS_ERR_NOMEM, SEAMS_ERR_INTERNAL.
Handle access
Non-const because the evaluation keeps bond-weight scratch on cv. The topology is not changed.
Ownership
The caller owns value and grad.
Thread safety
Exclusive use of cv. Read-only use of sys.
Example
seams_cv *cv = NULL;
seams_cv_create(0.3, 2.8, 6, 0, 2.9, 3.0, 6, &cv);
seams_cv_rebuild(cv, sys, 0, NULL, 0, 0.1);
double n6 = 0;
seams_cv_value(cv, sys, SEAMS_CV_RING_COUNT, 6, &n6, NULL, 0);
SEAMS_API seams_status seams_cv_value(seams_cv *cv, const seams_system *sys, int kind, int arg, double *value, double *grad, size_t grad_len)
Value and gradient of one collective variable.

◆ seams_switch_rational()

SEAMS_API seams_status seams_switch_rational ( double r,
double r0,
double d0,
int n,
int m,
double d_on,
double d_max,
double * s,
double * dsdr )

PLUMED RATIONAL switching function with a C2 taper to zero.

For x = (r - d0) / r0, s = (1 - x^n) / (1 - x^m) for r > d0 and 1 for r <= d0, times a taper that is 1 below d_on, 0 at and beyond d_max, and 1 - u^3 (10 - 15u + 6u^2) for u = (r - d_on) / (d_max - d_on) between them. s and its first two derivatives vanish at d_max. On r >= 0, s is C^2 in r except at r = d0 > 0 with n < 3, where it is only C^(n-1). At r = d0, dsdr is the right derivative: -1 / r0 for n = 1 and 0 otherwise. Above x = 1, s is evaluated in 1 / x, so for every finite argument s is finite when n and m are at most 4096. A larger exponent is SEAMS_ERR_RANGE and the message names 4096. ds/dr can exceed double range when r0 or d_max - d_on is near the smallest doubles; when dsdr is not NULL that is SEAMS_ERR_RANGE, and neither output is written.

Parameters
rDistance, Angstrom. Not negative.
r0Positive length scale, Angstrom.
d0Plateau radius, Angstrom, at least zero.
nNumerator exponent, from 1 through 4096.
mDenominator exponent, greater than n and at most 4096. Zero selects 2 * n, which needs 2 * n <= 4096.
d_onTaper start, Angstrom, from d0 and below d_max.
d_maxRadius where s reaches zero, Angstrom.
sReceives s(r).
dsdrReceives ds/dr in 1/Angstrom, the right derivative at r = d0, or NULL.
Returns
SEAMS_OK, or SEAMS_ERR_NULL, SEAMS_ERR_RANGE.
Ownership
The caller owns s and dsdr. The call keeps no state.
Thread safety
Safe from any thread.
Example
double sw = 0, dsw = 0;
seams_switch_rational(3.0, 0.5, 2.5, 6, 0, 3.3, 3.5, &sw, &dsw);
SEAMS_API seams_status seams_switch_rational(double r, double r0, double d0, int n, int m, double d_on, double d_max, double *s, double *dsdr)
PLUMED RATIONAL switching function with a C2 taper to zero.