Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_graph.cpp

    r94d5ac6 r3aa8a5  
    4848#include "Element/element.hpp"
    4949#include "Graph/BondGraph.hpp"
     50#include "Graph/ListOfLocalAtoms.hpp"
    5051#include "Helpers/defs.hpp"
    5152#include "Helpers/helpers.hpp"
     
    6162 * Calls this routine in each MoleculeLeafClass::next subgraph if it's not NULL.
    6263 * \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 filled
    64  * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
     64 * \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
    6566 * \return true - success, false - failure
    6667 */
    67 bool molecule::FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList)
     68bool molecule::FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList)
    6869{
    6970  bool status = true;
     
    9192          ++Runner) {
    9293        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
    9499        if (OtherWalker != NULL) {
    95100          if (OtherWalker->getNr() > (*iter)->getNr())
     
    103108  }
    104109
    105   if ((FreeList) && (ListOfLocalAtoms != NULL)) {
     110  if ((FreeList) && (!ListOfLocalAtoms.empty())) {
    106111    // free the index lookup list
    107     delete[](ListOfLocalAtoms);
     112    ListOfLocalAtoms.clear();
    108113  }
    109114  LOG(1, "End of FillBondStructureFromReference.");
     
    146151}
    147152
    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 ;
    180153
    181154/** Storing the bond structure of a molecule to file.
     
    227200
    228201/** 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 filled
     202 * \param ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
    230203 * \param GlobalAtomCount number of atoms in the complete molecule
    231204 * \return true - success, false - failure (ListOfLocalAtoms != NULL)
    232205 */
    233 bool molecule::FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount)
     206bool molecule::FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount)
    234207{
    235208  bool status = true;
    236209
    237   if (ListOfLocalAtoms == NULL) { // allocate and fill list of this fragment/subgraph
     210  if (ListOfLocalAtoms.empty()) { // allocate and fill list of this fragment/subgraph
    238211    status = status && CreateFatherLookupTable(ListOfLocalAtoms, GlobalAtomCount);
    239212  } else
     
    251224 * \return true - success, false - failure
    252225 */
    253 bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count)
     226bool molecule::CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count)
    254227{
    255228  bool status = true;
    256229  int AtomNo;
    257230
    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 ...");
    260233    return false;
    261234  }
     
    273246
    274247  // 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;
    293259    }
    294260  }
Note: See TracChangeset for help on using the changeset viewer.