1 |
#include <stdio.h> |
2 |
#include <stdlib.h> |
3 |
#include <string.h> |
4 |
#include <math.h> |
5 |
#include <unistd.h> |
6 |
#include <sys/types.h> |
7 |
#include <sys/stat.h> |
8 |
|
9 |
#include "frameCount.h" |
10 |
#include "atom_parser.h" |
11 |
#include "pov_writer.h" |
12 |
|
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 |
|
23 |
char *program_name; /*the name of the program */ |
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_box = 0; // boolean to draw the periodic Box |
28 |
int regenerateBonds = 0; // boolean to regenearate bonds each frame |
29 |
|
30 |
void usage(void); |
31 |
|
32 |
int main(argc, argv) |
33 |
int argc; |
34 |
char *argv[]; |
35 |
{ |
36 |
|
37 |
|
38 |
struct coords *out_coords; |
39 |
|
40 |
int i,j,k; /* loop counters */ |
41 |
mode_t dir_mode = S_IRWXU; |
42 |
|
43 |
int generate_header = 0; /* boolean for generating the pov ray header */ |
44 |
double big_x = 0; |
45 |
double big_y = 0; /* lets me know the biggest x y and z */ |
46 |
double big_z = 0; |
47 |
double small_x = 0; |
48 |
double small_y = 0; /* lets me know the smallest x, y, z */ |
49 |
double small_z = 0; |
50 |
double rsqr; /* the square of the diagonal */ |
51 |
double diagonal; /* the diagonal length of the sim box */ |
52 |
|
53 |
unsigned int n_atoms; /*the number of atoms in each time step */ |
54 |
char read_buffer[120]; /*the line buffer for reading */ |
55 |
char *eof_test; /*ptr to see when we reach the end of the file */ |
56 |
char *foo; /*the pointer to the current string token */ |
57 |
FILE *in_file; /* the input file */ |
58 |
FILE *out_file; /*the output file */ |
59 |
char *out_prefix = NULL; /*the prefix of the output file */ |
60 |
int have_prefix = 0; |
61 |
char out_name[500]; /*the output name */ |
62 |
char out_format[1000]; |
63 |
char *in_name = NULL; /*the name of the input file */ |
64 |
unsigned int n_out = 0; /*keeps track of which output file is being written*/ |
65 |
int done; |
66 |
char current_flag; |
67 |
int nFrames; |
68 |
int nZeroes; |
69 |
double count; |
70 |
|
71 |
int startFrame = 1; |
72 |
int endFrame; |
73 |
int span = 0; |
74 |
int currentCount = 0; |
75 |
int haveEnd = 0; |
76 |
|
77 |
struct linked_xyz *current_frame; |
78 |
struct linked_xyz *temp_frame; |
79 |
|
80 |
unsigned int n_interpolate = 0; /* number of frames to interpolate */ |
81 |
double dx, dy, dz; /* temp variables for interpolating distances */ |
82 |
double dm[3][3]; |
83 |
|
84 |
|
85 |
char pov_dir[500]; /* the pov_dir */ |
86 |
|
87 |
program_name = argv[0]; /*save the program name in case we need it*/ |
88 |
|
89 |
|
90 |
for( i = 1; i < argc; i++){ |
91 |
|
92 |
if(argv[i][0] =='-'){ |
93 |
|
94 |
// parse the option |
95 |
|
96 |
if(argv[i][1] == '-' ){ |
97 |
|
98 |
// parse long word options |
99 |
|
100 |
fprintf( stderr, |
101 |
"Invalid option \"%s\"\n", argv[i] ); |
102 |
usage(); |
103 |
|
104 |
} |
105 |
|
106 |
else{ |
107 |
|
108 |
// parse single character options |
109 |
|
110 |
done = 0; |
111 |
j = 1; |
112 |
current_flag = argv[i][j]; |
113 |
while( (current_flag != '\0') && (!done) ){ |
114 |
|
115 |
switch(current_flag){ |
116 |
|
117 |
case 'o': |
118 |
// -o <prefix> => the output prefix. |
119 |
|
120 |
i++; |
121 |
out_prefix = argv[i]; |
122 |
have_prefix = 1; |
123 |
done = 1; |
124 |
break; |
125 |
|
126 |
case 'i': |
127 |
// -i <#> => the number to interpolate |
128 |
|
129 |
i++; |
130 |
n_interpolate = atoi( argv[i] ); |
131 |
done = 1; |
132 |
break; |
133 |
|
134 |
case 'f': |
135 |
// -f <#> => frame to render |
136 |
|
137 |
i++; |
138 |
startFrame = atoi( argv[i] ); |
139 |
endFrame = startFrame; |
140 |
haveEnd = 1; |
141 |
done = 1; |
142 |
break; |
143 |
|
144 |
case 's': |
145 |
// -s <#> => frame to start |
146 |
|
147 |
i++; |
148 |
startFrame = atoi( argv[i] ); |
149 |
done = 1; |
150 |
break; |
151 |
|
152 |
case 'e': |
153 |
// -e <#> => frame to end |
154 |
|
155 |
i++; |
156 |
endFrame = atoi( argv[i] ); |
157 |
haveEnd = 1; |
158 |
done = 1; |
159 |
break; |
160 |
|
161 |
case 'H': |
162 |
// -h => generate a pov-ray Header |
163 |
|
164 |
generate_header = 1; |
165 |
break; |
166 |
|
167 |
case 'h': |
168 |
// -h => draw Hydrogens |
169 |
|
170 |
draw_hydrogens = 1; |
171 |
break; |
172 |
|
173 |
case 'b': |
174 |
// -b => draw bonds |
175 |
|
176 |
draw_bonds = 1; |
177 |
break; |
178 |
|
179 |
case 'a': |
180 |
// -a => draw the atoms |
181 |
|
182 |
draw_atoms = 1; |
183 |
break; |
184 |
|
185 |
case 'r': |
186 |
// -r => regenerate bonds |
187 |
|
188 |
regenerateBonds = 1; |
189 |
break; |
190 |
|
191 |
case 'p': |
192 |
// -r => draw periodic box |
193 |
|
194 |
draw_box = 1; |
195 |
break; |
196 |
|
197 |
default: |
198 |
|
199 |
(void)fprintf(stderr, "Bad option \"-%c\"\n", current_flag); |
200 |
usage(); |
201 |
} |
202 |
j++; |
203 |
current_flag = argv[i][j]; |
204 |
} |
205 |
} |
206 |
} |
207 |
|
208 |
else{ |
209 |
|
210 |
if( in_name != NULL ){ |
211 |
fprintf( stderr, |
212 |
"Error at \"%s\", program does not currently support\n" |
213 |
"more than one input file.\n" |
214 |
"\n", |
215 |
argv[i]); |
216 |
usage(); |
217 |
} |
218 |
|
219 |
in_name = argv[i]; |
220 |
} |
221 |
} |
222 |
|
223 |
if(in_name == NULL){ |
224 |
usage(); |
225 |
} |
226 |
|
227 |
|
228 |
|
229 |
in_file = fopen(in_name, "r"); |
230 |
if(in_file == NULL){ |
231 |
printf("Cannot open file: %s\n", in_name); |
232 |
exit(8); |
233 |
} |
234 |
|
235 |
|
236 |
|
237 |
if(access(POV_DIR, F_OK)){ |
238 |
/*create the pov directory*/ |
239 |
mkdir(POV_DIR, dir_mode); |
240 |
} |
241 |
strcpy(pov_dir, POV_DIR); strcat(pov_dir, "/"); |
242 |
|
243 |
|
244 |
// initialize atom type parser |
245 |
|
246 |
initializeParser(); |
247 |
initBondList(); |
248 |
|
249 |
// count the number of frames |
250 |
|
251 |
printf( "Counting the number of frames..." ); |
252 |
fflush(stdout); |
253 |
|
254 |
nFrames = frameCount( in_name ); |
255 |
|
256 |
printf( "done.\n" |
257 |
"%d frames found\n", |
258 |
nFrames); |
259 |
fflush(stdout); |
260 |
|
261 |
// create the output string |
262 |
|
263 |
nZeroes = 1; |
264 |
count = (double)( nFrames * (n_interpolate+1) ); |
265 |
while( count >= 10.0 ){ |
266 |
count /= 10.0; |
267 |
nZeroes++; |
268 |
} |
269 |
|
270 |
if(!have_prefix){ |
271 |
out_prefix = strtok(in_name, "."); |
272 |
} |
273 |
|
274 |
sprintf( out_format, "%s%s%%0%dd.pov", pov_dir, out_prefix, nZeroes ); |
275 |
|
276 |
// start reading the first frame |
277 |
|
278 |
eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); |
279 |
|
280 |
current_frame = (struct linked_xyz *)malloc(sizeof(struct linked_xyz)); |
281 |
current_frame->next = NULL; |
282 |
|
283 |
|
284 |
if( haveEnd ) span = endFrame - startFrame; |
285 |
done = 0; |
286 |
if( span < 0 ) done = 1; |
287 |
while( (eof_test != NULL) && !done ){ |
288 |
|
289 |
(void)sscanf(read_buffer, "%d", &n_atoms); |
290 |
current_frame->r = |
291 |
(struct coords *)calloc(n_atoms, sizeof(struct coords)); |
292 |
|
293 |
/*read and toss the comment line */ |
294 |
|
295 |
eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); |
296 |
if(eof_test == NULL){ |
297 |
printf("error in reading file\n"); |
298 |
exit(8); |
299 |
} |
300 |
|
301 |
// unless we need to get the box size |
302 |
|
303 |
if( draw_box ){ |
304 |
foo = strtok(read_buffer, " ,;\t"); |
305 |
if(foo == NULL){ |
306 |
printf("error in reading file\n"); |
307 |
exit(8); |
308 |
} |
309 |
|
310 |
foo = strtok(NULL, " ,;\t"); |
311 |
if(foo == NULL){ |
312 |
printf("error in reading file\n"); |
313 |
exit(8); |
314 |
} |
315 |
current_frame->Hmat[0][0] = atof( foo ); |
316 |
|
317 |
foo = strtok(NULL, " ,;\t"); |
318 |
if(foo == NULL){ |
319 |
printf("error in reading file\n"); |
320 |
exit(8); |
321 |
} |
322 |
current_frame->Hmat[1][0] = atof( foo ); |
323 |
|
324 |
foo = strtok(NULL, " ,;\t"); |
325 |
if(foo == NULL){ |
326 |
printf("error in reading file\n"); |
327 |
exit(8); |
328 |
} |
329 |
current_frame->Hmat[2][0] = atof( foo ); |
330 |
|
331 |
foo = strtok(NULL, " ,;\t"); |
332 |
if(foo == NULL){ |
333 |
printf("error in reading file\n"); |
334 |
exit(8); |
335 |
} |
336 |
current_frame->Hmat[0][1] = atof( foo ); |
337 |
|
338 |
foo = strtok(NULL, " ,;\t"); |
339 |
if(foo == NULL){ |
340 |
printf("error in reading file\n"); |
341 |
exit(8); |
342 |
} |
343 |
current_frame->Hmat[1][1] = atof( foo ); |
344 |
|
345 |
foo = strtok(NULL, " ,;\t"); |
346 |
if(foo == NULL){ |
347 |
printf("error in reading file\n"); |
348 |
exit(8); |
349 |
} |
350 |
current_frame->Hmat[2][1] = atof( foo ); |
351 |
|
352 |
foo = strtok(NULL, " ,;\t"); |
353 |
if(foo == NULL){ |
354 |
printf("error in reading file\n"); |
355 |
exit(8); |
356 |
} |
357 |
current_frame->Hmat[0][2] = atof( foo ); |
358 |
|
359 |
foo = strtok(NULL, " ,;\t"); |
360 |
if(foo == NULL){ |
361 |
printf("error in reading file\n"); |
362 |
exit(8); |
363 |
} |
364 |
current_frame->Hmat[1][2] = atof( foo ); |
365 |
|
366 |
foo = strtok(NULL, " ,;\t"); |
367 |
if(foo == NULL){ |
368 |
printf("error in reading file\n"); |
369 |
exit(8); |
370 |
} |
371 |
current_frame->Hmat[2][2] = atof( foo ); |
372 |
|
373 |
} |
374 |
|
375 |
for( i=0; i < n_atoms; i++){ |
376 |
|
377 |
eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); |
378 |
if(eof_test == NULL){ |
379 |
printf("error in reading file\n"); |
380 |
exit(8); |
381 |
} |
382 |
|
383 |
foo = strtok(read_buffer, " ,;\t"); |
384 |
if(foo == NULL){ |
385 |
printf("error in reading file\n"); |
386 |
exit(8); |
387 |
} |
388 |
(void)strcpy(current_frame->r[i].name, foo); /*copy the atom name */ |
389 |
|
390 |
/* next we grab the positions */ |
391 |
|
392 |
foo = strtok(NULL, " ,;\t"); |
393 |
if(foo == NULL){ |
394 |
printf("error in reading file\n"); |
395 |
exit(8); |
396 |
} |
397 |
(void)sscanf(foo, "%lf",¤t_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 |
|
402 |
foo = strtok(NULL, " ,;\t"); |
403 |
if(foo == NULL){ |
404 |
printf("error in reading file\n"); |
405 |
exit(8); |
406 |
} |
407 |
(void)sscanf(foo, "%lf", ¤t_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 |
|
412 |
foo = strtok(NULL, " ,;\t"); |
413 |
if(foo == NULL){ |
414 |
printf("error in reading file\n"); |
415 |
exit(8); |
416 |
} |
417 |
(void)sscanf(foo, "%lf", ¤t_frame->r[i].z); |
418 |
if(current_frame->r[i].z > big_z) big_z = current_frame->r[i].z; |
419 |
if(current_frame->r[i].z < small_z) small_z = current_frame->r[i].z; |
420 |
|
421 |
} |
422 |
currentCount++; |
423 |
|
424 |
|
425 |
if( currentCount >= startFrame ){ |
426 |
if(n_interpolate && current_frame->next != NULL){ |
427 |
|
428 |
temp_frame = current_frame->next; |
429 |
|
430 |
for(i = 0; i < n_interpolate; i++){ |
431 |
|
432 |
/* open the new output file */ |
433 |
|
434 |
sprintf(out_name, out_format, currentCount ); |
435 |
out_file = fopen(out_name, "w"); |
436 |
currentCount++; |
437 |
if(out_file == NULL){ |
438 |
printf("error opening output file: %s\n", out_name); |
439 |
exit(8); |
440 |
} |
441 |
(void)fprintf(out_file, |
442 |
"// The following script was automatically generated by:\n" |
443 |
"// xyz2pov Copyright 2001 by MATTHEW A. MEINEKE\n" |
444 |
"\n" |
445 |
"#include \"pov_header.pov\"\n" |
446 |
"\n"); |
447 |
if( draw_box ){ |
448 |
|
449 |
for (j = 0; j < 3; j++) { |
450 |
for (k = 0; k < 3; k++) { |
451 |
dm[j][k] = current_frame->Hmat[j][k] - temp_frame->Hmat[j][k]; |
452 |
dm[j][k] /= (double)(n_interpolate + 1); |
453 |
} |
454 |
} |
455 |
|
456 |
fprintf( out_file, |
457 |
"makePeriodicBox( %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf)\n" |
458 |
"\n", |
459 |
temp_frame->Hmat[0][0] + dm[0][0] * (i+1), |
460 |
temp_frame->Hmat[2][0] + dm[2][0] * (i+1), |
461 |
temp_frame->Hmat[1][0] + dm[1][0] * (i+1), |
462 |
temp_frame->Hmat[0][1] + dm[0][1] * (i+1), |
463 |
temp_frame->Hmat[2][1] + dm[2][1] * (i+1), |
464 |
temp_frame->Hmat[1][1] + dm[1][1] * (i+1), |
465 |
temp_frame->Hmat[0][2] + dm[0][2] * (i+1), |
466 |
temp_frame->Hmat[2][2] + dm[2][2] * (i+1), |
467 |
temp_frame->Hmat[1][2] + dm[1][2] * (i+1) ); |
468 |
} |
469 |
|
470 |
|
471 |
out_coords = |
472 |
(struct coords *)calloc(n_atoms, sizeof(struct coords)); |
473 |
|
474 |
for(j=0; j < n_atoms; j++){ |
475 |
dx = current_frame->r[j].x - temp_frame->r[j].x; |
476 |
dy = current_frame->r[j].y - temp_frame->r[j].y; |
477 |
dz = current_frame->r[j].z - temp_frame->r[j].z; |
478 |
|
479 |
dx /= (double)(n_interpolate + 1); |
480 |
dy /= (double)(n_interpolate + 1); |
481 |
dz /= (double)(n_interpolate + 1); |
482 |
|
483 |
strcpy(out_coords[j].name, temp_frame->r[j].name); |
484 |
out_coords[j].x = temp_frame->r[j].x + dx * (i+1); |
485 |
out_coords[j].y = temp_frame->r[j].y + dy * (i+1); |
486 |
out_coords[j].z = temp_frame->r[j].z + dz * (i+1); |
487 |
} |
488 |
|
489 |
pov_write(out_file, out_coords, n_atoms, draw_hydrogens, draw_bonds, |
490 |
draw_atoms); |
491 |
free(out_coords); |
492 |
(void)fclose(out_file); |
493 |
} |
494 |
} |
495 |
|
496 |
/* open the new output file */ |
497 |
|
498 |
sprintf(out_name, out_format, currentCount ); |
499 |
out_file = fopen(out_name, "w"); |
500 |
if(out_file == NULL){ |
501 |
printf("error opening output file: %s\n", out_name); |
502 |
exit(8); |
503 |
} |
504 |
(void)fprintf(out_file, |
505 |
"// The following script was automatically generated by:\n" |
506 |
"// xyz2pov Copyright 2001 by MATTHEW A. MEINEKE\n" |
507 |
"\n" |
508 |
"#include \"pov_header.pov\"\n" |
509 |
"\n"); |
510 |
|
511 |
if( draw_box ){ |
512 |
|
513 |
fprintf( out_file, |
514 |
"makePeriodicBox( %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf %lf )\n" |
515 |
"\n", |
516 |
current_frame->Hmat[0][0], |
517 |
current_frame->Hmat[2][0], |
518 |
current_frame->Hmat[1][0], |
519 |
current_frame->Hmat[0][1], |
520 |
current_frame->Hmat[2][1], |
521 |
current_frame->Hmat[1][1], |
522 |
current_frame->Hmat[0][2], |
523 |
current_frame->Hmat[2][2], |
524 |
current_frame->Hmat[1][2] ); |
525 |
} |
526 |
|
527 |
|
528 |
|
529 |
out_coords = |
530 |
(struct coords *)calloc(n_atoms, sizeof(struct coords)); |
531 |
|
532 |
for(i = 0; i < n_atoms; i++){ |
533 |
strcpy(out_coords[i].name, current_frame->r[i].name); |
534 |
out_coords[i].x = current_frame->r[i].x; |
535 |
out_coords[i].y = current_frame->r[i].y; |
536 |
out_coords[i].z = current_frame->r[i].z; |
537 |
} |
538 |
pov_write(out_file, out_coords, n_atoms, draw_hydrogens, draw_bonds, |
539 |
draw_atoms); |
540 |
free(out_coords); |
541 |
|
542 |
(void)fclose(out_file); |
543 |
} |
544 |
|
545 |
/*free up memory */ |
546 |
|
547 |
temp_frame = current_frame->next; |
548 |
current_frame->next = NULL; |
549 |
|
550 |
if(temp_frame != NULL){ |
551 |
|
552 |
free(temp_frame->r); |
553 |
free(temp_frame); |
554 |
} |
555 |
|
556 |
/* make a new frame */ |
557 |
|
558 |
temp_frame = (struct linked_xyz *)malloc(sizeof(struct linked_xyz)); |
559 |
temp_frame->next = current_frame; |
560 |
current_frame = temp_frame; |
561 |
|
562 |
eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); |
563 |
|
564 |
if( haveEnd ){ |
565 |
if( currentCount >= (endFrame + n_interpolate * span) ) done = 1; |
566 |
} |
567 |
} |
568 |
|
569 |
(void)fclose(in_file); |
570 |
|
571 |
|
572 |
if(generate_header){ |
573 |
|
574 |
dx = big_x - small_x; |
575 |
dy = big_y - small_y; |
576 |
dz = big_z - small_z; |
577 |
|
578 |
rsqr = dx * dx + dy * dy + dz * dz; |
579 |
diagonal = sqrt(rsqr); |
580 |
diagonal *= 0.5; |
581 |
|
582 |
// calculate the center |
583 |
|
584 |
dx = big_x + small_x; |
585 |
dy = big_y + small_y; |
586 |
dz = big_z + small_z; |
587 |
|
588 |
dx /= 2.0; |
589 |
dy /= 2.0; |
590 |
dz /= 2.0; |
591 |
|
592 |
|
593 |
/*note the y and z axis is exchanged for the different coordinate |
594 |
system in pov-ray*/ |
595 |
|
596 |
|
597 |
out_file = fopen("pov_header.pov", "w"); |
598 |
|
599 |
fprintf(out_file, |
600 |
"// The following script was automatically generated by:\n" |
601 |
"// xyz2pov Copyright 2001 by MATTHEW A. MEINEKE\n" |
602 |
"\n" |
603 |
"\n" |
604 |
"background { rgb <1.0, 1.0, 1.0> }\n" |
605 |
"\n" |
606 |
"\n" |
607 |
); |
608 |
|
609 |
fprintf(out_file, |
610 |
"//******************************************************\n" |
611 |
"// Declare the resolution, camera, and light sources.\n" |
612 |
"//******************************************************\n" |
613 |
"\n" |
614 |
"// NOTE: if you plan to render at a different resoltion,\n" |
615 |
"// be sure to update the following two lines to maintain\n" |
616 |
"// the correct aspect ratio.\n" |
617 |
"\n" |
618 |
"#declare Width = 640.0;\n" |
619 |
"#declare Height = 480.0;\n" |
620 |
"#declare Ratio = Width / Height;\n" |
621 |
"\n" |
622 |
"#declare ATOM_SPHERE_FACTOR = 0.2;\n" |
623 |
"#declare BOND_RADIUS = 0.1;\n" |
624 |
"\n" |
625 |
"// declare camera, light, and system variables\n" |
626 |
"\n" |
627 |
"#declare sysCenterX = %lf;\n" |
628 |
"#declare sysCenterY = %lf;\n" |
629 |
"#declare sysCenterZ = %lf;\n" |
630 |
"\n" |
631 |
"#declare zoom = %lf;\n" |
632 |
"\n", |
633 |
dx, dz, dy, |
634 |
diagonal ); |
635 |
|
636 |
fprintf(out_file, |
637 |
"#declare cameraLookX = sysCenterX;\n" |
638 |
"#declare cameraLookY = sysCenterY;\n" |
639 |
"#declare cameraLookZ = sysCenterZ;\n" |
640 |
"\n" |
641 |
"#declare cameraX = cameraLookX;\n" |
642 |
"#declare cameraY = cameraLookY;\n" |
643 |
"#declare cameraZ = cameraLookZ - zoom;\n" |
644 |
"\n" |
645 |
"#declare lightAx = cameraX;\n" |
646 |
"#declare lightAy = cameraY;\n" |
647 |
"#declare lightAz = cameraZ;\n" |
648 |
"\n" |
649 |
"#declare lightBx = cameraX - zoom;\n" |
650 |
"#declare lightBy = cameraY + zoom;\n" |
651 |
"#declare lightBz = cameraZ;\n" |
652 |
"\n" |
653 |
"#declare boxCenterX = cameraLookX;\n" |
654 |
"#declare boxCenterY = cameraLookY;\n" |
655 |
"#declare boxCenterZ = cameraLookZ;\n" |
656 |
"\n" |
657 |
"// declare the cameras and the light sources\n" |
658 |
"\n" |
659 |
"camera{\n" |
660 |
" location < cameraX, cameraY, cameraZ>\n" |
661 |
" right < Ratio , 0, 0>\n" |
662 |
" look_at < cameraLookX, cameraLookY, cameraLookZ >\n" |
663 |
"}\n" |
664 |
"\n" |
665 |
"light_source{\n" |
666 |
" < lightAx, lightAy, lightAz >\n" |
667 |
" rgb < 1.0, 1.0, 1.0 > }\n" |
668 |
"\n" |
669 |
"light_source{\n" |
670 |
" < lightBx, lightBy, lightBz >\n" |
671 |
" rgb < 1.0, 1.0, 1.0 > }\n" |
672 |
"\n" |
673 |
"\n" |
674 |
"//************************************************************\n" |
675 |
"// Set whether or not to rotate the system.\n" |
676 |
"//\n" |
677 |
"// To Rotate, set ROTATE to 1.0 (true),\n" |
678 |
"// Then set the Euler Angles PHI, THETA, and PSI in degrees.\n" |
679 |
"//************************************************************\n" |
680 |
"\n" |
681 |
"#declare ROTATE = 0.0;\n" |
682 |
"#declare PHI = 0.0;\n" |
683 |
"#declare THETA = 0.0;\n" |
684 |
"#declare PSI = 0.0;\n" |
685 |
"\n" |
686 |
"#if(ROTATE)\n" |
687 |
" #declare phi_r = radians(PHI);\n" |
688 |
" #declare theta_r = radians(THETA);\n" |
689 |
" #declare psi_r = radians(PSI);\n" |
690 |
"\n" |
691 |
" #declare A11 = cos(phi_r) * cos(psi_r) - sin(phi_r) * cos(theta_r) * sin(psi_r);\n" |
692 |
" #declare A12 = sin(phi_r) * cos(psi_r) + cos(phi_r) * cos(theta_r) * sin(psi_r);\n" |
693 |
" #declare A13 = sin(theta_r) * sin(psi_r);\n" |
694 |
"\n" |
695 |
" #declare A21 = -cos(phi_r) * sin(psi_r) - sin(phi_r) * cos(theta_r) * cos(psi_r);\n" |
696 |
" #declare A22 = -sin(phi_r) * sin(psi_r) + cos(phi_r) * cos(theta_r) * cos(psi_r);\n" |
697 |
" #declare A23 = sin(theta_r) * cos(psi_r);\n" |
698 |
"\n" |
699 |
" #declare A31 = sin(phi_r) * sin(theta_r);\n" |
700 |
" #declare A32 = -cos(phi_r) * sin(theta_r);\n" |
701 |
" #declare A33 = cos(theta_r);\n" |
702 |
"\n" |
703 |
"#end\n" |
704 |
"\n" |
705 |
"\n" |
706 |
"//************************************************************\n" |
707 |
"// declare the periodic box macro\n" |
708 |
"//************************************************************\n" |
709 |
"\n" |
710 |
"#macro makePeriodicBox( bx1, by1, bz1, bx2, by2, bz2, bx3, by3, bz3 )\n" |
711 |
"\n" |
712 |
" #local bcx = (bx1 + bx2 + bx3) / 2.0;\n" |
713 |
" #local bcy = (by1 + by2 + by3) / 2.0;\n" |
714 |
" #local bcz = (bz1 + bz2 + bz3) / 2.0;\n" |
715 |
"\n" |
716 |
" #local pAx = boxCenterX - bcx;\n" |
717 |
" #local pAy = boxCenterY - bcy;\n" |
718 |
" #local pAz = boxCenterZ - bcz;\n" |
719 |
" #local pBx = boxCenterX + bx1 - bcx;\n" |
720 |
" #local pBy = boxCenterY + by1 - bcy;\n" |
721 |
" #local pBz = boxCenterZ + bz1 - bcz;\n" |
722 |
" #local pCx = boxCenterX + bx2 - bcx;\n" |
723 |
" #local pCy = boxCenterY + by2 - bcy;\n" |
724 |
" #local pCz = boxCenterZ + bz2 - bcz;\n" |
725 |
" #local pDx = boxCenterX + bx3 - bcx;\n" |
726 |
" #local pDy = boxCenterY + by3 - bcy;\n" |
727 |
" #local pDz = boxCenterZ + bz3 - bcz;\n" |
728 |
" #local pEx = boxCenterX + bx1 + bx2 - bcx;\n" |
729 |
" #local pEy = boxCenterY + by1 + by2 - bcy;\n" |
730 |
" #local pEz = boxCenterZ + bz1 + bz2 - bcz;\n" |
731 |
" #local pFx = boxCenterX + bx1 + bx3 - bcx;\n" |
732 |
" #local pFy = boxCenterY + by1 + by3 - bcy;\n" |
733 |
" #local pFz = boxCenterZ + bz1 + bz3 - bcz;\n" |
734 |
" #local pGx = boxCenterX + bx2 + bx3 - bcx;\n" |
735 |
" #local pGy = boxCenterY + by2 + by3 - bcy;\n" |
736 |
" #local pGz = boxCenterZ + bz2 + bz3 - bcz;\n" |
737 |
" #local pHx = boxCenterX + bx1 + bx2 + bx3 - bcx;\n" |
738 |
" #local pHy = boxCenterY + by1 + by2 + by3 - bcy;\n" |
739 |
" #local pHz = boxCenterZ + bz1 + bz2 + bz3 - bcz;\n" |
740 |
"\n" |
741 |
" #local colorR = 0.90;\n" |
742 |
" #local colorG = 0.91;\n" |
743 |
" #local colorB = 0.98;\n" |
744 |
"\n" |
745 |
" #local pipeWidth = 0.4;\n" |
746 |
"\n" |
747 |
" // 1\n" |
748 |
" cylinder{\n" |
749 |
" < pAx, pAy, pAz >,\n" |
750 |
" < pBx, pBy, pBz >,\n" |
751 |
" pipeWidth\n" |
752 |
" texture{\n" |
753 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
754 |
" finish{\n" |
755 |
" ambient .2\n" |
756 |
" diffuse .6\n" |
757 |
" specular 1\n" |
758 |
" roughness .001\n" |
759 |
" metallic\n" |
760 |
" }\n" |
761 |
" }\n" |
762 |
" }\n" |
763 |
"\n" |
764 |
" // 2\n" |
765 |
" cylinder{\n" |
766 |
" < pAx, pAy, pAz >,\n" |
767 |
" < pCx, pCy, pCz >,\n" |
768 |
" pipeWidth\n" |
769 |
" texture{\n" |
770 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
771 |
" finish{\n" |
772 |
" ambient .2\n" |
773 |
" diffuse .6\n" |
774 |
" specular 1\n" |
775 |
" roughness .001\n" |
776 |
" metallic\n" |
777 |
" }\n" |
778 |
" }\n" |
779 |
" }\n" |
780 |
"\n" |
781 |
" // 3\n" |
782 |
" cylinder{\n" |
783 |
" < pAx, pAy, pAz >,\n" |
784 |
" < pDx, pDy, pDz >,\n" |
785 |
" pipeWidth\n" |
786 |
" texture{\n" |
787 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
788 |
" finish{\n" |
789 |
" ambient .2\n" |
790 |
" diffuse .6\n" |
791 |
" specular 1\n" |
792 |
" roughness .001\n" |
793 |
" metallic\n" |
794 |
" }\n" |
795 |
" }\n" |
796 |
" }\n" |
797 |
"\n" |
798 |
" // 4\n" |
799 |
" cylinder{\n" |
800 |
" < pBx, pBy, pBz >,\n" |
801 |
" < pEx, pEy, pEz >,\n" |
802 |
" pipeWidth\n" |
803 |
" texture{\n" |
804 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
805 |
" finish{\n" |
806 |
" ambient .2\n" |
807 |
" diffuse .6\n" |
808 |
" specular 1\n" |
809 |
" roughness .001\n" |
810 |
" metallic\n" |
811 |
" }\n" |
812 |
" }\n" |
813 |
" }\n" |
814 |
"\n" |
815 |
" // 5\n" |
816 |
" cylinder{\n" |
817 |
" < pCx, pCy, pCz >,\n" |
818 |
" < pEx, pEy, pEz >,\n" |
819 |
" pipeWidth\n" |
820 |
" texture{\n" |
821 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
822 |
" finish{\n" |
823 |
" ambient .2\n" |
824 |
" diffuse .6\n" |
825 |
" specular 1\n" |
826 |
" roughness .001\n" |
827 |
" metallic\n" |
828 |
" }\n" |
829 |
" }\n" |
830 |
" }\n" |
831 |
"\n" |
832 |
" // 6\n" |
833 |
" cylinder{\n" |
834 |
" < pBx, pBy, pBz >,\n" |
835 |
" < pFx, pFy, pFz >,\n" |
836 |
" pipeWidth\n" |
837 |
" texture{\n" |
838 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
839 |
" finish{\n" |
840 |
" ambient .2\n" |
841 |
" diffuse .6\n" |
842 |
" specular 1\n" |
843 |
" roughness .001\n" |
844 |
" metallic\n" |
845 |
" }\n" |
846 |
" }\n" |
847 |
" }\n" |
848 |
"\n" |
849 |
" // 7\n" |
850 |
" cylinder{\n" |
851 |
" < pCx, pCy, pCz >,\n" |
852 |
" < pGx, pGy, pGz >,\n" |
853 |
" pipeWidth\n" |
854 |
" texture{\n" |
855 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
856 |
" finish{\n" |
857 |
" ambient .2\n" |
858 |
" diffuse .6\n" |
859 |
" specular 1\n" |
860 |
" roughness .001\n" |
861 |
" metallic\n" |
862 |
" }\n" |
863 |
" }\n" |
864 |
" }\n" |
865 |
"\n" |
866 |
" // 8\n" |
867 |
" cylinder{\n" |
868 |
" < pDx, pDy, pDz >,\n" |
869 |
" < pGx, pGy, pGz >,\n" |
870 |
" pipeWidth\n" |
871 |
" texture{\n" |
872 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
873 |
" finish{\n" |
874 |
" ambient .2\n" |
875 |
" diffuse .6\n" |
876 |
" specular 1\n" |
877 |
" roughness .001\n" |
878 |
" metallic\n" |
879 |
" }\n" |
880 |
" }\n" |
881 |
" }\n" |
882 |
"\n" |
883 |
" // 9\n" |
884 |
" cylinder{\n" |
885 |
" < pDx, pDy, pDz >,\n" |
886 |
" < pFx, pFy, pFz >,\n" |
887 |
" pipeWidth\n" |
888 |
" texture{\n" |
889 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
890 |
" finish{\n" |
891 |
" ambient .2\n" |
892 |
" diffuse .6\n" |
893 |
" specular 1\n" |
894 |
" roughness .001\n" |
895 |
" metallic\n" |
896 |
" }\n" |
897 |
" }\n" |
898 |
" }\n" |
899 |
"\n" |
900 |
" // 10\n" |
901 |
" cylinder{\n" |
902 |
" < pEx, pEy, pEz >,\n" |
903 |
" < pHx, pHy, pHz >,\n" |
904 |
" pipeWidth\n" |
905 |
" texture{\n" |
906 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
907 |
" finish{\n" |
908 |
" ambient .2\n" |
909 |
" diffuse .6\n" |
910 |
" specular 1\n" |
911 |
" roughness .001\n" |
912 |
" metallic\n" |
913 |
" }\n" |
914 |
" }\n" |
915 |
" }\n" |
916 |
"\n" |
917 |
" // 11\n" |
918 |
" cylinder{\n" |
919 |
" < pFx, pFy, pFz >,\n" |
920 |
" < pHx, pHy, pHz >,\n" |
921 |
" pipeWidth\n" |
922 |
" texture{\n" |
923 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
924 |
" finish{\n" |
925 |
" ambient .2\n" |
926 |
" diffuse .6\n" |
927 |
" specular 1\n" |
928 |
" roughness .001\n" |
929 |
" metallic\n" |
930 |
" }\n" |
931 |
" }\n" |
932 |
" }\n" |
933 |
"\n" |
934 |
" // 12\n" |
935 |
" cylinder{\n" |
936 |
" < pGx, pGy, pGz >,\n" |
937 |
" < pHx, pHy, pHz >,\n" |
938 |
" pipeWidth\n" |
939 |
" texture{\n" |
940 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
941 |
" finish{\n" |
942 |
" ambient .2\n" |
943 |
" diffuse .6\n" |
944 |
" specular 1\n" |
945 |
" roughness .001\n" |
946 |
" metallic\n" |
947 |
" }\n" |
948 |
" }\n" |
949 |
" }\n" |
950 |
"\n" |
951 |
"#end\n" |
952 |
"\n" |
953 |
"\n"); |
954 |
|
955 |
|
956 |
|
957 |
|
958 |
make_header_macros(out_file); |
959 |
|
960 |
fclose(out_file); |
961 |
} |
962 |
|
963 |
return 0; |
964 |
|
965 |
} |
966 |
|
967 |
|
968 |
|
969 |
/*************************************************************************** |
970 |
* prints out the usage for the command line arguments, then exits. |
971 |
***************************************************************************/ |
972 |
|
973 |
void usage(){ |
974 |
(void)fprintf(stderr, |
975 |
"The proper usage is: %s [options] <xyz_file>\n" |
976 |
"\n" |
977 |
"Options:\n" |
978 |
"\n" |
979 |
" -o <prefix> the output file prefix\n" |
980 |
" -H generate a pov-ray header file\n" |
981 |
" -i <#> number of frames to interpolate\n" |
982 |
" -h draw hydrogens\n" |
983 |
" -b draw bonds\n" |
984 |
" -a draw atoms\n" |
985 |
" -p draw periodic box\n" |
986 |
" -r regenerate bond\n" |
987 |
" -f <#> render frame <#> only\n" |
988 |
" -s <#> begin at frame <#> (inclusive)\n" |
989 |
" -e <#> end at frame <#> (inclusive)\n" |
990 |
"\n", |
991 |
program_name); |
992 |
exit(8); |
993 |
} |