-
Notifications
You must be signed in to change notification settings - Fork 1
/
angles.c
executable file
·254 lines (154 loc) · 6.2 KB
/
angles.c
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
This file is part of ftdock, a program for rigid-body protein-protein docking
Copyright (C) 1997-2000 Henry Gabb/Gidon Moont
Biomolecular Modelling Laboratory
Imperial Cancer Research Fund
44 Lincoln's Inn Fields
London WC2A 3PX
+44 (0)20 7269 3565
http://www.bmm.icnet.uk/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "structures.h"
struct Angle generate_global_angles( int angle_step ) {
/************/
/* Counters */
int n ;
/* Variables */
int z_twist , theta , phi ;
int phi_step_for_this_theta ;
/* What the data is going into */
struct Angle Angles ;
/************/
if( ( Angles.z_twist = ( int * ) malloc ( MAX_ROTATIONS * sizeof( int ) ) ) &&
( Angles.theta = ( int * ) malloc ( MAX_ROTATIONS * sizeof( int ) ) ) &&
( Angles.phi = ( int * ) malloc ( MAX_ROTATIONS * sizeof( int ) ) ) ) {
} else {
GENERAL_MEMORY_PROBLEM
}
n = 0 ;
theta = 0 ;
phi = 0 ;
/************/
if( ( 180 % angle_step ) != 0 ) {
printf( "Bad angle step chosen\nPlease choose a value which is an integer factor of 180\nDying\n\n" ) ;
exit( EXIT_FAILURE ) ;
}
if( angle_step < 9 ) {
printf( "Sorry, but I refuse to do so many rotations (more than 70 thousand). Think again.\nIf you insist then you will have to check the byte size of an integer on your machine and possibly change all my ints to longs\nDying\n\n" ) ;
exit( EXIT_FAILURE ) ;
}
/************/
for( z_twist = 0 ; z_twist < 360 ; z_twist += angle_step ) {
n ++ ;
Angles.z_twist[n] = z_twist ;
Angles.theta[n] = 0 ;
Angles.phi[n] = 0 ;
}
for( theta = angle_step ; theta < 180 ; theta += angle_step ) {
phi_step_for_this_theta = 57.29578 * acos( ( cos( 0.017453293 * angle_step ) - ( cos( 0.017453293 * theta ) * cos( 0.017453293 * theta ) ) ) / ( sin( 0.017453293 * theta ) * sin( 0.017453293 * theta ) ) ) ;
while( ( 360 % phi_step_for_this_theta ) != 0 ) phi_step_for_this_theta -- ;
for( phi = 0 ; phi < 360 ; phi += phi_step_for_this_theta ) {
for( z_twist = 0 ; z_twist < 360 ; z_twist += angle_step ) {
n ++ ;
Angles.z_twist[n] = z_twist ;
Angles.theta[n] = theta ;
Angles.phi[n] = phi ;
}
}
}
for( z_twist = 0 ; z_twist < 360 ; z_twist += angle_step ) {
n ++ ;
Angles.z_twist[n] = z_twist ;
Angles.theta[n] = 180 ;
Angles.phi[n] = 0 ;
}
/************/
if( n >= MAX_ROTATIONS ) {
printf( "You have exceeded the MAX_ROTATIONS constant.\nEither choose a larger angle_step or recompile after editing structures.h\nDying\n\n" ) ;
exit( EXIT_FAILURE ) ;
}
if( ( Angles.z_twist = ( int * ) realloc ( Angles.z_twist , ( 1 + n ) * sizeof( int ) ) ) &&
( Angles.theta = ( int * ) realloc ( Angles.theta , ( 1 + n ) * sizeof( int ) ) ) &&
( Angles.phi = ( int * ) realloc ( Angles.phi , ( 1 + n ) * sizeof( int ) ) ) ) {
} else {
GENERAL_MEMORY_PROBLEM
}
Angles.n = n ;
/************/
return Angles ;
}
/************************/
struct Angle generate_range_of_angles( int angle_step , int angle_range , int z_twist , int theta , int phi ) {
/************/
/* Counters */
int n ;
/* Variables */
int z_twist_step , theta_step , phi_step ;
int phi_step_for_this_theta ;
int this_z_twist_step , this_phi_step ;
/* What the data is going into */
struct Angle Angles ;
/************/
if( ( Angles.z_twist = ( int * ) malloc ( MAX_ROTATIONS * sizeof( int ) ) ) &&
( Angles.theta = ( int * ) malloc ( MAX_ROTATIONS * sizeof( int ) ) ) &&
( Angles.phi = ( int * ) malloc ( MAX_ROTATIONS * sizeof( int ) ) ) ) {
} else {
GENERAL_MEMORY_PROBLEM
}
/************/
n = 0 ;
if( angle_range != 0 ) angle_range = angle_step * (int)( angle_range / angle_step ) ;
/************/
phi_step_for_this_theta = 57.29578 * acos( ( cos( 0.017453293 * angle_step ) - ( cos( 0.017453293 * theta ) * cos( 0.017453293 * theta ) ) ) / ( sin( 0.017453293 * theta ) * sin( 0.017453293 * theta ) ) ) ;
while( ( 360 % phi_step_for_this_theta ) != 0 ) phi_step_for_this_theta -- ;
/************/
for( z_twist_step = z_twist - angle_range ; z_twist_step <= z_twist + angle_range ; z_twist_step += angle_step ) {
this_z_twist_step = z_twist_step ;
if( this_z_twist_step >= 360 ) this_z_twist_step -= 360 ;
if( this_z_twist_step < 0 ) this_z_twist_step += 360 ;
n ++ ;
Angles.z_twist[n] = this_z_twist_step ;
Angles.theta[n] = theta ;
Angles.phi[n] = phi ;
}
for( theta_step = max( theta - angle_range , 0 ) ; theta_step <= min( theta + angle_range , 180 ) ; theta_step += angle_step ) {
if( theta_step != theta ) {
n ++ ;
Angles.z_twist[n] = z_twist ;
Angles.theta[n] = theta_step ;
Angles.phi[n] = phi ;
}
}
for( phi_step = phi - angle_range ; phi_step <= phi + angle_range ; phi_step += angle_step ) {
if( phi_step != phi ) {
this_phi_step = phi_step ;
if( this_phi_step >= 360 ) this_phi_step -= 360 ;
if( this_phi_step < 0 ) this_phi_step += 360 ;
n ++ ;
Angles.z_twist[n] = z_twist ;
Angles.theta[n] = theta ;
Angles.phi[n] = this_phi_step ;
}
}
/************/
if( ( Angles.z_twist = ( int * ) realloc ( Angles.z_twist , ( 1 + n ) * sizeof( int ) ) ) &&
( Angles.theta = ( int * ) realloc ( Angles.theta , ( 1 + n ) * sizeof( int ) ) ) &&
( Angles.phi = ( int * ) realloc ( Angles.phi , ( 1 + n ) * sizeof( int ) ) ) ) {
} else {
GENERAL_MEMORY_PROBLEM
}
Angles.n = n ;
/************/
return Angles ;
}