| 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[1][0] + dm[1][0] * (i+1), |
| 461 |
temp_frame->Hmat[2][0] + dm[2][0] * (i+1), |
| 462 |
temp_frame->Hmat[0][1] + dm[0][1] * (i+1), |
| 463 |
temp_frame->Hmat[1][1] + dm[1][1] * (i+1), |
| 464 |
temp_frame->Hmat[2][1] + dm[2][1] * (i+1), |
| 465 |
temp_frame->Hmat[0][2] + dm[0][2] * (i+1), |
| 466 |
temp_frame->Hmat[1][2] + dm[1][2] * (i+1), |
| 467 |
temp_frame->Hmat[2][2] + dm[2][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[1][0], |
| 518 |
current_frame->Hmat[2][0], |
| 519 |
current_frame->Hmat[0][1], |
| 520 |
current_frame->Hmat[1][1], |
| 521 |
current_frame->Hmat[2][1], |
| 522 |
current_frame->Hmat[0][2], |
| 523 |
current_frame->Hmat[1][2], |
| 524 |
current_frame->Hmat[2][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 pAx = -boxCenterX;\n" |
| 713 |
" #local pAy = -boxCenterY;\n" |
| 714 |
" #local pAz = -boxCenterZ;\n" |
| 715 |
" #local pBx = bx1 - boxCenterX;\n" |
| 716 |
" #local pBy = by1 - boxCenterY;\n" |
| 717 |
" #local pBz = bz1 - boxCenterZ;\n" |
| 718 |
" #local pCx = bx2 - boxCenterX;\n" |
| 719 |
" #local pCy = by2 - boxCenterY;\n" |
| 720 |
" #local pCz = bz2 - boxCenterZ;\n" |
| 721 |
" #local pDx = bx3 - boxCenterX;\n" |
| 722 |
" #local pDy = by3 - boxCenterY;\n" |
| 723 |
" #local pDz = bz3 - boxCenterZ;\n" |
| 724 |
" #local pEx = bx1 + bx2 - boxCenterX;\n" |
| 725 |
" #local pEy = by1 + by2 - boxCenterY;\n" |
| 726 |
" #local pEz = bz1 + bz2 - boxCenterZ;\n" |
| 727 |
" #local pFx = bx1 + bx3 - boxCenterX;\n" |
| 728 |
" #local pFy = by1 + by3 - boxCenterY;\n" |
| 729 |
" #local pFz = bz1 + bz3 - boxCenterZ;\n" |
| 730 |
" #local pGx = bx2 + bx3 - boxCenterX;\n" |
| 731 |
" #local pGy = by2 + by3 - boxCenterY;\n" |
| 732 |
" #local pGz = bz2 + bz3 - boxCenterZ;\n" |
| 733 |
" #local pHx = bx1 + bx2 + bx3 - boxCenterX;\n" |
| 734 |
" #local pHy = by1 + by2 + by3 - boxCenterY;\n" |
| 735 |
" #local pHz = bz1 + bz2 + bz3 - boxCenterZ;\n" |
| 736 |
"\n" |
| 737 |
" #local colorR = 0.90;\n" |
| 738 |
" #local colorG = 0.91;\n" |
| 739 |
" #local colorB = 0.98;\n" |
| 740 |
"\n" |
| 741 |
" #local pipeWidth = 0.4;\n" |
| 742 |
"\n" |
| 743 |
" // 1\n" |
| 744 |
" cylinder{\n" |
| 745 |
" < pAx, pAy, pAz >,\n" |
| 746 |
" < pBx, pBy, pBz >,\n" |
| 747 |
" pipeWidth\n" |
| 748 |
" texture{\n" |
| 749 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 750 |
" finish{\n" |
| 751 |
" ambient .2\n" |
| 752 |
" diffuse .6\n" |
| 753 |
" specular 1\n" |
| 754 |
" roughness .001\n" |
| 755 |
" metallic\n" |
| 756 |
" }\n" |
| 757 |
" }\n" |
| 758 |
" }\n" |
| 759 |
"\n" |
| 760 |
" // 2\n" |
| 761 |
" cylinder{\n" |
| 762 |
" < pAx, pAy, pAz >,\n" |
| 763 |
" < pCx, pCy, pCz >,\n" |
| 764 |
" pipeWidth\n" |
| 765 |
" texture{\n" |
| 766 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 767 |
" finish{\n" |
| 768 |
" ambient .2\n" |
| 769 |
" diffuse .6\n" |
| 770 |
" specular 1\n" |
| 771 |
" roughness .001\n" |
| 772 |
" metallic\n" |
| 773 |
" }\n" |
| 774 |
" }\n" |
| 775 |
" }\n" |
| 776 |
"\n" |
| 777 |
" // 3\n" |
| 778 |
" cylinder{\n" |
| 779 |
" < pAx, pAy, pAz >,\n" |
| 780 |
" < pDx, pDy, pDz >,\n" |
| 781 |
" pipeWidth\n" |
| 782 |
" texture{\n" |
| 783 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 784 |
" finish{\n" |
| 785 |
" ambient .2\n" |
| 786 |
" diffuse .6\n" |
| 787 |
" specular 1\n" |
| 788 |
" roughness .001\n" |
| 789 |
" metallic\n" |
| 790 |
" }\n" |
| 791 |
" }\n" |
| 792 |
" }\n" |
| 793 |
"\n" |
| 794 |
" // 4\n" |
| 795 |
" cylinder{\n" |
| 796 |
" < pBx, pBy, pBz >,\n" |
| 797 |
" < pEx, pEy, pEz >,\n" |
| 798 |
" pipeWidth\n" |
| 799 |
" texture{\n" |
| 800 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 801 |
" finish{\n" |
| 802 |
" ambient .2\n" |
| 803 |
" diffuse .6\n" |
| 804 |
" specular 1\n" |
| 805 |
" roughness .001\n" |
| 806 |
" metallic\n" |
| 807 |
" }\n" |
| 808 |
" }\n" |
| 809 |
" }\n" |
| 810 |
"\n" |
| 811 |
" // 5\n" |
| 812 |
" cylinder{\n" |
| 813 |
" < pCx, pCy, pCz >,\n" |
| 814 |
" < pEx, pEy, pEz >,\n" |
| 815 |
" pipeWidth\n" |
| 816 |
" texture{\n" |
| 817 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 818 |
" finish{\n" |
| 819 |
" ambient .2\n" |
| 820 |
" diffuse .6\n" |
| 821 |
" specular 1\n" |
| 822 |
" roughness .001\n" |
| 823 |
" metallic\n" |
| 824 |
" }\n" |
| 825 |
" }\n" |
| 826 |
" }\n" |
| 827 |
"\n" |
| 828 |
" // 6\n" |
| 829 |
" cylinder{\n" |
| 830 |
" < pBx, pBy, pBz >,\n" |
| 831 |
" < pFx, pFy, pFz >,\n" |
| 832 |
" pipeWidth\n" |
| 833 |
" texture{\n" |
| 834 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 835 |
" finish{\n" |
| 836 |
" ambient .2\n" |
| 837 |
" diffuse .6\n" |
| 838 |
" specular 1\n" |
| 839 |
" roughness .001\n" |
| 840 |
" metallic\n" |
| 841 |
" }\n" |
| 842 |
" }\n" |
| 843 |
" }\n" |
| 844 |
"\n" |
| 845 |
" // 7\n" |
| 846 |
" cylinder{\n" |
| 847 |
" < pCx, pCy, pCz >,\n" |
| 848 |
" < pGx, pGy, pGz >,\n" |
| 849 |
" pipeWidth\n" |
| 850 |
" texture{\n" |
| 851 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 852 |
" finish{\n" |
| 853 |
" ambient .2\n" |
| 854 |
" diffuse .6\n" |
| 855 |
" specular 1\n" |
| 856 |
" roughness .001\n" |
| 857 |
" metallic\n" |
| 858 |
" }\n" |
| 859 |
" }\n" |
| 860 |
" }\n" |
| 861 |
"\n" |
| 862 |
" // 8\n" |
| 863 |
" cylinder{\n" |
| 864 |
" < pDx, pDy, pDz >,\n" |
| 865 |
" < pGx, pGy, pGz >,\n" |
| 866 |
" pipeWidth\n" |
| 867 |
" texture{\n" |
| 868 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 869 |
" finish{\n" |
| 870 |
" ambient .2\n" |
| 871 |
" diffuse .6\n" |
| 872 |
" specular 1\n" |
| 873 |
" roughness .001\n" |
| 874 |
" metallic\n" |
| 875 |
" }\n" |
| 876 |
" }\n" |
| 877 |
" }\n" |
| 878 |
"\n" |
| 879 |
" // 9\n" |
| 880 |
" cylinder{\n" |
| 881 |
" < pDx, pDy, pDz >,\n" |
| 882 |
" < pFx, pFy, pFz >,\n" |
| 883 |
" pipeWidth\n" |
| 884 |
" texture{\n" |
| 885 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 886 |
" finish{\n" |
| 887 |
" ambient .2\n" |
| 888 |
" diffuse .6\n" |
| 889 |
" specular 1\n" |
| 890 |
" roughness .001\n" |
| 891 |
" metallic\n" |
| 892 |
" }\n" |
| 893 |
" }\n" |
| 894 |
" }\n" |
| 895 |
"\n" |
| 896 |
" // 10\n" |
| 897 |
" cylinder{\n" |
| 898 |
" < pEx, pEy, pEz >,\n" |
| 899 |
" < pHx, pHy, pHz >,\n" |
| 900 |
" pipeWidth\n" |
| 901 |
" texture{\n" |
| 902 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 903 |
" finish{\n" |
| 904 |
" ambient .2\n" |
| 905 |
" diffuse .6\n" |
| 906 |
" specular 1\n" |
| 907 |
" roughness .001\n" |
| 908 |
" metallic\n" |
| 909 |
" }\n" |
| 910 |
" }\n" |
| 911 |
" }\n" |
| 912 |
"\n" |
| 913 |
" // 11\n" |
| 914 |
" cylinder{\n" |
| 915 |
" < pFx, pFy, pFz >,\n" |
| 916 |
" < pHx, pHy, pHz >,\n" |
| 917 |
" pipeWidth\n" |
| 918 |
" texture{\n" |
| 919 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 920 |
" finish{\n" |
| 921 |
" ambient .2\n" |
| 922 |
" diffuse .6\n" |
| 923 |
" specular 1\n" |
| 924 |
" roughness .001\n" |
| 925 |
" metallic\n" |
| 926 |
" }\n" |
| 927 |
" }\n" |
| 928 |
" }\n" |
| 929 |
"\n" |
| 930 |
" // 12\n" |
| 931 |
" cylinder{\n" |
| 932 |
" < pGx, pGy, pGz >,\n" |
| 933 |
" < pHx, pHy, pHz >,\n" |
| 934 |
" pipeWidth\n" |
| 935 |
" texture{\n" |
| 936 |
" pigment{ rgb < colorR, colorG, colorB > }\n" |
| 937 |
" finish{\n" |
| 938 |
" ambient .2\n" |
| 939 |
" diffuse .6\n" |
| 940 |
" specular 1\n" |
| 941 |
" roughness .001\n" |
| 942 |
" metallic\n" |
| 943 |
" }\n" |
| 944 |
" }\n" |
| 945 |
" }\n" |
| 946 |
"\n" |
| 947 |
"#end\n" |
| 948 |
"\n" |
| 949 |
"\n"); |
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
make_header_macros(out_file); |
| 955 |
|
| 956 |
fclose(out_file); |
| 957 |
} |
| 958 |
|
| 959 |
return 0; |
| 960 |
|
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
/*************************************************************************** |
| 966 |
* prints out the usage for the command line arguments, then exits. |
| 967 |
***************************************************************************/ |
| 968 |
|
| 969 |
void usage(){ |
| 970 |
(void)fprintf(stderr, |
| 971 |
"The proper usage is: %s [options] <xyz_file>\n" |
| 972 |
"\n" |
| 973 |
"Options:\n" |
| 974 |
"\n" |
| 975 |
" -o <prefix> the output file prefix\n" |
| 976 |
" -H generate a pov-ray header file\n" |
| 977 |
" -i <#> number of frames to interpolate\n" |
| 978 |
" -h draw hydrogens\n" |
| 979 |
" -b draw bonds\n" |
| 980 |
" -a draw atoms\n" |
| 981 |
" -p draw periodic box\n" |
| 982 |
" -r regenerate bond\n" |
| 983 |
" -f <#> render frame <#> only\n" |
| 984 |
" -s <#> begin at frame <#> (inclusive)\n" |
| 985 |
" -e <#> end at frame <#> (inclusive)\n" |
| 986 |
"\n", |
| 987 |
program_name); |
| 988 |
exit(8); |
| 989 |
} |