Changes in src/molecules.cpp [f7f7a4:29812d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecules.cpp
rf7f7a4 r29812d 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: "; … … 613 614 }; 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 } 639 615 640 /** Adds a bond to a the molecule specified by two atoms, \a *first and \a *second. 616 641 * Also updates molecule::BondCount and molecule::NoNonBonds. … … 662 687 { 663 688 int length = 0; 664 const char *molname = strrchr(filename, '/'); 665 if (molname != NULL) 666 molname += sizeof(char); // search for filename without dirs 667 else 668 molname = filename; // contains no slashes 689 char *molname = strrchr(filename, '/')+sizeof(char); // search for filename without dirs 669 690 char *endname = strchr(molname, '.'); 670 691 if ((endname == NULL) || (endname < molname)) … … 1060 1081 } 1061 1082 } while (!flag); 1062 Free( (void **)&matrix, "molecule::DetermineCenter: *matrix");1083 Free(&matrix); 1063 1084 Center.Scale(1./(double)AtomCount); 1064 1085 }; … … 1172 1193 /** Evaluates the potential energy used for constrained molecular dynamics. 1173 1194 * \f$V_i^{con} = c^{bond} \cdot | r_{P(i)} - R_i | + sum_{i \neq j} C^{min} \cdot \frac{1}{C_{ij}} + C^{inj} \Bigl (1 - \theta \bigl (\prod_{i \neq j} (P(i) - P(j)) \bigr ) \Bigr )\f$ 1174 * where the first term points to the target in minimum distance, the second is a penalty for trajectories lying too close to each other (\f$C_{ij} \f$ is minimum distance between1195 * 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 1175 1196 * trajectories i and j) and the third term is a penalty for two atoms trying to each the same target point. 1176 1197 * Note that for the second term we have to solve the following linear system: … … 1319 1340 { 1320 1341 stringstream zeile1, zeile2; 1321 int *DoubleList = (int *) Malloc(Nr*sizeof(int), "PrintPermutationMap: *DoubleList");1342 int *DoubleList = Malloc<int>(Nr, "PrintPermutationMap: *DoubleList"); 1322 1343 int doubles = 0; 1323 1344 for (int i=0;i<Nr;i++) … … 1334 1355 doubles++; 1335 1356 // *out << "Found " << doubles << " Doubles." << endl; 1336 Free( (void **)&DoubleList, "PrintPermutationMap: *DoubleList");1357 Free(&DoubleList); 1337 1358 // *out << zeile1.str() << endl << zeile2.str() << endl; 1338 1359 }; … … 1368 1389 { 1369 1390 double Potential, OldPotential, OlderPotential; 1370 PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::MinimiseConstrainedPotential: **PermutationMap");1371 DistanceMap **DistanceList = (DistanceMap **) Malloc(AtomCount*sizeof(DistanceMap *), "molecule::MinimiseConstrainedPotential: **DistanceList");1372 DistanceMap::iterator *DistanceIterators = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *DistanceIterators");1373 int *DoubleList = (int *) Malloc(AtomCount*sizeof(int), "molecule::MinimiseConstrainedPotential: *DoubleList");1374 DistanceMap::iterator *StepList = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *StepList");1391 PermutationMap = Malloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: **PermutationMap"); 1392 DistanceMap **DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: **DistanceList"); 1393 DistanceMap::iterator *DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *DistanceIterators"); 1394 int *DoubleList = Malloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: *DoubleList"); 1395 DistanceMap::iterator *StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *StepList"); 1375 1396 double constants[3]; 1376 1397 int round; … … 1448 1469 } 1449 1470 *out << Verbose(1) << "done." << endl; 1450 Free( (void **)&DoubleList, "molecule::MinimiseConstrainedPotential: *DoubleList");1471 Free(&DoubleList); 1451 1472 // argument minimise the constrained potential in this injective PermutationMap 1452 1473 *out << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl; … … 1529 1550 for (int i=AtomCount; i--;) 1530 1551 DistanceList[i]->clear(); 1531 Free( (void **)&DistanceList, "molecule::MinimiseConstrainedPotential: **DistanceList");1532 Free( (void **)&DistanceIterators, "molecule::MinimiseConstrainedPotential: *DistanceIterators");1552 Free(&DistanceList); 1553 Free(&DistanceIterators); 1533 1554 return ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem); 1534 1555 }; … … 1566 1587 * \param endstep stating final configuration in molecule::Trajectories 1567 1588 * \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()1569 1589 * \return true - success in writing step files, false - error writing files or only one step in molecule::Trajectories 1570 1590 */ 1571 bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration , bool MapByIdentity)1591 bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration) 1572 1592 { 1573 1593 molecule *mol = NULL; … … 1578 1598 atom **PermutationMap = NULL; 1579 1599 atom *Walker = NULL, *Sprinter = NULL; 1580 if (!MapByIdentity) 1581 MinimiseConstrainedPotential(out, PermutationMap, startstep, endstep, configuration.GetIsAngstroem()); 1582 else { 1583 PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap"); 1584 Walker = start; 1585 while (Walker->next != end) { 1586 Walker = Walker->next; 1587 PermutationMap[Walker->nr] = Walker; // always pick target with the smallest distance 1588 } 1589 } 1600 MinimiseConstrainedPotential(out, PermutationMap, startstep, endstep, configuration.GetIsAngstroem()); 1590 1601 1591 1602 // check whether we have sufficient space in Trajectories for each atom … … 1637 1648 1638 1649 // store the list to single step files 1639 int *SortIndex = (int *) Malloc(AtomCount*sizeof(int), "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");1650 int *SortIndex = Malloc<int>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: *SortIndex"); 1640 1651 for (int i=AtomCount; i--; ) 1641 1652 SortIndex[i] = i; … … 1643 1654 1644 1655 // free and return 1645 Free( (void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");1656 Free(&PermutationMap); 1646 1657 delete(MoleculePerStep); 1647 1658 return status; … … 1702 1713 ConstrainedPotentialEnergy = MinimiseConstrainedPotential(out, PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem()); 1703 1714 EvaluateConstrainedForces(out, configuration.DoConstrainedMD, 0, PermutationMap, &Force); 1704 Free( (void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");1715 Free(&PermutationMap); 1705 1716 } 1706 1717 … … 2402 2413 if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it 2403 2414 NoNonHydrogen++; 2404 Free( (void **)&Walker->Name, "molecule::CountAtoms: *walker->Name");2405 Walker->Name = (char *) Malloc(sizeof(char)*6, "molecule::CountAtoms: *walker->Name");2415 Free(&Walker->Name); 2416 Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name"); 2406 2417 sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1); 2407 2418 *out << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl; … … 2614 2625 NumberCells = divisor[0]*divisor[1]*divisor[2]; 2615 2626 *out << Verbose(1) << "Allocating " << NumberCells << " cells." << endl; 2616 CellList = (molecule **) Malloc(sizeof(molecule *)*NumberCells, "molecule::CreateAdjacencyList - ** CellList");2627 CellList = Malloc<molecule*>(NumberCells, "molecule::CreateAdjacencyList - ** CellList"); 2617 2628 for (int i=NumberCells;i--;) 2618 2629 CellList[i] = NULL; … … 2696 2707 delete(CellList[i]); 2697 2708 } 2698 Free( (void **)&CellList, "molecule::CreateAdjacencyList - ** CellList");2709 Free(&CellList); 2699 2710 2700 2711 // create the adjacency list per atom … … 2761 2772 *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl; 2762 2773 *out << Verbose(0) << "End of CreateAdjacencyList." << endl; 2763 Free( (void **)&matrix, "molecule::CreateAdjacencyList: *matrix");2774 Free(&matrix); 2764 2775 2765 2776 }; … … 2971 2982 void molecule::CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> * BackEdgeStack, int *&MinimumRingSize) 2972 2983 { 2973 atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::CyclicStructureAnalysis: **PredecessorList");2974 int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList");2975 enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CyclicStructureAnalysis: *ColorList");2984 atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CyclicStructureAnalysis: **PredecessorList"); 2985 int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList"); 2986 enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::CyclicStructureAnalysis: *ColorList"); 2976 2987 class StackClass<atom *> *BFSStack = new StackClass<atom *> (AtomCount); // will hold the current ring 2977 2988 class StackClass<atom *> *TouchedStack = new StackClass<atom *> (AtomCount); // contains all "touched" atoms (that need to be reset after BFS loop) … … 3164 3175 *out << Verbose(1) << "No rings were detected in the molecular structure." << endl; 3165 3176 3166 Free( (void **)&PredecessorList, "molecule::CyclicStructureAnalysis: **PredecessorList");3167 Free( (void **)&ShortestPathList, "molecule::CyclicStructureAnalysis: **ShortestPathList");3168 Free( (void **)&ColorList, "molecule::CyclicStructureAnalysis: **ColorList");3177 Free(&PredecessorList); 3178 Free(&ShortestPathList); 3179 Free(&ColorList); 3169 3180 delete(BFSStack); 3170 3181 }; … … 3210 3221 Walker = Walker->next; 3211 3222 if (Walker->ComponentNr != NULL) 3212 Free( (void **)&Walker->ComponentNr, "molecule::InitComponentNumbers: **Walker->ComponentNr");3213 Walker->ComponentNr = (int *) Malloc(sizeof(int)*NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");3223 Free(&Walker->ComponentNr); 3224 Walker->ComponentNr = Malloc<int>(NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr"); 3214 3225 for (int i=NumberOfBondsPerAtom[Walker->nr];i--;) 3215 3226 Walker->ComponentNr[i] = -1; … … 3334 3345 int NumberOfFragments = 0; 3335 3346 double TEFactor; 3336 char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");3347 char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename"); 3337 3348 3338 3349 if (FragmentList == NULL) { // check list pointer … … 3346 3357 if (InputFile != NULL) { 3347 3358 // each line represents a new fragment 3348 char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");3359 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer"); 3349 3360 // 1. parse keysets and insert into temp. graph 3350 3361 while (!InputFile.eof()) { … … 3361 3372 InputFile.close(); 3362 3373 InputFile.clear(); 3363 Free( (void **)&buffer, "molecule::ParseKeySetFile - *buffer");3374 Free(&buffer); 3364 3375 *out << Verbose(1) << "done." << endl; 3365 3376 } else { … … 3394 3405 3395 3406 // free memory 3396 Free( (void **)&filename, "molecule::ParseKeySetFile - filename");3407 Free(&filename); 3397 3408 3398 3409 return status; … … 3501 3512 stringstream filename; 3502 3513 bool status = true; 3503 char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");3514 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer"); 3504 3515 3505 3516 filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE; … … 3509 3520 // allocate storage structure 3510 3521 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 atom3522 int *CurrentBonds = Malloc<int>(8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom 3512 3523 int CurrentBondsOfAtom; 3513 3524 … … 3554 3565 } else 3555 3566 *out << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl; 3556 Free( (void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds");3567 Free(&CurrentBonds); 3557 3568 } else { 3558 3569 *out << Verbose(1) << "Adjacency file not found." << endl; … … 3560 3571 } 3561 3572 *out << endl; 3562 Free( (void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");3573 Free(&buffer); 3563 3574 3564 3575 return status; … … 3588 3599 return false; 3589 3600 // parse the EnergyPerFragment file 3590 char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");3601 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer"); 3591 3602 sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT); 3592 3603 InputFile.open(buffer, ios::in); … … 3695 3706 } 3696 3707 } 3697 Free( (void **)&buffer, "molecule::CheckOrderAtSite: *buffer");3708 Free(&buffer); 3698 3709 // pick a given number of highest values and set AtomMask 3699 3710 } else { // global increase of Bond Order … … 3736 3747 * \param *&SortIndex Mapping array of size molecule::AtomCount 3737 3748 * \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 changes3739 3749 */ 3740 3750 bool molecule::CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex) … … 3748 3758 return false; 3749 3759 } 3750 SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex");3760 SortIndex = Malloc<int>(AtomCount, "molecule::FragmentMolecule: *SortIndex"); 3751 3761 for(int i=AtomCount;i--;) 3752 3762 SortIndex[i] = -1; … … 3822 3832 // === compare it with adjacency file === 3823 3833 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms); 3824 Free( (void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");3834 Free(&ListOfAtoms); 3825 3835 3826 3836 // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===== … … 3911 3921 delete(Subgraphs); 3912 3922 } 3913 Free( (void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");3923 Free(&FragmentList); 3914 3924 3915 3925 // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass ===== … … 3958 3968 *out << Verbose(1) << "Freeing bond memory" << endl; 3959 3969 delete(FragmentList); // remove bond molecule from memory 3960 Free( (void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");3970 Free(&SortIndex); 3961 3971 } else 3962 3972 *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl; … … 4046 4056 bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path) 4047 4057 { 4048 unsigned char *OrderArray = (unsigned char *) Malloc(sizeof(unsigned char)*AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");4049 bool *MaxArray = (bool *) Malloc(sizeof(bool)*AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");4058 unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray"); 4059 bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray"); 4050 4060 bool status; 4051 4061 int AtomNr, value; … … 4088 4098 status = false; 4089 4099 } 4090 Free( (void **)&OrderArray, "molecule::ParseOrderAtSiteFromFile - *OrderArray");4091 Free( (void **)&MaxArray, "molecule::ParseOrderAtSiteFromFile - *MaxArray");4100 Free(&OrderArray); 4101 Free(&MaxArray); 4092 4102 4093 4103 *out << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl; … … 4112 4122 if (ListOfBondsPerAtom != NULL) { 4113 4123 for(int i=AtomCount;i--;) 4114 Free( (void **)&ListOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom[i]");4115 Free( (void **)&ListOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom");4124 Free(&ListOfBondsPerAtom[i]); 4125 Free(&ListOfBondsPerAtom); 4116 4126 } 4117 4127 if (NumberOfBondsPerAtom != NULL) 4118 Free( (void **)&NumberOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: NumberOfBondsPerAtom");4119 ListOfBondsPerAtom = (bond ***) Malloc(sizeof(bond **)*AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom");4120 NumberOfBondsPerAtom = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom");4128 Free(&NumberOfBondsPerAtom); 4129 ListOfBondsPerAtom = Malloc<bond**>(AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom"); 4130 NumberOfBondsPerAtom = Malloc<int>(AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom"); 4121 4131 4122 4132 // reset bond counts per atom … … 4132 4142 for(int i=AtomCount;i--;) { 4133 4143 // allocate list of bonds per atom 4134 ListOfBondsPerAtom[i] = (bond **) Malloc(sizeof(bond *)*NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");4144 ListOfBondsPerAtom[i] = Malloc<bond*>(NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]"); 4135 4145 // clear the list again, now each NumberOfBondsPerAtom marks current free field 4136 4146 NumberOfBondsPerAtom[i] = 0; … … 4174 4184 void molecule::BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem) 4175 4185 { 4176 atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::BreadthFirstSearchAdd: **PredecessorList");4177 int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList");4178 enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList");4186 atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::BreadthFirstSearchAdd: **PredecessorList"); 4187 int *ShortestPathList = Malloc<int>(AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList"); 4188 enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList"); 4179 4189 class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount); 4180 4190 atom *Walker = NULL, *OtherAtom = NULL; … … 4281 4291 *out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl; 4282 4292 } 4283 Free( (void **)&PredecessorList, "molecule::BreadthFirstSearchAdd: **PredecessorList");4284 Free( (void **)&ShortestPathList, "molecule::BreadthFirstSearchAdd: **ShortestPathList");4285 Free( (void **)&ColorList, "molecule::BreadthFirstSearchAdd: **ColorList");4293 Free(&PredecessorList); 4294 Free(&ShortestPathList); 4295 Free(&ColorList); 4286 4296 delete(AtomStack); 4287 4297 }; … … 4300 4310 atom *Walker = NULL, *OtherAtom = NULL; 4301 4311 bool status = true; 4302 atom **ParentList = (atom **) Malloc(sizeof(atom *)*Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");4312 atom **ParentList = Malloc<atom*>(Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList"); 4303 4313 4304 4314 *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl; … … 4339 4349 } 4340 4350 4341 Free( (void **)&ParentList, "molecule::BuildInducedSubgraph: **ParentList");4351 Free(&ParentList); 4342 4352 *out << Verbose(2) << "End of BuildInducedSubgraph." << endl; 4343 4353 return status; … … 4382 4392 { 4383 4393 atom *Runner = NULL, *FatherOfRunner = NULL, *OtherFather = NULL; 4384 atom **SonList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::StoreFragmentFromStack: **SonList");4394 atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList"); 4385 4395 molecule *Leaf = new molecule(elemente); 4386 4396 bool LonelyFlag = false; … … 4452 4462 Leaf->CreateListOfBondsPerAtom(out); 4453 4463 //Leaflet->Leaf->ScanForPeriodicCorrection(out); 4454 Free( (void **)&SonList, "molecule::StoreFragmentFromStack: **SonList");4464 Free(&SonList); 4455 4465 // *out << Verbose(1) << "End of StoreFragmentFromKeyset." << endl; 4456 4466 return Leaf; … … 4473 4483 MoleculeListClass * molecule::CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, config *configuration) 4474 4484 { 4475 atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");4476 int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");4477 int *Labels = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");4478 enum Shading *ColorVertexList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");4479 enum Shading *ColorEdgeList = (enum Shading *) Malloc(sizeof(enum Shading)*BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList");4485 atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList"); 4486 int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList"); 4487 int *Labels = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels"); 4488 enum Shading *ColorVertexList = Malloc<enum Shading>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList"); 4489 enum Shading *ColorEdgeList = Malloc<enum Shading>(BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList"); 4480 4490 StackClass<atom *> *RootStack = new StackClass<atom *>(AtomCount); 4481 4491 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 4617 4608 4618 // free memory and exit 4609 Free( (void **)&PredecessorList, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");4610 Free( (void **)&ShortestPathList, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");4611 Free( (void **)&Labels, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");4612 Free( (void **)&ColorVertexList, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");4619 Free(&PredecessorList); 4620 Free(&ShortestPathList); 4621 Free(&Labels); 4622 Free(&ColorVertexList); 4613 4623 delete(RootStack); 4614 4624 delete(TouchedStack); … … 4660 4670 int Removal; 4661 4671 int SpaceLeft; 4662 int *TouchedList = (int *) Malloc(sizeof(int)*(SubOrder+1), "molecule::SPFragmentGenerator: *TouchedList");4672 int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList"); 4663 4673 bond *Binder = NULL; 4664 4674 bond **BondsList = NULL; … … 4668 4678 4669 4679 // 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 werden4680 // von Endstuecken (aus den Bonds) hinzugefuegt werden und fuer verbleibende ANOVAOrder 4681 // rekursiv GraphCrawler in der naechsten Ebene aufgerufen werden 4672 4682 4673 4683 *out << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl; … … 4729 4739 } 4730 4740 // then allocate and fill the list 4731 BondsList = (bond **) Malloc(sizeof(bond *)*SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");4741 BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList"); 4732 4742 SubSetDimension = 0; 4733 4743 Binder = FragmentSearch->BondsPerSPList[2*SP]; … … 4741 4751 *out << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl; 4742 4752 SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits); 4743 Free( (void **)&BondsList, "molecule::SPFragmentGenerator: **BondsList");4753 Free(&BondsList); 4744 4754 } 4745 4755 } else { … … 4775 4785 } 4776 4786 } 4777 Free( (void **)&TouchedList, "molecule::SPFragmentGenerator: *TouchedList");4787 Free(&TouchedList); 4778 4788 *out << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl; 4779 4789 }; … … 4953 4963 *out << Verbose(0) << "Preparing subset for this root and calling generator." << endl; 4954 4964 // prepare the subset and call the generator 4955 BondsList = (bond **) Malloc(sizeof(bond *)*FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");4965 BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList"); 4956 4966 BondsList[0] = FragmentSearch.BondsPerSPList[0]->next; // on SP level 0 there's only the root bond 4957 4967 4958 4968 SPFragmentGenerator(out, &FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order); 4959 4969 4960 Free( (void **)&BondsList, "molecule::PowerSetGenerator: **BondsList");4970 Free(&BondsList); 4961 4971 } else { 4962 4972 *out << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl; … … 5012 5022 *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl; 5013 5023 5014 ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");5024 ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList"); 5015 5025 while (flag) { 5016 5026 // remove bonds that are beyond bonddistance … … 5073 5083 // free allocated space from ReturnFullMatrixforSymmetric() 5074 5084 delete(AtomStack); 5075 Free( (void **)&ColorList, "molecule::ScanForPeriodicCorrection: *ColorList");5076 Free( (void **)&matrix, "molecule::ScanForPeriodicCorrection: *matrix");5085 Free(&ColorList); 5086 Free(&matrix); 5077 5087 *out << Verbose(2) << "End of ScanForPeriodicCorrection." << endl; 5078 5088 }; … … 5084 5094 double * molecule::ReturnFullMatrixforSymmetric(double *symm) 5085 5095 { 5086 double *matrix = (double *) Malloc(sizeof(double)*NDIM*NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");5096 double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix"); 5087 5097 matrix[0] = symm[0]; 5088 5098 matrix[1] = symm[1]; … … 5211 5221 // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5) 5212 5222 // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5) 5213 NumMoleculesOfOrder = (int *) Malloc(sizeof(int)*UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");5214 FragmentLowerOrdersList = (Graph ***) Malloc(sizeof(Graph **)*UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");5223 NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder"); 5224 FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList"); 5215 5225 5216 5226 // initialise the fragments structure 5217 FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");5227 FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList"); 5218 5228 FragmentSearch.FragmentCounter = 0; 5219 5229 FragmentSearch.FragmentSet = new KeySet; … … 5250 5260 5251 5261 // initialise Order-dependent entries of UniqueFragments structure 5252 FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");5253 FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");5262 FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList"); 5263 FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount"); 5254 5264 for (int i=Order;i--;) { 5255 5265 FragmentSearch.BondsPerSPList[2*i] = new bond(); // start node … … 5262 5272 // allocate memory for all lower level orders in this 1D-array of ptrs 5263 5273 NumLevels = 1 << (Order-1); // (int)pow(2,Order); 5264 FragmentLowerOrdersList[RootNr] = (Graph **) Malloc(sizeof(Graph *)*NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");5274 FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]"); 5265 5275 for (int i=0;i<NumLevels;i++) 5266 5276 FragmentLowerOrdersList[RootNr][i] = NULL; … … 5329 5339 5330 5340 // free Order-dependent entries of UniqueFragments structure for next loop cycle 5331 Free( (void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");5341 Free(&FragmentSearch.BondsPerSPCount); 5332 5342 for (int i=Order;i--;) { 5333 5343 delete(FragmentSearch.BondsPerSPList[2*i]); 5334 5344 delete(FragmentSearch.BondsPerSPList[2*i+1]); 5335 5345 } 5336 Free( (void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");5346 Free(&FragmentSearch.BondsPerSPList); 5337 5347 } 5338 5348 } … … 5342 5352 5343 5353 // cleanup FragmentSearch structure 5344 Free( (void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");5354 Free(&FragmentSearch.ShortestPathList); 5345 5355 delete(FragmentSearch.FragmentSet); 5346 5356 … … 5373 5383 } 5374 5384 } 5375 Free( (void **)&FragmentLowerOrdersList[RootNr], "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");5385 Free(&FragmentLowerOrdersList[RootNr]); 5376 5386 RootNr++; 5377 5387 } 5378 Free( (void **)&FragmentLowerOrdersList, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");5379 Free( (void **)&NumMoleculesOfOrder, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");5388 Free(&FragmentLowerOrdersList); 5389 Free(&NumMoleculesOfOrder); 5380 5390 5381 5391 *out << Verbose(0) << "End of FragmentBOSSANOVA." << endl; … … 5467 5477 if (result) { 5468 5478 *out << Verbose(5) << "Calculating distances" << endl; 5469 Distances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: Distances");5470 OtherDistances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");5479 Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances"); 5480 OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances"); 5471 5481 Walker = start; 5472 5482 while (Walker->next != end) { … … 5482 5492 /// ... sort each list (using heapsort (o(N log N)) from GSL) 5483 5493 *out << Verbose(5) << "Sorting distances" << endl; 5484 PermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");5485 OtherPermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");5494 PermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap"); 5495 OtherPermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap"); 5486 5496 gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles); 5487 5497 gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles); 5488 PermutationMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");5498 PermutationMap = Malloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap"); 5489 5499 *out << Verbose(5) << "Combining Permutation Maps" << endl; 5490 5500 for(int i=AtomCount;i--;) 5491 5501 PermutationMap[PermMap[i]] = (int) OtherPermMap[i]; 5492 5502 5493 /// ... and compare them step by step, whether the difference is individ iually(!) below \a threshold for all5503 /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all 5494 5504 *out << Verbose(4) << "Comparing distances" << endl; 5495 5505 flag = 0; … … 5499 5509 flag = 1; 5500 5510 } 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");5511 5512 // free memory 5513 Free(&PermMap); 5514 Free(&OtherPermMap); 5515 Free(&Distances); 5516 Free(&OtherDistances); 5507 5517 if (flag) { // if not equal 5508 Free( (void **)&PermutationMap, "molecule::IsEqualToWithinThreshold: *PermutationMap");5518 Free(&PermutationMap); 5509 5519 result = false; 5510 5520 } … … 5532 5542 atom *Walker = NULL, *OtherWalker = NULL; 5533 5543 *out << Verbose(3) << "Begin of GetFatherAtomicMap." << endl; 5534 int *AtomicMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::GetAtomicMap: *AtomicMap"); //Calloc5544 int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap"); 5535 5545 for (int i=AtomCount;i--;) 5536 5546 AtomicMap[i] = -1;
Note:
See TracChangeset
for help on using the changeset viewer.