-
Notifications
You must be signed in to change notification settings - Fork 5
/
centres.c
executable file
·307 lines (204 loc) · 9.05 KB
/
centres.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
Copyright (C) 1997-2000 Imperial Cancer Research Technology
author: Gidon Moont
Biomolecular Modelling Laboratory
Imperial Cancer Research Fund
44 Lincoln's Inn Fields
London WC2A 3PX
+44 (0)20 7269 3348
http://www.bmm.icnet.uk/
*/
#include "structures.h"
int main( int argc , char *argv[] ) {
/* index counters */
int i , j ;
int residue , atom , total_atoms ;
int length , atom_serial_number , residue_number ;
/* Command line options */
char *input_file_name ;
char *gf_type ;
char gf_one_letter_code ;
/* File stuff */
FILE *ftdock_file ;
char line_buffer[100] ;
char *static_file_name ;
char *mobile_file_name ;
/* Structures */
struct Structure Static_Structure , Mobile_Structure ;
struct Structure Centres_Structure , Origin_Mobile_Structure ;
struct Structure Rotated_at_Origin_Mobile_Structure , Translated_and_Rotated_at_Origin_Mobile_Structure ;
/* Co-ordinates and Angles */
int x , y , z , z_twist , theta, phi ;
float average_x , average_y , average_z ;
/* Grid stuff */
int grid_size ;
float grid_span , one_span ;
/* ftdock.dat file values */
int complex_id , prev_complex_id , SCscore ;
float RPscore ;
/************/
/* Its nice to tell people what going on straight away */
setvbuf( stdout , (char *)NULL , _IONBF , 0 ) ;
printf( "\n 3D-Dock Suite (May 2000)\n" ) ;
printf( " Copyright (C) 1997-2001 Imperial Cancer Research Technology\n" ) ;
printf( " Biomolecular Modelling Laboratory\n" ) ;
printf( " Imperial Cancer Research Fund\n" ) ;
printf( " 44 Lincoln's Inn Fields\n" ) ;
printf( " London WC2A 3PX\n" ) ;
printf( " +44 (0)20 7269 3565\n" ) ;
printf( " http://www.bmm.icnet.uk/\n\n" ) ;
printf( "Starting Centres central positions of mobile molecules program\n" ) ;
/************/
/* Memory allocation */
if( ( ( input_file_name = ( char * ) malloc ( 500 * sizeof( char ) ) ) == NULL ) ||
( ( gf_type = ( char * ) malloc ( 10 * sizeof( char ) ) ) == NULL ) ||
( ( static_file_name = ( char * ) malloc ( 500 * sizeof( char ) ) ) == NULL ) ||
( ( mobile_file_name = ( char * ) malloc ( 500 * sizeof( char ) ) ) == NULL ) ) {
GENERAL_MEMORY_PROBLEM
}
/************/
/* Command Line defaults */
strcpy( input_file_name , "ftdock_global.dat" ) ;
strcpy( gf_type , "G_DATA" ) ;
gf_one_letter_code = 'g' ;
/* Command Line parse */
for( i = 1 ; i < argc ; i ++ ) {
if( strcmp( argv[i] , "-in" ) == 0 ) {
i ++ ;
if( ( i == argc ) || ( strncmp( argv[i] , "-" , 1 ) == 0 ) ) {
printf( "Bad command line\n" ) ;
exit( EXIT_FAILURE ) ;
}
strcpy( input_file_name , argv[i] ) ;
} else {
if( strcmp( argv[i] , "-fine" ) == 0 ) {
strcpy( gf_type , "F_DATA" ) ;
gf_one_letter_code = 'f' ;
} else {
printf( "Bad command line\n" ) ;
exit( EXIT_FAILURE ) ;
}
}
}
/************/
/* Read neat data file - headers */
if( ( ftdock_file = fopen( input_file_name , "r" ) ) == NULL ) {
printf( "Could not open %s for reading.\nDying\n\n" , input_file_name ) ;
exit( EXIT_FAILURE ) ;
}
while( fgets( line_buffer, 99, ftdock_file ) ) {
if( strncmp( line_buffer , "Static molecule" , 15 ) == 0 ) sscanf( line_buffer , "Static molecule :: %s" , static_file_name ) ;
if( strncmp( line_buffer , "Mobile molecule" , 15 ) == 0 ) sscanf( line_buffer , "Mobile molecule :: %s" , mobile_file_name ) ;
if( gf_one_letter_code == 'g' ) {
if( strncmp( line_buffer , "Global grid size" , 16 ) == 0 ) sscanf( line_buffer , "Global grid size :: %d" , &grid_size ) ;
} else {
if( strncmp( line_buffer , "Refinement grid size" , 20 ) == 0 ) sscanf( line_buffer , "Refinement grid size :: %d" , &grid_size ) ;
}
if( strncmp( line_buffer , gf_type , 6 ) == 0 ) break ;
}
fclose( ftdock_file ) ;
/************/
/* Read in Structures from pdb files */
Static_Structure = read_pdb_to_structure( static_file_name ) ;
Mobile_Structure = read_pdb_to_structure( mobile_file_name ) ;
/************/
/* Store new structures centered on Origin */
Centres_Structure = translate_structure_onto_origin( Static_Structure ) ;
Origin_Mobile_Structure = translate_structure_onto_origin( Mobile_Structure ) ;
/* Free some memory */
for( i = 1 ; i <= Static_Structure.length ; i ++ ) {
free( Static_Structure.Residue[i].Atom ) ;
}
free( Static_Structure.Residue ) ;
for( i = 1 ; i <= Mobile_Structure.length ; i ++ ) {
free( Mobile_Structure.Residue[i].Atom ) ;
}
free( Mobile_Structure.Residue ) ;
/************/
/* Calculate Grid stuff */
grid_span = total_span_of_structures( Centres_Structure , Origin_Mobile_Structure ) ;
one_span = grid_span / (float)grid_size ;
/************/
/* Reopen ftdock.dat */
if( ( ftdock_file = fopen( input_file_name , "r" ) ) == NULL ) {
printf( "Could not open %s for reading.\nDying\n\n" , input_file_name ) ;
exit( EXIT_FAILURE ) ;
}
/************/
/* Loop */
length = Centres_Structure.length ;
atom_serial_number = Centres_Structure.Residue[length].Atom[1].serial + 100 ;
residue_number = 0 ;
while( fgets( line_buffer, 99, ftdock_file ) ) {
if( strncmp( line_buffer , gf_type , 6 ) == 0 ) {
sscanf( line_buffer + 1 , "_DATA %d %d %d %f %d %d %d %d %d %d" , &complex_id , &prev_complex_id , &SCscore , &RPscore , &x , &y , &z , &z_twist , &theta , &phi ) ;
/* Rotate Mobile Structure */
Rotated_at_Origin_Mobile_Structure = rotate_structure( Origin_Mobile_Structure , z_twist , theta , phi ) ;
/* Translate Mobile Structure */
Translated_and_Rotated_at_Origin_Mobile_Structure = translate_structure( Rotated_at_Origin_Mobile_Structure , (float)x * one_span , (float)y * one_span , (float)z * one_span ) ;
/* Find current centre of mobile structure */
total_atoms = 0 ;
average_x = 0 ;
average_y = 0 ;
average_z = 0 ;
for( residue = 1 ; residue <= Translated_and_Rotated_at_Origin_Mobile_Structure.length ; residue ++ ) {
for( atom = 1 ; atom <= Translated_and_Rotated_at_Origin_Mobile_Structure.Residue[residue].size ; atom ++ ) {
total_atoms ++ ;
average_x += Translated_and_Rotated_at_Origin_Mobile_Structure.Residue[residue].Atom[atom].coord[1] ;
average_y += Translated_and_Rotated_at_Origin_Mobile_Structure.Residue[residue].Atom[atom].coord[2] ;
average_z += Translated_and_Rotated_at_Origin_Mobile_Structure.Residue[residue].Atom[atom].coord[3] ;
}
}
average_x /= (float)total_atoms ;
average_y /= (float)total_atoms ;
average_z /= (float)total_atoms ;
/* Add centre */
length ++ ;
atom_serial_number ++ ;
residue_number ++ ;
if( ( Centres_Structure.Residue = (struct Amino_Acid * ) realloc ( Centres_Structure.Residue, ( length + 1 ) * sizeof_Amino_Acid ) ) == NULL ) {
GENERAL_MEMORY_PROBLEM
}
strcpy( Centres_Structure.Residue[length].chainID , "X" ) ;
sprintf( Centres_Structure.Residue[length].res_seq_plus_iCode , "%4d " , residue_number ) ;
strcpy( Centres_Structure.Residue[length].olc , "x" ) ;
Centres_Structure.Residue[length].nc = 0 ;
Centres_Structure.Residue[length].size = 1 ;
strcpy( Centres_Structure.Residue[length].res_name , "HOH" ) ;
if( ( Centres_Structure.Residue[length].Atom = ( struct Atom * ) malloc ( 2 * sizeof_Atom ) ) == NULL ) {
GENERAL_MEMORY_PROBLEM
}
Centres_Structure.Residue[length].Atom[1].serial = atom_serial_number ;
strcpy( Centres_Structure.Residue[length].Atom[1].atom_name, " O " ) ;
Centres_Structure.Residue[length].Atom[1].coord[1] = average_x ;
Centres_Structure.Residue[length].Atom[1].coord[2] = average_y ;
Centres_Structure.Residue[length].Atom[1].coord[3] = average_z ;
Centres_Structure.Residue[length].Atom[1].occupancy = 0.0 ;
Centres_Structure.Residue[length].Atom[1].temp_factor = 0.0 ;
/* Free some memory */
for( j = 1 ; j <= Rotated_at_Origin_Mobile_Structure.length ; j ++ ) {
free( Rotated_at_Origin_Mobile_Structure.Residue[j].Atom ) ;
free( Translated_and_Rotated_at_Origin_Mobile_Structure.Residue[j].Atom ) ;
}
free( Rotated_at_Origin_Mobile_Structure.Residue ) ;
free( Translated_and_Rotated_at_Origin_Mobile_Structure.Residue ) ;
}
}
/* End of Loop */
Centres_Structure.length = length ;
/* Write pdb file */
write_structure_to_pdb( Centres_Structure , "centres.pdb" ) ;
/************/
/* Free the memory */
for( i = 1 ; i <= Centres_Structure.length ; i ++ ) {
free( Centres_Structure.Residue[i].Atom ) ;
}
free( Centres_Structure.Residue ) ;
for( i = 1 ; i <= Origin_Mobile_Structure.length ; i ++ ) {
free( Origin_Mobile_Structure.Residue[i].Atom ) ;
}
free( Origin_Mobile_Structure.Residue ) ;
/************/
printf( "Finished\n\n" ) ;
return( 0 ) ;
} /* end main */