Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecules.cpp

    r29812d rf7f7a4  
    66
    77#include "config.hpp"
    8 #include "memoryallocator.hpp"
    98#include "molecules.hpp"
    109
     
    5655  if (ListOfBondsPerAtom != NULL)
    5756    for(int i=AtomCount;i--;)
    58       Free(&ListOfBondsPerAtom[i]);
    59   Free(&ListOfBondsPerAtom);
    60   Free(&NumberOfBondsPerAtom);
     57      Free((void **)&ListOfBondsPerAtom[i], "molecule::~molecule: ListOfBondsPerAtom[i]");
     58  Free((void **)&ListOfBondsPerAtom, "molecule::~molecule: ListOfBondsPerAtom");
     59  Free((void **)&NumberOfBondsPerAtom, "molecule::~molecule: NumberOfBondsPerAtom");
    6160  if (TesselStruct != NULL)
    6261    delete(TesselStruct);
     
    164163        NoNonHydrogen++;
    165164      if (pointer->Name == NULL) {
    166         Free(&pointer->Name);
    167         pointer->Name = Malloc<char>(6, "molecule::AddAtom: *pointer->Name");
     165        Free((void **)&pointer->Name, "molecule::AddAtom: *pointer->Name");
     166        pointer->Name = (char *) Malloc(sizeof(char)*6, "molecule::AddAtom: *pointer->Name");
    168167        sprintf(pointer->Name, "%2s%02d", pointer->type->symbol, pointer->nr+1);
    169168      }
     
    177176 * Increases molecule::last_atom and gives last number to added atom.
    178177 * \param *pointer allocated and set atom
    179  * \return pointer to the newly added atom
     178 * \return true - succeeded, false - atom not found in list
    180179 */
    181180atom * molecule::AddCopyAtom(atom *pointer)
     
    183182  if (pointer != NULL) {
    184183    atom *walker = new atom(pointer);
    185     walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
     184    walker->Name = (char *) Malloc(sizeof(char)*strlen(pointer->Name)+1, "atom::atom: *Name");
    186185    strcpy (walker->Name, pointer->Name);
    187186    walker->nr = last_atom++;  // increase number within molecule
     
    268267    Orthovector1.MatrixMultiplication(matrix);
    269268    InBondvector.SubtractVector(&Orthovector1); // subtract just the additional translation
    270     Free(&matrix);
     269    Free((void **)&matrix, "molecule::AddHydrogenReplacementAtom: *matrix");
    271270    bondlength = InBondvector.Norm();
    272271//    *out << Verbose(4) << "Corrected InBondvector is now: ";
     
    614613};
    615614
    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  */
    623 molecule* 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 
    640615/** Adds a bond to a the molecule specified by two atoms, \a *first and \a *second.
    641616 * Also updates molecule::BondCount and molecule::NoNonBonds.
     
    687662{
    688663  int length = 0;
    689   char *molname = strrchr(filename, '/')+sizeof(char);  // search for filename without dirs
     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
    690669  char *endname = strchr(molname, '.');
    691670  if ((endname == NULL) || (endname < molname))
     
    10811060    }
    10821061  } while (!flag);
    1083   Free(&matrix);
     1062  Free((void **)&matrix, "molecule::DetermineCenter: *matrix");
    10841063  Center.Scale(1./(double)AtomCount);
    10851064};
     
    11931172/** Evaluates the potential energy used for constrained molecular dynamics.
    11941173 * \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$
    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
     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
    11961175 *     trajectories i and j) and the third term is a penalty for two atoms trying to each the same target point.
    11971176 * Note that for the second term we have to solve the following linear system:
     
    13401319{
    13411320  stringstream zeile1, zeile2;
    1342   int *DoubleList = Malloc<int>(Nr, "PrintPermutationMap: *DoubleList");
     1321  int *DoubleList = (int *) Malloc(Nr*sizeof(int), "PrintPermutationMap: *DoubleList");
    13431322  int doubles = 0;
    13441323  for (int i=0;i<Nr;i++)
     
    13551334    doubles++;
    13561335 // *out << "Found " << doubles << " Doubles." << endl;
    1357   Free(&DoubleList);
     1336  Free((void **)&DoubleList, "PrintPermutationMap: *DoubleList");
    13581337//  *out << zeile1.str() << endl << zeile2.str() << endl;
    13591338};
     
    13891368{
    13901369  double Potential, OldPotential, OlderPotential;
    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");
     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");
    13961375  double constants[3];
    13971376  int round;
     
    14691448    }
    14701449  *out << Verbose(1) << "done." << endl;
    1471   Free(&DoubleList);
     1450  Free((void **)&DoubleList, "molecule::MinimiseConstrainedPotential: *DoubleList");
    14721451  // argument minimise the constrained potential in this injective PermutationMap
    14731452  *out << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl;
     
    15501529  for (int i=AtomCount; i--;)
    15511530    DistanceList[i]->clear();
    1552   Free(&DistanceList);
    1553   Free(&DistanceIterators);
     1531  Free((void **)&DistanceList, "molecule::MinimiseConstrainedPotential: **DistanceList");
     1532  Free((void **)&DistanceIterators, "molecule::MinimiseConstrainedPotential: *DistanceIterators");
    15541533  return ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem);
    15551534};
     
    15871566 * \param endstep stating final configuration in molecule::Trajectories
    15881567 * \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()
    15891569 * \return true - success in writing step files, false - error writing files or only one step in molecule::Trajectories
    15901570 */
    1591 bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration)
     1571bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration, bool MapByIdentity)
    15921572{
    15931573  molecule *mol = NULL;
     
    15981578  atom **PermutationMap = NULL;
    15991579  atom *Walker = NULL, *Sprinter = NULL;
    1600   MinimiseConstrainedPotential(out, PermutationMap, startstep, endstep, configuration.GetIsAngstroem());
     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  }
    16011590
    16021591  // check whether we have sufficient space in Trajectories for each atom
     
    16481637 
    16491638  // store the list to single step files
    1650   int *SortIndex = Malloc<int>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
     1639  int *SortIndex = (int *) Malloc(AtomCount*sizeof(int), "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
    16511640  for (int i=AtomCount; i--; )
    16521641    SortIndex[i] = i;
     
    16541643 
    16551644  // free and return
    1656   Free(&PermutationMap);
     1645  Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
    16571646  delete(MoleculePerStep);
    16581647  return status;
     
    17131702      ConstrainedPotentialEnergy = MinimiseConstrainedPotential(out, PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem());
    17141703      EvaluateConstrainedForces(out, configuration.DoConstrainedMD, 0, PermutationMap, &Force);
    1715       Free(&PermutationMap);
     1704      Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
    17161705    }
    17171706   
     
    24132402        if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it
    24142403          NoNonHydrogen++;
    2415         Free(&Walker->Name);
    2416         Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
     2404        Free((void **)&Walker->Name, "molecule::CountAtoms: *walker->Name");
     2405        Walker->Name = (char *) Malloc(sizeof(char)*6, "molecule::CountAtoms: *walker->Name");
    24172406        sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);
    24182407        *out << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;
     
    26252614    NumberCells = divisor[0]*divisor[1]*divisor[2];
    26262615    *out << Verbose(1) << "Allocating " << NumberCells << " cells." << endl;
    2627     CellList = Malloc<molecule*>(NumberCells, "molecule::CreateAdjacencyList - ** CellList");
     2616    CellList = (molecule **) Malloc(sizeof(molecule *)*NumberCells, "molecule::CreateAdjacencyList - ** CellList");
    26282617    for (int i=NumberCells;i--;)
    26292618      CellList[i] = NULL;
     
    27072696        delete(CellList[i]);
    27082697      }
    2709     Free(&CellList);
     2698    Free((void **)&CellList, "molecule::CreateAdjacencyList - ** CellList");
    27102699
    27112700    // create the adjacency list per atom
     
    27722761    *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
    27732762  *out << Verbose(0) << "End of CreateAdjacencyList." << endl;
    2774   Free(&matrix);
     2763  Free((void **)&matrix, "molecule::CreateAdjacencyList: *matrix");
    27752764
    27762765};
     
    29822971void molecule::CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *  BackEdgeStack, int *&MinimumRingSize)
    29832972{
    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");
     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");
    29872976  class StackClass<atom *> *BFSStack = new StackClass<atom *> (AtomCount);   // will hold the current ring
    29882977  class StackClass<atom *> *TouchedStack = new StackClass<atom *> (AtomCount);   // contains all "touched" atoms (that need to be reset after BFS loop)
     
    31753164    *out << Verbose(1) << "No rings were detected in the molecular structure." << endl;
    31763165
    3177   Free(&PredecessorList);
    3178   Free(&ShortestPathList);
    3179   Free(&ColorList);
     3166  Free((void **)&PredecessorList, "molecule::CyclicStructureAnalysis: **PredecessorList");
     3167  Free((void **)&ShortestPathList, "molecule::CyclicStructureAnalysis: **ShortestPathList");
     3168  Free((void **)&ColorList, "molecule::CyclicStructureAnalysis: **ColorList");
    31803169  delete(BFSStack);
    31813170};
     
    32213210    Walker = Walker->next;
    32223211    if (Walker->ComponentNr != NULL)
    3223       Free(&Walker->ComponentNr);
    3224     Walker->ComponentNr = Malloc<int>(NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
     3212      Free((void **)&Walker->ComponentNr, "molecule::InitComponentNumbers: **Walker->ComponentNr");
     3213    Walker->ComponentNr = (int *) Malloc(sizeof(int)*NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
    32253214    for (int i=NumberOfBondsPerAtom[Walker->nr];i--;)
    32263215      Walker->ComponentNr[i] = -1;
     
    33453334  int NumberOfFragments = 0;
    33463335  double TEFactor;
    3347   char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
     3336  char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
    33483337
    33493338  if (FragmentList == NULL) { // check list pointer
     
    33573346  if (InputFile != NULL) {
    33583347    // each line represents a new fragment
    3359     char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
     3348    char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
    33603349    // 1. parse keysets and insert into temp. graph
    33613350    while (!InputFile.eof()) {
     
    33723361    InputFile.close();
    33733362    InputFile.clear();
    3374     Free(&buffer);
     3363    Free((void **)&buffer, "molecule::ParseKeySetFile - *buffer");
    33753364    *out << Verbose(1) << "done." << endl;
    33763365  } else {
     
    34053394
    34063395  // free memory
    3407   Free(&filename);
     3396  Free((void **)&filename, "molecule::ParseKeySetFile - filename");
    34083397
    34093398  return status;
     
    35123501  stringstream filename;
    35133502  bool status = true;
    3514   char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
     3503  char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    35153504
    35163505  filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     
    35203509    // allocate storage structure
    35213510    int NonMatchNumber = 0;   // will number of atoms with differing bond structure
    3522     int *CurrentBonds = Malloc<int>(8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
     3511    int *CurrentBonds = (int *) Malloc(sizeof(int)*8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
    35233512    int CurrentBondsOfAtom;
    35243513
     
    35653554    } else
    35663555      *out << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl;
    3567     Free(&CurrentBonds);
     3556    Free((void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds");
    35683557  } else {
    35693558    *out << Verbose(1) << "Adjacency file not found." << endl;
     
    35713560  }
    35723561  *out << endl;
    3573   Free(&buffer);
     3562  Free((void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    35743563
    35753564  return status;
     
    35993588      return false;
    36003589    // parse the EnergyPerFragment file
    3601     char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
     3590    char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
    36023591    sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT);
    36033592    InputFile.open(buffer, ios::in);
     
    37063695      }
    37073696    }
    3708     Free(&buffer);
     3697    Free((void **)&buffer, "molecule::CheckOrderAtSite: *buffer");
    37093698    // pick a given number of highest values and set AtomMask
    37103699  } else { // global increase of Bond Order
     
    37473736 * \param *&SortIndex Mapping array of size molecule::AtomCount
    37483737 * \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
    37493739 */
    37503740bool molecule::CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex)
     
    37583748    return false;
    37593749  }
    3760   SortIndex = Malloc<int>(AtomCount, "molecule::FragmentMolecule: *SortIndex");
     3750  SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex");
    37613751  for(int i=AtomCount;i--;)
    37623752    SortIndex[i] = -1;
     
    38323822  // === compare it with adjacency file ===
    38333823  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms);
    3834   Free(&ListOfAtoms);
     3824  Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");
    38353825
    38363826  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
     
    39213911    delete(Subgraphs);
    39223912  }
    3923   Free(&FragmentList);
     3913  Free((void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");
    39243914
    39253915  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
     
    39683958      *out << Verbose(1) << "Freeing bond memory" << endl;
    39693959      delete(FragmentList); // remove bond molecule from memory
    3970       Free(&SortIndex);
     3960      Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");
    39713961    } else
    39723962      *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
     
    40564046bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path)
    40574047{
    4058   unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    4059   bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     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");
    40604050  bool status;
    40614051  int AtomNr, value;
     
    40984088    status = false;
    40994089  }
    4100   Free(&OrderArray);
    4101   Free(&MaxArray);
     4090  Free((void **)&OrderArray, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
     4091  Free((void **)&MaxArray, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
    41024092
    41034093  *out << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl;
     
    41224112  if (ListOfBondsPerAtom != NULL) {
    41234113    for(int i=AtomCount;i--;)
    4124       Free(&ListOfBondsPerAtom[i]);
    4125     Free(&ListOfBondsPerAtom);
     4114      Free((void **)&ListOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom[i]");
     4115    Free((void **)&ListOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom");
    41264116  }
    41274117  if (NumberOfBondsPerAtom != NULL)
    4128     Free(&NumberOfBondsPerAtom);
    4129   ListOfBondsPerAtom = Malloc<bond**>(AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom");
    4130   NumberOfBondsPerAtom = Malloc<int>(AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom");
     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");
    41314121
    41324122  // reset bond counts per atom
     
    41424132  for(int i=AtomCount;i--;) {
    41434133    // allocate list of bonds per atom
    4144     ListOfBondsPerAtom[i] = Malloc<bond*>(NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
     4134    ListOfBondsPerAtom[i] = (bond **) Malloc(sizeof(bond *)*NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
    41454135    // clear the list again, now each NumberOfBondsPerAtom marks current free field
    41464136    NumberOfBondsPerAtom[i] = 0;
     
    41844174void molecule::BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem)
    41854175{
    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");
     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");
    41894179  class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount);
    41904180  atom *Walker = NULL, *OtherAtom = NULL;
     
    42914281    *out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
    42924282  }
    4293   Free(&PredecessorList);
    4294   Free(&ShortestPathList);
    4295   Free(&ColorList);
     4283  Free((void **)&PredecessorList, "molecule::BreadthFirstSearchAdd: **PredecessorList");
     4284  Free((void **)&ShortestPathList, "molecule::BreadthFirstSearchAdd: **ShortestPathList");
     4285  Free((void **)&ColorList, "molecule::BreadthFirstSearchAdd: **ColorList");
    42964286  delete(AtomStack);
    42974287};
     
    43104300  atom *Walker = NULL, *OtherAtom = NULL;
    43114301  bool status = true;
    4312   atom **ParentList = Malloc<atom*>(Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
     4302  atom **ParentList = (atom **) Malloc(sizeof(atom *)*Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
    43134303
    43144304  *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
     
    43494339  }
    43504340
    4351   Free(&ParentList);
     4341  Free((void **)&ParentList, "molecule::BuildInducedSubgraph: **ParentList");
    43524342  *out << Verbose(2) << "End of BuildInducedSubgraph." << endl;
    43534343  return status;
     
    43924382{
    43934383  atom *Runner = NULL, *FatherOfRunner = NULL, *OtherFather = NULL;
    4394   atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
     4384  atom **SonList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    43954385  molecule *Leaf = new molecule(elemente);
    43964386  bool LonelyFlag = false;
     
    44624452  Leaf->CreateListOfBondsPerAtom(out);
    44634453  //Leaflet->Leaf->ScanForPeriodicCorrection(out);
    4464   Free(&SonList);
     4454  Free((void **)&SonList, "molecule::StoreFragmentFromStack: **SonList");
    44654455//  *out << Verbose(1) << "End of StoreFragmentFromKeyset." << endl;
    44664456  return Leaf;
     
    44834473MoleculeListClass * molecule::CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, config *configuration)
    44844474{
    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");
     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");
    44904480  StackClass<atom *> *RootStack = new StackClass<atom *>(AtomCount);
    44914481  StackClass<atom *> *TouchedStack = new StackClass<atom *>((int)pow(4,Order)+2); // number of atoms reached from one with maximal 4 bonds plus Root itself
     
    46174607
    46184608  // free memory and exit
    4619   Free(&PredecessorList);
    4620   Free(&ShortestPathList);
    4621   Free(&Labels);
    4622   Free(&ColorVertexList);
     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");
    46234613  delete(RootStack);
    46244614  delete(TouchedStack);
     
    46704660  int Removal;
    46714661  int SpaceLeft;
    4672   int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList");
     4662  int *TouchedList = (int *) Malloc(sizeof(int)*(SubOrder+1), "molecule::SPFragmentGenerator: *TouchedList");
    46734663  bond *Binder = NULL;
    46744664  bond **BondsList = NULL;
     
    46784668
    46794669  // Hier muessen von 1 bis NumberOfBondsPerAtom[Walker->nr] alle Kombinationen
    4680   // von Endstuecken (aus den Bonds) hinzugefuegt werden und fuer verbleibende ANOVAOrder
    4681   // rekursiv GraphCrawler in der naechsten Ebene aufgerufen werden
     4670  // von Endstuecken (aus den Bonds) hinzugefᅵᅵgt werden und fᅵᅵr verbleibende ANOVAOrder
     4671  // rekursiv GraphCrawler in der nᅵᅵchsten Ebene aufgerufen werden
    46824672
    46834673  *out << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl;
     
    47394729          }
    47404730          // then allocate and fill the list
    4741           BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
     4731          BondsList = (bond **) Malloc(sizeof(bond *)*SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
    47424732          SubSetDimension = 0;
    47434733          Binder = FragmentSearch->BondsPerSPList[2*SP];
     
    47514741          *out << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
    47524742          SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
    4753           Free(&BondsList);
     4743          Free((void **)&BondsList, "molecule::SPFragmentGenerator: **BondsList");
    47544744        }
    47554745      } else {
     
    47854775    }
    47864776  }
    4787   Free(&TouchedList);
     4777  Free((void **)&TouchedList, "molecule::SPFragmentGenerator: *TouchedList");
    47884778  *out << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl;
    47894779};
     
    49634953    *out << Verbose(0) << "Preparing subset for this root and calling generator." << endl;
    49644954    // prepare the subset and call the generator
    4965     BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     4955    BondsList = (bond **) Malloc(sizeof(bond *)*FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
    49664956    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
    49674957
    49684958    SPFragmentGenerator(out, &FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
    49694959
    4970     Free(&BondsList);
     4960    Free((void **)&BondsList, "molecule::PowerSetGenerator: **BondsList");
    49714961  } else {
    49724962    *out << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl;
     
    50225012  *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl;
    50235013
    5024   ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     5014  ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
    50255015  while (flag) {
    50265016    // remove bonds that are beyond bonddistance
     
    50835073  // free allocated space from ReturnFullMatrixforSymmetric()
    50845074  delete(AtomStack);
    5085   Free(&ColorList);
    5086   Free(&matrix);
     5075  Free((void **)&ColorList, "molecule::ScanForPeriodicCorrection: *ColorList");
     5076  Free((void **)&matrix, "molecule::ScanForPeriodicCorrection: *matrix");
    50875077  *out << Verbose(2) << "End of ScanForPeriodicCorrection." << endl;
    50885078};
     
    50945084double * molecule::ReturnFullMatrixforSymmetric(double *symm)
    50955085{
    5096   double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
     5086  double *matrix = (double *) Malloc(sizeof(double)*NDIM*NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
    50975087  matrix[0] = symm[0];
    50985088  matrix[1] = symm[1];
     
    52215211  // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
    52225212  // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5)
    5223   NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    5224   FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
     5213  NumMoleculesOfOrder = (int *) Malloc(sizeof(int)*UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
     5214  FragmentLowerOrdersList = (Graph ***) Malloc(sizeof(Graph **)*UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    52255215
    52265216  // initialise the fragments structure
    5227   FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
     5217  FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    52285218  FragmentSearch.FragmentCounter = 0;
    52295219  FragmentSearch.FragmentSet = new KeySet;
     
    52605250
    52615251      // initialise Order-dependent entries of UniqueFragments structure
    5262       FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList");
    5263       FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
     5252      FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
     5253      FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
    52645254      for (int i=Order;i--;) {
    52655255        FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
     
    52725262      // allocate memory for all lower level orders in this 1D-array of ptrs
    52735263      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
    5274       FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
     5264      FragmentLowerOrdersList[RootNr] = (Graph **) Malloc(sizeof(Graph *)*NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    52755265      for (int i=0;i<NumLevels;i++)
    52765266        FragmentLowerOrdersList[RootNr][i] = NULL;
     
    53395329
    53405330      // free Order-dependent entries of UniqueFragments structure for next loop cycle
    5341       Free(&FragmentSearch.BondsPerSPCount);
     5331      Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");
    53425332      for (int i=Order;i--;) {
    53435333        delete(FragmentSearch.BondsPerSPList[2*i]);
    53445334        delete(FragmentSearch.BondsPerSPList[2*i+1]);
    53455335      }
    5346       Free(&FragmentSearch.BondsPerSPList);
     5336      Free((void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");
    53475337    }
    53485338  }
     
    53525342
    53535343  // cleanup FragmentSearch structure
    5354   Free(&FragmentSearch.ShortestPathList);
     5344  Free((void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");
    53555345  delete(FragmentSearch.FragmentSet);
    53565346
     
    53835373      }
    53845374    }
    5385     Free(&FragmentLowerOrdersList[RootNr]);
     5375    Free((void **)&FragmentLowerOrdersList[RootNr], "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    53865376    RootNr++;
    53875377  }
    5388   Free(&FragmentLowerOrdersList);
    5389   Free(&NumMoleculesOfOrder);
     5378  Free((void **)&FragmentLowerOrdersList, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
     5379  Free((void **)&NumMoleculesOfOrder, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    53905380
    53915381  *out << Verbose(0) << "End of FragmentBOSSANOVA." << endl;
     
    54775467  if (result) {
    54785468    *out << Verbose(5) << "Calculating distances" << endl;
    5479     Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
    5480     OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
     5469    Distances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
     5470    OtherDistances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
    54815471    Walker = start;
    54825472    while (Walker->next != end) {
     
    54925482    /// ... sort each list (using heapsort (o(N log N)) from GSL)
    54935483    *out << Verbose(5) << "Sorting distances" << endl;
    5494     PermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
    5495     OtherPermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
     5484    PermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
     5485    OtherPermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
    54965486    gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles);
    54975487    gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);
    5498     PermutationMap = Malloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     5488    PermutationMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
    54995489    *out << Verbose(5) << "Combining Permutation Maps" << endl;
    55005490    for(int i=AtomCount;i--;)
    55015491      PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
    55025492
    5503     /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all
     5493    /// ... and compare them step by step, whether the difference is individiually(!) below \a threshold for all
    55045494    *out << Verbose(4) << "Comparing distances" << endl;
    55055495    flag = 0;
     
    55095499        flag = 1;
    55105500    }
    5511 
    5512     // free memory
    5513     Free(&PermMap);
    5514     Free(&OtherPermMap);
    5515     Free(&Distances);
    5516     Free(&OtherDistances);
     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");
    55175507    if (flag) { // if not equal
    5518       Free(&PermutationMap);
     5508      Free((void **)&PermutationMap, "molecule::IsEqualToWithinThreshold: *PermutationMap");
    55195509      result = false;
    55205510    }
     
    55425532  atom *Walker = NULL, *OtherWalker = NULL;
    55435533  *out << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;
    5544   int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap");
     5534  int *AtomicMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::GetAtomicMap: *AtomicMap");  //Calloc
    55455535  for (int i=AtomCount;i--;)
    55465536    AtomicMap[i] = -1;
Note: See TracChangeset for help on using the changeset viewer.