Changeset 1b192d
- Timestamp:
- Jun 20, 2008, 5:55:00 PM (17 years ago)
- Children:
- e2f3fde
- Parents:
- c6a100
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
util/src/NanoCreator.c
rc6a100 r1b192d 404 404 exit(255); 405 405 } 406 double betrag 1, betrag2;406 double betrag; 407 407 int i; 408 408 409 409 // first vector is untouched 410 410 // second vector 411 betrag1 = Projection(orthvector[axis[1]], orthvector[axis[0]]); 411 betrag = Projection(orthvector[axis[1]], orthvector[axis[0]]); 412 fprintf(stdout,"%lg\t",betrag); 412 413 for (i=0;i<NDIM;i++) 413 orthvector[axis[ 0]][i] -= orthvector[axis[1]][i] * betrag1;414 orthvector[axis[1]][i] -= orthvector[axis[0]][i] * betrag; 414 415 // third vector 415 betrag 1= Projection(orthvector[axis[0]], orthvector[axis[2]]);416 betrag2 = Projection(orthvector[axis[1]], orthvector[axis[2]]);416 betrag = Projection(orthvector[axis[0]], orthvector[axis[2]]); 417 fprintf(stdout,"%lg\t",betrag); 417 418 for (i=0;i<NDIM;i++) 418 orthvector[axis[2]][i] -= orthvector[axis[0]][i] * betrag1 + orthvector[axis[1]][i] * betrag2; 419 orthvector[axis[2]][i] -= orthvector[axis[0]][i] * betrag; 420 betrag = Projection(orthvector[axis[1]], orthvector[axis[2]]); 421 fprintf(stdout,"%lg\n",betrag); 422 for (i=0;i<NDIM;i++) 423 orthvector[axis[2]][i] -= orthvector[axis[1]][i] * betrag; 419 424 } 420 425 … … 581 586 } 582 587 588 /** Creates orthogonal vectors to directions axis[0] and axis[1], assuming that axis[2] is always orthogonal. 589 * \param **OrthoVector contains vectors set on return with axis[2] equal to Vector[axis[2]] 590 * \param **Vector vectors to orthogonalize against 591 * \param *axis lookup for which direction is which. 592 */ 593 void CreateOrthogonalAxisVectors(double **OrthoVector, double **Vector, int *axis) { 594 int i,j; 595 double factor; 596 // allocate memory 597 int *TempAxis = (int *) Malloc(sizeof(int)*NDIM, "Main: *TempAxis"); 598 double **TempVectors = (double **) Malloc(sizeof(double *)*NDIM, "Main: *TempVectors"); 599 for (i=0; i<NDIM; i++) 600 TempVectors[i] = (double *) Malloc(sizeof(double)*NDIM, "Main: TempVectors"); 601 602 for (i=0; i<NDIM; i++) 603 for (j=0; j<NDIM; j++) 604 TempVectors[i][j] = Vector[i][j]; 605 // GramSchmidt generates Vector[1] orthogonal to Vector[0] and Vector[2] ortho. to Vector[1] and Vector[0]! 606 TempAxis[0] = axis[2]; // (axis 2 is the orthogonal plane axis) 607 TempAxis[1] = axis[0]; 608 TempAxis[2] = axis[1]; 609 Orthogonalize(TempVectors, TempAxis); 610 factor = Norm(Vector[axis[0]])/Norm(TempVectors[TempAxis[2]]); 611 factor *= (Projection(TempVectors[TempAxis[2]], Vector[axis[0]]) > 0) ? 1. : -1.; 612 for (i=0; i<NDIM; i++) 613 OrthoVector[axis[0]][i] = TempVectors[TempAxis[2]][i]*factor; 614 615 TempAxis[1] = axis[1]; 616 TempAxis[2] = axis[0]; 617 for (i=0; i<NDIM; i++) 618 for (j=0; j<NDIM; j++) 619 TempVectors[i][j] = Vector[i][j]; 620 Orthogonalize(TempVectors, TempAxis); 621 factor = Norm(Vector[axis[1]])/Norm(TempVectors[TempAxis[2]]); 622 factor *= (Projection(TempVectors[TempAxis[2]], Vector[axis[1]]) > 0) ? 1. : -1.; 623 for (i=0; i<NDIM; i++) 624 OrthoVector[axis[1]][i] = TempVectors[TempAxis[2]][i]*factor; 625 626 for (i=0; i<NDIM; i++) 627 OrthoVector[axis[2]][i] = Vector[axis[2]][i]; 628 //print vectors 629 fprintf(stdout, "Orthogonal vectors are: \n"); 630 for (i=0; i<NDIM; i++) { 631 for (j=0; j<NDIM; j++) 632 fprintf(stdout, "%lg\t", OrthoVector[axis[i]][j]); 633 fprintf(stdout, "\n"); 634 } 635 636 // free memory 637 Free(TempAxis, "CreateOrthogonalAxisVectors: *TempAxis"); 638 for (i=0; i<NDIM; i++ ) 639 Free(TempVectors[i], "CreateOrthogonalAxisVectors: TempVectors"); 640 Free(TempVectors, "CreateOrthogonalAxisVectors: *TempVectors"); 641 }; 642 583 643 // ================================= other functions ============================== 584 644 645 /** Prints a debug message. 646 * \param *msg debug message 647 */ 585 648 void Debug(char *msg) 586 649 { … … 591 654 fprintf(stdout, "%s", msg); 592 655 } 656 593 657 594 658 // --------------------------------------- M A I N --------------------------------------------------- … … 597 661 char *CellFilename = NULL, *SheetFilename = NULL, *TubeFilename = NULL, *TorusFilename = NULL; 598 662 char *SheetFilenameAligned = NULL, *TubeFilenameAligned = NULL; 599 double **Vector, ** Recivector = NULL, **Tubevector = NULL, **TubevectorInverse = NULL;663 double **Vector, **OrthoVector, **Recivector = NULL, **Tubevector = NULL, **TubevectorInverse = NULL; 600 664 double *atom = NULL, *atom_transformed = NULL; 601 665 double *x = NULL, *coord = NULL, *tempvector = NULL, *offset = NULL; … … 645 709 atom = (double *) Malloc(sizeof(double)*NDIM, "Main: atom"); 646 710 Vector = (double **) Malloc(sizeof(double *)*NDIM, "Main: *Vector"); 711 OrthoVector = (double **) Malloc(sizeof(double *)*NDIM, "Main: *OrthoVector"); 647 712 Recivector = (double **) Malloc(sizeof(double *)*NDIM, "Main: *Recivector"); 648 713 Tubevector = (double **) Malloc(sizeof(double *)*NDIM, "Main: *Tubevector"); … … 650 715 for (i=0; i<NDIM; i++ ) { 651 716 Vector[i] = (double *) Malloc(sizeof(double)*NDIM, "Main: Vector"); 717 OrthoVector[i] = (double *) Malloc(sizeof(double)*NDIM, "Main: OrthoVector"); 652 718 Recivector[i] = (double *) Malloc(sizeof(double)*NDIM, "Main: Recivector"); 653 719 Tubevector[i] = (double *) Malloc(sizeof(double)*NDIM, "Main: Tubevector"); … … 701 767 PrintMatrix(stdout, Recivector); 702 768 fprintf(stdout, "Reciprocal volume is %lg\n", Determinant(Recivector)); 703 769 704 770 fprintf(stdout, "Vector magnitudes: %5.5lg %5.5lg %5.5lg\n", Norm(Vector[0]), Norm(Vector[1]), Norm(Vector[2])); 705 771 … … 788 854 fscanf(stdin, "%d %d %d", &axis[0], &axis[1], &axis[2]); 789 855 fprintf(stdout, "axis: %d %d %d\n", axis[0], axis[1], axis[2]); 856 857 // create orthogonal vectors individually for each unit cell vector 858 CreateOrthogonalAxisVectors(OrthoVector, Vector, axis); 859 fprintf(stdout, "Orthogonal vector axis[0] %lg\n", Projection(Vector[axis[0]], OrthoVector[axis[0]])); 860 fprintf(stdout, "Orthogonal vector axis[1] %lg\n", Projection(Vector[axis[1]], OrthoVector[axis[1]])); 861 790 862 do { 791 863 fprintf(stdout, "\nNow specify the two natural numbers (m n) defining the chiral angle, \nif the result is crap, try flipping to (m,n): "); … … 795 867 fprintf(stdout, "chiral0: %d\tchiral1: %d\n", chiral[0], chiral[1]); 796 868 for (i=0;i<NDIM;i++) { 797 //Tubevector[axis[0]][i] = (double)chiral[0] * Vector[axis[0]][i] + (double)chiral[1] * Vector[axis[1]][i];798 Tubevector[axis[0]][i] = chiral[0] * Vector[axis[0]][i] + chiral[1] * Vector[axis[1]][i];869 Tubevector[axis[0]][i] = (double)chiral[0] * Vector[axis[0]][i] + (double)chiral[1] * Vector[axis[1]][i]; 870 //Tubevector[axis[0]][i] = chiral[0] * Vector[axis[0]][i] + chiral[1] * Vector[axis[1]][i]; 799 871 //Tubevector[axis[0]][i] = (2.*chiral[0]+chiral[1])/(double)ggT * Vector[axis[0]][i] + (-chiral[0]-2.*chiral[1])/(double)ggT * Vector[axis[1]][i]; 800 Tubevector[axis[1]][i] = -chiral[1] * Vector[axis[0]][i] + chiral[0] * Vector[axis[1]][i]; 872 //Tubevector[axis[1]][i] = -chiral[1] * Vector[axis[0]][i] + chiral[0] * Vector[axis[1]][i]; 873 Tubevector[axis[1]][i] = (double)chiral[0] * OrthoVector[axis[0]][i] - (double)chiral[1] * OrthoVector[axis[1]][i]; 801 874 //Tubevector[axis[1]][i] = (-chiral[0]-2.*chiral[1])/(double)ggT * Vector[axis[0]][i] + (2.*chiral[0]+chiral[1])/(double)ggT * Vector[axis[1]][i]; 802 875 // fprintf(stderr, "Tubevector[axis[0]][i] = (double)chiral[0] * Vector[axis[0]][i] + (double)chiral[1] * Vector[axis[1]][i]\n = %lg * %lg + %lg * %lg = %lg + %lg = %lg\n\n", … … 806 879 Tubevector[axis[2]][i] = Vector[axis[2]][i]; 807 880 } 881 // tmp = Norm(Tubevector[axis[1]]); 882 // for (i=0;i<NDIM;i++) 883 // Tubevector[axis[1]][i] *= Norm(Vector[axis[1]])*sqrt(3)*sqrt(chiral[0]*chiral[0]+chiral[1]*chiral[1]+chiral[0]*chiral[1])/(double)ggT/tmp; 884 fprintf(stdout, "Orthogonal Tubevector axis[0->1] %lg\n", Projection(Tubevector[axis[0]], Tubevector[axis[1]])); 885 fprintf(stdout, "Orthogonal Tubevector axis[0->2] %lg\n", Projection(Tubevector[axis[0]], Tubevector[axis[2]])); 886 fprintf(stdout, "Orthogonal Tubevector axis[1->2] %lg\n", Projection(Tubevector[axis[1]], Tubevector[axis[2]])); 887 808 888 /* fprintf(stdout, "Vector\n"); 809 889 PrintMatrix(stdout, Vector); … … 895 975 fprintf(stdout, "%d %d %d\n", factors[0], factors[1], factors[2]); 896 976 977 // create orthogonal vectors individually for each unit cell vector 978 CreateOrthogonalAxisVectors(OrthoVector, Vector, axis); 979 fprintf(stdout, "Orthogonal vector axis[0] %lg", Projection(Vector[axis[0]], OrthoVector[axis[0]])); 980 fprintf(stdout, "Orthogonal vector axis[1] %lg", Projection(Vector[axis[1]], OrthoVector[axis[1]])); 897 981 // create Tubevectors 898 982 for (i=0;i<NDIM;i++) { 899 983 Tubevector[axis[0]][i] = chiral[0] * Vector[axis[0]][i] + chiral[1] * Vector[axis[1]][i]; 900 984 //Tubevector[axis[0]][i] = (2.*chiral[0]+chiral[1])/(double)ggT * Vector[axis[0]][i] + (-chiral[0]-2.*chiral[1])/(double)ggT * Vector[axis[1]][i]; 901 Tubevector[axis[1]][i] = -chiral[1] * Vector[axis[0]][i] + chiral[0] * Vector[axis[1]][i]; 985 //Tubevector[axis[1]][i] = -chiral[1] * Vector[axis[0]][i] + chiral[0] * Vector[axis[1]][i]; 986 Tubevector[axis[1]][i] = chiral[0] * OrthoVector[axis[0]][i] + chiral[1] * OrthoVector[axis[1]][i]; 902 987 //Tubevector[axis[1]][i] = (-chiral[0]-2.*chiral[1])/(double)ggT * Vector[axis[0]][i] + (2.*chiral[0]+chiral[1])/(double)ggT * Vector[axis[1]][i]; 903 988 Tubevector[axis[2]][i] = Vector[axis[2]][i]; 904 989 } 990 905 991 906 992 // retrieve seed ... … … 949 1035 } 950 1036 951 //Orthogonalize(Tubevector,axis); 1037 //int OrthOrder[NDIM] = { axis[2], axis[0], axis[1] }; 1038 //Orthogonalize(Tubevector,OrthOrder); 952 1039 angle = acos(Projection(Vector[axis[0]], Vector[axis[1]])); // calcs angle between shanks in unit cell 953 fprintf(stdout, "The basic angle between the two shanks of the unit cell is %lg\n", angle/M_PI*180.); 1040 fprintf(stdout, "The basic angle between the two shanks of the unit cell is %lg %lg\n", angle/M_PI*180., Projection(Vector[axis[0]], Vector[axis[1]])); 1041 if ( angle/M_PI*180. > 90 ) { 1042 fprintf(stderr, "There seems to be something wrong with the unit cell! for nanotube the angle should be 60 degrees for example!\n"); 1043 return 1; 1044 } 954 1045 angle = acos(Projection(Tubevector[axis[0]], Tubevector[axis[1]])); // calcs angle between shanks in unit cell 955 fprintf(stdout, "The basic angle between the two shanks of the tube unit cell is %lg \n", angle/M_PI*180.);1046 fprintf(stdout, "The basic angle between the two shanks of the tube unit cell is %lg %lg\n", angle/M_PI*180., Projection(Tubevector[axis[0]], Tubevector[axis[1]])); 956 1047 //angle -= acos(Projection(Vector[axis[0]], Tubevector[axis[0]])); 957 1048 //angle = 30./180.*M_PI - acos(Projection(Vector[axis[0]], Tubevector[axis[0]])); 958 angle = - 1049 angle = -acos(Projection(Tubevector[axis[0]], Vector[axis[0]])); 959 1050 fprintf(stdout, "The relative alignment rotation angle then is %lg\n", angle/M_PI*180.); 960 angle += acos(Projection(Vector[axis[0]], Vector[axis[1]]))/2.; 961 fprintf(stdout, "The absolute alignment rotation angle then is %lg\n", angle/M_PI*180.); 1051 if (fabs(Tubevector[axis[0]][0]) > MYEPSILON) 1052 angle = M_PI/2. - acos(Tubevector[axis[0]][0]/Norm(Tubevector[axis[0]])); 1053 else 1054 angle = 0.; 1055 fprintf(stdout, "The absolute alignment rotation angle then is %lg %lg\n", angle/M_PI*180., Tubevector[axis[0]][0]/Norm(Tubevector[axis[0]])); 962 1056 fprintf(stdout, "\nThe chiral angle then is %5.5f degrees with tube radius %5.5f A and length %5.5f A, i.e. torus radius of %5.5f A.\n", 963 1057 acos(Projection(Vector[axis[0]], Tubevector[axis[0]]))/M_PI*180., … … 968 1062 Orthogonalize(Tubevector, axis); // with correct translational vector, not needed anymore (? what's been done here. Hence, re-inserted) 969 1063 fprintf(stdout, "Tubevector magnitudes: %5.5lg %5.5lg %5.5lg\n", Norm(Tubevector[0]), Norm(Tubevector[1]), Norm(Tubevector[2])); 970 fprintf(stdout, "Tube bvectors are \n");1064 fprintf(stdout, "Tubevectors are \n"); 971 1065 PrintMatrix(stdout, Tubevector); 972 1066 MatrixInversion(Tubevector, TubevectorInverse); … … 1057 1151 //PrintVector(stdout, coord); 1058 1152 // project down on major and minor Tubevectors and check for length if out of sheet 1059 tempvector = MatrixTrafoInverse( coord, TubevectorInverse);1153 tempvector = MatrixTrafoInverse(offset, TubevectorInverse); 1060 1154 if (((tempvector[axis[0]] + MYEPSILON) >= 0) && ((factors[0] - tempvector[axis[0]]) > MYEPSILON) && 1061 1155 ((tempvector[axis[1]] + MYEPSILON) >= 0) && ((factors[1] - tempvector[axis[1]]) > MYEPSILON) && … … 1166 1260 fprintf(TubeFile, "%s\t%lg\t%lg\t%lg\n", name, atom_transformed[0], atom_transformed[1], atom_transformed[2]); 1167 1261 // rotate and flip to align tube in z-direction 1168 x1 = atom_transformed[0]*cos( angle) + atom_transformed[1] * sin(angle);1169 x2 = atom_transformed[0]*(-sin( angle)) + atom_transformed[1] * cos(angle);1262 x1 = atom_transformed[0]*cos(-angle) + atom_transformed[1] * sin(-angle); 1263 x2 = atom_transformed[0]*(-sin(-angle)) + atom_transformed[1] * cos(-angle); 1170 1264 x3 = atom_transformed[2]; 1171 fprintf(TubeFileAligned, "%s\t%lg\t%lg\t%lg\n", name, x 1, x3, x2);1265 fprintf(TubeFileAligned, "%s\t%lg\t%lg\t%lg\n", name, x3, x2, x1); // order so that symmetry is along z axis 1172 1266 //fprintf(stdout, "%s\t%5.5lg\t%5.5lg\t%5.5lg\n", name, atom_transformed[0], atom_transformed[1] ,atom_transformed[2]); 1173 1267
Note:
See TracChangeset
for help on using the changeset viewer.