Changes in src/molecule.cpp [e359a8:a67d19]
- File:
-
- 1 edited
-
src/molecule.cpp (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/molecule.cpp
re359a8 ra67d19 4 4 * 5 5 */ 6 7 #include <cstring> 6 8 7 9 #include "atom.hpp" … … 21 23 #include "tesselation.hpp" 22 24 #include "vector.hpp" 25 #include "World.hpp" 23 26 24 27 /************************************* Functions for class molecule *********************************/ … … 43 46 for(int i=MAX_ELEMENTS;i--;) 44 47 ElementsInMolecule[i] = 0; 45 cell_size[0] = cell_size[2] = cell_size[5]= 20.; 46 cell_size[1] = cell_size[3] = cell_size[4]= 0.; 47 strcpy(name,"none"); 48 strcpy(name,World::get()->DefaultName); 48 49 }; 49 50 … … 157 158 double *matrix = NULL; 158 159 bond *Binder = NULL; 160 double * const cell_size = World::get()->cell_size; 159 161 160 162 // Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl; … … 192 194 BondRescale = TopOrigin->type->HBondDistance[TopBond->BondDegree-1]; 193 195 if (BondRescale == -1) { 194 eLog() << Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;196 DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl); 195 197 return false; 196 198 BondRescale = bondlength; … … 235 237 SecondOtherAtom = (*Runner)->GetOtherAtom(TopOrigin); 236 238 } else { 237 eLog() << Verbose(2) << "Detected more than four bonds for atom " << TopOrigin->Name;239 DoeLog(2) && (eLog()<< Verbose(2) << "Detected more than four bonds for atom " << TopOrigin->Name); 238 240 } 239 241 } … … 272 274 bondangle = TopOrigin->type->HBondAngle[1]; 273 275 if (bondangle == -1) { 274 eLog() << Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;276 DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl); 275 277 return false; 276 278 bondangle = 0; … … 394 396 break; 395 397 default: 396 eLog() << Verbose(1) << "BondDegree does not state single, double or triple bond!" << endl;398 DoeLog(1) && (eLog()<< Verbose(1) << "BondDegree does not state single, double or triple bond!" << endl); 397 399 AllWentWell = false; 398 400 break; … … 427 429 input = new istringstream(line); 428 430 *input >> NumberOfAtoms; 429 Log() << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl;431 DoLog(0) && (Log() << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl); 430 432 getline(xyzfile,line,'\n'); // Read comment 431 Log() << Verbose(1) << "Comment: " << line << endl;433 DoLog(1) && (Log() << Verbose(1) << "Comment: " << line << endl); 432 434 433 435 if (MDSteps == 0) // no atoms yet present … … 445 447 Walker->type = elemente->FindElement(shorthand); 446 448 if (Walker->type == NULL) { 447 eLog() << Verbose(1) << "Could not parse the element at line: '" << line << "', setting to H.";449 DoeLog(1) && (eLog()<< Verbose(1) << "Could not parse the element at line: '" << line << "', setting to H."); 448 450 Walker->type = elemente->FindElement(1); 449 451 } … … 541 543 add(Binder, last); 542 544 } else { 543 eLog() << Verbose(1) << "Could not add bond between " << atom1->Name << " and " << atom2->Name << " as one or both are not present in the molecule." << endl;545 DoeLog(1) && (eLog()<< Verbose(1) << "Could not add bond between " << atom1->Name << " and " << atom2->Name << " as one or both are not present in the molecule." << endl); 544 546 } 545 547 return Binder; … … 553 555 bool molecule::RemoveBond(bond *pointer) 554 556 { 555 // eLog() << Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl;557 //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl); 556 558 pointer->leftatom->RegisterBond(pointer); 557 559 pointer->rightatom->RegisterBond(pointer); … … 567 569 bool molecule::RemoveBonds(atom *BondPartner) 568 570 { 569 // eLog() << Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl;571 //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl); 570 572 BondList::const_iterator ForeRunner; 571 573 while (!BondPartner->ListOfBonds.empty()) { … … 587 589 else 588 590 molname = filename; // contains no slashes 589 c har *endname = strchr(molname, '.');591 const char *endname = strchr(molname, '.'); 590 592 if ((endname == NULL) || (endname < molname)) 591 593 length = strlen(molname); … … 601 603 void molecule::SetBoxDimension(Vector *dim) 602 604 { 605 double * const cell_size = World::get()->cell_size; 603 606 cell_size[0] = dim->x[0]; 604 607 cell_size[1] = 0.; … … 619 622 AtomCount--; 620 623 } else 621 eLog() << Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;624 DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl); 622 625 if (ElementsInMolecule[pointer->type->Z] == 0) // was last atom of this element? 623 626 ElementCount--; … … 637 640 ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element 638 641 else 639 eLog() << Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;642 DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl); 640 643 if (ElementsInMolecule[pointer->type->Z] == 0) // was last atom of this element? 641 644 ElementCount--; … … 662 665 return walker; 663 666 } else { 664 Log() << Verbose(0) << "Atom not found in list." << endl;667 DoLog(0) && (Log() << Verbose(0) << "Atom not found in list." << endl); 665 668 return NULL; 666 669 } … … 678 681 //mol->Output((ofstream *)&cout); 679 682 //Log() << Verbose(0) << "===============================================" << endl; 680 Log() << Verbose(0) << text;683 DoLog(0) && (Log() << Verbose(0) << text); 681 684 cin >> No; 682 685 ion = this->FindAtom(No); … … 691 694 bool molecule::CheckBounds(const Vector *x) const 692 695 { 696 double * const cell_size = World::get()->cell_size; 693 697 bool result = true; 694 698 int j =-1; … … 766 770 void molecule::OutputListOfBonds() const 767 771 { 768 Log() << Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl;772 DoLog(2) && (Log() << Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl); 769 773 ActOnAllAtoms (&atom::OutputBondOfAtom ); 770 Log() << Verbose(0) << endl;774 DoLog(0) && (Log() << Verbose(0) << endl); 771 775 }; 772 776 … … 825 829 } 826 830 if ((AtomCount == 0) || (i != AtomCount)) { 827 Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl;831 DoLog(3) && (Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl); 828 832 AtomCount = i; 829 833 … … 841 845 Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name"); 842 846 sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1); 843 Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;847 DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl); 844 848 i++; 845 849 } 846 850 } else 847 Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl;851 DoLog(3) && (Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl); 848 852 } 849 853 }; … … 905 909 bool result = true; // status of comparison 906 910 907 Log() << Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl;911 DoLog(3) && (Log() << Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl); 908 912 /// first count both their atoms and elements and update lists thereby ... 909 913 //Log() << Verbose(0) << "Counting atoms, updating list" << endl; … … 917 921 if (result) { 918 922 if (AtomCount != OtherMolecule->AtomCount) { 919 Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl;923 DoLog(4) && (Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl); 920 924 result = false; 921 925 } else Log() << Verbose(4) << "AtomCounts match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl; … … 924 928 if (result) { 925 929 if (ElementCount != OtherMolecule->ElementCount) { 926 Log() << Verbose(4) << "ElementCount don't match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl;930 DoLog(4) && (Log() << Verbose(4) << "ElementCount don't match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl); 927 931 result = false; 928 932 } else Log() << Verbose(4) << "ElementCount match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl; … … 936 940 } 937 941 if (flag < MAX_ELEMENTS) { 938 Log() << Verbose(4) << "ElementsInMolecule don't match." << endl;942 DoLog(4) && (Log() << Verbose(4) << "ElementsInMolecule don't match." << endl); 939 943 result = false; 940 944 } else Log() << Verbose(4) << "ElementsInMolecule match." << endl; … … 942 946 /// then determine and compare center of gravity for each molecule ... 943 947 if (result) { 944 Log() << Verbose(5) << "Calculating Centers of Gravity" << endl;948 DoLog(5) && (Log() << Verbose(5) << "Calculating Centers of Gravity" << endl); 945 949 DeterminePeriodicCenter(CenterOfGravity); 946 950 OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity); 947 Log() << Verbose(5) << "Center of Gravity: ";951 DoLog(5) && (Log() << Verbose(5) << "Center of Gravity: "); 948 952 CenterOfGravity.Output(); 949 Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: ";953 DoLog(0) && (Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: "); 950 954 OtherCenterOfGravity.Output(); 951 Log() << Verbose(0) << endl;955 DoLog(0) && (Log() << Verbose(0) << endl); 952 956 if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) { 953 Log() << Verbose(4) << "Centers of gravity don't match." << endl;957 DoLog(4) && (Log() << Verbose(4) << "Centers of gravity don't match." << endl); 954 958 result = false; 955 959 } … … 958 962 /// ... then make a list with the euclidian distance to this center for each atom of both molecules 959 963 if (result) { 960 Log() << Verbose(5) << "Calculating distances" << endl;964 DoLog(5) && (Log() << Verbose(5) << "Calculating distances" << endl); 961 965 Distances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances"); 962 966 OtherDistances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances"); … … 965 969 966 970 /// ... sort each list (using heapsort (o(N log N)) from GSL) 967 Log() << Verbose(5) << "Sorting distances" << endl;971 DoLog(5) && (Log() << Verbose(5) << "Sorting distances" << endl); 968 972 PermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap"); 969 973 OtherPermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap"); … … 971 975 gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles); 972 976 PermutationMap = Calloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap"); 973 Log() << Verbose(5) << "Combining Permutation Maps" << endl;977 DoLog(5) && (Log() << Verbose(5) << "Combining Permutation Maps" << endl); 974 978 for(int i=AtomCount;i--;) 975 979 PermutationMap[PermMap[i]] = (int) OtherPermMap[i]; 976 980 977 981 /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all 978 Log() << Verbose(4) << "Comparing distances" << endl;982 DoLog(4) && (Log() << Verbose(4) << "Comparing distances" << endl); 979 983 flag = 0; 980 984 for (int i=0;i<AtomCount;i++) { 981 Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " << threshold << endl;985 DoLog(5) && (Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " << threshold << endl); 982 986 if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold) 983 987 flag = 1; … … 995 999 } 996 1000 /// return pointer to map if all distances were below \a threshold 997 Log() << Verbose(3) << "End of IsEqualToWithinThreshold." << endl;1001 DoLog(3) && (Log() << Verbose(3) << "End of IsEqualToWithinThreshold." << endl); 998 1002 if (result) { 999 Log() << Verbose(3) << "Result: Equal." << endl;1003 DoLog(3) && (Log() << Verbose(3) << "Result: Equal." << endl); 1000 1004 return PermutationMap; 1001 1005 } else { 1002 Log() << Verbose(3) << "Result: Not equal." << endl;1006 DoLog(3) && (Log() << Verbose(3) << "Result: Not equal." << endl); 1003 1007 return NULL; 1004 1008 } … … 1015 1019 { 1016 1020 atom *Walker = NULL, *OtherWalker = NULL; 1017 Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;1021 DoLog(3) && (Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl); 1018 1022 int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap"); 1019 1023 for (int i=AtomCount;i--;) … … 1022 1026 for (int i=AtomCount;i--;) // no need as -1 means already that there is trivial correspondence 1023 1027 AtomicMap[i] = i; 1024 Log() << Verbose(4) << "Map is trivial." << endl;1028 DoLog(4) && (Log() << Verbose(4) << "Map is trivial." << endl); 1025 1029 } else { 1026 Log() << Verbose(4) << "Map is ";1030 DoLog(4) && (Log() << Verbose(4) << "Map is "); 1027 1031 Walker = start; 1028 1032 while (Walker->next != end) { … … 1041 1045 } 1042 1046 } 1043 Log() << Verbose(0) << AtomicMap[Walker->nr] << "\t";1044 } 1045 Log() << Verbose(0) << endl;1046 } 1047 Log() << Verbose(3) << "End of GetFatherAtomicMap." << endl;1047 DoLog(0) && (Log() << Verbose(0) << AtomicMap[Walker->nr] << "\t"); 1048 } 1049 DoLog(0) && (Log() << Verbose(0) << endl); 1050 } 1051 DoLog(3) && (Log() << Verbose(3) << "End of GetFatherAtomicMap." << endl); 1048 1052 return AtomicMap; 1049 1053 };
Note:
See TracChangeset
for help on using the changeset viewer.
