Changeset c901e3 for molecuilder/src


Ignore:
Timestamp:
May 8, 2008, 12:01:42 PM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
b8eb3a
Parents:
7afa7e
Message:

new function CreateFatherLookupTable

Creates a lookup table for true father's atom:nr -> atom, which is used during the molecule::FragmentMolecule lateron. Implemented as a template to be used not only for atoms but also for bonds and others

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/helpers.hpp

    r7afa7e rc901e3  
    6161/********************************************** helpful template functions *********************************/
    6262
     63/** Creates a lookup table for true father's Atom::Nr -> atom ptr.
     64 * \param *out output stream for debugging
     65 * \param *start begin of chain list
     66 * \paran *end end of chain list
     67 * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start)
     68 * \param count optional predetermined count for table (otherwise we set the count to highest true father id)
     69 * \return true - success, false - failure
     70 */
     71template <typename T> bool CreateFatherLookupTable(ofstream *out, T *start, T *end, T **&LookupTable, int count = 0)
     72{
     73  bool status = true;
     74  T *Walker = NULL;
     75  int AtomNo;
     76 
     77  if (LookupTable != NULL) {
     78    *out << "Pointer for Lookup table is not NULL! Aborting ..." <<endl;
     79    return false;
     80  }
     81 
     82  // count them
     83  if (count == 0) {
     84    Walker = start;
     85    while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
     86      Walker = Walker->next;
     87      count = (count < Walker->GetTrueFather()->nr) ? Walker->GetTrueFather()->nr : count;
     88    }
     89  }
     90  if (count <= 0) {
     91    *out << "Count of lookup list is 0 or less." << endl;
     92    return false;
     93  }
     94
     95  // allocat and fill
     96  LookupTable = (T **) Malloc(sizeof(T *)*count, "CreateFatherLookupTable - **LookupTable");
     97  if (LookupTable == NULL) {
     98    cerr << "LookupTable memory allocation failed!" << endl;
     99    status = false;
     100  } else {
     101    Walker = start;
     102    while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
     103      Walker = Walker->next;
     104      AtomNo = Walker->GetTrueFather()->nr;
     105      if ((AtomNo >= 0) && (AtomNo < count)) {
     106        //*out << "Setting LookupTable[" << AtomNo << "] to " << *Walker << endl;
     107        LookupTable[AtomNo] = Walker;
     108      } else {
     109        *out << "Walker " << *Walker << " exceeded range of nuclear ids [0, " << count << ")." << endl;
     110        status = false;
     111        break;
     112      }
     113    }
     114  }
     115 
     116  return status;
     117};
     118
     119
     120
    63121/******************************** Some templates for list management ***********************************/
    64122
Note: See TracChangeset for help on using the changeset viewer.