Changeset 13a574 for src/molecules.cpp


Ignore:
Timestamp:
Oct 5, 2009, 6:45:06 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
33f9f7
Parents:
aba92d (diff), fa861b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'ConvexHull' into ActOnAll

Conflicts:

molecuilder/src/Makefile.am

Boost implementation commit was overlapping with ActOnAllTest

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecules.cpp

    raba92d r13a574  
    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: ";
     
    612613  return copy;
    613614};
     615
     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}
    614639
    615640/** Adds a bond to a the molecule specified by two atoms, \a *first and \a *second.
     
    10601085    }
    10611086  } while (!flag);
    1062   Free((void **)&matrix, "molecule::DetermineCenter: *matrix");
     1087  Free(&matrix);
    10631088  Center.Scale(1./(double)AtomCount);
    10641089};
     
    13191344{
    13201345  stringstream zeile1, zeile2;
    1321   int *DoubleList = (int *) Malloc(Nr*sizeof(int), "PrintPermutationMap: *DoubleList");
     1346  int *DoubleList = Malloc<int>(Nr, "PrintPermutationMap: *DoubleList");
    13221347  int doubles = 0;
    13231348  for (int i=0;i<Nr;i++)
     
    13341359    doubles++;
    13351360 // *out << "Found " << doubles << " Doubles." << endl;
    1336   Free((void **)&DoubleList, "PrintPermutationMap: *DoubleList");
     1361  Free(&DoubleList);
    13371362//  *out << zeile1.str() << endl << zeile2.str() << endl;
    13381363};
     
    13681393{
    13691394  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");
     1395  PermutationMap = Malloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: **PermutationMap");
     1396  DistanceMap **DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: **DistanceList");
     1397  DistanceMap::iterator *DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *DistanceIterators");
     1398  int *DoubleList = Malloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: *DoubleList");
     1399  DistanceMap::iterator *StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *StepList");
    13751400  double constants[3];
    13761401  int round;
     
    14481473    }
    14491474  *out << Verbose(1) << "done." << endl;
    1450   Free((void **)&DoubleList, "molecule::MinimiseConstrainedPotential: *DoubleList");
     1475  Free(&DoubleList);
    14511476  // argument minimise the constrained potential in this injective PermutationMap
    14521477  *out << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl;
     
    15291554  for (int i=AtomCount; i--;)
    15301555    DistanceList[i]->clear();
    1531   Free((void **)&DistanceList, "molecule::MinimiseConstrainedPotential: **DistanceList");
    1532   Free((void **)&DistanceIterators, "molecule::MinimiseConstrainedPotential: *DistanceIterators");
     1556  Free(&DistanceList);
     1557  Free(&DistanceIterators);
    15331558  return ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem);
    15341559};
     
    15811606    MinimiseConstrainedPotential(out, PermutationMap, startstep, endstep, configuration.GetIsAngstroem());
    15821607  else {
    1583     PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap");
     1608    PermutationMap = Malloc<atom *>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap");
    15841609    Walker = start;
    15851610    while (Walker->next != end) {
     
    16371662 
    16381663  // store the list to single step files
    1639   int *SortIndex = (int *) Malloc(AtomCount*sizeof(int), "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
     1664  int *SortIndex = Malloc<int>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
    16401665  for (int i=AtomCount; i--; )
    16411666    SortIndex[i] = i;
     
    16431668 
    16441669  // free and return
    1645   Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
     1670  Free(&PermutationMap);
    16461671  delete(MoleculePerStep);
    16471672  return status;
     
    17021727      ConstrainedPotentialEnergy = MinimiseConstrainedPotential(out, PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem());
    17031728      EvaluateConstrainedForces(out, configuration.DoConstrainedMD, 0, PermutationMap, &Force);
    1704       Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
     1729      Free(&PermutationMap);
    17051730    }
    17061731   
     
    24022427        if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it
    24032428          NoNonHydrogen++;
    2404         Free((void **)&Walker->Name, "molecule::CountAtoms: *walker->Name");
    2405         Walker->Name = (char *) Malloc(sizeof(char)*6, "molecule::CountAtoms: *walker->Name");
     2429        Free(&Walker->Name);
     2430        Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
    24062431        sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);
    24072432        *out << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;
     
    26142639    NumberCells = divisor[0]*divisor[1]*divisor[2];
    26152640    *out << Verbose(1) << "Allocating " << NumberCells << " cells." << endl;
    2616     CellList = (molecule **) Malloc(sizeof(molecule *)*NumberCells, "molecule::CreateAdjacencyList - ** CellList");
     2641    CellList = Malloc<molecule*>(NumberCells, "molecule::CreateAdjacencyList - ** CellList");
    26172642    for (int i=NumberCells;i--;)
    26182643      CellList[i] = NULL;
     
    26962721        delete(CellList[i]);
    26972722      }
    2698     Free((void **)&CellList, "molecule::CreateAdjacencyList - ** CellList");
     2723    Free(&CellList);
    26992724
    27002725    // create the adjacency list per atom
     
    27612786    *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
    27622787  *out << Verbose(0) << "End of CreateAdjacencyList." << endl;
    2763   Free((void **)&matrix, "molecule::CreateAdjacencyList: *matrix");
     2788  Free(&matrix);
    27642789
    27652790};
     
    29712996void molecule::CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *  BackEdgeStack, int *&MinimumRingSize)
    29722997{
    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");
     2998  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CyclicStructureAnalysis: **PredecessorList");
     2999  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList");
     3000  enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::CyclicStructureAnalysis: *ColorList");
    29763001  class StackClass<atom *> *BFSStack = new StackClass<atom *> (AtomCount);   // will hold the current ring
    29773002  class StackClass<atom *> *TouchedStack = new StackClass<atom *> (AtomCount);   // contains all "touched" atoms (that need to be reset after BFS loop)
     
    31643189    *out << Verbose(1) << "No rings were detected in the molecular structure." << endl;
    31653190
    3166   Free((void **)&PredecessorList, "molecule::CyclicStructureAnalysis: **PredecessorList");
    3167   Free((void **)&ShortestPathList, "molecule::CyclicStructureAnalysis: **ShortestPathList");
    3168   Free((void **)&ColorList, "molecule::CyclicStructureAnalysis: **ColorList");
     3191  Free(&PredecessorList);
     3192  Free(&ShortestPathList);
     3193  Free(&ColorList);
    31693194  delete(BFSStack);
    31703195};
     
    32103235    Walker = Walker->next;
    32113236    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");
     3237      Free(&Walker->ComponentNr);
     3238    Walker->ComponentNr = Malloc<int>(NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
    32143239    for (int i=NumberOfBondsPerAtom[Walker->nr];i--;)
    32153240      Walker->ComponentNr[i] = -1;
     
    33343359  int NumberOfFragments = 0;
    33353360  double TEFactor;
    3336   char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
     3361  char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
    33373362
    33383363  if (FragmentList == NULL) { // check list pointer
     
    33463371  if (InputFile != NULL) {
    33473372    // each line represents a new fragment
    3348     char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
     3373    char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
    33493374    // 1. parse keysets and insert into temp. graph
    33503375    while (!InputFile.eof()) {
     
    33613386    InputFile.close();
    33623387    InputFile.clear();
    3363     Free((void **)&buffer, "molecule::ParseKeySetFile - *buffer");
     3388    Free(&buffer);
    33643389    *out << Verbose(1) << "done." << endl;
    33653390  } else {
     
    33943419
    33953420  // free memory
    3396   Free((void **)&filename, "molecule::ParseKeySetFile - filename");
     3421  Free(&filename);
    33973422
    33983423  return status;
     
    35013526  stringstream filename;
    35023527  bool status = true;
    3503   char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
     3528  char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    35043529
    35053530  filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     
    35093534    // allocate storage structure
    35103535    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
     3536    int *CurrentBonds = Malloc<int>(8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
    35123537    int CurrentBondsOfAtom;
    35133538
     
    35543579    } else
    35553580      *out << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl;
    3556     Free((void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds");
     3581    Free(&CurrentBonds);
    35573582  } else {
    35583583    *out << Verbose(1) << "Adjacency file not found." << endl;
     
    35603585  }
    35613586  *out << endl;
    3562   Free((void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
     3587  Free(&buffer);
    35633588
    35643589  return status;
     
    35883613      return false;
    35893614    // parse the EnergyPerFragment file
    3590     char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
     3615    char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
    35913616    sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT);
    35923617    InputFile.open(buffer, ios::in);
     
    36953720      }
    36963721    }
    3697     Free((void **)&buffer, "molecule::CheckOrderAtSite: *buffer");
     3722    Free(&buffer);
    36983723    // pick a given number of highest values and set AtomMask
    36993724  } else { // global increase of Bond Order
     
    37483773    return false;
    37493774  }
    3750   SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex");
     3775  SortIndex = Malloc<int>(AtomCount, "molecule::FragmentMolecule: *SortIndex");
    37513776  for(int i=AtomCount;i--;)
    37523777    SortIndex[i] = -1;
     
    38223847  // === compare it with adjacency file ===
    38233848  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms);
    3824   Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");
     3849  Free(&ListOfAtoms);
    38253850
    38263851  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
     
    39113936    delete(Subgraphs);
    39123937  }
    3913   Free((void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");
     3938  Free(&FragmentList);
    39143939
    39153940  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
     
    39583983      *out << Verbose(1) << "Freeing bond memory" << endl;
    39593984      delete(FragmentList); // remove bond molecule from memory
    3960       Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");
     3985      Free(&SortIndex);
    39613986    } else
    39623987      *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
     
    40464071bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path)
    40474072{
    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");
     4073  unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
     4074  bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
    40504075  bool status;
    40514076  int AtomNr, value;
     
    40884113    status = false;
    40894114  }
    4090   Free((void **)&OrderArray, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    4091   Free((void **)&MaxArray, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     4115  Free(&OrderArray);
     4116  Free(&MaxArray);
    40924117
    40934118  *out << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl;
     
    41124137  if (ListOfBondsPerAtom != NULL) {
    41134138    for(int i=AtomCount;i--;)
    4114       Free((void **)&ListOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom[i]");
    4115     Free((void **)&ListOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom");
     4139      Free(&ListOfBondsPerAtom[i]);
     4140    Free(&ListOfBondsPerAtom);
    41164141  }
    41174142  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");
     4143    Free(&NumberOfBondsPerAtom);
     4144  ListOfBondsPerAtom = Malloc<bond**>(AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom");
     4145  NumberOfBondsPerAtom = Malloc<int>(AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom");
    41214146
    41224147  // reset bond counts per atom
     
    41324157  for(int i=AtomCount;i--;) {
    41334158    // allocate list of bonds per atom
    4134     ListOfBondsPerAtom[i] = (bond **) Malloc(sizeof(bond *)*NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
     4159    ListOfBondsPerAtom[i] = Malloc<bond*>(NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
    41354160    // clear the list again, now each NumberOfBondsPerAtom marks current free field
    41364161    NumberOfBondsPerAtom[i] = 0;
     
    41744199void molecule::BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem)
    41754200{
    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");
     4201  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::BreadthFirstSearchAdd: **PredecessorList");
     4202  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList");
     4203  enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList");
    41794204  class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount);
    41804205  atom *Walker = NULL, *OtherAtom = NULL;
     
    42814306    *out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
    42824307  }
    4283   Free((void **)&PredecessorList, "molecule::BreadthFirstSearchAdd: **PredecessorList");
    4284   Free((void **)&ShortestPathList, "molecule::BreadthFirstSearchAdd: **ShortestPathList");
    4285   Free((void **)&ColorList, "molecule::BreadthFirstSearchAdd: **ColorList");
     4308  Free(&PredecessorList);
     4309  Free(&ShortestPathList);
     4310  Free(&ColorList);
    42864311  delete(AtomStack);
    42874312};
     
    43004325  atom *Walker = NULL, *OtherAtom = NULL;
    43014326  bool status = true;
    4302   atom **ParentList = (atom **) Malloc(sizeof(atom *)*Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
     4327  atom **ParentList = Malloc<atom*>(Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
    43034328
    43044329  *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
     
    43394364  }
    43404365
    4341   Free((void **)&ParentList, "molecule::BuildInducedSubgraph: **ParentList");
     4366  Free(&ParentList);
    43424367  *out << Verbose(2) << "End of BuildInducedSubgraph." << endl;
    43434368  return status;
     
    43824407{
    43834408  atom *Runner = NULL, *FatherOfRunner = NULL, *OtherFather = NULL;
    4384   atom **SonList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::StoreFragmentFromStack: **SonList");
     4409  atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    43854410  molecule *Leaf = new molecule(elemente);
    43864411  bool LonelyFlag = false;
     
    44524477  Leaf->CreateListOfBondsPerAtom(out);
    44534478  //Leaflet->Leaf->ScanForPeriodicCorrection(out);
    4454   Free((void **)&SonList, "molecule::StoreFragmentFromStack: **SonList");
     4479  Free(&SonList);
    44554480//  *out << Verbose(1) << "End of StoreFragmentFromKeyset." << endl;
    44564481  return Leaf;
     
    44734498MoleculeListClass * molecule::CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, config *configuration)
    44744499{
    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");
     4500  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
     4501  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
     4502  int *Labels = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
     4503  enum Shading *ColorVertexList = Malloc<enum Shading>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
     4504  enum Shading *ColorEdgeList = Malloc<enum Shading>(BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList");
    44804505  StackClass<atom *> *RootStack = new StackClass<atom *>(AtomCount);
    44814506  StackClass<atom *> *TouchedStack = new StackClass<atom *>((int)pow(4,Order)+2); // number of atoms reached from one with maximal 4 bonds plus Root itself
     
    46074632
    46084633  // 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");
     4634  Free(&PredecessorList);
     4635  Free(&ShortestPathList);
     4636  Free(&Labels);
     4637  Free(&ColorVertexList);
    46134638  delete(RootStack);
    46144639  delete(TouchedStack);
     
    46604685  int Removal;
    46614686  int SpaceLeft;
    4662   int *TouchedList = (int *) Malloc(sizeof(int)*(SubOrder+1), "molecule::SPFragmentGenerator: *TouchedList");
     4687  int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList");
    46634688  bond *Binder = NULL;
    46644689  bond **BondsList = NULL;
     
    46684693
    46694694  // 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
     4695  // von Endstuecken (aus den Bonds) hinzugefuegt werden und fuer verbleibende ANOVAOrder
     4696  // rekursiv GraphCrawler in der naechsten Ebene aufgerufen werden
    46724697
    46734698  *out << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl;
     
    47294754          }
    47304755          // then allocate and fill the list
    4731           BondsList = (bond **) Malloc(sizeof(bond *)*SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
     4756          BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
    47324757          SubSetDimension = 0;
    47334758          Binder = FragmentSearch->BondsPerSPList[2*SP];
     
    47414766          *out << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
    47424767          SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
    4743           Free((void **)&BondsList, "molecule::SPFragmentGenerator: **BondsList");
     4768          Free(&BondsList);
    47444769        }
    47454770      } else {
     
    47754800    }
    47764801  }
    4777   Free((void **)&TouchedList, "molecule::SPFragmentGenerator: *TouchedList");
     4802  Free(&TouchedList);
    47784803  *out << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl;
    47794804};
     
    49534978    *out << Verbose(0) << "Preparing subset for this root and calling generator." << endl;
    49544979    // prepare the subset and call the generator
    4955     BondsList = (bond **) Malloc(sizeof(bond *)*FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     4980    BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
    49564981    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
    49574982
    49584983    SPFragmentGenerator(out, &FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
    49594984
    4960     Free((void **)&BondsList, "molecule::PowerSetGenerator: **BondsList");
     4985    Free(&BondsList);
    49614986  } else {
    49624987    *out << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl;
     
    50125037  *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl;
    50135038
    5014   ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     5039  ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
    50155040  while (flag) {
    50165041    // remove bonds that are beyond bonddistance
     
    50735098  // free allocated space from ReturnFullMatrixforSymmetric()
    50745099  delete(AtomStack);
    5075   Free((void **)&ColorList, "molecule::ScanForPeriodicCorrection: *ColorList");
    5076   Free((void **)&matrix, "molecule::ScanForPeriodicCorrection: *matrix");
     5100  Free(&ColorList);
     5101  Free(&matrix);
    50775102  *out << Verbose(2) << "End of ScanForPeriodicCorrection." << endl;
    50785103};
     
    50845109double * molecule::ReturnFullMatrixforSymmetric(double *symm)
    50855110{
    5086   double *matrix = (double *) Malloc(sizeof(double)*NDIM*NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
     5111  double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
    50875112  matrix[0] = symm[0];
    50885113  matrix[1] = symm[1];
     
    52115236  // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
    52125237  // 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");
     5238  NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
     5239  FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    52155240
    52165241  // initialise the fragments structure
    5217   FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
     5242  FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    52185243  FragmentSearch.FragmentCounter = 0;
    52195244  FragmentSearch.FragmentSet = new KeySet;
     
    52505275
    52515276      // 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");
     5277      FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList");
     5278      FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
    52545279      for (int i=Order;i--;) {
    52555280        FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
     
    52625287      // allocate memory for all lower level orders in this 1D-array of ptrs
    52635288      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
    5264       FragmentLowerOrdersList[RootNr] = (Graph **) Malloc(sizeof(Graph *)*NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
     5289      FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    52655290      for (int i=0;i<NumLevels;i++)
    52665291        FragmentLowerOrdersList[RootNr][i] = NULL;
     
    53295354
    53305355      // free Order-dependent entries of UniqueFragments structure for next loop cycle
    5331       Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");
     5356      Free(&FragmentSearch.BondsPerSPCount);
    53325357      for (int i=Order;i--;) {
    53335358        delete(FragmentSearch.BondsPerSPList[2*i]);
    53345359        delete(FragmentSearch.BondsPerSPList[2*i+1]);
    53355360      }
    5336       Free((void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");
     5361      Free(&FragmentSearch.BondsPerSPList);
    53375362    }
    53385363  }
     
    53425367
    53435368  // cleanup FragmentSearch structure
    5344   Free((void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");
     5369  Free(&FragmentSearch.ShortestPathList);
    53455370  delete(FragmentSearch.FragmentSet);
    53465371
     
    53735398      }
    53745399    }
    5375     Free((void **)&FragmentLowerOrdersList[RootNr], "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
     5400    Free(&FragmentLowerOrdersList[RootNr]);
    53765401    RootNr++;
    53775402  }
    5378   Free((void **)&FragmentLowerOrdersList, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    5379   Free((void **)&NumMoleculesOfOrder, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
     5403  Free(&FragmentLowerOrdersList);
     5404  Free(&NumMoleculesOfOrder);
    53805405
    53815406  *out << Verbose(0) << "End of FragmentBOSSANOVA." << endl;
     
    54675492  if (result) {
    54685493    *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");
     5494    Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
     5495    OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
    54715496    Walker = start;
    54725497    while (Walker->next != end) {
     
    54825507    /// ... sort each list (using heapsort (o(N log N)) from GSL)
    54835508    *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");
     5509    PermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
     5510    OtherPermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
    54865511    gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles);
    54875512    gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);
    5488     PermutationMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     5513    PermutationMap = Malloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
    54895514    *out << Verbose(5) << "Combining Permutation Maps" << endl;
    54905515    for(int i=AtomCount;i--;)
    54915516      PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
    54925517
    5493     /// ... and compare them step by step, whether the difference is individiually(!) below \a threshold for all
     5518    /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all
    54945519    *out << Verbose(4) << "Comparing distances" << endl;
    54955520    flag = 0;
     
    54995524        flag = 1;
    55005525    }
    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");
     5526
     5527    // free memory
     5528    Free(&PermMap);
     5529    Free(&OtherPermMap);
     5530    Free(&Distances);
     5531    Free(&OtherDistances);
    55075532    if (flag) { // if not equal
    5508       Free((void **)&PermutationMap, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     5533      Free(&PermutationMap);
    55095534      result = false;
    55105535    }
     
    55325557  atom *Walker = NULL, *OtherWalker = NULL;
    55335558  *out << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;
    5534   int *AtomicMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::GetAtomicMap: *AtomicMap");  //Calloc
     5559  int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap");
    55355560  for (int i=AtomCount;i--;)
    55365561    AtomicMap[i] = -1;
Note: See TracChangeset for help on using the changeset viewer.