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