switchingfunction

Functions that measure whether values are less than a certain quantity. Functions that measure whether values are less than a certain quantity.

Switching functions \(s(r)\) take a minimum of one input parameter \(r_0\). For \(r \le d_0 \quad s(r)=1.0\) while for \(r > d_0\) the function decays smoothly to 0. The various switching functions available in plumed differ in terms of how this decay is performed.

Where there is an accepted convention in the literature (e.g. COORDINATION) on the form of the switching function we use the convention as the default. However, the flexibility to use different switching functions is always present generally through a single keyword. This keyword generally takes an input with the following form:

KEYWORD={TYPE <list of parameters>}

The following table contains a list of the various switching functions that are available in plumed 2 together with an example input.

TYPE FUNCTION EXAMPLE INPUT DEFAULT PARAMETERS
RATIONAL \( s(r)=\frac{ 1 - \left(\frac{ r - d_0 }{ r_0 }\right)^{n} }{ 1 - \left(\frac{ r - d_0 }{ r_0 }\right)^{m} } \) {RATIONAL R_0= \(r_0\) D_0= \(d_0\) NN= \(n\) MM= \(m\)} \(d_0=0.0\), \(n=6\), \(m=2n\)
EXP \( s(r)=\exp\left(-\frac{ r - d_0 }{ r_0 }\right) \) {EXP R_0= \(r_0\) D_0= \(d_0\)} \(d_0=0.0\)
GAUSSIAN \( s(r)=\exp\left(-\frac{ (r - d_0)^2 }{ 2r_0^2 }\right) \) {GAUSSIAN R_0= \(r_0\) D_0= \(d_0\)} \(d_0=0.0\)
SMAP \( s(r) = \left[ 1 + ( 2^{a/b} -1 )\left( \frac{r-d_0}{r_0} \right)^a \right]^{-b/a} \) {SMAP R_0= \(r_0\) D_0= \(d_0\) A= \(a\) B= \(b\)} \(d_0=0.0\)
Q \( s(r) = \frac{1}{1 + \exp(\beta(r_{ij} - \lambda r_{ij}^0))} \) {Q REF= \(r_{ij}^0\) BETA= \(\beta\) LAMBDA= \(\lambda\) } \(\lambda=1.8\), \(\beta=50 nm^-1\) (all-atom)
\(\lambda=1.5\), \(\beta=50 nm^-1\) (coarse-grained)
CUBIC \( s(r) = (y-1)^2(1+2y) \qquad \textrm{where} \quad y = \frac{r - r_1}{r_0-r_1} \) {CUBIC D_0= \(r_1\) D_MAX= \(r_0\)}
TANH \( s(r) = 1 - \tanh\left( \frac{ r - d_0 }{ r_0 } \right) \) {TANH R_0= \(r_0\) D_0= \(d_0\)}
COSINUS \( s(r) &= 1 & if r<=d0 s(r) &= 0.5 \left( \cos ( \frac{ r - d_0 }{ r_0 } * PI ) + 1 \right) & if d0<r<=d0+r0 s(r) &= 0 & if r> d0+r0 \) {COSINUS R_0= \(r_0\) D_0= \(d_0\)}
CUSTOM \( s(r) = FUNC \) {CUSTOM FUNC=1/(1+x^6) R_0= \(r_0\) D_0= \(d_0\)}

Notice that for backward compatibility we allow using MATHEVAL instead of CUSTOM. Also notice that if the a CUSTOM switching function only depends on even powers of x it can be made faster by using x2 as a variable. For instance

{CUSTOM FUNC=1/(1+x2^3) R_0=0.3}

is equivalent to

{CUSTOM FUNC=1/(1+x^6) R_0=0.3}

but runs faster. The reason is that there is an expensive square root calculation that can be optimized out.

Attention
With the default implementation CUSTOM is slower than other functions (e.g., it is slower than an equivalent RATIONAL function by approximately a factor 2). Checkout page Making lepton library faster to see how to improve its performance.

For all the switching functions in the above table one can also specify a further (optional) parameter using the parameter keyword D_MAX to assert that for \(r>d_{\textrm{max}}\) the switching function can be assumed equal to zero. In this case the function is brought smoothly to zero by stretching and shifting it.

KEYWORD={RATIONAL R_0=1 D_MAX=3}

the resulting switching function will be \( s(r) = \frac{s'(r)-s'(d_{max})}{s'(0)-s'(d_{max})} \) where \( s'(r)=\frac{1-r^6}{1-r^{12}} \) Since PLUMED 2.2 this is the default. The old behavior (no stretching) can be obtained with the NOSTRETCH flag. The NOSTRETCH keyword is only provided for backward compatibility and might be removed in the future. Similarly, the STRETCH keyword is still allowed but has no effect.

Notice that switching functions defined with the simplified syntax are never stretched for backward compatibility. This might change in the future.

Glossary of keywords and components