Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_fragmentation.cpp

    rd4c9ae r112b09  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <cstring>
     
    3941  int FragmentCount;
    4042  // get maximum bond degree
    41   atom *Walker = start;
    42   while (Walker->next != end) {
    43     Walker = Walker->next;
    44     c = (Walker->ListOfBonds.size() > c) ? Walker->ListOfBonds.size() : c;
     43  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     44    c = ((*iter)->ListOfBonds.size() > c) ? (*iter)->ListOfBonds.size() : c;
    4545  }
    4646  FragmentCount = NoNonHydrogen*(1 << (c*order));
     
    9494  GraphTestPair testGraphInsert;
    9595  int NumberOfFragments = 0;
    96   char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
     96  char filename[MAXSTRINGSIZE];
    9797
    9898  if (FragmentList == NULL) { // check list pointer
     
    106106  if (InputFile != NULL) {
    107107    // each line represents a new fragment
    108     char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
     108    char buffer[MAXSTRINGSIZE];
    109109    // 1. parse keysets and insert into temp. graph
    110110    while (!InputFile.eof()) {
     
    122122    InputFile.close();
    123123    InputFile.clear();
    124     Free(&buffer);
    125     DoLog(1) && (Log() << Verbose(1) << "done." << endl);
     124    DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl);
    126125  } else {
    127     DoLog(1) && (Log() << Verbose(1) << "File " << filename << " not found." << endl);
     126    DoLog(1) && (Log() << Verbose(1) << "\t ... File " << filename << " not found." << endl);
    128127    status = false;
    129128  }
    130129
    131   Free(&filename);
    132130  return status;
    133131};
     
    148146  int NumberOfFragments = 0;
    149147  double TEFactor;
    150   char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseTEFactorsFile - filename");
     148  char filename[MAXSTRINGSIZE];
    151149
    152150  if (FragmentList == NULL) { // check list pointer
     
    179177  }
    180178
    181   // free memory
    182   Free(&filename);
    183 
    184179  return status;
    185180};
     
    317312  int No = 0, FragOrder = 0;
    318313  double Value = 0.;
    319   char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
     314  char buffer[MAXSTRINGSIZE];
    320315  sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT);
    321316  ifstream InputFile(buffer, ios::in);
     
    345340    InputFile.clear();
    346341  }
    347   Free(&buffer);
    348342
    349343  return AdaptiveCriteriaList;
     
    359353map<double, pair<int,int> >  * ReMapAdaptiveCriteriaListToValue(map<int, pair<double,int> > *AdaptiveCriteriaList, molecule *mol)
    360354{
    361   atom *Walker = mol->start;
     355  atom *Walker = NULL;
    362356  map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ;
    363357  DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl);
     
    391385bool MarkUpdateCandidates(bool *AtomMask, map<double, pair<int,int> > &FinalRootCandidates, int Order, molecule *mol)
    392386{
    393   atom *Walker = mol->start;
     387  atom *Walker = NULL;
    394388  int No = -1;
    395389  bool status = false;
     
    435429bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path)
    436430{
    437   atom *Walker = start;
    438431  bool status = false;
    439432
    440433  // initialize mask list
    441   for(int i=AtomCount;i--;)
     434  for(int i=getAtomCount();i--;)
    442435    AtomMask[i] = false;
    443436
    444437  if (Order < 0) { // adaptive increase of BondOrder per site
    445     if (AtomMask[AtomCount] == true)  // break after one step
     438    if (AtomMask[getAtomCount()] == true)  // break after one step
    446439      return false;
    447440
     
    457450    if (AdaptiveCriteriaList->empty()) {
    458451      DoeLog(2) && (eLog()<< Verbose(2) << "Unable to parse file, incrementing all." << endl);
    459       while (Walker->next != end) {
    460         Walker = Walker->next;
     452      for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    461453    #ifdef ADDHYDROGEN
    462         if (Walker->type->Z != 1) // skip hydrogen
     454        if ((*iter)->type->Z != 1) // skip hydrogen
    463455    #endif
    464456        {
    465           AtomMask[Walker->nr] = true;  // include all (non-hydrogen) atoms
     457          AtomMask[(*iter)->nr] = true;  // include all (non-hydrogen) atoms
    466458          status = true;
    467459        }
     
    474466    MarkUpdateCandidates(AtomMask, *FinalRootCandidates, Order, this);
    475467
    476     Free(&IndexKeySetList);
    477     Free(&AdaptiveCriteriaList);
    478     Free(&FinalRootCandidates);
     468    delete[](IndexKeySetList);
     469    delete[](AdaptiveCriteriaList);
     470    delete[](FinalRootCandidates);
    479471  } else { // global increase of Bond Order
    480     while (Walker->next != end) {
    481       Walker = Walker->next;
     472    for(molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    482473  #ifdef ADDHYDROGEN
    483       if (Walker->type->Z != 1) // skip hydrogen
     474      if ((*iter)->type->Z != 1) // skip hydrogen
    484475  #endif
    485476      {
    486         AtomMask[Walker->nr] = true;  // include all (non-hydrogen) atoms
    487         if ((Order != 0) && (Walker->AdaptiveOrder < Order)) // && (Walker->AdaptiveOrder < MinimumRingSize[Walker->nr]))
     477        AtomMask[(*iter)->nr] = true;  // include all (non-hydrogen) atoms
     478        if ((Order != 0) && ((*iter)->AdaptiveOrder < Order)) // && ((*iter)->AdaptiveOrder < MinimumRingSize[(*iter)->nr]))
    488479          status = true;
    489480      }
    490481    }
    491     if ((Order == 0) && (AtomMask[AtomCount] == false))  // single stepping, just check
     482    if ((!Order) && (!AtomMask[getAtomCount()]))  // single stepping, just check
    492483      status = true;
    493484
     
    500491  }
    501492
    502   PrintAtomMask(AtomMask, AtomCount); // for debugging
     493  PrintAtomMask(AtomMask, getAtomCount()); // for debugging
    503494
    504495  return status;
     
    516507    return false;
    517508  }
    518   SortIndex = Malloc<int>(AtomCount, "molecule::CreateMappingLabelsToConfigSequence: *SortIndex");
    519   for(int i=AtomCount;i--;)
     509  SortIndex = new int[getAtomCount()];
     510  for(int i=getAtomCount();i--;)
    520511    SortIndex[i] = -1;
    521512
     
    524515
    525516  return true;
     517};
     518
     519
     520
     521/** Creates a lookup table for true father's Atom::Nr -> atom ptr.
     522 * \param *start begin of list (STL iterator, i.e. first item)
     523 * \paran *end end of list (STL iterator, i.e. one past last item)
     524 * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start)
     525 * \param count optional predetermined size for table (otherwise we set the count to highest true father id)
     526 * \return true - success, false - failure
     527 */
     528bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count)
     529{
     530  bool status = true;
     531  int AtomNo;
     532
     533  if (LookupTable != NULL) {
     534    Log() << Verbose(0) << "Pointer for Lookup table is not NULL! Aborting ..." <<endl;
     535    return false;
     536  }
     537
     538  // count them
     539  if (count == 0) {
     540    for (molecule::iterator iter = begin(); iter != end(); ++iter) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
     541      count = (count < (*iter)->GetTrueFather()->nr) ? (*iter)->GetTrueFather()->nr : count;
     542    }
     543  }
     544  if (count <= 0) {
     545    Log() << Verbose(0) << "Count of lookup list is 0 or less." << endl;
     546    return false;
     547  }
     548
     549  // allocate and fill
     550  LookupTable = new atom *[count];
     551  if (LookupTable == NULL) {
     552    eLog() << Verbose(0) << "LookupTable memory allocation failed!" << endl;
     553    performCriticalExit();
     554    status = false;
     555  } else {
     556    for (int i=0;i<count;i++)
     557      LookupTable[i] = NULL;
     558    for (molecule::iterator iter = begin(); iter != end(); ++iter) {
     559      AtomNo = (*iter)->GetTrueFather()->nr;
     560      if ((AtomNo >= 0) && (AtomNo < count)) {
     561        //*out << "Setting LookupTable[" << AtomNo << "] to " << *(*iter) << endl;
     562        LookupTable[AtomNo] = (*iter);
     563      } else {
     564        Log() << Verbose(0) << "Walker " << *(*iter) << " exceeded range of nuclear ids [0, " << count << ")." << endl;
     565        status = false;
     566        break;
     567      }
     568    }
     569  }
     570
     571  return status;
    526572};
    527573
     
    547593{
    548594  MoleculeListClass *BondFragments = NULL;
    549   int *SortIndex = NULL;
    550   int *MinimumRingSize = new int[AtomCount];
     595  int *MinimumRingSize = new int[getAtomCount()];
    551596  int FragmentCounter;
    552597  MoleculeLeafClass *MolecularWalker = NULL;
     
    576621
    577622  // create lookup table for Atom::nr
    578   FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(start, end, ListOfAtoms, AtomCount);
     623  FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(ListOfAtoms, getAtomCount());
    579624
    580625  // === compare it with adjacency file ===
    581626  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(configuration->configpath, ListOfAtoms);
    582   Free(&ListOfAtoms);
     627  delete[](ListOfAtoms);
    583628
    584629  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
     
    586631
    587632  // analysis of the cycles (print rings, get minimum cycle length) for each subgraph
    588   for(int i=AtomCount;i--;)
    589     MinimumRingSize[i] = AtomCount;
     633  for(int i=getAtomCount();i--;)
     634    MinimumRingSize[i] = getAtomCount();
    590635  MolecularWalker = Subgraphs;
    591636  FragmentCounter = 0;
     
    598643//    // check the list of local atoms for debugging
    599644//    Log() << Verbose(0) << "ListOfLocalAtoms for this subgraph is:" << endl;
    600 //    for (int i=0;i<AtomCount;i++)
     645//    for (int i=0;i<getAtomCount();i++)
    601646//      if (ListOfLocalAtoms[FragmentCounter][i] == NULL)
    602647//        Log() << Verbose(0) << "\tNULL";
     
    624669  // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle
    625670  KeyStack *RootStack = new KeyStack[Subgraphs->next->Count()];
    626   AtomMask = new bool[AtomCount+1];
    627   AtomMask[AtomCount] = false;
     671  AtomMask = new bool[getAtomCount()+1];
     672  AtomMask[getAtomCount()] = false;
    628673  FragmentationToDo = false;  // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards
    629674  while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) {
    630675    FragmentationToDo = FragmentationToDo || CheckOrder;
    631     AtomMask[AtomCount] = true;   // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
     676    AtomMask[getAtomCount()] = true;   // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
    632677    // ===== 6b. fill RootStack for each subgraph (second adaptivity check) =====
    633678    Subgraphs->next->FillRootStackForSubgraphs(RootStack, AtomMask, (FragmentCounter = 0));
     
    640685      DoLog(1) && (Log() << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl);
    641686      //MolecularWalker->Leaf->OutputListOfBonds(out);  // output atom::ListOfBonds for debugging
    642       if (MolecularWalker->Leaf->first->next != MolecularWalker->Leaf->last) {
     687      if (MolecularWalker->Leaf->hasBondStructure()) {
    643688        // call BOSSANOVA method
    644689        DoLog(0) && (Log() << Verbose(0) << endl << " ========== BOND ENERGY of subgraph " << FragmentCounter << " ========================= " << endl);
     
    672717    delete(Subgraphs);
    673718  }
    674   Free(&FragmentList);
     719  delete[](FragmentList);
    675720
    676721  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
     
    690735  if (BondFragments->ListOfMolecules.size() != 0) {
    691736    // create the SortIndex from BFS labels to order in the config file
     737    int *SortIndex = NULL;
    692738    CreateMappingLabelsToConfigSequence(SortIndex);
    693739
     
    704750    StoreKeySetFile(TotalGraph, configuration->configpath);
    705751
    706     // store Adjacency file
    707     char *filename = Malloc<char> (MAXSTRINGSIZE, "molecule::FragmentMolecule - *filename");
    708     strcpy(filename, FRAGMENTPREFIX);
    709     strcat(filename, ADJACENCYFILE);
    710     StoreAdjacencyToFile(configuration->configpath, filename);
    711     Free(&filename);
     752    {
     753      // store Adjacency file
     754      char filename[MAXSTRINGSIZE];
     755      strcpy(filename, FRAGMENTPREFIX);
     756      strcat(filename, ADJACENCYFILE);
     757      StoreAdjacencyToFile(configuration->configpath, filename);
     758    }
    712759
    713760    // store Hydrogen saturation correction file
     
    722769    // free memory for bond part
    723770    DoLog(1) && (Log() << Verbose(1) << "Freeing bond memory" << endl);
    724     Free(&FragmentList); // remove bond molecule from memory
    725     Free(&SortIndex);
     771    delete[](SortIndex);
    726772  } else {
    727773    DoLog(1) && (Log() << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl);
     
    768814bool molecule::ParseOrderAtSiteFromFile(char *path)
    769815{
    770   unsigned char *OrderArray = Calloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    771   bool *MaxArray = Calloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     816  unsigned char *OrderArray = new unsigned char[getAtomCount()];
     817  bool *MaxArray = new bool[getAtomCount()];
    772818  bool status;
    773819  int AtomNr, value;
    774820  stringstream line;
    775821  ifstream file;
     822
     823  for(int i=0;i<getAtomCount();i++) {
     824    OrderArray[i] = 0;
     825    MaxArray[i] = false;
     826  }
    776827
    777828  DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl);
     
    796847    SetAtomValueToIndexedArray( MaxArray, &atom::nr, &atom::MaxOrder );
    797848
    798     DoLog(1) && (Log() << Verbose(1) << "done." << endl);
     849    DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl);
    799850    status = true;
    800851  } else {
    801     DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
     852    DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line.str() << "." << endl);
    802853    status = false;
    803854  }
    804   Free(&OrderArray);
    805   Free(&MaxArray);
     855  delete[](OrderArray);
     856  delete[](MaxArray);
    806857
    807858  DoLog(1) && (Log() << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl);
     
    872923  atom *OtherFather = NULL;
    873924  atom *FatherOfRunner = NULL;
    874   Leaf->CountAtoms();
    875 
    876   atom *Runner = Leaf->start;
    877   while (Runner->next != Leaf->end) {
    878     Runner = Runner->next;
     925
     926#ifdef ADDHYDROGEN
     927  molecule::const_iterator runner;
     928#endif
     929  // we increment the iter just before skipping the hydrogen
     930  for (molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end();) {
    879931    LonelyFlag = true;
    880     FatherOfRunner = Runner->father;
     932    FatherOfRunner = (*iter)->father;
     933    ASSERT(FatherOfRunner,"Atom without father found");
    881934    if (SonList[FatherOfRunner->nr] != NULL)  {  // check if this, our father, is present in list
    882935      // create all bonds
     
    889942//            Log() << Verbose(3) << "Adding Bond: ";
    890943//            Log() << Verbose(0) <<
    891             Leaf->AddBond(Runner, SonList[OtherFather->nr], (*BondRunner)->BondDegree);
     944            Leaf->AddBond((*iter), SonList[OtherFather->nr], (*BondRunner)->BondDegree);
    892945//            Log() << Verbose(0) << "." << endl;
    893             //NumBonds[Runner->nr]++;
     946            //NumBonds[(*iter)->nr]++;
    894947          } else {
    895948//            Log() << Verbose(3) << "Not adding bond, labels in wrong order." << endl;
     
    899952//          Log() << Verbose(0) << ", who has no son in this fragment molecule." << endl;
    900953#ifdef ADDHYDROGEN
    901           //Log() << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;
    902           if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), Runner, FatherOfRunner, OtherFather, IsAngstroem))
     954          //Log() << Verbose(3) << "Adding Hydrogen to " << (*iter)->Name << " and a bond in between." << endl;
     955          if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))
    903956            exit(1);
    904957#endif
    905           //NumBonds[Runner->nr] += Binder->BondDegree;
     958          //NumBonds[(*iter)->nr] += Binder->BondDegree;
    906959        }
    907960      }
    908961    } else {
    909       DoeLog(1) && (eLog()<< Verbose(1) << "Son " << Runner->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl);
    910     }
    911     if ((LonelyFlag) && (Leaf->AtomCount > 1)) {
    912       DoLog(0) && (Log() << Verbose(0) << *Runner << "has got bonds only to hydrogens!" << endl);
    913     }
     962    DoeLog(1) && (eLog()<< Verbose(1) << "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl);
     963    }
     964    if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {
     965      DoLog(0) && (Log() << Verbose(0) << **iter << "has got bonds only to hydrogens!" << endl);
     966    }
     967    ++iter;
    914968#ifdef ADDHYDROGEN
    915     while ((Runner->next != Leaf->end) && (Runner->next->type->Z == 1)) // skip added hydrogen
    916       Runner = Runner->next;
     969    while ((iter != Leaf->end()) && ((*iter)->type->Z == 1)){ // skip added hydrogen
     970      iter++;
     971    }
    917972#endif
    918973  }
     
    929984molecule * molecule::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)
    930985{
    931   atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
     986  atom **SonList = new atom*[getAtomCount()];
    932987  molecule *Leaf = World::getInstance().createMolecule();
     988
     989  for(int i=0;i<getAtomCount();i++)
     990    SonList[i] = NULL;
    933991
    934992//  Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl;
     
    939997
    940998  //Leaflet->Leaf->ScanForPeriodicCorrection(out);
    941   Free(&SonList);
     999  delete[](SonList);
    9421000//  Log() << Verbose(1) << "End of StoreFragmentFromKeyset." << endl;
    9431001  return Leaf;
     
    10841142  int bits, TouchedIndex, SubSetDimension, SP, Added;
    10851143  int SpaceLeft;
    1086   int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList");
    1087   bond **BondsList = NULL;
     1144  int *TouchedList = new int[SubOrder + 1];
    10881145  KeySetTestPair TestKeySetInsert;
    10891146
     
    11241181
    11251182          // then allocate and fill the list
    1126           BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
     1183          bond *BondsList[SubSetDimension];
    11271184          SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
    11281185
     
    11301187          Log() << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
    11311188          SPFragmentGenerator(FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
    1132 
    1133           Free(&BondsList);
    11341189        }
    11351190      } else {
     
    11531208    }
    11541209  }
    1155   Free(&TouchedList);
     1210  delete[](TouchedList);
    11561211  Log() << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl;
    11571212};
     
    11651220void InitialiseSPList(int Order, struct UniqueFragments &FragmentSearch)
    11661221{
    1167   FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList");
    1168   FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
     1222  FragmentSearch.BondsPerSPList = new bond* [Order * 2];
     1223  FragmentSearch.BondsPerSPCount = new int[Order];
    11691224  for (int i=Order;i--;) {
    11701225    FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
     
    11841239void FreeSPList(int Order, struct UniqueFragments &FragmentSearch)
    11851240{
    1186   Free(&FragmentSearch.BondsPerSPCount);
     1241  delete[](FragmentSearch.BondsPerSPCount);
    11871242  for (int i=Order;i--;) {
    11881243    delete(FragmentSearch.BondsPerSPList[2*i]);
    11891244    delete(FragmentSearch.BondsPerSPList[2*i+1]);
    11901245  }
    1191   Free(&FragmentSearch.BondsPerSPList);
     1246  delete[](FragmentSearch.BondsPerSPList);
    11921247};
    11931248
     
    13701425int molecule::PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet)
    13711426{
    1372   bond **BondsList = NULL;
    13731427  int Counter = FragmentSearch.FragmentCounter; // mark current value of counter
    13741428
     
    13941448
    13951449    // prepare the subset and call the generator
    1396     BondsList = Calloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     1450    bond* BondsList[FragmentSearch.BondsPerSPCount[0]];
     1451    for(int i=0;i<FragmentSearch.BondsPerSPCount[0];i++)
     1452      BondsList[i] = NULL;
    13971453    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
    13981454
    13991455    SPFragmentGenerator(&FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
    1400 
    1401     Free(&BondsList);
    14021456  } else {
    14031457    DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl);
     
    15071561      }
    15081562    }
    1509     Free(&FragmentLowerOrdersList[RootNr]);
     1563    delete[](FragmentLowerOrdersList[RootNr]);
    15101564    RootNr++;
    15111565  }
    1512   Free(&FragmentLowerOrdersList);
     1566  delete[](FragmentLowerOrdersList);
    15131567};
    15141568
     
    15491603  // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
    15501604  // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5)
    1551   NumMoleculesOfOrder = Calloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    1552   FragmentLowerOrdersList = Calloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
     1605  NumMoleculesOfOrder = new int[UpgradeCount];
     1606  FragmentLowerOrdersList = new Graph**[UpgradeCount];
     1607
     1608  for(int i=0;i<UpgradeCount;i++) {
     1609    NumMoleculesOfOrder[i] = 0;
     1610    FragmentLowerOrdersList[i] = NULL;
     1611  }
    15531612
    15541613  // initialise the fragments structure
     
    15561615  FragmentSearch.FragmentSet = new KeySet;
    15571616  FragmentSearch.Root = FindAtom(RootKeyNr);
    1558   FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    1559   for (int i=AtomCount;i--;) {
     1617  FragmentSearch.ShortestPathList = new int[getAtomCount()];
     1618  for (int i=getAtomCount();i--;) {
    15601619    FragmentSearch.ShortestPathList[i] = -1;
    15611620  }
    15621621
    15631622  // Construct the complete KeySet which we need for topmost level only (but for all Roots)
    1564   atom *Walker = start;
    15651623  KeySet CompleteMolecule;
    1566   while (Walker->next != end) {
    1567     Walker = Walker->next;
    1568     CompleteMolecule.insert(Walker->GetTrueFather()->nr);
     1624  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     1625    CompleteMolecule.insert((*iter)->GetTrueFather()->nr);
    15691626  }
    15701627
     
    15771634    RootKeyNr = RootStack.front();
    15781635    RootStack.pop_front();
    1579     Walker = FindAtom(RootKeyNr);
     1636    atom *Walker = FindAtom(RootKeyNr);
    15801637    // check cyclic lengths
    15811638    //if ((MinimumRingSize[Walker->GetTrueFather()->nr] != -1) && (Walker->GetTrueFather()->AdaptiveOrder+1 > MinimumRingSize[Walker->GetTrueFather()->nr])) {
     
    15921649      // allocate memory for all lower level orders in this 1D-array of ptrs
    15931650      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
    1594       FragmentLowerOrdersList[RootNr] = Calloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
     1651      FragmentLowerOrdersList[RootNr] = new Graph*[NumLevels];
     1652      for (int i=0;i<NumLevels;i++)
     1653        FragmentLowerOrdersList[RootNr][i] = NULL;
    15951654
    15961655      // create top order where nothing is reduced
     
    16281687
    16291688  // cleanup FragmentSearch structure
    1630   Free(&FragmentSearch.ShortestPathList);
     1689  delete[](FragmentSearch.ShortestPathList);
    16311690  delete(FragmentSearch.FragmentSet);
    16321691
     
    16411700  CombineAllOrderListIntoOne(FragmentList, FragmentLowerOrdersList, RootStack, this);
    16421701  FreeAllOrdersList(FragmentLowerOrdersList, RootStack, this);
    1643   Free(&NumMoleculesOfOrder);
     1702  delete[](NumMoleculesOfOrder);
    16441703
    16451704  DoLog(0) && (Log() << Verbose(0) << "End of FragmentBOSSANOVA." << endl);
     
    16641723  Vector Translationvector;
    16651724  //class StackClass<atom *> *CompStack = NULL;
    1666   class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount);
     1725  class StackClass<atom *> *AtomStack = new StackClass<atom *>(getAtomCount());
    16671726  bool flag = true;
    16681727
    16691728  DoLog(2) && (Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl);
    16701729
    1671   ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     1730  ColorList = new enum Shading[getAtomCount()];
     1731  for (int i=0;i<getAtomCount();i++)
     1732    ColorList[i] = (enum Shading)0;
    16721733  while (flag) {
    16731734    // remove bonds that are beyond bonddistance
    16741735    Translationvector.Zero();
    16751736    // scan all bonds
    1676     Binder = first;
    16771737    flag = false;
    1678     while ((!flag) && (Binder->next != last)) {
    1679       Binder = Binder->next;
    1680       for (int i=NDIM;i--;) {
    1681         tmp = fabs(Binder->leftatom->x[i] - Binder->rightatom->x[i]);
    1682         //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl;
    1683         if (tmp > BondDistance) {
    1684           OtherBinder = Binder->next; // note down binding partner for later re-insertion
    1685           unlink(Binder);   // unlink bond
    1686           DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl);
    1687           flag = true;
    1688           break;
     1738    for(molecule::iterator AtomRunner = begin(); (!flag) && (AtomRunner != end()); ++AtomRunner)
     1739      for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); (!flag) && (BondRunner != (*AtomRunner)->ListOfBonds.end()); ++BondRunner) {
     1740        Binder = (*BondRunner);
     1741        for (int i=NDIM;i--;) {
     1742          tmp = fabs(Binder->leftatom->x[i] - Binder->rightatom->x[i]);
     1743          //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl;
     1744          if (tmp > BondDistance) {
     1745            OtherBinder = Binder->next; // note down binding partner for later re-insertion
     1746            unlink(Binder);   // unlink bond
     1747            DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl);
     1748            flag = true;
     1749            break;
     1750          }
    16891751        }
    16901752      }
    1691     }
    16921753    if (flag) {
    16931754      // create translation vector from their periodically modified distance
     
    17011762      Log() << Verbose(0) << Translationvector <<  endl;
    17021763      // apply to all atoms of first component via BFS
    1703       for (int i=AtomCount;i--;)
     1764      for (int i=getAtomCount();i--;)
    17041765        ColorList[i] = white;
    17051766      AtomStack->Push(Binder->leftatom);
     
    17271788  // free allocated space from ReturnFullMatrixforSymmetric()
    17281789  delete(AtomStack);
    1729   Free(&ColorList);
    1730   Free(&matrix);
     1790  delete[](ColorList);
     1791  delete[](matrix);
    17311792  DoLog(2) && (Log() << Verbose(2) << "End of ScanForPeriodicCorrection." << endl);
    17321793};
Note: See TracChangeset for help on using the changeset viewer.