Skip to content

Commit

Permalink
Fixed some examples in function documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed Nov 26, 2024
1 parent 2d850bb commit d3363e8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
31 changes: 28 additions & 3 deletions src/function/Custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,32 @@ PRINT ARG=onaxis,fromaxis
```
The equations in this input were also used to combine [RMSD](RMSD.md) values from different snapshots of a protein so as to define
progression (S) and distance (Z) variables in the paper that is cited in the bibliography.
progression (S) and distance (Z) variables in the paper that is cited in the bibliography. We can understand how these expressions
are derived by noting that $x$, $y$ and $z$ are the distances between atoms 1 and 3, 2 and 3 and 1 and 2 respectively. The projection
of the vector connecting atom 1 to atom 3 onto the vector connecting atom 1 to atom 2 is thus $x\cos(\theta)$, where theta is the angle
between the vector connecting atoms 1 and 3 and the vector connecting atoms 1 and 2. We can arrive at the following expression for $x\cos(\theta)$
by rearranging the cosine rule:
$$
x\cos(\theta) = \frac{y^2 - x^2}{z} - \frac{z}{2}
$$
Notice that the value called `onaxis` in the above input is thus $o=x\cos(\theta) + \frac{z}{2}$. Adding the factor of $\frac{z}{2}$ ensures that the origin
is at the center of the bond connecting atom 1 to atom 2.
The value `fromaxis` measures the square of the distance from the the line. It is calculated using pythagoras theorem as follows:
$$
f^2 = y^2 - x^2\cos^2(\theta)
$$
Inserting $x\cos(\theta) = o - \frac{z}{2}$ into this expression gives:
$$
f^2 = y^2 - (o -\frac{z}{2})^2 = y^2 - o^2 + oz - \frac{z^2}{4}
$$
Inserting the fact that $oz = \frac{y^2 - x^2}{2}$, which comes from the expression for $o$ that was used to calculate `onaxis`, gets us to the expression that is used to calculate `fromaxis`.
## CUSTOM with vector arguments
Expand Down Expand Up @@ -326,8 +351,8 @@ PRINT ARG=angles FILE=colvar
Notice that you can pass multiple $N\times M$ matrices in the input to a CUSTOM action as illustrated in the example below:
```plumed
c1: CUSTOM VALUES=2,3,4,5 NROWS=2 NCOLS=2
c2: CUSTOM VALUES=1,0,0,1 NROWS=2 NCOLS=2
c1: CONSTANT VALUES=2,3,4,5 NROWS=2 NCOLS=2
c2: CONSTANT VALUES=1,0,0,1 NROWS=2 NCOLS=2
f: CUSTOM ARG=c1,c2 FUNC=x*y PERIODIC=NO
PRINT ARG=f FILE=colvar
```
Expand Down
5 changes: 5 additions & 0 deletions src/function/FunctionOfMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ FunctionOfMatrix<T>::FunctionOfMatrix(const ActionOptions&ao):
}
}
}
bool allconstant=true;
for(unsigned i=argstart; i<getNumberOfArguments(); ++i) {
if( !getPntrToArgument(i)->isConstant() ) { allconstant=false; break; }
}
if( allconstant ) done_in_chain=false;
// Now setup the action in the chain if we can
nderivatives = buildArgumentStore(myfunc.getArgStart());
}
Expand Down
4 changes: 2 additions & 2 deletions src/function/Highest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Notice that you can also use a combination of scalars and vectors in the input t
```plumed
c: CONSTANT VALUE=0.05
d: DISTANCE ATOMS1=1,2 ATOMS2=3,4
h: HIGHEST ARG=c,d
h: HIGHEST ARG=d,c
PRINT ARG=h FILE=colvar
```
Expand Down Expand Up @@ -187,7 +187,7 @@ Notice that you can also use a combination of scalars and vectors in the input t
```plumed
c: CONSTANT VALUE=0.5
d: DISTANCE ATOMS1=1,2 ATOMS2=3,4
h: LOWEST ARG=c,d
h: LOWEST ARG=d,c
PRINT ARG=h FILE=colvar
```
Expand Down
2 changes: 1 addition & 1 deletion src/function/Moments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Notice that you can also achieve the same result using the following input:
```plumed
d: DISTANCE ATOMS1=1,2 ATOMS2=1,3 ATOMS3=1,4 ATOMS4=1,5
sort: MOMENTS ARG=d POWERS=2,3
mv: MOMENTS ARG=d POWERS=2,3
PRINT ARG=mv.moment-2,mv.moment-3 FILE=colvar
```
Expand Down
2 changes: 1 addition & 1 deletion src/function/Sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ This example calculates and outputs the number of distances that are less than 0
You can do something similar by summing the elements of a matrix as shown below:
```plumed
c: CONTACT_MATRIX SPECIES=1-100 SWITCH={RATIONAL R_0=0.1}
c: CONTACT_MATRIX GROUP=1-100 SWITCH={RATIONAL R_0=0.1}
s: SUM ARG=c PERIODIC=NO
PRINT ARG=s FILE=colvar
```
Expand Down

1 comment on commit d3363e8

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/CLASSICAL_MDS.tmp
Found broken examples in automatic/CONVERT_TO_FES.tmp
Found broken examples in automatic/COORDINATIONNUMBER.tmp
Found broken examples in automatic/DISTANCE_FROM_CONTOUR.tmp
Found broken examples in automatic/DUMPCUBE.tmp
Found broken examples in automatic/DUMPGRID.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/FIND_CONTOUR.tmp
Found broken examples in automatic/FIND_CONTOUR_SURFACE.tmp
Found broken examples in automatic/FIND_SPHERICAL_CONTOUR.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GPROPERTYMAP.tmp
Found broken examples in automatic/HISTOGRAM.tmp
Found broken examples in automatic/INTERPOLATE_GRID.tmp
Found broken examples in automatic/LOCAL_AVERAGE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/METATENSOR.tmp
Found broken examples in automatic/MULTICOLVARDENS.tmp
Found broken examples in automatic/PCA.tmp
Found broken examples in automatic/PCAVARS.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PYCVINTERFACE.tmp
Found broken examples in automatic/PYTHONFUNCTION.tmp
Found broken examples in automatic/Q3.tmp
Found broken examples in automatic/Q4.tmp
Found broken examples in automatic/Q6.tmp
Found broken examples in automatic/QUATERNION.tmp
Found broken examples in automatic/REWEIGHT_BIAS.tmp
Found broken examples in automatic/REWEIGHT_METAD.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_LINEAR_PROJ.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_MAHA_DIST.tmp
Found broken examples in AnalysisPP.md
Found broken examples in CollectiveVariablesPP.md
Found broken examples in MiscelaneousPP.md

Please sign in to comment.