Changes in / [8a3e45:d250b2]
- Location:
- src
- Files:
-
- 2 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Makefile.am
r8a3e45 rd250b2 1 SOURCE = atom.cpp bond.cpp b oundary.cpp builder.cpp config.cpp element.cpp helpers.cpp molecules.cpp moleculelist.cpp periodentafel.cpp vector.cpp verbose.cpp2 HEADER = boundary.hppdefs.hpp helpers.hpp molecules.hpp stackclass.hpp vector.hpp1 SOURCE = atom.cpp bond.cpp builder.cpp config.cpp element.cpp helpers.cpp molecules.cpp moleculelist.cpp periodentafel.cpp vector.cpp verbose.cpp 2 HEADER = defs.hpp helpers.hpp molecules.hpp stackclass.hpp vector.hpp 3 3 4 4 bin_PROGRAMS = molecuilder joiner analyzer -
src/builder.cpp
r8a3e45 rd250b2 52 52 #include "helpers.hpp" 53 53 #include "molecules.hpp" 54 #include "boundary.hpp"55 54 56 55 /********************************************** Submenu routine **************************************/ … … 485 484 * \param *mol the molecule with all the atoms 486 485 */ 487 static void MeasureAtoms(periodentafel *periode, molecule *mol , config *configuration)486 static void MeasureAtoms(periodentafel *periode, molecule *mol) 488 487 { 489 488 atom *first, *second, *third; … … 497 496 cout << Verbose(0) << " b - calculate bond length between two atoms" << endl; 498 497 cout << Verbose(0) << " c - calculate bond angle" << endl; 499 cout << Verbose(0) << " d - calculate principal axis of the system" << endl;500 cout << Verbose(0) << " e - calculate volume of the convex envelope" << endl;501 498 cout << Verbose(0) << "all else - go back" << endl; 502 499 cout << Verbose(0) << "===============================================" << endl; … … 556 553 cout << Verbose(0) << (acos(x.ScalarProduct((const vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl; 557 554 break; 558 case 'd':559 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;560 cout << Verbose(0) << "Shall we rotate? [0/1]: ";561 cin >> Z;562 if ((Z >=0) && (Z <=1))563 mol->PrincipalAxisSystem((ofstream *)&cout, (bool)Z);564 else565 mol->PrincipalAxisSystem((ofstream *)&cout, false);566 break;567 case 'e':568 cout << Verbose(0) << "Evaluating volume of the convex envelope.";569 VolumeOfConvexEnvelope((ofstream *)&cout, configuration, NULL, mol);570 break;571 555 } 572 556 }; … … 736 720 int ExitFlag = 0; 737 721 int j; 738 double volume = 0.;739 722 enum ConfigStatus config_present = absent; 740 723 clock_t start,end; … … 759 742 cout << "\t-b x1 x2 x3\tCenter atoms in domain with given edge lengths of (x1,x2,x3)." << endl; 760 743 cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl; 761 cout << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl;762 744 cout << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl; 763 745 cout << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner and stores config files in same dir as config." << endl; 764 746 cout << "\t-h/-H/-?\tGive this help screen." << endl; 765 cout << "\t-m\tAlign in PAS with greatest EV along z axis." << endl;766 cout << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;767 cout << "\t-o\tGet volume of the convex envelope (and store to tecplot file)." << endl;768 747 cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl; 769 748 cout << "\t-r\t\tConvert file from an old pcp syntax." << endl; 770 749 cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl; 771 750 cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl; 772 cout << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl;773 751 cout << "\t-v/-V\t\tGives version information." << endl; 774 752 cout << "Note: config files must not begin with '-' !" << endl; … … 790 768 argptr+=1; 791 769 break; 792 case 'n':793 cout << "I won't parse trajectories." << endl;794 configuration.FastParsing = true;795 770 default: // no match? Step on 796 771 argptr++; … … 805 780 cout << Verbose(0) << "Element list loaded successfully." << endl; 806 781 periode->Output((ofstream *)&cout); 807 } else {782 } else 808 783 cout << Verbose(0) << "Element list loading failed." << endl; 809 return 1;810 }811 784 812 785 // 3. Find config file name and parse if possible … … 972 945 } 973 946 break; 974 case 'm':975 ExitFlag = 1;976 j = atoi(argv[argptr++]);977 if ((j<0) || (j>1)) {978 cerr << Verbose(1) << "ERROR: Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl;979 j = 0;980 }981 if (j)982 cout << Verbose(0) << "Converting to prinicipal axis system." << endl;983 else984 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;985 mol->PrincipalAxisSystem((ofstream *)&cout, (bool)j);986 break;987 case 'o':988 ExitFlag = 1;989 cout << Verbose(0) << "Evaluating volume of the convex envelope.";990 VolumeOfConvexEnvelope((ofstream *)&cout, &configuration, NULL, mol);991 break;992 case 'U':993 volume = atof(argv[argptr++]);994 cout << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl;995 case 'u':996 {997 double density;998 ExitFlag = 1;999 cout << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.";1000 density = atof(argv[argptr++]);1001 if (density < 1.0) {1002 cerr << Verbose(0) << "Density must be greater than 1.0g/cm^3 !" << endl;1003 density = 1.3;1004 }1005 // for(int i=0;i<NDIM;i++) {1006 // repetition[i] = atoi(argv[argptr++]);1007 // if (repetition[i] < 1)1008 // cerr << Verbose(0) << "ERROR: repetition value must be greater 1!" << endl;1009 // repetition[i] = 1;1010 // }1011 PrepareClustersinWater((ofstream *)&cout, &configuration, mol, volume, density);1012 }1013 break;1014 case 'd':1015 for (int axis = 1; axis <= NDIM; axis++) {1016 int faktor = atoi(argv[argptr++]);1017 int count;1018 element ** Elements;1019 vector ** Vectors;1020 if (faktor < 1) {1021 cerr << Verbose(0) << "ERROR: Repetition faktor mus be greater than 1!" << endl;1022 faktor = 1;1023 }1024 mol->CountAtoms((ofstream *)&cout); // recount atoms1025 if (mol->AtomCount != 0) { // if there is more than none1026 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand1027 Elements = new element *[count];1028 Vectors = new vector *[count];1029 j = 0;1030 first = mol->start;1031 while (first->next != mol->end) { // make a list of all atoms with coordinates and element1032 first = first->next;1033 Elements[j] = first->type;1034 Vectors[j] = &first->x;1035 j++;1036 }1037 if (count != j)1038 cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;1039 x.Zero();1040 y.Zero();1041 y.x[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude1042 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times1043 x.AddVector(&y); // per factor one cell width further1044 for (int k=count;k--;) { // go through every atom of the original cell1045 first = new atom(); // create a new body1046 first->x.CopyVector(Vectors[k]); // use coordinate of original atom1047 first->x.AddVector(&x); // translate the coordinates1048 first->type = Elements[k]; // insert original element1049 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)1050 }1051 }1052 // free memory1053 delete[](Elements);1054 delete[](Vectors);1055 // correct cell size1056 if (axis < 0) { // if sign was negative, we have to translate everything1057 x.Zero();1058 x.AddVector(&y);1059 x.Scale(-(faktor-1));1060 mol->Translate(&x);1061 }1062 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;1063 }1064 }1065 break;1066 947 default: // no match? Step on 1067 if (argv[argptr][0] != '-') // if it started with a '-' we've already made a step! 1068 argptr++; 948 argptr++; 1069 949 break; 1070 950 } … … 1271 1151 1272 1152 case 'l': // measure distances or angles 1273 MeasureAtoms(periode, mol , &configuration);1153 MeasureAtoms(periode, mol); 1274 1154 break; 1275 1155 … … 1284 1164 mol->CreateAdjacencyList((ofstream *)&cout, tmp1, configuration.GetIsAngstroem()); 1285 1165 //mol->CreateListOfBondsPerAtom((ofstream *)&cout); 1286 Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);1166 Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, false, MinimumRingSize); 1287 1167 while (Subgraphs->next != NULL) { 1288 1168 Subgraphs = Subgraphs->next; … … 1340 1220 1341 1221 // save element data base 1342 if (periode->StorePeriodentafel( ElementsFileName)) //ElementsFileName1222 if (periode->StorePeriodentafel()) //ElementsFileName 1343 1223 cout << Verbose(0) << "Saving of elements.db successful." << endl; 1344 1224 else -
src/config.cpp
r8a3e45 rd250b2 24 24 configname[0]='\0'; 25 25 26 FastParsing = false;27 26 ProcPEGamma=8; 28 27 ProcPEPsi=1; … … 456 455 string zeile; 457 456 string dummy; 458 element *elementhash[ MAX_ELEMENTS];459 char name[ MAX_ELEMENTS];460 char keyword[ MAX_ELEMENTS];461 int Z, No [MAX_ELEMENTS];457 element *elementhash[128]; 458 char name[128]; 459 char keyword[128]; 460 int Z, No; 462 461 int verbose = 0; 463 462 … … 633 632 if (!ParseForParameter(verbose,file,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional)) 634 633 config::StructOpt = 0; 635 // prescan number of ions per type636 cout << Verbose(0) << "Prescanning ions per type: " << endl;637 634 for (int i=0; i < config::MaxTypes; i++) { 638 635 sprintf(name,"Ion_Type%i",i+1); 639 ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No [i], 1, critical);636 ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No, 1, critical); 640 637 ParseForParameter(verbose,file, name, 0, 2, 1, int_type, &Z, 1, critical); 641 638 elementhash[i] = periode->FindElement(Z); 642 cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl; 643 } 644 for (int i=0; i < config::MaxTypes; i++) { 645 sprintf(name,"Ion_Type%i",i+1); 646 for(int j=0;j<No[i];j++) { 639 for(int j=0;j<No;j++) { 647 640 int repetition = 1; // which repeated keyword shall be read 648 641 sprintf(keyword,"%s_%i",name, j+1); 649 642 atom *neues = new atom(); 650 643 // then parse for each atom the coordinates as often as present 651 if (!FastParsing) { 652 while (ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition, (repetition == 1) ? critical : optional) && 653 ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition, (repetition == 1) ? critical : optional) && 654 ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition, (repetition == 1) ? critical : optional)) 655 repetition++; 656 repetition--; 657 //cout << "Found " << repetition << " times of the keyword " << keyword << "." << endl; 658 } 644 while (ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition, (repetition == 1) ? critical : optional) && 645 ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition, (repetition == 1) ? critical : optional) && 646 ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition, (repetition == 1) ? critical : optional)) 647 repetition++; 648 repetition--; 649 //cout << "Found " << repetition << " times of the keyword " << keyword << "." << endl; 659 650 ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical); 660 651 ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical); … … 665 656 if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional)) 666 657 neues->v.x[1] = 0.; 667 if(!ParseForParameter(verbose,file, keyword, (int)FastParsing, 7, 1, double_type, &neues->v.x[2], repetition,optional))658 if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional)) 668 659 neues->v.x[2] = 0.; 669 660 neues->type = elementhash[i]; // find element type -
src/defs.hpp
r8a3e45 rd250b2 43 43 44 44 // various standard filenames 45 #define DEFAULTCONFIG "main_pcp_linux" //!< default filename of config file 46 #define CONVEXENVELOPE "ConvexEnvelope.dat" //!< default filename of convex envelope tecplot data file 47 #define KEYSETFILE "KeySets.dat" //!< default filename of BOSSANOVA key sets file 48 #define ADJACENCYFILE "Adjacency.dat" //!< default filename of BOSSANOVA adjacancy file 49 #define TEFACTORSFILE "TE-Factors.dat" //!< default filename of BOSSANOVA total energy factors file 50 #define FORCESFILE "Forces-Factors.dat" //!< default filename of BOSSANOVA force factors file 51 #define ORDERATSITEFILE "OrderAtSite.dat" //!< default filename of BOSSANOVA Bond Order at each atom file 52 #define ENERGYPERFRAGMENT "EnergyPerFragment" //!< default filename of BOSSANOVA Energy contribution Per Fragment file 53 #define FRAGMENTPREFIX "BondFragment" //!< default filename prefix of BOSSANOVA fragment config and directories 54 #define STANDARDCONFIG "unknown.conf" //!< default filename of standard config file 55 #define STANDARDELEMENTSDB "elements.db" //!< default filename of elements data base with masses, Z, VanDerWaals radii, ... 56 #define STANDARDVALENCEDB "valence.db" //!< default filename of valence number per element database 57 #define STANDARDORBITALDB "orbitals.db" //!< default filename of orbitals per element database 58 #define STANDARDHBONDDISTANCEDB "Hbonddistance.db" //!< default filename of typial bond distance to hydrogen database 59 #define STANDARDHBONDANGLEDB "Hbondangle.db" //!< default filename of typial bond angle to hydrogen database 60 61 // some values 62 #define SOLVENTDENSITY_A 0.6022142 63 #define SOLVENTDENSITY_a0 0.089238936 64 45 #define DEFAULTCONFIG "main_pcp_linux" 46 #define KEYSETFILE "KeySets.dat" 47 #define ADJACENCYFILE "Adjacency.dat" 48 #define TEFACTORSFILE "TE-Factors.dat" 49 #define FORCESFILE "Forces-Factors.dat" 50 #define ORDERATSITEFILE "OrderAtSite.dat" 51 #define ENERGYPERFRAGMENT "EnergyPerFragment" 52 #define FRAGMENTPREFIX "BondFragment" 53 #define STANDARDCONFIG "unknown.conf" 54 #define STANDARDELEMENTSDB "elements.db" 55 #define STANDARDVALENCEDB "valence.db" 56 #define STANDARDORBITALDB "orbitals.db" 57 #define STANDARDHBONDDISTANCEDB "Hbonddistance.db" 58 #define STANDARDHBONDANGLEDB "Hbondangle.db" 65 59 66 60 #define UPDATECOUNT 10 //!< update ten sites per BOSSANOVA interval -
src/helpers.hpp
r8a3e45 rd250b2 118 118 }; 119 119 120 121 120 122 /******************************** Some templates for list management ***********************************/ 121 123 -
src/moleculelist.cpp
r8a3e45 rd250b2 240 240 *out << endl; 241 241 // prepare output of config file 242 sprintf(FragmentName, "%s/%s%s.conf", PathBackup, FRAGMENTPREFIX, FragmentNumber);242 sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); 243 243 outputFragment.open(FragmentName, ios::out); 244 //strcpy(PathBackup, configuration->configpath);245 sprintf(FragmentName, "%s/%s%s/", PathBackup, FRAGMENTPREFIX, FragmentNumber);244 strcpy(PathBackup, configuration->configpath); 245 sprintf(FragmentName, "%s/%s%s/", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); 246 246 247 247 // center on edge … … 251 251 for (int k=0;k<NDIM;k++) { 252 252 j += k+1; 253 BoxDimension.x[k] = 2.5* (configuration->GetIsAngstroem() ? 1. : 1./AtomicLengthToAngstroem);253 BoxDimension.x[k] = 5.; 254 254 ListOfMolecules[i]->cell_size[j] += BoxDimension.x[k]*2.; 255 255 } -
src/molecules.cpp
r8a3e45 rd250b2 179 179 bond *FirstBond = NULL, *SecondBond = NULL; // Other bonds in double bond case to determine "other" plane 180 180 atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added 181 int i; // loop variable 181 182 double b,l,d,f,g, alpha, factors[NDIM]; // hold temporary values in triple bond case for coordination determination 182 183 vector OrthoVector1, OrthoVector2; // temporary vectors in coordination construction … … 252 253 case 2: 253 254 // determine two other bonds (warning if there are more than two other) plus valence sanity check 254 for (i nt i=0;i<NumBond;i++) {255 for (i=0;i<NumBond;i++) { 255 256 if (BondList[i] != TopBond) { 256 257 if (FirstBond == NULL) { … … 311 312 FirstOtherAtom->x.Zero(); 312 313 SecondOtherAtom->x.Zero(); 313 for(i nt i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondVector is bondangle = 0 direction)314 for(i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondVector is bondangle = 0 direction) 314 315 FirstOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (sin(bondangle)); 315 316 SecondOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (-sin(bondangle)); … … 318 319 SecondOtherAtom->x.Scale(&BondRescale); 319 320 //*out << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl; 320 for(i nt i=NDIM;i--;) { // and make relative to origin atom321 for(i=NDIM;i--;) { // and make relative to origin atom 321 322 FirstOtherAtom->x.x[i] += TopOrigin->x.x[i]; 322 323 SecondOtherAtom->x.x[i] += TopOrigin->x.x[i]; … … 438 439 int NumberOfAtoms = 0; // atom number in xyz read 439 440 int i, j; // loop variables 440 atom * Walker= NULL; // pointer to added atom441 atom *first = NULL; // pointer to added atom 441 442 char shorthand[3]; // shorthand for atom name 442 443 ifstream xyzfile; // xyz file … … 456 457 457 458 for(i=0;i<NumberOfAtoms;i++){ 458 Walker= new atom;459 first = new atom; 459 460 getline(xyzfile,line,'\n'); 460 461 istringstream *item = new istringstream(line); … … 465 466 *item >> x[1]; 466 467 *item >> x[2]; 467 Walker->type = elemente->FindElement(shorthand);468 if ( Walker->type == NULL) {468 first->type = elemente->FindElement(shorthand); 469 if (first->type == NULL) { 469 470 cerr << "Could not parse the element at line: '" << line << "', setting to H."; 470 Walker->type = elemente->FindElement(1);471 first->type = elemente->FindElement(1); 471 472 } 472 473 for(j=NDIM;j--;) 473 Walker->x.x[j] = x[j];474 AddAtom( Walker); // add to molecule474 first->x.x[j] = x[j]; 475 AddAtom(first); // add to molecule 475 476 delete(item); 476 477 } … … 709 710 }; 710 711 711 /** Returns vector pointing to center of gravity.712 /** Centers the center of gravity of the atoms at (0,0,0). 712 713 * \param *out output stream for debugging 713 * \return pointer to center of gravity vector 714 */ 715 vector * molecule::DetermineCenterOfGravity(ofstream *out) 716 { 717 atom *ptr = start->next; // start at first in list 718 vector *a = new vector(); 719 vector tmp; 714 * \param *center return vector for translation vector 715 */ 716 void molecule::CenterGravity(ofstream *out, vector *center) 717 { 720 718 double Num = 0; 721 722 a->Zero(); 723 719 atom *ptr = start->next; // start at first in list 720 vector tmp; 721 722 for(int i=NDIM;i--;) // zero center vector 723 center->x[i] = 0.; 724 724 725 if (ptr != end) { //list not empty? 725 726 while (ptr->next != end) { // continue with second if present … … 728 729 tmp.CopyVector(&ptr->x); 729 730 tmp.Scale(ptr->type->mass); // scale by mass 730 a->AddVector(&tmp); 731 } 732 a->Scale(-1./Num); // divide through total mass (and sign for direction) 733 } 734 *out << Verbose(1) << "Resulting center of gravity: "; 735 a->Output(out); 736 *out << endl; 737 return a; 738 }; 739 740 /** Centers the center of gravity of the atoms at (0,0,0). 741 * \param *out output stream for debugging 742 * \param *center return vector for translation vector 743 */ 744 void molecule::CenterGravity(ofstream *out, vector *center) 745 { 746 if (center == NULL) { 747 DetermineCenter(*center); 748 Translate(center); 749 delete(center); 750 } else { 731 center->AddVector(&tmp); 732 } 733 center->Scale(-1./Num); // divide through total mass (and sign for direction) 751 734 Translate(center); 752 735 } … … 792 775 }; 793 776 794 /** Determines center of molecule(yet not considering atom masses).795 * \param Center reference to return vector796 */ 797 void molecule::DetermineCenter (vector &Center)777 /** Determines center of gravity (yet not considering atom masses). 778 * \param CenterOfGravity reference to return vector 779 */ 780 void molecule::DetermineCenterOfGravity(vector &CenterOfGravity) 798 781 { 799 782 atom *Walker = start; … … 805 788 806 789 do { 807 Center .Zero();790 CenterOfGravity.Zero(); 808 791 flag = true; 809 792 while (Walker->next != end) { … … 832 815 TestVector.AddVector(&TranslationVector); 833 816 TestVector.MatrixMultiplication(matrix); 834 Center .AddVector(&TestVector);817 CenterOfGravity.AddVector(&TestVector); 835 818 cout << Verbose(1) << "Vector is: "; 836 819 TestVector.Output((ofstream *)&cout); … … 845 828 TestVector.AddVector(&TranslationVector); 846 829 TestVector.MatrixMultiplication(matrix); 847 Center .AddVector(&TestVector);830 CenterOfGravity.AddVector(&TestVector); 848 831 cout << Verbose(1) << "Hydrogen Vector is: "; 849 832 TestVector.Output((ofstream *)&cout); … … 855 838 } 856 839 } while (!flag); 857 Free((void **)&matrix, "molecule::DetermineCenter: *matrix"); 858 Center.Scale(1./(double)AtomCount); 859 }; 860 861 /** Transforms/Rotates the given molecule into its principal axis system. 862 * \param *out output stream for debugging 863 * \param DoRotate whether to rotate (true) or only to determine the PAS. 864 */ 865 void molecule::PrincipalAxisSystem(ofstream *out, bool DoRotate) 866 { 867 atom *ptr = start; // start at first in list 868 double InertiaTensor[NDIM*NDIM]; 869 vector *CenterOfGravity = DetermineCenterOfGravity(out); 870 871 CenterGravity(out, CenterOfGravity); 872 873 // reset inertia tensor 874 for(int i=0;i<NDIM*NDIM;i++) 875 InertiaTensor[i] = 0.; 876 877 // sum up inertia tensor 878 while (ptr->next != end) { 879 ptr = ptr->next; 880 vector x; 881 x.CopyVector(&ptr->x); 882 //x.SubtractVector(CenterOfGravity); 883 InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]); 884 InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]); 885 InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]); 886 InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]); 887 InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]); 888 InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]); 889 InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]); 890 InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]); 891 InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]); 892 } 893 // print InertiaTensor for debugging 894 *out << "The inertia tensor is:" << endl; 895 for(int i=0;i<NDIM;i++) { 896 for(int j=0;j<NDIM;j++) 897 *out << InertiaTensor[i*NDIM+j] << " "; 898 *out << endl; 899 } 900 *out << endl; 901 902 // diagonalize to determine principal axis system 903 gsl_eigen_symmv_workspace *T = gsl_eigen_symmv_alloc(NDIM); 904 gsl_matrix_view m = gsl_matrix_view_array(InertiaTensor, NDIM, NDIM); 905 gsl_vector *eval = gsl_vector_alloc(NDIM); 906 gsl_matrix *evec = gsl_matrix_alloc(NDIM, NDIM); 907 gsl_eigen_symmv(&m.matrix, eval, evec, T); 908 gsl_eigen_symmv_free(T); 909 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC); 910 911 for(int i=0;i<NDIM;i++) { 912 *out << Verbose(1) << "eigenvalue = " << gsl_vector_get(eval, i); 913 *out << ", eigenvector = (" << evec->data[i * evec->tda + 0] << "," << evec->data[i * evec->tda + 1] << "," << evec->data[i * evec->tda + 2] << ")" << endl; 914 } 915 916 // check whether we rotate or not 917 if (DoRotate) { 918 *out << Verbose(1) << "Transforming molecule into PAS ... "; 919 // the eigenvectors specify the transformation matrix 920 ptr = start; 921 while (ptr->next != end) { 922 ptr = ptr->next; 923 ptr->x.MatrixMultiplication(evec->data); 924 } 925 *out << "done." << endl; 926 927 // summing anew for debugging (resulting matrix has to be diagonal!) 928 // reset inertia tensor 929 for(int i=0;i<NDIM*NDIM;i++) 930 InertiaTensor[i] = 0.; 931 932 // sum up inertia tensor 933 ptr = start; 934 while (ptr->next != end) { 935 ptr = ptr->next; 936 vector x; 937 x.CopyVector(&ptr->x); 938 //x.SubtractVector(CenterOfGravity); 939 InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]); 940 InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]); 941 InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]); 942 InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]); 943 InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]); 944 InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]); 945 InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]); 946 InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]); 947 InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]); 948 } 949 // print InertiaTensor for debugging 950 *out << "The inertia tensor is:" << endl; 951 for(int i=0;i<NDIM;i++) { 952 for(int j=0;j<NDIM;j++) 953 *out << InertiaTensor[i*NDIM+j] << " "; 954 *out << endl; 955 } 956 *out << endl; 957 } 958 959 // free everything 960 delete(CenterOfGravity); 961 gsl_vector_free(eval); 962 gsl_matrix_free(evec); 840 Free((void **)&matrix, "molecule::DetermineCenterOfGravity: *matrix"); 841 CenterOfGravity.Scale(1./(double)AtomCount); 963 842 }; 964 843 … … 1355 1234 if ((Binder->next != last) && (Binder->next->Type == Undetermined)) { 1356 1235 *out << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl; 1357 Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);1236 Subgraphs = DepthFirstSearchAnalysis(out, false, MinimumRingSize); 1358 1237 while (Subgraphs->next != NULL) { 1359 1238 Subgraphs = Subgraphs->next; … … 1370 1249 return No; 1371 1250 }; 1251 1372 1252 /** Returns Shading as a char string. 1373 1253 * \param color the Shading … … 1573 1453 for(j=0;j<NumberOfBondsPerAtom[Walker->nr];j++) 1574 1454 NoBonds += ListOfBondsPerAtom[Walker->nr][j]->BondDegree; 1575 *out << Verbose(3) << "Walker: " << (int)Walker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;1455 //*out << Verbose(3) << "Walker: " << (int)Walker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl; 1576 1456 if ((int)(Walker->type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check NoBonds of other atom 1577 1457 // count valence of second partner … … 1579 1459 for(j=0;j<NumberOfBondsPerAtom[OtherWalker->nr];j++) 1580 1460 NoBonds += ListOfBondsPerAtom[OtherWalker->nr][j]->BondDegree; 1581 *out << Verbose(3) << "OtherWalker: " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;1461 //*out << Verbose(3) << "OtherWalker: " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl; 1582 1462 if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) // increase bond degree by one 1583 1463 ListOfBondsPerAtom[Walker->nr][i]->BondDegree++; … … 1591 1471 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << "." << endl; 1592 1472 1593 // output bonds for debugging (if bond chain list was correctly installed)1594 *out << Verbose(1) << endl << "From contents of bond chain list:";1595 bond *Binder = first;1596 while(Binder->next != last) {1597 Binder = Binder->next;1598 *out << *Binder << "\t" << endl;1599 }1600 *out << endl;1473 // // output bonds for debugging (if bond chain list was correctly installed) 1474 // *out << Verbose(1) << endl << "From contents of bond chain list:"; 1475 // bond *Binder = first; 1476 // while(Binder->next != last) { 1477 // Binder = Binder->next; 1478 // *out << *Binder << "\t" << endl; 1479 // } 1480 // *out << endl; 1601 1481 } else 1602 1482 *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl; … … 1610 1490 * We use the algorithm from [Even, Graph Algorithms, p.62]. 1611 1491 * \param *out output stream for debugging 1492 * \param ReturnStack true - return pointer to atom stack of separable components, false - return NULL 1612 1493 * \param *&MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found 1613 1494 * \return list of each disconnected subgraph as an individual molecule class structure 1614 1495 */ 1615 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize)1496 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, bool ReturnStack, int *&MinimumRingSize) 1616 1497 { 1617 1498 class StackClass<atom *> *AtomStack; … … 2125 2006 * \param *path path to file 2126 2007 * \param *FragmentList empty, filled on return 2008 * \param IsAngstroem whether we have Ansgtroem or bohrradius 2127 2009 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL) 2128 2010 */ 2129 bool molecule::ParseKeySetFile(ofstream *out, char *path, Graph *&FragmentList )2011 bool molecule::ParseKeySetFile(ofstream *out, char *path, Graph *&FragmentList, bool IsAngstroem) 2130 2012 { 2131 2013 bool status = true; … … 2304 2186 { 2305 2187 ifstream File; 2306 stringstream filename;2188 stringstream line; 2307 2189 bool status = true; 2308 2190 char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer"); 2309 2191 2310 filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;2311 File.open( filename.str().c_str(), ios::out);2192 line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE; 2193 File.open(line.str().c_str(), ios::out); 2312 2194 *out << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... "; 2313 2195 if (File != NULL) { … … 2611 2493 2612 2494 // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===== 2613 Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);2495 Subgraphs = DepthFirstSearchAnalysis(out, false, MinimumRingSize); 2614 2496 // fill the bond structure of the individually stored subgraphs 2615 2497 Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms 2616 2498 2617 2499 // ===== 3. if structure still valid, parse key set file and others ===== 2618 FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList );2500 FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList, configuration->GetIsAngstroem()); 2619 2501 2620 2502 // ===== 4. check globally whether there's something to do actually (first adaptivity check) … … 3131 3013 // *out << ", who has no son in this fragment molecule." << endl; 3132 3014 #ifdef ADDHYDROGEN 3133 //*out << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;3015 // *out << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl; 3134 3016 Leaf->AddHydrogenReplacementAtom(out, ListOfBondsPerAtom[FatherOfRunner->nr][i], Runner, FatherOfRunner, OtherFather, ListOfBondsPerAtom[FatherOfRunner->nr],NumberOfBondsPerAtom[FatherOfRunner->nr], IsAngstroem); 3135 3017 #endif … … 3539 3421 KeyStack AtomStack; 3540 3422 atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::PowerSetGenerator: **PredecessorList"); 3423 KeySet::iterator runner; 3541 3424 int RootKeyNr = FragmentSearch.Root->nr; 3542 3425 int Counter = FragmentSearch.FragmentCounter; … … 3933 3816 { 3934 3817 Graph ***FragmentLowerOrdersList = NULL; 3935 int NumLevels, NumMolecules, TotalNumMolecules = 0, *NumMoleculesOfOrder = NULL;3936 int counter = 0 , Order;3818 int Order, NumLevels, NumMolecules, TotalNumMolecules = 0, *NumMoleculesOfOrder = NULL; 3819 int counter = 0; 3937 3820 int UpgradeCount = RootStack.size(); 3938 3821 KeyStack FragmentRootStack; … … 3948 3831 3949 3832 // initialise the fragments structure 3833 FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList"); 3834 FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount"); 3950 3835 FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList"); 3951 3836 FragmentSearch.Labels = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *Labels"); … … 4174 4059 if (result) { 4175 4060 *out << Verbose(5) << "Calculating Centers of Gravity" << endl; 4176 DetermineCenter (CenterOfGravity);4177 OtherMolecule->DetermineCenter (OtherCenterOfGravity);4061 DetermineCenterOfGravity(CenterOfGravity); 4062 OtherMolecule->DetermineCenterOfGravity(OtherCenterOfGravity); 4178 4063 *out << Verbose(5) << "Center of Gravity: "; 4179 4064 CenterOfGravity.Output(out); -
src/molecules.hpp
r8a3e45 rd250b2 13 13 #include <gsl/gsl_vector.h> 14 14 #include <gsl/gsl_matrix.h> 15 #include <gsl/gsl_eigen.h>16 15 #include <gsl/gsl_heapsort.h> 17 16 … … 40 39 #define KeySet set<int> 41 40 #define NumberValuePair pair<int, double> 42 #define Graph map 43 #define GraphPair pair 41 #define Graph map<KeySet, NumberValuePair, KeyCompare > 42 #define GraphPair pair<KeySet, NumberValuePair > 44 43 #define KeySetTestPair pair<KeySet::iterator, bool> 45 44 #define GraphTestPair pair<Graph::iterator, bool> … … 266 265 void CenterEdge(ofstream *out, vector *max); 267 266 void CenterOrigin(ofstream *out, vector *max); 268 void CenterGravity(ofstream *out, vector *max); 267 void CenterGravity(ofstream *out, vector *max); 269 268 void Translate(const vector *x); 270 269 void Mirror(const vector *x); 271 270 void Align(vector *n); 272 271 void Scale(double **factor); 273 void DetermineCenter(vector ¢er); 274 vector * DetermineCenterOfGravity(ofstream *out); 272 void DetermineCenterOfGravity(vector &CenterOfGravity); 275 273 void SetBoxDimension(vector *dim); 276 274 double * ReturnFullMatrixforSymmetric(double *cell_size); 277 275 void ScanForPeriodicCorrection(ofstream *out); 278 void PrincipalAxisSystem(ofstream *out, bool DoRotate); 279 double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem); 280 276 281 277 bool CheckBounds(const vector *x) const; 282 278 void GetAlignVector(struct lsq_params * par) const; … … 287 283 288 284 // Graph analysis 289 MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize);285 MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, bool ReturnStack, int *&MinimumRingSize); 290 286 void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize); 291 287 bond * FindNextUnused(atom *vertex); … … 307 303 bool ParseOrderAtSiteFromFile(ofstream *out, char *path); 308 304 bool StoreOrderAtSiteFile(ofstream *out, char *path); 309 bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList );305 bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList, bool IsAngstroem); 310 306 bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path); 311 307 bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex); … … 396 392 char *configpath; 397 393 char *configname; 398 bool FastParsing;399 394 400 395 private: -
src/periodentafel.cpp
r8a3e45 rd250b2 217 217 218 218 // fill valence DB per element 219 strncpy(filename, path, MAXSTRINGSIZE); 220 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 221 strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename)); 219 strncat(filename, path, MAXSTRINGSIZE); 220 strncpy(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename)); 222 221 infile.open(filename); 223 222 if (infile != NULL) { … … 227 226 infile >> FindElement((int)tmp)->Valence; 228 227 infile >> ws; 229 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;228 //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->Valence << " valence electrons." << endl; 230 229 } 231 230 infile.close(); … … 235 234 236 235 // fill valence DB per element 237 strncpy(filename, path, MAXSTRINGSIZE); 238 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 239 strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename)); 236 strncat(filename, path, MAXSTRINGSIZE); 237 strncpy(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename)); 240 238 infile.open(filename); 241 239 if (infile != NULL) { … … 245 243 infile >> FindElement((int)tmp)->NoValenceOrbitals; 246 244 infile >> ws; 247 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;245 //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl; 248 246 } 249 247 infile.close(); … … 253 251 254 252 // fill H-BondDistance DB per element 255 strncpy(filename, path, MAXSTRINGSIZE); 256 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 257 strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename)); 253 strncat(filename, path, MAXSTRINGSIZE); 254 strncpy(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename)); 258 255 infile.open(filename); 259 256 if (infile != NULL) { … … 266 263 infile >> ptr->HBondDistance[2]; 267 264 infile >> ws; 268 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;265 //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl; 269 266 } 270 267 infile.close(); … … 274 271 275 272 // fill H-BondAngle DB per element 276 strncpy(filename, path, MAXSTRINGSIZE); 277 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 278 strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename)); 273 strncat(filename, path, MAXSTRINGSIZE); 274 strncpy(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename)); 279 275 infile.open(filename); 280 276 if (infile != NULL) { … … 293 289 otherstatus = false; 294 290 295 if (!otherstatus)296 cerr << "ERROR: Something went wrong while parsing the databases!" << endl;297 298 291 return status; 299 292 }; … … 305 298 bool result = true; 306 299 ofstream f; 307 char file[MAXSTRINGSIZE]; 308 309 if (filename == STANDARDELEMENTSDB) 310 f.open(file); 300 301 if (filename == NULL) 302 f.open("elements.db"); 311 303 else 312 304 f.open(filename); -
src/vector.cpp
r8a3e45 rd250b2 13 13 */ 14 14 vector::vector() { x[0] = x[1] = x[2] = 0.; }; 15 16 /** Constructor of class vector.17 */18 vector::vector(double x1, double x2, double x3) { x[0] = x1; x[1] = x2; x[2] = x3; };19 15 20 16 /** Desctructor of class vector. … … 115 111 }; 116 112 117 /** projects this vector onto plane defined by \a *y.118 * \param *y array to normal vector of plane119 * \return \f$\langle x, y \rangle\f$120 */121 void vector::ProjectOntoPlane(const vector *y)122 {123 vector tmp;124 tmp.CopyVector(y);125 tmp.Scale(Projection(y));126 this->SubtractVector(&tmp);127 };128 129 113 /** Calculates the projection of a vector onto another \a *y. 130 114 * \param *y array to second vector … … 133 117 double vector::Projection(const vector *y) const 134 118 { 135 return (ScalarProduct(y) );119 return (ScalarProduct(y)/Norm()/y->Norm()); 136 120 }; 137 121 … … 166 150 }; 167 151 168 /** Zeros all components of this vector.169 */170 void vector::One(double one)171 {172 for (int i=NDIM;i--;)173 this->x[i] = one;174 };175 176 /** Initialises all components of this vector.177 */178 void vector::Init(double x1, double x2, double x3)179 {180 x[0] = x1;181 x[1] = x2;182 x[2] = x3;183 };184 185 152 /** Calculates the angle between this and another vector. 186 153 * \param *y array to second vector 187 * \return \f$\ acos\bigl(frac{\langle x, y \rangle}{|x||y|}\bigr)\f$154 * \return \f$\frac{\langle x, y \rangle}{|x||y|}\f$ 188 155 */ 189 156 double vector::Angle(vector *y) const 190 157 { 191 return acos(this->ScalarProduct(y)/Norm()/y->Norm());158 return (this->ScalarProduct(y)/(this->Norm()*y->Norm())); 192 159 }; 193 160 … … 387 354 { 388 355 double projection; 389 projection = ScalarProduct(n)/ n->ScalarProduct(n); // remove constancy from n (keep as logical one)356 projection = ScalarProduct(n)/((vector *)n)->ScalarProduct(n); // remove constancy from n (keep as logical one) 390 357 // withdraw projected vector twice from original one 391 358 cout << Verbose(1) << "Vector: "; … … 418 385 return false; 419 386 } 420 //cout << Verbose(4) << "relative, first plane coordinates:";421 //x1.Output((ofstream *)&cout);422 //cout << endl;423 //cout << Verbose(4) << "second plane coordinates:";424 //x2.Output((ofstream *)&cout);425 //cout << endl;387 cout << Verbose(4) << "relative, first plane coordinates:"; 388 x1.Output((ofstream *)&cout); 389 cout << endl; 390 cout << Verbose(4) << "second plane coordinates:"; 391 x2.Output((ofstream *)&cout); 392 cout << endl; 426 393 427 394 this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]); … … 452 419 return false; 453 420 } 454 //cout << Verbose(4) << "relative, first plane coordinates:";455 //x1.Output((ofstream *)&cout);456 //cout << endl;457 //cout << Verbose(4) << "second plane coordinates:";458 //x2.Output((ofstream *)&cout);459 //cout << endl;421 cout << Verbose(4) << "relative, first plane coordinates:"; 422 x1.Output((ofstream *)&cout); 423 cout << endl; 424 cout << Verbose(4) << "second plane coordinates:"; 425 x2.Output((ofstream *)&cout); 426 cout << endl; 460 427 461 428 this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]); … … 491 458 * \return true - success, false - failure (null vector given) 492 459 */ 493 bool vector::GetOneNormalVector(const vector * GivenVector)460 bool vector::GetOneNormalVector(const vector *vector) 494 461 { 495 462 int Components[NDIM]; // contains indices of non-zero components … … 499 466 500 467 cout << Verbose(4); 501 GivenVector->Output((ofstream *)&cout);468 vector->Output((ofstream *)&cout); 502 469 cout << endl; 503 470 for (j=NDIM;j--;) … … 505 472 // find two components != 0 506 473 for (j=0;j<NDIM;j++) 507 if (fabs( GivenVector->x[j]) > MYEPSILON)474 if (fabs(vector->x[j]) > MYEPSILON) 508 475 Components[Last++] = j; 509 476 cout << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl; … … 512 479 case 3: // threecomponent system 513 480 case 2: // two component system 514 norm = sqrt(1./( GivenVector->x[Components[1]]*GivenVector->x[Components[1]]) + 1./(GivenVector->x[Components[0]]*GivenVector->x[Components[0]]));481 norm = sqrt(1./(vector->x[Components[1]]*vector->x[Components[1]]) + 1./(vector->x[Components[0]]*vector->x[Components[0]])); 515 482 x[Components[2]] = 0.; 516 483 // in skp both remaining parts shall become zero but with opposite sign and third is zero 517 x[Components[1]] = -1./ GivenVector->x[Components[1]] / norm;518 x[Components[0]] = 1./ GivenVector->x[Components[0]] / norm;484 x[Components[1]] = -1./vector->x[Components[1]] / norm; 485 x[Components[0]] = 1./vector->x[Components[0]] / norm; 519 486 return true; 520 487 break; … … 531 498 }; 532 499 533 /** Determines paramter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.534 * \param *A first plane vector535 * \param *B second plane vector536 * \param *C third plane vector537 * \return scaling parameter for this vector538 */539 double vector::CutsPlaneAt(vector *A, vector *B, vector *C)540 {541 // cout << Verbose(3) << "For comparison: ";542 // cout << "A " << A->Projection(this) << "\t";543 // cout << "B " << B->Projection(this) << "\t";544 // cout << "C " << C->Projection(this) << "\t";545 // cout << endl;546 return A->Projection(this);547 };548 549 500 /** Creates a new vector as the one with least square distance to a given set of \a vectors. 550 501 * \param *vectors set of vectors … … 568 519 gsl_multimin_fminimizer_nmsimplex; 569 520 gsl_multimin_fminimizer *s = NULL; 570 gsl_vector *ss, * y;521 gsl_vector *ss, *x; 571 522 gsl_multimin_function minex_func; 572 523 … … 577 528 /* Initial vertex size vector */ 578 529 ss = gsl_vector_alloc (np); 579 y= gsl_vector_alloc (np);530 x = gsl_vector_alloc (np); 580 531 581 532 /* Set all step sizes to 1 */ … … 587 538 588 539 for (i=NDIM;i--;) 589 gsl_vector_set( y, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.);540 gsl_vector_set(x, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.); 590 541 591 542 /* Initialize method and iterate */ … … 595 546 596 547 s = gsl_multimin_fminimizer_alloc (T, np); 597 gsl_multimin_fminimizer_set (s, &minex_func, y, ss);548 gsl_multimin_fminimizer_set (s, &minex_func, x, ss); 598 549 599 550 do … … 624 575 for (i=(size_t)np;i--;) 625 576 this->x[i] = gsl_vector_get(s->x, i); 626 gsl_vector_free( y);577 gsl_vector_free(x); 627 578 gsl_vector_free(ss); 628 579 gsl_multimin_fminimizer_free (s); -
src/vector.hpp
r8a3e45 rd250b2 10 10 11 11 vector(); 12 vector(double x1, double x2, double x3);13 12 ~vector(); 14 13 … … 24 23 void CopyVector(const vector *y); 25 24 void RotateVector(const vector *y, const double alpha); 26 void ProjectOntoPlane(const vector *y);27 25 void Zero(); 28 void One(double one);29 void Init(double x1, double x2, double x3);30 26 void Normalize(); 31 27 void Translate(const vector *x); … … 39 35 void LinearCombinationOfVectors(const vector *x1, const vector *x2, const vector *x3, double *factors); 40 36 41 double CutsPlaneAt(vector *A, vector *B, vector *C);42 37 bool GetOneNormalVector(const vector *x1); 43 38 bool MakeNormalVector(const vector *y1);
Note:
See TracChangeset
for help on using the changeset viewer.