Changes in src/molecule_graph.cpp [94d5ac6:3aa8a5]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_graph.cpp
r94d5ac6 r3aa8a5 48 48 #include "Element/element.hpp" 49 49 #include "Graph/BondGraph.hpp" 50 #include "Graph/ListOfLocalAtoms.hpp" 50 51 #include "Helpers/defs.hpp" 51 52 #include "Helpers/helpers.hpp" … … 61 62 * Calls this routine in each MoleculeLeafClass::next subgraph if it's not NULL. 62 63 * \param *reference reference molecule with the bond structure to be copied 63 * \param **&ListOfLocalAtoms Lookup table for this subgraph and index of each atom in \a *reference, may be NULL on start, then it is filled64 * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not64 * \param ListOfLocalAtoms Lookup table for this subgraph and index of each atom in \a *reference, may be NULL on start, then it is filled 65 * \param FreeList true - ListOfLocalAtoms is free'd before return, false - it is not 65 66 * \return true - success, false - failure 66 67 */ 67 bool molecule::FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList)68 bool molecule::FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList) 68 69 { 69 70 bool status = true; … … 91 92 ++Runner) { 92 93 atom * const OtherAtom = (*Runner)->GetOtherAtom((*iter)->GetTrueFather()); 93 atom * const OtherWalker = ListOfLocalAtoms[OtherAtom->getNr()]; // local copy of current bond partner of walker 94 const ListOfLocalAtoms_t::const_iterator localiter = ListOfLocalAtoms.find(OtherAtom->getNr()); 95 ASSERT( localiter != ListOfLocalAtoms.end(), 96 "molecule::FillBondStructureFromReference() - could not find id" 97 +toString(OtherAtom->getNr())+" in ListOfLocalAtoms."); 98 atom * const OtherWalker = localiter->second; // local copy of current bond partner of walker 94 99 if (OtherWalker != NULL) { 95 100 if (OtherWalker->getNr() > (*iter)->getNr()) … … 103 108 } 104 109 105 if ((FreeList) && ( ListOfLocalAtoms != NULL)) {110 if ((FreeList) && (!ListOfLocalAtoms.empty())) { 106 111 // free the index lookup list 107 delete[](ListOfLocalAtoms);112 ListOfLocalAtoms.clear(); 108 113 } 109 114 LOG(1, "End of FillBondStructureFromReference."); … … 146 151 } 147 152 148 149 /** Storing the bond structure of a molecule to file.150 * Simply stores Atom::Nr and then the Atom::Nr of all bond partners per line.151 * \param &filename name of file152 * \param path path to file, defaults to empty153 * \return true - file written successfully, false - writing failed154 */155 bool molecule::StoreAdjacencyToFile(std::string filename, std::string path)156 {157 ofstream AdjacencyFile;158 string line;159 bool status = true;160 161 if (path != "")162 line = path + "/" + filename;163 else164 line = filename;165 AdjacencyFile.open(line.c_str(), ios::out);166 LOG(1, "Saving adjacency list ... ");167 if (AdjacencyFile.good()) {168 AdjacencyFile << "m\tn" << endl;169 for_each(begin(),end(),bind2nd(mem_fun(&atom::OutputAdjacency),&AdjacencyFile));170 AdjacencyFile.close();171 LOG(1, "\t... done.");172 } else {173 LOG(1, "\t... failed to open file " << line << ".");174 status = false;175 }176 177 return status;178 }179 ;180 153 181 154 /** Storing the bond structure of a molecule to file. … … 227 200 228 201 /** Fills a lookup list of father's Atom::nr -> atom for each subgraph. 229 * \param **&ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled202 * \param ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled 230 203 * \param GlobalAtomCount number of atoms in the complete molecule 231 204 * \return true - success, false - failure (ListOfLocalAtoms != NULL) 232 205 */ 233 bool molecule::FillListOfLocalAtoms( atom **&ListOfLocalAtoms, const int GlobalAtomCount)206 bool molecule::FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount) 234 207 { 235 208 bool status = true; 236 209 237 if (ListOfLocalAtoms == NULL) { // allocate and fill list of this fragment/subgraph210 if (ListOfLocalAtoms.empty()) { // allocate and fill list of this fragment/subgraph 238 211 status = status && CreateFatherLookupTable(ListOfLocalAtoms, GlobalAtomCount); 239 212 } else … … 251 224 * \return true - success, false - failure 252 225 */ 253 bool molecule::CreateFatherLookupTable( atom **&LookupTable, int count)226 bool molecule::CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count) 254 227 { 255 228 bool status = true; 256 229 int AtomNo; 257 230 258 if ( LookupTable != NULL) {259 ELOG(1, "Pointer for Lookup table is not NULL! Aborting ...");231 if (!LookupTable.empty()) { 232 ELOG(1, "Pointer for Lookup table is not empty! Aborting ..."); 260 233 return false; 261 234 } … … 273 246 274 247 // allocate and fill 275 LookupTable = new atom *[count+1]; 276 if (LookupTable == NULL) { 277 ELOG(0, "LookupTable memory allocation failed!"); 278 performCriticalExit(); 279 status = false; 280 } else { 281 for (int i=0;i<=count;i++) 282 LookupTable[i] = NULL; 283 for (molecule::iterator iter = begin(); iter != end(); ++iter) { 284 AtomNo = (*iter)->GetTrueFather()->getNr(); 285 if ((AtomNo >= 0) && (AtomNo <= count)) { 286 LOG(3, "DEBUG: Setting LookupTable[" << AtomNo << "] to " << *(*iter)); 287 LookupTable[AtomNo] = (*iter); 288 } else { 289 ELOG(1, "Walker " << *(*iter) << " exceeded range of nuclear ids [0, " << count << "]."); 290 status = false; 291 break; 292 } 248 for (int i=0;i<=count;i++) 249 LookupTable[i] = NULL; 250 for (molecule::iterator iter = begin(); iter != end(); ++iter) { 251 AtomNo = (*iter)->GetTrueFather()->getNr(); 252 if ((AtomNo >= 0) && (AtomNo <= count)) { 253 LOG(3, "DEBUG: Setting LookupTable[" << AtomNo << "] to " << *(*iter)); 254 LookupTable[AtomNo] = (*iter); 255 } else { 256 ELOG(1, "Walker " << *(*iter) << " exceeded range of nuclear ids [0, " << count << "]."); 257 status = false; 258 break; 293 259 } 294 260 }
Note:
See TracChangeset
for help on using the changeset viewer.