Changes in src/molecule_graph.cpp [68f03d:e5ad5c]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_graph.cpp
r68f03d re5ad5c 17 17 #include "memoryallocator.hpp" 18 18 #include "molecule.hpp" 19 #include "World.hpp"20 #include "Helpers/fast_functions.hpp"21 19 22 20 struct BFSAccounting … … 60 58 61 59 if (!input) { 62 DoLog(1) && (Log() << Verbose(1) << "Opening silica failed \n");60 Log() << Verbose(1) << "Opening silica failed \n"; 63 61 }; 64 62 65 63 *input >> ws >> atom1; 66 64 *input >> ws >> atom2; 67 DoLog(1) && (Log() << Verbose(1) << "Scanning file\n");65 Log() << Verbose(1) << "Scanning file\n"; 68 66 while (!input->eof()) // Check whether we read everything already 69 67 { … … 108 106 LinkedCell *LC = NULL; 109 107 bool free_BG = false; 110 double * const cell_size = World::getInstance().getDomain();111 108 112 109 if (BG == NULL) { … … 116 113 117 114 BondDistance = bonddistance; // * ((IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem); 118 DoLog(0) && (Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl);115 Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl; 119 116 // remove every bond from the list 120 117 bond *Binder = NULL; … … 129 126 // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering) 130 127 CountAtoms(); 131 DoLog(1) && (Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl);128 Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl; 132 129 133 130 if ((AtomCount > 1) && (bonddistance > 1.)) { 134 DoLog(2) && (Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl);131 Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl; 135 132 LC = new LinkedCell(this, bonddistance); 136 133 137 134 // create a list to map Tesselpoint::nr to atom * 138 DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl);135 Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl; 139 136 AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount"); 140 137 Walker = start; … … 145 142 146 143 // 3a. go through every cell 147 DoLog(2) && (Log() << Verbose(2) << "Celling ... " << endl);144 Log() << Verbose(2) << "Celling ... " << endl; 148 145 for (LC->n[0] = 0; LC->n[0] < LC->N[0]; LC->n[0]++) 149 146 for (LC->n[1] = 0; LC->n[1] < LC->N[1]; LC->n[1]++) 150 147 for (LC->n[2] = 0; LC->n[2] < LC->N[2]; LC->n[2]++) { 151 const Linked Cell::LinkedNodes *List = LC->GetCurrentCell();148 const LinkedNodes *List = LC->GetCurrentCell(); 152 149 // Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl; 153 150 if (List != NULL) { 154 for (Linked Cell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {151 for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 155 152 Walker = AtomMap[(*Runner)->nr]; 156 153 // Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl; … … 159 156 for (n[1] = -1; n[1] <= 1; n[1]++) 160 157 for (n[2] = -1; n[2] <= 1; n[2]++) { 161 const Linked Cell::LinkedNodes *OtherList = LC->GetRelativeToCurrentCell(n);158 const LinkedNodes *OtherList = LC->GetRelativeToCurrentCell(n); 162 159 // Log() << Verbose(2) << "Current relative cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl; 163 160 if (OtherList != NULL) { 164 for (Linked Cell::LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {161 for (LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) { 165 162 if ((*OtherRunner)->nr > Walker->nr) { 166 163 OtherWalker = AtomMap[(*OtherRunner)->nr]; 167 164 // Log() << Verbose(0) << "Current other Atom is " << *OtherWalker << "." << endl; 168 const double distance = OtherWalker->x.PeriodicDistanceSquared( Walker->x, cell_size);165 const double distance = OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size); 169 166 // Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl; 170 167 (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem); … … 190 187 Free(&AtomMap); 191 188 delete (LC); 192 DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl);189 Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl; 193 190 194 191 // correct bond degree by comparing valence and bond degree 195 DoLog(2) && (Log() << Verbose(2) << "Correcting bond degree ... " << endl);192 Log() << Verbose(2) << "Correcting bond degree ... " << endl; 196 193 CorrectBondDegree(); 197 194 … … 199 196 ActOnAllAtoms( &atom::OutputBondOfAtom ); 200 197 } else 201 DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl);202 DoLog(0) && (Log() << Verbose(0) << "End of CreateAdjacencyList." << endl);198 Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl; 199 Log() << Verbose(0) << "End of CreateAdjacencyList." << endl; 203 200 if (free_BG) 204 201 delete(BG); … … 211 208 void molecule::OutputBondsList() const 212 209 { 213 DoLog(1) && (Log() << Verbose(1) << endl << "From contents of bond chain list:");210 Log() << Verbose(1) << endl << "From contents of bond chain list:"; 214 211 bond *Binder = first; 215 212 while (Binder->next != last) { 216 213 Binder = Binder->next; 217 DoLog(0) && (Log() << Verbose(0) << *Binder << "\t" << endl);218 } 219 DoLog(0) && (Log() << Verbose(0) << endl);214 Log() << Verbose(0) << *Binder << "\t" << endl; 215 } 216 Log() << Verbose(0) << endl; 220 217 } 221 218 ; … … 234 231 235 232 if (BondCount != 0) { 236 DoLog(1) && (Log() << Verbose(1) << "Correcting Bond degree of each bond ... " << endl);233 Log() << Verbose(1) << "Correcting Bond degree of each bond ... " << endl; 237 234 do { 238 235 OldNo = No; 239 236 No = SumPerAtom( &atom::CorrectBondDegree ); 240 237 } while (OldNo != No); 241 DoLog(0) && (Log() << Verbose(0) << " done." << endl);238 Log() << Verbose(0) << " done." << endl; 242 239 } else { 243 DoLog(1) && (Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl);244 } 245 DoLog(0) && (Log() << Verbose(0) << No << " bonds could not be corrected." << endl);240 Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl; 241 } 242 Log() << Verbose(0) << No << " bonds could not be corrected." << endl; 246 243 247 244 return (No); … … 262 259 bond *Binder = first; 263 260 if ((Binder->next != last) && (Binder->next->Type == Undetermined)) { 264 DoLog(0) && (Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl);261 Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl; 265 262 Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack); 266 263 while (Subgraphs->next != NULL) { … … 317 314 Walker->GraphNr = DFS.CurrentGraphNr; 318 315 Walker->LowpointNr = DFS.CurrentGraphNr; 319 DoLog(1) && (Log() << Verbose(1) << "Setting Walker[" << Walker->getName() << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << "." << endl);316 Log() << Verbose(1) << "Setting Walker[" << Walker->Name << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << "." << endl; 320 317 DFS.AtomStack->Push(Walker); 321 318 DFS.CurrentGraphNr++; … … 344 341 if (Binder == NULL) 345 342 break; 346 DoLog(2) && (Log() << Verbose(2) << "Current Unused Bond is " << *Binder << "." << endl);343 Log() << Verbose(2) << "Current Unused Bond is " << *Binder << "." << endl; 347 344 // (4) Mark Binder used, ... 348 345 Binder->MarkUsed(black); 349 346 OtherAtom = Binder->GetOtherAtom(Walker); 350 DoLog(2) && (Log() << Verbose(2) << "(4) OtherAtom is " << OtherAtom->getName() << "." << endl);347 Log() << Verbose(2) << "(4) OtherAtom is " << OtherAtom->Name << "." << endl; 351 348 if (OtherAtom->GraphNr != -1) { 352 349 // (4a) ... if "other" atom has been visited (GraphNr != 0), set lowpoint to minimum of both, go to (3) … … 354 351 DFS.BackEdgeStack->Push(Binder); 355 352 Walker->LowpointNr = (Walker->LowpointNr < OtherAtom->GraphNr) ? Walker->LowpointNr : OtherAtom->GraphNr; 356 DoLog(3) && (Log() << Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->getName() << "] to " << Walker->LowpointNr << "." << endl);353 Log() << Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->Name << "] to " << Walker->LowpointNr << "." << endl; 357 354 } else { 358 355 // (4b) ... otherwise set OtherAtom as Ancestor of Walker and Walker as OtherAtom, go to (2) … … 360 357 OtherAtom->Ancestor = Walker; 361 358 Walker = OtherAtom; 362 DoLog(3) && (Log() << Verbose(3) << "(4b) Not Visited: OtherAtom[" << OtherAtom->getName() << "]'s Ancestor is now " << OtherAtom->Ancestor->getName() << ", Walker is OtherAtom " << OtherAtom->getName() << "." << endl);359 Log() << Verbose(3) << "(4b) Not Visited: OtherAtom[" << OtherAtom->Name << "]'s Ancestor is now " << OtherAtom->Ancestor->Name << ", Walker is OtherAtom " << OtherAtom->Name << "." << endl; 363 360 break; 364 361 } … … 382 379 383 380 // (5) if Ancestor of Walker is ... 384 DoLog(1) && (Log() << Verbose(1) << "(5) Number of Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "] is " << Walker->Ancestor->GraphNr << "." << endl);381 Log() << Verbose(1) << "(5) Number of Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "] is " << Walker->Ancestor->GraphNr << "." << endl; 385 382 386 383 if (Walker->Ancestor->GraphNr != DFS.Root->GraphNr) { … … 389 386 // (6a) set Ancestor's Lowpoint number to minimum of of its Ancestor and itself, go to Step(8) 390 387 Walker->Ancestor->LowpointNr = (Walker->Ancestor->LowpointNr < Walker->LowpointNr) ? Walker->Ancestor->LowpointNr : Walker->LowpointNr; 391 DoLog(2) && (Log() << Verbose(2) << "(6) Setting Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << "." << endl);388 Log() << Verbose(2) << "(6) Setting Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << "." << endl; 392 389 } else { 393 390 // (7) (Ancestor of Walker is a separating vertex, remove all from stack till Walker (including), these and Ancestor form a component 394 391 Walker->Ancestor->SeparationVertex = true; 395 DoLog(2) && (Log() << Verbose(2) << "(7) Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "]'s is a separating vertex, creating component." << endl);392 Log() << Verbose(2) << "(7) Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s is a separating vertex, creating component." << endl; 396 393 mol->SetNextComponentNumber(Walker->Ancestor, DFS.ComponentNumber); 397 DoLog(3) && (Log() << Verbose(3) << "(7) Walker[" << Walker->getName() << "]'s Ancestor's Compont is " << DFS.ComponentNumber << "." << endl);394 Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Ancestor's Compont is " << DFS.ComponentNumber << "." << endl; 398 395 mol->SetNextComponentNumber(Walker, DFS.ComponentNumber); 399 DoLog(3) && (Log() << Verbose(3) << "(7) Walker[" << Walker->getName() << "]'s Compont is " << DFS.ComponentNumber << "." << endl);396 Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl; 400 397 do { 401 398 OtherAtom = DFS.AtomStack->PopLast(); 402 399 LeafWalker->Leaf->AddCopyAtom(OtherAtom); 403 400 mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber); 404 DoLog(3) && (Log() << Verbose(3) << "(7) Other[" << OtherAtom->getName() << "]'s Compont is " << DFS.ComponentNumber << "." << endl);401 Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl; 405 402 } while (OtherAtom != Walker); 406 403 DFS.ComponentNumber++; 407 404 } 408 405 // (8) Walker becomes its Ancestor, go to (3) 409 DoLog(2) && (Log() << Verbose(2) << "(8) Walker[" << Walker->getName() << "] is now its Ancestor " << Walker->Ancestor->getName() << ", backstepping. " << endl);406 Log() << Verbose(2) << "(8) Walker[" << Walker->Name << "] is now its Ancestor " << Walker->Ancestor->Name << ", backstepping. " << endl; 410 407 Walker = Walker->Ancestor; 411 408 DFS.BackStepping = true; … … 431 428 //DFS.AtomStack->Output(out); 432 429 mol->SetNextComponentNumber(DFS.Root, DFS.ComponentNumber); 433 DoLog(3) && (Log() << Verbose(3) << "(9) Root[" << DFS.Root->getName() << "]'s Component is " << DFS.ComponentNumber << "." << endl);430 Log() << Verbose(3) << "(9) Root[" << DFS.Root->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl; 434 431 mol->SetNextComponentNumber(Walker, DFS.ComponentNumber); 435 DoLog(3) && (Log() << Verbose(3) << "(9) Walker[" << Walker->getName() << "]'s Component is " << DFS.ComponentNumber << "." << endl);432 Log() << Verbose(3) << "(9) Walker[" << Walker->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl; 436 433 do { 437 434 OtherAtom = DFS.AtomStack->PopLast(); 438 435 LeafWalker->Leaf->AddCopyAtom(OtherAtom); 439 436 mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber); 440 DoLog(3) && (Log() << Verbose(3) << "(7) Other[" << OtherAtom->getName() << "]'s Compont is " << DFS.ComponentNumber << "." << endl);437 Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl; 441 438 } while (OtherAtom != Walker); 442 439 DFS.ComponentNumber++; … … 445 442 Walker = DFS.Root; 446 443 Binder = mol->FindNextUnused(Walker); 447 DoLog(1) && (Log() << Verbose(1) << "(10) Walker is Root[" << DFS.Root->getName() << "], next Unused Bond is " << Binder << "." << endl);444 Log() << Verbose(1) << "(10) Walker is Root[" << DFS.Root->Name << "], next Unused Bond is " << Binder << "." << endl; 448 445 if (Binder != NULL) { // Root is separation vertex 449 DoLog(1) && (Log() << Verbose(1) << "(11) Root is a separation vertex." << endl);446 Log() << Verbose(1) << "(11) Root is a separation vertex." << endl; 450 447 Walker->SeparationVertex = true; 451 448 } … … 502 499 bond *Binder = NULL; 503 500 504 if (AtomCount == 0) 505 return SubGraphs; 506 DoLog(0) && (Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl); 501 Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl; 507 502 DepthFirstSearchAnalysis_Init(DFS, this); 508 503 … … 514 509 // put into new subgraph molecule and add this to list of subgraphs 515 510 LeafWalker = new MoleculeLeafClass(LeafWalker); 516 LeafWalker->Leaf = World::getInstance().createMolecule();511 LeafWalker->Leaf = new molecule(elemente); 517 512 LeafWalker->Leaf->AddCopyAtom(DFS.Root); 518 513 … … 526 521 527 522 if (Binder == NULL) { 528 DoLog(2) && (Log() << Verbose(2) << "No more Unused Bonds." << endl);523 Log() << Verbose(2) << "No more Unused Bonds." << endl; 529 524 break; 530 525 } else … … 543 538 544 539 // From OldGraphNr to CurrentGraphNr ranges an disconnected subgraph 545 DoLog(0) && (Log() << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << DFS.CurrentGraphNr << "." << endl);540 Log() << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << DFS.CurrentGraphNr << "." << endl; 546 541 LeafWalker->Leaf->Output((ofstream *)&cout); 547 DoLog(0) && (Log() << Verbose(0) << endl);542 Log() << Verbose(0) << endl; 548 543 549 544 // step on to next root … … 563 558 // free all and exit 564 559 DepthFirstSearchAnalysis_Finalize(DFS); 565 DoLog(0) && (Log() << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl);560 Log() << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl; 566 561 return SubGraphs; 567 562 } … … 589 584 void molecule::OutputGraphInfoPerAtom() const 590 585 { 591 DoLog(1) && (Log() << Verbose(1) << "Final graph info for each atom is:" << endl);586 Log() << Verbose(1) << "Final graph info for each atom is:" << endl; 592 587 ActOnAllAtoms( &atom::OutputGraphInfo ); 593 588 } … … 599 594 void molecule::OutputGraphInfoPerBond() const 600 595 { 601 DoLog(1) && (Log() << Verbose(1) << "Final graph info for each bond is:" << endl);596 Log() << Verbose(1) << "Final graph info for each bond is:" << endl; 602 597 bond *Binder = first; 603 598 while (Binder->next != last) { 604 599 Binder = Binder->next; 605 DoLog(2) && (Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <");606 DoLog(0) && (Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.");600 Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <"; 601 Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp."; 607 602 Binder->leftatom->OutputComponentNumber(); 608 DoLog(0) && (Log() << Verbose(0) << " === ");609 DoLog(0) && (Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.");603 Log() << Verbose(0) << " === "; 604 Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp."; 610 605 Binder->rightatom->OutputComponentNumber(); 611 DoLog(0) && (Log() << Verbose(0) << ">." << endl);606 Log() << Verbose(0) << ">." << endl; 612 607 if (Binder->Cyclic) // cyclic ?? 613 DoLog(3) && (Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl);608 Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl; 614 609 } 615 610 } … … 685 680 do { // look for Root 686 681 Walker = BFS.BFSStack->PopFirst(); 687 DoLog(2) && (Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *BFS.Root << "." << endl);682 Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *BFS.Root << "." << endl; 688 683 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 689 684 if ((*Runner) != BackEdge) { // only walk along DFS spanning tree (otherwise we always find SP of one being backedge Binder) … … 692 687 if (OtherAtom->type->Z != 1) { 693 688 #endif 694 DoLog(2) && (Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->getName() << " for bond " << *(*Runner) << "." << endl);689 Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl; 695 690 if (BFS.ColorList[OtherAtom->nr] == white) { 696 691 BFS.TouchedStack->Push(OtherAtom); … … 698 693 BFS.PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor 699 694 BFS.ShortestPathList[OtherAtom->nr] = BFS.ShortestPathList[Walker->nr] + 1; 700 DoLog(2) && (Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->getName() << " lightgray, its predecessor is " << Walker->getName() << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl);695 Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " lightgray, its predecessor is " << Walker->Name << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl; 701 696 //if (BFS.ShortestPathList[OtherAtom->nr] < MinimumRingSize[Walker->GetTrueFather()->nr]) { // Check for maximum distance 702 DoLog(3) && (Log() << Verbose(3) << "Putting OtherAtom into queue." << endl);697 Log() << Verbose(3) << "Putting OtherAtom into queue." << endl; 703 698 BFS.BFSStack->Push(OtherAtom); 704 699 //} 705 700 } else { 706 DoLog(3) && (Log() << Verbose(3) << "Not Adding, has already been visited." << endl);701 Log() << Verbose(3) << "Not Adding, has already been visited." << endl; 707 702 } 708 703 if (OtherAtom == BFS.Root) … … 710 705 #ifdef ADDHYDROGEN 711 706 } else { 712 DoLog(2) && (Log() << Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl);707 Log() << Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl; 713 708 BFS.ColorList[OtherAtom->nr] = black; 714 709 } 715 710 #endif 716 711 } else { 717 DoLog(2) && (Log() << Verbose(2) << "Bond " << *(*Runner) << " not Visiting, is the back edge." << endl);712 Log() << Verbose(2) << "Bond " << *(*Runner) << " not Visiting, is the back edge." << endl; 718 713 } 719 714 } 720 715 BFS.ColorList[Walker->nr] = black; 721 DoLog(1) && (Log() << Verbose(1) << "Coloring Walker " << Walker->getName() << " black." << endl);716 Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl; 722 717 if (OtherAtom == BFS.Root) { // if we have found the root, check whether this cycle wasn't already found beforehand 723 718 // step through predecessor list … … 729 724 } 730 725 if (OtherAtom == BackEdge->rightatom) { // if each atom in found cycle is cyclic, loop's been found before already 731 DoLog(3) && (Log() << Verbose(3) << "This cycle was already found before, skipping and removing seeker from search." << endl);726 Log() << Verbose(3) << "This cycle was already found before, skipping and removing seeker from search." << endl; 732 727 do { 733 728 OtherAtom = BFS.TouchedStack->PopLast(); 734 729 if (BFS.PredecessorList[OtherAtom->nr] == Walker) { 735 DoLog(4) && (Log() << Verbose(4) << "Removing " << *OtherAtom << " from lists and stacks." << endl);730 Log() << Verbose(4) << "Removing " << *OtherAtom << " from lists and stacks." << endl; 736 731 BFS.PredecessorList[OtherAtom->nr] = NULL; 737 732 BFS.ShortestPathList[OtherAtom->nr] = -1; … … 767 762 RingSize = 1; 768 763 BFS.Root->GetTrueFather()->IsCyclic = true; 769 DoLog(1) && (Log() << Verbose(1) << "Found ring contains: ");764 Log() << Verbose(1) << "Found ring contains: "; 770 765 Walker = BFS.Root; 771 766 while (Walker != BackEdge->rightatom) { 772 DoLog(0) && (Log() << Verbose(0) << Walker->getName() << " <-> ");767 Log() << Verbose(0) << Walker->Name << " <-> "; 773 768 Walker = BFS.PredecessorList[Walker->nr]; 774 769 Walker->GetTrueFather()->IsCyclic = true; 775 770 RingSize++; 776 771 } 777 DoLog(0) && (Log() << Verbose(0) << Walker->getName() << " with a length of " << RingSize << "." << endl << endl);772 Log() << Verbose(0) << Walker->Name << " with a length of " << RingSize << "." << endl << endl; 778 773 // walk through all and set MinimumRingSize 779 774 Walker = BFS.Root; … … 787 782 MinRingSize = RingSize; 788 783 } else { 789 DoLog(1) && (Log() << Verbose(1) << "No ring containing " << *BFS.Root << " with length equal to or smaller than " << MinimumRingSize[Walker->GetTrueFather()->nr] << " found." << endl);784 Log() << Verbose(1) << "No ring containing " << *BFS.Root << " with length equal to or smaller than " << MinimumRingSize[Walker->GetTrueFather()->nr] << " found." << endl; 790 785 } 791 786 }; … … 865 860 866 861 } 867 DoLog(1) && (Log() << Verbose(1) << "Minimum ring size of " << *Root << " is " << MinimumRingSize[Root->GetTrueFather()->nr] << "." << endl);868 } 869 DoLog(1) && (Log() << Verbose(1) << "Minimum ring size is " << MinRingSize << ", over " << NumCycles << " cycles total." << endl);862 Log() << Verbose(1) << "Minimum ring size of " << *Root << " is " << MinimumRingSize[Root->GetTrueFather()->nr] << "." << endl; 863 } 864 Log() << Verbose(1) << "Minimum ring size is " << MinRingSize << ", over " << NumCycles << " cycles total." << endl; 870 865 } else 871 DoLog(1) && (Log() << Verbose(1) << "No rings were detected in the molecular structure." << endl);866 Log() << Verbose(1) << "No rings were detected in the molecular structure." << endl; 872 867 } 873 868 ; … … 897 892 //BackEdgeStack->Output(out); 898 893 899 DoLog(1) && (Log() << Verbose(1) << "Analysing cycles ... " << endl);894 Log() << Verbose(1) << "Analysing cycles ... " << endl; 900 895 NumCycles = 0; 901 896 while (!BackEdgeStack->IsEmpty()) { … … 908 903 ResetBFSAccounting(Walker, BFS); 909 904 910 DoLog(1) && (Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl);905 Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl; 911 906 OtherAtom = NULL; 912 907 CyclicStructureAnalysis_CyclicBFSFromRootToRoot(BackEdge, BFS); … … 937 932 break; // breaking here will not cause error! 938 933 } 939 if (i == vertex->ListOfBonds.size()) { 940 DoeLog(0) && (eLog()<< Verbose(0) << "Error: All Component entries are already occupied!" << endl); 941 performCriticalExit(); 942 } 943 } else { 944 DoeLog(0) && (eLog()<< Verbose(0) << "Error: Given vertex is NULL!" << endl); 945 performCriticalExit(); 946 } 934 if (i == vertex->ListOfBonds.size()) 935 eLog() << Verbose(0) << "Error: All Component entries are already occupied!" << endl; 936 } else 937 eLog() << Verbose(0) << "Error: Given vertex is NULL!" << endl; 947 938 } 948 939 ; … … 980 971 void OutputAlreadyVisited(int *list) 981 972 { 982 DoLog(4) && (Log() << Verbose(4) << "Already Visited Bonds:\t");973 Log() << Verbose(4) << "Already Visited Bonds:\t"; 983 974 for (int i = 1; i <= list[0]; i++) 984 DoLog(0) && (Log() << Verbose(0) << list[i] << " ");985 DoLog(0) && (Log() << Verbose(0) << endl);975 Log() << Verbose(0) << list[i] << " "; 976 Log() << Verbose(0) << endl; 986 977 } 987 978 ; … … 989 980 /** Storing the bond structure of a molecule to file. 990 981 * Simply stores Atom::nr and then the Atom::nr of all bond partners per line. 982 * \param *out output stream for debugging 991 983 * \param *path path to file 992 * \param *filename name of file993 984 * \return true - file written successfully, false - writing failed 994 985 */ 995 bool molecule::StoreAdjacencyToFile(char *path , char *filename)986 bool molecule::StoreAdjacencyToFile(char *path) 996 987 { 997 988 ofstream AdjacencyFile; … … 999 990 bool status = true; 1000 991 1001 if (path != NULL) 1002 line << path << "/" << filename; 1003 else 1004 line << filename; 992 line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE; 1005 993 AdjacencyFile.open(line.str().c_str(), ios::out); 1006 DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... ");994 Log() << Verbose(1) << "Saving adjacency list ... "; 1007 995 if (AdjacencyFile != NULL) { 1008 AdjacencyFile << "m\tn" << endl;1009 996 ActOnAllAtoms(&atom::OutputAdjacency, &AdjacencyFile); 1010 997 AdjacencyFile.close(); 1011 DoLog(1) && (Log() << Verbose(1) << "done." << endl);998 Log() << Verbose(1) << "done." << endl; 1012 999 } else { 1013 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl); 1014 status = false; 1015 } 1016 1017 return status; 1018 } 1019 ; 1020 1021 /** Storing the bond structure of a molecule to file. 1022 * Simply stores Atom::nr and then the Atom::nr of all bond partners, one per line. 1023 * \param *path path to file 1024 * \param *filename name of file 1025 * \return true - file written successfully, false - writing failed 1026 */ 1027 bool molecule::StoreBondsToFile(char *path, char *filename) 1028 { 1029 ofstream BondFile; 1030 stringstream line; 1031 bool status = true; 1032 1033 if (path != NULL) 1034 line << path << "/" << filename; 1035 else 1036 line << filename; 1037 BondFile.open(line.str().c_str(), ios::out); 1038 DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... "); 1039 if (BondFile != NULL) { 1040 BondFile << "m\tn" << endl; 1041 ActOnAllAtoms(&atom::OutputBonds, &BondFile); 1042 BondFile.close(); 1043 DoLog(1) && (Log() << Verbose(1) << "done." << endl); 1044 } else { 1045 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl); 1000 Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl; 1046 1001 status = false; 1047 1002 } … … 1056 1011 filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE; 1057 1012 File.open(filename.str().c_str(), ios::out); 1058 DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... ");1013 Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... "; 1059 1014 if (File == NULL) 1060 1015 return false; … … 1097 1052 //Log() << Verbose(0) << endl; 1098 1053 } else { 1099 DoLog(0) && (Log() << Verbose(0) << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << Walker->ListOfBonds.size() << "." << endl);1054 Log() << Verbose(0) << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << Walker->ListOfBonds.size() << "." << endl; 1100 1055 status = false; 1101 1056 } … … 1120 1075 1121 1076 if (!CheckAdjacencyFileAgainstMolecule_Init(path, File, CurrentBonds)) { 1122 DoLog(1) && (Log() << Verbose(1) << "Adjacency file not found." << endl);1077 Log() << Verbose(1) << "Adjacency file not found." << endl; 1123 1078 return true; 1124 1079 } … … 1146 1101 1147 1102 if (status) { // if equal we parse the KeySetFile 1148 DoLog(1) && (Log() << Verbose(1) << "done: Equal." << endl);1103 Log() << Verbose(1) << "done: Equal." << endl; 1149 1104 } else 1150 DoLog(1) && (Log() << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl);1105 Log() << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl; 1151 1106 return status; 1152 1107 } … … 1164 1119 bool status = true; 1165 1120 if (ReferenceStack->IsEmpty()) { 1166 DoLog(1) && (Log() << Verbose(1) << "ReferenceStack is empty!" << endl);1121 eLog() << Verbose(0) << "ReferenceStack is empty!" << endl; 1167 1122 return false; 1168 1123 } … … 1179 1134 if (OtherAtom == ListOfLocalAtoms[(*Runner)->rightatom->nr]) { // found the bond 1180 1135 LocalStack->Push((*Runner)); 1181 DoLog(3) && (Log() << Verbose(3) << "Found local edge " << *(*Runner) << "." << endl);1136 Log() << Verbose(3) << "Found local edge " << *(*Runner) << "." << endl; 1182 1137 break; 1183 1138 } 1184 1139 } 1185 1140 Binder = ReferenceStack->PopFirst(); // loop the stack for next item 1186 DoLog(3) && (Log() << Verbose(3) << "Current candidate edge " << Binder << "." << endl);1141 Log() << Verbose(3) << "Current candidate edge " << Binder << "." << endl; 1187 1142 ReferenceStack->Push(Binder); 1188 1143 } while (FirstBond != Binder); … … 1233 1188 BFS.PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor 1234 1189 BFS.ShortestPathList[OtherAtom->nr] = BFS.ShortestPathList[Walker->nr] + 1; 1235 DoLog(2) && (Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->getName() << " " << ((BFS.ColorList[OtherAtom->nr] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->getName() << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl);1190 Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " " << ((BFS.ColorList[OtherAtom->nr] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->Name << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl; 1236 1191 if ((((BFS.ShortestPathList[OtherAtom->nr] < BFS.BondOrder) && (Binder != Bond)))) { // Check for maximum distance 1237 DoLog(3) && (Log() << Verbose(3));1192 Log() << Verbose(3); 1238 1193 if (AddedAtomList[OtherAtom->nr] == NULL) { // add if it's not been so far 1239 1194 AddedAtomList[OtherAtom->nr] = Mol->AddCopyAtom(OtherAtom); 1240 DoLog(0) && (Log() << Verbose(0) << "Added OtherAtom " << OtherAtom->getName());1195 Log() << Verbose(0) << "Added OtherAtom " << OtherAtom->Name; 1241 1196 AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder); 1242 DoLog(0) && (Log() << Verbose(0) << " and bond " << *(AddedBondList[Binder->nr]) << ", ");1197 Log() << Verbose(0) << " and bond " << *(AddedBondList[Binder->nr]) << ", "; 1243 1198 } else { // this code should actually never come into play (all white atoms are not yet present in BondMolecule, that's why they are white in the first place) 1244 DoLog(0) && (Log() << Verbose(0) << "Not adding OtherAtom " << OtherAtom->getName());1199 Log() << Verbose(0) << "Not adding OtherAtom " << OtherAtom->Name; 1245 1200 if (AddedBondList[Binder->nr] == NULL) { 1246 1201 AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder); 1247 DoLog(0) && (Log() << Verbose(0) << ", added Bond " << *(AddedBondList[Binder->nr]));1202 Log() << Verbose(0) << ", added Bond " << *(AddedBondList[Binder->nr]); 1248 1203 } else 1249 DoLog(0) && (Log() << Verbose(0) << ", not added Bond ");1250 } 1251 DoLog(0) && (Log() << Verbose(0) << ", putting OtherAtom into queue." << endl);1204 Log() << Verbose(0) << ", not added Bond "; 1205 } 1206 Log() << Verbose(0) << ", putting OtherAtom into queue." << endl; 1252 1207 BFS.BFSStack->Push(OtherAtom); 1253 1208 } else { // out of bond order, then replace … … 1255 1210 BFS.ColorList[OtherAtom->nr] = white; // unmark if it has not been queued/added, to make it available via its other bonds (cyclic) 1256 1211 if (Binder == Bond) 1257 DoLog(3) && (Log() << Verbose(3) << "Not Queueing, is the Root bond");1212 Log() << Verbose(3) << "Not Queueing, is the Root bond"; 1258 1213 else if (BFS.ShortestPathList[OtherAtom->nr] >= BFS.BondOrder) 1259 DoLog(3) && (Log() << Verbose(3) << "Not Queueing, is out of Bond Count of " << BFS.BondOrder);1214 Log() << Verbose(3) << "Not Queueing, is out of Bond Count of " << BFS.BondOrder; 1260 1215 if (!Binder->Cyclic) 1261 DoLog(0) && (Log() << Verbose(0) << ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl);1216 Log() << Verbose(0) << ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl; 1262 1217 if (AddedBondList[Binder->nr] == NULL) { 1263 1218 if ((AddedAtomList[OtherAtom->nr] != NULL)) { // .. whether we add or saturate … … 1276 1231 void BreadthFirstSearchAdd_VisitedNode(molecule *Mol, struct BFSAccounting &BFS, atom *&Walker, atom *&OtherAtom, bond *&Binder, bond *&Bond, atom **&AddedAtomList, bond **&AddedBondList, bool IsAngstroem) 1277 1232 { 1278 DoLog(3) && (Log() << Verbose(3) << "Not Adding, has already been visited." << endl);1233 Log() << Verbose(3) << "Not Adding, has already been visited." << endl; 1279 1234 // This has to be a cyclic bond, check whether it's present ... 1280 1235 if (AddedBondList[Binder->nr] == NULL) { … … 1322 1277 // followed by n+1 till top of stack. 1323 1278 Walker = BFS.BFSStack->PopFirst(); // pop oldest added 1324 DoLog(1) && (Log() << Verbose(1) << "Current Walker is: " << Walker->getName() << ", and has " << Walker->ListOfBonds.size() << " bonds." << endl);1279 Log() << Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << Walker->ListOfBonds.size() << " bonds." << endl; 1325 1280 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 1326 1281 if ((*Runner) != NULL) { // don't look at bond equal NULL 1327 1282 Binder = (*Runner); 1328 1283 OtherAtom = (*Runner)->GetOtherAtom(Walker); 1329 DoLog(2) && (Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->getName() << " for bond " << *(*Runner) << "." << endl);1284 Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl; 1330 1285 if (BFS.ColorList[OtherAtom->nr] == white) { 1331 1286 BreadthFirstSearchAdd_UnvisitedNode(Mol, BFS, Walker, OtherAtom, Binder, Bond, AddedAtomList, AddedBondList, IsAngstroem); … … 1336 1291 } 1337 1292 BFS.ColorList[Walker->nr] = black; 1338 DoLog(1) && (Log() << Verbose(1) << "Coloring Walker " << Walker->getName() << " black." << endl);1293 Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl; 1339 1294 } 1340 1295 BreadthFirstSearchAdd_Free(BFS); … … 1361 1316 // reset parent list 1362 1317 ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList"); 1363 DoLog(3) && (Log() << Verbose(3) << "Resetting ParentList." << endl);1318 Log() << Verbose(3) << "Resetting ParentList." << endl; 1364 1319 } 1365 1320 ; … … 1368 1323 { 1369 1324 // fill parent list with sons 1370 DoLog(3) && (Log() << Verbose(3) << "Filling Parent List." << endl);1325 Log() << Verbose(3) << "Filling Parent List." << endl; 1371 1326 atom *Walker = mol->start; 1372 1327 while (Walker->next != mol->end) { … … 1374 1329 ParentList[Walker->father->nr] = Walker; 1375 1330 // Outputting List for debugging 1376 DoLog(4) && (Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl);1331 Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl; 1377 1332 } 1378 1333 … … 1392 1347 atom *OtherAtom = NULL; 1393 1348 // check each entry of parent list and if ok (one-to-and-onto matching) create bonds 1394 DoLog(3) && (Log() << Verbose(3) << "Creating bonds." << endl);1349 Log() << Verbose(3) << "Creating bonds." << endl; 1395 1350 Walker = Father->start; 1396 1351 while (Walker->next != Father->end) { … … 1403 1358 OtherAtom = (*Runner)->GetOtherAtom(Walker); 1404 1359 if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond 1405 DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->getName() << " and " << ParentList[OtherAtom->nr]->getName() << "." << endl);1360 Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl; 1406 1361 mol->AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree); 1407 1362 } … … 1428 1383 atom **ParentList = NULL; 1429 1384 1430 DoLog(2) && (Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl);1385 Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl; 1431 1386 BuildInducedSubgraph_Init(ParentList, Father->AtomCount); 1432 1387 BuildInducedSubgraph_FillParentList(this, Father, ParentList); 1433 1388 status = BuildInducedSubgraph_CreateBondsFromParent(this, Father, ParentList); 1434 1389 BuildInducedSubgraph_Finalize(ParentList); 1435 DoLog(2) && (Log() << Verbose(2) << "End of BuildInducedSubgraph." << endl);1390 Log() << Verbose(2) << "End of BuildInducedSubgraph." << endl; 1436 1391 return status; 1437 1392 } … … 1450 1405 int size; 1451 1406 1452 DoLog(1) && (Log() << Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl);1453 DoLog(2) && (Log() << Verbose(2) << "Disconnected atom: ");1407 Log() << Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl; 1408 Log() << Verbose(2) << "Disconnected atom: "; 1454 1409 1455 1410 // count number of atoms in graph … … 1473 1428 } 1474 1429 if (!BondStatus) { 1475 DoLog(0) && (Log() << Verbose(0) << (*Walker) << endl);1430 Log() << Verbose(0) << (*Walker) << endl; 1476 1431 return false; 1477 1432 } 1478 1433 } 1479 1434 else { 1480 DoLog(0) && (Log() << Verbose(0) << "none." << endl);1435 Log() << Verbose(0) << "none." << endl; 1481 1436 return true; 1482 1437 } 1483 DoLog(0) && (Log() << Verbose(0) << "none." << endl);1484 1485 DoLog(1) && (Log() << Verbose(1) << "End of CheckForConnectedSubgraph" << endl);1438 Log() << Verbose(0) << "none." << endl; 1439 1440 Log() << Verbose(1) << "End of CheckForConnectedSubgraph" << endl; 1486 1441 1487 1442 return true;
Note:
See TracChangeset
for help on using the changeset viewer.