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 629 by mmeineke, Thu Jul 17 15:47:36 2003 UTC vs.
Revision 868 by gezelter, Wed Nov 19 16:26:33 2003 UTC

# Line 24 | 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 47 | 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 66 | 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;
# Line 180 | 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':
# Line 271 | 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 303 | Line 313 | int main(argc, argv)
313      if( draw_box ){
314        foo = strtok(read_buffer, " ,;\t");
315        if(foo == NULL){
316 <        printf("error in reading file\n");
316 >        printf("error in reading file time\n");
317          exit(8);
318        }
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        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        current_frame->Hmat[1][0] = atof( foo );
333  
334        foo = strtok(NULL, " ,;\t");
335        if(foo == NULL){
336 <        printf("error in reading file\n");
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        current_frame->Hmat[0][1] = atof( foo );
347  
348        foo = strtok(NULL, " ,;\t");
349        if(foo == NULL){
350 <        printf("error in reading file\n");
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\n");
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\n");
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\n");
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\n");
378 >        printf("error in reading file h22\n");
379          exit(8);
380        }
381        current_frame->Hmat[2][2] = atof( foo );
# Line 376 | Line 386 | int main(argc, argv)
386        
387        eof_test = fgets(read_buffer, sizeof(read_buffer), in_file);
388        if(eof_test == NULL){
389 <        printf("error in reading file\n");
389 >        printf("error in reading file line at atom %d\n", i);
390          exit(8);
391        }
392  
393 <      foo = strtok(read_buffer, " ,;\t");
394 <      if(foo == NULL){
395 <        printf("error in reading file\n");
396 <        exit(8);
393 >      nTokens = count_tokens(read_buffer, " ,;\t");
394 >
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  
390      /* next we grab the positions */
391      
403        foo = strtok(NULL, " ,;\t");
393      if(foo == NULL){
394        printf("error in reading file\n");
395        exit(8);
396      }
404        (void)sscanf(foo, "%lf",&current_frame->r[i].x);
398      if(current_frame->r[i].x > big_x) big_x = current_frame->r[i].x;
399      if(current_frame->r[i].x < small_x) small_x = current_frame->r[i].x;
400            
401  
405        foo = strtok(NULL, " ,;\t");
403      if(foo == NULL){
404        printf("error in reading file\n");
405        exit(8);
406      }
406        (void)sscanf(foo, "%lf", &current_frame->r[i].y);
408      if(current_frame->r[i].y > big_y) big_y = current_frame->r[i].y;
409      if(current_frame->r[i].y < small_y) small_y = current_frame->r[i].y;
410
411
407        foo = strtok(NULL, " ,;\t");
413      if(foo == NULL){
414        printf("error in reading file\n");
415        exit(8);
416      }
408        (void)sscanf(foo, "%lf", &current_frame->r[i].z);
409 <      if(current_frame->r[i].z > big_z) big_z = current_frame->r[i].z;
410 <      if(current_frame->r[i].z < small_z) small_z = 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      
# Line 484 | Line 516 | int main(argc, argv)
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);
547 >                    draw_atoms, draw_vectors);
548            free(out_coords);
549            (void)fclose(out_file);
550          }
# Line 511 | Line 568 | int main(argc, argv)
568        if( draw_box ){
569          
570          fprintf( out_file,
571 <                 "makePeriodicBox( %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf %lf )\n"
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],
# Line 534 | Line 591 | int main(argc, argv)
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 +        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);
608 >                draw_atoms, draw_vectors);
609        free(out_coords);
610        
611        (void)fclose(out_file);
# Line 621 | Line 690 | int main(argc, argv)
690              "\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              "// declare camera, light, and system variables\n"
699              "\n"
# Line 638 | Line 711 | int main(argc, argv)
711              "#declare cameraLookY = sysCenterY;\n"
712              "#declare cameraLookZ = sysCenterZ;\n"
713              "\n"
714 +            "#declare rotatePointX = cameraLookX;\n"
715 +            "#declare rotatePointY = cameraLookY;\n"
716 +            "#declare rotatePointZ = cameraLookZ;\n"
717 +            "\n"
718              "#declare cameraX = cameraLookX;\n"
719              "#declare cameraY = cameraLookY;\n"
720              "#declare cameraZ = cameraLookZ - zoom;\n"
# Line 737 | Line 814 | int main(argc, argv)
814              "  #local pHx = boxCenterX + bx1 + bx2 + bx3 - bcx;\n"
815              "  #local pHy = boxCenterY + by1 + by2 + by3 - bcy;\n"
816              "  #local pHz = boxCenterZ + bz1 + bz2 + bz3 - bcz;\n"
817 +            "\n"
818 +            "  #if(ROTATE)\n"
819 +            "    #local pAx_new = rotatePointX + A11 * (pAx-rotatePointX) + A12 * (pAy-rotatePointY) + A13 * (pAz-rotatePointZ);\n"
820 +            "    #local pAy_new = rotatePointY + A21 * (pAx-rotatePointX) + A22 * (pAy-rotatePointY) + A23 * (pAz-rotatePointZ);\n"
821 +            "    #local pAz_new = rotatePointZ + A31 * (pAx-rotatePointX) + A32 * (pAy-rotatePointY) + A33 * (pAz-rotatePointZ);\n"
822 +            "\n"
823 +            "    #local pBx_new = rotatePointX + A11 * (pBx-rotatePointX) + A12 * (pBy-rotatePointY) + A13 * (pBz-rotatePointZ);\n"
824 +            "    #local pBy_new = rotatePointY + A21 * (pBx-rotatePointX) + A22 * (pBy-rotatePointY) + A23 * (pBz-rotatePointZ);\n"
825 +            "    #local pBz_new = rotatePointZ + A31 * (pBx-rotatePointX) + A32 * (pBy-rotatePointY) + A33 * (pBz-rotatePointZ);\n"
826 +            "\n"
827 +            "    #local pCx_new = rotatePointX + A11 * (pCx-rotatePointX) + A12 * (pCy-rotatePointY) + A13 * (pCz-rotatePointZ);\n"
828 +            "    #local pCy_new = rotatePointY + A21 * (pCx-rotatePointX) + A22 * (pCy-rotatePointY) + A23 * (pCz-rotatePointZ);\n"
829 +            "    #local pCz_new = rotatePointZ + A31 * (pCx-rotatePointX) + A32 * (pCy-rotatePointY) + A33 * (pCz-rotatePointZ);\n"
830 +            "\n"
831 +            "    #local pDx_new = rotatePointX + A11 * (pDx-rotatePointX) + A12 * (pDy-rotatePointY) + A13 * (pDz-rotatePointZ);\n"
832 +            "    #local pDy_new = rotatePointY + A21 * (pDx-rotatePointX) + A22 * (pDy-rotatePointY) + A23 * (pDz-rotatePointZ);\n"
833 +            "    #local pDz_new = rotatePointZ + A31 * (pDx-rotatePointX) + A32 * (pDy-rotatePointY) + A33 * (pDz-rotatePointZ);\n"
834 +            "\n"
835 +            "    #local pEx_new = rotatePointX + A11 * (pEx-rotatePointX) + A12 * (pEy-rotatePointY) + A13 * (pEz-rotatePointZ);\n"
836 +            "    #local pEy_new = rotatePointY + A21 * (pEx-rotatePointX) + A22 * (pEy-rotatePointY) + A23 * (pEz-rotatePointZ);\n"
837 +            "    #local pEz_new = rotatePointZ + A31 * (pEx-rotatePointX) + A32 * (pEy-rotatePointY) + A33 * (pEz-rotatePointZ);\n"
838 +            "\n"
839 +            "    #local pFx_new = rotatePointX + A11 * (pFx-rotatePointX) + A12 * (pFy-rotatePointY) + A13 * (pFz-rotatePointZ);\n"
840 +            "    #local pFy_new = rotatePointY + A21 * (pFx-rotatePointX) + A22 * (pFy-rotatePointY) + A23 * (pFz-rotatePointZ);\n"
841 +            "    #local pFz_new = rotatePointZ + A31 * (pFx-rotatePointX) + A32 * (pFy-rotatePointY) + A33 * (pFz-rotatePointZ);\n"
842 +            "\n"
843 +            "    #local pGx_new = rotatePointX + A11 * (pGx-rotatePointX) + A12 * (pGy-rotatePointY) + A13 * (pGz-rotatePointZ);\n"
844 +            "    #local pGy_new = rotatePointY + A21 * (pGx-rotatePointX) + A22 * (pGy-rotatePointY) + A23 * (pGz-rotatePointZ);\n"
845 +            "    #local pGz_new = rotatePointZ + A31 * (pGx-rotatePointX) + A32 * (pGy-rotatePointY) + A33 * (pGz-rotatePointZ);\n"
846 +            "\n"
847 +            "    #local pHx_new = rotatePointX + A11 * (pHx-rotatePointX) + A12 * (pHy-rotatePointY) + A13 * (pHz-rotatePointZ);\n"
848 +            "    #local pHy_new = rotatePointY + A21 * (pHx-rotatePointX) + A22 * (pHy-rotatePointY) + A23 * (pHz-rotatePointZ);\n"
849 +            "    #local pHz_new = rotatePointZ + A31 * (pHx-rotatePointX) + A32 * (pHy-rotatePointY) + A33 * (pHz-rotatePointZ);\n"
850 +            "\n"
851 +            "  #else\n"
852 +            "    #local pAx_new = pAx;"
853 +            "    #local pAy_new = pAy;"
854 +            "    #local pAz_new = pAz;"
855 +            "\n"
856 +            "    #local pBx_new = pBx;"
857 +            "    #local pBy_new = pBy;"
858 +            "    #local pBz_new = pBz;"
859 +            "\n"
860 +            "    #local pCx_new = pCx;"
861 +            "    #local pCy_new = pCy;"
862 +            "    #local pCz_new = pCz;"
863 +            "\n"
864 +            "    #local pDx_new = pDx;"
865 +            "    #local pDy_new = pDy;"
866 +            "    #local pDz_new = pDz;"
867 +            "\n"
868 +            "    #local pEx_new = pEx;"
869 +            "    #local pEy_new = pEy;"
870 +            "    #local pEz_new = pEz;"
871 +            "\n"
872 +            "    #local pFx_new = pFx;"
873 +            "    #local pFy_new = pFy;"
874 +            "    #local pFz_new = pFz;"
875 +            "\n"
876 +            "    #local pGx_new = pGx;"
877 +            "    #local pGy_new = pGy;"
878 +            "    #local pGz_new = pGz;"
879 +            "\n"
880 +            "    #local pHx_new = pHx;"
881 +            "    #local pHy_new = pHy;"
882 +            "    #local pHz_new = pHz;"
883 +            "\n"
884 +            "  #end\n"
885 +            "  #local pAx = pAx_new;"
886 +            "  #local pAy = pAy_new;"
887 +            "  #local pAz = pAz_new;"
888 +            "\n"                    
889 +            "  #local pBx = pBx_new;"
890 +            "  #local pBy = pBy_new;"
891 +            "  #local pBz = pBz_new;"
892 +            "\n"                    
893 +            "  #local pCx = pCx_new;"
894 +            "  #local pCy = pCy_new;"
895 +            "  #local pCz = pCz_new;"
896 +            "\n"                    
897 +            "  #local pDx = pDx_new;"
898 +            "  #local pDy = pDy_new;"
899 +            "  #local pDz = pDz_new;"
900 +            "\n"                    
901 +            "  #local pEx = pEx_new;"
902 +            "  #local pEy = pEy_new;"
903 +            "  #local pEz = pEz_new;"
904 +            "\n"                    
905 +            "  #local pFx = pFx_new;"
906 +            "  #local pFy = pFy_new;"
907 +            "  #local pFz = pFz_new;"
908 +            "\n"                    
909 +            "  #local pGx = pGx_new;"
910 +            "  #local pGy = pGy_new;"
911 +            "  #local pGz = pGz_new;"
912 +            "\n"                    
913 +            "  #local pHx = pHx_new;"
914 +            "  #local pHy = pHy_new;"
915 +            "  #local pHz = pHz_new;"
916              "\n"
917              "  #local colorR = 0.90;\n"
918              "  #local colorG = 0.91;\n"
# Line 982 | Line 1158 | void usage(){
1158                  "   -h            draw hydrogens\n"
1159                  "   -b            draw bonds\n"
1160                  "   -a            draw atoms\n"
1161 +                "   -v            draw vectors\n"
1162                  "   -p            draw periodic box\n"
1163                  "   -r            regenerate bond\n"
1164                  "   -f <#>        render frame <#> only\n"
# Line 990 | Line 1167 | void usage(){
1167                  "\n",
1168                  program_name);
1169    exit(8);
1170 + }
1171 +
1172 + int count_tokens(line, delimiters)
1173 +     /* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */
1174 +     char *line;                /* LINE CONTAINING TOKENS. */
1175 +     char *delimiters;  /* POSSIBLE TOKEN DELIMITERS TO USE. */
1176 + {
1177 +  char *working_line;   /* WORKING COPY OF LINE. */
1178 +  int ntokens;          /* NUMBER OF TOKENS FOUND IN LINE. */
1179 +  char *strtok_ptr;     /* POINTER FOR STRTOK. */
1180 +  
1181 +  strtok_ptr= working_line= strdup(line);
1182 +  
1183 +  ntokens=0;
1184 +  while (strtok(strtok_ptr,delimiters)!=NULL)
1185 +    {
1186 +      ntokens++;
1187 +      strtok_ptr=NULL;
1188 +    }
1189 +  
1190 +  free(working_line);
1191 +  return(ntokens);
1192   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines