-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrandom-rotate.f
241 lines (178 loc) · 10.2 KB
/
random-rotate.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
********************************************************************************
** FICHE F.15. ROUTINES TO RANDOMLY ROTATE MOLECULES. **
** This FORTRAN code is intended to illustrate points made in the text. **
** To our knowledge it works correctly. However it is the responsibility of **
** the user to test it, if it is to be used in a research application. **
********************************************************************************
C *******************************************************************
C ** THREE METHODS FOR UNIFORM RANDOM ROTATION OF LINEAR MOLECULE. **
C ** **
C ** ROUTINES SUPPLIED: **
C ** **
C ** SUBROUTINE FLIP1 ( EXIOLD, EYIOLD, EZIOLD, DPHIMX, DCOSMX, **
C ** EXINEW, EYINEW, EZINEW ) **
C ** SUBROUTINE FLIP2 ( EXIOLD, EYIOLD, EZIOLD, DGAMAX, **
C ** EXINEW, EYINEW, EZINEW ) **
C ** SUBROUTINE FLIP3 ( EXIOLD, EYIOLD, EZIOLD, DOTMIN, **
C ** EXINEW, EYINEW, EZINEW ) **
C ** **
C ** ROUTINE REQUIRED: **
C ** **
C ** REAL FUNCTION RANF ( DUMMY ) **
C ** RETURNS A UNIFORM RANDOM VARIATE ON THE RANGE ZERO TO ONE **
C ** INCLUSIVE (SEE F.11). **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** REAL EXIOLD,EYIOLD,EZIOLD OLD AXIAL VECTOR FOR MOL. I **
C ** REAL EYINEW,EYINEW,EZINEW TRIAL AXIAL VECTOR FOR MOL. I **
C *******************************************************************
SUBROUTINE FLIP1 ( EXIOLD, EYIOLD, EZIOLD, DPHIMX, DCOSMX,
: EXINEW, EYINEW, EZINEW )
C *******************************************************************
C ** MAKES A RANDOM CHANGE IN THE POLAR ANGLES PHI AND THETA. **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** REAL DCOSMX MAXIMUM CHANGE IN COS(THETA) **
C ** REAL DPHIMX MAXIMUM CHANGE IN PHI **
C ** REAL PHIOLD PHI IN THE OLD STATE **
C ** REAL PHINEW PHI IN THE NEW TRIAL STATE **
C ** REAL COSOLD COS(THETA) IN THE OLD STATE **
C ** REAL COSNEW COS(THETA) IN THE NEW TRIAL STATE **
C ** **
C ** USAGE: **
C ** **
C ** FLIP1 MAKES A RANDOM CHANGE IN PHI AND COS(THETA). **
C ** THE MAXIMUM ALLOWED CHANGES IN THESE VARIABLES ARE CONTROLLED **
C ** BY THE PARAMETERS DPHIMX AND DCOSMX RESPECTIVELY. **
C ** PHI AND THETA ARE THE EULER ANGLES DESCRIBING THE ORIENTATION **
C ** OF THE AXIAL VECTOR. THIS METHOD CAN BE READILY EXTENDED TO **
C ** POLYATOMICS BY CHANGING THE THIRD EULER ANGLE , PSI, IN THE **
C ** RANGE ZERO TO TWOPI. IT WOULD BE FASTER TO PASS THE VARIABLES **
C ** PHIOLD AND COSOLD DIRECTLY TO FLIP1 IF THEY ARE AVAILABLE IN **
C ** THE MAIN PROGRAM. SIMILARLY PHINEW AND COSNEW COULD BE **
C ** PASSED DIRECTLY BACK THROUGH THE SUBROUTINE HEADER **
C *******************************************************************
REAL EXIOLD, EYIOLD, EZIOLD, EXINEW, EYINEW, EZINEW
REAL DPHIMX, DCOSMX
REAL COSNEW, COSOLD, PHINEW, PHIOLD, SINNEW
REAL TWOPI, PI
REAL RANF, DUMMY
PARAMETER ( TWOPI = 6.2831853 )
C *******************************************************************
C ** CONVERT THE AXIAL VECTOR TO THE EULER ANGLES **
COSOLD = EZIOLD
PHIOLD = ATAN2 ( EYIOLD, EXIOLD )
C ** PERFORM THE DISPLACEMENTS **
PHINEW = PHIOLD + ( 2.0 * RANF ( DUMMY ) - 1.0 ) * DPHIMX
PHINEW = PHINEW - ANINT ( PHINEW / TWOPI ) * TWOPI
COSNEW = COSOLD + ( 2.0 * RANF ( DUMMY ) - 1.0 ) * DCOSMX
COSNEW = COSNEW - ANINT ( COSNEW / 2.0 ) * 2.0
SINNEW = SQRT ( 1.0 - COSNEW * COSNEW )
C ** CONVERT THE EULER ANGLES TO AXIAL VECTORS **
EXINEW = COS ( PHINEW ) * SINNEW
EYINEW = SIN ( PHINEW ) * SINNEW
EZINEW = COSNEW
RETURN
END
SUBROUTINE FLIP2 ( EXIOLD, EYIOLD, EZIOLD, DGAMAX,
: EXINEW, EYINEW, EZINEW )
C *******************************************************************
C ** PERFORMS RANDOM ROTATION ABOUT SPACE-FIXED AXES. **
C ** **
C ** REFERENCE: **
C ** **
C ** BARKER AND WATTS, CHEM PHYS LETTS 3, 144, 1969. **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** REAL DGAMAX MAXIMUM ANGULAR DISPLACEMENT IN RADIANS **
C ** INTEGER IAXIS SPACE FIXED AXIS FOR ROTATION **
C ** (1 = X, 2 = Y, 3 = Z) **
C ** **
C ** USAGE: **
C ** **
C ** FLIP2 CHOOSES ONE OF THE THREE SPACE-FIXED AXES AT RANDOM **
C ** AND ROTATES THE MOLECULE AROUND THIS AXIS BY DGAMMA RADIANS. **
C ** THE MAXIMUM ANGULAR DISPLACEMENT IS DGAMAX. THIS METHOD CAN **
C ** READILY EXTENDED TO POLYATOMIC MOLECULES. **
C *******************************************************************
REAL EXIOLD, EYIOLD, EZIOLD, EXINEW, EYINEW, EZINEW, DGAMAX
REAL COSDG, SINDG, DGAMMA
REAL RANF, DUMMY
INTEGER IAXIS
C *******************************************************************
C ** CHOOSE A SPACE FIXED AXIS AT RANDOM **
IAXIS = INT ( 3.0 * RANF ( DUMMY ) ) + 1
C ** CHOOSE A RANDOM ROTATION **
DGAMMA = ( 2.0 * RANF ( DUMMY ) - 1.0 ) * DGAMAX
C ** SET UP THE ROTATION MATRIX **
COSDG = COS ( DGAMMA )
SINDG = SIN ( DGAMMA )
C ** PERFORM ROTATIONS **
IF ( IAXIS .EQ. 1 ) THEN
EXINEW = EXIOLD
EYINEW = COSDG * EYIOLD + SINDG * EZIOLD
EZINEW = COSDG * EZIOLD - SINDG * EYIOLD
ELSE IF ( IAXIS .EQ. 2 ) THEN
EXINEW = COSDG * EXIOLD - SINDG * EZIOLD
EYINEW = EYIOLD
EZINEW = COSDG * EZIOLD + SINDG * EXIOLD
ELSE
EXINEW = COSDG * EXIOLD + SINDG * EYIOLD
EYINEW = COSDG * EYIOLD - SINDG * EXIOLD
EZINEW = EZIOLD
ENDIF
RETURN
END
SUBROUTINE FLIP3 ( EXIOLD, EYIOLD, EZIOLD, DOTMIN,
: EXINEW, EYINEW, EZINEW )
C *******************************************************************
C ** CHOOSES A RANDOM DISPLACEMENT ON THE SURFACE OF A UNIT SPHERE.**
C ** **
C ** REFERENCE: **
C ** **
C ** MARSAGLIA, ANN MATHS STAT 43, 645, 1972. **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** REAL DOT DOT PRODUCT OF OLD AND NEW **
C ** AXIAL VECTORS **
C ** REAL DOTMIN PARAMETER TO ADJUST MAXIMUM **
C ** DISPLACEMENT. DOTMIN SHOULD **
C ** BE LESS THAN ONE **
C ** **
C ** USAGE: **
C ** **
C ** FLIP3 USES A REJECTION TECHNIQUE TO CREATE A TRIAL **
C ** ORIENTATION OF MOLECULE I SUBJECT TO THE CONSTRAINT THAT **
C ** THE COSINE OF THE ANGLE BETWEEN THE OLD AND NEW AXIAL **
C ** VECTORS IS GREATER THAN ( 1.0 - DOTMIN ). **
C *******************************************************************
REAL EXIOLD, EYIOLD, EZIOLD, EXINEW, EYINEW, EZINEW, DOTMIN
REAL DOT, XI1, XI2, XI, XISQ
REAL RANF, DUMMY
C *******************************************************************
C ** INITIALISE DOT **
DOT = 0.0
C ** ITERATIVE LOOP **
1000 IF ( ( 1.0 - DOT ) .GE. DOTMIN ) THEN
C ** INITIALISE XISQ **
XISQ = 1.0
C ** INNER ITERATIVE LOOP **
2000 IF ( XISQ .GE. 1.0 ) THEN
XI1 = RANF ( DUMMY ) * 2.0 - 1.0
XI2 = RANF ( DUMMY ) * 2.0 - 1.0
XISQ = XI1 * XI1 + XI2 * XI2
GOTO 2000
ENDIF
XI = SQRT ( 1.0 - XISQ )
EXINEW = 2.0 * XI1 * XI
EYINEW = 2.0 * XI2 * XI
EZINEW = 1.0 - 2.0 * XISQ
DOT = EXINEW * EXIOLD + EYINEW * EYIOLD + EZINEW * EZIOLD
GOTO 1000
ENDIF
RETURN
END