COMBINE and PERIODIC
I just added a short example of COMBINE with PERIODIC in the manual (on Pratyush request).
Better thinking about it, I think we could automatize this choice for COMBINE. I write here how I think we could do it.
If none of the arguments is periodic, then use PERIODIC=NO
Else, if there are at least two arguments contributing (i.e. with POWERS!=0 and COEFFICIENTS!=0), then PERIODIC cannot be computed. Give an error and ask the user to provide periodicity.
Now we assume there is a single periodic argument. Consider its range (min,max), its coefficient (c), and its power (n). Notice that n might need to be normalized.
If n is odd OR (n is even AND min and max have the same sign) then one can set PERIODIC=A,B where A and B are same as c_min__n and c_max**n but sorted. Otherwise, give an error and ask user to provide periodicity.
Giovanni
I better thought about this and actually it would probably make more sense to enforce sin/cos combinations when using periodic variables. I propose the following definition:
- If some of the arguments is not periodic or the result is not periodic, do the usual calculation.
- If all the arguments are periodic and the result is periodic, do the sin/cos combination described below.
In order to make the sin/cos combination, do the following:
- Subtract from each
ARGthe correspondingPARAMETER(as now). Differences should be done with PBC (notice that this is not currently done, I think it is a sort of bug that should be fixed). - Scale the results by a factor
2*pi/(max-min)in order to convert it to an angle in radians. If applied to normal torsions, it would scale by a factor 1. - Combine sin and cos of that angle using
COEFFICIENTSas weights. - Compute the
atan2of the resulting combinations. - Scale the result by
(max-min)/(2*pi)to make it consistent with the domain specified in thePERIODICoption.
Notice that the result will be invariant by a scaling of all the COEFFICIENTS, implying their normalization. This is because atan2(y,x) only depends on y/x and on the sign of y.
In this manner it would be possible to take the average value of many angles easily:
av: COMBINE ARG=(torsion.*) PERIODIC=-pi,pi
Also notice that POWERS could be used to scale the angles, in order to be consistent with taking the powers of an imaginary exponential. To this aim they should be >=0 and integers. Although I am not sure how useful this would be.