Changes in src/molecule_graph.cpp [3aa8a5:94d5ac6]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_graph.cpp
r3aa8a5 r94d5ac6 48 48 #include "Element/element.hpp" 49 49 #include "Graph/BondGraph.hpp" 50 #include "Graph/ListOfLocalAtoms.hpp"51 50 #include "Helpers/defs.hpp" 52 51 #include "Helpers/helpers.hpp" … … 62 61 * Calls this routine in each MoleculeLeafClass::next subgraph if it's not NULL. 63 62 * \param *reference reference molecule with the bond structure to be copied 64 * \param ListOfLocalAtoms Lookup table for this subgraph and index of each atom in \a *reference, may be NULL on start, then it is filled65 * \param FreeList true - ListOfLocalAtoms is free'd before return, false - it is not63 * \param **&ListOfLocalAtoms Lookup table for this subgraph and index of each atom in \a *reference, may be NULL on start, then it is filled 64 * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not 66 65 * \return true - success, false - failure 67 66 */ 68 bool molecule::FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t&ListOfLocalAtoms, bool FreeList)67 bool molecule::FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList) 69 68 { 70 69 bool status = true; … … 92 91 ++Runner) { 93 92 atom * const OtherAtom = (*Runner)->GetOtherAtom((*iter)->GetTrueFather()); 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 93 atom * const OtherWalker = ListOfLocalAtoms[OtherAtom->getNr()]; // local copy of current bond partner of walker 99 94 if (OtherWalker != NULL) { 100 95 if (OtherWalker->getNr() > (*iter)->getNr()) … … 108 103 } 109 104 110 if ((FreeList) && ( !ListOfLocalAtoms.empty())) {105 if ((FreeList) && (ListOfLocalAtoms != NULL)) { 111 106 // free the index lookup list 112 ListOfLocalAtoms.clear();107 delete[](ListOfLocalAtoms); 113 108 } 114 109 LOG(1, "End of FillBondStructureFromReference."); … … 151 146 } 152 147 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 file 152 * \param path path to file, defaults to empty 153 * \return true - file written successfully, false - writing failed 154 */ 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 else 164 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 ; 153 180 154 181 /** Storing the bond structure of a molecule to file. … … 200 227 201 228 /** Fills a lookup list of father's Atom::nr -> atom for each subgraph. 202 * \param ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled229 * \param **&ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled 203 230 * \param GlobalAtomCount number of atoms in the complete molecule 204 231 * \return true - success, false - failure (ListOfLocalAtoms != NULL) 205 232 */ 206 bool molecule::FillListOfLocalAtoms( ListOfLocalAtoms_t&ListOfLocalAtoms, const int GlobalAtomCount)233 bool molecule::FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount) 207 234 { 208 235 bool status = true; 209 236 210 if (ListOfLocalAtoms .empty()) { // allocate and fill list of this fragment/subgraph237 if (ListOfLocalAtoms == NULL) { // allocate and fill list of this fragment/subgraph 211 238 status = status && CreateFatherLookupTable(ListOfLocalAtoms, GlobalAtomCount); 212 239 } else … … 224 251 * \return true - success, false - failure 225 252 */ 226 bool molecule::CreateFatherLookupTable( ListOfLocalAtoms_t&LookupTable, int count)253 bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count) 227 254 { 228 255 bool status = true; 229 256 int AtomNo; 230 257 231 if ( !LookupTable.empty()) {232 ELOG(1, "Pointer for Lookup table is not empty! Aborting ...");258 if (LookupTable != NULL) { 259 ELOG(1, "Pointer for Lookup table is not NULL! Aborting ..."); 233 260 return false; 234 261 } … … 246 273 247 274 // allocate and fill 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; 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 } 259 293 } 260 294 }
Note:
See TracChangeset
for help on using the changeset viewer.