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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines