Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecules.cpp

    rf7f7a4 r29812d  
    66
    77#include "config.hpp"
     8#include "memoryallocator.hpp"
    89#include "molecules.hpp"
    910
     
    5556  if (ListOfBondsPerAtom != NULL)
    5657    for(int i=AtomCount;i--;)
    57       Free((void **)&ListOfBondsPerAtom[i], "molecule::~molecule: ListOfBondsPerAtom[i]");
    58   Free((void **)&ListOfBondsPerAtom, "molecule::~molecule: ListOfBondsPerAtom");
    59   Free((void **)&NumberOfBondsPerAtom, "molecule::~molecule: NumberOfBondsPerAtom");
     58      Free(&ListOfBondsPerAtom[i]);
     59  Free(&ListOfBondsPerAtom);
     60  Free(&NumberOfBondsPerAtom);
    6061  if (TesselStruct != NULL)
    6162    delete(TesselStruct);
     
    163164        NoNonHydrogen++;
    164165      if (pointer->Name == NULL) {
    165         Free((void **)&pointer->Name, "molecule::AddAtom: *pointer->Name");
    166         pointer->Name = (char *) Malloc(sizeof(char)*6, "molecule::AddAtom: *pointer->Name");
     166        Free(&pointer->Name);
     167        pointer->Name = Malloc<char>(6, "molecule::AddAtom: *pointer->Name");
    167168        sprintf(pointer->Name, "%2s%02d", pointer->type->symbol, pointer->nr+1);
    168169      }
     
    176177 * Increases molecule::last_atom and gives last number to added atom.
    177178 * \param *pointer allocated and set atom
    178  * \return true - succeeded, false - atom not found in list
     179 * \return pointer to the newly added atom
    179180 */
    180181atom * molecule::AddCopyAtom(atom *pointer)
     
    182183  if (pointer != NULL) {
    183184    atom *walker = new atom(pointer);
    184     walker->Name = (char *) Malloc(sizeof(char)*strlen(pointer->Name)+1, "atom::atom: *Name");
     185    walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
    185186    strcpy (walker->Name, pointer->Name);
    186187    walker->nr = last_atom++;  // increase number within molecule
     
    267268    Orthovector1.MatrixMultiplication(matrix);
    268269    InBondvector.SubtractVector(&Orthovector1); // subtract just the additional translation
    269     Free((void **)&matrix, "molecule::AddHydrogenReplacementAtom: *matrix");
     270    Free(&matrix);
    270271    bondlength = InBondvector.Norm();
    271272//    *out << Verbose(4) << "Corrected InBondvector is now: ";
     
    613614};
    614615
     616
     617/**
     618 * Copies all atoms of a molecule which are within the defined parallelepiped.
     619 *
     620 * @param offest for the origin of the parallelepiped
     621 * @param three vectors forming the matrix that defines the shape of the parallelpiped
     622 */
     623molecule* molecule::CopyMoleculeFromSubRegion(Vector offset, double *parallelepiped) {
     624  molecule *copy = new molecule(elemente);
     625  atom *Walker = start;
     626
     627  while(Walker->next != end) {
     628    Walker = Walker->next;
     629    if (Walker->x.IsInParallelepiped(offset, parallelepiped)) {
     630      cout << "Adding atom " << *Walker << endl;
     631      copy->AddCopyAtom(Walker);
     632    }
     633  }
     634
     635  //TODO: copy->BuildInducedSubgraph((ofstream *)&cout, this);
     636
     637  return copy;
     638}
     639
    615640/** Adds a bond to a the molecule specified by two atoms, \a *first and \a *second.
    616641 * Also updates molecule::BondCount and molecule::NoNonBonds.
     
    662687{
    663688  int length = 0;
    664   const char *molname = strrchr(filename, '/');
    665   if (molname != NULL)
    666     molname += sizeof(char);  // search for filename without dirs
    667   else
    668     molname = filename; // contains no slashes
     689  char *molname = strrchr(filename, '/')+sizeof(char);  // search for filename without dirs
    669690  char *endname = strchr(molname, '.');
    670691  if ((endname == NULL) || (endname < molname))
     
    10601081    }
    10611082  } while (!flag);
    1062   Free((void **)&matrix, "molecule::DetermineCenter: *matrix");
     1083  Free(&matrix);
    10631084  Center.Scale(1./(double)AtomCount);
    10641085};
     
    11721193/** Evaluates the potential energy used for constrained molecular dynamics.
    11731194 * \f$V_i^{con} = c^{bond} \cdot | r_{P(i)} - R_i | + sum_{i \neq j} C^{min} \cdot \frac{1}{C_{ij}} + C^{inj} \Bigl (1 - \theta \bigl (\prod_{i \neq j} (P(i) - P(j)) \bigr ) \Bigr )\f$
    1174  *     where the first term points to the target in minimum distance, the second is a penalty for trajectories lying too close to each other (\f$C_{ij}\f$ is minimum distance between
     1195 *     where the first term points to the target in minimum distance, the second is a penalty for trajectories lying too close to each other (\f$C_{ij}$ is minimum distance between
    11751196 *     trajectories i and j) and the third term is a penalty for two atoms trying to each the same target point.
    11761197 * Note that for the second term we have to solve the following linear system:
     
    13191340{
    13201341  stringstream zeile1, zeile2;
    1321   int *DoubleList = (int *) Malloc(Nr*sizeof(int), "PrintPermutationMap: *DoubleList");
     1342  int *DoubleList = Malloc<int>(Nr, "PrintPermutationMap: *DoubleList");
    13221343  int doubles = 0;
    13231344  for (int i=0;i<Nr;i++)
     
    13341355    doubles++;
    13351356 // *out << "Found " << doubles << " Doubles." << endl;
    1336   Free((void **)&DoubleList, "PrintPermutationMap: *DoubleList");
     1357  Free(&DoubleList);
    13371358//  *out << zeile1.str() << endl << zeile2.str() << endl;
    13381359};
     
    13681389{
    13691390  double Potential, OldPotential, OlderPotential;
    1370   PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::MinimiseConstrainedPotential: **PermutationMap");
    1371   DistanceMap **DistanceList = (DistanceMap **) Malloc(AtomCount*sizeof(DistanceMap *), "molecule::MinimiseConstrainedPotential: **DistanceList");
    1372   DistanceMap::iterator *DistanceIterators = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *DistanceIterators");
    1373   int *DoubleList = (int *) Malloc(AtomCount*sizeof(int), "molecule::MinimiseConstrainedPotential: *DoubleList");
    1374   DistanceMap::iterator *StepList = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *StepList");
     1391  PermutationMap = Malloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: **PermutationMap");
     1392  DistanceMap **DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: **DistanceList");
     1393  DistanceMap::iterator *DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *DistanceIterators");
     1394  int *DoubleList = Malloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: *DoubleList");
     1395  DistanceMap::iterator *StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *StepList");
    13751396  double constants[3];
    13761397  int round;
     
    14481469    }
    14491470  *out << Verbose(1) << "done." << endl;
    1450   Free((void **)&DoubleList, "molecule::MinimiseConstrainedPotential: *DoubleList");
     1471  Free(&DoubleList);
    14511472  // argument minimise the constrained potential in this injective PermutationMap
    14521473  *out << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl;
     
    15291550  for (int i=AtomCount; i--;)
    15301551    DistanceList[i]->clear();
    1531   Free((void **)&DistanceList, "molecule::MinimiseConstrainedPotential: **DistanceList");
    1532   Free((void **)&DistanceIterators, "molecule::MinimiseConstrainedPotential: *DistanceIterators");
     1552  Free(&DistanceList);
     1553  Free(&DistanceIterators);
    15331554  return ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem);
    15341555};
     
    15661587 * \param endstep stating final configuration in molecule::Trajectories
    15671588 * \param &config configuration structure
    1568  * \param MapByIdentity if true we just use the identity to map atoms in start config to end config, if not we find mapping by \sa MinimiseConstrainedPotential()
    15691589 * \return true - success in writing step files, false - error writing files or only one step in molecule::Trajectories
    15701590 */
    1571 bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration, bool MapByIdentity)
     1591bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration)
    15721592{
    15731593  molecule *mol = NULL;
     
    15781598  atom **PermutationMap = NULL;
    15791599  atom *Walker = NULL, *Sprinter = NULL;
    1580   if (!MapByIdentity)
    1581     MinimiseConstrainedPotential(out, PermutationMap, startstep, endstep, configuration.GetIsAngstroem());
    1582   else {
    1583     PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap");
    1584     Walker = start;
    1585     while (Walker->next != end) {
    1586       Walker = Walker->next;
    1587       PermutationMap[Walker->nr] = Walker;   // always pick target with the smallest distance
    1588     }
    1589   }
     1600  MinimiseConstrainedPotential(out, PermutationMap, startstep, endstep, configuration.GetIsAngstroem());
    15901601
    15911602  // check whether we have sufficient space in Trajectories for each atom
     
    16371648 
    16381649  // store the list to single step files
    1639   int *SortIndex = (int *) Malloc(AtomCount*sizeof(int), "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
     1650  int *SortIndex = Malloc<int>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
    16401651  for (int i=AtomCount; i--; )
    16411652    SortIndex[i] = i;
     
    16431654 
    16441655  // free and return
    1645   Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
     1656  Free(&PermutationMap);
    16461657  delete(MoleculePerStep);
    16471658  return status;
     
    17021713      ConstrainedPotentialEnergy = MinimiseConstrainedPotential(out, PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem());
    17031714      EvaluateConstrainedForces(out, configuration.DoConstrainedMD, 0, PermutationMap, &Force);
    1704       Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
     1715      Free(&PermutationMap);
    17051716    }
    17061717   
     
    24022413        if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it
    24032414          NoNonHydrogen++;
    2404         Free((void **)&Walker->Name, "molecule::CountAtoms: *walker->Name");
    2405         Walker->Name = (char *) Malloc(sizeof(char)*6, "molecule::CountAtoms: *walker->Name");
     2415        Free(&Walker->Name);
     2416        Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
    24062417        sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);
    24072418        *out << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;
     
    26142625    NumberCells = divisor[0]*divisor[1]*divisor[2];
    26152626    *out << Verbose(1) << "Allocating " << NumberCells << " cells." << endl;
    2616     CellList = (molecule **) Malloc(sizeof(molecule *)*NumberCells, "molecule::CreateAdjacencyList - ** CellList");
     2627    CellList = Malloc<molecule*>(NumberCells, "molecule::CreateAdjacencyList - ** CellList");
    26172628    for (int i=NumberCells;i--;)
    26182629      CellList[i] = NULL;
     
    26962707        delete(CellList[i]);
    26972708      }
    2698     Free((void **)&CellList, "molecule::CreateAdjacencyList - ** CellList");
     2709    Free(&CellList);
    26992710
    27002711    // create the adjacency list per atom
     
    27612772    *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
    27622773  *out << Verbose(0) << "End of CreateAdjacencyList." << endl;
    2763   Free((void **)&matrix, "molecule::CreateAdjacencyList: *matrix");
     2774  Free(&matrix);
    27642775
    27652776};
     
    29712982void molecule::CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *  BackEdgeStack, int *&MinimumRingSize)
    29722983{
    2973   atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::CyclicStructureAnalysis: **PredecessorList");
    2974   int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList");
    2975   enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CyclicStructureAnalysis: *ColorList");
     2984  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CyclicStructureAnalysis: **PredecessorList");
     2985  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList");
     2986  enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::CyclicStructureAnalysis: *ColorList");
    29762987  class StackClass<atom *> *BFSStack = new StackClass<atom *> (AtomCount);   // will hold the current ring
    29772988  class StackClass<atom *> *TouchedStack = new StackClass<atom *> (AtomCount);   // contains all "touched" atoms (that need to be reset after BFS loop)
     
    31643175    *out << Verbose(1) << "No rings were detected in the molecular structure." << endl;
    31653176
    3166   Free((void **)&PredecessorList, "molecule::CyclicStructureAnalysis: **PredecessorList");
    3167   Free((void **)&ShortestPathList, "molecule::CyclicStructureAnalysis: **ShortestPathList");
    3168   Free((void **)&ColorList, "molecule::CyclicStructureAnalysis: **ColorList");
     3177  Free(&PredecessorList);
     3178  Free(&ShortestPathList);
     3179  Free(&ColorList);
    31693180  delete(BFSStack);
    31703181};
     
    32103221    Walker = Walker->next;
    32113222    if (Walker->ComponentNr != NULL)
    3212       Free((void **)&Walker->ComponentNr, "molecule::InitComponentNumbers: **Walker->ComponentNr");
    3213     Walker->ComponentNr = (int *) Malloc(sizeof(int)*NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
     3223      Free(&Walker->ComponentNr);
     3224    Walker->ComponentNr = Malloc<int>(NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
    32143225    for (int i=NumberOfBondsPerAtom[Walker->nr];i--;)
    32153226      Walker->ComponentNr[i] = -1;
     
    33343345  int NumberOfFragments = 0;
    33353346  double TEFactor;
    3336   char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
     3347  char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
    33373348
    33383349  if (FragmentList == NULL) { // check list pointer
     
    33463357  if (InputFile != NULL) {
    33473358    // each line represents a new fragment
    3348     char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
     3359    char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
    33493360    // 1. parse keysets and insert into temp. graph
    33503361    while (!InputFile.eof()) {
     
    33613372    InputFile.close();
    33623373    InputFile.clear();
    3363     Free((void **)&buffer, "molecule::ParseKeySetFile - *buffer");
     3374    Free(&buffer);
    33643375    *out << Verbose(1) << "done." << endl;
    33653376  } else {
     
    33943405
    33953406  // free memory
    3396   Free((void **)&filename, "molecule::ParseKeySetFile - filename");
     3407  Free(&filename);
    33973408
    33983409  return status;
     
    35013512  stringstream filename;
    35023513  bool status = true;
    3503   char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
     3514  char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    35043515
    35053516  filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     
    35093520    // allocate storage structure
    35103521    int NonMatchNumber = 0;   // will number of atoms with differing bond structure
    3511     int *CurrentBonds = (int *) Malloc(sizeof(int)*8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
     3522    int *CurrentBonds = Malloc<int>(8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
    35123523    int CurrentBondsOfAtom;
    35133524
     
    35543565    } else
    35553566      *out << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl;
    3556     Free((void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds");
     3567    Free(&CurrentBonds);
    35573568  } else {
    35583569    *out << Verbose(1) << "Adjacency file not found." << endl;
     
    35603571  }
    35613572  *out << endl;
    3562   Free((void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
     3573  Free(&buffer);
    35633574
    35643575  return status;
     
    35883599      return false;
    35893600    // parse the EnergyPerFragment file
    3590     char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
     3601    char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
    35913602    sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT);
    35923603    InputFile.open(buffer, ios::in);
     
    36953706      }
    36963707    }
    3697     Free((void **)&buffer, "molecule::CheckOrderAtSite: *buffer");
     3708    Free(&buffer);
    36983709    // pick a given number of highest values and set AtomMask
    36993710  } else { // global increase of Bond Order
     
    37363747 * \param *&SortIndex Mapping array of size molecule::AtomCount
    37373748 * \return true - success, false - failure of SortIndex alloc
    3738  * \todo do we really need this still as the IonType may appear in any order due to recent changes
    37393749 */
    37403750bool molecule::CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex)
     
    37483758    return false;
    37493759  }
    3750   SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex");
     3760  SortIndex = Malloc<int>(AtomCount, "molecule::FragmentMolecule: *SortIndex");
    37513761  for(int i=AtomCount;i--;)
    37523762    SortIndex[i] = -1;
     
    38223832  // === compare it with adjacency file ===
    38233833  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms);
    3824   Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");
     3834  Free(&ListOfAtoms);
    38253835
    38263836  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
     
    39113921    delete(Subgraphs);
    39123922  }
    3913   Free((void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");
     3923  Free(&FragmentList);
    39143924
    39153925  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
     
    39583968      *out << Verbose(1) << "Freeing bond memory" << endl;
    39593969      delete(FragmentList); // remove bond molecule from memory
    3960       Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");
     3970      Free(&SortIndex);
    39613971    } else
    39623972      *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
     
    40464056bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path)
    40474057{
    4048   unsigned char *OrderArray = (unsigned char *) Malloc(sizeof(unsigned char)*AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    4049   bool *MaxArray = (bool *) Malloc(sizeof(bool)*AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     4058  unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
     4059  bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
    40504060  bool status;
    40514061  int AtomNr, value;
     
    40884098    status = false;
    40894099  }
    4090   Free((void **)&OrderArray, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    4091   Free((void **)&MaxArray, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     4100  Free(&OrderArray);
     4101  Free(&MaxArray);
    40924102
    40934103  *out << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl;
     
    41124122  if (ListOfBondsPerAtom != NULL) {
    41134123    for(int i=AtomCount;i--;)
    4114       Free((void **)&ListOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom[i]");
    4115     Free((void **)&ListOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom");
     4124      Free(&ListOfBondsPerAtom[i]);
     4125    Free(&ListOfBondsPerAtom);
    41164126  }
    41174127  if (NumberOfBondsPerAtom != NULL)
    4118     Free((void **)&NumberOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: NumberOfBondsPerAtom");
    4119   ListOfBondsPerAtom = (bond ***) Malloc(sizeof(bond **)*AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom");
    4120   NumberOfBondsPerAtom = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom");
     4128    Free(&NumberOfBondsPerAtom);
     4129  ListOfBondsPerAtom = Malloc<bond**>(AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom");
     4130  NumberOfBondsPerAtom = Malloc<int>(AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom");
    41214131
    41224132  // reset bond counts per atom
     
    41324142  for(int i=AtomCount;i--;) {
    41334143    // allocate list of bonds per atom
    4134     ListOfBondsPerAtom[i] = (bond **) Malloc(sizeof(bond *)*NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
     4144    ListOfBondsPerAtom[i] = Malloc<bond*>(NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
    41354145    // clear the list again, now each NumberOfBondsPerAtom marks current free field
    41364146    NumberOfBondsPerAtom[i] = 0;
     
    41744184void molecule::BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem)
    41754185{
    4176   atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::BreadthFirstSearchAdd: **PredecessorList");
    4177   int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList");
    4178   enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList");
     4186  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::BreadthFirstSearchAdd: **PredecessorList");
     4187  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList");
     4188  enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList");
    41794189  class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount);
    41804190  atom *Walker = NULL, *OtherAtom = NULL;
     
    42814291    *out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
    42824292  }
    4283   Free((void **)&PredecessorList, "molecule::BreadthFirstSearchAdd: **PredecessorList");
    4284   Free((void **)&ShortestPathList, "molecule::BreadthFirstSearchAdd: **ShortestPathList");
    4285   Free((void **)&ColorList, "molecule::BreadthFirstSearchAdd: **ColorList");
     4293  Free(&PredecessorList);
     4294  Free(&ShortestPathList);
     4295  Free(&ColorList);
    42864296  delete(AtomStack);
    42874297};
     
    43004310  atom *Walker = NULL, *OtherAtom = NULL;
    43014311  bool status = true;
    4302   atom **ParentList = (atom **) Malloc(sizeof(atom *)*Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
     4312  atom **ParentList = Malloc<atom*>(Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
    43034313
    43044314  *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
     
    43394349  }
    43404350
    4341   Free((void **)&ParentList, "molecule::BuildInducedSubgraph: **ParentList");
     4351  Free(&ParentList);
    43424352  *out << Verbose(2) << "End of BuildInducedSubgraph." << endl;
    43434353  return status;
     
    43824392{
    43834393  atom *Runner = NULL, *FatherOfRunner = NULL, *OtherFather = NULL;
    4384   atom **SonList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::StoreFragmentFromStack: **SonList");
     4394  atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    43854395  molecule *Leaf = new molecule(elemente);
    43864396  bool LonelyFlag = false;
     
    44524462  Leaf->CreateListOfBondsPerAtom(out);
    44534463  //Leaflet->Leaf->ScanForPeriodicCorrection(out);
    4454   Free((void **)&SonList, "molecule::StoreFragmentFromStack: **SonList");
     4464  Free(&SonList);
    44554465//  *out << Verbose(1) << "End of StoreFragmentFromKeyset." << endl;
    44564466  return Leaf;
     
    44734483MoleculeListClass * molecule::CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, config *configuration)
    44744484{
    4475   atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
    4476   int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
    4477   int *Labels = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
    4478   enum Shading *ColorVertexList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
    4479   enum Shading *ColorEdgeList = (enum Shading *) Malloc(sizeof(enum Shading)*BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList");
     4485  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
     4486  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
     4487  int *Labels = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
     4488  enum Shading *ColorVertexList = Malloc<enum Shading>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
     4489  enum Shading *ColorEdgeList = Malloc<enum Shading>(BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList");
    44804490  StackClass<atom *> *RootStack = new StackClass<atom *>(AtomCount);
    44814491  StackClass<atom *> *TouchedStack = new StackClass<atom *>((int)pow(4,Order)+2); // number of atoms reached from one with maximal 4 bonds plus Root itself
     
    46074617
    46084618  // free memory and exit
    4609   Free((void **)&PredecessorList, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
    4610   Free((void **)&ShortestPathList, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
    4611   Free((void **)&Labels, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
    4612   Free((void **)&ColorVertexList, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
     4619  Free(&PredecessorList);
     4620  Free(&ShortestPathList);
     4621  Free(&Labels);
     4622  Free(&ColorVertexList);
    46134623  delete(RootStack);
    46144624  delete(TouchedStack);
     
    46604670  int Removal;
    46614671  int SpaceLeft;
    4662   int *TouchedList = (int *) Malloc(sizeof(int)*(SubOrder+1), "molecule::SPFragmentGenerator: *TouchedList");
     4672  int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList");
    46634673  bond *Binder = NULL;
    46644674  bond **BondsList = NULL;
     
    46684678
    46694679  // Hier muessen von 1 bis NumberOfBondsPerAtom[Walker->nr] alle Kombinationen
    4670   // von Endstuecken (aus den Bonds) hinzugefᅵᅵgt werden und fᅵᅵr verbleibende ANOVAOrder
    4671   // rekursiv GraphCrawler in der nᅵᅵchsten Ebene aufgerufen werden
     4680  // von Endstuecken (aus den Bonds) hinzugefuegt werden und fuer verbleibende ANOVAOrder
     4681  // rekursiv GraphCrawler in der naechsten Ebene aufgerufen werden
    46724682
    46734683  *out << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl;
     
    47294739          }
    47304740          // then allocate and fill the list
    4731           BondsList = (bond **) Malloc(sizeof(bond *)*SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
     4741          BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
    47324742          SubSetDimension = 0;
    47334743          Binder = FragmentSearch->BondsPerSPList[2*SP];
     
    47414751          *out << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
    47424752          SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
    4743           Free((void **)&BondsList, "molecule::SPFragmentGenerator: **BondsList");
     4753          Free(&BondsList);
    47444754        }
    47454755      } else {
     
    47754785    }
    47764786  }
    4777   Free((void **)&TouchedList, "molecule::SPFragmentGenerator: *TouchedList");
     4787  Free(&TouchedList);
    47784788  *out << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl;
    47794789};
     
    49534963    *out << Verbose(0) << "Preparing subset for this root and calling generator." << endl;
    49544964    // prepare the subset and call the generator
    4955     BondsList = (bond **) Malloc(sizeof(bond *)*FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     4965    BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
    49564966    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
    49574967
    49584968    SPFragmentGenerator(out, &FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
    49594969
    4960     Free((void **)&BondsList, "molecule::PowerSetGenerator: **BondsList");
     4970    Free(&BondsList);
    49614971  } else {
    49624972    *out << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl;
     
    50125022  *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl;
    50135023
    5014   ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     5024  ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
    50155025  while (flag) {
    50165026    // remove bonds that are beyond bonddistance
     
    50735083  // free allocated space from ReturnFullMatrixforSymmetric()
    50745084  delete(AtomStack);
    5075   Free((void **)&ColorList, "molecule::ScanForPeriodicCorrection: *ColorList");
    5076   Free((void **)&matrix, "molecule::ScanForPeriodicCorrection: *matrix");
     5085  Free(&ColorList);
     5086  Free(&matrix);
    50775087  *out << Verbose(2) << "End of ScanForPeriodicCorrection." << endl;
    50785088};
     
    50845094double * molecule::ReturnFullMatrixforSymmetric(double *symm)
    50855095{
    5086   double *matrix = (double *) Malloc(sizeof(double)*NDIM*NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
     5096  double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
    50875097  matrix[0] = symm[0];
    50885098  matrix[1] = symm[1];
     
    52115221  // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
    52125222  // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5)
    5213   NumMoleculesOfOrder = (int *) Malloc(sizeof(int)*UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    5214   FragmentLowerOrdersList = (Graph ***) Malloc(sizeof(Graph **)*UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
     5223  NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
     5224  FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    52155225
    52165226  // initialise the fragments structure
    5217   FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
     5227  FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    52185228  FragmentSearch.FragmentCounter = 0;
    52195229  FragmentSearch.FragmentSet = new KeySet;
     
    52505260
    52515261      // initialise Order-dependent entries of UniqueFragments structure
    5252       FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
    5253       FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
     5262      FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList");
     5263      FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
    52545264      for (int i=Order;i--;) {
    52555265        FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
     
    52625272      // allocate memory for all lower level orders in this 1D-array of ptrs
    52635273      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
    5264       FragmentLowerOrdersList[RootNr] = (Graph **) Malloc(sizeof(Graph *)*NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
     5274      FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    52655275      for (int i=0;i<NumLevels;i++)
    52665276        FragmentLowerOrdersList[RootNr][i] = NULL;
     
    53295339
    53305340      // free Order-dependent entries of UniqueFragments structure for next loop cycle
    5331       Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");
     5341      Free(&FragmentSearch.BondsPerSPCount);
    53325342      for (int i=Order;i--;) {
    53335343        delete(FragmentSearch.BondsPerSPList[2*i]);
    53345344        delete(FragmentSearch.BondsPerSPList[2*i+1]);
    53355345      }
    5336       Free((void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");
     5346      Free(&FragmentSearch.BondsPerSPList);
    53375347    }
    53385348  }
     
    53425352
    53435353  // cleanup FragmentSearch structure
    5344   Free((void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");
     5354  Free(&FragmentSearch.ShortestPathList);
    53455355  delete(FragmentSearch.FragmentSet);
    53465356
     
    53735383      }
    53745384    }
    5375     Free((void **)&FragmentLowerOrdersList[RootNr], "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
     5385    Free(&FragmentLowerOrdersList[RootNr]);
    53765386    RootNr++;
    53775387  }
    5378   Free((void **)&FragmentLowerOrdersList, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    5379   Free((void **)&NumMoleculesOfOrder, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
     5388  Free(&FragmentLowerOrdersList);
     5389  Free(&NumMoleculesOfOrder);
    53805390
    53815391  *out << Verbose(0) << "End of FragmentBOSSANOVA." << endl;
     
    54675477  if (result) {
    54685478    *out << Verbose(5) << "Calculating distances" << endl;
    5469     Distances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
    5470     OtherDistances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
     5479    Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
     5480    OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
    54715481    Walker = start;
    54725482    while (Walker->next != end) {
     
    54825492    /// ... sort each list (using heapsort (o(N log N)) from GSL)
    54835493    *out << Verbose(5) << "Sorting distances" << endl;
    5484     PermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
    5485     OtherPermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
     5494    PermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
     5495    OtherPermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
    54865496    gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles);
    54875497    gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);
    5488     PermutationMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     5498    PermutationMap = Malloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
    54895499    *out << Verbose(5) << "Combining Permutation Maps" << endl;
    54905500    for(int i=AtomCount;i--;)
    54915501      PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
    54925502
    5493     /// ... and compare them step by step, whether the difference is individiually(!) below \a threshold for all
     5503    /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all
    54945504    *out << Verbose(4) << "Comparing distances" << endl;
    54955505    flag = 0;
     
    54995509        flag = 1;
    55005510    }
    5501     Free((void **)&PermMap, "molecule::IsEqualToWithinThreshold: *PermMap");
    5502     Free((void **)&OtherPermMap, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
    5503 
    5504     /// free memory
    5505     Free((void **)&Distances, "molecule::IsEqualToWithinThreshold: Distances");
    5506     Free((void **)&OtherDistances, "molecule::IsEqualToWithinThreshold: OtherDistances");
     5511
     5512    // free memory
     5513    Free(&PermMap);
     5514    Free(&OtherPermMap);
     5515    Free(&Distances);
     5516    Free(&OtherDistances);
    55075517    if (flag) { // if not equal
    5508       Free((void **)&PermutationMap, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     5518      Free(&PermutationMap);
    55095519      result = false;
    55105520    }
     
    55325542  atom *Walker = NULL, *OtherWalker = NULL;
    55335543  *out << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;
    5534   int *AtomicMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::GetAtomicMap: *AtomicMap");  //Calloc
     5544  int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap");
    55355545  for (int i=AtomCount;i--;)
    55365546    AtomicMap[i] = -1;
Note: See TracChangeset for help on using the changeset viewer.