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); |
22 |
|
int lineNum = 0; // keeps track of the line number |
23 |
|
int n_atoms; // the number of atoms |
24 |
|
int i,j; // loop counters |
25 |
+ |
int isFirst; |
26 |
|
|
27 |
|
char read_buffer[2000]; /*the line buffer for reading */ |
28 |
|
char *foo; /*the pointer to the current string token */ |
29 |
|
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 |
+ |
|
36 |
+ |
int done = 0; // multipurpose boolean |
37 |
+ |
int have_prefix = 0; // prefix boolean |
38 |
+ |
int calcRMSD = 0; |
39 |
+ |
|
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*/ |
57 |
|
|
58 |
< |
for( i = 0; i < argc; i++){ |
58 |
> |
for( i = 1; i < argc; i++){ |
59 |
|
|
60 |
|
if(argv[i][0] =='-'){ |
61 |
+ |
|
62 |
+ |
// parse the option |
63 |
|
|
64 |
< |
/* argv[i][1] is the actual option character */ |
64 |
> |
if(argv[i][1] == '-' ){ |
65 |
> |
|
66 |
> |
// parse long word options |
67 |
> |
|
68 |
> |
if( !strcmp( argv[i], "--GofR" ) ){ |
69 |
> |
calcGofR = 1; |
70 |
> |
i++; |
71 |
> |
strcpy( gofR1, argv[i] ); |
72 |
> |
i++; |
73 |
> |
strcpy( gofR2, argv[i] ); |
74 |
> |
} |
75 |
> |
|
76 |
> |
else if( !strcmp( argv[i], "--CosCorr" ) ){ |
77 |
> |
calcCosCorr = 1; |
78 |
> |
i++; |
79 |
> |
strcpy( cosCorr1, argv[i] ); |
80 |
> |
i++; |
81 |
> |
strcpy( cosCorr2, argv[i] ); |
82 |
> |
} |
83 |
> |
|
84 |
> |
else if( !strcmp( argv[i], "--MuCorr") ){ |
85 |
> |
calcMuCorr = 1; |
86 |
> |
i++; |
87 |
> |
strcpy( muCorr, argv[i] ); |
88 |
> |
} |
89 |
> |
|
90 |
> |
else if( !strcmp( argv[i], "--startFrame" ) ){ |
91 |
> |
haveStartFrame = 1; |
92 |
> |
i++; |
93 |
> |
startFrame = atoi(argv[i]); |
94 |
> |
startFrame--; |
95 |
> |
} |
96 |
> |
|
97 |
> |
else if( !strcmp( argv[i], "--endFrame" ) ){ |
98 |
> |
haveEndFrame = 1; |
99 |
> |
i++; |
100 |
> |
endFrame = atoi(argv[i]); |
101 |
> |
} |
102 |
> |
|
103 |
> |
else{ |
104 |
> |
fprintf( stderr, |
105 |
> |
"Invalid option \"%s\"\n", argv[i] ); |
106 |
> |
usage(); |
107 |
> |
} |
108 |
> |
} |
109 |
|
|
110 |
< |
switch(argv[i][1]){ |
110 |
> |
else{ |
111 |
|
|
112 |
< |
/* -f <name> => the xyz input file |
113 |
< |
* [i+1] actually starts the name |
114 |
< |
*/ |
112 |
> |
// parse single character options |
113 |
> |
|
114 |
> |
done =0; |
115 |
> |
j = 1; |
116 |
> |
current_flag = argv[i][j]; |
117 |
> |
while( (current_flag != '\0') && (!done) ){ |
118 |
> |
|
119 |
> |
switch(current_flag){ |
120 |
|
|
121 |
< |
case 'f': |
122 |
< |
in_name = argv[i+1]; |
61 |
< |
break; |
121 |
> |
case 'o': |
122 |
> |
// -o <prefix> => the output prefix. |
123 |
|
|
124 |
< |
default: |
125 |
< |
(void)fprintf(stderr, "Bad option %s\n", argv[i]); |
124 |
> |
i++; |
125 |
> |
out_prefix = argv[i]; |
126 |
> |
have_prefix = 1; |
127 |
> |
done = 1; |
128 |
> |
break; |
129 |
> |
|
130 |
> |
case 'h': |
131 |
> |
// -h => give the usage |
132 |
> |
|
133 |
> |
usage(); |
134 |
> |
break; |
135 |
> |
|
136 |
> |
case 'r': |
137 |
> |
// calculates the rmsd |
138 |
> |
|
139 |
> |
calcRMSD = 1; |
140 |
> |
break; |
141 |
> |
|
142 |
> |
case 'g': |
143 |
> |
// calculate all to all g(r) |
144 |
> |
|
145 |
> |
calcGofR = 1; |
146 |
> |
strcpy( gofR1, "all" ); |
147 |
> |
strcpy( gofR2, "all" ); |
148 |
> |
break; |
149 |
> |
|
150 |
> |
default: |
151 |
> |
|
152 |
> |
fprintf( stderr, "about to print bad option\n" ); |
153 |
> |
|
154 |
> |
(void)fprintf(stderr, "Bad option \"-%s\"\n", current_flag); |
155 |
> |
usage(); |
156 |
> |
} |
157 |
> |
j++; |
158 |
> |
current_flag = argv[i][j]; |
159 |
> |
} |
160 |
> |
} |
161 |
> |
} |
162 |
> |
|
163 |
> |
else{ |
164 |
> |
|
165 |
> |
if( in_name != NULL ){ |
166 |
> |
fprintf( stderr, |
167 |
> |
"Error at \"%s\", program does not currently support\n" |
168 |
> |
"more than one input file.\n" |
169 |
> |
"\n", |
170 |
> |
argv[i]); |
171 |
|
usage(); |
172 |
|
} |
173 |
+ |
|
174 |
+ |
in_name = argv[i]; |
175 |
|
} |
176 |
|
} |
177 |
|
|
178 |
|
if(in_name == NULL){ |
179 |
|
usage(); |
180 |
|
} |
181 |
+ |
|
182 |
+ |
if( !have_prefix ) out_prefix = in_name; |
183 |
|
|
184 |
|
printf( "Counting number of frames..." ); |
185 |
|
fflush( stdout ); |
186 |
|
|
187 |
|
nFrames = frameCount( in_name ); |
188 |
+ |
if( !haveEndFrame ) endFrame = nFrames; |
189 |
|
|
190 |
|
printf( "done.\n" |
191 |
|
"nframes = %d\n" |
199 |
|
exit(8); |
200 |
|
} |
201 |
|
|
202 |
< |
// create the array of frames |
202 |
> |
// create and initialize the array of frames |
203 |
|
|
204 |
|
dumpArray = (struct xyz_frame*)calloc( nFrames, |
205 |
|
sizeof( struct xyz_frame ) ); |
206 |
+ |
for( i=0; i<nFrames; i++ ){ |
207 |
+ |
dumpArray[i].nAtoms = 0; |
208 |
+ |
dumpArray[i].time = 0.0; |
209 |
+ |
dumpArray[i].boxX = 0.0; |
210 |
+ |
dumpArray[i].boxY = 0.0; |
211 |
+ |
dumpArray[i].boxZ = 0.0; |
212 |
+ |
dumpArray[i].r = NULL; |
213 |
+ |
dumpArray[i].v = NULL; |
214 |
+ |
dumpArray[i].names = NULL; |
215 |
+ |
} |
216 |
|
|
217 |
|
// read the frames |
218 |
|
|
219 |
|
printf( "Reading the frames into the coordinate arrays..." ); |
220 |
|
fflush( stdout ); |
221 |
|
|
222 |
+ |
isFirst = 1; |
223 |
|
for(j =0; j<nFrames; j++ ){ |
224 |
|
|
225 |
|
// read the number of atoms |
232 |
|
|
233 |
|
dumpArray[j].r = |
234 |
|
(struct coords *)calloc(n_atoms, sizeof(struct coords)); |
235 |
+ |
|
236 |
+ |
if( isFirst ) { |
237 |
+ |
dumpArray[0].names = |
238 |
+ |
(atomID *)calloc( n_atoms, sizeof(atomID) ); |
239 |
+ |
isFirst = 0; |
240 |
+ |
} |
241 |
|
|
242 |
+ |
if( calcMuCorr || calcCosCorr ){ |
243 |
+ |
dumpArray[j].v = |
244 |
+ |
(struct vect *)calloc(n_atoms, sizeof(struct vect)); |
245 |
+ |
} |
246 |
+ |
|
247 |
|
//read the time and the box sizes |
248 |
|
|
249 |
|
fgets(read_buffer, sizeof(read_buffer), in_file); |
295 |
|
exit(8); |
296 |
|
} |
297 |
|
|
298 |
< |
strcpy(dumpArray[j].r[i].name, foo); /*copy the atom name */ |
298 |
> |
strcpy(dumpArray[0].names[i], foo); /*copy the atom name */ |
299 |
|
|
300 |
|
foo = strtok(NULL, " ,;\t"); |
301 |
|
if(foo == NULL){ |
320 |
|
} |
321 |
|
|
322 |
|
dumpArray[j].r[i].z = atof( foo ); |
323 |
< |
|
323 |
> |
|
324 |
> |
if( calcCosCorr || calcMuCorr ){ |
325 |
> |
|
326 |
> |
foo = strtok(NULL, " ,;\t"); |
327 |
> |
if(foo == NULL){ |
328 |
> |
|
329 |
> |
dumpArray[j].v[i].x = 0.0; |
330 |
> |
dumpArray[j].v[i].y = 0.0; |
331 |
> |
dumpArray[j].v[i].z = 0.0; |
332 |
> |
} |
333 |
> |
else{ |
334 |
> |
|
335 |
> |
dumpArray[j].v[i].x = atof( foo ); |
336 |
> |
|
337 |
> |
foo = strtok(NULL, " ,;\t"); |
338 |
> |
if(foo == NULL){ |
339 |
> |
printf("error in reading vector y at line %d\n", lineNum); |
340 |
> |
exit(8); |
341 |
> |
} |
342 |
> |
|
343 |
> |
dumpArray[j].v[i].y = atof( foo ); |
344 |
> |
|
345 |
> |
foo = strtok(NULL, " ,;\t"); |
346 |
> |
if(foo == NULL){ |
347 |
> |
printf("error in reading vector z at line %d\n", lineNum); |
348 |
> |
exit(8); |
349 |
> |
} |
350 |
> |
|
351 |
> |
dumpArray[j].v[i].z = atof( foo ); |
352 |
> |
} |
353 |
> |
} |
354 |
> |
|
355 |
|
} |
356 |
|
} |
357 |
|
|
365 |
|
|
366 |
|
// do calculations here. |
367 |
|
|
368 |
+ |
if( calcGofR ){ |
369 |
+ |
|
370 |
+ |
fprintf( stdout, |
371 |
+ |
"Calculating the g(r) between atoms \"%s\" and \"%s\"...", |
372 |
+ |
gofR1, gofR2 ); |
373 |
+ |
fflush( stdout ); |
374 |
+ |
|
375 |
+ |
// gofr call |
376 |
+ |
GofR( out_prefix, gofR1, gofR2, dumpArray, nFrames, startFrame, endFrame ); |
377 |
+ |
|
378 |
+ |
fprintf( stdout, |
379 |
+ |
" done.\n" |
380 |
+ |
"\n"); |
381 |
+ |
fflush(stdout); |
382 |
+ |
} |
383 |
|
|
384 |
< |
|
384 |
> |
if( calcRMSD ){ |
385 |
> |
|
386 |
> |
fprintf( stdout, |
387 |
> |
"Calculating the RMSD..." ); |
388 |
> |
fflush( stdout ); |
389 |
> |
|
390 |
> |
// RMSD call |
391 |
|
|
392 |
+ |
|
393 |
+ |
fprintf( stdout, |
394 |
+ |
" done.\n" |
395 |
+ |
"\n"); |
396 |
+ |
fflush(stdout); |
397 |
+ |
} |
398 |
|
|
399 |
+ |
if( calcMuCorr ){ |
400 |
+ |
|
401 |
+ |
fprintf( stdout, |
402 |
+ |
"Calculating the mu correlation for \"%s\"...", |
403 |
+ |
muCorr); |
404 |
+ |
fflush( stdout ); |
405 |
+ |
|
406 |
+ |
// muCorr call |
407 |
|
|
408 |
+ |
|
409 |
+ |
fprintf( stdout, |
410 |
+ |
" done.\n" |
411 |
+ |
"\n"); |
412 |
+ |
fflush(stdout); |
413 |
+ |
} |
414 |
+ |
|
415 |
+ |
if( calcCosCorr ){ |
416 |
+ |
|
417 |
+ |
fprintf( stdout, |
418 |
+ |
"Calculating the cos correlation between \"%s\" and \"%s\"...", |
419 |
+ |
cosCorr1, cosCorr2 ); |
420 |
+ |
fflush( stdout ); |
421 |
+ |
|
422 |
+ |
cosCorr( out_prefix, cosCorr1, cosCorr2, dumpArray, nFrames, startFrame, |
423 |
+ |
endFrame ); |
424 |
+ |
|
425 |
+ |
fprintf( stdout, |
426 |
+ |
" done.\n" |
427 |
+ |
"\n"); |
428 |
+ |
fflush(stdout); |
429 |
+ |
} |
430 |
|
|
431 |
|
return 0; |
432 |
|
|
433 |
|
} |
434 |
|
|
435 |
|
|
436 |
+ |
void map( double *x, double *y, double *z, |
437 |
+ |
double boxX, double boxY, double boxZ ){ |
438 |
+ |
|
439 |
+ |
*x -= boxX * copysign(1.0,*x) * floor( fabs( *x/boxX ) + 0.5 ); |
440 |
+ |
*y -= boxY * copysign(1.0,*y) * floor( fabs( *y/boxY ) + 0.5 ); |
441 |
+ |
*z -= boxZ * copysign(1.0,*z) * floor( fabs( *z/boxZ ) + 0.5 ); |
442 |
|
|
443 |
+ |
} |
444 |
+ |
|
445 |
+ |
|
446 |
|
/*************************************************************************** |
447 |
|
* prints out the usage for the command line arguments, then exits. |
448 |
|
***************************************************************************/ |
449 |
|
|
450 |
|
void usage(){ |
451 |
< |
(void)fprintf(stderr, |
452 |
< |
"The proper usage is: %s [options] -f <xyz_file>\n\n" |
453 |
< |
"Options:\n", |
451 |
> |
(void)fprintf(stdout, |
452 |
> |
"The proper usage is: %s [options] <xyz_file>\n" |
453 |
> |
"\n" |
454 |
> |
"Options:\n" |
455 |
> |
"\n" |
456 |
> |
" short:\n" |
457 |
> |
" ------\n" |
458 |
> |
" -h Display this message\n" |
459 |
> |
" -o <prefix> The output prefix\n" |
460 |
> |
" -r Calculate the RMSD\n" |
461 |
> |
" -g Calculate all to all g(r)\n" |
462 |
> |
|
463 |
> |
"\n" |
464 |
> |
" long:\n" |
465 |
> |
" -----\n" |
466 |
> |
" --GofR <atom1> <atom2> Calculates g(r) between atom1 and atom 2\n" |
467 |
> |
" -note: \"all\" will do all atoms\n" |
468 |
> |
" --MuCorr <atom> Calculate mu correlation of atom\n" |
469 |
> |
" --CosCorr <atom1> <atom2> Calculate the cos correlation between atom1 and atom2\n" |
470 |
> |
" --startFrame <frame#> Specifies a frame to start correlating\n" |
471 |
> |
" --endFrame <frame#> Specifies a frame to stop correlating.\n" |
472 |
> |
|
473 |
> |
"\n" |
474 |
> |
"\n", |
475 |
|
program_name); |
476 |
|
exit(8); |
477 |
|
} |