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