Changes in src/molecule_graph.cpp [920c70:68f03d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_graph.cpp
r920c70 r68f03d 12 12 #include "element.hpp" 13 13 #include "helpers.hpp" 14 #include "info.hpp"15 14 #include "linkedcell.hpp" 16 15 #include "lists.hpp" … … 55 54 void molecule::CreateAdjacencyListFromDbondFile(ifstream *input) 56 55 { 57 Info FunctionInfo(__func__); 56 58 57 // 1 We will parse bonds out of the dbond file created by tremolo. 59 58 int atom1, atom2; 60 59 atom *Walker, *OtherWalker; 61 char line[MAXSTRINGSIZE]; 62 63 if (input->fail()) { 64 DoeLog(0) && (eLog() << Verbose(0) << "Opening of bond file failed \n"); 65 performCriticalExit(); 60 61 if (!input) { 62 DoLog(1) && (Log() << Verbose(1) << "Opening silica failed \n"); 66 63 }; 67 64 68 // skip header69 input->getline(line,MAXSTRINGSIZE);70 DoLog(1) && (Log() << Verbose(1) << "Scanning file ...\n");65 *input >> ws >> atom1; 66 *input >> ws >> atom2; 67 DoLog(1) && (Log() << Verbose(1) << "Scanning file\n"); 71 68 while (!input->eof()) // Check whether we read everything already 72 69 { 73 input->getline(line,MAXSTRINGSIZE); 74 stringstream zeile(line); 75 zeile >> atom1; 76 zeile >> atom2; 77 78 DoLog(2) && (Log() << Verbose(2) << "Looking for atoms " << atom1 << " and " << atom2 << "." << endl); 70 *input >> ws >> atom1; 71 *input >> ws >> atom2; 72 79 73 if (atom2 < atom1) //Sort indices of atoms in order 80 74 flip(atom1, atom2); … … 143 137 // create a list to map Tesselpoint::nr to atom * 144 138 DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl); 145 AtomMap = new atom *[AtomCount]; 146 for (int i=0;i<AtomCount;i++) 147 AtomMap[i] = NULL; 139 AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount"); 148 140 Walker = start; 149 141 while (Walker->next != end) { … … 196 188 } 197 189 } 198 delete[](AtomMap);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); … … 632 624 { 633 625 BFS.AtomCount = AtomCount; 634 BFS.PredecessorList = new atom*[AtomCount];635 BFS.ShortestPathList = new int[AtomCount];636 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"); 637 629 BFS.BFSStack = new StackClass<atom *> (AtomCount); 638 630 639 for (int i = AtomCount; i--;) {631 for (int i = AtomCount; i--;) 640 632 BFS.ShortestPathList[i] = -1; 641 BFS.PredecessorList[i] = 0;642 }643 633 }; 644 634 … … 649 639 void FinalizeBFSAccounting(struct BFSAccounting &BFS) 650 640 { 651 delete[](BFS.PredecessorList);652 delete[](BFS.ShortestPathList);653 delete[](BFS.ColorList);641 Free(&BFS.PredecessorList); 642 Free(&BFS.ShortestPathList); 643 Free(&BFS.ColorList); 654 644 delete (BFS.BFSStack); 655 645 BFS.AtomCount = 0; … … 1071 1061 1072 1062 // allocate storage structure 1073 CurrentBonds = new int[8]; // contains parsed bonds of current atom 1074 for(int i=0;i<8;i++) 1075 CurrentBonds[i] = 0; 1063 CurrentBonds = Calloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom 1076 1064 return true; 1077 1065 } … … 1082 1070 File.close(); 1083 1071 File.clear(); 1084 delete[](CurrentBonds);1072 Free(&CurrentBonds); 1085 1073 } 1086 1074 ; … … 1126 1114 bool status = true; 1127 1115 atom *Walker = NULL; 1116 char *buffer = NULL; 1128 1117 int *CurrentBonds = NULL; 1129 1118 int NonMatchNumber = 0; // will number of atoms with differing bond structure … … 1135 1124 } 1136 1125 1137 char buffer[MAXSTRINGSIZE];1126 buffer = Malloc<char> (MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer"); 1138 1127 // Parse the file line by line and count the bonds 1139 1128 while (!File.eof()) { … … 1153 1142 } 1154 1143 } 1144 Free(&buffer); 1155 1145 CheckAdjacencyFileAgainstMolecule_Finalize(File, CurrentBonds); 1156 1146 … … 1206 1196 BFS.AtomCount = AtomCount; 1207 1197 BFS.BondOrder = BondOrder; 1208 BFS.PredecessorList = new atom*[AtomCount];1209 BFS.ShortestPathList = new int[AtomCount];1210 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"); 1211 1201 BFS.BFSStack = new StackClass<atom *> (AtomCount); 1212 1202 … … 1217 1207 // initialise each vertex as white with no predecessor, empty queue, color Root lightgray 1218 1208 for (int i = AtomCount; i--;) { 1219 BFS.PredecessorList[i] = NULL;1220 1209 BFS.ShortestPathList[i] = -1; 1221 1210 if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited … … 1224 1213 BFS.ColorList[i] = white; 1225 1214 } 1226 //BFS.ShortestPathList[Root->nr] = 0; // done by Calloc1215 //BFS.ShortestPathList[Root->nr] = 0; //is set due to Calloc() 1227 1216 } 1228 1217 ; … … 1230 1219 void BreadthFirstSearchAdd_Free(struct BFSAccounting &BFS) 1231 1220 { 1232 delete[](BFS.PredecessorList);1233 delete[](BFS.ShortestPathList);1234 delete[](BFS.ColorList);1221 Free(&BFS.PredecessorList); 1222 Free(&BFS.ShortestPathList); 1223 Free(&BFS.ColorList); 1235 1224 delete (BFS.BFSStack); 1236 1225 BFS.AtomCount = 0; … … 1371 1360 { 1372 1361 // reset parent list 1373 ParentList = new atom*[AtomCount]; 1374 for (int i=0;i<AtomCount;i++) 1375 ParentList[i] = NULL; 1362 ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList"); 1376 1363 DoLog(3) && (Log() << Verbose(3) << "Resetting ParentList." << endl); 1377 1364 } … … 1395 1382 void BuildInducedSubgraph_Finalize(atom **&ParentList) 1396 1383 { 1397 delete[](ParentList);1384 Free(&ParentList); 1398 1385 } 1399 1386 ;
Note:
See TracChangeset
for help on using the changeset viewer.