Changeset fafb43
- Timestamp:
- Feb 6, 2009, 9:48:35 AM (17 years ago)
- Children:
- 4aef8a
- Parents:
- d3d15c
- File:
-
- 1 edited
-
util/src/NanoCreator.c (modified) (69 diffs)
Legend:
- Unmodified
- Added
- Removed
-
util/src/NanoCreator.c
rd3d15c rfafb43 25 25 * \return pointer to allocated memory 26 26 */ 27 void * Malloc (size_t size, const char *msg) 27 void * Malloc (size_t size, const char *msg) 28 28 { 29 29 void *ptr = malloc(size); … … 45 45 * \return pointer to allocated memory 46 46 */ 47 void * Calloc (size_t size, double value, const char *msg) 47 void * Calloc (size_t size, double value, const char *msg) 48 48 { 49 49 void *ptr = calloc(size, value); … … 76 76 77 77 /** Allocs memory and prints a message on fail. 78 * \param **old_ptr pointer to old memory range 78 * \param **old_ptr pointer to old memory range 79 79 * \param *newsize new size of alloc in bytes 80 80 * \param *msg error msg 81 81 * \return pointer to allocated memory 82 82 */ 83 void * Realloc (void *old_ptr, size_t newsize, const char *msg) 83 void * Realloc (void *old_ptr, size_t newsize, const char *msg) 84 84 { 85 85 if (old_ptr == NULL) { … … 104 104 * \return pointer to allocated segment with contents 105 105 */ 106 char * ReadBuffer (char *filename, int *bufferlength) 106 char * ReadBuffer (char *filename, int *bufferlength) 107 107 { 108 108 if ((filename == NULL) || (bufferlength == NULL)) { … … 160 160 * \param atomicnumber number of atoms in cell 161 161 */ 162 void AddAtomicNumber(char *filename, int atomicnumber, double **Vector, double **Recivector) 162 void AddAtomicNumber(char *filename, int atomicnumber, double **Vector, double **Recivector) 163 163 { 164 164 if ((filename == NULL) || (Vector == NULL) || (Recivector == NULL)) { … … 175 175 double volume = Determinant(Vector); 176 176 time_t now; 177 177 178 178 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 179 179 // open for writing and prepend … … 204 204 * \param *factors pointer to array with length and radius factor 205 205 * \param seed random number seed 206 * \param numbercell number of atoms in unit cell, needed as length of \a *randomness 206 * \param numbercell number of atoms in unit cell, needed as length of \a *randomness 207 207 * \param *randomness for each atom in unit cell a factor between 0..1, giving its probability of appearance 208 208 */ … … 254 254 } 255 255 int i,j; 256 256 257 257 for (i=0;i<NDIM;i++) 258 258 for (j=0;j<NDIM;j++) 259 259 returnvector[j] += matrixref[i][j] * vectorref[i]; 260 261 return returnvector; 260 261 return returnvector; 262 262 } 263 263 double *MatrixTrafoInverse(double *vectorref, double **matrixref) … … 274 274 } 275 275 int i,j; 276 276 277 277 for (i=0;i<NDIM;i++) 278 278 for (j=0;j<NDIM;j++) 279 279 returnvector[i] += matrixref[i][j] * vectorref[j]; 280 281 return returnvector; 280 281 return returnvector; 282 282 } 283 283 … … 286 286 * \param **inverse allocated space for inverse of \a **matrix 287 287 */ 288 void MatrixInversion(double **matrix, double **inverse) 288 void MatrixInversion(double **matrix, double **inverse) 289 289 { 290 290 if ((matrix == NULL) || (inverse == NULL)) { … … 294 294 // determine inverse 295 295 double det = Determinant(matrix); 296 inverse[0][0] = (matrix[1][1]*matrix[2][2] - matrix[1][2]*matrix[2][1])/det; 297 inverse[1][0] = (matrix[0][2]*matrix[2][1] - matrix[0][1]*matrix[2][2])/det; 298 inverse[2][0] = (matrix[0][1]*matrix[1][2] - matrix[0][2]*matrix[1][1])/det; 299 inverse[0][1] = (matrix[1][2]*matrix[2][0] - matrix[1][0]*matrix[2][2])/det; 300 inverse[1][1] = (matrix[0][0]*matrix[2][2] - matrix[0][2]*matrix[2][0])/det; 301 inverse[2][1] = (matrix[0][2]*matrix[1][0] - matrix[0][0]*matrix[1][2])/det; 302 inverse[0][2] = (matrix[1][0]*matrix[2][1] - matrix[1][1]*matrix[2][0])/det; 303 inverse[1][2] = (matrix[0][1]*matrix[2][0] - matrix[0][0]*matrix[2][1])/det; 296 inverse[0][0] = (matrix[1][1]*matrix[2][2] - matrix[1][2]*matrix[2][1])/det; 297 inverse[1][0] = (matrix[0][2]*matrix[2][1] - matrix[0][1]*matrix[2][2])/det; 298 inverse[2][0] = (matrix[0][1]*matrix[1][2] - matrix[0][2]*matrix[1][1])/det; 299 inverse[0][1] = (matrix[1][2]*matrix[2][0] - matrix[1][0]*matrix[2][2])/det; 300 inverse[1][1] = (matrix[0][0]*matrix[2][2] - matrix[0][2]*matrix[2][0])/det; 301 inverse[2][1] = (matrix[0][2]*matrix[1][0] - matrix[0][0]*matrix[1][2])/det; 302 inverse[0][2] = (matrix[1][0]*matrix[2][1] - matrix[1][1]*matrix[2][0])/det; 303 inverse[1][2] = (matrix[0][1]*matrix[2][0] - matrix[0][0]*matrix[2][1])/det; 304 304 inverse[2][2] = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0])/det; 305 305 306 306 // check inverse 307 int flag = 0; 307 int flag = 0; 308 308 int i,j,k; 309 double tmp; 309 double tmp; 310 310 fprintf(stdout, "Checking inverse ... "); 311 311 for (i=0;i<NDIM;i++) … … 319 319 } else { 320 320 flag = (fabs(tmp) > MYEPSILON) ? 1 : 0; 321 } 321 } 322 322 } 323 323 } … … 357 357 flip(&matrix[i][j],&matrix[j][i]); 358 358 } 359 359 360 360 361 361 /** Computes the determinant of a NDIMxNDIM matrix. … … 370 370 double det = matrix[0][0] * (matrix[1][1]*matrix[2][2] - matrix[1][2]*matrix[2][1]) 371 371 - matrix[1][1] * (matrix[0][0]*matrix[2][2] - matrix[0][2]*matrix[2][0]) 372 + matrix[2][2] * (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]); 372 + matrix[2][2] * (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]); 373 373 return det; 374 374 } … … 392 392 } 393 393 int i; 394 394 395 395 for (i=0;i<NDIM;i++) 396 396 returnvector[i] = vector1[i] + vector2[i]; 397 397 398 398 return returnvector; 399 399 } … … 412 412 double betrag; 413 413 int i; 414 414 415 415 // first vector is untouched 416 416 // second vector 417 betrag = Projection(orthvector[axis[1]], orthvector[axis[0]]); 417 betrag = Projection(orthvector[axis[1]], orthvector[axis[0]]); 418 418 fprintf(stdout,"%lg\t",betrag); 419 419 for (i=0;i<NDIM;i++) 420 420 orthvector[axis[1]][i] -= orthvector[axis[0]][i] * betrag; 421 421 // third vector 422 betrag = Projection(orthvector[axis[0]], orthvector[axis[2]]); 422 betrag = Projection(orthvector[axis[0]], orthvector[axis[2]]); 423 423 fprintf(stdout,"%lg\t",betrag); 424 424 for (i=0;i<NDIM;i++) 425 425 orthvector[axis[2]][i] -= orthvector[axis[0]][i] * betrag; 426 betrag = Projection(orthvector[axis[1]], orthvector[axis[2]]); 426 betrag = Projection(orthvector[axis[1]], orthvector[axis[2]]); 427 427 fprintf(stdout,"%lg\n",betrag); 428 428 for (i=0;i<NDIM;i++) … … 433 433 * \param *vector1 reference vector 434 434 * \param *vector2 vector which is projected 435 * \return projection 435 * \return projection 436 436 */ 437 437 double Projection(double *vector1, double *vector2) … … 457 457 double scp = 0.; 458 458 int i; 459 459 460 460 for (i=0;i<NDIM;i++) 461 461 scp += vector1[i] * vector2[i]; 462 462 463 463 return scp; 464 464 } … … 468 468 * \return norm of \a *vector 469 469 */ 470 double Norm(double *vector) 470 double Norm(double *vector) 471 471 { 472 472 if (vector == NULL) { … … 540 540 double diameter[2] = {0.,0.}; 541 541 int i, biggest; 542 542 543 543 for (i=0;i<NDIM;i++) { 544 544 diameter[0] += (matrix[axis[0]][i]*factors[0] - matrix[axis[1]][i]*factors[1]) * (matrix[axis[0]][i]*factors[0] - matrix[axis[1]][i]*factors[1]); … … 555 555 556 556 return diameter[biggest]; 557 } 557 } 558 558 559 559 /** Determines the center of gravity of atoms in a buffer \a bufptr with given \a number … … 576 576 char name[255], line[255]; 577 577 int i,j; 578 578 579 579 // Determine center of gravity 580 580 for (i=0;i<number;i++) { … … 587 587 for (i=0;i<NDIM;i++) 588 588 cog[i] /= -number; 589 589 590 590 Free(atom, "CenterOfGravity: atom"); 591 591 return cog; … … 605 605 for (i=0; i<NDIM; i++) 606 606 TempVectors[i] = (double *) Malloc(sizeof(double)*NDIM, "Main: TempVectors"); 607 607 608 608 for (i=0; i<NDIM; i++) 609 609 for (j=0; j<NDIM; j++) … … 618 618 for (i=0; i<NDIM; i++) 619 619 OrthoVector[axis[0]][i] = TempVectors[TempAxis[2]][i]*factor; 620 620 621 621 TempAxis[1] = axis[1]; 622 622 TempAxis[2] = axis[0]; … … 629 629 for (i=0; i<NDIM; i++) 630 630 OrthoVector[axis[1]][i] = TempVectors[TempAxis[2]][i]*factor; 631 631 632 632 for (i=0; i<NDIM; i++) 633 633 OrthoVector[axis[2]][i] = Vector[axis[2]][i]; … … 635 635 fprintf(stdout, "Orthogonal vectors are: \n"); 636 636 for (i=0; i<NDIM; i++) { 637 for (j=0; j<NDIM; j++) 637 for (j=0; j<NDIM; j++) 638 638 fprintf(stdout, "%lg\t", OrthoVector[axis[i]][j]); 639 639 fprintf(stdout, "\n"); 640 640 } 641 641 642 642 // free memory 643 643 Free(TempAxis, "CreateOrthogonalAxisVectors: *TempAxis"); … … 664 664 // --------------------------------------- M A I N --------------------------------------------------- 665 665 int main(int argc, char **argv) { 666 char *filename = NULL; 666 char *filename = NULL; 667 667 char *CellFilename = NULL, *SheetFilename = NULL, *TubeFilename = NULL, *TorusFilename = NULL; 668 668 char *SheetFilenameAligned = NULL, *TubeFilenameAligned = NULL; … … 678 678 int i,j, ggT; 679 679 int length; 680 681 // Read command line arguments 680 681 // Read command line arguments 682 682 if (argc <= 2) { 683 683 fprintf(stdout, "Usage: %s <file> <stage>\n\tWhere <file> specifies a file to start from <stage> or a basename\n\t<stage> is either None, Cell, Sheet, Tube, Torus and specifies where to start the rolling up from.\n\tNote: The .Aligned. files can't be used (rotation is essential).\n", argv[0]); … … 688 688 strncpy(stage, argv[2], 5); 689 689 fprintf(stdout, "I will begin at stage %s.\n", stage); 690 690 691 691 // build filenames 692 692 char *ptr = strrchr(filename, '.'); 693 693 length = strlen(filename); 694 694 if (ptr != NULL) { 695 length = ((int)(ptr-filename) >= length-5) ? (int)(ptr-filename) : length; 695 length = ((int)(ptr-filename) >= length-5) ? (int)(ptr-filename) : length; 696 696 filename[length] = '\0'; // eventueller 697 697 } … … 710 710 sprintf(TubeFilenameAligned, "%s.Tube.Aligned.xyz", filename); 711 711 } 712 712 713 713 // Allocating memory 714 714 Debug ("Allocating memory\n"); … … 726 726 TubevectorInverse[i] = (double *) Malloc(sizeof(double)*NDIM, "Main: TubevectorInverse"); 727 727 } 728 728 729 729 // ======================== STAGE: Cell ============================== 730 730 // The cell is simply created by transforming relative coordinates within the cell 731 731 // into cartesian ones using the unit cell vectors. 732 732 733 733 double volume; 734 734 int numbercell; … … 740 740 fprintf(stdout, "You will give the unit cell of the given substance.\nAfterwards, the programme will create a Sheet, a Tube and a Torus, each with their own xyz-file named accordingly.\n\n"); 741 741 fprintf(stdout, "Enter 1st primitive vector: "); 742 fscanf(stdin, "%lg %lg %lg", &Vector[0][0], &Vector[0][1], &Vector[0][2]); 742 fscanf(stdin, "%lg %lg %lg", &Vector[0][0], &Vector[0][1], &Vector[0][2]); 743 743 fprintf(stdout, "Enter 2nd primitive vector: "); 744 fscanf(stdin, "%lg %lg %lg", &Vector[1][0], &Vector[1][1], &Vector[1][2]); 744 fscanf(stdin, "%lg %lg %lg", &Vector[1][0], &Vector[1][1], &Vector[1][2]); 745 745 fprintf(stdout, "Enter 3rd primitive vector: "); 746 746 fscanf(stdin, "%lg %lg %lg", &Vector[2][0], &Vector[2][1], &Vector[2][2]); 747 747 fprintf(stdout,"Unit vectors are\n"); 748 PrintMatrix(stdout, Vector); 748 PrintMatrix(stdout, Vector); 749 749 } else { 750 750 char *ptr = NULL; … … 762 762 ptr += strlen(dummy); 763 763 sscanf(ptr, "%lg %lg %lg", &Vector[i][0], &Vector[i][1], &Vector[i][2]); 764 fprintf(stdout, "%5.5lg %5.5lg %5.5lg\n", Vector[i][0], Vector[i][1], Vector[i][2]); 764 fprintf(stdout, "%5.5lg %5.5lg %5.5lg\n", Vector[i][0], Vector[i][1], Vector[i][2]); 765 765 } 766 766 } … … 768 768 volume = Determinant(Vector); 769 769 fprintf(stdout,"Volume is %lg\n", volume); 770 MatrixInversion(Vector, Recivector); 770 MatrixInversion(Vector, Recivector); 771 771 //Transpose(Recivector); // inverse's got row vectors if normal matrix' got column ones 772 772 fprintf(stdout, "Reciprocal vector is "); 773 773 PrintMatrix(stdout, Recivector); 774 774 fprintf(stdout, "Reciprocal volume is %lg\n", Determinant(Recivector)); 775 775 776 776 fprintf(stdout, "Vector magnitudes: %5.5lg %5.5lg %5.5lg\n", Norm(Vector[0]), Norm(Vector[1]), Norm(Vector[2])); 777 777 778 778 Debug ("STAGE: Cell\n"); 779 779 if (!strncmp(stage, "Non", 3)) { … … 793 793 fprintf(stdout, "Atom %i: %s %5.5lg %5.5lg %5.5lg\n", i, name, tempvector[0], tempvector[1], tempvector[2]); 794 794 fprintf(stdout, "Probe: %s %5.5lg %5.5lg %5.5lg\n", name, 795 atom[0]*Vector[0][0]+atom[1]*Vector[1][0]+atom[2]*Vector[2][0], 796 atom[0]*Vector[0][1]+atom[1]*Vector[1][1]+atom[2]*Vector[2][1], 797 atom[0]*Vector[0][2]+atom[1]*Vector[1][2]+atom[2]*Vector[2][2] 795 atom[0]*Vector[0][0]+atom[1]*Vector[1][0]+atom[2]*Vector[2][0], 796 atom[0]*Vector[0][1]+atom[1]*Vector[1][1]+atom[2]*Vector[2][1], 797 atom[0]*Vector[0][2]+atom[1]*Vector[1][2]+atom[2]*Vector[2][2] 798 798 ); 799 799 fprintf(CellFile, "%s %lg %lg %lg\n", name, tempvector[0], tempvector[1], tempvector[2]); … … 805 805 806 806 CellBuffer = ReadBuffer(CellFilename, &length); 807 807 808 808 sprintf(stage, "Cell"); 809 809 } else { … … 812 812 sscanf(line, "%i", &numbercell); 813 813 } 814 814 815 815 fprintf(stdout, "\nThere are %i atoms in the cell.\n", numbercell); 816 816 817 817 // ======================== STAGE: Sheet ============================= 818 818 // The sheet is a bit more complex. We read the cell in cartesian coordinates … … 838 838 FILE *SheetFile = NULL; 839 839 FILE *SheetFileAligned = NULL; 840 840 841 841 Debug ("STAGE: Sheet\n"); 842 842 if (!strncmp(stage, "Cell", 4)) { 843 843 fprintf(stdout, "\nEnter seed unequal 0 if any of the bonds shall have a randomness in their being: "); 844 844 fscanf(stdin, "%d", &seed); 845 if (seed != 0) 845 if (seed != 0) 846 846 input = 'y'; 847 847 randomness = (double *) Malloc(sizeof(double)*numbercell, "Main: at sheet - randomness"); … … 856 856 else { randomness[i] = 1.-percentage; } 857 857 }; 858 858 859 859 fprintf(stdout, "\nSpecify the axis permutation that is going to be perpendicular to the sheet [tubeaxis, torusaxis, noaxis]: "); 860 860 fscanf(stdin, "%d %d %d", &axis[0], &axis[1], &axis[2]); 861 861 fprintf(stdout, "axis: %d %d %d\n", axis[0], axis[1], axis[2]); 862 862 863 863 // create orthogonal vectors individually for each unit cell vector 864 864 CreateOrthogonalAxisVectors(OrthoVector, Vector, axis); … … 866 866 fprintf(stdout, "Orthogonal vector axis[1] %lg\n", Projection(Vector[axis[1]], OrthoVector[axis[1]])); 867 867 868 do { 868 do { 869 869 fprintf(stdout, "\nNow specify the two natural numbers (m n) defining the chiral angle, \nif the result is crap, try flipping to (m,n): "); 870 870 fscanf(stdin, "%d %d", &chiral[0], &chiral[1]); … … 879 879 Tubevector[axis[1]][i] = (double)chiral[0] * OrthoVector[axis[0]][i] - (double)chiral[1] * OrthoVector[axis[1]][i]; 880 880 //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]; 881 // 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", 882 // (double)chiral[0], Vector[axis[0]][i], (double)chiral[1], Vector[axis[1]][i], 883 // (double)chiral[0] * Vector[axis[0]][i], (double)chiral[1] * Vector[axis[1]][i], 881 // 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", 882 // (double)chiral[0], Vector[axis[0]][i], (double)chiral[1], Vector[axis[1]][i], 883 // (double)chiral[0] * Vector[axis[0]][i], (double)chiral[1] * Vector[axis[1]][i], 884 884 // Tubevector[axis[0]][i]); 885 885 Tubevector[axis[2]][i] = Vector[axis[2]][i]; … … 917 917 x1 = gsl_vector_get(u,0)*(double)i; 918 918 x2 = gsl_vector_get(u,1)*(double)i; 919 x3 = 919 x3 = 920 920 fprintf(stdout, "%d: %d\t%d vs. %lg\t%lg\n",i, ((int)(x1+x1/fabs(x1)*.5)), ((int)(x2+x2/fabs(x2)*.5)), (x1), (x2)); 921 921 if (( fabs( ((int)(x1+x1/fabs(x1)*.5)) - (x1) ) < 1e-6) && ( fabs( ((int)(x2+x2/fabs(x2)*.5)) - (x2) ) < 1e-6 )) { … … 956 956 gsl_vector_free(u); 957 957 gsl_eigen_symmv_free(w); 958 958 959 959 if (fabs(x1) > 1e-6) { 960 960 fprintf(stderr,"Resulting TubeVectors of axis %d and %d and not orthogonal, aborting.\n", axis[0], axis[1]); 961 961 return(128); 962 962 } 963 964 963 964 965 965 angle = Projection(Tubevector[axis[1]], Vector[axis[0]]); 966 966 fprintf(stdout, "Projection Tubevector1 axis[0] %lg %lg\n", angle, 1./angle); 967 967 angle = Projection(Tubevector[axis[1]], Vector[axis[1]]); 968 968 fprintf(stdout, "Projection Tubevector1 axis[1] %lg %lg\n", angle, 1./angle); 969 969 970 970 /* fprintf(stdout, "Vector\n"); 971 971 PrintMatrix(stdout, Vector); … … 1006 1006 bufptr += (GetNextline(bufptr, line))*sizeof(char); 1007 1007 sscanf(line, "%d", &numbersheet); 1008 1008 1009 1009 // retrieve axis permutation 1010 1010 sprintf(dummy, "Axis"); … … 1021 1021 ptr += strlen(dummy); 1022 1022 sscanf(ptr, "%d %d %d", &axis[0], &axis[1], &axis[2]); 1023 fprintf(stdout, "%d %d %d\n", axis[0], axis[1], axis[2]); 1024 1023 fprintf(stdout, "%d %d %d\n", axis[0], axis[1], axis[2]); 1024 1025 1025 // retrieve chiral numbers 1026 1026 sprintf(dummy, "(n,m)"); … … 1034 1034 fprintf(stderr, "ERROR: Main at stage Sheet - could not find %s in %s\n", dummy, SheetFilename); 1035 1035 exit(255); 1036 } 1036 } 1037 1037 ptr += strlen(dummy); 1038 1038 sscanf(ptr, "%d %d", &chiral[0], &chiral[1]); 1039 fprintf(stdout, "%d %d\n", chiral[0], chiral[1]); 1039 fprintf(stdout, "%d %d\n", chiral[0], chiral[1]); 1040 1040 ggT = GCD(2*chiral[1]+chiral[0],2*chiral[0]+chiral[1]); 1041 1041 fprintf(stdout, "Greatest Common Denominator of (2n+m, 2m+n) is %d\n", ggT); 1042 1042 1043 1043 // retrieve length and radius factors 1044 1044 sprintf(dummy, "factors"); … … 1055 1055 ptr += strlen(dummy); 1056 1056 sscanf(ptr, "%d %d %d", &factors[0], &factors[1], &factors[2]); 1057 fprintf(stdout, "%d %d %d\n", factors[0], factors[1], factors[2]); 1057 fprintf(stdout, "%d %d %d\n", factors[0], factors[1], factors[2]); 1058 1058 1059 1059 // create orthogonal vectors individually for each unit cell vector … … 1102 1102 x1 = gsl_vector_get(u,0)*(double)i; 1103 1103 x2 = gsl_vector_get(u,1)*(double)i; 1104 x3 = 1104 x3 = 1105 1105 fprintf(stdout, "%d: %d\t%d vs. %lg\t%lg\n",i, ((int)(x1+x1/fabs(x1)*.5)), ((int)(x2+x2/fabs(x2)*.5)), (x1), (x2)); 1106 1106 if (( fabs( ((int)(x1+x1/fabs(x1)*.5)) - (x1) ) < 1e-6) && ( fabs( ((int)(x2+x2/fabs(x2)*.5)) - (x2) ) < 1e-6 )) { … … 1140 1140 gsl_vector_free(v); 1141 1141 gsl_vector_free(u); 1142 gsl_eigen_symmv_free(w); 1142 gsl_eigen_symmv_free(w); 1143 1143 1144 1144 if (fabs(x1) > 1e-6) { … … 1147 1147 } 1148 1148 1149 // retrieve seed ... 1149 // retrieve seed ... 1150 1150 randomness = (double *) Calloc(sizeof(double)*numbercell, 0., "Main: at sheet - randomness"); 1151 1151 sprintf(dummy, "seed"); … … 1159 1159 fprintf(stderr, "ERROR: Main at stage Sheet - could not find %s in %s\n", dummy, SheetFilename); 1160 1160 exit(255); 1161 } 1161 } 1162 1162 ptr += strlen(dummy); 1163 1163 sscanf(ptr, "%d", &seed); 1164 fprintf(stdout, "%d\n", seed); 1164 fprintf(stdout, "%d\n", seed); 1165 1165 1166 1166 // ... and randomness … … 1187 1187 sscanf(line, "%d %lg", &j, &dummydouble); 1188 1188 randomness[j] = dummydouble; 1189 fprintf(stdout, "%d %g\n", j, randomness[j]); 1189 fprintf(stdout, "%d %g\n", j, randomness[j]); 1190 1190 } 1191 1191 } … … 1204 1204 //angle -= acos(Projection(Vector[axis[0]], Tubevector[axis[0]])); 1205 1205 //angle = 30./180.*M_PI - acos(Projection(Vector[axis[0]], Tubevector[axis[0]])); 1206 angle = -acos(Projection(Tubevector[axis[0]], Vector[axis[0]]));1206 //angle = acos(Projection(Tubevector[axis[0]], Vector[axis[0]])); 1207 1207 fprintf(stdout, "The relative alignment rotation angle then is %lg\n", angle/M_PI*180.); 1208 1208 if (fabs(Tubevector[axis[0]][0]) > MYEPSILON) 1209 angle = M_PI/2. -acos(Tubevector[axis[0]][0]/Norm(Tubevector[axis[0]]));1209 angle = -M_PI/2. + acos(Tubevector[axis[0]][0]/Norm(Tubevector[axis[0]])); 1210 1210 else 1211 1211 angle = 0.; … … 1251 1251 sheetnr[j] = sheetnr[j] > tmp ? sheetnr[j] : tmp; 1252 1252 } 1253 } 1253 } 1254 1254 fprintf(stdout, "Maximum indices to regard: %d %d %d\n", sheetnr[0], sheetnr[1], sheetnr[2]); 1255 1255 for (i=0;i<NDIM;i++) { … … 1260 1260 // parse in atoms for quicker processing 1261 1261 struct Atoms *atombuffer = malloc(sizeof(struct Atoms)*numbercell); 1262 bufptr = CellBuffer; 1262 bufptr = CellBuffer; 1263 1263 bufptr += GetNextline(bufptr, line)*sizeof(char); 1264 1264 bufptr += GetNextline(bufptr, line)*sizeof(char); … … 1301 1301 for (nr = 0; nr < numbercell; nr++) { 1302 1302 percentage = rand()/(RAND_MAX+1.0); 1303 //fprintf(stdout, "Lucky number for %d is %lg >? %lg\n", nr, percentage, randomness[nr]); 1303 //fprintf(stdout, "Lucky number for %d is %lg >? %lg\n", nr, percentage, randomness[nr]); 1304 1304 if (percentage >= randomness[nr]) { 1305 1305 // Create coordinates at atom site 1306 1306 coord = VectorAdd(atombuffer[nr].x, offset); 1307 //fprintf(stdout, "Atom Nr. %i: ", (numbersheet+1)); 1307 //fprintf(stdout, "Atom Nr. %i: ", (numbersheet+1)); 1308 1308 //PrintVector(stdout, coord); 1309 1309 // project down on major and minor Tubevectors and check for length if out of sheet … … 1350 1350 //} 1351 1351 SheetBuffer = ReadBuffer(SheetFilename, &length); 1352 1353 1352 1353 1354 1354 // ======================== STAGE: Tube ============================== 1355 1355 // The tube starts with the rectangular (due to the orthogonalization) sheet … … 1365 1365 FILE *TubeFile = NULL; 1366 1366 FILE *TubeFileAligned = NULL; 1367 1367 1368 1368 Debug ("STAGE: Tube\n"); 1369 1369 if (!strncmp(stage, "Sheet", 4)) { … … 1385 1385 //cog_projected = MatrixTrafoInverse(cog, TubevectorInverse); 1386 1386 //fprintf(stdout, "\nCenter of Gravity at (%5.5lg\t%5.5lg\t%5.5lg) and projected at (%5.5lg\t%5.5lg\t%5.5lg)\n", cog[0], cog[1], cog[2], cog_projected[0], cog_projected[1], cog_projected[2]); 1387 1387 1388 1388 // restart 1389 1389 bufptr = SheetBuffer; … … 1395 1395 for (i=0;i<NDIM;i++) 1396 1396 halfaxis[i] = factors[0]*Norm(Tubevector[axis[0]])/Norm(Tubevector[i]); 1397 1398 double arg, radius; 1397 1398 double arg, radius; 1399 1399 for (i=0;i<numbersheet;i++) { 1400 // scan next atom 1400 // scan next atom 1401 1401 bufptr += GetNextline(bufptr, line); 1402 1402 sscanf(line, "%s %lg %lg %lg", name, &atom[0], &atom[1], &atom[2]); … … 1406 1406 //x = VectorAdd(y, cog_projected); 1407 1407 //free(y); 1408 1408 1409 1409 // roll up (project (x,y,z) on cylindrical coordinates (radius,arg,z)) 1410 1410 arg = 2.*M_PI*x[axis[0]]/(factors[0]) - M_PI; // is angle 1411 1411 radius = 1./(2.*M_PI); // is length of sheet in units of axis vector, divide by pi to get radius (from circumference) 1412 1412 // fprintf(stdout, "arg: %5.2f (c%2.2f,s%2.2f)\t",$arg, cos($arg), sin($arg)); 1413 x[axis[0]] = cos(arg)*halfaxis[axis[0]]* radius; //(radius+x[axis[2]]/halfaxis[axis[2]]); // as both vectors are not normalized additional betrag has to be taken into account!1414 x[axis[2]] = sin(arg)*halfaxis[axis[2]]* radius; //(radius+x[axis[2]]/halfaxis[axis[2]]); // due to the back-transformation from eigensystem to cartesian one1413 x[axis[0]] = cos(arg)*halfaxis[axis[0]]*(radius+x[axis[2]]/halfaxis[axis[2]]); // as both vectors are not normalized additional betrag has to be taken into account! 1414 x[axis[2]] = sin(arg)*halfaxis[axis[2]]*(radius+x[axis[2]]/halfaxis[axis[2]]); // due to the back-transformation from eigensystem to cartesian one 1415 1415 //fprintf(stdout, "rotated: (%5.2f,%5.2f,%5.2f)\n",x[0],x[1],x[2]); 1416 1416 atom_transformed = MatrixTrafo(Tubevector, x); … … 1423 1423 //fprintf(stdout, "%s\t%5.5lg\t%5.5lg\t%5.5lg\n", name, atom_transformed[0], atom_transformed[1] ,atom_transformed[2]); 1424 1424 1425 Free(x, "Main: at stage Tube - x"); 1425 Free(x, "Main: at stage Tube - x"); 1426 1426 Free(atom_transformed, "Main: at stage Tube - atom_transformed"); 1427 1427 } 1428 1428 1429 1429 1430 1430 fclose(TubeFile); 1431 1431 fclose(TubeFileAligned); … … 1436 1436 AddSheetInfo(TubeFilename,axis,chiral, factors, seed, numbercell, randomness); 1437 1437 fprintf(stdout, "\nThere are %i atoms in the created tube.\n", numbersheet); 1438 1438 1439 1439 strncpy(stage, "Tube", 4); 1440 1440 } else { … … 1454 1454 1455 1455 FILE *TorusFile; 1456 1456 1457 1457 Debug ("STAGE: Torus\n"); 1458 1458 if (!strncmp(stage, "Tube", 4)) { … … 1465 1465 bufptr += GetNextline(bufptr, line); // write numbers to file 1466 1466 bufptr += GetNextline(bufptr, line); // write comment to file 1467 1467 1468 1468 //cog = CenterOfGravity(bufptr, numbersheet); 1469 1469 //cog_projected = MatrixTrafoInverse(cog, TubevectorInverse); 1470 1470 //fprintf(stdout, "\nCenter of Gravity at (%5.5lg\t%5.5lg\t%5.5lg) and projected at (%5.5lg\t%5.5lg\t%5.5lg)\n", cog[0], cog[1], cog[2], cog_projected[0], cog_projected[1], cog_projected[2]); 1471 1471 1472 1472 // determine half axis as tube vectors not necessarily have same length 1473 1473 double halfaxis[NDIM]; 1474 1474 for (i=0;i<NDIM;i++) 1475 1475 halfaxis[i] = Norm(Tubevector[axis[1]])/Norm(Tubevector[i]); 1476 1477 double arg, radius; 1476 1477 double arg, radius; 1478 1478 for (i=0;i<numbersheet;i++) { 1479 // scan next atom 1479 // scan next atom 1480 1480 bufptr += GetNextline(bufptr, line); 1481 1481 sscanf(line, "%s %lg %lg %lg", name, &atom[0], &atom[1], &atom[2]); … … 1485 1485 //x = VectorAdd(y, cog_projected); 1486 1486 //free(y); 1487 1487 1488 1488 // roll up (project (x,y,z) on cylindrical coordinates (radius,arg,z)) 1489 1489 arg = 2.*M_PI*x[axis[1]]/(factors[1]) - M_PI; // is angle … … 1497 1497 //fprintf(stdout, "%s\t%5.5lg\t%5.5lg\t%5.5lg\n", name, atom_transformed[0], atom_transformed[1] ,atom_transformed[2]); 1498 1498 1499 Free(x, "Main: at stage Torus - x"); 1499 Free(x, "Main: at stage Torus - x"); 1500 1500 Free(atom_transformed, "Main: at stage Torus - atom_transformed"); 1501 1501 } 1502 1502 1503 1503 fclose(TorusFile); 1504 1504 //free(cog); … … 1536 1536 Free(SheetFilenameAligned, "Main: end of stafes - CellFilename"); 1537 1537 Free(TubeFilenameAligned, "Main: end of stafes - CellFilename"); 1538 1538 1539 1539 // exit 1540 1540 exit(0);
Note:
See TracChangeset
for help on using the changeset viewer.
