ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/tcProps/tcProps.c
(Generate patch)

Comparing trunk/tcProps/tcProps.c (file contents):
Revision 1049 by mmeineke, Wed Feb 11 21:55:56 2004 UTC vs.
Revision 1085 by mmeineke, Fri Mar 5 03:10:29 2004 UTC

# Line 1 | Line 1
1 + #define _FILE_OFFSET_BITS 64
2 +
3   #include <stdio.h>
4   #include <stdlib.h>
5 + #include <string.h>
6  
7  
8   #include "params.h"
9   #include "tcProps.h"
10 + #include "readWrite.h"
11 + #include "scdCorr.h"
12 + #include "directorHead.h"
13 + #include "directorWhole.h"
14 + #include "rmsd.h"
15 + #include "gofz.h"
16  
17  
18 + #define VERSION_MAJOR 0
19 + #define VERSION_MINOR 1
20 +
21 + char *programName; /*the name of the program */
22 + void usage(void);
23 +
24   int main( int argC, char *argV[] ){
25  
26    // list of 'a priori' constants
27  
28 <  const int nLipAtoms = 19;
29 <  const int nBonds = 18;
30 <  const int nLipids = NLIPIDS;
31 <  const int nSSD = NSSD;
32 <  const int nAtoms = nLipAtoms * nLipids + nSSD;
28 >  const int nLipAtoms = NL_ATOMS;
29 >  const int nBonds    = NBONDS;
30 >  const int nLipids   = NLIPIDS;
31 >  const int nSSD      = NSSD;
32 >  const int nAtoms    = nLipAtoms * nLipids + nSSD;
33 >
34 >  // different needed variables
35    
36    struct atomCoord atoms[nAtoms];
37 +  int i,j,k;
38 +  
39 +  char* outPrefix; // the output prefix
40 +  char currentFlag; // used in parsing the flags
41 +  int done = 0; // multipurpose boolean
42 +  int havePrefix; // boolean for the output prefix  
43 +  int haveMaxLength;
44 +  char* conversionCheck;
45 +  int conversionError;
46 +  int optionError;
47 +  char* rmsdName;
48 +  char* pair1;
49 +  char* pair2;
50 +  int scdCorr;
51 +  double startTime;
52 +  double avgXY;
53 +  double maxLength;
54  
55 +  int directorHead, directorWhole, doRMSD, doGofz, doAvgXY;
56 +  enum atomNames rmsdType;
57 +
58 +  // system initialization
59    
60 +  isScanned = 0;
61 +  fileOpen = 0;
62 +  nFrames = 0;
63 +  frameTimes = NULL;
64  
65 <  int i,j,k;
65 >  outPrefix = NULL;
66 >  inName = NULL;
67 >  
68 >  haveMaxLength = 0;
69 >  conversionError = 0;
70 >  optionError = 0;
71 >  havePrefix = 0;
72 >  scdCorr = 0;
73 >  startTime = 0.0;
74 >  directorHead = 0;
75 >  directorWhole = 0;
76 >  doRMSD = 0;
77 >  doGofz = 0;
78 >  doAvgXY = 0;
79 >  
80 >
81 >  // parse the command line
82 >
83 >  programName = argV[0]; /*save the program name in case we need it*/
84 >
85 >  for( i = 1; i < argC; i++){
86 >    
87 >    if(argV[i][0] =='-'){
88 >
89 >      // parse the option
90 >      
91 >      if(argV[i][1] == '-' ){
92 >
93 >        // parse long word options
94 >        
95 >        if( !strcmp( argV[i], "--rmsd" ) ){
96 >
97 >          doRMSD = 1;
98 >          i++;
99 >          if( i>=argC ){
100 >            fprintf( stderr,
101 >                     "\n"
102 >                     "not enough arguments for --rmsd\n");
103 >            usage();
104 >            exit(0);
105 >          }      
106 >          rmsdName = argV[i];
107 >
108 >          if( !strcmp(rmsdName, "HEAD") )    rmsdType = HEAD;
109 >          else if( !strcmp(rmsdName, "CH") ) rmsdType = CH;
110 >          else if( !strcmp(rmsdName, "CH2") )rmsdType = CH2;
111 >          else if( !strcmp(rmsdName, "CH3") )rmsdType = CH3;
112 >          else if( !strcmp(rmsdName, "SSD") )rmsdType = SSD;
113 >          else if( !strcmp(rmsdName, "COM") )rmsdType = COM;
114 >          else{
115 >            fprintf( stderr,
116 >                     "Unrecognized rmsd atom type \"%s\"\n",
117 >                     rmsdName );
118 >            exit(0);
119 >          }
120 >
121 >        }
122 >
123 >        else if( !strcmp( argV[i], "--gofrTheta" ) ){
124 >          
125 >          i++;
126 >          if( i>=argC ){
127 >            fprintf( stderr,
128 >                     "\n"
129 >                     "not enough arguments for --gofrTheta\n");
130 >            usage();
131 >            exit(0);
132 >          }      
133 >          pair1 = argV[i];
134 >
135 >          i++;
136 >          if( i>=argC ){
137 >            fprintf( stderr,
138 >                     "\n"
139 >                     "not enough arguments for --gofrTheta\n");
140 >            usage();
141 >            exit(0);
142 >          }      
143 >          pair2 = argV[i];
144 >
145 >        }
146 >
147 >        else if( !strcmp( argV[i], "--gofrOmega" ) ){
148 >          
149 >          i++;
150 >          if( i>=argC ){
151 >            fprintf( stderr,
152 >                     "\n"
153 >                     "not enough arguments for --gofrOmega\n");
154 >            usage();
155 >            exit(0);
156 >          }      
157 >          pair1 = argV[i];
158 >
159 >          i++;
160 >          if( i>=argC ){
161 >            fprintf( stderr,
162 >                     "\n"
163 >                     "not enough arguments for --gofrOmega\n");
164 >            usage();
165 >            exit(0);
166 >          }      
167 >          pair2 = argV[i];
168 >
169 >        }
170 >
171 >        else if( !strcmp( argV[i], "--version") ){
172 >          
173 >          printf("\n"
174 >                 "tcProps version %d.%d\n"
175 >                 "\n",
176 >                 VERSION_MAJOR, VERSION_MINOR );
177 >          exit(0);
178 >          
179 >        }
180 >
181 >        else if( !strcmp( argV[i], "--help") ){
182 >          
183 >          usage();
184 >          exit(0);
185 >        }
186 >        
187 >        // anything else is an error
188 >
189 >        else{
190 >          fprintf( stderr,
191 >                   "Invalid option \"%s\"\n", argV[i] );
192 >          usage();
193 >          exit(0);
194 >        }
195 >      }
196 >      
197 >      else{
198 >        
199 >        // parse single character options
200 >        
201 >        done =0;
202 >        j = 1;
203 >        currentFlag = argV[i][j];
204 >        while( (currentFlag != '\0') && (!done) ){
205 >          
206 >          switch(currentFlag){
207 >
208 >          case 'o':
209 >            // -o <prefix> => the output prefix.
210 >
211 >            j++;
212 >            currentFlag = argV[i][j];
213 >              
214 >            if( currentFlag != '\0' ) optionError = 1;
215 >            
216 >            if( optionError ){
217 >              fprintf( stderr,
218 >                       "\n"
219 >                       "The -o flag should end an option sequence.\n"
220 >                       "   example: -r <outname> *NOT* -or <outname>\n" );
221 >              usage();
222 >              exit(0);
223 >            }
224 >              
225 >            i++;
226 >            if( i>=argC ){
227 >              fprintf( stderr,
228 >                       "\n"
229 >                       "not enough arguments for -o\n");
230 >              usage();
231 >              exit(0);
232 >            }    
233 >            
234 >            outPrefix = argV[i];
235 >            if( outPrefix[0] == '-' ) optionError = 1;
236 >                
237 >            if( optionError ){
238 >              fprintf( stderr,
239 >                       "\n"
240 >                       "\"%s\" is not a valid out prefix/name.\n"
241 >                       "Out prefix/name should not begin with a dash.\n",
242 >                       outPrefix );
243 >              usage();
244 >              exit(0);
245 >            }
246 >            
247 >            havePrefix = 1;
248 >            done = 1;
249 >            break;
250 >
251 >          case 'l':
252 >            // -l <double>    set <double> to the maxLength
253 >
254 >            haveMaxLength = 1;
255 >            j++;
256 >            currentFlag = argV[i][j];
257 >              
258 >            if( currentFlag != '\0' ) optionError = 1;
259 >            
260 >            if( optionError ){
261 >              fprintf( stderr,
262 >                       "\n"
263 >                       "The -l flag should end an option sequence.\n"
264 >                       "   example: -sl <double> *NOT* -ls <double>\n" );
265 >              usage();
266 >              exit(0);
267 >            }
268 >
269 >            i++;
270 >            if( i>=argC ){
271 >              fprintf( stderr,
272 >                       "\n"
273 >                       "not enough arguments for -l\n");
274 >              usage();
275 >              exit(0);
276 >            }    
277 >
278 >            maxLength = atof( argV[i] );
279 >            
280 >            done = 1;
281 >
282 >            break;
283 >
284 >          case 't':
285 >            // -t <double>    set <double> to the startTime
286 >
287 >            j++;
288 >            currentFlag = argV[i][j];
289 >              
290 >            if( currentFlag != '\0' ) optionError = 1;
291 >            
292 >            if( optionError ){
293 >              fprintf( stderr,
294 >                       "\n"
295 >                       "The -t flag should end an option sequence.\n"
296 >                       "   example: -st <double> *NOT* -ts <double>\n" );
297 >              usage();
298 >              exit(0);
299 >            }
300 >
301 >            i++;
302 >            if( i>=argC ){
303 >              fprintf( stderr,
304 >                       "\n"
305 >                       "not enough arguments for -t\n");
306 >              usage();
307 >              exit(0);
308 >            }    
309 >
310 >            startTime = atof( argV[i] );
311 >            done = 1;
312 >            break;
313 >
314 >          case 's':
315 >            // -s turn on Scd corr
316 >
317 >            scdCorr = 1;
318 >            break;
319 >
320 >          case 'h':
321 >            // -h turn on director head
322 >
323 >            directorHead = 1;
324 >            break;
325 >
326 >          case 'w':
327 >            // -w turn on director head
328 >
329 >            directorWhole = 1;
330 >            break;
331 >
332 >          case 'g':
333 >            // -g turn on gofZ
334 >
335 >            doGofz = 1;
336 >            break;
337 >
338 >          case 'v':
339 >            // -v turn on average XY
340 >
341 >            doAvgXY = 1;
342 >            break;
343 >
344 >
345 >          default:
346 >
347 >            fprintf( stderr,
348 >                    "\n"
349 >                    "Bad option \"-%c\"\n", currentFlag);
350 >            usage();
351 >            exit(0);
352 >          }
353 >          j++;
354 >          currentFlag = argV[i][j];
355 >        }
356 >      }
357 >    }
358 >
359 >    else{
360 >      
361 >      if( inName != NULL ){
362 >        fprintf( stderr,
363 >                 "Error at \"%s\", program does not currently support\n"
364 >                 "more than one input dump file.\n"
365 >                 "\n",
366 >                 argV[i]);
367 >        usage();
368 >        exit(0);
369 >      }
370 >      
371 >      inName = argV[i];
372 >      
373 >    }
374 >  }  
375    
376 +  if( inName == NULL ){
377 +    fprintf( stderr,
378 +             "Error, dump file is needed to run.\n" );
379 +    usage();
380 +    exit(0);
381 +  }
382 +
383 +  if( outPrefix == NULL )
384 +    outPrefix = inName;
385 +
386 +
387    // initialize the arrays
388  
389    for(i=0;i<nLipids;i++){
390  
391      atoms[nLipAtoms*i+0].type = HEAD;
392 +    atoms[nLipAtoms*i+0].mass = 72;
393 +    atoms[nLipAtoms*i+0].u[0] = 0.0;
394 +    atoms[nLipAtoms*i+0].u[1] = 0.0;
395 +    atoms[nLipAtoms*i+0].u[2] = 1.0;
396 +    
397 +    
398  
399      atoms[nLipAtoms*i+1].type = CH2;
400 +    atoms[nLipAtoms*i+1].mass = 14.03;
401  
402      atoms[nLipAtoms*i+2].type = CH;
403 +    atoms[nLipAtoms*i+2].mass = 13.02;
404  
405      atoms[nLipAtoms*i+3].type = CH2;
406 +    atoms[nLipAtoms*i+3].mass = 14.03;
407  
408      atoms[nLipAtoms*i+4].type = CH2;
409 +    atoms[nLipAtoms*i+4].mass = 14.03;
410  
411      atoms[nLipAtoms*i+5].type = CH2;
412 +    atoms[nLipAtoms*i+5].mass = 14.03;
413  
414      atoms[nLipAtoms*i+6].type = CH2;
415 +    atoms[nLipAtoms*i+6].mass = 14.03;
416  
417      atoms[nLipAtoms*i+7].type = CH2;
418 +    atoms[nLipAtoms*i+7].mass = 14.03;
419  
420      atoms[nLipAtoms*i+8].type = CH2;
421 +    atoms[nLipAtoms*i+8].mass = 14.03;
422  
423      atoms[nLipAtoms*i+9].type = CH2;
424 +    atoms[nLipAtoms*i+9].mass = 14.03;
425  
426      atoms[nLipAtoms*i+10].type = CH3;
427 +    atoms[nLipAtoms*i+10].mass = 15.04;
428  
429      atoms[nLipAtoms*i+11].type = CH2;
430 +    atoms[nLipAtoms*i+11].mass = 14.03;
431  
432      atoms[nLipAtoms*i+12].type = CH2;
433 +    atoms[nLipAtoms*i+12].mass = 14.03;
434  
435 <    atoms[nLipAtoms*i+13].type = CH2;
435 >    atoms[nLipAtoms*i+13].type = CH2;    
436 >    atoms[nLipAtoms*i+13].mass = 14.03;
437  
438      atoms[nLipAtoms*i+14].type = CH2;
439 +    atoms[nLipAtoms*i+14].mass = 14.03;
440    
441      atoms[nLipAtoms*i+15].type = CH2;
442 +    atoms[nLipAtoms*i+15].mass = 14.03;
443    
444      atoms[nLipAtoms*i+16].type = CH2;
445 +    atoms[nLipAtoms*i+16].mass = 14.03;
446    
447      atoms[nLipAtoms*i+17].type = CH2;
448 +    atoms[nLipAtoms*i+17].mass = 14.03;
449    
450      atoms[nLipAtoms*i+18].type = CH3;
451 +    atoms[nLipAtoms*i+18].mass = 15.04;
452    }
453    
454 <  for(i=;i<nAtoms;i++){
454 >  for(i=(nLipAtoms*nLipids);i<nAtoms;i++){
455      atoms[i].type = SSD;
456 +    atoms[i].mass = 18.03;
457 +    atoms[i].u[0] = 0.0;
458 +    atoms[i].u[1] = 0.0;
459 +    atoms[i].u[2] = 1.0;
460    }
461 +
462 +  // read and set the frames
463 +  
464 +  openFile();
465 +
466 +  fprintf( stdout,
467 +           "\n"
468 +           "Counting the number of frames in \"%s\"...",
469 +           inName );
470 +  fflush(stdout);
471 +
472 +  setFrames();
473 +  
474 +  fprintf( stdout,
475 +           "done.\n"
476 +           "nFrames = %d.\n",
477 +           nFrames );
478 +  fflush(stdout);
479 +
480 +  if(scdCorr){
481 +
482 +    fprintf ( stdout,
483 +              "Calculating the Scd correlation\n" );
484 +    fflush( stdout );
485 +    
486 +    calcScdCorr( startTime, atoms, outPrefix );
487 +  }
488 +
489 +  if(directorHead){
490 +
491 +    fprintf ( stdout,
492 +              "Calculating the Head director\n" );
493 +    fflush( stdout );
494 +    
495 +    calcDirHeadCorr( startTime, atoms, outPrefix );
496 +  }
497 +
498 +  if(directorWhole){
499 +
500 +    fprintf ( stdout,
501 +              "Calculating the bilayer director\n" );
502 +    fflush( stdout );
503 +    
504 +    calcDirWholeCorr( startTime, atoms, outPrefix );
505 +  }
506 +
507 +  if(doRMSD){
508 +
509 +    fprintf ( stdout,
510 +              "Calculating the RMSD\n" );
511 +    fflush( stdout );
512 +    
513 +    rmsd( rmsdType, startTime, outPrefix, rmsdName );
514 +  }
515 +
516 +  if(doGofz){
517 +
518 +    fprintf ( stdout,
519 +              "Calculating the gofZ\n" );
520 +    fflush( stdout );
521 +    
522 +    calcGofz( startTime, atoms, outPrefix );
523 +  }
524 +
525 +  if(doAvgXY){
526 +
527 +    fprintf ( stdout,
528 +              "Calculating the average XY\n" );
529 +    fflush( stdout );
530 +    
531 +    avgXY = calcAverageXY( startTime );
532 +    
533 +    fprintf ( stdout,
534 +              "Done, average XY = %6G\n", avgXY );
535 +    fflush( stdout );
536 +    
537 +  }
538 +  
539 +
540 +  closeFile();
541 +
542 + }
543 +
544 +
545 + /***************************************************************************
546 + * prints out the usage for the command line arguments, then exits.
547 + ***************************************************************************/
548 +
549 + void usage(){
550 +  (void)fprintf(stdout,
551 +                "\n"
552 +                "The proper usage is: %s [options] <input_file>\n"
553 +                "\n"
554 +                "Options:\n"
555 +                "\n"
556 +                "   short:\n"
557 +                "   ------\n"
558 +                "   -o <name>       The output prefix\n"
559 +                "   -t <time>       Set the start time for correlations\n"
560 +                "   -l <maxLength>  set the maximum value of r\n"
561 +                "                     *Defaults to 1/2 smallest length of first frame.\n"
562 +                "   -s              Calculate the Scd chain correlation.\n"
563 +                "   -h              Calculate the directors for the head groups\n"
564 +                "   -w              Calculate the director from the bilayers\n"
565 +                "   -g              Calculate the gofz profile\n"
566 +                "\n"
567 +                "   long:\n"
568 +                "   -----\n"
569 +                "   --rmsd <atom1>                 rmsd for atom1\n"
570 +                "   --gofrTheta <atom1> <atom2>    g(r, theta) for atom1 and atom2\n"
571 +                "   --gofrOmega <atom1> <atom2>    g(r, omega) for atom1 and atom2\n"
572 +                "   --version                      displays the version number\n"
573 +                "   --help                         displays this help message.\n"
574 +                
575 +                "\n"
576 +                "\n",
577 +                programName);
578 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines