Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_graph.cpp

    r3aa8a5 r94d5ac6  
    4848#include "Element/element.hpp"
    4949#include "Graph/BondGraph.hpp"
    50 #include "Graph/ListOfLocalAtoms.hpp"
    5150#include "Helpers/defs.hpp"
    5251#include "Helpers/helpers.hpp"
     
    6261 * Calls this routine in each MoleculeLeafClass::next subgraph if it's not NULL.
    6362 * \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 filled
    65  * \param FreeList true - ListOfLocalAtoms is free'd before return, false - it is not
     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
    6665 * \return true - success, false - failure
    6766 */
    68 bool molecule::FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList)
     67bool molecule::FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList)
    6968{
    7069  bool status = true;
     
    9291          ++Runner) {
    9392        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
    9994        if (OtherWalker != NULL) {
    10095          if (OtherWalker->getNr() > (*iter)->getNr())
     
    108103  }
    109104
    110   if ((FreeList) && (!ListOfLocalAtoms.empty())) {
     105  if ((FreeList) && (ListOfLocalAtoms != NULL)) {
    111106    // free the index lookup list
    112     ListOfLocalAtoms.clear();
     107    delete[](ListOfLocalAtoms);
    113108  }
    114109  LOG(1, "End of FillBondStructureFromReference.");
     
    151146}
    152147
     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 */
     155bool 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;
    153180
    154181/** Storing the bond structure of a molecule to file.
     
    200227
    201228/** 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 filled
     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
    203230 * \param GlobalAtomCount number of atoms in the complete molecule
    204231 * \return true - success, false - failure (ListOfLocalAtoms != NULL)
    205232 */
    206 bool molecule::FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount)
     233bool molecule::FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount)
    207234{
    208235  bool status = true;
    209236
    210   if (ListOfLocalAtoms.empty()) { // allocate and fill list of this fragment/subgraph
     237  if (ListOfLocalAtoms == NULL) { // allocate and fill list of this fragment/subgraph
    211238    status = status && CreateFatherLookupTable(ListOfLocalAtoms, GlobalAtomCount);
    212239  } else
     
    224251 * \return true - success, false - failure
    225252 */
    226 bool molecule::CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count)
     253bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count)
    227254{
    228255  bool status = true;
    229256  int AtomNo;
    230257
    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 ...");
    233260    return false;
    234261  }
     
    246273
    247274  // 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      }
    259293    }
    260294  }
Note: See TracChangeset for help on using the changeset viewer.