| 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; |
| 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 |
|
|
| 69 |
|
char current_flag; |
| 70 |
|
int nFrames; |
| 71 |
|
int nZeroes; |
| 72 |
+ |
int nTokens; |
| 73 |
|
double count; |
| 74 |
|
|
| 75 |
|
int startFrame = 1; |
| 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': |
| 388 |
|
if(eof_test == NULL){ |
| 389 |
|
printf("error in reading file line at atom %d\n", i); |
| 390 |
|
exit(8); |
| 391 |
+ |
} |
| 392 |
+ |
|
| 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"); |
| 384 |
– |
if(foo == NULL){ |
| 385 |
– |
printf("error in reading atom %d name\n", i); |
| 386 |
– |
exit(8); |
| 387 |
– |
} |
| 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"); |
| 404 |
< |
if(foo == NULL){ |
| 394 |
< |
printf("error in reading atom %d position x\n", i); |
| 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 |
< |
|
| 404 |
> |
(void)sscanf(foo, "%lf",¤t_frame->r[i].x); |
| 405 |
|
foo = strtok(NULL, " ,;\t"); |
| 403 |
– |
if(foo == NULL){ |
| 404 |
– |
printf("error in reading atom %d position y\n", i); |
| 405 |
– |
exit(8); |
| 406 |
– |
} |
| 406 |
|
(void)sscanf(foo, "%lf", ¤t_frame->r[i].y); |
| 407 |
< |
if(current_frame->r[i].y > big_y) big_y = current_frame->r[i].y; |
| 408 |
< |
if(current_frame->r[i].y < small_y) small_y = current_frame->r[i].y; |
| 407 |
> |
foo = strtok(NULL, " ,;\t"); |
| 408 |
> |
(void)sscanf(foo, "%lf", ¤t_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 |
< |
foo = strtok(NULL, " ,;\t"); |
| 430 |
< |
if(foo == NULL){ |
| 414 |
< |
printf("error in reading atom %d position z\n", i); |
| 415 |
< |
exit(8); |
| 429 |
> |
extremaSet = 1; |
| 430 |
> |
|
| 431 |
|
} |
| 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; |
| 432 |
|
|
| 433 |
+ |
if (nTokens == 5 || nTokens > 7) { |
| 434 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 435 |
+ |
(void)sscanf(foo, "%lf", ¤t_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", ¤t_frame->r[i].ux); |
| 445 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 446 |
+ |
(void)sscanf(foo, "%lf", ¤t_frame->r[i].uy); |
| 447 |
+ |
foo = strtok(NULL, " ,;\t"); |
| 448 |
+ |
(void)sscanf(foo, "%lf", ¤t_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 |
|
|
| 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 |
|
} |
| 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); |
| 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" |
| 1055 |
|
" -h draw hydrogens\n" |
| 1056 |
|
" -b draw bonds\n" |
| 1057 |
|
" -a draw atoms\n" |
| 1058 |
+ |
" -v draw vectors\n" |
| 1059 |
|
" -p draw periodic box\n" |
| 1060 |
|
" -r regenerate bond\n" |
| 1061 |
|
" -f <#> render frame <#> only\n" |
| 1065 |
|
program_name); |
| 1066 |
|
exit(8); |
| 1067 |
|
} |
| 1068 |
+ |
|
| 1069 |
+ |
int count_tokens(line, delimiters) |
| 1070 |
+ |
/* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */ |
| 1071 |
+ |
char *line; /* LINE CONTAINING TOKENS. */ |
| 1072 |
+ |
char *delimiters; /* POSSIBLE TOKEN DELIMITERS TO USE. */ |
| 1073 |
+ |
{ |
| 1074 |
+ |
char *working_line; /* WORKING COPY OF LINE. */ |
| 1075 |
+ |
int ntokens; /* NUMBER OF TOKENS FOUND IN LINE. */ |
| 1076 |
+ |
char *strtok_ptr; /* POINTER FOR STRTOK. */ |
| 1077 |
+ |
|
| 1078 |
+ |
strtok_ptr= working_line= strdup(line); |
| 1079 |
+ |
|
| 1080 |
+ |
ntokens=0; |
| 1081 |
+ |
while (strtok(strtok_ptr,delimiters)!=NULL) |
| 1082 |
+ |
{ |
| 1083 |
+ |
ntokens++; |
| 1084 |
+ |
strtok_ptr=NULL; |
| 1085 |
+ |
} |
| 1086 |
+ |
|
| 1087 |
+ |
free(working_line); |
| 1088 |
+ |
return(ntokens); |
| 1089 |
+ |
} |