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

Comparing trunk/xyz2pov/src/xyz2pov.c (file contents):
Revision 61 by mmeineke, Thu Aug 1 21:12:33 2002 UTC vs.
Revision 864 by gezelter, Tue Nov 18 17:04:25 2003 UTC

# Line 13 | Line 13
13  
14   #define POV_DIR "./pov"
15  
16 +
17   struct linked_xyz{
18    struct coords *r;
19 +  double Hmat[3][3];
20    struct linked_xyz *next;
21   };
22  
# Line 22 | Line 24 | int draw_atoms = 0; /*boolean to draw atoms */
24   int draw_bonds = 0; /* boolean to draw bonds or not */
25   int draw_hydrogens = 0; /*boolean to draw hydrogens */
26   int draw_atoms = 0; /*boolean to draw atoms */
27 + int draw_vectors = 0; /*boolean to draw vectors */
28 + int draw_box = 0;  // boolean to draw the periodic Box
29 + int regenerateBonds = 0; // boolean to regenearate bonds each frame
30  
31   void usage(void);
32 + int count_tokens(char *line, char *delimiters);
33  
34   int main(argc, argv)
35       int argc;
# Line 33 | Line 39 | int main(argc, argv)
39  
40    struct coords *out_coords;
41  
42 <  int i,j; /* loop counters */
42 >  int i,j,k; /* loop counters */
43    mode_t dir_mode = S_IRWXU;
44  
45    int generate_header = 0; /* boolean for generating the pov ray header */
# Line 43 | Line 49 | int main(argc, argv)
49    double small_x = 0;
50    double small_y = 0; /* lets me know the smallest x, y, z */
51    double small_z = 0;
52 +  int extremaSet = 0;
53    double rsqr; /* the square of the diagonal */
54    double diagonal; /* the diagonal length of the sim box */
55  
56    unsigned int n_atoms; /*the number of atoms in each time step */
57 <  char read_buffer[120]; /*the line buffer for reading */
57 >  char read_buffer[2000]; /*the line buffer for reading */
58    char *eof_test; /*ptr to see when we reach the end of the file */
59    char *foo; /*the pointer to the current string token */
60    FILE *in_file; /* the input file */
# Line 62 | Line 69 | int main(argc, argv)
69    char current_flag;
70    int nFrames;
71    int nZeroes;
72 +  int nTokens;
73    double count;
74  
75 +  int startFrame = 1;
76 +  int endFrame;
77 +  int span = 0;
78 +  int currentCount = 0;
79 +  int haveEnd = 0;
80 +
81    struct linked_xyz *current_frame;
82    struct linked_xyz *temp_frame;
83    
84    unsigned int n_interpolate = 0; /* number of frames to interpolate */
85    double dx, dy, dz; /* temp variables for interpolating distances */
86 +  double dm[3][3];
87 +  
88  
89    char pov_dir[500]; /* the pov_dir */
90  
91    program_name = argv[0]; /*save the program name in case we need it*/
92  
93 <
93 >
94    for( i = 1; i < argc; i++){
95      
96      if(argv[i][0] =='-'){
# Line 119 | Line 135 | int main(argc, argv)
135              done = 1;
136              break;
137  
138 +          case 'f':
139 +            // -f <#> => frame to render
140 +
141 +            i++;
142 +            startFrame =  atoi( argv[i] );
143 +            endFrame = startFrame;
144 +            haveEnd = 1;
145 +            done = 1;
146 +            break;
147 +
148 +          case 's':
149 +            // -s <#> => frame to start
150 +
151 +            i++;
152 +            startFrame =  atoi( argv[i] );
153 +            done = 1;
154 +            break;
155 +
156 +          case 'e':
157 +            // -e <#> => frame to end
158 +
159 +            i++;
160 +            endFrame =  atoi( argv[i] );
161 +            haveEnd = 1;
162 +            done = 1;
163 +            break;
164 +
165            case 'H':
166              // -h => generate a pov-ray Header
167              
# Line 141 | Line 184 | int main(argc, argv)
184              // -a => draw the atoms
185  
186              draw_atoms = 1;
187 +            break;
188 +
189 +          case 'v':
190 +            // -v => draw the vectors
191 +
192 +            draw_vectors = 1;
193              break;
194  
195 +          case 'r':
196 +            // -r => regenerate bonds
197 +
198 +            regenerateBonds = 1;
199 +            break;
200 +
201 +          case 'p':
202 +            // -r => draw periodic box
203 +
204 +            draw_box = 1;
205 +            break;
206 +
207            default:
208  
209              (void)fprintf(stderr, "Bad option \"-%c\"\n", current_flag);
# Line 193 | Line 254 | int main(argc, argv)
254    // initialize atom type parser
255    
256    initializeParser();
257 +  initBondList();
258    
259    // count the number of frames
260  
# Line 219 | Line 281 | int main(argc, argv)
281      out_prefix = strtok(in_name, ".");
282    }
283  
284 <  sprintf( out_format, "%s%s%%0%dd.pov", pov_dir, out_prefix, nZeroes );
284 >  sprintf( out_format, "%s%s-%%0%dd.pov", pov_dir, out_prefix, nZeroes );
285  
286    // start reading the first frame
287  
# Line 229 | Line 291 | int main(argc, argv)
291    current_frame->next = NULL;
292    
293  
294 <  while(eof_test != NULL){
294 >  if( haveEnd ) span = endFrame - startFrame;
295 >  done = 0;
296 >  if( span < 0 ) done = 1;
297 >  while( (eof_test != NULL) && !done ){
298      
299      (void)sscanf(read_buffer, "%d", &n_atoms);
300      current_frame->r =
# Line 242 | Line 307 | int main(argc, argv)
307        printf("error in reading file\n");
308        exit(8);
309      }
310 <
311 <    for( i=0; i < n_atoms; i++){
312 <      
313 <      eof_test = fgets(read_buffer, sizeof(read_buffer), in_file);
314 <      if(eof_test == NULL){
315 <        printf("error in reading file\n");
310 >    
311 >    // unless we need to get the box size
312 >    
313 >    if( draw_box ){
314 >      foo = strtok(read_buffer, " ,;\t");
315 >      if(foo == NULL){
316 >        printf("error in reading file time\n");
317          exit(8);
318        }
253
254      foo = strtok(read_buffer, " ,;\t");
255      (void)strcpy(current_frame->r[i].name, foo); /*copy the atom name */
256
257      /* next we grab the positions */
319        
320        foo = strtok(NULL, " ,;\t");
321        if(foo == NULL){
322 <        printf("error in reading file\n");
322 >        printf("error in reading file h00\n");
323          exit(8);
324        }
325 <      (void)sscanf(foo, "%lf",&current_frame->r[i].x);
326 <      if(current_frame->r[i].x > big_x) big_x = current_frame->r[i].x;
266 <      if(current_frame->r[i].x < small_x) small_x = current_frame->r[i].x;
267 <            
268 <  
325 >      current_frame->Hmat[0][0] = atof( foo );
326 >
327        foo = strtok(NULL, " ,;\t");
328        if(foo == NULL){
329 <        printf("error in reading file\n");
329 >        printf("error in reading file h10\n");
330          exit(8);
331        }
332 <      (void)sscanf(foo, "%lf", &current_frame->r[i].y);
275 <      if(current_frame->r[i].y > big_y) big_y = current_frame->r[i].y;
276 <      if(current_frame->r[i].y < small_y) small_y = current_frame->r[i].y;
332 >      current_frame->Hmat[1][0] = atof( foo );
333  
334 +      foo = strtok(NULL, " ,;\t");
335 +      if(foo == NULL){
336 +        printf("error in reading file h20\n");
337 +        exit(8);
338 +      }
339 +      current_frame->Hmat[2][0] = atof( foo );
340  
341        foo = strtok(NULL, " ,;\t");
342        if(foo == NULL){
343 <        printf("error in reading file\n");
343 >        printf("error in reading file h01\n");
344          exit(8);
345        }
346 <      (void)sscanf(foo, "%lf", &current_frame->r[i].z);
285 <      if(current_frame->r[i].z > big_z) big_z = current_frame->r[i].z;
286 <      if(current_frame->r[i].z < small_z) small_z = current_frame->r[i].z;
346 >      current_frame->Hmat[0][1] = atof( foo );
347  
348 +      foo = strtok(NULL, " ,;\t");
349 +      if(foo == NULL){
350 +        printf("error in reading file h11\n");
351 +        exit(8);
352 +      }
353 +      current_frame->Hmat[1][1] = atof( foo );
354 +
355 +      foo = strtok(NULL, " ,;\t");
356 +      if(foo == NULL){
357 +        printf("error in reading file h21\n");
358 +        exit(8);
359 +      }
360 +      current_frame->Hmat[2][1] = atof( foo );
361 +
362 +      foo = strtok(NULL, " ,;\t");
363 +      if(foo == NULL){
364 +        printf("error in reading file h02\n");
365 +        exit(8);
366 +      }
367 +      current_frame->Hmat[0][2] = atof( foo );
368 +
369 +      foo = strtok(NULL, " ,;\t");
370 +      if(foo == NULL){
371 +        printf("error in reading file h12\n");
372 +        exit(8);
373 +      }
374 +      current_frame->Hmat[1][2] = atof( foo );
375 +
376 +      foo = strtok(NULL, " ,;\t");
377 +      if(foo == NULL){
378 +        printf("error in reading file h22\n");
379 +        exit(8);
380 +      }
381 +      current_frame->Hmat[2][2] = atof( foo );
382 +
383      }
384 <    
385 <    if(n_interpolate && current_frame->next != NULL){
384 >
385 >    for( i=0; i < n_atoms; i++){
386        
387 <      temp_frame = current_frame->next;
388 <      
389 <      for(i = 0; i < n_interpolate; i++){
390 <        
391 <        /* open the new output file */
297 <        
298 <        sprintf(out_name, out_format, n_out );
299 <        out_file = fopen(out_name, "w");
300 <        n_out++;
301 <        if(out_file == NULL){
302 <          printf("error opening output file: %s\n", out_name);
303 <          exit(8);
304 <        }
305 <        (void)fprintf(out_file,
306 <                      "// The following script was automatically generated by:\n"
307 <                      "// xyz2pov Copyright 2001 by MATTHEW A. MEINEKE\n"
308 <                      "\n"
309 <                      "#include \"pov_header.pov\"\n"
310 <                      "\n");
387 >      eof_test = fgets(read_buffer, sizeof(read_buffer), in_file);
388 >      if(eof_test == NULL){
389 >        printf("error in reading file line at atom %d\n", i);
390 >        exit(8);
391 >      }
392  
393 <        out_coords =
313 <          (struct coords *)calloc(n_atoms, sizeof(struct coords));
314 <        
315 <        for(j=0; j < n_atoms; j++){
316 <          dx = current_frame->r[j].x - temp_frame->r[j].x;
317 <          dy = current_frame->r[j].y - temp_frame->r[j].y;
318 <          dz = current_frame->r[j].z - temp_frame->r[j].z;
393 >      nTokens = count_tokens(read_buffer, " ,;\t");
394  
395 <          dx /= (double)(n_interpolate + 1);
396 <          dy /= (double)(n_interpolate + 1);
397 <          dz /= (double)(n_interpolate + 1);
395 >      if (nTokens < 4) {
396 >        printf("Not enough tokens while parsing file at atom %d\n", i);
397 >        exit(8);
398 >      }
399 >
400 >      foo = strtok(read_buffer, " ,;\t");
401 >      (void)strcpy(current_frame->r[i].name, foo); /*copy the atom name */
402 >
403 >      foo = strtok(NULL, " ,;\t");
404 >      (void)sscanf(foo, "%lf",&current_frame->r[i].x);
405 >      foo = strtok(NULL, " ,;\t");
406 >      (void)sscanf(foo, "%lf", &current_frame->r[i].y);
407 >      foo = strtok(NULL, " ,;\t");
408 >      (void)sscanf(foo, "%lf", &current_frame->r[i].z);
409 >
410 >      if (extremaSet) {
411 >        if(current_frame->r[i].x > big_x) big_x = current_frame->r[i].x;
412 >        if(current_frame->r[i].x < small_x) small_x = current_frame->r[i].x;
413 >        
414 >        if(current_frame->r[i].y > big_y) big_y = current_frame->r[i].y;
415 >        if(current_frame->r[i].y < small_y) small_y = current_frame->r[i].y;
416 >        
417 >        if(current_frame->r[i].z > big_z) big_z = current_frame->r[i].z;
418 >        if(current_frame->r[i].z < small_z) small_z = current_frame->r[i].z;
419 >      } else {
420 >        big_x = current_frame->r[i].x;
421 >        small_x = current_frame->r[i].x;
422 >        
423 >        big_y = current_frame->r[i].y;
424 >        small_y = current_frame->r[i].y;
425 >        
426 >        big_z = current_frame->r[i].z;
427 >        small_z = current_frame->r[i].z;
428 >
429 >        extremaSet = 1;
430 >
431 >      }
432 >
433 >      if (nTokens == 5 || nTokens > 7) {
434 >        foo = strtok(NULL, " ,;\t");
435 >        (void)sscanf(foo, "%lf", &current_frame->r[i].charge);
436 >        current_frame->r[i].hasCharge = 1;
437 >      } else {
438 >        current_frame->r[i].hasCharge = 0;
439 >      }
440 >
441 >      
442 >      if (nTokens >= 7) {
443 >        foo = strtok(NULL, " ,;\t");
444 >        (void)sscanf(foo, "%lf", &current_frame->r[i].ux);
445 >        foo = strtok(NULL, " ,;\t");
446 >        (void)sscanf(foo, "%lf", &current_frame->r[i].uy);
447 >        foo = strtok(NULL, " ,;\t");
448 >        (void)sscanf(foo, "%lf", &current_frame->r[i].uz);
449 >        current_frame->r[i].hasVector = 1;
450 >      } else {
451 >        current_frame->r[i].hasVector = 0;
452 >      }
453 >    }
454 >    currentCount++;
455      
456 <          strcpy(out_coords[j].name, temp_frame->r[j].name);
457 <          out_coords[j].x = temp_frame->r[j].x + dx * (i+1);
458 <          out_coords[j].y = temp_frame->r[j].y + dy * (i+1);
459 <          out_coords[j].z = temp_frame->r[j].z + dz * (i+1);
456 >    
457 >    if( currentCount >= startFrame ){
458 >      if(n_interpolate && current_frame->next != NULL){
459 >        
460 >        temp_frame = current_frame->next;
461 >        
462 >        for(i = 0; i < n_interpolate; i++){
463 >          
464 >          /* open the new output file */
465 >          
466 >          sprintf(out_name, out_format, currentCount );
467 >          out_file = fopen(out_name, "w");
468 >          currentCount++;
469 >          if(out_file == NULL){
470 >            printf("error opening output file: %s\n", out_name);
471 >            exit(8);
472 >          }
473 >          (void)fprintf(out_file,
474 >                        "// The following script was automatically generated by:\n"
475 >                        "// xyz2pov Copyright 2001 by MATTHEW A. MEINEKE\n"
476 >                        "\n"
477 >                        "#include \"pov_header.pov\"\n"
478 >                        "\n");
479 >          if( draw_box ){
480 >
481 >            for (j = 0; j < 3; j++) {
482 >              for (k = 0; k < 3; k++) {
483 >                dm[j][k] = current_frame->Hmat[j][k] - temp_frame->Hmat[j][k];
484 >                dm[j][k] /= (double)(n_interpolate + 1);
485 >              }
486 >            }
487 >                            
488 >            fprintf( out_file,
489 >                     "makePeriodicBox( %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf)\n"
490 >                     "\n",
491 >                     temp_frame->Hmat[0][0] + dm[0][0] * (i+1),
492 >                     temp_frame->Hmat[2][0] + dm[2][0] * (i+1),
493 >                     temp_frame->Hmat[1][0] + dm[1][0] * (i+1),
494 >                     temp_frame->Hmat[0][1] + dm[0][1] * (i+1),
495 >                     temp_frame->Hmat[2][1] + dm[2][1] * (i+1),
496 >                     temp_frame->Hmat[1][1] + dm[1][1] * (i+1),
497 >                     temp_frame->Hmat[0][2] + dm[0][2] * (i+1),
498 >                     temp_frame->Hmat[2][2] + dm[2][2] * (i+1),
499 >                     temp_frame->Hmat[1][2] + dm[1][2] * (i+1) );
500 >          }
501 >          
502 >          
503 >          out_coords =
504 >            (struct coords *)calloc(n_atoms, sizeof(struct coords));
505 >          
506 >          for(j=0; j < n_atoms; j++){
507 >            dx = current_frame->r[j].x - temp_frame->r[j].x;
508 >            dy = current_frame->r[j].y - temp_frame->r[j].y;
509 >            dz = current_frame->r[j].z - temp_frame->r[j].z;
510 >            
511 >            dx /= (double)(n_interpolate + 1);
512 >            dy /= (double)(n_interpolate + 1);
513 >            dz /= (double)(n_interpolate + 1);
514 >            
515 >            strcpy(out_coords[j].name, temp_frame->r[j].name);
516 >            out_coords[j].x = temp_frame->r[j].x + dx * (i+1);
517 >            out_coords[j].y = temp_frame->r[j].y + dy * (i+1);
518 >            out_coords[j].z = temp_frame->r[j].z + dz * (i+1);
519 >
520 >            if (current_frame->r[j].hasVector) {              
521 >              dx = current_frame->r[j].ux - temp_frame->r[j].ux;
522 >              dy = current_frame->r[j].uy - temp_frame->r[j].uy;
523 >              dz = current_frame->r[j].uz - temp_frame->r[j].uz;
524 >              
525 >              dx /= (double)(n_interpolate + 1);
526 >              dy /= (double)(n_interpolate + 1);
527 >              dz /= (double)(n_interpolate + 1);
528 >              
529 >              out_coords[j].hasVector = current_frame->r[j].hasVector;
530 >              out_coords[j].ux = temp_frame->r[j].ux + dx * (i+1);
531 >              out_coords[j].uy = temp_frame->r[j].uy + dy * (i+1);
532 >              out_coords[j].uz = temp_frame->r[j].uz + dz * (i+1);
533 >            }
534 >
535 >            if (current_frame->r[j].hasCharge) {              
536 >              dx = current_frame->r[j].charge - temp_frame->r[j].charge;
537 >              
538 >              dx /= (double)(n_interpolate + 1);
539 >              
540 >              out_coords[j].hasCharge = current_frame->r[j].hasCharge;
541 >              out_coords[j].charge = temp_frame->r[j].charge + dx * (i+1);
542 >            }
543 >
544 >          }
545 >          
546 >          pov_write(out_file, out_coords, n_atoms, draw_hydrogens, draw_bonds,
547 >                    draw_atoms, draw_vectors);
548 >          free(out_coords);
549 >          (void)fclose(out_file);
550          }
551 +      }
552 +      
553 +      /* open the new output file */
554 +      
555 +      sprintf(out_name, out_format, currentCount );
556 +      out_file = fopen(out_name, "w");
557 +      if(out_file == NULL){
558 +        printf("error opening output file: %s\n", out_name);
559 +        exit(8);
560 +      }
561 +      (void)fprintf(out_file,
562 +                    "// The following script was automatically generated by:\n"
563 +                    "// xyz2pov Copyright 2001 by MATTHEW A. MEINEKE\n"
564 +                    "\n"
565 +                    "#include \"pov_header.pov\"\n"
566 +                    "\n");
567 +      
568 +      if( draw_box ){
569          
570 <        pov_write(out_file, out_coords, n_atoms, draw_hydrogens, draw_bonds,
571 <                  draw_atoms);
572 <        free(out_coords);
573 <        (void)fclose(out_file);
570 >        fprintf( out_file,
571 >                 "makePeriodicBox( %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf )\n"
572 >                 "\n",
573 >                 current_frame->Hmat[0][0],
574 >                 current_frame->Hmat[2][0],
575 >                 current_frame->Hmat[1][0],
576 >                 current_frame->Hmat[0][1],
577 >                 current_frame->Hmat[2][1],
578 >                 current_frame->Hmat[1][1],
579 >                 current_frame->Hmat[0][2],
580 >                 current_frame->Hmat[2][2],
581 >                 current_frame->Hmat[1][2] );
582        }
583 <    }
583 >      
584 >      
585 >      
586 >      out_coords =
587 >        (struct coords *)calloc(n_atoms, sizeof(struct coords));
588 >      
589 >      for(i = 0; i < n_atoms; i++){
590 >        strcpy(out_coords[i].name, current_frame->r[i].name);
591 >        out_coords[i].x = current_frame->r[i].x;
592 >        out_coords[i].y = current_frame->r[i].y;
593 >        out_coords[i].z = current_frame->r[i].z;
594  
595 <    /* open the new output file */
596 <    
597 <    sprintf(out_name, out_format, n_out );
598 <    out_file = fopen(out_name, "w");
599 <    n_out++;
600 <    if(out_file == NULL){
601 <      printf("error opening output file: %s\n", out_name);
602 <      exit(8);
603 <    }
604 <    (void)fprintf(out_file,
605 <                  "// The following script was automatically generated by:\n"
606 <                  "// xyz2pov Copyright 2001 by MATTHEW A. MEINEKE\n"
607 <                  "\n"
608 <                  "#include \"pov_header.pov\"\n"
609 <                  "\n");
610 <    
611 <    out_coords =
354 <      (struct coords *)calloc(n_atoms, sizeof(struct coords));
355 <    
356 <    for(i = 0; i < n_atoms; i++){
357 <      strcpy(out_coords[i].name, current_frame->r[i].name);
358 <      out_coords[i].x = current_frame->r[i].x;
359 <      out_coords[i].y = current_frame->r[i].y;
360 <      out_coords[i].z = current_frame->r[i].z;
595 >        if (current_frame->r[i].hasVector) {              
596 >          out_coords[i].hasVector = current_frame->r[i].hasVector;
597 >          out_coords[i].ux = current_frame->r[i].ux;
598 >          out_coords[i].uy = current_frame->r[i].uy;
599 >          out_coords[i].uz = current_frame->r[i].uz;
600 >        }
601 >
602 >        if (current_frame->r[i].hasCharge) {              
603 >          out_coords[i].hasCharge = current_frame->r[i].hasCharge;
604 >          out_coords[i].charge = current_frame->r[i].charge;
605 >        }
606 >      }
607 >      pov_write(out_file, out_coords, n_atoms, draw_hydrogens, draw_bonds,
608 >                draw_atoms, draw_vectors);
609 >      free(out_coords);
610 >      
611 >      (void)fclose(out_file);
612      }
362    pov_write(out_file, out_coords, n_atoms, draw_hydrogens, draw_bonds,
363              draw_atoms);
364    free(out_coords);
613      
366    (void)fclose(out_file);
367          
614      /*free up memory */
615  
616      temp_frame = current_frame->next;
# Line 384 | Line 630 | int main(argc, argv)
630      
631      eof_test = fgets(read_buffer, sizeof(read_buffer), in_file);
632  
633 +    if( haveEnd ){
634 +      if( currentCount >= (endFrame + n_interpolate * span) ) done = 1;
635 +    }
636    }
637  
638    (void)fclose(in_file);
# Line 399 | Line 648 | int main(argc, argv)
648      diagonal = sqrt(rsqr);
649      diagonal *= 0.5;
650      
651 +    // calculate the center
652 +
653 +    dx = big_x + small_x;
654 +    dy = big_y + small_y;
655 +    dz = big_z + small_z;
656 +
657      dx /= 2.0;
658      dy /= 2.0;
659      dz /= 2.0;
660 <    
406 <    dx += small_x;
407 <    dy += small_y;
408 <    dz += small_z;
409 <    
660 >        
661  
662      /*note the y and z axis is exchanged for the different coordinate
663        system in pov-ray*/
# Line 437 | Line 688 | int main(argc, argv)
688              "#declare Height = 480.0;\n"
689              "#declare Ratio = Width / Height;\n"
690              "\n"
440            "#declare zoom = %lf;\n"
441            "\n"
691              "#declare ATOM_SPHERE_FACTOR = 0.2;\n"
692              "#declare BOND_RADIUS = 0.1;\n"
693 +            "#declare VECTOR_SCALE = 1.0;\n"    
694 +            "#declare STICK_RADIUS = 0.5 * BOND_RADIUS;\n"
695 +            "#declare CONE_RADIUS = 2.0 * STICK_RADIUS;\n"
696 +            "#declare CONE_FRACTION = 0.15;\n"
697              "\n"
698 <            "camera{\n"
699 <            "  location < %lf, %lf, %lf - zoom>\n"
700 <            "  right < Ratio , 0, 0>\n"
701 <            "  look_at < %lf, %lf, %lf >\n"
702 <            "}\n"
698 >            "// declare camera, light, and system variables\n"
699 >            "\n"
700 >            "#declare sysCenterX = %lf;\n"
701 >            "#declare sysCenterY = %lf;\n"
702 >            "#declare sysCenterZ = %lf;\n"
703 >            "\n"
704 >            "#declare zoom = %lf;\n"
705              "\n",
451            diagonal,
706              dx, dz, dy,
707 <            dx, dz, dy);
708 <
707 >            diagonal );
708 >    
709      fprintf(out_file,
710 +            "#declare cameraLookX = sysCenterX;\n"
711 +            "#declare cameraLookY = sysCenterY;\n"
712 +            "#declare cameraLookZ = sysCenterZ;\n"
713 +            "\n"
714 +            "#declare cameraX = cameraLookX;\n"
715 +            "#declare cameraY = cameraLookY;\n"
716 +            "#declare cameraZ = cameraLookZ - zoom;\n"
717 +            "\n"
718 +            "#declare lightAx = cameraX;\n"
719 +            "#declare lightAy = cameraY;\n"
720 +            "#declare lightAz = cameraZ;\n"
721 +            "\n"
722 +            "#declare lightBx = cameraX - zoom;\n"
723 +            "#declare lightBy = cameraY + zoom;\n"
724 +            "#declare lightBz = cameraZ;\n"
725 +            "\n"
726 +            "#declare boxCenterX = cameraLookX;\n"
727 +            "#declare boxCenterY = cameraLookY;\n"
728 +            "#declare boxCenterZ = cameraLookZ;\n"
729 +            "\n"
730 +            "// declare the cameras and the light sources\n"
731 +            "\n"
732 +            "camera{\n"
733 +            "  location < cameraX, cameraY, cameraZ>\n"
734 +            "  right < Ratio , 0, 0>\n"
735 +            "  look_at < cameraLookX, cameraLookY, cameraLookZ >\n"
736 +            "}\n"
737 +            "\n"
738              "light_source{\n"
739 <            "  < %lf, %lf, %lf - zoom >\n"
740 <            "  rgb < 1.0, 1.0, 1.0 > }\n",
741 <            dx, dz, dy);
460 <        
461 <    fprintf(out_file,
739 >            "  < lightAx, lightAy, lightAz >\n"
740 >            "  rgb < 1.0, 1.0, 1.0 > }\n"
741 >            "\n"
742              "light_source{\n"
743 <            "  < %lf - zoom , %lf + zoom, %lf - zoom >\n"
743 >            "  < lightBx, lightBy, lightBz >\n"
744              "  rgb < 1.0, 1.0, 1.0 > }\n"
745              "\n"
746 <            "\n",
467 <            dx, dz, dy);
468 <
469 <    fprintf(out_file,
746 >            "\n"
747              "//************************************************************\n"
748              "// Set whether or not to rotate the system.\n"
749              "//\n"
# Line 495 | Line 772 | int main(argc, argv)
772              "  #declare A31 = sin(phi_r) * sin(theta_r);\n"
773              "  #declare A32 = -cos(phi_r) * sin(theta_r);\n"
774              "  #declare A33 = cos(theta_r);\n"
775 +            "\n"
776 +            "#end\n"
777 +            "\n"
778 +            "\n"
779 +            "//************************************************************\n"
780 +            "// declare the periodic box macro\n"
781 +            "//************************************************************\n"
782 +            "\n"
783 +            "#macro makePeriodicBox( bx1, by1, bz1, bx2, by2, bz2, bx3, by3, bz3 )\n"
784 +            "\n"
785 +            "  #local bcx = (bx1 + bx2 + bx3) / 2.0;\n"
786 +            "  #local bcy = (by1 + by2 + by3) / 2.0;\n"
787 +            "  #local bcz = (bz1 + bz2 + bz3) / 2.0;\n"
788 +            "\n"
789 +            "  #local pAx = boxCenterX - bcx;\n"
790 +            "  #local pAy = boxCenterY - bcy;\n"
791 +            "  #local pAz = boxCenterZ - bcz;\n"
792 +            "  #local pBx = boxCenterX + bx1 - bcx;\n"
793 +            "  #local pBy = boxCenterY + by1 - bcy;\n"
794 +            "  #local pBz = boxCenterZ + bz1 - bcz;\n"
795 +            "  #local pCx = boxCenterX + bx2 - bcx;\n"
796 +            "  #local pCy = boxCenterY + by2 - bcy;\n"
797 +            "  #local pCz = boxCenterZ + bz2 - bcz;\n"
798 +            "  #local pDx = boxCenterX + bx3 - bcx;\n"
799 +            "  #local pDy = boxCenterY + by3 - bcy;\n"
800 +            "  #local pDz = boxCenterZ + bz3 - bcz;\n"
801 +            "  #local pEx = boxCenterX + bx1 + bx2 - bcx;\n"
802 +            "  #local pEy = boxCenterY + by1 + by2 - bcy;\n"
803 +            "  #local pEz = boxCenterZ + bz1 + bz2 - bcz;\n"
804 +            "  #local pFx = boxCenterX + bx1 + bx3 - bcx;\n"
805 +            "  #local pFy = boxCenterY + by1 + by3 - bcy;\n"
806 +            "  #local pFz = boxCenterZ + bz1 + bz3 - bcz;\n"
807 +            "  #local pGx = boxCenterX + bx2 + bx3 - bcx;\n"
808 +            "  #local pGy = boxCenterY + by2 + by3 - bcy;\n"
809 +            "  #local pGz = boxCenterZ + bz2 + bz3 - bcz;\n"
810 +            "  #local pHx = boxCenterX + bx1 + bx2 + bx3 - bcx;\n"
811 +            "  #local pHy = boxCenterY + by1 + by2 + by3 - bcy;\n"
812 +            "  #local pHz = boxCenterZ + bz1 + bz2 + bz3 - bcz;\n"
813 +            "\n"
814 +            "  #local colorR = 0.90;\n"
815 +            "  #local colorG = 0.91;\n"
816 +            "  #local colorB = 0.98;\n"
817 +            "\n"
818 +            "  #local pipeWidth = 0.4;\n"
819 +            "\n"
820 +            "  // 1\n"
821 +            "  cylinder{\n"
822 +            "    < pAx, pAy, pAz >,\n"
823 +            "    < pBx, pBy, pBz >,\n"
824 +            "    pipeWidth\n"
825 +            "    texture{\n"
826 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
827 +            "      finish{\n"
828 +            "        ambient .2\n"
829 +            "        diffuse .6\n"
830 +            "        specular 1\n"
831 +            "        roughness .001\n"
832 +            "        metallic\n"
833 +            "      }\n"
834 +            "    }\n"
835 +            "  }\n"
836 +            "\n"
837 +            "  // 2\n"
838 +            "  cylinder{\n"
839 +            "    < pAx, pAy, pAz >,\n"
840 +            "    < pCx, pCy, pCz >,\n"
841 +            "    pipeWidth\n"
842 +            "    texture{\n"
843 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
844 +            "      finish{\n"
845 +            "        ambient .2\n"
846 +            "        diffuse .6\n"
847 +            "        specular 1\n"
848 +            "        roughness .001\n"
849 +            "        metallic\n"
850 +            "      }\n"
851 +            "    }\n"
852 +            "  }\n"
853 +            "\n"
854 +            "  // 3\n"
855 +            "  cylinder{\n"
856 +            "    < pAx, pAy, pAz >,\n"
857 +            "    < pDx, pDy, pDz >,\n"
858 +            "    pipeWidth\n"
859 +            "    texture{\n"
860 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
861 +            "      finish{\n"
862 +            "        ambient .2\n"
863 +            "        diffuse .6\n"
864 +            "        specular 1\n"
865 +            "        roughness .001\n"
866 +            "        metallic\n"
867 +            "      }\n"
868 +            "    }\n"
869 +            "  }\n"
870              "\n"
871 +            "  // 4\n"
872 +            "  cylinder{\n"
873 +            "    < pBx, pBy, pBz >,\n"
874 +            "    < pEx, pEy, pEz >,\n"
875 +            "    pipeWidth\n"
876 +            "    texture{\n"
877 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
878 +            "      finish{\n"
879 +            "        ambient .2\n"
880 +            "        diffuse .6\n"
881 +            "        specular 1\n"
882 +            "        roughness .001\n"
883 +            "        metallic\n"
884 +            "      }\n"
885 +            "    }\n"
886 +            "  }\n"
887 +            "\n"
888 +            "  // 5\n"
889 +            "  cylinder{\n"
890 +            "    < pCx, pCy, pCz >,\n"
891 +            "    < pEx, pEy, pEz >,\n"
892 +            "    pipeWidth\n"
893 +            "    texture{\n"
894 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
895 +            "      finish{\n"
896 +            "        ambient .2\n"
897 +            "        diffuse .6\n"
898 +            "        specular 1\n"
899 +            "        roughness .001\n"
900 +            "        metallic\n"
901 +            "      }\n"
902 +            "    }\n"
903 +            "  }\n"
904 +            "\n"
905 +            "  // 6\n"
906 +            "  cylinder{\n"
907 +            "    < pBx, pBy, pBz >,\n"
908 +            "    < pFx, pFy, pFz >,\n"
909 +            "    pipeWidth\n"
910 +            "    texture{\n"
911 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
912 +            "      finish{\n"
913 +            "        ambient .2\n"
914 +            "        diffuse .6\n"
915 +            "        specular 1\n"
916 +            "        roughness .001\n"
917 +            "        metallic\n"
918 +            "      }\n"
919 +            "    }\n"
920 +            "  }\n"
921 +            "\n"
922 +            "  // 7\n"
923 +            "  cylinder{\n"
924 +            "    < pCx, pCy, pCz >,\n"
925 +            "    < pGx, pGy, pGz >,\n"
926 +            "    pipeWidth\n"
927 +            "    texture{\n"
928 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
929 +            "      finish{\n"
930 +            "        ambient .2\n"
931 +            "        diffuse .6\n"
932 +            "        specular 1\n"
933 +            "        roughness .001\n"
934 +            "        metallic\n"
935 +            "      }\n"
936 +            "    }\n"
937 +            "  }\n"
938 +            "\n"
939 +            "  // 8\n"
940 +            "  cylinder{\n"
941 +            "    < pDx, pDy, pDz >,\n"
942 +            "    < pGx, pGy, pGz >,\n"
943 +            "    pipeWidth\n"
944 +            "    texture{\n"
945 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
946 +            "      finish{\n"
947 +            "        ambient .2\n"
948 +            "        diffuse .6\n"
949 +            "        specular 1\n"
950 +            "        roughness .001\n"
951 +            "        metallic\n"
952 +            "      }\n"
953 +            "    }\n"
954 +            "  }\n"
955 +            "\n"
956 +            "  // 9\n"
957 +            "  cylinder{\n"
958 +            "    < pDx, pDy, pDz >,\n"
959 +            "    < pFx, pFy, pFz >,\n"
960 +            "    pipeWidth\n"
961 +            "    texture{\n"
962 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
963 +            "      finish{\n"
964 +            "        ambient .2\n"
965 +            "        diffuse .6\n"
966 +            "        specular 1\n"
967 +            "        roughness .001\n"
968 +            "        metallic\n"
969 +            "      }\n"
970 +            "    }\n"
971 +            "  }\n"
972 +            "\n"
973 +            "  // 10\n"
974 +            "  cylinder{\n"
975 +            "    < pEx, pEy, pEz >,\n"
976 +            "    < pHx, pHy, pHz >,\n"
977 +            "    pipeWidth\n"
978 +            "    texture{\n"
979 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
980 +            "      finish{\n"
981 +            "        ambient .2\n"
982 +            "        diffuse .6\n"
983 +            "        specular 1\n"
984 +            "        roughness .001\n"
985 +            "        metallic\n"
986 +            "      }\n"
987 +            "    }\n"
988 +            "  }\n"
989 +            "\n"
990 +            "  // 11\n"
991 +            "  cylinder{\n"
992 +            "    < pFx, pFy, pFz >,\n"
993 +            "    < pHx, pHy, pHz >,\n"
994 +            "    pipeWidth\n"
995 +            "    texture{\n"
996 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
997 +            "      finish{\n"
998 +            "        ambient .2\n"
999 +            "        diffuse .6\n"
1000 +            "        specular 1\n"
1001 +            "        roughness .001\n"
1002 +            "        metallic\n"
1003 +            "      }\n"
1004 +            "    }\n"
1005 +            "  }\n"
1006 +            "\n"
1007 +            "  // 12\n"
1008 +            "  cylinder{\n"
1009 +            "    < pGx, pGy, pGz >,\n"
1010 +            "    < pHx, pHy, pHz >,\n"
1011 +            "    pipeWidth\n"
1012 +            "    texture{\n"
1013 +            "      pigment{ rgb < colorR, colorG, colorB > }\n"
1014 +            "      finish{\n"
1015 +            "        ambient .2\n"
1016 +            "        diffuse .6\n"
1017 +            "        specular 1\n"
1018 +            "        roughness .001\n"
1019 +            "        metallic\n"
1020 +            "      }\n"
1021 +            "    }\n"
1022 +            "  }\n"
1023 +            "\n"
1024              "#end\n"
1025 +            "\n"
1026              "\n");
1027 <    
1028 <    
1027 >
1028 >
1029 >
1030 >
1031      make_header_macros(out_file);
1032  
1033      fclose(out_file);
# Line 527 | Line 1055 | void usage(){
1055                  "   -h            draw hydrogens\n"
1056                  "   -b            draw bonds\n"
1057                  "   -a            draw atoms\n"
1058 +                "   -v            draw vectors\n"
1059 +                "   -p            draw periodic box\n"
1060 +                "   -r            regenerate bond\n"
1061 +                "   -f <#>        render frame <#> only\n"
1062 +                "   -s <#>        begin at frame <#> (inclusive)\n"
1063 +                "   -e <#>        end at frame <#> (inclusive)\n"
1064                  "\n",
1065                  program_name);
1066    exit(8);
1067   }
1068 +
1069 + int count_tokens(line, delimiters)
1070 +     /* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */
1071 +     char *line;                /* LINE CONTAINING TOKENS. */
1072 +     char *delimiters;  /* POSSIBLE TOKEN DELIMITERS TO USE. */
1073 + {
1074 +  char *working_line;   /* WORKING COPY OF LINE. */
1075 +  int ntokens;          /* NUMBER OF TOKENS FOUND IN LINE. */
1076 +  char *strtok_ptr;     /* POINTER FOR STRTOK. */
1077 +  
1078 +  strtok_ptr= working_line= strdup(line);
1079 +  
1080 +  ntokens=0;
1081 +  while (strtok(strtok_ptr,delimiters)!=NULL)
1082 +    {
1083 +      ntokens++;
1084 +      strtok_ptr=NULL;
1085 +    }
1086 +  
1087 +  free(working_line);
1088 +  return(ntokens);
1089 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines