Changeset 543ce4 for molecuilder/src/molecule.cpp
- Timestamp:
- Nov 4, 2009, 7:56:04 PM (16 years ago)
- Children:
- 4ef101, aa8542
- Parents:
- ec70ec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/molecule.cpp
rec70ec r543ce4 14 14 #include "linkedcell.hpp" 15 15 #include "lists.hpp" 16 #include "log.hpp" 16 17 #include "molecule.hpp" 17 18 #include "memoryallocator.hpp" … … 143 144 * \todo double and triple bonds splitting (always use the tetraeder angle!) 144 145 */ 145 bool molecule::AddHydrogenReplacementAtom( ofstream *out,bond *TopBond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem)146 bool molecule::AddHydrogenReplacementAtom(bond *TopBond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem) 146 147 { 147 148 double bondlength; // bond length of the bond to be replaced/cut … … 157 158 bond *Binder = NULL; 158 159 159 // *out<< Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl;160 // Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl; 160 161 // create vector in direction of bond 161 162 InBondvector.CopyVector(&TopReplacement->x); … … 167 168 // due to TopReplacement or Origin being on the wrong side! 168 169 if (bondlength > BondDistance) { 169 // *out<< Verbose(4) << "InBondvector is: ";170 // Log() << Verbose(4) << "InBondvector is: "; 170 171 // InBondvector.Output(out); 171 // *out<< endl;172 // Log() << Verbose(0) << endl; 172 173 Orthovector1.Zero(); 173 174 for (int i=NDIM;i--;) { … … 182 183 Free(&matrix); 183 184 bondlength = InBondvector.Norm(); 184 // *out<< Verbose(4) << "Corrected InBondvector is now: ";185 // Log() << Verbose(4) << "Corrected InBondvector is now: "; 185 186 // InBondvector.Output(out); 186 // *out<< endl;187 // Log() << Verbose(0) << endl; 187 188 } // periodic correction finished 188 189 … … 191 192 BondRescale = TopOrigin->type->HBondDistance[TopBond->BondDegree-1]; 192 193 if (BondRescale == -1) { 193 cerr<< Verbose(3) << "ERROR: There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;194 eLog() << Verbose(3) << "ERROR: There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl; 194 195 return false; 195 196 BondRescale = bondlength; … … 216 217 FirstOtherAtom->x.AddVector(&InBondvector); // ... and add distance vector to replacement atom 217 218 AllWentWell = AllWentWell && AddAtom(FirstOtherAtom); 218 // *out<< Verbose(4) << "Added " << *FirstOtherAtom << " at: ";219 // Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: "; 219 220 // FirstOtherAtom->x.Output(out); 220 // *out<< endl;221 // Log() << Verbose(0) << endl; 221 222 Binder = AddBond(BottomOrigin, FirstOtherAtom, 1); 222 223 Binder->Cyclic = false; … … 234 235 SecondOtherAtom = (*Runner)->GetOtherAtom(TopOrigin); 235 236 } else { 236 *out<< Verbose(3) << "WARNING: Detected more than four bonds for atom " << TopOrigin->Name;237 Log() << Verbose(3) << "WARNING: Detected more than four bonds for atom " << TopOrigin->Name; 237 238 } 238 239 } … … 243 244 } 244 245 if (FirstOtherAtom != NULL) { // then we just have this double bond and the plane does not matter at all 245 // *out<< Verbose(3) << "Regarding the double bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") to be constructed: Taking " << FirstOtherAtom->Name << " and " << SecondOtherAtom->Name << " along with " << TopOrigin->Name << " to determine orthogonal plane." << endl;246 // Log() << Verbose(3) << "Regarding the double bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") to be constructed: Taking " << FirstOtherAtom->Name << " and " << SecondOtherAtom->Name << " along with " << TopOrigin->Name << " to determine orthogonal plane." << endl; 246 247 247 248 // determine the plane of these two with the *origin … … 250 251 Orthovector1.GetOneNormalVector(&InBondvector); 251 252 } 252 // *out<< Verbose(3)<< "Orthovector1: ";253 //Log() << Verbose(3)<< "Orthovector1: "; 253 254 //Orthovector1.Output(out); 254 // *out<< endl;255 //Log() << Verbose(0) << endl; 255 256 // orthogonal vector and bond vector between origin and replacement form the new plane 256 257 Orthovector1.MakeNormalVector(&InBondvector); 257 258 Orthovector1.Normalize(); 258 // *out<< Verbose(3) << "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << "." << endl;259 //Log() << Verbose(3) << "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << "." << endl; 259 260 260 261 // create the two Hydrogens ... … … 271 272 bondangle = TopOrigin->type->HBondAngle[1]; 272 273 if (bondangle == -1) { 273 *out<< Verbose(3) << "ERROR: There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;274 Log() << Verbose(3) << "ERROR: There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl; 274 275 return false; 275 276 bondangle = 0; 276 277 } 277 278 bondangle *= M_PI/180./2.; 278 // *out<< Verbose(3) << "ReScaleCheck: InBondvector ";279 // Log() << Verbose(3) << "ReScaleCheck: InBondvector "; 279 280 // InBondvector.Output(out); 280 // *out<< endl;281 // *out<< Verbose(3) << "ReScaleCheck: Orthovector ";281 // Log() << Verbose(0) << endl; 282 // Log() << Verbose(3) << "ReScaleCheck: Orthovector "; 282 283 // Orthovector1.Output(out); 283 // *out<< endl;284 // *out<< Verbose(3) << "Half the bond angle is " << bondangle << ", sin and cos of it: " << sin(bondangle) << ", " << cos(bondangle) << endl;284 // Log() << Verbose(0) << endl; 285 // Log() << Verbose(3) << "Half the bond angle is " << bondangle << ", sin and cos of it: " << sin(bondangle) << ", " << cos(bondangle) << endl; 285 286 FirstOtherAtom->x.Zero(); 286 287 SecondOtherAtom->x.Zero(); … … 291 292 FirstOtherAtom->x.Scale(&BondRescale); // rescale by correct BondDistance 292 293 SecondOtherAtom->x.Scale(&BondRescale); 293 // *out<< Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl;294 //Log() << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl; 294 295 for(int i=NDIM;i--;) { // and make relative to origin atom 295 296 FirstOtherAtom->x.x[i] += TopOrigin->x.x[i]; … … 299 300 AllWentWell = AllWentWell && AddAtom(FirstOtherAtom); 300 301 AllWentWell = AllWentWell && AddAtom(SecondOtherAtom); 301 // *out<< Verbose(4) << "Added " << *FirstOtherAtom << " at: ";302 // Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: "; 302 303 // FirstOtherAtom->x.Output(out); 303 // *out<< endl;304 // *out<< Verbose(4) << "Added " << *SecondOtherAtom << " at: ";304 // Log() << Verbose(0) << endl; 305 // Log() << Verbose(4) << "Added " << *SecondOtherAtom << " at: "; 305 306 // SecondOtherAtom->x.Output(out); 306 // *out<< endl;307 // Log() << Verbose(0) << endl; 307 308 Binder = AddBond(BottomOrigin, FirstOtherAtom, 1); 308 309 Binder->Cyclic = false; … … 332 333 // we need to vectors orthonormal the InBondvector 333 334 AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(&InBondvector); 334 // *out<< Verbose(3) << "Orthovector1: ";335 // Log() << Verbose(3) << "Orthovector1: "; 335 336 // Orthovector1.Output(out); 336 // *out<< endl;337 // Log() << Verbose(0) << endl; 337 338 AllWentWell = AllWentWell && Orthovector2.MakeNormalVector(&InBondvector, &Orthovector1); 338 // *out<< Verbose(3) << "Orthovector2: ";339 // Log() << Verbose(3) << "Orthovector2: "; 339 340 // Orthovector2.Output(out); 340 // *out<< endl;341 // Log() << Verbose(0) << endl; 341 342 342 343 // create correct coordination for the three atoms … … 347 348 f = b/sqrt(3.); // length for Orthvector1 348 349 g = b/2.; // length for Orthvector2 349 // *out<< Verbose(3) << "Bond length and half-angle: " << l << ", " << alpha << "\t (b,d,f,g) = " << b << ", " << d << ", " << f << ", " << g << ", " << endl;350 // *out<< Verbose(3) << "The three Bond lengths: " << sqrt(d*d+f*f) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g) << endl;350 // Log() << Verbose(3) << "Bond length and half-angle: " << l << ", " << alpha << "\t (b,d,f,g) = " << b << ", " << d << ", " << f << ", " << g << ", " << endl; 351 // Log() << Verbose(3) << "The three Bond lengths: " << sqrt(d*d+f*f) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g) << endl; 351 352 factors[0] = d; 352 353 factors[1] = f; … … 373 374 AllWentWell = AllWentWell && AddAtom(SecondOtherAtom); 374 375 AllWentWell = AllWentWell && AddAtom(ThirdOtherAtom); 375 // *out<< Verbose(4) << "Added " << *FirstOtherAtom << " at: ";376 // Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: "; 376 377 // FirstOtherAtom->x.Output(out); 377 // *out<< endl;378 // *out<< Verbose(4) << "Added " << *SecondOtherAtom << " at: ";378 // Log() << Verbose(0) << endl; 379 // Log() << Verbose(4) << "Added " << *SecondOtherAtom << " at: "; 379 380 // SecondOtherAtom->x.Output(out); 380 // *out<< endl;381 // *out<< Verbose(4) << "Added " << *ThirdOtherAtom << " at: ";381 // Log() << Verbose(0) << endl; 382 // Log() << Verbose(4) << "Added " << *ThirdOtherAtom << " at: "; 382 383 // ThirdOtherAtom->x.Output(out); 383 // *out<< endl;384 // Log() << Verbose(0) << endl; 384 385 Binder = AddBond(BottomOrigin, FirstOtherAtom, 1); 385 386 Binder->Cyclic = false; … … 393 394 break; 394 395 default: 395 cerr<< "ERROR: BondDegree does not state single, double or triple bond!" << endl;396 eLog() << Verbose(0) << "ERROR: BondDegree does not state single, double or triple bond!" << endl; 396 397 AllWentWell = false; 397 398 break; 398 399 } 399 400 400 // *out<< Verbose(3) << "End of AddHydrogenReplacementAtom." << endl;401 // Log() << Verbose(3) << "End of AddHydrogenReplacementAtom." << endl; 401 402 return AllWentWell; 402 403 }; … … 425 426 input = new istringstream(line); 426 427 *input >> NumberOfAtoms; 427 cout<< Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl;428 Log() << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl; 428 429 getline(xyzfile,line,'\n'); // Read comment 429 cout<< Verbose(1) << "Comment: " << line << endl;430 Log() << Verbose(1) << "Comment: " << line << endl; 430 431 431 432 if (MDSteps == 0) // no atoms yet present … … 436 437 istringstream *item = new istringstream(line); 437 438 //istringstream input(line); 438 // cout<< Verbose(1) << "Reading: " << line << endl;439 //Log() << Verbose(1) << "Reading: " << line << endl; 439 440 *item >> shorthand; 440 441 *item >> x[0]; … … 443 444 Walker->type = elemente->FindElement(shorthand); 444 445 if (Walker->type == NULL) { 445 cerr<< "Could not parse the element at line: '" << line << "', setting to H.";446 eLog() << Verbose(0) << "Could not parse the element at line: '" << line << "', setting to H."; 446 447 Walker->type = elemente->FindElement(1); 447 448 } … … 496 497 497 498 // copy values 498 copy->CountAtoms( (ofstream *)&cout);499 copy->CountAtoms(); 499 500 copy->CountElements(); 500 501 if (first->next != last) { // if adjaceny list is present … … 517 518 ActOnCopyWithEachAtomIfTrue ( &molecule::AddCopyAtom, copy, &atom::IsInParallelepiped, offset, parallelepiped ); 518 519 519 //TODO: copy->BuildInducedSubgraph( (ofstream *)&cout,this);520 //TODO: copy->BuildInducedSubgraph(this); 520 521 521 522 return copy; … … 539 540 add(Binder, last); 540 541 } else { 541 cerr<< Verbose(1) << "ERROR: Could not add bond between " << atom1->Name << " and " << atom2->Name << " as one or both are not present in the molecule." << endl;542 eLog() << Verbose(1) << "ERROR: Could not add bond between " << atom1->Name << " and " << atom2->Name << " as one or both are not present in the molecule." << endl; 542 543 } 543 544 return Binder; … … 551 552 bool molecule::RemoveBond(bond *pointer) 552 553 { 553 // cerr<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl;554 //eLog() << Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl; 554 555 pointer->leftatom->RegisterBond(pointer); 555 556 pointer->rightatom->RegisterBond(pointer); … … 565 566 bool molecule::RemoveBonds(atom *BondPartner) 566 567 { 567 // cerr<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl;568 //eLog() << Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl; 568 569 BondList::const_iterator ForeRunner; 569 570 while (!BondPartner->ListOfBonds.empty()) { … … 617 618 AtomCount--; 618 619 } else 619 cerr<< "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;620 eLog() << Verbose(0) << "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl; 620 621 if (ElementsInMolecule[pointer->type->Z] == 0) // was last atom of this element? 621 622 ElementCount--; … … 635 636 ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element 636 637 else 637 cerr<< "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;638 eLog() << Verbose(0) << "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl; 638 639 if (ElementsInMolecule[pointer->type->Z] == 0) // was last atom of this element? 639 640 ElementCount--; … … 657 658 atom * walker = find(&Nr, start,end); 658 659 if (walker != NULL) { 659 // cout<< Verbose(0) << "Found Atom Nr. " << walker->nr << endl;660 //Log() << Verbose(0) << "Found Atom Nr. " << walker->nr << endl; 660 661 return walker; 661 662 } else { 662 cout<< Verbose(0) << "Atom not found in list." << endl;663 Log() << Verbose(0) << "Atom not found in list." << endl; 663 664 return NULL; 664 665 } … … 673 674 atom *ion = NULL; 674 675 do { 675 // cout<< Verbose(0) << "============Atom list==========================" << endl;676 //Log() << Verbose(0) << "============Atom list==========================" << endl; 676 677 //mol->Output((ofstream *)&cout); 677 // cout<< Verbose(0) << "===============================================" << endl;678 cout<< Verbose(0) << text;678 //Log() << Verbose(0) << "===============================================" << endl; 679 Log() << Verbose(0) << text; 679 680 cin >> No; 680 681 ion = this->FindAtom(No); … … 702 703 * \param *out output stream 703 704 */ 704 bool molecule::Output(ofstream * out)705 bool molecule::Output(ofstream * const output) 705 706 { 706 707 int ElementNo[MAX_ELEMENTS], AtomNo[MAX_ELEMENTS]; … … 711 712 ElementNo[i] = 0; 712 713 } 713 if (out == NULL) {714 if (output == NULL) { 714 715 return false; 715 716 } else { 716 *out << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl;717 *output << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl; 717 718 SetIndexedArrayForEachAtomTo ( ElementNo, &element::Z, &AbsoluteValue, 1); 718 719 int current=1; … … 721 722 ElementNo[i] = current++; 722 723 } 723 ActOnAllAtoms( &atom::OutputArrayIndexed, (ofstream *)out, (const int *)ElementNo, (int *)AtomNo, (const char *) NULL );724 ActOnAllAtoms( &atom::OutputArrayIndexed, output, (const int *)ElementNo, (int *)AtomNo, (const char *) NULL ); 724 725 return true; 725 726 } … … 729 730 * \param *out output stream 730 731 */ 731 bool molecule::OutputTrajectories(ofstream * out)732 bool molecule::OutputTrajectories(ofstream * const output) 732 733 { 733 734 int ElementNo[MAX_ELEMENTS], AtomNo[MAX_ELEMENTS]; 734 735 CountElements(); 735 736 736 if (out == NULL) {737 if (output == NULL) { 737 738 return false; 738 739 } else { 739 740 for (int step = 0; step < MDSteps; step++) { 740 741 if (step == 0) { 741 *out << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl;742 *output << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl; 742 743 } else { 743 *out << "# ====== MD step " << step << " =========" << endl;744 *output << "# ====== MD step " << step << " =========" << endl; 744 745 } 745 746 for (int i=0;i<MAX_ELEMENTS;++i) { … … 753 754 ElementNo[i] = current++; 754 755 } 755 ActOnAllAtoms( &atom::OutputTrajectory, out , (const int *)ElementNo, AtomNo, (const int)step );756 ActOnAllAtoms( &atom::OutputTrajectory, output, (const int *)ElementNo, AtomNo, (const int)step ); 756 757 } 757 758 return true; … … 762 763 * \param *out output stream 763 764 */ 764 void molecule::OutputListOfBonds( ofstream *out) const765 { 766 *out<< Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl;767 ActOnAllAtoms (&atom::OutputBondOfAtom , out);768 *out<< endl;765 void molecule::OutputListOfBonds() const 766 { 767 Log() << Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl; 768 ActOnAllAtoms (&atom::OutputBondOfAtom ); 769 Log() << Verbose(0) << endl; 769 770 }; 770 771 … … 772 773 * \param *out stream pointer 773 774 */ 774 bool molecule::Checkout(ofstream * out) const775 { 776 return elemente->Checkout(out , ElementsInMolecule);775 bool molecule::Checkout(ofstream * const output) const 776 { 777 return elemente->Checkout(output, ElementsInMolecule); 777 778 }; 778 779 … … 780 781 * \param *out output stream 781 782 */ 782 bool molecule::OutputTrajectoriesXYZ(ofstream * out)783 bool molecule::OutputTrajectoriesXYZ(ofstream * const output) 783 784 { 784 785 time_t now; 785 786 786 if (out != NULL) {787 if (output != NULL) { 787 788 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 788 789 for (int step=0;step<MDSteps;step++) { 789 *out << AtomCount << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now);790 ActOnAllAtoms( &atom::OutputTrajectoryXYZ, out , step );790 *output << AtomCount << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now); 791 ActOnAllAtoms( &atom::OutputTrajectoryXYZ, output, step ); 791 792 } 792 793 return true; … … 798 799 * \param *out output stream 799 800 */ 800 bool molecule::OutputXYZ(ofstream * out) const801 bool molecule::OutputXYZ(ofstream * const output) const 801 802 { 802 803 time_t now; 803 804 804 if (out != NULL) {805 if (output != NULL) { 805 806 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 806 *out << AtomCount << "\n\tCreated by molecuilder on " << ctime(&now);807 ActOnAllAtoms( &atom::OutputXYZLine, out );807 *output << AtomCount << "\n\tCreated by molecuilder on " << ctime(&now); 808 ActOnAllAtoms( &atom::OutputXYZLine, output ); 808 809 return true; 809 810 } else … … 814 815 * \param *out output stream for debugging 815 816 */ 816 void molecule::CountAtoms( ofstream *out)817 void molecule::CountAtoms() 817 818 { 818 819 int i = 0; … … 823 824 } 824 825 if ((AtomCount == 0) || (i != AtomCount)) { 825 *out<< Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl;826 Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl; 826 827 AtomCount = i; 827 828 … … 839 840 Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name"); 840 841 sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1); 841 *out<< "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;842 Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl; 842 843 i++; 843 844 } 844 845 } else 845 *out<< Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl;846 Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl; 846 847 } 847 848 }; … … 870 871 for(int i=MAX_ELEMENTS;i--;) { 871 872 if (ElementsInMolecule[i] != 0) { 872 // cout<< "CalculateOrbitals: " << elemente->FindElement(i)->name << " has a valence of " << (int)elemente->FindElement(i)->Valence << " and there are " << ElementsInMolecule[i] << " of it." << endl;873 //Log() << Verbose(0) << "CalculateOrbitals: " << elemente->FindElement(i)->name << " has a valence of " << (int)elemente->FindElement(i)->Valence << " and there are " << ElementsInMolecule[i] << " of it." << endl; 873 874 configuration.MaxPsiDouble += ElementsInMolecule[i]*((int)elemente->FindElement(i)->Valence); 874 875 } … … 894 895 * \return NULL - not equal, otherwise an allocated (molecule::AtomCount) permutation map of the atom numbers (which corresponds to which) 895 896 */ 896 int * molecule::IsEqualToWithinThreshold( ofstream *out,molecule *OtherMolecule, double threshold)897 int * molecule::IsEqualToWithinThreshold(molecule *OtherMolecule, double threshold) 897 898 { 898 899 int flag; … … 903 904 bool result = true; // status of comparison 904 905 905 *out<< Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl;906 Log() << Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl; 906 907 /// first count both their atoms and elements and update lists thereby ... 907 // *out<< Verbose(0) << "Counting atoms, updating list" << endl;908 CountAtoms( out);909 OtherMolecule->CountAtoms( out);908 //Log() << Verbose(0) << "Counting atoms, updating list" << endl; 909 CountAtoms(); 910 OtherMolecule->CountAtoms(); 910 911 CountElements(); 911 912 OtherMolecule->CountElements(); … … 915 916 if (result) { 916 917 if (AtomCount != OtherMolecule->AtomCount) { 917 *out<< Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl;918 Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl; 918 919 result = false; 919 } else *out<< Verbose(4) << "AtomCounts match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl;920 } else Log() << Verbose(4) << "AtomCounts match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl; 920 921 } 921 922 /// -# ElementCount 922 923 if (result) { 923 924 if (ElementCount != OtherMolecule->ElementCount) { 924 *out<< Verbose(4) << "ElementCount don't match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl;925 Log() << Verbose(4) << "ElementCount don't match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl; 925 926 result = false; 926 } else *out<< Verbose(4) << "ElementCount match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl;927 } else Log() << Verbose(4) << "ElementCount match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl; 927 928 } 928 929 /// -# ElementsInMolecule 929 930 if (result) { 930 931 for (flag=MAX_ELEMENTS;flag--;) { 931 // *out<< Verbose(5) << "Element " << flag << ": " << ElementsInMolecule[flag] << " <-> " << OtherMolecule->ElementsInMolecule[flag] << "." << endl;932 //Log() << Verbose(5) << "Element " << flag << ": " << ElementsInMolecule[flag] << " <-> " << OtherMolecule->ElementsInMolecule[flag] << "." << endl; 932 933 if (ElementsInMolecule[flag] != OtherMolecule->ElementsInMolecule[flag]) 933 934 break; 934 935 } 935 936 if (flag < MAX_ELEMENTS) { 936 *out<< Verbose(4) << "ElementsInMolecule don't match." << endl;937 Log() << Verbose(4) << "ElementsInMolecule don't match." << endl; 937 938 result = false; 938 } else *out<< Verbose(4) << "ElementsInMolecule match." << endl;939 } else Log() << Verbose(4) << "ElementsInMolecule match." << endl; 939 940 } 940 941 /// then determine and compare center of gravity for each molecule ... 941 942 if (result) { 942 *out<< Verbose(5) << "Calculating Centers of Gravity" << endl;943 Log() << Verbose(5) << "Calculating Centers of Gravity" << endl; 943 944 DeterminePeriodicCenter(CenterOfGravity); 944 945 OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity); 945 *out<< Verbose(5) << "Center of Gravity: ";946 CenterOfGravity.Output( out);947 *out<< endl << Verbose(5) << "Other Center of Gravity: ";948 OtherCenterOfGravity.Output( out);949 *out<< endl;946 Log() << Verbose(5) << "Center of Gravity: "; 947 CenterOfGravity.Output(); 948 Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: "; 949 OtherCenterOfGravity.Output(); 950 Log() << Verbose(0) << endl; 950 951 if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) { 951 *out<< Verbose(4) << "Centers of gravity don't match." << endl;952 Log() << Verbose(4) << "Centers of gravity don't match." << endl; 952 953 result = false; 953 954 } … … 956 957 /// ... then make a list with the euclidian distance to this center for each atom of both molecules 957 958 if (result) { 958 *out<< Verbose(5) << "Calculating distances" << endl;959 Log() << Verbose(5) << "Calculating distances" << endl; 959 960 Distances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances"); 960 961 OtherDistances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances"); … … 963 964 964 965 /// ... sort each list (using heapsort (o(N log N)) from GSL) 965 *out<< Verbose(5) << "Sorting distances" << endl;966 Log() << Verbose(5) << "Sorting distances" << endl; 966 967 PermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap"); 967 968 OtherPermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap"); … … 969 970 gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles); 970 971 PermutationMap = Calloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap"); 971 *out<< Verbose(5) << "Combining Permutation Maps" << endl;972 Log() << Verbose(5) << "Combining Permutation Maps" << endl; 972 973 for(int i=AtomCount;i--;) 973 974 PermutationMap[PermMap[i]] = (int) OtherPermMap[i]; 974 975 975 976 /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all 976 *out<< Verbose(4) << "Comparing distances" << endl;977 Log() << Verbose(4) << "Comparing distances" << endl; 977 978 flag = 0; 978 979 for (int i=0;i<AtomCount;i++) { 979 *out<< Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " << threshold << endl;980 Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " << threshold << endl; 980 981 if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold) 981 982 flag = 1; … … 993 994 } 994 995 /// return pointer to map if all distances were below \a threshold 995 *out<< Verbose(3) << "End of IsEqualToWithinThreshold." << endl;996 Log() << Verbose(3) << "End of IsEqualToWithinThreshold." << endl; 996 997 if (result) { 997 *out<< Verbose(3) << "Result: Equal." << endl;998 Log() << Verbose(3) << "Result: Equal." << endl; 998 999 return PermutationMap; 999 1000 } else { 1000 *out<< Verbose(3) << "Result: Not equal." << endl;1001 Log() << Verbose(3) << "Result: Not equal." << endl; 1001 1002 return NULL; 1002 1003 } … … 1010 1011 * \todo make this with a good sort O(n), not O(n^2) 1011 1012 */ 1012 int * molecule::GetFatherSonAtomicMap( ofstream *out,molecule *OtherMolecule)1013 int * molecule::GetFatherSonAtomicMap(molecule *OtherMolecule) 1013 1014 { 1014 1015 atom *Walker = NULL, *OtherWalker = NULL; 1015 *out<< Verbose(3) << "Begin of GetFatherAtomicMap." << endl;1016 Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl; 1016 1017 int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap"); 1017 1018 for (int i=AtomCount;i--;) … … 1020 1021 for (int i=AtomCount;i--;) // no need as -1 means already that there is trivial correspondence 1021 1022 AtomicMap[i] = i; 1022 *out<< Verbose(4) << "Map is trivial." << endl;1023 Log() << Verbose(4) << "Map is trivial." << endl; 1023 1024 } else { 1024 *out<< Verbose(4) << "Map is ";1025 Log() << Verbose(4) << "Map is "; 1025 1026 Walker = start; 1026 1027 while (Walker->next != end) { … … 1034 1035 //for (int i=0;i<AtomCount;i++) { // search atom 1035 1036 //for (int j=0;j<OtherMolecule->AtomCount;j++) { 1036 // *out<< Verbose(4) << "Comparing father " << Walker->father << " with the other one " << OtherWalker->father << "." << endl;1037 //Log() << Verbose(4) << "Comparing father " << Walker->father << " with the other one " << OtherWalker->father << "." << endl; 1037 1038 if (Walker->father == OtherWalker) 1038 1039 AtomicMap[Walker->nr] = OtherWalker->nr; 1039 1040 } 1040 1041 } 1041 *out<< AtomicMap[Walker->nr] << "\t";1042 } 1043 *out<< endl;1044 } 1045 *out<< Verbose(3) << "End of GetFatherAtomicMap." << endl;1042 Log() << Verbose(0) << AtomicMap[Walker->nr] << "\t"; 1043 } 1044 Log() << Verbose(0) << endl; 1045 } 1046 Log() << Verbose(3) << "End of GetFatherAtomicMap." << endl; 1046 1047 return AtomicMap; 1047 1048 }; … … 1050 1051 * We simply use the formula equivaleting temperature and kinetic energy: 1051 1052 * \f$k_B T = \sum_i m_i v_i^2\f$ 1052 * \param *out output stream for debugging1053 * \param *output output stream of temperature file 1053 1054 * \param startstep first MD step in molecule::Trajectories 1054 1055 * \param endstep last plus one MD step in molecule::Trajectories 1055 * \param *output output stream of temperature file1056 1056 * \return file written (true), failure on writing file (false) 1057 1057 */ 1058 bool molecule::OutputTemperatureFromTrajectories(ofstream * out, int startstep, int endstep, ofstream *output)1058 bool molecule::OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep) 1059 1059 { 1060 1060 double temperature;
Note:
See TracChangeset
for help on using the changeset viewer.