1 |
|
#include <stdio.h> |
2 |
|
#include <stdlib.h> |
3 |
|
#include <string.h> |
4 |
– |
#include <math.h> |
4 |
|
|
5 |
|
|
7 |
– |
#include "madProps.h" |
8 |
– |
#include "frameCount.h" |
9 |
– |
|
6 |
|
char *program_name; /*the name of the program */ |
11 |
– |
|
7 |
|
void usage(void); |
8 |
|
|
9 |
|
int main(argc, argv) |
10 |
|
int argc; |
11 |
|
char *argv[]; |
12 |
|
{ |
18 |
– |
|
19 |
– |
|
20 |
– |
struct xyz_frame *dumpArray; |
21 |
– |
int nFrames; // the nu8mvber of frames |
22 |
– |
int lineNum = 0; // keeps track of the line number |
23 |
– |
int n_atoms; // the number of atoms |
13 |
|
int i,j; // loop counters |
25 |
– |
int isFirst; |
14 |
|
|
15 |
< |
char read_buffer[2000]; /*the line buffer for reading */ |
16 |
< |
char *foo; /*the pointer to the current string token */ |
17 |
< |
FILE *in_file; /* the input file */ |
30 |
< |
char *in_name = NULL; /*the name of the input file */ |
31 |
< |
char *out_prefix; // the output prefix |
32 |
< |
char current_flag; // used in parseing the flags |
33 |
< |
|
34 |
< |
|
35 |
< |
|
15 |
> |
char *in_name = NULL; // name of the input file |
16 |
> |
char* out_prefix = NULL; // the output prefix |
17 |
> |
char current_flag; // used in parsing the flags |
18 |
|
int done = 0; // multipurpose boolean |
19 |
< |
int have_prefix = 0; // prefix boolean |
38 |
< |
int calcRMSD = 0; |
19 |
> |
int have_prefix; // boolean for the output prefix |
20 |
|
|
40 |
– |
int calcGofR = 0; |
41 |
– |
char gofR1[30]; |
42 |
– |
char gofR2[30]; |
43 |
– |
|
44 |
– |
int calcMuCorr = 0; |
45 |
– |
char muCorr[30]; |
46 |
– |
|
47 |
– |
int calcCosCorr = 0; |
48 |
– |
char cosCorr1[30]; |
49 |
– |
char cosCorr2[30]; |
50 |
– |
|
51 |
– |
int startFrame = 0; |
52 |
– |
int haveStartFrame = 0; |
53 |
– |
int endFrame = 0; |
54 |
– |
int haveEndFrame = 0; |
55 |
– |
|
56 |
– |
program_name = argv[0]; /*save the program name in case we need it*/ |
21 |
|
|
22 |
+ |
// here we set the name of the program need by the usage message |
23 |
+ |
program_name = argv[0]; |
24 |
+ |
|
25 |
+ |
|
26 |
|
for( i = 1; i < argc; i++){ |
27 |
|
|
28 |
|
if(argv[i][0] =='-'){ |
146 |
|
} |
147 |
|
|
148 |
|
if( !have_prefix ) out_prefix = in_name; |
181 |
– |
|
182 |
– |
printf( "Counting number of frames..." ); |
183 |
– |
fflush( stdout ); |
184 |
– |
|
185 |
– |
nFrames = frameCount( in_name ); |
186 |
– |
if( !haveEndFrame ) endFrame = nFrames; |
187 |
– |
|
188 |
– |
printf( "done.\n" |
189 |
– |
"nframes = %d\n" |
190 |
– |
"\n", |
191 |
– |
nFrames ); |
192 |
– |
fflush( stdout ); |
193 |
– |
|
194 |
– |
in_file = fopen(in_name, "r"); |
195 |
– |
if(in_file == NULL){ |
196 |
– |
printf("Cannot open file: %s\n", in_name); |
197 |
– |
exit(8); |
198 |
– |
} |
199 |
– |
|
200 |
– |
// create and initialize the array of frames |
201 |
– |
|
202 |
– |
dumpArray = (struct xyz_frame*)calloc( nFrames, |
203 |
– |
sizeof( struct xyz_frame ) ); |
204 |
– |
for( i=0; i<nFrames; i++ ){ |
205 |
– |
dumpArray[i].nAtoms = 0; |
206 |
– |
dumpArray[i].time = 0.0; |
207 |
– |
dumpArray[i].boxX = 0.0; |
208 |
– |
dumpArray[i].boxY = 0.0; |
209 |
– |
dumpArray[i].boxZ = 0.0; |
210 |
– |
dumpArray[i].r = NULL; |
211 |
– |
dumpArray[i].v = NULL; |
212 |
– |
dumpArray[i].names = NULL; |
213 |
– |
} |
214 |
– |
|
215 |
– |
// read the frames |
216 |
– |
|
217 |
– |
printf( "Reading the frames into the coordinate arrays..." ); |
218 |
– |
fflush( stdout ); |
219 |
– |
|
220 |
– |
isFirst = 1; |
221 |
– |
for(j =0; j<nFrames; j++ ){ |
222 |
– |
|
223 |
– |
// read the number of atoms |
224 |
– |
|
225 |
– |
fgets(read_buffer, sizeof(read_buffer), in_file); |
226 |
– |
lineNum++; |
227 |
– |
|
228 |
– |
n_atoms = atoi( read_buffer ); |
229 |
– |
dumpArray[j].nAtoms = n_atoms; |
230 |
– |
|
231 |
– |
dumpArray[j].r = |
232 |
– |
(struct coords *)calloc(n_atoms, sizeof(struct coords)); |
233 |
– |
|
234 |
– |
if( isFirst ) { |
235 |
– |
dumpArray[0].names = |
236 |
– |
(atomID *)calloc( n_atoms, sizeof(atomID) ); |
237 |
– |
isFirst = 0; |
238 |
– |
} |
239 |
– |
|
240 |
– |
if( calcMuCorr || calcCosCorr ){ |
241 |
– |
dumpArray[j].v = |
242 |
– |
(struct vect *)calloc(n_atoms, sizeof(struct vect)); |
243 |
– |
} |
244 |
– |
|
245 |
– |
//read the time and the box sizes |
246 |
– |
|
247 |
– |
fgets(read_buffer, sizeof(read_buffer), in_file); |
248 |
– |
lineNum++; |
249 |
– |
|
250 |
– |
foo = strtok(read_buffer, " ,;\t"); |
251 |
– |
if(foo == NULL){ |
252 |
– |
printf("error in reading time at line %d\n", lineNum); |
253 |
– |
exit(8); |
254 |
– |
} |
255 |
– |
|
256 |
– |
dumpArray[j].time = atof( foo ); |
257 |
– |
|
258 |
– |
foo = strtok(NULL, " ,;\t"); |
259 |
– |
if(foo == NULL){ |
260 |
– |
printf("error in reading boxX at line %d\n", lineNum); |
261 |
– |
exit(8); |
262 |
– |
} |
263 |
– |
|
264 |
– |
dumpArray[j].boxX = atof( foo ); |
265 |
– |
|
266 |
– |
foo = strtok(NULL, " ,;\t"); |
267 |
– |
if(foo == NULL){ |
268 |
– |
printf("error in reading boxY at line %d\n", lineNum); |
269 |
– |
exit(8); |
270 |
– |
} |
271 |
– |
|
272 |
– |
dumpArray[j].boxY = atof( foo ); |
273 |
– |
|
274 |
– |
foo = strtok(NULL, " ,;\t"); |
275 |
– |
if(foo == NULL){ |
276 |
– |
printf("error in reading boxZ at line %d\n", lineNum); |
277 |
– |
exit(8); |
278 |
– |
} |
279 |
– |
|
280 |
– |
dumpArray[j].boxZ = atof( foo ); |
281 |
– |
|
282 |
– |
|
283 |
– |
for( i=0; i < n_atoms; i++){ |
284 |
– |
|
285 |
– |
fgets(read_buffer, sizeof(read_buffer), in_file); |
286 |
– |
lineNum++; |
287 |
– |
|
288 |
– |
// get the name and positions |
289 |
– |
|
290 |
– |
foo = strtok(read_buffer, " ,;\t"); |
291 |
– |
if(foo == NULL){ |
292 |
– |
printf("error in reading atom name at line %d\n", lineNum ); |
293 |
– |
exit(8); |
294 |
– |
} |
295 |
– |
|
296 |
– |
strcpy(dumpArray[0].names[i], foo); /*copy the atom name */ |
149 |
|
|
298 |
– |
foo = strtok(NULL, " ,;\t"); |
299 |
– |
if(foo == NULL){ |
300 |
– |
printf("error in reading position x at line %d\n", lineNum); |
301 |
– |
exit(8); |
302 |
– |
} |
303 |
– |
|
304 |
– |
dumpArray[j].r[i].x = atof( foo ); |
305 |
– |
|
306 |
– |
foo = strtok(NULL, " ,;\t"); |
307 |
– |
if(foo == NULL){ |
308 |
– |
printf("error in reading position y at line %d\n", lineNum); |
309 |
– |
exit(8); |
310 |
– |
} |
311 |
– |
|
312 |
– |
dumpArray[j].r[i].y = atof( foo ); |
313 |
– |
|
314 |
– |
foo = strtok(NULL, " ,;\t"); |
315 |
– |
if(foo == NULL){ |
316 |
– |
printf("error in reading position z at line %d\n", lineNum); |
317 |
– |
exit(8); |
318 |
– |
} |
319 |
– |
|
320 |
– |
dumpArray[j].r[i].z = atof( foo ); |
321 |
– |
|
322 |
– |
if( calcCosCorr || calcMuCorr ){ |
323 |
– |
|
324 |
– |
foo = strtok(NULL, " ,;\t"); |
325 |
– |
if(foo == NULL){ |
326 |
– |
|
327 |
– |
dumpArray[j].v[i].x = 0.0; |
328 |
– |
dumpArray[j].v[i].y = 0.0; |
329 |
– |
dumpArray[j].v[i].z = 0.0; |
330 |
– |
} |
331 |
– |
else{ |
332 |
– |
|
333 |
– |
dumpArray[j].v[i].x = atof( foo ); |
334 |
– |
|
335 |
– |
foo = strtok(NULL, " ,;\t"); |
336 |
– |
if(foo == NULL){ |
337 |
– |
printf("error in reading vector y at line %d\n", lineNum); |
338 |
– |
exit(8); |
339 |
– |
} |
340 |
– |
|
341 |
– |
dumpArray[j].v[i].y = atof( foo ); |
342 |
– |
|
343 |
– |
foo = strtok(NULL, " ,;\t"); |
344 |
– |
if(foo == NULL){ |
345 |
– |
printf("error in reading vector z at line %d\n", lineNum); |
346 |
– |
exit(8); |
347 |
– |
} |
348 |
– |
|
349 |
– |
dumpArray[j].v[i].z = atof( foo ); |
350 |
– |
} |
351 |
– |
} |
352 |
– |
|
353 |
– |
} |
354 |
– |
} |
355 |
– |
|
356 |
– |
(void)fclose(in_file); |
357 |
– |
|
358 |
– |
printf( "done\n" |
359 |
– |
"\n" ); |
360 |
– |
fflush( stdout ); |
361 |
– |
|
362 |
– |
|
363 |
– |
|
364 |
– |
// do calculations here. |
365 |
– |
|
366 |
– |
if( calcGofR ){ |
367 |
– |
|
368 |
– |
fprintf( stdout, |
369 |
– |
"Calculating the g(r) between atoms \"%s\" and \"%s\"...", |
370 |
– |
gofR1, gofR2 ); |
371 |
– |
fflush( stdout ); |
372 |
– |
|
373 |
– |
// gofr call |
374 |
– |
GofR( out_prefix, gofR1, gofR2, dumpArray, nFrames, startFrame, endFrame ); |
375 |
– |
|
376 |
– |
fprintf( stdout, |
377 |
– |
" done.\n" |
378 |
– |
"\n"); |
379 |
– |
fflush(stdout); |
380 |
– |
} |
381 |
– |
|
382 |
– |
if( calcRMSD ){ |
383 |
– |
|
384 |
– |
fprintf( stdout, |
385 |
– |
"Calculating the RMSD..." ); |
386 |
– |
fflush( stdout ); |
387 |
– |
|
388 |
– |
// RMSD call |
389 |
– |
|
390 |
– |
|
391 |
– |
fprintf( stdout, |
392 |
– |
" done.\n" |
393 |
– |
"\n"); |
394 |
– |
fflush(stdout); |
395 |
– |
} |
396 |
– |
|
397 |
– |
if( calcMuCorr ){ |
398 |
– |
|
399 |
– |
fprintf( stdout, |
400 |
– |
"Calculating the mu correlation for \"%s\"...", |
401 |
– |
muCorr); |
402 |
– |
fflush( stdout ); |
403 |
– |
|
404 |
– |
// muCorr call |
405 |
– |
|
406 |
– |
|
407 |
– |
fprintf( stdout, |
408 |
– |
" done.\n" |
409 |
– |
"\n"); |
410 |
– |
fflush(stdout); |
411 |
– |
} |
412 |
– |
|
413 |
– |
if( calcCosCorr ){ |
414 |
– |
|
415 |
– |
fprintf( stdout, |
416 |
– |
"Calculating the cos correlation between \"%s\" and \"%s\"...", |
417 |
– |
cosCorr1, cosCorr2 ); |
418 |
– |
fflush( stdout ); |
419 |
– |
|
420 |
– |
cosCorr( out_prefix, cosCorr1, cosCorr2, dumpArray, nFrames, startFrame, |
421 |
– |
endFrame ); |
422 |
– |
|
423 |
– |
fprintf( stdout, |
424 |
– |
" done.\n" |
425 |
– |
"\n"); |
426 |
– |
fflush(stdout); |
427 |
– |
} |
428 |
– |
|
429 |
– |
return 0; |
430 |
– |
|
150 |
|
} |
151 |
|
|
152 |
|
|
434 |
– |
void map( double *x, double *y, double *z, |
435 |
– |
double boxX, double boxY, double boxZ ){ |
436 |
– |
|
437 |
– |
*x -= boxX * copysign(1.0,*x) * floor( fabs( *x/boxX ) + 0.5 ); |
438 |
– |
*y -= boxY * copysign(1.0,*y) * floor( fabs( *y/boxY ) + 0.5 ); |
439 |
– |
*z -= boxZ * copysign(1.0,*z) * floor( fabs( *z/boxZ ) + 0.5 ); |
440 |
– |
|
441 |
– |
} |
442 |
– |
|
443 |
– |
|
153 |
|
/*************************************************************************** |
154 |
|
* prints out the usage for the command line arguments, then exits. |
155 |
|
***************************************************************************/ |
156 |
|
|
157 |
|
void usage(){ |
158 |
|
(void)fprintf(stdout, |
159 |
< |
"The proper usage is: %s [options] <xyz_file>\n" |
159 |
> |
"The proper usage is: %s [options] <input_file>\n" |
160 |
|
"\n" |
161 |
|
"Options:\n" |
162 |
|
"\n" |
163 |
|
" short:\n" |
164 |
|
" ------\n" |
165 |
|
" -h Display this message\n" |
166 |
< |
" -o <prefix> The output prefix\n" |
167 |
< |
" -r Calculate the RMSD\n" |
168 |
< |
" -g Calculate all to all g(r)\n" |
166 |
> |
" -o <name> The output name/prefix\n" |
167 |
> |
" -r the r flag\n" |
168 |
> |
" -i <#> set number to <#>\n" |
169 |
|
|
170 |
|
"\n" |
171 |
|
" long:\n" |
172 |
|
" -----\n" |
173 |
< |
" --GofR <atom1> <atom2> Calculates g(r) between atom1 and atom 2\n" |
174 |
< |
" -note: \"all\" will do all atoms\n" |
175 |
< |
" --MuCorr <atom> Calculate mu correlation of atom\n" |
467 |
< |
" --CosCorr <atom1> <atom2> Calculate the cos correlation between atom1 and atom2\n" |
468 |
< |
" --startFrame <frame#> Specifies a frame to start correlating\n" |
469 |
< |
" --endFrame <frame#> Specifies a frame to stop correlating.\n" |
173 |
> |
" --flag1 <arg1> <arg2> does flag 1 for arg1 and 2\n" |
174 |
> |
" --flag2 <arg1> does flag 2 for arg1\n" |
175 |
> |
" --flag3 does flag 3\n" |
176 |
|
|
177 |
|
"\n" |
178 |
|
"\n", |