Changeset 543ce4 for molecuilder/src/molecule_graph.cpp
- Timestamp:
- Nov 4, 2009, 7:56:04 PM (16 years ago)
- Children:
- 4ef101, aa8542
- Parents:
- ec70ec
- File:
-
- 1 edited
-
molecuilder/src/molecule_graph.cpp (modified) (83 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/molecule_graph.cpp
rec70ec r543ce4 14 14 #include "linkedcell.hpp" 15 15 #include "lists.hpp" 16 #include "log.hpp" 16 17 #include "memoryallocator.hpp" 17 18 #include "molecule.hpp" … … 49 50 * We obtain an outside file with the indices of atoms which are bondmembers. 50 51 */ 51 void molecule::CreateAdjacencyListFromDbondFile( ofstream *out,ifstream *input)52 void molecule::CreateAdjacencyListFromDbondFile(ifstream *input) 52 53 { 53 54 … … 57 58 58 59 if (!input) { 59 cout<< Verbose(1) << "Opening silica failed \n";60 Log() << Verbose(1) << "Opening silica failed \n"; 60 61 }; 61 62 62 63 *input >> ws >> atom1; 63 64 *input >> ws >> atom2; 64 cout<< Verbose(1) << "Scanning file\n";65 Log() << Verbose(1) << "Scanning file\n"; 65 66 while (!input->eof()) // Check whether we read everything already 66 67 { … … 96 97 * \param *BG BondGraph with the member function above or NULL, if just standard covalent should be used. 97 98 */ 98 void molecule::CreateAdjacencyList( ofstream *out,double bonddistance, bool IsAngstroem, void (BondGraph::*minmaxdistance)(BondedParticle * const , BondedParticle * const , double &, double &, bool), BondGraph *BG)99 void molecule::CreateAdjacencyList(double bonddistance, bool IsAngstroem, void (BondGraph::*minmaxdistance)(BondedParticle * const , BondedParticle * const , double &, double &, bool), BondGraph *BG) 99 100 { 100 101 atom *Walker = NULL; … … 112 113 113 114 BondDistance = bonddistance; // * ((IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem); 114 *out<< Verbose(0) << "Begin of CreateAdjacencyList." << endl;115 Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl; 115 116 // remove every bond from the list 116 117 bond *Binder = NULL; … … 124 125 125 126 // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering) 126 CountAtoms( out);127 *out<< Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl;127 CountAtoms(); 128 Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl; 128 129 129 130 if ((AtomCount > 1) && (bonddistance > 1.)) { 130 *out<< Verbose(2) << "Creating Linked Cell structure ... " << endl;131 Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl; 131 132 LC = new LinkedCell(this, bonddistance); 132 133 133 134 // create a list to map Tesselpoint::nr to atom * 134 *out<< Verbose(2) << "Creating TesselPoint to atom map ... " << endl;135 Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl; 135 136 AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount"); 136 137 Walker = start; … … 141 142 142 143 // 3a. go through every cell 143 *out<< Verbose(2) << "Celling ... " << endl;144 Log() << Verbose(2) << "Celling ... " << endl; 144 145 for (LC->n[0] = 0; LC->n[0] < LC->N[0]; LC->n[0]++) 145 146 for (LC->n[1] = 0; LC->n[1] < LC->N[1]; LC->n[1]++) 146 147 for (LC->n[2] = 0; LC->n[2] < LC->N[2]; LC->n[2]++) { 147 148 const LinkedNodes *List = LC->GetCurrentCell(); 148 // *out<< Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;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; 149 150 if (List != NULL) { 150 151 for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 151 152 Walker = AtomMap[(*Runner)->nr]; 152 // *out<< Verbose(0) << "Current Atom is " << *Walker << "." << endl;153 //Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl; 153 154 // 3c. check for possible bond between each atom in this and every one in the 27 cells 154 155 for (n[0] = -1; n[0] <= 1; n[0]++) … … 156 157 for (n[2] = -1; n[2] <= 1; n[2]++) { 157 158 const LinkedNodes *OtherList = LC->GetRelativeToCurrentCell(n); 158 // *out<< Verbose(2) << "Current relative cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;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; 159 160 if (OtherList != NULL) { 160 161 for (LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) { 161 162 if ((*OtherRunner)->nr > Walker->nr) { 162 163 OtherWalker = AtomMap[(*OtherRunner)->nr]; 163 // *out<< Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl;164 //Log() << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl; 164 165 (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem); 165 166 const double distance = OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size); 166 167 const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance); 167 168 if ((OtherWalker->father->nr > Walker->father->nr) && (status)) { // create bond if distance is smaller 168 // *out<< Verbose(1) << "Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << "." << endl;169 //Log() << Verbose(1) << "Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << "." << endl; 169 170 AddBond(Walker->father, OtherWalker->father, 1); // also increases molecule::BondCount 170 171 } else { 171 // *out<< Verbose(1) << "Not Adding: Wrong label order or distance too great." << endl;172 //Log() << Verbose(1) << "Not Adding: Wrong label order or distance too great." << endl; 172 173 } 173 174 } … … 180 181 Free(&AtomMap); 181 182 delete (LC); 182 *out<< Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl;183 Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl; 183 184 184 185 // correct bond degree by comparing valence and bond degree 185 *out<< Verbose(2) << "Correcting bond degree ... " << endl;186 CorrectBondDegree( out);186 Log() << Verbose(2) << "Correcting bond degree ... " << endl; 187 CorrectBondDegree(); 187 188 188 189 // output bonds for debugging (if bond chain list was correctly installed) 189 ActOnAllAtoms( &atom::OutputBondOfAtom, out);190 ActOnAllAtoms( &atom::OutputBondOfAtom ); 190 191 } else 191 *out<< Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;192 *out<< Verbose(0) << "End of CreateAdjacencyList." << endl;192 Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl; 193 Log() << Verbose(0) << "End of CreateAdjacencyList." << endl; 193 194 if (free_BG) 194 195 delete(BG); … … 199 200 * \param output stream 200 201 */ 201 void molecule::OutputBondsList( ofstream *out) const202 { 203 *out<< Verbose(1) << endl << "From contents of bond chain list:";202 void molecule::OutputBondsList() const 203 { 204 Log() << Verbose(1) << endl << "From contents of bond chain list:"; 204 205 bond *Binder = first; 205 206 while (Binder->next != last) { 206 207 Binder = Binder->next; 207 *out<< *Binder << "\t" << endl;208 } 209 *out<< endl;208 Log() << Verbose(0) << *Binder << "\t" << endl; 209 } 210 Log() << Verbose(0) << endl; 210 211 } 211 212 ; … … 219 220 * \return number of bonds that could not be corrected 220 221 */ 221 int molecule::CorrectBondDegree( ofstream *out) const222 int molecule::CorrectBondDegree() const 222 223 { 223 224 int No = 0, OldNo = -1; 224 225 225 226 if (BondCount != 0) { 226 *out<< Verbose(1) << "Correcting Bond degree of each bond ... " << endl;227 Log() << Verbose(1) << "Correcting Bond degree of each bond ... " << endl; 227 228 do { 228 229 OldNo = No; 229 No = SumPerAtom( &atom::CorrectBondDegree, out);230 No = SumPerAtom( &atom::CorrectBondDegree ); 230 231 } while (OldNo != No); 231 *out<< " done." << endl;232 Log() << Verbose(0) << " done." << endl; 232 233 } else { 233 *out<< Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl;234 } 235 *out<< No << " bonds could not be corrected." << endl;234 Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl; 235 } 236 Log() << Verbose(0) << No << " bonds could not be corrected." << endl; 236 237 237 238 return (No); … … 244 245 * \return number opf cyclic bonds 245 246 */ 246 int molecule::CountCyclicBonds( ofstream *out)247 int molecule::CountCyclicBonds() 247 248 { 248 249 NoCyclicBonds = 0; … … 252 253 bond *Binder = first; 253 254 if ((Binder->next != last) && (Binder->next->Type == Undetermined)) { 254 *out<< Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl;255 Subgraphs = DepthFirstSearchAnalysis( out,BackEdgeStack);255 Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl; 256 Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack); 256 257 while (Subgraphs->next != NULL) { 257 258 Subgraphs = Subgraphs->next; … … 302 303 * \param &BFS structure with accounting data for BFS 303 304 */ 304 void DepthFirstSearchAnalysis_SetWalkersGraphNr( ofstream *out,atom *&Walker, struct DFSAccounting &DFS)305 void DepthFirstSearchAnalysis_SetWalkersGraphNr(atom *&Walker, struct DFSAccounting &DFS) 305 306 { 306 307 if (!DFS.BackStepping) { // if we don't just return from (8) 307 308 Walker->GraphNr = DFS.CurrentGraphNr; 308 309 Walker->LowpointNr = DFS.CurrentGraphNr; 309 *out<< Verbose(1) << "Setting Walker[" << Walker->Name << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << "." << endl;310 Log() << Verbose(1) << "Setting Walker[" << Walker->Name << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << "." << endl; 310 311 DFS.AtomStack->Push(Walker); 311 312 DFS.CurrentGraphNr++; … … 324 325 * \param &DFS DFS accounting data 325 326 */ 326 void DepthFirstSearchAnalysis_ProbeAlongUnusedBond( ofstream *out,const molecule * const mol, atom *&Walker, bond *&Binder, struct DFSAccounting &DFS)327 void DepthFirstSearchAnalysis_ProbeAlongUnusedBond(const molecule * const mol, atom *&Walker, bond *&Binder, struct DFSAccounting &DFS) 327 328 { 328 329 atom *OtherAtom = NULL; … … 334 335 if (Binder == NULL) 335 336 break; 336 *out<< Verbose(2) << "Current Unused Bond is " << *Binder << "." << endl;337 Log() << Verbose(2) << "Current Unused Bond is " << *Binder << "." << endl; 337 338 // (4) Mark Binder used, ... 338 339 Binder->MarkUsed(black); 339 340 OtherAtom = Binder->GetOtherAtom(Walker); 340 *out<< Verbose(2) << "(4) OtherAtom is " << OtherAtom->Name << "." << endl;341 Log() << Verbose(2) << "(4) OtherAtom is " << OtherAtom->Name << "." << endl; 341 342 if (OtherAtom->GraphNr != -1) { 342 343 // (4a) ... if "other" atom has been visited (GraphNr != 0), set lowpoint to minimum of both, go to (3) … … 344 345 DFS.BackEdgeStack->Push(Binder); 345 346 Walker->LowpointNr = (Walker->LowpointNr < OtherAtom->GraphNr) ? Walker->LowpointNr : OtherAtom->GraphNr; 346 *out<< Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->Name << "] to " << Walker->LowpointNr << "." << endl;347 Log() << Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->Name << "] to " << Walker->LowpointNr << "." << endl; 347 348 } else { 348 349 // (4b) ... otherwise set OtherAtom as Ancestor of Walker and Walker as OtherAtom, go to (2) … … 350 351 OtherAtom->Ancestor = Walker; 351 352 Walker = OtherAtom; 352 *out<< Verbose(3) << "(4b) Not Visited: OtherAtom[" << OtherAtom->Name << "]'s Ancestor is now " << OtherAtom->Ancestor->Name << ", Walker is OtherAtom " << OtherAtom->Name << "." << endl;353 Log() << Verbose(3) << "(4b) Not Visited: OtherAtom[" << OtherAtom->Name << "]'s Ancestor is now " << OtherAtom->Ancestor->Name << ", Walker is OtherAtom " << OtherAtom->Name << "." << endl; 353 354 break; 354 355 } … … 367 368 * \param &DFS DFS accounting data 368 369 */ 369 void DepthFirstSearchAnalysis_CheckForaNewComponent( ofstream *out,const molecule * const mol, atom *&Walker, struct DFSAccounting &DFS, MoleculeLeafClass *&LeafWalker)370 void DepthFirstSearchAnalysis_CheckForaNewComponent(const molecule * const mol, atom *&Walker, struct DFSAccounting &DFS, MoleculeLeafClass *&LeafWalker) 370 371 { 371 372 atom *OtherAtom = NULL; 372 373 373 374 // (5) if Ancestor of Walker is ... 374 *out<< Verbose(1) << "(5) Number of Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "] is " << Walker->Ancestor->GraphNr << "." << endl;375 Log() << Verbose(1) << "(5) Number of Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "] is " << Walker->Ancestor->GraphNr << "." << endl; 375 376 376 377 if (Walker->Ancestor->GraphNr != DFS.Root->GraphNr) { … … 379 380 // (6a) set Ancestor's Lowpoint number to minimum of of its Ancestor and itself, go to Step(8) 380 381 Walker->Ancestor->LowpointNr = (Walker->Ancestor->LowpointNr < Walker->LowpointNr) ? Walker->Ancestor->LowpointNr : Walker->LowpointNr; 381 *out<< Verbose(2) << "(6) Setting Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << "." << endl;382 Log() << Verbose(2) << "(6) Setting Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << "." << endl; 382 383 } else { 383 384 // (7) (Ancestor of Walker is a separating vertex, remove all from stack till Walker (including), these and Ancestor form a component 384 385 Walker->Ancestor->SeparationVertex = true; 385 *out<< Verbose(2) << "(7) Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s is a separating vertex, creating component." << endl;386 Log() << Verbose(2) << "(7) Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s is a separating vertex, creating component." << endl; 386 387 mol->SetNextComponentNumber(Walker->Ancestor, DFS.ComponentNumber); 387 *out<< Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Ancestor's Compont is " << DFS.ComponentNumber << "." << endl;388 Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Ancestor's Compont is " << DFS.ComponentNumber << "." << endl; 388 389 mol->SetNextComponentNumber(Walker, DFS.ComponentNumber); 389 *out<< Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl;390 Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl; 390 391 do { 391 392 OtherAtom = DFS.AtomStack->PopLast(); 392 393 LeafWalker->Leaf->AddCopyAtom(OtherAtom); 393 394 mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber); 394 *out<< Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl;395 Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl; 395 396 } while (OtherAtom != Walker); 396 397 DFS.ComponentNumber++; 397 398 } 398 399 // (8) Walker becomes its Ancestor, go to (3) 399 *out<< Verbose(2) << "(8) Walker[" << Walker->Name << "] is now its Ancestor " << Walker->Ancestor->Name << ", backstepping. " << endl;400 Log() << Verbose(2) << "(8) Walker[" << Walker->Name << "] is now its Ancestor " << Walker->Ancestor->Name << ", backstepping. " << endl; 400 401 Walker = Walker->Ancestor; 401 402 DFS.BackStepping = true; … … 413 414 * \param &DFS DFS accounting data 414 415 */ 415 void DepthFirstSearchAnalysis_CleanRootStackDownTillWalker( ofstream *out,const molecule * const mol, atom *&Walker, bond *&Binder, struct DFSAccounting &DFS, MoleculeLeafClass *&LeafWalker)416 void DepthFirstSearchAnalysis_CleanRootStackDownTillWalker(const molecule * const mol, atom *&Walker, bond *&Binder, struct DFSAccounting &DFS, MoleculeLeafClass *&LeafWalker) 416 417 { 417 418 atom *OtherAtom = NULL; … … 421 422 //DFS.AtomStack->Output(out); 422 423 mol->SetNextComponentNumber(DFS.Root, DFS.ComponentNumber); 423 *out<< Verbose(3) << "(9) Root[" << DFS.Root->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl;424 Log() << Verbose(3) << "(9) Root[" << DFS.Root->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl; 424 425 mol->SetNextComponentNumber(Walker, DFS.ComponentNumber); 425 *out<< Verbose(3) << "(9) Walker[" << Walker->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl;426 Log() << Verbose(3) << "(9) Walker[" << Walker->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl; 426 427 do { 427 428 OtherAtom = DFS.AtomStack->PopLast(); 428 429 LeafWalker->Leaf->AddCopyAtom(OtherAtom); 429 430 mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber); 430 *out<< Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl;431 Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl; 431 432 } while (OtherAtom != Walker); 432 433 DFS.ComponentNumber++; … … 435 436 Walker = DFS.Root; 436 437 Binder = mol->FindNextUnused(Walker); 437 *out<< Verbose(1) << "(10) Walker is Root[" << DFS.Root->Name << "], next Unused Bond is " << Binder << "." << endl;438 Log() << Verbose(1) << "(10) Walker is Root[" << DFS.Root->Name << "], next Unused Bond is " << Binder << "." << endl; 438 439 if (Binder != NULL) { // Root is separation vertex 439 *out<< Verbose(1) << "(11) Root is a separation vertex." << endl;440 Log() << Verbose(1) << "(11) Root is a separation vertex." << endl; 440 441 Walker->SeparationVertex = true; 441 442 } … … 449 450 * \param *mol molecule with AtomCount, BondCount and all atoms 450 451 */ 451 void DepthFirstSearchAnalysis_Init( ofstream *out,struct DFSAccounting &DFS, const molecule * const mol)452 void DepthFirstSearchAnalysis_Init(struct DFSAccounting &DFS, const molecule * const mol) 452 453 { 453 454 DFS.AtomStack = new StackClass<atom *> (mol->AtomCount); … … 466 467 * \param &DFS accounting structure to free 467 468 */ 468 void DepthFirstSearchAnalysis_Finalize( ofstream *out,struct DFSAccounting &DFS)469 void DepthFirstSearchAnalysis_Finalize(struct DFSAccounting &DFS) 469 470 { 470 471 delete (DFS.AtomStack); … … 481 482 * \return list of each disconnected subgraph as an individual molecule class structure 482 483 */ 483 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis( ofstream *out,class StackClass<bond *> *&BackEdgeStack) const484 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(class StackClass<bond *> *&BackEdgeStack) const 484 485 { 485 486 struct DFSAccounting DFS; … … 492 493 bond *Binder = NULL; 493 494 494 *out<< Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl;495 DepthFirstSearchAnalysis_Init( out,DFS, this);495 Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl; 496 DepthFirstSearchAnalysis_Init(DFS, this); 496 497 497 498 DFS.Root = start->next; … … 509 510 do { // (10) 510 511 do { // (2) set number and Lowpoint of Atom to i, increase i, push current atom 511 DepthFirstSearchAnalysis_SetWalkersGraphNr( out,Walker, DFS);512 513 DepthFirstSearchAnalysis_ProbeAlongUnusedBond( out,this, Walker, Binder, DFS);512 DepthFirstSearchAnalysis_SetWalkersGraphNr(Walker, DFS); 513 514 DepthFirstSearchAnalysis_ProbeAlongUnusedBond(this, Walker, Binder, DFS); 514 515 515 516 if (Binder == NULL) { 516 *out<< Verbose(2) << "No more Unused Bonds." << endl;517 Log() << Verbose(2) << "No more Unused Bonds." << endl; 517 518 break; 518 519 } else … … 524 525 break; 525 526 526 DepthFirstSearchAnalysis_CheckForaNewComponent( out,this, Walker, DFS, LeafWalker);527 528 DepthFirstSearchAnalysis_CleanRootStackDownTillWalker( out,this, Walker, Binder, DFS, LeafWalker);527 DepthFirstSearchAnalysis_CheckForaNewComponent(this, Walker, DFS, LeafWalker); 528 529 DepthFirstSearchAnalysis_CleanRootStackDownTillWalker(this, Walker, Binder, DFS, LeafWalker); 529 530 530 531 } while ((DFS.BackStepping) || (Binder != NULL)); // (10) halt only if Root has no unused edges 531 532 532 533 // From OldGraphNr to CurrentGraphNr ranges an disconnected subgraph 533 *out<< Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << DFS.CurrentGraphNr << "." << endl;534 LeafWalker->Leaf->Output( out);535 *out<< endl;534 Log() << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << DFS.CurrentGraphNr << "." << endl; 535 LeafWalker->Leaf->Output((ofstream *)&cout); 536 Log() << Verbose(0) << endl; 536 537 537 538 // step on to next root 538 539 while ((DFS.Root != end) && (DFS.Root->GraphNr != -1)) { 539 // *out<< Verbose(1) << "Current next subgraph root candidate is " << Root->Name << "." << endl;540 //Log() << Verbose(1) << "Current next subgraph root candidate is " << Root->Name << "." << endl; 540 541 if (DFS.Root->GraphNr != -1) // if already discovered, step on 541 542 DFS.Root = DFS.Root->next; … … 545 546 CyclicBondAnalysis(); 546 547 547 OutputGraphInfoPerAtom( out);548 549 OutputGraphInfoPerBond( out);548 OutputGraphInfoPerAtom(); 549 550 OutputGraphInfoPerBond(); 550 551 551 552 // free all and exit 552 DepthFirstSearchAnalysis_Finalize( out,DFS);553 *out<< Verbose(0) << "End of DepthFirstSearchAnalysis" << endl;553 DepthFirstSearchAnalysis_Finalize(DFS); 554 Log() << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl; 554 555 return SubGraphs; 555 556 } … … 575 576 * \param *out output stream 576 577 */ 577 void molecule::OutputGraphInfoPerAtom( ofstream *out) const578 { 579 *out<< Verbose(1) << "Final graph info for each atom is:" << endl;580 ActOnAllAtoms( &atom::OutputGraphInfo, out);578 void molecule::OutputGraphInfoPerAtom() const 579 { 580 Log() << Verbose(1) << "Final graph info for each atom is:" << endl; 581 ActOnAllAtoms( &atom::OutputGraphInfo ); 581 582 } 582 583 ; … … 585 586 * \param *out output stream 586 587 */ 587 void molecule::OutputGraphInfoPerBond( ofstream *out) const588 { 589 *out<< Verbose(1) << "Final graph info for each bond is:" << endl;588 void molecule::OutputGraphInfoPerBond() const 589 { 590 Log() << Verbose(1) << "Final graph info for each bond is:" << endl; 590 591 bond *Binder = first; 591 592 while (Binder->next != last) { 592 593 Binder = Binder->next; 593 *out<< Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <";594 *out<< ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.";595 Binder->leftatom->OutputComponentNumber( out);596 *out<< " === ";597 *out<< ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.";598 Binder->rightatom->OutputComponentNumber( out);599 *out<< ">." << endl;594 Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <"; 595 Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp."; 596 Binder->leftatom->OutputComponentNumber(); 597 Log() << Verbose(0) << " === "; 598 Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp."; 599 Binder->rightatom->OutputComponentNumber(); 600 Log() << Verbose(0) << ">." << endl; 600 601 if (Binder->Cyclic) // cyclic ?? 601 *out<< Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl;602 Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl; 602 603 } 603 604 } … … 609 610 * \param AtomCount number of entries in the array to allocate 610 611 */ 611 void InitializeBFSAccounting( ofstream *out,struct BFSAccounting &BFS, int AtomCount)612 void InitializeBFSAccounting(struct BFSAccounting &BFS, int AtomCount) 612 613 { 613 614 BFS.AtomCount = AtomCount; … … 625 626 * \param &BFS accounting structure 626 627 */ 627 void FinalizeBFSAccounting( ofstream *out,struct BFSAccounting &BFS)628 void FinalizeBFSAccounting(struct BFSAccounting &BFS) 628 629 { 629 630 Free(&BFS.PredecessorList); … … 638 639 * \param &BFS accounting structure 639 640 */ 640 void CleanBFSAccounting( ofstream *out,struct BFSAccounting &BFS)641 void CleanBFSAccounting(struct BFSAccounting &BFS) 641 642 { 642 643 atom *Walker = NULL; … … 654 655 * \param &BFS accounting structure 655 656 */ 656 void ResetBFSAccounting( ofstream *out,atom *&Walker, struct BFSAccounting &BFS)657 void ResetBFSAccounting(atom *&Walker, struct BFSAccounting &BFS) 657 658 { 658 659 BFS.ShortestPathList[Walker->nr] = 0; … … 667 668 * \param &BFS accounting structure 668 669 */ 669 void CyclicStructureAnalysis_CyclicBFSFromRootToRoot( ofstream *out,bond *&BackEdge, struct BFSAccounting &BFS)670 void CyclicStructureAnalysis_CyclicBFSFromRootToRoot(bond *&BackEdge, struct BFSAccounting &BFS) 670 671 { 671 672 atom *Walker = NULL; … … 673 674 do { // look for Root 674 675 Walker = BFS.BFSStack->PopFirst(); 675 *out<< Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *BFS.Root << "." << endl;676 Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *BFS.Root << "." << endl; 676 677 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 677 678 if ((*Runner) != BackEdge) { // only walk along DFS spanning tree (otherwise we always find SP of one being backedge Binder) … … 680 681 if (OtherAtom->type->Z != 1) { 681 682 #endif 682 *out<< Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl;683 Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl; 683 684 if (BFS.ColorList[OtherAtom->nr] == white) { 684 685 BFS.TouchedStack->Push(OtherAtom); … … 686 687 BFS.PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor 687 688 BFS.ShortestPathList[OtherAtom->nr] = BFS.ShortestPathList[Walker->nr] + 1; 688 *out<< 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;689 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; 689 690 //if (BFS.ShortestPathList[OtherAtom->nr] < MinimumRingSize[Walker->GetTrueFather()->nr]) { // Check for maximum distance 690 *out<< Verbose(3) << "Putting OtherAtom into queue." << endl;691 Log() << Verbose(3) << "Putting OtherAtom into queue." << endl; 691 692 BFS.BFSStack->Push(OtherAtom); 692 693 //} 693 694 } else { 694 *out<< Verbose(3) << "Not Adding, has already been visited." << endl;695 Log() << Verbose(3) << "Not Adding, has already been visited." << endl; 695 696 } 696 697 if (OtherAtom == BFS.Root) … … 698 699 #ifdef ADDHYDROGEN 699 700 } else { 700 *out<< Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl;701 Log() << Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl; 701 702 BFS.ColorList[OtherAtom->nr] = black; 702 703 } 703 704 #endif 704 705 } else { 705 *out<< Verbose(2) << "Bond " << *(*Runner) << " not Visiting, is the back edge." << endl;706 Log() << Verbose(2) << "Bond " << *(*Runner) << " not Visiting, is the back edge." << endl; 706 707 } 707 708 } 708 709 BFS.ColorList[Walker->nr] = black; 709 *out<< Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;710 Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl; 710 711 if (OtherAtom == BFS.Root) { // if we have found the root, check whether this cycle wasn't already found beforehand 711 712 // step through predecessor list … … 717 718 } 718 719 if (OtherAtom == BackEdge->rightatom) { // if each atom in found cycle is cyclic, loop's been found before already 719 *out<< Verbose(3) << "This cycle was already found before, skipping and removing seeker from search." << endl;720 Log() << Verbose(3) << "This cycle was already found before, skipping and removing seeker from search." << endl; 720 721 do { 721 722 OtherAtom = BFS.TouchedStack->PopLast(); 722 723 if (BFS.PredecessorList[OtherAtom->nr] == Walker) { 723 *out<< Verbose(4) << "Removing " << *OtherAtom << " from lists and stacks." << endl;724 Log() << Verbose(4) << "Removing " << *OtherAtom << " from lists and stacks." << endl; 724 725 BFS.PredecessorList[OtherAtom->nr] = NULL; 725 726 BFS.ShortestPathList[OtherAtom->nr] = -1; … … 744 745 * \param &MinRingSize global minimum distance from one node without encountering oneself, set on return 745 746 */ 746 void CyclicStructureAnalysis_RetrieveCycleMembers( ofstream *out,atom *&OtherAtom, bond *&BackEdge, struct BFSAccounting &BFS, int *&MinimumRingSize, int &MinRingSize)747 void CyclicStructureAnalysis_RetrieveCycleMembers(atom *&OtherAtom, bond *&BackEdge, struct BFSAccounting &BFS, int *&MinimumRingSize, int &MinRingSize) 747 748 { 748 749 atom *Walker = NULL; … … 755 756 RingSize = 1; 756 757 BFS.Root->GetTrueFather()->IsCyclic = true; 757 *out<< Verbose(1) << "Found ring contains: ";758 Log() << Verbose(1) << "Found ring contains: "; 758 759 Walker = BFS.Root; 759 760 while (Walker != BackEdge->rightatom) { 760 *out<< Walker->Name << " <-> ";761 Log() << Verbose(0) << Walker->Name << " <-> "; 761 762 Walker = BFS.PredecessorList[Walker->nr]; 762 763 Walker->GetTrueFather()->IsCyclic = true; 763 764 RingSize++; 764 765 } 765 *out<< Walker->Name << " with a length of " << RingSize << "." << endl << endl;766 Log() << Verbose(0) << Walker->Name << " with a length of " << RingSize << "." << endl << endl; 766 767 // walk through all and set MinimumRingSize 767 768 Walker = BFS.Root; … … 775 776 MinRingSize = RingSize; 776 777 } else { 777 *out<< Verbose(1) << "No ring containing " << *BFS.Root << " with length equal to or smaller than " << MinimumRingSize[Walker->GetTrueFather()->nr] << " found." << endl;778 Log() << Verbose(1) << "No ring containing " << *BFS.Root << " with length equal to or smaller than " << MinimumRingSize[Walker->GetTrueFather()->nr] << " found." << endl; 778 779 } 779 780 }; … … 785 786 * \param AtomCount number of nodes in graph 786 787 */ 787 void CyclicStructureAnalysis_BFSToNextCycle( ofstream *out,atom *&Root, atom *&Walker, int *&MinimumRingSize, int AtomCount)788 void CyclicStructureAnalysis_BFSToNextCycle(atom *&Root, atom *&Walker, int *&MinimumRingSize, int AtomCount) 788 789 { 789 790 struct BFSAccounting BFS; 790 791 atom *OtherAtom = Walker; 791 792 792 InitializeBFSAccounting( out,BFS, AtomCount);793 794 ResetBFSAccounting( out,Walker, BFS);793 InitializeBFSAccounting(BFS, AtomCount); 794 795 ResetBFSAccounting(Walker, BFS); 795 796 while (OtherAtom != NULL) { // look for Root 796 797 Walker = BFS.BFSStack->PopFirst(); 797 // *out<< Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *Root << "." << endl;798 //Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *Root << "." << endl; 798 799 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 799 800 // "removed (*Runner) != BackEdge) || " from next if, is u 800 801 if ((Walker->ListOfBonds.size() == 1)) { // only walk along DFS spanning tree (otherwise we always find SP of 1 being backedge Binder), but terminal hydrogens may be connected via backedge, hence extra check 801 802 OtherAtom = (*Runner)->GetOtherAtom(Walker); 802 // *out<< Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *Binder << "." << endl;803 //Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *Binder << "." << endl; 803 804 if (BFS.ColorList[OtherAtom->nr] == white) { 804 805 BFS.TouchedStack->Push(OtherAtom); … … 806 807 BFS.PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor 807 808 BFS.ShortestPathList[OtherAtom->nr] = BFS.ShortestPathList[Walker->nr] + 1; 808 // *out<< Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " lightgray, its predecessor is " << Walker->Name << " and its Shortest Path is " << ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl;809 //Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " lightgray, its predecessor is " << Walker->Name << " and its Shortest Path is " << ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl; 809 810 if (OtherAtom->GetTrueFather()->IsCyclic) { // if the other atom is connected to a ring 810 811 MinimumRingSize[Root->GetTrueFather()->nr] = BFS.ShortestPathList[OtherAtom->nr] + MinimumRingSize[OtherAtom->GetTrueFather()->nr]; … … 814 815 BFS.BFSStack->Push(OtherAtom); 815 816 } else { 816 // *out<< Verbose(3) << "Not Adding, has already been visited." << endl;817 //Log() << Verbose(3) << "Not Adding, has already been visited." << endl; 817 818 } 818 819 } else { 819 // *out<< Verbose(3) << "Not Visiting, is a back edge." << endl;820 //Log() << Verbose(3) << "Not Visiting, is a back edge." << endl; 820 821 } 821 822 } 822 823 BFS.ColorList[Walker->nr] = black; 823 // *out<< Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;824 //Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl; 824 825 } 825 826 //CleanAccountingLists(TouchedStack, PredecessorList, ShortestPathList, ColorList); 826 827 827 FinalizeBFSAccounting( out,BFS);828 FinalizeBFSAccounting(BFS); 828 829 } 829 830 ; … … 836 837 * \param *mol molecule with atoms 837 838 */ 838 void CyclicStructureAnalysis_AssignRingSizetoNonCycleMembers( ofstream *out,int *&MinimumRingSize, int &MinRingSize, int &NumCycles, const molecule * const mol)839 void CyclicStructureAnalysis_AssignRingSizetoNonCycleMembers(int *&MinimumRingSize, int &MinRingSize, int &NumCycles, const molecule * const mol) 839 840 { 840 841 atom *Root = NULL; … … 849 850 Walker = Root; 850 851 851 // *out<< Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl;852 CyclicStructureAnalysis_BFSToNextCycle( out,Root, Walker, MinimumRingSize, mol->AtomCount);852 //Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl; 853 CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol->AtomCount); 853 854 854 855 } 855 *out<< Verbose(1) << "Minimum ring size of " << *Root << " is " << MinimumRingSize[Root->GetTrueFather()->nr] << "." << endl;856 } 857 *out<< Verbose(1) << "Minimum ring size is " << MinRingSize << ", over " << NumCycles << " cycles total." << endl;856 Log() << Verbose(1) << "Minimum ring size of " << *Root << " is " << MinimumRingSize[Root->GetTrueFather()->nr] << "." << endl; 857 } 858 Log() << Verbose(1) << "Minimum ring size is " << MinRingSize << ", over " << NumCycles << " cycles total." << endl; 858 859 } else 859 *out<< Verbose(1) << "No rings were detected in the molecular structure." << endl;860 Log() << Verbose(1) << "No rings were detected in the molecular structure." << endl; 860 861 } 861 862 ; … … 871 872 * \todo BFS from the not-same-LP to find back to starting point of tributary cycle over more than one bond 872 873 */ 873 void molecule::CyclicStructureAnalysis( ofstream *out,class StackClass<bond *> * BackEdgeStack, int *&MinimumRingSize) const874 void molecule::CyclicStructureAnalysis(class StackClass<bond *> * BackEdgeStack, int *&MinimumRingSize) const 874 875 { 875 876 struct BFSAccounting BFS; … … 880 881 int MinRingSize = -1; 881 882 882 InitializeBFSAccounting( out,BFS, AtomCount);883 884 // *out<< Verbose(1) << "Back edge list - ";883 InitializeBFSAccounting(BFS, AtomCount); 884 885 //Log() << Verbose(1) << "Back edge list - "; 885 886 //BackEdgeStack->Output(out); 886 887 887 *out<< Verbose(1) << "Analysing cycles ... " << endl;888 Log() << Verbose(1) << "Analysing cycles ... " << endl; 888 889 NumCycles = 0; 889 890 while (!BackEdgeStack->IsEmpty()) { … … 894 895 Walker = BackEdge->rightatom; 895 896 896 ResetBFSAccounting( out,Walker, BFS);897 898 *out<< Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl;897 ResetBFSAccounting(Walker, BFS); 898 899 Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl; 899 900 OtherAtom = NULL; 900 CyclicStructureAnalysis_CyclicBFSFromRootToRoot( out,BackEdge, BFS);901 902 CyclicStructureAnalysis_RetrieveCycleMembers( out,OtherAtom, BackEdge, BFS, MinimumRingSize, MinRingSize);903 904 CleanBFSAccounting( out,BFS);905 } 906 FinalizeBFSAccounting( out,BFS);907 908 CyclicStructureAnalysis_AssignRingSizetoNonCycleMembers( out,MinimumRingSize, MinRingSize, NumCycles, this);901 CyclicStructureAnalysis_CyclicBFSFromRootToRoot(BackEdge, BFS); 902 903 CyclicStructureAnalysis_RetrieveCycleMembers(OtherAtom, BackEdge, BFS, MinimumRingSize, MinRingSize); 904 905 CleanBFSAccounting(BFS); 906 } 907 FinalizeBFSAccounting(BFS); 908 909 CyclicStructureAnalysis_AssignRingSizetoNonCycleMembers(MinimumRingSize, MinRingSize, NumCycles, this); 909 910 }; 910 911 … … 926 927 } 927 928 if (i == vertex->ListOfBonds.size()) 928 cerr<< "Error: All Component entries are already occupied!" << endl;929 eLog() << Verbose(0) << "Error: All Component entries are already occupied!" << endl; 929 930 } else 930 cerr<< "Error: Given vertex is NULL!" << endl;931 eLog() << Verbose(0) << "Error: Given vertex is NULL!" << endl; 931 932 } 932 933 ; … … 962 963 * \param *list 963 964 */ 964 void OutputAlreadyVisited( ofstream *out,int *list)965 { 966 *out<< Verbose(4) << "Already Visited Bonds:\t";965 void OutputAlreadyVisited(int *list) 966 { 967 Log() << Verbose(4) << "Already Visited Bonds:\t"; 967 968 for (int i = 1; i <= list[0]; i++) 968 *out<< Verbose(0) << list[i] << " ";969 *out<< endl;969 Log() << Verbose(0) << list[i] << " "; 970 Log() << Verbose(0) << endl; 970 971 } 971 972 ; … … 977 978 * \return true - file written successfully, false - writing failed 978 979 */ 979 bool molecule::StoreAdjacencyToFile( ofstream *out,char *path)980 bool molecule::StoreAdjacencyToFile(char *path) 980 981 { 981 982 ofstream AdjacencyFile; … … 985 986 line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE; 986 987 AdjacencyFile.open(line.str().c_str(), ios::out); 987 *out<< Verbose(1) << "Saving adjacency list ... ";988 Log() << Verbose(1) << "Saving adjacency list ... "; 988 989 if (AdjacencyFile != NULL) { 989 990 ActOnAllAtoms(&atom::OutputAdjacency, &AdjacencyFile); 990 991 AdjacencyFile.close(); 991 *out<< Verbose(1) << "done." << endl;992 Log() << Verbose(1) << "done." << endl; 992 993 } else { 993 *out<< Verbose(1) << "failed to open file " << line.str() << "." << endl;994 Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl; 994 995 status = false; 995 996 } … … 999 1000 ; 1000 1001 1001 bool CheckAdjacencyFileAgainstMolecule_Init( ofstream *out,char *path, ifstream &File, int *&CurrentBonds)1002 bool CheckAdjacencyFileAgainstMolecule_Init(char *path, ifstream &File, int *&CurrentBonds) 1002 1003 { 1003 1004 stringstream filename; 1004 1005 filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE; 1005 1006 File.open(filename.str().c_str(), ios::out); 1006 *out<< Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... ";1007 Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... "; 1007 1008 if (File == NULL) 1008 1009 return false; … … 1014 1015 ; 1015 1016 1016 void CheckAdjacencyFileAgainstMolecule_Finalize( ofstream *out,ifstream &File, int *&CurrentBonds)1017 void CheckAdjacencyFileAgainstMolecule_Finalize(ifstream &File, int *&CurrentBonds) 1017 1018 { 1018 1019 File.close(); … … 1022 1023 ; 1023 1024 1024 void CheckAdjacencyFileAgainstMolecule_CompareBonds( ofstream *out,bool &status, int &NonMatchNumber, atom *&Walker, size_t &CurrentBondsOfAtom, int AtomNr, int *&CurrentBonds, atom **ListOfAtoms)1025 void CheckAdjacencyFileAgainstMolecule_CompareBonds(bool &status, int &NonMatchNumber, atom *&Walker, size_t &CurrentBondsOfAtom, int AtomNr, int *&CurrentBonds, atom **ListOfAtoms) 1025 1026 { 1026 1027 size_t j = 0; 1027 1028 int id = -1; 1028 1029 1029 // *out<< Verbose(2) << "Walker is " << *Walker << ", bond partners: ";1030 //Log() << Verbose(2) << "Walker is " << *Walker << ", bond partners: "; 1030 1031 if (CurrentBondsOfAtom == Walker->ListOfBonds.size()) { 1031 1032 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { … … 1038 1039 NonMatchNumber++; 1039 1040 status = false; 1040 // *out<< "[" << id << "]\t";1041 //Log() << Verbose(0) << "[" << id << "]\t"; 1041 1042 } else { 1042 // *out<< id << "\t";1043 //Log() << Verbose(0) << id << "\t"; 1043 1044 } 1044 1045 } 1045 // *out<< endl;1046 //Log() << Verbose(0) << endl; 1046 1047 } else { 1047 *out<< "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << Walker->ListOfBonds.size() << "." << endl;1048 Log() << Verbose(0) << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << Walker->ListOfBonds.size() << "." << endl; 1048 1049 status = false; 1049 1050 } … … 1057 1058 * \return true - structure is equal, false - not equivalence 1058 1059 */ 1059 bool molecule::CheckAdjacencyFileAgainstMolecule( ofstream *out,char *path, atom **ListOfAtoms)1060 bool molecule::CheckAdjacencyFileAgainstMolecule(char *path, atom **ListOfAtoms) 1060 1061 { 1061 1062 ifstream File; … … 1067 1068 size_t CurrentBondsOfAtom = -1; 1068 1069 1069 if (!CheckAdjacencyFileAgainstMolecule_Init( out,path, File, CurrentBonds)) {1070 *out<< Verbose(1) << "Adjacency file not found." << endl;1070 if (!CheckAdjacencyFileAgainstMolecule_Init(path, File, CurrentBonds)) { 1071 Log() << Verbose(1) << "Adjacency file not found." << endl; 1071 1072 return true; 1072 1073 } … … 1087 1088 line >> CurrentBonds[++CurrentBondsOfAtom]; 1088 1089 // compare against present bonds 1089 CheckAdjacencyFileAgainstMolecule_CompareBonds( out,status, NonMatchNumber, Walker, CurrentBondsOfAtom, AtomNr, CurrentBonds, ListOfAtoms);1090 CheckAdjacencyFileAgainstMolecule_CompareBonds(status, NonMatchNumber, Walker, CurrentBondsOfAtom, AtomNr, CurrentBonds, ListOfAtoms); 1090 1091 } 1091 1092 } 1092 1093 Free(&buffer); 1093 CheckAdjacencyFileAgainstMolecule_Finalize( out,File, CurrentBonds);1094 CheckAdjacencyFileAgainstMolecule_Finalize(File, CurrentBonds); 1094 1095 1095 1096 if (status) { // if equal we parse the KeySetFile 1096 *out<< Verbose(1) << "done: Equal." << endl;1097 Log() << Verbose(1) << "done: Equal." << endl; 1097 1098 } else 1098 *out<< Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl;1099 Log() << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl; 1099 1100 return status; 1100 1101 } … … 1108 1109 * \return true - everything ok, false - ReferenceStack was empty 1109 1110 */ 1110 bool molecule::PickLocalBackEdges( ofstream *out,atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack) const1111 bool molecule::PickLocalBackEdges(atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack) const 1111 1112 { 1112 1113 bool status = true; 1113 1114 if (ReferenceStack->IsEmpty()) { 1114 cerr<< "ReferenceStack is empty!" << endl;1115 eLog() << Verbose(0) << "ReferenceStack is empty!" << endl; 1115 1116 return false; 1116 1117 } … … 1127 1128 if (OtherAtom == ListOfLocalAtoms[(*Runner)->rightatom->nr]) { // found the bond 1128 1129 LocalStack->Push((*Runner)); 1129 *out<< Verbose(3) << "Found local edge " << *(*Runner) << "." << endl;1130 Log() << Verbose(3) << "Found local edge " << *(*Runner) << "." << endl; 1130 1131 break; 1131 1132 } 1132 1133 } 1133 1134 Binder = ReferenceStack->PopFirst(); // loop the stack for next item 1134 *out<< Verbose(3) << "Current candidate edge " << Binder << "." << endl;1135 Log() << Verbose(3) << "Current candidate edge " << Binder << "." << endl; 1135 1136 ReferenceStack->Push(Binder); 1136 1137 } while (FirstBond != Binder); … … 1175 1176 ; 1176 1177 1177 void BreadthFirstSearchAdd_UnvisitedNode( ofstream *out,molecule *Mol, struct BFSAccounting &BFS, atom *&Walker, atom *&OtherAtom, bond *&Binder, bond *&Bond, atom **&AddedAtomList, bond **&AddedBondList, bool IsAngstroem)1178 void BreadthFirstSearchAdd_UnvisitedNode(molecule *Mol, struct BFSAccounting &BFS, atom *&Walker, atom *&OtherAtom, bond *&Binder, bond *&Bond, atom **&AddedAtomList, bond **&AddedBondList, bool IsAngstroem) 1178 1179 { 1179 1180 if (Binder != Bond) // let other atom white if it's via Root bond. In case it's cyclic it has to be reached again (yet Root is from OtherAtom already black, thus no problem) … … 1181 1182 BFS.PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor 1182 1183 BFS.ShortestPathList[OtherAtom->nr] = BFS.ShortestPathList[Walker->nr] + 1; 1183 *out<< 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;1184 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; 1184 1185 if ((((BFS.ShortestPathList[OtherAtom->nr] < BFS.BondOrder) && (Binder != Bond)))) { // Check for maximum distance 1185 *out<< Verbose(3);1186 Log() << Verbose(3); 1186 1187 if (AddedAtomList[OtherAtom->nr] == NULL) { // add if it's not been so far 1187 1188 AddedAtomList[OtherAtom->nr] = Mol->AddCopyAtom(OtherAtom); 1188 *out<< "Added OtherAtom " << OtherAtom->Name;1189 Log() << Verbose(0) << "Added OtherAtom " << OtherAtom->Name; 1189 1190 AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder); 1190 *out<< " and bond " << *(AddedBondList[Binder->nr]) << ", ";1191 Log() << Verbose(0) << " and bond " << *(AddedBondList[Binder->nr]) << ", "; 1191 1192 } 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) 1192 *out<< "Not adding OtherAtom " << OtherAtom->Name;1193 Log() << Verbose(0) << "Not adding OtherAtom " << OtherAtom->Name; 1193 1194 if (AddedBondList[Binder->nr] == NULL) { 1194 1195 AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder); 1195 *out<< ", added Bond " << *(AddedBondList[Binder->nr]);1196 Log() << Verbose(0) << ", added Bond " << *(AddedBondList[Binder->nr]); 1196 1197 } else 1197 *out<< ", not added Bond ";1198 } 1199 *out<< ", putting OtherAtom into queue." << endl;1198 Log() << Verbose(0) << ", not added Bond "; 1199 } 1200 Log() << Verbose(0) << ", putting OtherAtom into queue." << endl; 1200 1201 BFS.BFSStack->Push(OtherAtom); 1201 1202 } else { // out of bond order, then replace … … 1203 1204 BFS.ColorList[OtherAtom->nr] = white; // unmark if it has not been queued/added, to make it available via its other bonds (cyclic) 1204 1205 if (Binder == Bond) 1205 *out<< Verbose(3) << "Not Queueing, is the Root bond";1206 Log() << Verbose(3) << "Not Queueing, is the Root bond"; 1206 1207 else if (BFS.ShortestPathList[OtherAtom->nr] >= BFS.BondOrder) 1207 *out<< Verbose(3) << "Not Queueing, is out of Bond Count of " << BFS.BondOrder;1208 Log() << Verbose(3) << "Not Queueing, is out of Bond Count of " << BFS.BondOrder; 1208 1209 if (!Binder->Cyclic) 1209 *out<< ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl;1210 Log() << Verbose(0) << ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl; 1210 1211 if (AddedBondList[Binder->nr] == NULL) { 1211 1212 if ((AddedAtomList[OtherAtom->nr] != NULL)) { // .. whether we add or saturate … … 1213 1214 } else { 1214 1215 #ifdef ADDHYDROGEN 1215 if (!Mol->AddHydrogenReplacementAtom( out,Binder, AddedAtomList[Walker->nr], Walker, OtherAtom, IsAngstroem))1216 if (!Mol->AddHydrogenReplacementAtom(Binder, AddedAtomList[Walker->nr], Walker, OtherAtom, IsAngstroem)) 1216 1217 exit(1); 1217 1218 #endif … … 1222 1223 ; 1223 1224 1224 void BreadthFirstSearchAdd_VisitedNode( ofstream *out,molecule *Mol, struct BFSAccounting &BFS, atom *&Walker, atom *&OtherAtom, bond *&Binder, bond *&Bond, atom **&AddedAtomList, bond **&AddedBondList, bool IsAngstroem)1225 { 1226 *out<< Verbose(3) << "Not Adding, has already been visited." << endl;1225 void BreadthFirstSearchAdd_VisitedNode(molecule *Mol, struct BFSAccounting &BFS, atom *&Walker, atom *&OtherAtom, bond *&Binder, bond *&Bond, atom **&AddedAtomList, bond **&AddedBondList, bool IsAngstroem) 1226 { 1227 Log() << Verbose(3) << "Not Adding, has already been visited." << endl; 1227 1228 // This has to be a cyclic bond, check whether it's present ... 1228 1229 if (AddedBondList[Binder->nr] == NULL) { … … 1231 1232 } else { // if it's root bond it has to broken (otherwise we would not create the fragments) 1232 1233 #ifdef ADDHYDROGEN 1233 if(!Mol->AddHydrogenReplacementAtom( out,Binder, AddedAtomList[Walker->nr], Walker, OtherAtom, IsAngstroem))1234 if(!Mol->AddHydrogenReplacementAtom(Binder, AddedAtomList[Walker->nr], Walker, OtherAtom, IsAngstroem)) 1234 1235 exit(1); 1235 1236 #endif … … 1251 1252 * \param IsAngstroem lengths are in angstroem or bohrradii 1252 1253 */ 1253 void molecule::BreadthFirstSearchAdd( ofstream *out,molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem)1254 void molecule::BreadthFirstSearchAdd(molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem) 1254 1255 { 1255 1256 struct BFSAccounting BFS; … … 1270 1271 // followed by n+1 till top of stack. 1271 1272 Walker = BFS.BFSStack->PopFirst(); // pop oldest added 1272 *out<< Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << Walker->ListOfBonds.size() << " bonds." << endl;1273 Log() << Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << Walker->ListOfBonds.size() << " bonds." << endl; 1273 1274 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 1274 1275 if ((*Runner) != NULL) { // don't look at bond equal NULL 1275 1276 Binder = (*Runner); 1276 1277 OtherAtom = (*Runner)->GetOtherAtom(Walker); 1277 *out<< Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl;1278 Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl; 1278 1279 if (BFS.ColorList[OtherAtom->nr] == white) { 1279 BreadthFirstSearchAdd_UnvisitedNode( out,Mol, BFS, Walker, OtherAtom, Binder, Bond, AddedAtomList, AddedBondList, IsAngstroem);1280 BreadthFirstSearchAdd_UnvisitedNode(Mol, BFS, Walker, OtherAtom, Binder, Bond, AddedAtomList, AddedBondList, IsAngstroem); 1280 1281 } else { 1281 BreadthFirstSearchAdd_VisitedNode( out,Mol, BFS, Walker, OtherAtom, Binder, Bond, AddedAtomList, AddedBondList, IsAngstroem);1282 BreadthFirstSearchAdd_VisitedNode(Mol, BFS, Walker, OtherAtom, Binder, Bond, AddedAtomList, AddedBondList, IsAngstroem); 1282 1283 } 1283 1284 } 1284 1285 } 1285 1286 BFS.ColorList[Walker->nr] = black; 1286 *out<< Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;1287 Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl; 1287 1288 } 1288 1289 BreadthFirstSearchAdd_Free(BFS); … … 1305 1306 ; 1306 1307 1307 void BuildInducedSubgraph_Init( ofstream *out,atom **&ParentList, int AtomCount)1308 void BuildInducedSubgraph_Init(atom **&ParentList, int AtomCount) 1308 1309 { 1309 1310 // reset parent list 1310 1311 ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList"); 1311 *out<< Verbose(3) << "Resetting ParentList." << endl;1312 } 1313 ; 1314 1315 void BuildInducedSubgraph_FillParentList( ofstream *out,const molecule *mol, const molecule *Father, atom **&ParentList)1312 Log() << Verbose(3) << "Resetting ParentList." << endl; 1313 } 1314 ; 1315 1316 void BuildInducedSubgraph_FillParentList(const molecule *mol, const molecule *Father, atom **&ParentList) 1316 1317 { 1317 1318 // fill parent list with sons 1318 *out<< Verbose(3) << "Filling Parent List." << endl;1319 Log() << Verbose(3) << "Filling Parent List." << endl; 1319 1320 atom *Walker = mol->start; 1320 1321 while (Walker->next != mol->end) { … … 1322 1323 ParentList[Walker->father->nr] = Walker; 1323 1324 // Outputting List for debugging 1324 *out<< Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl;1325 } 1326 1327 } 1328 ; 1329 1330 void BuildInducedSubgraph_Finalize( ofstream *out,atom **&ParentList)1325 Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl; 1326 } 1327 1328 } 1329 ; 1330 1331 void BuildInducedSubgraph_Finalize(atom **&ParentList) 1331 1332 { 1332 1333 Free(&ParentList); … … 1334 1335 ; 1335 1336 1336 bool BuildInducedSubgraph_CreateBondsFromParent( ofstream *out,molecule *mol, const molecule *Father, atom **&ParentList)1337 bool BuildInducedSubgraph_CreateBondsFromParent(molecule *mol, const molecule *Father, atom **&ParentList) 1337 1338 { 1338 1339 bool status = true; … … 1340 1341 atom *OtherAtom = NULL; 1341 1342 // check each entry of parent list and if ok (one-to-and-onto matching) create bonds 1342 *out<< Verbose(3) << "Creating bonds." << endl;1343 Log() << Verbose(3) << "Creating bonds." << endl; 1343 1344 Walker = Father->start; 1344 1345 while (Walker->next != Father->end) { … … 1351 1352 OtherAtom = (*Runner)->GetOtherAtom(Walker); 1352 1353 if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond 1353 *out<< Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl;1354 Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl; 1354 1355 mol->AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree); 1355 1356 } … … 1371 1372 * \todo not checked, not fully working probably 1372 1373 */ 1373 bool molecule::BuildInducedSubgraph( ofstream *out,const molecule *Father)1374 bool molecule::BuildInducedSubgraph(const molecule *Father) 1374 1375 { 1375 1376 bool status = true; 1376 1377 atom **ParentList = NULL; 1377 1378 1378 *out<< Verbose(2) << "Begin of BuildInducedSubgraph." << endl;1379 BuildInducedSubgraph_Init( out,ParentList, Father->AtomCount);1380 BuildInducedSubgraph_FillParentList( out,this, Father, ParentList);1381 status = BuildInducedSubgraph_CreateBondsFromParent( out,this, Father, ParentList);1382 BuildInducedSubgraph_Finalize( out,ParentList);1383 *out<< Verbose(2) << "End of BuildInducedSubgraph." << endl;1379 Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl; 1380 BuildInducedSubgraph_Init(ParentList, Father->AtomCount); 1381 BuildInducedSubgraph_FillParentList(this, Father, ParentList); 1382 status = BuildInducedSubgraph_CreateBondsFromParent(this, Father, ParentList); 1383 BuildInducedSubgraph_Finalize(ParentList); 1384 Log() << Verbose(2) << "End of BuildInducedSubgraph." << endl; 1384 1385 return status; 1385 1386 } … … 1392 1393 * \note this is O(n^2) for it's just a bug checker not meant for permanent use! 1393 1394 */ 1394 bool molecule::CheckForConnectedSubgraph( ofstream *out,KeySet *Fragment)1395 bool molecule::CheckForConnectedSubgraph(KeySet *Fragment) 1395 1396 { 1396 1397 atom *Walker = NULL, *Walker2 = NULL; … … 1398 1399 int size; 1399 1400 1400 *out<< Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl;1401 *out<< Verbose(2) << "Disconnected atom: ";1401 Log() << Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl; 1402 Log() << Verbose(2) << "Disconnected atom: "; 1402 1403 1403 1404 // count number of atoms in graph … … 1421 1422 } 1422 1423 if (!BondStatus) { 1423 *out<< (*Walker) << endl;1424 Log() << Verbose(0) << (*Walker) << endl; 1424 1425 return false; 1425 1426 } 1426 1427 } 1427 1428 else { 1428 *out<< "none." << endl;1429 Log() << Verbose(0) << "none." << endl; 1429 1430 return true; 1430 1431 } 1431 *out<< "none." << endl;1432 1433 *out<< Verbose(1) << "End of CheckForConnectedSubgraph" << endl;1432 Log() << Verbose(0) << "none." << endl; 1433 1434 Log() << Verbose(1) << "End of CheckForConnectedSubgraph" << endl; 1434 1435 1435 1436 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
