3 |
|
#include <string.h> |
4 |
|
#include <math.h> |
5 |
|
|
6 |
+ |
|
7 |
+ |
#include "madProps.h" |
8 |
|
#include "frameCount.h" |
9 |
|
|
8 |
– |
struct coords{ |
9 |
– |
double x; |
10 |
– |
double y; |
11 |
– |
double z; |
12 |
– |
char name[30]; |
13 |
– |
}; |
14 |
– |
|
15 |
– |
|
16 |
– |
struct xyz_frame{ |
17 |
– |
int nAtoms; |
18 |
– |
double time; |
19 |
– |
double boxX, boxY, boxZ; |
20 |
– |
struct coords *r; |
21 |
– |
}; |
22 |
– |
|
10 |
|
char *program_name; /*the name of the program */ |
11 |
|
|
12 |
|
void usage(void); |
27 |
|
char *foo; /*the pointer to the current string token */ |
28 |
|
FILE *in_file; /* the input file */ |
29 |
|
char *in_name = NULL; /*the name of the input file */ |
30 |
+ |
char *out_prefix; // the output prefix |
31 |
+ |
char current_flag; // used in parseing the flags |
32 |
|
|
33 |
|
|
34 |
+ |
|
35 |
+ |
int done = 0; // multipurpose boolean |
36 |
+ |
int have_prefix = 0; // prefix boolean |
37 |
+ |
int calcRMSD = 0; |
38 |
+ |
|
39 |
+ |
int calcGofR = 0; |
40 |
+ |
char gofR1[30]; |
41 |
+ |
char gofR2[30]; |
42 |
+ |
|
43 |
+ |
int calcMuCorr = 0; |
44 |
+ |
char muCorr[30]; |
45 |
+ |
|
46 |
+ |
int calcCosCorr = 0; |
47 |
+ |
char cosCorr1[30]; |
48 |
+ |
char cosCorr2[30]; |
49 |
+ |
|
50 |
+ |
|
51 |
+ |
|
52 |
|
program_name = argv[0]; /*save the program name in case we need it*/ |
53 |
|
|
54 |
< |
for( i = 0; i < argc; i++){ |
54 |
> |
for( i = 1; i < argc; i++){ |
55 |
|
|
56 |
|
if(argv[i][0] =='-'){ |
57 |
+ |
|
58 |
+ |
// parse the option |
59 |
|
|
60 |
< |
/* argv[i][1] is the actual option character */ |
60 |
> |
if(argv[i][1] == '-' ){ |
61 |
> |
|
62 |
> |
// parse long word options |
63 |
> |
|
64 |
> |
if( !strcmp( argv[i], "--GofR" ) ){ |
65 |
> |
calcGofR = 1; |
66 |
> |
i++; |
67 |
> |
strcpy( gofR1, argv[i] ); |
68 |
> |
i++; |
69 |
> |
strcpy( gofR2, argv[i] ); |
70 |
> |
} |
71 |
> |
|
72 |
> |
else if( !strcmp( argv[i], "--MuCorr") ){ |
73 |
> |
calcMuCorr = 1; |
74 |
> |
i++; |
75 |
> |
strcpy( muCorr, argv[i] ); |
76 |
> |
} |
77 |
> |
|
78 |
> |
else if( !strcmp( argv[i], "--CosCorr" ) ){ |
79 |
> |
calcCosCorr = 1; |
80 |
> |
i++; |
81 |
> |
strcpy( cosCorr1, argv[i] ); |
82 |
> |
i++; |
83 |
> |
strcpy( cosCorr2, argv[i] ); |
84 |
> |
} |
85 |
> |
|
86 |
> |
else{ |
87 |
> |
fprintf( stderr, |
88 |
> |
"Invalid option \"%s\"\n", argv[i] ); |
89 |
> |
usage(); |
90 |
> |
} |
91 |
> |
} |
92 |
|
|
93 |
< |
switch(argv[i][1]){ |
93 |
> |
else{ |
94 |
|
|
95 |
< |
/* -f <name> => the xyz input file |
96 |
< |
* [i+1] actually starts the name |
97 |
< |
*/ |
95 |
> |
// parse single character options |
96 |
> |
|
97 |
> |
done =0; |
98 |
> |
j = 1; |
99 |
> |
current_flag = argv[i][j]; |
100 |
> |
while( (current_flag != '\0') && (!done) ){ |
101 |
> |
|
102 |
> |
switch(current_flag){ |
103 |
|
|
104 |
< |
case 'f': |
105 |
< |
in_name = argv[i+1]; |
61 |
< |
break; |
104 |
> |
case 'o': |
105 |
> |
// -o <prefix> => the output prefix. |
106 |
|
|
107 |
< |
default: |
108 |
< |
(void)fprintf(stderr, "Bad option %s\n", argv[i]); |
107 |
> |
i++; |
108 |
> |
out_prefix = argv[i]; |
109 |
> |
have_prefix = 1; |
110 |
> |
done = 1; |
111 |
> |
break; |
112 |
> |
|
113 |
> |
case 'h': |
114 |
> |
// -h => give the usage |
115 |
> |
|
116 |
> |
usage(); |
117 |
> |
break; |
118 |
> |
|
119 |
> |
case 'r': |
120 |
> |
// calculates the rmsd |
121 |
> |
|
122 |
> |
calcRMSD = 1; |
123 |
> |
break; |
124 |
> |
|
125 |
> |
case 'g': |
126 |
> |
// calculate all to all g(r) |
127 |
> |
|
128 |
> |
calcGofR = 1; |
129 |
> |
strcpy( gofR1, "all" ); |
130 |
> |
strcpy( gofR2, "all" ); |
131 |
> |
break; |
132 |
> |
|
133 |
> |
default: |
134 |
> |
|
135 |
> |
fprintf( stderr, "about to print bad option\n" ); |
136 |
> |
|
137 |
> |
(void)fprintf(stderr, "Bad option \"-%s\"\n", current_flag); |
138 |
> |
usage(); |
139 |
> |
} |
140 |
> |
j++; |
141 |
> |
current_flag = argv[i][j]; |
142 |
> |
} |
143 |
> |
} |
144 |
> |
} |
145 |
> |
|
146 |
> |
else{ |
147 |
> |
|
148 |
> |
if( in_name != NULL ){ |
149 |
> |
fprintf( stderr, |
150 |
> |
"Error at \"%s\", program does not currently support\n" |
151 |
> |
"more than one input file.\n" |
152 |
> |
"\n", |
153 |
> |
argv[i]); |
154 |
|
usage(); |
155 |
|
} |
156 |
+ |
|
157 |
+ |
in_name = argv[i]; |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
|
if(in_name == NULL){ |
162 |
|
usage(); |
163 |
|
} |
164 |
+ |
|
165 |
+ |
if( !have_prefix ) out_prefix = in_name; |
166 |
|
|
167 |
|
printf( "Counting number of frames..." ); |
168 |
|
fflush( stdout ); |
204 |
|
dumpArray[j].r = |
205 |
|
(struct coords *)calloc(n_atoms, sizeof(struct coords)); |
206 |
|
|
207 |
+ |
if( calcMuCorr || calcCosCorr ){ |
208 |
+ |
dumpArray[j].v = |
209 |
+ |
(struct vect *)calloc(n_atoms, sizeof(struct vect)); |
210 |
+ |
} |
211 |
+ |
|
212 |
|
//read the time and the box sizes |
213 |
|
|
214 |
|
fgets(read_buffer, sizeof(read_buffer), in_file); |
285 |
|
} |
286 |
|
|
287 |
|
dumpArray[j].r[i].z = atof( foo ); |
288 |
< |
|
288 |
> |
|
289 |
> |
if( calcCosCorr || calcMuCorr ){ |
290 |
> |
|
291 |
> |
foo = strtok(NULL, " ,;\t"); |
292 |
> |
if(foo == NULL){ |
293 |
> |
|
294 |
> |
dumpArray[j].v[i].x = 0.0; |
295 |
> |
dumpArray[j].v[i].y = 0.0; |
296 |
> |
dumpArray[j].v[i].z = 0.0; |
297 |
> |
} |
298 |
> |
else{ |
299 |
> |
|
300 |
> |
dumpArray[j].v[i].x = atof( foo ); |
301 |
> |
|
302 |
> |
foo = strtok(NULL, " ,;\t"); |
303 |
> |
if(foo == NULL){ |
304 |
> |
printf("error in reading vector y at line %d\n", lineNum); |
305 |
> |
exit(8); |
306 |
> |
} |
307 |
> |
|
308 |
> |
dumpArray[j].v[i].y = atof( foo ); |
309 |
> |
|
310 |
> |
foo = strtok(NULL, " ,;\t"); |
311 |
> |
if(foo == NULL){ |
312 |
> |
printf("error in reading vector z at line %d\n", lineNum); |
313 |
> |
exit(8); |
314 |
> |
} |
315 |
> |
|
316 |
> |
dumpArray[j].v[i].z = atof( foo ); |
317 |
> |
} |
318 |
> |
} |
319 |
> |
|
320 |
|
} |
321 |
|
} |
322 |
|
|
330 |
|
|
331 |
|
// do calculations here. |
332 |
|
|
333 |
+ |
if( calcGofR ){ |
334 |
+ |
|
335 |
+ |
fprintf( stdout, |
336 |
+ |
"Calculating the g(r) between atoms \"%s\" and \"%s\"...", |
337 |
+ |
gofR1, gofR2 ); |
338 |
+ |
fflush( stdout ); |
339 |
+ |
|
340 |
+ |
// gofr call |
341 |
+ |
GofR( out_prefix, gofR1, gofR2, dumpArray, nFrames ); |
342 |
+ |
|
343 |
+ |
fprintf( stdout, |
344 |
+ |
" done.\n" |
345 |
+ |
"\n"); |
346 |
+ |
fflush(stdout); |
347 |
+ |
} |
348 |
|
|
349 |
< |
|
349 |
> |
if( calcRMSD ){ |
350 |
> |
|
351 |
> |
fprintf( stdout, |
352 |
> |
"Calculating the RMSD..." ); |
353 |
> |
fflush( stdout ); |
354 |
> |
|
355 |
> |
// RMSD call |
356 |
|
|
357 |
+ |
|
358 |
+ |
fprintf( stdout, |
359 |
+ |
" done.\n" |
360 |
+ |
"\n"); |
361 |
+ |
fflush(stdout); |
362 |
+ |
} |
363 |
|
|
364 |
+ |
if( calcMuCorr ){ |
365 |
+ |
|
366 |
+ |
fprintf( stdout, |
367 |
+ |
"Calculating the mu correlation for \"%s\"...", |
368 |
+ |
muCorr); |
369 |
+ |
fflush( stdout ); |
370 |
+ |
|
371 |
+ |
// muCorr call |
372 |
|
|
373 |
+ |
|
374 |
+ |
fprintf( stdout, |
375 |
+ |
" done.\n" |
376 |
+ |
"\n"); |
377 |
+ |
fflush(stdout); |
378 |
+ |
} |
379 |
+ |
|
380 |
+ |
if( calcCosCorr ){ |
381 |
+ |
|
382 |
+ |
fprintf( stdout, |
383 |
+ |
"Calculating the cos correlation between \"%s\" and \"%s\"...", |
384 |
+ |
cosCorr1, cosCorr2 ); |
385 |
+ |
fflush( stdout ); |
386 |
+ |
|
387 |
+ |
// cosCorr call |
388 |
+ |
|
389 |
+ |
|
390 |
+ |
fprintf( stdout, |
391 |
+ |
" done.\n" |
392 |
+ |
"\n"); |
393 |
+ |
fflush(stdout); |
394 |
+ |
} |
395 |
|
|
396 |
+ |
|
397 |
|
return 0; |
398 |
|
|
399 |
|
} |
405 |
|
***************************************************************************/ |
406 |
|
|
407 |
|
void usage(){ |
408 |
< |
(void)fprintf(stderr, |
409 |
< |
"The proper usage is: %s [options] -f <xyz_file>\n\n" |
410 |
< |
"Options:\n", |
408 |
> |
(void)fprintf(stdout, |
409 |
> |
"The proper usage is: %s [options] <xyz_file>\n" |
410 |
> |
"\n" |
411 |
> |
"Options:\n" |
412 |
> |
"\n" |
413 |
> |
" short:\n" |
414 |
> |
" ------\n" |
415 |
> |
" -h Display this message\n" |
416 |
> |
" -o <prefix> The output prefix\n" |
417 |
> |
" -r Calculate the RMSD\n" |
418 |
> |
" -g Calculate all to all g(r)\n" |
419 |
> |
|
420 |
> |
"\n" |
421 |
> |
" long:\n" |
422 |
> |
" -----\n" |
423 |
> |
" --GofR <atom1> <atom2> Calculates g(r) between atom1 and atom 2\n" |
424 |
> |
" -note: \"all\" will do all atoms\n" |
425 |
> |
" --MuCorr <atom> Calculate mu correlation of atom\n" |
426 |
> |
" --CosCorr <atom1> <atom2> Calculate the cos correlation between atom1 and atom2\n" |
427 |
> |
|
428 |
> |
|
429 |
> |
"\n" |
430 |
> |
"\n", |
431 |
|
program_name); |
432 |
|
exit(8); |
433 |
|
} |