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