This is part of the function module |
Calculate a combination of variables using a custom expression.
This action computes an arbitrary function of one or more collective variables. Arguments are chosen with the ARG keyword, and the function is provided with the FUNC string. Notice that this string should contain no space. Within FUNC, one can refer to the arguments as x,y,z, and t (up to four variables provided as ARG). This names can be customized using the VAR keyword (see examples below).
This function is implemented using the Lepton library, that allows to evaluate algebraic expressions and to automatically differentiate them.
If you want a function that depends not only on collective variables but also on time you can use the TIME action.
The following input tells plumed to perform a metadynamics using as a CV the difference between two distances.
dAB: DISTANCEATOMS=10,12 dAC: DISTANCEthe pair of atom that we are calculating the distance between.ATOMS=10,15 diff: CUSTOMthe pair of atom that we are calculating the distance between.ARG=dAB,dACthe input for this action is the scalar output from one or more other actions.FUNC=y-xcompulsory keyword the function you wish to evaluatePERIODIC=NO # notice: the previous line could be replaced with the following # diff: COMBINE ARG=dAB,dAC COEFFICIENTS=-1,1 METADcompulsory keyword if the output of your function is periodic then you should specify the periodicity of the function.ARG=diffthe input for this action is the scalar output from one or more other actions.SIGMA=0.1compulsory keyword the widths of the Gaussian hillsHEIGHT=0.5the heights of the Gaussian hills.BIASFACTOR=10use well tempered metadynamics and use this bias factor.PACE=100compulsory keyword the frequency for hill addition
(see also DISTANCE, COMBINE, and METAD). Notice that forces applied to diff will be correctly propagated to atoms 10, 12, and 15. Also notice that since CUSTOM is used without the VAR option the two arguments should be referred to as x and y in the expression FUNC. For simple functions such as this one it is possible to use COMBINE.
The following input tells plumed to print the angle between vectors identified by atoms 1,2 and atoms 2,3 its square (as computed from the x,y,z components) and the distance again as computed from the square root of the square.
d1: DISTANCEATOMS=1,2the pair of atom that we are calculating the distance between.COMPONENTSd2: DISTANCE( default=off ) calculate the x, y and z components of the distance separately and store them as label.x,ATOMS=2,3the pair of atom that we are calculating the distance between.COMPONENTStheta: CUSTOM ...( default=off ) calculate the x, y and z components of the distance separately and store them as label.x,ARG=d1.x,d1.y,d1.z,d2.x,d2.y,d2.zthe input for this action is the scalar output from one or more other actions.VAR=ax,ay,az,bx,by,bzthe names to give each of the arguments in the function.FUNC=acos((ax*bx+ay*by+az*bz)/sqrt((ax*ax+ay*ay+az*az)*(bx*bx+by*by+bz*bz)))compulsory keyword the function you wish to evaluatePERIODIC=NO ... PRINTcompulsory keyword if the output of your function is periodic then you should specify the periodicity of the function.ARG=thetathe input for this action is the scalar output from one or more other actions.
(See also PRINT and DISTANCE).
Notice that this action implements a large number of functions (trigonometric, exp, log, etc). Among the useful functions, have a look at the step function (that is the Heaviside function). step(x)
is defined as 1 when x
is positive and 0
when x is negative. This allows for a straightforward implementation of if clauses.
For example, imagine that you want to implement a restraint that only acts when a distance is larger than 0.5. You can do it with
d: DISTANCEATOMS=10,15 m: CUSTOMthe pair of atom that we are calculating the distance between.ARG=dthe input for this action is the scalar output from one or more other actions.FUNC=0.5*step(0.5-x)+x*step(x-0.5)compulsory keyword the function you wish to evaluatePERIODIC=NO # check the function you are applying: PRINTcompulsory keyword if the output of your function is periodic then you should specify the periodicity of the function.ARG=d,mthe input for this action is the scalar output from one or more other actions.FILE=checkme RESTRAINTthe name of the file on which to output these quantitiesARG=dthe input for this action is the scalar output from one or more other actions.AT=0.5compulsory keyword the position of the restraintKAPPA=10.0compulsory keyword ( default=0.0 ) specifies that the restraint is harmonic and what the values of the force constants on each of the variables are
(see also DISTANCE, PRINT, and RESTRAINT)
The meaning of the function 0.5*step(0.5-x)+x*step(x-0.5)
is:
A possible continuity check with gnuplot is
# this allow to step function to be used in gnuplot: gnuplot> step(x)=0.5*(erf(x*10000000)+1) # here you can test your function gnuplot> p 0.5*step(0.5-x)+x*step(x-0.5)
Also notice that you can easily make logical operations on the conditions that you create. The equivalent of the AND operator is the product: step(1.0-x)*step(x-0.5)
is only equal to 1 when x is between 0.5 and 1.0. By combining negation and AND you can obtain an OR. That is, 1-step(1.0-x)*step(x-0.5)
is only equal to 1 when x is outside the 0.5-1.0 interval.
CUSTOM can be used in combination with DISTANCE to implement variants of the DISTANCE keyword that were present in PLUMED 1.3 and that allowed to compute the distance of a point from a line defined by two other points, or the progression along that line.
# take center of atoms 1 to 10 as reference point 1 p1: CENTERPRINT ARG=onaxis,fromaxisATOMS=1-10 # take center of atoms 11 to 20 as reference point 2 p2: CENTERthe list of atoms which are involved the virtual atom's definition.ATOMS=11-20 # take center of atoms 21 to 30 as reference point 3 p3: CENTERthe list of atoms which are involved the virtual atom's definition.ATOMS=21-30 # compute distances d12: DISTANCEthe list of atoms which are involved the virtual atom's definition.ATOMS=p1,p2 d13: DISTANCEthe pair of atom that we are calculating the distance between.ATOMS=p1,p3 d23: DISTANCEthe pair of atom that we are calculating the distance between.ATOMS=p2,p3 # compute progress variable of the projection of point p3 # along the vector joining p1 and p2 # notice that progress is measured from the middle point onaxis: CUSTOMthe pair of atom that we are calculating the distance between.ARG=d13,d23,d12the input for this action is the scalar output from one or more other actions.FUNC=(0.5*(y^2-x^2)/z)compulsory keyword the function you wish to evaluatePERIODIC=NO # compute between point p3 and the vector joining p1 and p2 fromaxis: CUSTOMcompulsory keyword if the output of your function is periodic then you should specify the periodicity of the function.ARG=d13,d23,d12,onaxisthe input for this action is the scalar output from one or more other actions.VAR=x,y,z,othe names to give each of the arguments in the function.FUNC=(0.5*(y^2+x^2)-o^2-0.25*z^2)compulsory keyword the function you wish to evaluatePERIODIC=NOcompulsory keyword if the output of your function is periodic then you should specify the periodicity of the function.
Notice that these equations have been used to combine RMSD from different snapshots of a protein so as to define progression (S) and distance (Z) variables [98].
PERIODIC | if the output of your function is periodic then you should specify the periodicity of the function. If the output is not periodic you must state this using PERIODIC=NO |
FUNC | the function you wish to evaluate |
NUMERICAL_DERIVATIVES | ( default=off ) calculate the derivatives for these quantities numerically |
ARG | the input for this action is the scalar output from one or more other actions. The particular scalars that you will use are referenced using the label of the action. If the label appears on its own then it is assumed that the Action calculates a single scalar value. The value of this scalar is thus used as the input to this new action. If * or *.* appears the scalars calculated by all the proceeding actions in the input file are taken. Some actions have multi-component outputs and each component of the output has a specific label. For example a DISTANCE action labelled dist may have three components x, y and z. To take just the x component you should use dist.x, if you wish to take all three components then use dist.*.More information on the referencing of Actions can be found in the section of the manual on the PLUMED Getting Started. Scalar values can also be referenced using POSIX regular expressions as detailed in the section on Regular Expressions. To use this feature you you must compile PLUMED with the appropriate flag. You can use multiple instances of this keyword i.e. ARG1, ARG2, ARG3... |
VAR | the names to give each of the arguments in the function. If you have up to three arguments in your function you can use x, y and z to refer to them. Otherwise you must use this flag to give your variables names. |