36 |
|
|
37 |
|
void parseDumpLine( char readBuffer[BUFFER_SIZE], int index, |
38 |
|
struct atomCoord* atoms ); |
39 |
+ |
void setU( double q[4], double u[3] ); |
40 |
+ |
void normalizeQ( double q[4] ); |
41 |
|
|
42 |
|
void openFile( char* inName ){ |
43 |
|
|
368 |
|
} |
369 |
|
} |
370 |
|
|
371 |
< |
void parseDumpLine( char readLine[BUFFER_SIZE], int index, |
371 |
> |
void parseDumpLine( char readLine[BUFFER_SIZE], int i, |
372 |
|
struct atomCoord* atoms ){ |
373 |
|
char* foo; |
374 |
|
double q[4]; |
379 |
|
|
380 |
|
// check the atom ID |
381 |
|
|
382 |
< |
switch( atoms[index].type ){ |
382 |
> |
switch( atoms[i].type ){ |
383 |
|
|
384 |
|
case HEAD: |
385 |
|
if( strcmp(foo, "HEAD") ){ |
429 |
|
default: |
430 |
|
fprintf(stderr, |
431 |
|
"Atom %d is an unrecognized enumeration\n", |
432 |
< |
index ); |
432 |
> |
i ); |
433 |
|
exit(0); |
434 |
|
} |
435 |
|
|
439 |
|
if(foo == NULL){ |
440 |
|
fprintf( stderr, |
441 |
|
"error in reading postition x from %s\n" |
442 |
< |
"natoms = %d, index = %d\n", |
443 |
< |
inName, nAtoms, index ); |
442 |
> |
"natoms = %d, i = %d\n", |
443 |
> |
inName, nAtoms, i ); |
444 |
|
exit(0); |
445 |
|
} |
446 |
|
atoms[i].pos[0] = atof( foo ); |
449 |
|
if(foo == NULL){ |
450 |
|
fprintf( stderr, |
451 |
|
"error in reading postition y from %s\n" |
452 |
< |
"natoms = %d, index = %d\n", |
453 |
< |
inName, nAtoms, index ); |
452 |
> |
"natoms = %d, i = %d\n", |
453 |
> |
inName, nAtoms, i ); |
454 |
|
exit(0); |
455 |
|
} |
456 |
|
atoms[i].pos[1] = atof( foo ); |
459 |
|
if(foo == NULL){ |
460 |
|
fprintf( stderr, |
461 |
|
"error in reading postition z from %s\n" |
462 |
< |
"natoms = %d, index = %d\n", |
463 |
< |
inName, nAtoms, index ); |
462 |
> |
"natoms = %d, i = %d\n", |
463 |
> |
inName, nAtoms, i ); |
464 |
|
exit(0); |
465 |
|
} |
466 |
|
atoms[i].pos[2] = atof( foo ); |
472 |
|
if(foo == NULL){ |
473 |
|
fprintf( stderr, |
474 |
|
"error in reading velocity x from %s\n" |
475 |
< |
"natoms = %d, index = %d\n", |
476 |
< |
inName, nAtoms, index ); |
475 |
> |
"natoms = %d, i = %d\n", |
476 |
> |
inName, nAtoms, i ); |
477 |
|
exit(0); |
478 |
|
} |
479 |
|
atoms[i].vel[0] = atof( foo ); |
482 |
|
if(foo == NULL){ |
483 |
|
fprintf( stderr, |
484 |
|
"error in reading velocity y from %s\n" |
485 |
< |
"natoms = %d, index = %d\n", |
486 |
< |
inName, nAtoms, index ); |
485 |
> |
"natoms = %d, i = %d\n", |
486 |
> |
inName, nAtoms, i ); |
487 |
|
exit(0); |
488 |
|
} |
489 |
|
atoms[i].vel[1] = atof( foo ); |
492 |
|
if(foo == NULL){ |
493 |
|
fprintf( stderr, |
494 |
|
"error in reading velocity z from %s\n" |
495 |
< |
"natoms = %d, index = %d\n", |
496 |
< |
inName, nAtoms, index ); |
495 |
> |
"natoms = %d, i = %d\n", |
496 |
> |
inName, nAtoms, i ); |
497 |
|
exit(0); |
498 |
|
} |
499 |
|
atoms[i].vel[2] = atof( foo ); |
507 |
|
if(foo == NULL){ |
508 |
|
sprintf(painCave.errMsg, |
509 |
|
"error in reading quaternion 0 from %s\n" |
510 |
< |
"natoms = %d, index = %d\n", |
511 |
< |
inName, nAtoms, index ); |
510 |
> |
"natoms = %d, i = %d\n", |
511 |
> |
inName, nAtoms, i ); |
512 |
|
exit(0); |
513 |
|
} |
514 |
|
q[0] = atof( foo ); |
517 |
|
if(foo == NULL){ |
518 |
|
fprintf( stderr, |
519 |
|
"error in reading quaternion 1 from %s\n" |
520 |
< |
"natoms = %d, index = %d\n", |
521 |
< |
inName, nAtoms, index ); |
520 |
> |
"natoms = %d, i = %d\n", |
521 |
> |
inName, nAtoms, i ); |
522 |
|
exit(0); |
523 |
|
} |
524 |
|
q[1] = atof( foo ); |
527 |
|
if(foo == NULL){ |
528 |
|
fprintf( stderr, |
529 |
|
"error in reading quaternion 2 from %s\n" |
530 |
< |
"natoms = %d, index = %d\n", |
531 |
< |
inName, nAtoms, index ); |
530 |
> |
"natoms = %d, i = %d\n", |
531 |
> |
inName, nAtoms, i ); |
532 |
|
exit(0); |
533 |
|
} |
534 |
|
q[2] = atof( foo ); |
537 |
|
if(foo == NULL){ |
538 |
|
fprintf( stderr, |
539 |
|
"error in reading quaternion 3 from %s\n" |
540 |
< |
"natoms = %d, index = %d\n", |
541 |
< |
inName, nAtoms, index ); |
540 |
> |
"natoms = %d, i = %d\n", |
541 |
> |
inName, nAtoms, i ); |
542 |
|
exit(0); |
543 |
|
} |
544 |
|
q[3] = atof( foo ); |
545 |
+ |
|
546 |
+ |
normalizeQ( q ); |
547 |
+ |
|
548 |
+ |
setU( q, atoms[i].u ); |
549 |
|
} |
550 |
+ |
} |
551 |
|
|
552 |
|
|
553 |
+ |
void setU( double the_q[4], double u[3] ){ |
554 |
|
|
555 |
+ |
double q0Sqr, q1Sqr, q2Sqr, q3Sqr; |
556 |
+ |
double A[3][3]; |
557 |
+ |
double rb[3]; |
558 |
|
|
559 |
+ |
// initialize the axis |
560 |
|
|
561 |
+ |
rb[0] = 0.0; |
562 |
+ |
rb[1] = 0.0; |
563 |
+ |
rb[2] = 1.0; |
564 |
+ |
|
565 |
+ |
// set the rotation matrix |
566 |
+ |
|
567 |
+ |
q0Sqr = the_q[0] * the_q[0]; |
568 |
+ |
q1Sqr = the_q[1] * the_q[1]; |
569 |
+ |
q2Sqr = the_q[2] * the_q[2]; |
570 |
+ |
q3Sqr = the_q[3] * the_q[3]; |
571 |
+ |
|
572 |
+ |
A[0][0] = q0Sqr + q1Sqr - q2Sqr - q3Sqr; |
573 |
+ |
A[0][1] = 2.0 * ( the_q[1] * the_q[2] + the_q[0] * the_q[3] ); |
574 |
+ |
A[0][2] = 2.0 * ( the_q[1] * the_q[3] - the_q[0] * the_q[2] ); |
575 |
+ |
|
576 |
+ |
A[1][0] = 2.0 * ( the_q[1] * the_q[2] - the_q[0] * the_q[3] ); |
577 |
+ |
A[1][1] = q0Sqr - q1Sqr + q2Sqr - q3Sqr; |
578 |
+ |
A[1][2] = 2.0 * ( the_q[2] * the_q[3] + the_q[0] * the_q[1] ); |
579 |
+ |
|
580 |
+ |
A[2][0] = 2.0 * ( the_q[1] * the_q[3] + the_q[0] * the_q[2] ); |
581 |
+ |
A[2][1] = 2.0 * ( the_q[2] * the_q[3] - the_q[0] * the_q[1] ); |
582 |
+ |
A[2][2] = q0Sqr - q1Sqr -q2Sqr +q3Sqr; |
583 |
+ |
|
584 |
+ |
// perform the rotation |
585 |
+ |
|
586 |
+ |
for( i=0; i<3; i++ ){ |
587 |
+ |
u[i] = 0.0; |
588 |
+ |
|
589 |
+ |
for( j=0; j<3; j++ ){ |
590 |
+ |
u[i] += A[j][i] * rb[j]; |
591 |
+ |
} |
592 |
+ |
} |
593 |
|
} |
594 |
+ |
|
595 |
+ |
void normalizeQ( double q[4] ){ |
596 |
+ |
|
597 |
+ |
double qSqr, qL; |
598 |
+ |
int i; |
599 |
+ |
|
600 |
+ |
qSqr = 0.0; |
601 |
+ |
for(i=0;i<4;i++) |
602 |
+ |
qSqr += q[i] * q[i]; |
603 |
+ |
|
604 |
+ |
for(i=0;i<4;i++) |
605 |
+ |
q[i] /= qSqr; |
606 |
+ |
} |
607 |
+ |
|