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