Changes in src/molecule_graph.cpp [68f03d:112b09]
- File:
-
- 1 edited
-
src/molecule_graph.cpp (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_graph.cpp
r68f03d r112b09 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom.hpp" … … 12 14 #include "element.hpp" 13 15 #include "helpers.hpp" 16 #include "info.hpp" 14 17 #include "linkedcell.hpp" 15 18 #include "lists.hpp" … … 19 22 #include "World.hpp" 20 23 #include "Helpers/fast_functions.hpp" 24 #include "Helpers/Assert.hpp" 25 21 26 22 27 struct BFSAccounting … … 54 59 void molecule::CreateAdjacencyListFromDbondFile(ifstream *input) 55 60 { 56 61 Info FunctionInfo(__func__); 57 62 // 1 We will parse bonds out of the dbond file created by tremolo. 58 63 int atom1, atom2; 59 64 atom *Walker, *OtherWalker; 60 61 if (!input) { 62 DoLog(1) && (Log() << Verbose(1) << "Opening silica failed \n"); 65 char line[MAXSTRINGSIZE]; 66 67 if (input->fail()) { 68 DoeLog(0) && (eLog() << Verbose(0) << "Opening of bond file failed \n"); 69 performCriticalExit(); 63 70 }; 64 65 *input >> ws >> atom1; 66 *input >> ws >> atom2; 67 DoLog(1) && (Log() << Verbose(1) << "Scanning file\n"); 71 doCountAtoms(); 72 73 // skip header 74 input->getline(line,MAXSTRINGSIZE); 75 DoLog(1) && (Log() << Verbose(1) << "Scanning file ... \n"); 68 76 while (!input->eof()) // Check whether we read everything already 69 77 { 70 *input >> ws >> atom1; 71 *input >> ws >> atom2; 72 78 input->getline(line,MAXSTRINGSIZE); 79 stringstream zeile(line); 80 zeile >> atom1; 81 zeile >> atom2; 82 83 DoLog(2) && (Log() << Verbose(2) << "Looking for atoms " << atom1 << " and " << atom2 << "." << endl); 73 84 if (atom2 < atom1) //Sort indices of atoms in order 74 85 flip(atom1, atom2); 75 86 Walker = FindAtom(atom1); 87 ASSERT(Walker,"Could not find an atom with the ID given in dbond file"); 76 88 OtherWalker = FindAtom(atom2); 89 ASSERT(OtherWalker,"Could not find an atom with the ID given in dbond file"); 77 90 AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices. 78 91 } … … 103 116 atom *Walker = NULL; 104 117 atom *OtherWalker = NULL; 105 atom **AtomMap = NULL;106 118 int n[NDIM]; 107 119 double MinDistance, MaxDistance; … … 118 130 DoLog(0) && (Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl); 119 131 // remove every bond from the list 120 bond *Binder = NULL; 121 while (last->previous != first) { 122 Binder = last->previous; 123 Binder->leftatom->UnregisterBond(Binder); 124 Binder->rightatom->UnregisterBond(Binder); 125 removewithoutcheck(Binder); 126 } 132 for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) 133 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin()) 134 if ((*BondRunner)->leftatom == *AtomRunner) 135 delete((*BondRunner)); 127 136 BondCount = 0; 128 137 129 138 // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering) 130 CountAtoms(); 131 DoLog(1) && (Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl); 132 133 if ((AtomCount > 1) && (bonddistance > 1.)) { 139 DoLog(1) && (Log() << Verbose(1) << "AtomCount " << getAtomCount() << " and bonddistance is " << bonddistance << "." << endl); 140 141 if ((getAtomCount() > 1) && (bonddistance > 1.)) { 134 142 DoLog(2) && (Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl); 135 143 LC = new LinkedCell(this, bonddistance); … … 137 145 // create a list to map Tesselpoint::nr to atom * 138 146 DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl); 139 AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount"); 140 Walker = start;141 while (Walker->next != end) {142 Walker = Walker->next;143 AtomMap[Walker->nr] = Walker;147 148 // set numbers for atoms that can later be used 149 int i=0; 150 for(internal_iterator iter = atoms.begin();iter!= atoms.end(); ++iter){ 151 (*iter)->nr = i++; 144 152 } 145 153 … … 153 161 if (List != NULL) { 154 162 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 155 Walker = AtomMap[(*Runner)->nr]; 156 // Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl; 163 Walker = dynamic_cast<atom*>(*Runner); 164 ASSERT(Walker,"Tesselpoint that was not an atom retrieved from LinkedNode"); 165 //Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl; 157 166 // 3c. check for possible bond between each atom in this and every one in the 27 cells 158 167 for (n[0] = -1; n[0] <= 1; n[0]++) … … 164 173 for (LinkedCell::LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) { 165 174 if ((*OtherRunner)->nr > Walker->nr) { 166 OtherWalker = AtomMap[(*OtherRunner)->nr]; 167 // Log() << Verbose(0) << "Current other Atom is " << *OtherWalker << "." << endl; 168 const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x, cell_size); 169 // Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl; 175 OtherWalker = dynamic_cast<atom*>(*OtherRunner); 176 ASSERT(OtherWalker,"TesselPoint that was not an atom retrieved from LinkedNode"); 177 //Log() << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl; 170 178 (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem); 179 const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x,cell_size); 171 180 const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance); 172 181 // Log() << Verbose(1) << "MinDistance is " << MinDistance << " and MaxDistance is " << MaxDistance << "." << endl; … … 188 197 } 189 198 } 190 Free(&AtomMap);191 199 delete (LC); 192 200 DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl); … … 199 207 ActOnAllAtoms( &atom::OutputBondOfAtom ); 200 208 } else 201 DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << AtomCount<< ", thus no bonds, no connections!." << endl);209 DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << getAtomCount() << ", thus no bonds, no connections!." << endl); 202 210 DoLog(0) && (Log() << Verbose(0) << "End of CreateAdjacencyList." << endl); 203 211 if (free_BG) … … 206 214 ; 207 215 216 /** Checks for presence of bonds within atom list. 217 * TODO: more sophisticated check for bond structure (e.g. connected subgraph, ...) 218 * \return true - bonds present, false - no bonds 219 */ 220 bool molecule::hasBondStructure() 221 { 222 for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) 223 if (!(*AtomRunner)->ListOfBonds.empty()) 224 return true; 225 return false; 226 } 227 228 /** Counts the number of present bonds. 229 * \return number of bonds 230 */ 231 unsigned int molecule::CountBonds() const 232 { 233 unsigned int counter = 0; 234 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) 235 for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner) 236 if ((*BondRunner)->leftatom == *AtomRunner) 237 counter++; 238 return counter; 239 } 240 208 241 /** Prints a list of all bonds to \a *out. 209 242 * \param output stream … … 212 245 { 213 246 DoLog(1) && (Log() << Verbose(1) << endl << "From contents of bond chain list:"); 214 bond *Binder = first;215 while (Binder->next != last) {216 Binder = Binder->next;217 DoLog(0) && (Log() << Verbose(0) << *Binder<< "\t" << endl);218 }247 for(molecule::const_iterator AtomRunner = molecule::begin(); AtomRunner != molecule::end(); ++AtomRunner) 248 for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner) 249 if ((*BondRunner)->leftatom == *AtomRunner) { 250 DoLog(0) && (Log() << Verbose(0) << *(*BondRunner) << "\t" << endl); 251 } 219 252 DoLog(0) && (Log() << Verbose(0) << endl); 220 253 } … … 241 274 DoLog(0) && (Log() << Verbose(0) << " done." << endl); 242 275 } else { 243 DoLog(1) && (Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount<< " atoms." << endl);276 DoLog(1) && (Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << getAtomCount() << " atoms." << endl); 244 277 } 245 278 DoLog(0) && (Log() << Verbose(0) << No << " bonds could not be corrected." << endl); … … 260 293 MoleculeLeafClass *Subgraphs = NULL; 261 294 class StackClass<bond *> *BackEdgeStack = NULL; 262 bond *Binder = first; 263 if ((Binder->next != last) && (Binder->next->Type == Undetermined)) { 264 DoLog(0) && (Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl); 265 Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack); 266 while (Subgraphs->next != NULL) { 267 Subgraphs = Subgraphs->next; 268 delete (Subgraphs->previous); 269 } 270 delete (Subgraphs); 271 delete[] (MinimumRingSize); 272 } 273 while (Binder->next != last) { 274 Binder = Binder->next; 275 if (Binder->Cyclic) 276 NoCyclicBonds++; 277 } 295 for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) 296 if ((!(*AtomRunner)->ListOfBonds.empty()) && ((*(*AtomRunner)->ListOfBonds.begin())->Type == Undetermined)) { 297 DoLog(0) && (Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl); 298 Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack); 299 while (Subgraphs->next != NULL) { 300 Subgraphs = Subgraphs->next; 301 delete (Subgraphs->previous); 302 } 303 delete (Subgraphs); 304 delete[] (MinimumRingSize); 305 break; 306 } 307 for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) 308 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner) 309 if ((*BondRunner)->leftatom == *AtomRunner) 310 if ((*BondRunner)->Cyclic) 311 NoCyclicBonds++; 278 312 delete (BackEdgeStack); 279 313 return NoCyclicBonds; … … 461 495 void DepthFirstSearchAnalysis_Init(struct DFSAccounting &DFS, const molecule * const mol) 462 496 { 463 DFS.AtomStack = new StackClass<atom *> (mol-> AtomCount);497 DFS.AtomStack = new StackClass<atom *> (mol->getAtomCount()); 464 498 DFS.CurrentGraphNr = 0; 465 499 DFS.ComponentNumber = 0; … … 502 536 bond *Binder = NULL; 503 537 504 if ( AtomCount== 0)538 if (getAtomCount() == 0) 505 539 return SubGraphs; 506 540 DoLog(0) && (Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl); 507 541 DepthFirstSearchAnalysis_Init(DFS, this); 508 542 509 DFS.Root = start->next;510 while (DFS.Root != end) { // if there any atoms at all543 for (molecule::const_iterator iter = begin(); iter != end();) { 544 DFS.Root = *iter; 511 545 // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all 512 546 DFS.AtomStack->ClearStack(); … … 548 582 549 583 // step on to next root 550 while (( DFS.Root != end) && (DFS.Root->GraphNr != -1)) {551 //Log() << Verbose(1) << "Current next subgraph root candidate is " << Root->Name << "." << endl;552 if ( DFS.Root->GraphNr != -1) // if already discovered, step on553 DFS.Root = DFS.Root->next;584 while ((iter != end()) && ((*iter)->GraphNr != -1)) { 585 //Log() << Verbose(1) << "Current next subgraph root candidate is " << (*iter)->Name << "." << endl; 586 if ((*iter)->GraphNr != -1) // if already discovered, step on 587 iter++; 554 588 } 555 589 } … … 573 607 { 574 608 NoCyclicBonds = 0; 575 bond *Binder = first; 576 while (Binder->next != last) { 577 Binder = Binder->next; 578 if (Binder->rightatom->LowpointNr == Binder->leftatom->LowpointNr) { // cyclic ?? 579 Binder->Cyclic = true; 580 NoCyclicBonds++; 581 } 582 } 609 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) 610 for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner) 611 if ((*BondRunner)->leftatom == *AtomRunner) 612 if ((*BondRunner)->rightatom->LowpointNr == (*BondRunner)->leftatom->LowpointNr) { // cyclic ?? 613 (*BondRunner)->Cyclic = true; 614 NoCyclicBonds++; 615 } 583 616 } 584 617 ; … … 599 632 void molecule::OutputGraphInfoPerBond() const 600 633 { 634 bond *Binder = NULL; 601 635 DoLog(1) && (Log() << Verbose(1) << "Final graph info for each bond is:" << endl); 602 bond *Binder = first; 603 while (Binder->next != last) { 604 Binder = Binder->next; 605 DoLog(2) && (Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <"); 606 DoLog(0) && (Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp."); 607 Binder->leftatom->OutputComponentNumber(); 608 DoLog(0) && (Log() << Verbose(0) << " === "); 609 DoLog(0) && (Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp."); 610 Binder->rightatom->OutputComponentNumber(); 611 DoLog(0) && (Log() << Verbose(0) << ">." << endl); 612 if (Binder->Cyclic) // cyclic ?? 613 DoLog(3) && (Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl); 614 } 636 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) 637 for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner) 638 if ((*BondRunner)->leftatom == *AtomRunner) { 639 Binder = *BondRunner; 640 DoLog(2) && (Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <"); 641 DoLog(0) && (Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp."); 642 Binder->leftatom->OutputComponentNumber(); 643 DoLog(0) && (Log() << Verbose(0) << " === "); 644 DoLog(0) && (Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp."); 645 Binder->rightatom->OutputComponentNumber(); 646 DoLog(0) && (Log() << Verbose(0) << ">." << endl); 647 if (Binder->Cyclic) // cyclic ?? 648 DoLog(3) && (Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl); 649 } 615 650 } 616 651 ; … … 624 659 { 625 660 BFS.AtomCount = AtomCount; 626 BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");627 BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");628 BFS.ColorList = Calloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");661 BFS.PredecessorList = new atom*[AtomCount]; 662 BFS.ShortestPathList = new int[AtomCount]; 663 BFS.ColorList = new enum Shading[AtomCount]; 629 664 BFS.BFSStack = new StackClass<atom *> (AtomCount); 630 665 631 for (int i = AtomCount; i--;) 666 for (int i = AtomCount; i--;) { 632 667 BFS.ShortestPathList[i] = -1; 668 BFS.PredecessorList[i] = 0; 669 } 633 670 }; 634 671 … … 639 676 void FinalizeBFSAccounting(struct BFSAccounting &BFS) 640 677 { 641 Free(&BFS.PredecessorList);642 Free(&BFS.ShortestPathList);643 Free(&BFS.ColorList);678 delete[](BFS.PredecessorList); 679 delete[](BFS.ShortestPathList); 680 delete[](BFS.ColorList); 644 681 delete (BFS.BFSStack); 645 682 BFS.AtomCount = 0; … … 854 891 if (MinRingSize != -1) { // if rings are present 855 892 // go over all atoms 856 Root = mol->start; 857 while (Root->next != mol->end) { 858 Root = Root->next; 859 860 if (MinimumRingSize[Root->GetTrueFather()->nr] == mol->AtomCount) { // check whether MinimumRingSize is set, if not BFS to next where it is 893 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 894 Root = *iter; 895 896 if (MinimumRingSize[Root->GetTrueFather()->nr] == mol->getAtomCount()) { // check whether MinimumRingSize is set, if not BFS to next where it is 861 897 Walker = Root; 862 898 863 899 //Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl; 864 CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol-> AtomCount);900 CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol->getAtomCount()); 865 901 866 902 } … … 892 928 int MinRingSize = -1; 893 929 894 InitializeBFSAccounting(BFS, AtomCount);930 InitializeBFSAccounting(BFS, getAtomCount()); 895 931 896 932 //Log() << Verbose(1) << "Back edge list - "; … … 966 1002 void molecule::ResetAllBondsToUnused() const 967 1003 { 968 bond *Binder = first; 969 while (Binder->next != last) { 970 Binder = Binder->next; 971 Binder->ResetUsed(); 972 } 1004 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) 1005 for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner) 1006 if ((*BondRunner)->leftatom == *AtomRunner) 1007 (*BondRunner)->ResetUsed(); 973 1008 } 974 1009 ; … … 1004 1039 line << filename; 1005 1040 AdjacencyFile.open(line.str().c_str(), ios::out); 1006 DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... " );1041 DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... " << endl); 1007 1042 if (AdjacencyFile != NULL) { 1008 1043 AdjacencyFile << "m\tn" << endl; 1009 1044 ActOnAllAtoms(&atom::OutputAdjacency, &AdjacencyFile); 1010 1045 AdjacencyFile.close(); 1011 DoLog(1) && (Log() << Verbose(1) << " done." << endl);1046 DoLog(1) && (Log() << Verbose(1) << "\t... done." << endl); 1012 1047 } else { 1013 DoLog(1) && (Log() << Verbose(1) << " failed to open file " << line.str() << "." << endl);1048 DoLog(1) && (Log() << Verbose(1) << "\t... failed to open file " << line.str() << "." << endl); 1014 1049 status = false; 1015 1050 } … … 1036 1071 line << filename; 1037 1072 BondFile.open(line.str().c_str(), ios::out); 1038 DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... " );1073 DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... " << endl); 1039 1074 if (BondFile != NULL) { 1040 1075 BondFile << "m\tn" << endl; 1041 1076 ActOnAllAtoms(&atom::OutputBonds, &BondFile); 1042 1077 BondFile.close(); 1043 DoLog(1) && (Log() << Verbose(1) << " done." << endl);1078 DoLog(1) && (Log() << Verbose(1) << "\t... done." << endl); 1044 1079 } else { 1045 DoLog(1) && (Log() << Verbose(1) << " failed to open file " << line.str() << "." << endl);1080 DoLog(1) && (Log() << Verbose(1) << "\t... failed to open file " << line.str() << "." << endl); 1046 1081 status = false; 1047 1082 } … … 1056 1091 filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE; 1057 1092 File.open(filename.str().c_str(), ios::out); 1058 DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... " );1093 DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... " << endl); 1059 1094 if (File == NULL) 1060 1095 return false; 1061 1096 1062 1097 // allocate storage structure 1063 CurrentBonds = Calloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom 1098 CurrentBonds = new int[8]; // contains parsed bonds of current atom 1099 for(int i=0;i<8;i++) 1100 CurrentBonds[i] = 0; 1064 1101 return true; 1065 1102 } … … 1070 1107 File.close(); 1071 1108 File.clear(); 1072 Free(&CurrentBonds);1109 delete[](CurrentBonds); 1073 1110 } 1074 1111 ; … … 1090 1127 NonMatchNumber++; 1091 1128 status = false; 1129 DoeLog(2) && (eLog() << Verbose(2) << id << " can not be found in list." << endl); 1130 } else { 1092 1131 //Log() << Verbose(0) << "[" << id << "]\t"; 1093 } else {1094 //Log() << Verbose(0) << id << "\t";1095 1132 } 1096 1133 } … … 1114 1151 bool status = true; 1115 1152 atom *Walker = NULL; 1116 char *buffer = NULL;1117 1153 int *CurrentBonds = NULL; 1118 1154 int NonMatchNumber = 0; // will number of atoms with differing bond structure 1119 1155 size_t CurrentBondsOfAtom = -1; 1156 const int AtomCount = getAtomCount(); 1120 1157 1121 1158 if (!CheckAdjacencyFileAgainstMolecule_Init(path, File, CurrentBonds)) { … … 1124 1161 } 1125 1162 1126 buffer = Malloc<char> (MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");1163 char buffer[MAXSTRINGSIZE]; 1127 1164 // Parse the file line by line and count the bonds 1128 1165 while (!File.eof()) { … … 1140 1177 // compare against present bonds 1141 1178 CheckAdjacencyFileAgainstMolecule_CompareBonds(status, NonMatchNumber, Walker, CurrentBondsOfAtom, AtomNr, CurrentBonds, ListOfAtoms); 1142 } 1143 } 1144 Free(&buffer); 1179 } else { 1180 if (AtomNr != -1) 1181 DoeLog(2) && (eLog() << Verbose(2) << AtomNr << " is not valid in the range of ids [" << 0 << "," << AtomCount << ")." << endl); 1182 } 1183 } 1145 1184 CheckAdjacencyFileAgainstMolecule_Finalize(File, CurrentBonds); 1146 1185 … … 1196 1235 BFS.AtomCount = AtomCount; 1197 1236 BFS.BondOrder = BondOrder; 1198 BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");1199 BFS.ShortestPathList = Calloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");1200 BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");1237 BFS.PredecessorList = new atom*[AtomCount]; 1238 BFS.ShortestPathList = new int[AtomCount]; 1239 BFS.ColorList = new enum Shading[AtomCount]; 1201 1240 BFS.BFSStack = new StackClass<atom *> (AtomCount); 1202 1241 … … 1207 1246 // initialise each vertex as white with no predecessor, empty queue, color Root lightgray 1208 1247 for (int i = AtomCount; i--;) { 1248 BFS.PredecessorList[i] = NULL; 1209 1249 BFS.ShortestPathList[i] = -1; 1210 1250 if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited … … 1213 1253 BFS.ColorList[i] = white; 1214 1254 } 1215 //BFS.ShortestPathList[Root->nr] = 0; // is set due to Calloc()1255 //BFS.ShortestPathList[Root->nr] = 0; // done by Calloc 1216 1256 } 1217 1257 ; … … 1219 1259 void BreadthFirstSearchAdd_Free(struct BFSAccounting &BFS) 1220 1260 { 1221 Free(&BFS.PredecessorList);1222 Free(&BFS.ShortestPathList);1223 Free(&BFS.ColorList);1261 delete[](BFS.PredecessorList); 1262 delete[](BFS.ShortestPathList); 1263 delete[](BFS.ColorList); 1224 1264 delete (BFS.BFSStack); 1225 1265 BFS.AtomCount = 0; … … 1313 1353 AddedAtomList[Root->nr] = Mol->AddCopyAtom(Root); 1314 1354 1315 BreadthFirstSearchAdd_Init(BFS, Root, BondOrder, AtomCount, AddedAtomList);1355 BreadthFirstSearchAdd_Init(BFS, Root, BondOrder, getAtomCount(), AddedAtomList); 1316 1356 1317 1357 // and go on ... Queue always contains all lightgray vertices … … 1360 1400 { 1361 1401 // reset parent list 1362 ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList"); 1402 ParentList = new atom*[AtomCount]; 1403 for (int i=0;i<AtomCount;i++) 1404 ParentList[i] = NULL; 1363 1405 DoLog(3) && (Log() << Verbose(3) << "Resetting ParentList." << endl); 1364 1406 } … … 1369 1411 // fill parent list with sons 1370 1412 DoLog(3) && (Log() << Verbose(3) << "Filling Parent List." << endl); 1371 atom *Walker = mol->start; 1372 while (Walker->next != mol->end) { 1373 Walker = Walker->next; 1374 ParentList[Walker->father->nr] = Walker; 1413 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 1414 ParentList[(*iter)->father->nr] = (*iter); 1375 1415 // Outputting List for debugging 1376 DoLog(4) && (Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl); 1377 } 1378 1379 } 1380 ; 1416 DoLog(4) && (Log() << Verbose(4) << "Son[" << (*iter)->father->nr << "] of " << (*iter)->father << " is " << ParentList[(*iter)->father->nr] << "." << endl); 1417 } 1418 }; 1381 1419 1382 1420 void BuildInducedSubgraph_Finalize(atom **&ParentList) 1383 1421 { 1384 Free(&ParentList);1422 delete[](ParentList); 1385 1423 } 1386 1424 ; … … 1389 1427 { 1390 1428 bool status = true; 1391 atom *Walker = NULL;1392 1429 atom *OtherAtom = NULL; 1393 1430 // check each entry of parent list and if ok (one-to-and-onto matching) create bonds 1394 1431 DoLog(3) && (Log() << Verbose(3) << "Creating bonds." << endl); 1395 Walker = Father->start; 1396 while (Walker->next != Father->end) { 1397 Walker = Walker->next; 1398 if (ParentList[Walker->nr] != NULL) { 1399 if (ParentList[Walker->nr]->father != Walker) { 1432 for (molecule::const_iterator iter = Father->begin(); iter != Father->end(); ++iter) { 1433 if (ParentList[(*iter)->nr] != NULL) { 1434 if (ParentList[(*iter)->nr]->father != (*iter)) { 1400 1435 status = false; 1401 1436 } else { 1402 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {1403 OtherAtom = (*Runner)->GetOtherAtom( Walker);1437 for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) { 1438 OtherAtom = (*Runner)->GetOtherAtom((*iter)); 1404 1439 if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond 1405 DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[ Walker->nr]->getName() << " and " << ParentList[OtherAtom->nr]->getName() << "." << endl);1406 mol->AddBond(ParentList[ Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);1440 DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[(*iter)->nr]->getName() << " and " << ParentList[OtherAtom->nr]->getName() << "." << endl); 1441 mol->AddBond(ParentList[(*iter)->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree); 1407 1442 } 1408 1443 } … … 1427 1462 bool status = true; 1428 1463 atom **ParentList = NULL; 1429 1430 1464 DoLog(2) && (Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl); 1431 BuildInducedSubgraph_Init(ParentList, Father-> AtomCount);1465 BuildInducedSubgraph_Init(ParentList, Father->getAtomCount()); 1432 1466 BuildInducedSubgraph_FillParentList(this, Father, ParentList); 1433 1467 status = BuildInducedSubgraph_CreateBondsFromParent(this, Father, ParentList);
Note:
See TracChangeset
for help on using the changeset viewer.
