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

Comparing trunk/xyz2pov/src/pov_writer.c (file contents):
Revision 508 by mmeineke, Tue Apr 29 15:21:34 2003 UTC vs.
Revision 2750 by tim, Fri May 12 19:24:30 2006 UTC

# Line 1 | Line 1
1 + #define _FILE_OFFSET_BITS 64
2 +
3   #include <stdio.h>
4   #include <stdlib.h>
5   #include <string.h>
# Line 27 | Line 29 | void pov_write(FILE *out_file, struct coords *the_coor
29   }
30  
31   void pov_write(FILE *out_file, struct coords *the_coords, int n_atoms,
32 <               int d_hydrogens, int d_bonds, int d_atoms){
32 >               int d_hydrogens, int d_bonds, int d_atoms, int d_vectors){
33  
34    int i,j; /*loop counters */
35    int skip_atom, skip_bond, test1, test2; /*booleans */
36 +  int gb_atom, gbdp_atom;
37    double dx, dy, dz; /* used in making the bonds */
38    
39    struct linked_bond_list *current_bond; /*keeps track of the linked list*/
# Line 47 | Line 50 | void pov_write(FILE *out_file, struct coords *the_coor
50              "//************************************************************\n"
51              "\n"
52              "\n");
53 <
53 >    
54      for(i = 0; i < n_atoms; i++){
55        
56 <      skip_atom = 0;
56 >      skip_atom = 0;    
57        
58        if(!d_hydrogens){
59          skip_atom = !strcmp("H", the_coords[i].name);
60        }
61        
62 <      if(!skip_atom){
63 <        
64 <        fprintf(out_file,
65 <                "make_%s_atom( %lf, %lf, %lf )\n",
66 <                the_coords[i].name,
67 <                the_coords[i].x,
68 <                the_coords[i].z,
69 <                the_coords[i].y);
62 >      if(!skip_atom){          
63 >        
64 >        gb_atom = !strcmp("GB", the_coords[i].name);
65 >        gbdp_atom = !strcmp("GBDP", the_coords[i].name);
66 >        
67 >        if (gb_atom) {
68 >          fprintf(out_file,
69 >                  "make_%s_ellipse( %lf, %lf, %lf, %lf, %lf, %lf, %lf)\n",
70 >                  the_coords[i].name,
71 >                  the_coords[i].x,
72 >                  the_coords[i].z,
73 >                  the_coords[i].y,
74 >                  the_coords[i].charge,
75 >                  the_coords[i].ux,
76 >                  the_coords[i].uz,
77 >                  the_coords[i].uy);
78 >        } else {
79 >          if (gbdp_atom) {
80 >            fprintf(out_file,
81 >                    "make_%s_shaded_ellipse( %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf)\n",
82 >                    the_coords[i].name,
83 >                    the_coords[i].x,
84 >                    the_coords[i].z,
85 >                    the_coords[i].y,
86 >                    the_coords[i].charge,
87 >                    the_coords[i].ux,
88 >                    the_coords[i].uz,
89 >                    the_coords[i].uy,
90 >                    the_coords[i].vx,
91 >                    the_coords[i].vz,
92 >                    the_coords[i].vy);
93 >          } else {
94 >            fprintf(out_file,
95 >                    "make_%s_atom( %lf, %lf, %lf )\n",
96 >                    the_coords[i].name,
97 >                    the_coords[i].x,
98 >                    the_coords[i].z,
99 >                    the_coords[i].y);
100 >          }
101 >        }
102        }
103      }
104      
105      fprintf(out_file,
106              "\n"
107              "\n");
108 +  }
109 +
110 +      
111 +  if (d_vectors) {
112 +
113 +    fprintf(out_file,
114 +            "//************************************************************\n"
115 +            "// The list of vectors\n"
116 +            "//************************************************************\n"
117 +            "\n"
118 +            "\n");
119      
120 +    for(i = 0; i < n_atoms; i++){
121 +      
122 +      if (the_coords[i].hasVector) {
123 +        fprintf(out_file,
124 +                "make_%s_vector(%lf, %lf, %lf, %lf, %lf, %lf)\n",
125 +                the_coords[i].name,
126 +                the_coords[i].x,
127 +                the_coords[i].z,
128 +                the_coords[i].y,
129 +                the_coords[i].ux,
130 +                the_coords[i].uz,
131 +                the_coords[i].uy);
132 +      }
133 +    }
134 +    
135 +    fprintf(out_file,
136 +            "\n"
137 +            "\n");
138    }
139 <  
139 >      
140    if(d_bonds){
141      
142      fprintf(out_file,
# Line 255 | Line 319 | void make_header_macros(FILE *out_file){
319              "  #local z2 = end_2z;\n"
320              "\n"
321              "  #if(ROTATE)\n"
322 <            "    #local x1_new = A11 * x1 + A12 * y1 + A13 * z1;\n"
323 <            "    #local y1_new = A21 * x1 + A22 * y1 + A23 * z1;\n"
324 <            "    #local z1_new = A31 * x1 + A32 * y1 + A33 * z1;\n"
322 >            "    #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
323 >            "    #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
324 >            "    #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
325              "\n"
326 <            "    #local x2_new = A11 * x2 + A12 * y2 + A13 * z2;\n"
327 <            "    #local y2_new = A21 * x2 + A22 * y2 + A23 * z2;\n"
328 <            "    #local z2_new = A31 * x2 + A32 * y2 + A33 * z2;\n"
326 >            "    #local x2_new = rotatePointX + A11 * (x2-rotatePointX) + A12 * (y2-rotatePointY) + A13 * (z2-rotatePointZ);\n"
327 >            "    #local y2_new = rotatePointY + A21 * (x2-rotatePointX) + A22 * (y2-rotatePointY) + A23 * (z2-rotatePointZ);\n"
328 >            "    #local z2_new = rotatePointZ + A31 * (x2-rotatePointX) + A32 * (y2-rotatePointY) + A33 * (z2-rotatePointZ);\n"
329              "\n"
330              "  #else\n"
331              "    #local x1_new = x1;"
# Line 299 | Line 363 | void make_header_macros(FILE *out_file){
363              "\n"
364              "  #if(ROTATE)\n"
365              "\n"
366 <            "    #local x1_new = A11 * x1 + A12 * y1 + A13 * z1;\n"
367 <            "    #local y1_new = A21 * x1 + A22 * y1 + A23 * z1;\n"
368 <            "    #local z1_new = A31 * x1 + A32 * y1 + A33 * z1;\n"
366 >            "    #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
367 >            "    #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
368 >            "    #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
369              "\n"
370              "  #else\n"
371              "\n"
# Line 314 | Line 378 | void make_header_macros(FILE *out_file){
378              "  sphere{\n"
379              "    < x1_new, y1_new, z1_new >,\n"
380              "    ATOM_SPHERE_FACTOR * %lf\n"
381 +            "    texture{\n"
382 +            "      pigment{ rgb < %lf, %lf, %lf > }\n"
383 +            "      finish{\n"
384 +            "        ambient .2\n"
385 +            "        diffuse .6\n"
386 +            "        specular 1\n"
387 +            "        roughness .001\n"
388 +            "        metallic\n"
389 +            "      }\n"
390 +            "    }\n"
391 +            "  }\n"
392 +            "#end\n"
393 +            "#macro make_%s_ellipse "
394 +            "(center_x, center_y, center_z, ecc, u_x, u_y, u_z)\n"
395 +                    "\n"
396 +            "  #local x1 = center_x;\n"
397 +            "  #local y1 = center_y;\n"
398 +            "  #local z1 = center_z;\n"
399 +            "  #local x2 = u_x;\n"
400 +            "  #local y2 = u_y;\n"
401 +            "  #local z2 = u_z;\n"
402 +            "\n"
403 +            "  #if(ROTATE)\n"
404 +            "\n"
405 +            "    #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
406 +            "    #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
407 +            "    #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
408 +            "\n"
409 +            "    #local x2_new = rotatePointX + A11 * (x2-rotatePointX) + A12 * (y2-rotatePointY) + A13 * (z2-rotatePointZ);\n"
410 +            "    #local y2_new = rotatePointY + A21 * (x2-rotatePointX) + A22 * (y2-rotatePointY) + A23 * (z2-rotatePointZ);\n"
411 +            "    #local z2_new = rotatePointZ + A31 * (x2-rotatePointX) + A32 * (y2-rotatePointY) + A33 * (z2-rotatePointZ);\n"
412 +            "\n"
413 +            "  #else\n"
414 +            "\n"
415 +            "    #local x1_new = x1;"
416 +            "    #local y1_new = y1;"
417 +            "    #local z1_new = z1;"
418 +            "\n"
419 +            "    #local x2_new = x2;"
420 +            "    #local y2_new = y2;"
421 +            "    #local z2_new = z2;"
422 +            "\n"
423 +            "  #end\n"
424 +            "\n"
425 +            "    #local myUlen = sqrt(x2_new*x2_new + y2_new*y2_new + z2_new*z2_new);\n"
426 +            "    #local uux = x2_new / myUlen;\n"
427 +            "    #local uuy = y2_new / myUlen;\n"
428 +            "    #local uuz = z2_new / myUlen;\n"
429 +            "    #local myTheta = -degrees(acos(uuz));\n"
430 +            "    #local myPsi = -degrees(atan(uux/uuy));\n"
431 +            "    #local myScale = ATOM_SPHERE_FACTOR * %lf;\n"
432 +            "\n"
433 +            "  sphere{\n"
434 +            "    < 0, 0, 0 >, 1\n"
435 +            "    texture{\n"
436 +            "      pigment{\n"
437 +            "        average\n"
438 +            "        pigment_map{\n"
439 +            "          [1.0 grad1]\n"
440 +            "          [1.0 grad2]\n"
441 +            "          [1.0 grad3]\n"
442 +            "          [5.0 gradz]\n"
443 +            "        }\n"
444 +            "      }\n"
445 +            "      finish{\n"
446 +            "        ambient .2\n"
447 +            "        diffuse .6\n"
448 +            "        specular 1\n"
449 +            "        roughness .001\n"
450 +            "        metallic\n"
451 +            "      }\n"
452 +            "    }\n"
453 +            "    scale<myScale,myScale,ecc*myScale>\n"
454 +            "    rotate<myTheta,0,myPsi>\n"
455 +            "    translate< x1_new, y1_new, z1_new>\n"
456 +            "  }\n"
457 +            "#end\n"
458 +            "#macro make_%s_shaded_ellipse "
459 +            "(center_x, center_y, center_z, ecc, u_x, u_y, u_z, v_x, v_y, v_z)\n"
460 +                    "\n"
461 +            "  #local x1 = center_x;\n"
462 +            "  #local y1 = center_y;\n"
463 +            "  #local z1 = center_z;\n"
464 +            "  #local x2 = u_x;\n"
465 +            "  #local y2 = u_y;\n"
466 +            "  #local z2 = u_z;\n"
467 +            "  #local x3 = v_x;\n"
468 +            "  #local y3 = v_y;\n"
469 +            "  #local z3 = v_z;\n"
470 +            "\n"
471 +            "  #if(ROTATE)\n"
472 +            "\n"
473 +            "    #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
474 +            "    #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
475 +            "    #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
476 +            "\n"
477 +            "    #local x2_new = rotatePointX + A11 * (x2-rotatePointX) + A12 * (y2-rotatePointY) + A13 * (z2-rotatePointZ);\n"
478 +            "    #local y2_new = rotatePointY + A21 * (x2-rotatePointX) + A22 * (y2-rotatePointY) + A23 * (z2-rotatePointZ);\n"
479 +            "    #local z2_new = rotatePointZ + A31 * (x2-rotatePointX) + A32 * (y2-rotatePointY) + A33 * (z2-rotatePointZ);\n"
480 +            "\n"
481 +            "    #local x3_new = rotatePointX + A11 * (x3-rotatePointX) + A12 * (y3-rotatePointY) + A13 * (z3-rotatePointZ);\n"
482 +            "    #local y3_new = rotatePointY + A21 * (x3-rotatePointX) + A22 * (y3-rotatePointY) + A23 * (z3-rotatePointZ);\n"
483 +            "    #local z3_new = rotatePointZ + A31 * (x3-rotatePointX) + A32 * (y3-rotatePointY) + A33 * (z3-rotatePointZ);\n"
484 +            "\n"
485 +            "  #else\n"
486 +            "\n"
487 +            "    #local x1_new = x1;"
488 +            "    #local y1_new = y1;"
489 +            "    #local z1_new = z1;"
490 +            "\n"
491 +            "    #local x2_new = x2;"
492 +            "    #local y2_new = y2;"
493 +            "    #local z2_new = z2;"
494 +            "\n"
495 +            "    #local x3_new = x3;"
496 +            "    #local y3_new = y3;"
497 +            "    #local z3_new = z3;"
498 +            "\n"
499 +            "  #end\n"
500 +            "\n"
501 +            "    #local myUlen = sqrt(x2_new*x2_new + y2_new*y2_new + z2_new*z2_new);\n"
502 +            "    #local uux = x2_new / myUlen;\n"
503 +            "    #local uuy = y2_new / myUlen;\n"
504 +            "    #local uuz = z2_new / myUlen;\n"
505 +            "    #local myVlen = sqrt(x3_new*x3_new + y3_new*y3_new + z3_new*z3_new);\n"
506 +            "    #local vvx = x3_new / myVlen;\n"
507 +            "    #local vvy = y3_new / myVlen;\n"
508 +            "    #local vvz = z3_new / myVlen;\n"
509 +            "\n"
510 +            "    #local myTheta = degrees(acos(uuz));\n"
511 +            "    #local myPsi = -degrees(atan(uux/uuy));\n"
512 +            "    #local myPhi = degrees(acos(vvz));\n"
513 +            "    #local myScale = ATOM_SPHERE_FACTOR * %lf;\n"
514 +            "\n"
515 +            "  sphere{\n"
516 +            "    < 0, 0, 0 >, 1\n"
517              "    texture{\n"
518 +            "      pigment{\n"
519 +            "        average\n"
520 +            "        pigment_map{\n"
521 +            "          [1.0 grad1]\n"
522 +            "          [1.0 grad2]\n"
523 +            "          [1.0 grad3]\n"
524 +            "          [5.0 gradz]\n"
525 +            "        }\n"
526 +            "      }\n"
527 +            "      finish{\n"
528 +            "        ambient .2\n"
529 +            "        diffuse .6\n"
530 +            "        specular 1\n"
531 +            "        roughness .001\n"
532 +            "        metallic\n"
533 +            "      }\n"
534 +            "    }\n"
535 +            "    scale<myScale,myScale,ecc*myScale>\n"
536 +            "    rotate<myTheta,myPhi,myPsi>\n"
537 +            "    translate< x1_new, y1_new, z1_new>\n"
538 +            "  }\n"
539 +            "#end\n"
540 +            "#macro make_%s_vector "
541 +            "(center_x, center_y, center_z, ux, uy, uz)\n"
542 +            "\n"
543 +            "  #local vx = VECTOR_SCALE * ux;\n"
544 +            "  #local vy = VECTOR_SCALE * uy;\n"
545 +            "  #local vz = VECTOR_SCALE * uz;\n"
546 +            "  #local x1 = center_x - 0.5 * vx;\n"
547 +            "  #local y1 = center_y - 0.5 * vy;\n"
548 +            "  #local z1 = center_z - 0.5 * vz;\n"
549 +            "  #local x2 = center_x + 0.5 * vx;\n"
550 +            "  #local y2 = center_y + 0.5 * vy;\n"
551 +            "  #local z2 = center_z + 0.5 * vz;\n"
552 +            "  #local v2 = vx*vx + vy*vy + vz*vz;\n"
553 +            "  #local vl  = sqrt(v2);\n"
554 +            "  #local x3 = x1 + vx * (1.0 - CONE_FRACTION);\n"
555 +            "  #local y3 = y1 + vy * (1.0 - CONE_FRACTION);\n"
556 +            "  #local z3 = z1 + vz * (1.0 - CONE_FRACTION);\n"
557 +            "\n"
558 +            "  #if(ROTATE)\n"
559 +            "    #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
560 +            "    #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
561 +            "    #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
562 +            "\n"
563 +            "    #local x2_new = rotatePointX + A11 * (x2-rotatePointX) + A12 * (y2-rotatePointY) + A13 * (z2-rotatePointZ);\n"
564 +            "    #local y2_new = rotatePointY + A21 * (x2-rotatePointX) + A22 * (y2-rotatePointY) + A23 * (z2-rotatePointZ);\n"
565 +            "    #local z2_new = rotatePointZ + A31 * (x2-rotatePointX) + A32 * (y2-rotatePointY) + A33 * (z2-rotatePointZ);\n"
566 +            "\n"
567 +            "    #local x3_new = rotatePointX + A11 * (x3-rotatePointX) + A12 * (y3-rotatePointY) + A13 * (z3-rotatePointZ);\n"
568 +            "    #local y3_new = rotatePointY + A21 * (x3-rotatePointX) + A22 * (y3-rotatePointY) + A23 * (z3-rotatePointZ);\n"
569 +            "    #local z3_new = rotatePointZ + A31 * (x3-rotatePointX) + A32 * (y3-rotatePointY) + A33 * (z3-rotatePointZ);\n"
570 +            "\n"
571 +            "  #else\n"
572 +            "    #local x1_new = x1;"
573 +            "    #local y1_new = y1;"
574 +            "    #local z1_new = z1;"
575 +            "\n"
576 +            "    #local x2_new = x2;"
577 +            "    #local y2_new = y2;"
578 +            "    #local z2_new = z2;"
579 +            "\n"
580 +            "    #local x3_new = x3;"
581 +            "    #local y3_new = y3;"
582 +            "    #local z3_new = z3;"
583 +            "\n"
584 +            "  #end\n"
585 +            "\n"
586 +            "  cylinder{\n"
587 +            "    < x1_new, y1_new, z1_new >,\n"
588 +            "    < x3_new, y3_new, z3_new >,\n"
589 +            "    STICK_RADIUS\n"
590 +            "    texture{\n"
591              "      pigment{ rgb < %lf, %lf, %lf > }\n"
592              "      finish{\n"
593              "        ambient .2\n"
# Line 325 | Line 598 | void make_header_macros(FILE *out_file){
598              "      }\n"
599              "    }\n"
600              "  }\n"
601 +            "  cone{\n"
602 +            "    < x2_new, y2_new, z2_new >, 0.0\n"
603 +            "    < x3_new, y3_new, z3_new >, CONE_RADIUS\n"
604 +            "    texture{\n"
605 +            "      pigment{ rgb < %lf, %lf, %lf > }\n"
606 +            "      finish{\n"
607 +            "        ambient .2\n"
608 +            "        diffuse .6\n"
609 +            "        specular 1\n"
610 +            "        roughness .001\n"
611 +            "        metallic\n"
612 +            "      }\n"
613 +            "    }\n"
614 +            "  }\n"
615              "#end\n"
616              "\n"
617              "\n",
# Line 333 | Line 620 | void make_header_macros(FILE *out_file){
620              red, green, blue,
621              name,
622              radius,
623 +            red, green, blue,
624 +            name,
625 +            radius,
626 +            name,
627 +            radius,
628 +            name,
629 +            red, green, blue,
630              red, green, blue);
631      
632      current_type = current_type->next;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines