Changeset 13a574 for src/molecules.cpp
- Timestamp:
- Oct 5, 2009, 6:45:06 PM (16 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecules.cpp
raba92d r13a574 6 6 7 7 #include "config.hpp" 8 #include "memoryallocator.hpp" 8 9 #include "molecules.hpp" 9 10 … … 55 56 if (ListOfBondsPerAtom != NULL) 56 57 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); 60 61 if (TesselStruct != NULL) 61 62 delete(TesselStruct); … … 163 164 NoNonHydrogen++; 164 165 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"); 167 168 sprintf(pointer->Name, "%2s%02d", pointer->type->symbol, pointer->nr+1); 168 169 } … … 176 177 * Increases molecule::last_atom and gives last number to added atom. 177 178 * \param *pointer allocated and set atom 178 * \return true - succeeded, false - atom not found in list179 * \return pointer to the newly added atom 179 180 */ 180 181 atom * molecule::AddCopyAtom(atom *pointer) … … 182 183 if (pointer != NULL) { 183 184 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"); 185 186 strcpy (walker->Name, pointer->Name); 186 187 walker->nr = last_atom++; // increase number within molecule … … 267 268 Orthovector1.MatrixMultiplication(matrix); 268 269 InBondvector.SubtractVector(&Orthovector1); // subtract just the additional translation 269 Free( (void **)&matrix, "molecule::AddHydrogenReplacementAtom: *matrix");270 Free(&matrix); 270 271 bondlength = InBondvector.Norm(); 271 272 // *out << Verbose(4) << "Corrected InBondvector is now: "; … … 612 613 return copy; 613 614 }; 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 */ 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 } 614 639 615 640 /** Adds a bond to a the molecule specified by two atoms, \a *first and \a *second. … … 1060 1085 } 1061 1086 } while (!flag); 1062 Free( (void **)&matrix, "molecule::DetermineCenter: *matrix");1087 Free(&matrix); 1063 1088 Center.Scale(1./(double)AtomCount); 1064 1089 }; … … 1319 1344 { 1320 1345 stringstream zeile1, zeile2; 1321 int *DoubleList = (int *) Malloc(Nr*sizeof(int), "PrintPermutationMap: *DoubleList");1346 int *DoubleList = Malloc<int>(Nr, "PrintPermutationMap: *DoubleList"); 1322 1347 int doubles = 0; 1323 1348 for (int i=0;i<Nr;i++) … … 1334 1359 doubles++; 1335 1360 // *out << "Found " << doubles << " Doubles." << endl; 1336 Free( (void **)&DoubleList, "PrintPermutationMap: *DoubleList");1361 Free(&DoubleList); 1337 1362 // *out << zeile1.str() << endl << zeile2.str() << endl; 1338 1363 }; … … 1368 1393 { 1369 1394 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"); 1375 1400 double constants[3]; 1376 1401 int round; … … 1448 1473 } 1449 1474 *out << Verbose(1) << "done." << endl; 1450 Free( (void **)&DoubleList, "molecule::MinimiseConstrainedPotential: *DoubleList");1475 Free(&DoubleList); 1451 1476 // argument minimise the constrained potential in this injective PermutationMap 1452 1477 *out << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl; … … 1529 1554 for (int i=AtomCount; i--;) 1530 1555 DistanceList[i]->clear(); 1531 Free( (void **)&DistanceList, "molecule::MinimiseConstrainedPotential: **DistanceList");1532 Free( (void **)&DistanceIterators, "molecule::MinimiseConstrainedPotential: *DistanceIterators");1556 Free(&DistanceList); 1557 Free(&DistanceIterators); 1533 1558 return ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem); 1534 1559 }; … … 1581 1606 MinimiseConstrainedPotential(out, PermutationMap, startstep, endstep, configuration.GetIsAngstroem()); 1582 1607 else { 1583 PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap");1608 PermutationMap = Malloc<atom *>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap"); 1584 1609 Walker = start; 1585 1610 while (Walker->next != end) { … … 1637 1662 1638 1663 // 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"); 1640 1665 for (int i=AtomCount; i--; ) 1641 1666 SortIndex[i] = i; … … 1643 1668 1644 1669 // free and return 1645 Free( (void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");1670 Free(&PermutationMap); 1646 1671 delete(MoleculePerStep); 1647 1672 return status; … … 1702 1727 ConstrainedPotentialEnergy = MinimiseConstrainedPotential(out, PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem()); 1703 1728 EvaluateConstrainedForces(out, configuration.DoConstrainedMD, 0, PermutationMap, &Force); 1704 Free( (void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");1729 Free(&PermutationMap); 1705 1730 } 1706 1731 … … 2402 2427 if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it 2403 2428 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"); 2406 2431 sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1); 2407 2432 *out << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl; … … 2614 2639 NumberCells = divisor[0]*divisor[1]*divisor[2]; 2615 2640 *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"); 2617 2642 for (int i=NumberCells;i--;) 2618 2643 CellList[i] = NULL; … … 2696 2721 delete(CellList[i]); 2697 2722 } 2698 Free( (void **)&CellList, "molecule::CreateAdjacencyList - ** CellList");2723 Free(&CellList); 2699 2724 2700 2725 // create the adjacency list per atom … … 2761 2786 *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl; 2762 2787 *out << Verbose(0) << "End of CreateAdjacencyList." << endl; 2763 Free( (void **)&matrix, "molecule::CreateAdjacencyList: *matrix");2788 Free(&matrix); 2764 2789 2765 2790 }; … … 2971 2996 void molecule::CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> * BackEdgeStack, int *&MinimumRingSize) 2972 2997 { 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"); 2976 3001 class StackClass<atom *> *BFSStack = new StackClass<atom *> (AtomCount); // will hold the current ring 2977 3002 class StackClass<atom *> *TouchedStack = new StackClass<atom *> (AtomCount); // contains all "touched" atoms (that need to be reset after BFS loop) … … 3164 3189 *out << Verbose(1) << "No rings were detected in the molecular structure." << endl; 3165 3190 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); 3169 3194 delete(BFSStack); 3170 3195 }; … … 3210 3235 Walker = Walker->next; 3211 3236 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"); 3214 3239 for (int i=NumberOfBondsPerAtom[Walker->nr];i--;) 3215 3240 Walker->ComponentNr[i] = -1; … … 3334 3359 int NumberOfFragments = 0; 3335 3360 double TEFactor; 3336 char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");3361 char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename"); 3337 3362 3338 3363 if (FragmentList == NULL) { // check list pointer … … 3346 3371 if (InputFile != NULL) { 3347 3372 // 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"); 3349 3374 // 1. parse keysets and insert into temp. graph 3350 3375 while (!InputFile.eof()) { … … 3361 3386 InputFile.close(); 3362 3387 InputFile.clear(); 3363 Free( (void **)&buffer, "molecule::ParseKeySetFile - *buffer");3388 Free(&buffer); 3364 3389 *out << Verbose(1) << "done." << endl; 3365 3390 } else { … … 3394 3419 3395 3420 // free memory 3396 Free( (void **)&filename, "molecule::ParseKeySetFile - filename");3421 Free(&filename); 3397 3422 3398 3423 return status; … … 3501 3526 stringstream filename; 3502 3527 bool status = true; 3503 char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");3528 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer"); 3504 3529 3505 3530 filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE; … … 3509 3534 // allocate storage structure 3510 3535 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 atom3536 int *CurrentBonds = Malloc<int>(8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom 3512 3537 int CurrentBondsOfAtom; 3513 3538 … … 3554 3579 } else 3555 3580 *out << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl; 3556 Free( (void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds");3581 Free(&CurrentBonds); 3557 3582 } else { 3558 3583 *out << Verbose(1) << "Adjacency file not found." << endl; … … 3560 3585 } 3561 3586 *out << endl; 3562 Free( (void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");3587 Free(&buffer); 3563 3588 3564 3589 return status; … … 3588 3613 return false; 3589 3614 // parse the EnergyPerFragment file 3590 char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");3615 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer"); 3591 3616 sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT); 3592 3617 InputFile.open(buffer, ios::in); … … 3695 3720 } 3696 3721 } 3697 Free( (void **)&buffer, "molecule::CheckOrderAtSite: *buffer");3722 Free(&buffer); 3698 3723 // pick a given number of highest values and set AtomMask 3699 3724 } else { // global increase of Bond Order … … 3748 3773 return false; 3749 3774 } 3750 SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex");3775 SortIndex = Malloc<int>(AtomCount, "molecule::FragmentMolecule: *SortIndex"); 3751 3776 for(int i=AtomCount;i--;) 3752 3777 SortIndex[i] = -1; … … 3822 3847 // === compare it with adjacency file === 3823 3848 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms); 3824 Free( (void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");3849 Free(&ListOfAtoms); 3825 3850 3826 3851 // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===== … … 3911 3936 delete(Subgraphs); 3912 3937 } 3913 Free( (void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");3938 Free(&FragmentList); 3914 3939 3915 3940 // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass ===== … … 3958 3983 *out << Verbose(1) << "Freeing bond memory" << endl; 3959 3984 delete(FragmentList); // remove bond molecule from memory 3960 Free( (void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");3985 Free(&SortIndex); 3961 3986 } else 3962 3987 *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl; … … 4046 4071 bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path) 4047 4072 { 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"); 4050 4075 bool status; 4051 4076 int AtomNr, value; … … 4088 4113 status = false; 4089 4114 } 4090 Free( (void **)&OrderArray, "molecule::ParseOrderAtSiteFromFile - *OrderArray");4091 Free( (void **)&MaxArray, "molecule::ParseOrderAtSiteFromFile - *MaxArray");4115 Free(&OrderArray); 4116 Free(&MaxArray); 4092 4117 4093 4118 *out << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl; … … 4112 4137 if (ListOfBondsPerAtom != NULL) { 4113 4138 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); 4116 4141 } 4117 4142 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"); 4121 4146 4122 4147 // reset bond counts per atom … … 4132 4157 for(int i=AtomCount;i--;) { 4133 4158 // 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[]"); 4135 4160 // clear the list again, now each NumberOfBondsPerAtom marks current free field 4136 4161 NumberOfBondsPerAtom[i] = 0; … … 4174 4199 void molecule::BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem) 4175 4200 { 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"); 4179 4204 class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount); 4180 4205 atom *Walker = NULL, *OtherAtom = NULL; … … 4281 4306 *out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl; 4282 4307 } 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); 4286 4311 delete(AtomStack); 4287 4312 }; … … 4300 4325 atom *Walker = NULL, *OtherAtom = NULL; 4301 4326 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"); 4303 4328 4304 4329 *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl; … … 4339 4364 } 4340 4365 4341 Free( (void **)&ParentList, "molecule::BuildInducedSubgraph: **ParentList");4366 Free(&ParentList); 4342 4367 *out << Verbose(2) << "End of BuildInducedSubgraph." << endl; 4343 4368 return status; … … 4382 4407 { 4383 4408 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"); 4385 4410 molecule *Leaf = new molecule(elemente); 4386 4411 bool LonelyFlag = false; … … 4452 4477 Leaf->CreateListOfBondsPerAtom(out); 4453 4478 //Leaflet->Leaf->ScanForPeriodicCorrection(out); 4454 Free( (void **)&SonList, "molecule::StoreFragmentFromStack: **SonList");4479 Free(&SonList); 4455 4480 // *out << Verbose(1) << "End of StoreFragmentFromKeyset." << endl; 4456 4481 return Leaf; … … 4473 4498 MoleculeListClass * molecule::CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, config *configuration) 4474 4499 { 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"); 4480 4505 StackClass<atom *> *RootStack = new StackClass<atom *>(AtomCount); 4481 4506 StackClass<atom *> *TouchedStack = new StackClass<atom *>((int)pow(4,Order)+2); // number of atoms reached from one with maximal 4 bonds plus Root itself … … 4607 4632 4608 4633 // 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); 4613 4638 delete(RootStack); 4614 4639 delete(TouchedStack); … … 4660 4685 int Removal; 4661 4686 int SpaceLeft; 4662 int *TouchedList = (int *) Malloc(sizeof(int)*(SubOrder+1), "molecule::SPFragmentGenerator: *TouchedList");4687 int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList"); 4663 4688 bond *Binder = NULL; 4664 4689 bond **BondsList = NULL; … … 4668 4693 4669 4694 // Hier muessen von 1 bis NumberOfBondsPerAtom[Walker->nr] alle Kombinationen 4670 // von Endstuecken (aus den Bonds) hinzugef ᅵᅵgt werden und fᅵᅵr verbleibende ANOVAOrder4671 // rekursiv GraphCrawler in der n ᅵᅵchsten Ebene aufgerufen werden4695 // von Endstuecken (aus den Bonds) hinzugefuegt werden und fuer verbleibende ANOVAOrder 4696 // rekursiv GraphCrawler in der naechsten Ebene aufgerufen werden 4672 4697 4673 4698 *out << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl; … … 4729 4754 } 4730 4755 // then allocate and fill the list 4731 BondsList = (bond **) Malloc(sizeof(bond *)*SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");4756 BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList"); 4732 4757 SubSetDimension = 0; 4733 4758 Binder = FragmentSearch->BondsPerSPList[2*SP]; … … 4741 4766 *out << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl; 4742 4767 SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits); 4743 Free( (void **)&BondsList, "molecule::SPFragmentGenerator: **BondsList");4768 Free(&BondsList); 4744 4769 } 4745 4770 } else { … … 4775 4800 } 4776 4801 } 4777 Free( (void **)&TouchedList, "molecule::SPFragmentGenerator: *TouchedList");4802 Free(&TouchedList); 4778 4803 *out << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl; 4779 4804 }; … … 4953 4978 *out << Verbose(0) << "Preparing subset for this root and calling generator." << endl; 4954 4979 // 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"); 4956 4981 BondsList[0] = FragmentSearch.BondsPerSPList[0]->next; // on SP level 0 there's only the root bond 4957 4982 4958 4983 SPFragmentGenerator(out, &FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order); 4959 4984 4960 Free( (void **)&BondsList, "molecule::PowerSetGenerator: **BondsList");4985 Free(&BondsList); 4961 4986 } else { 4962 4987 *out << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl; … … 5012 5037 *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl; 5013 5038 5014 ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");5039 ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList"); 5015 5040 while (flag) { 5016 5041 // remove bonds that are beyond bonddistance … … 5073 5098 // free allocated space from ReturnFullMatrixforSymmetric() 5074 5099 delete(AtomStack); 5075 Free( (void **)&ColorList, "molecule::ScanForPeriodicCorrection: *ColorList");5076 Free( (void **)&matrix, "molecule::ScanForPeriodicCorrection: *matrix");5100 Free(&ColorList); 5101 Free(&matrix); 5077 5102 *out << Verbose(2) << "End of ScanForPeriodicCorrection." << endl; 5078 5103 }; … … 5084 5109 double * molecule::ReturnFullMatrixforSymmetric(double *symm) 5085 5110 { 5086 double *matrix = (double *) Malloc(sizeof(double)*NDIM*NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");5111 double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix"); 5087 5112 matrix[0] = symm[0]; 5088 5113 matrix[1] = symm[1]; … … 5211 5236 // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5) 5212 5237 // 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"); 5215 5240 5216 5241 // initialise the fragments structure 5217 FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");5242 FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList"); 5218 5243 FragmentSearch.FragmentCounter = 0; 5219 5244 FragmentSearch.FragmentSet = new KeySet; … … 5250 5275 5251 5276 // 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"); 5254 5279 for (int i=Order;i--;) { 5255 5280 FragmentSearch.BondsPerSPList[2*i] = new bond(); // start node … … 5262 5287 // allocate memory for all lower level orders in this 1D-array of ptrs 5263 5288 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[]"); 5265 5290 for (int i=0;i<NumLevels;i++) 5266 5291 FragmentLowerOrdersList[RootNr][i] = NULL; … … 5329 5354 5330 5355 // free Order-dependent entries of UniqueFragments structure for next loop cycle 5331 Free( (void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");5356 Free(&FragmentSearch.BondsPerSPCount); 5332 5357 for (int i=Order;i--;) { 5333 5358 delete(FragmentSearch.BondsPerSPList[2*i]); 5334 5359 delete(FragmentSearch.BondsPerSPList[2*i+1]); 5335 5360 } 5336 Free( (void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");5361 Free(&FragmentSearch.BondsPerSPList); 5337 5362 } 5338 5363 } … … 5342 5367 5343 5368 // cleanup FragmentSearch structure 5344 Free( (void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");5369 Free(&FragmentSearch.ShortestPathList); 5345 5370 delete(FragmentSearch.FragmentSet); 5346 5371 … … 5373 5398 } 5374 5399 } 5375 Free( (void **)&FragmentLowerOrdersList[RootNr], "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");5400 Free(&FragmentLowerOrdersList[RootNr]); 5376 5401 RootNr++; 5377 5402 } 5378 Free( (void **)&FragmentLowerOrdersList, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");5379 Free( (void **)&NumMoleculesOfOrder, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");5403 Free(&FragmentLowerOrdersList); 5404 Free(&NumMoleculesOfOrder); 5380 5405 5381 5406 *out << Verbose(0) << "End of FragmentBOSSANOVA." << endl; … … 5467 5492 if (result) { 5468 5493 *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"); 5471 5496 Walker = start; 5472 5497 while (Walker->next != end) { … … 5482 5507 /// ... sort each list (using heapsort (o(N log N)) from GSL) 5483 5508 *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"); 5486 5511 gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles); 5487 5512 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"); 5489 5514 *out << Verbose(5) << "Combining Permutation Maps" << endl; 5490 5515 for(int i=AtomCount;i--;) 5491 5516 PermutationMap[PermMap[i]] = (int) OtherPermMap[i]; 5492 5517 5493 /// ... and compare them step by step, whether the difference is individ iually(!) below \a threshold for all5518 /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all 5494 5519 *out << Verbose(4) << "Comparing distances" << endl; 5495 5520 flag = 0; … … 5499 5524 flag = 1; 5500 5525 } 5501 Free((void **)&PermMap, "molecule::IsEqualToWithinThreshold: *PermMap"); 5502 Free((void **)&OtherPermMap, "molecule::IsEqualToWithinThreshold: *OtherPermMap");5503 5504 /// free memory5505 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); 5507 5532 if (flag) { // if not equal 5508 Free( (void **)&PermutationMap, "molecule::IsEqualToWithinThreshold: *PermutationMap");5533 Free(&PermutationMap); 5509 5534 result = false; 5510 5535 } … … 5532 5557 atom *Walker = NULL, *OtherWalker = NULL; 5533 5558 *out << Verbose(3) << "Begin of GetFatherAtomicMap." << endl; 5534 int *AtomicMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::GetAtomicMap: *AtomicMap"); //Calloc5559 int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap"); 5535 5560 for (int i=AtomCount;i--;) 5536 5561 AtomicMap[i] = -1;
Note:
See TracChangeset
for help on using the changeset viewer.