Changes in src/molecule_fragmentation.cpp [d4c9ae:112b09]
- File:
-
- 1 edited
-
src/molecule_fragmentation.cpp (modified) (52 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_fragmentation.cpp
rd4c9ae r112b09 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <cstring> … … 39 41 int FragmentCount; 40 42 // get maximum bond degree 41 atom *Walker = start; 42 while (Walker->next != end) { 43 Walker = Walker->next; 44 c = (Walker->ListOfBonds.size() > c) ? Walker->ListOfBonds.size() : c; 43 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 44 c = ((*iter)->ListOfBonds.size() > c) ? (*iter)->ListOfBonds.size() : c; 45 45 } 46 46 FragmentCount = NoNonHydrogen*(1 << (c*order)); … … 94 94 GraphTestPair testGraphInsert; 95 95 int NumberOfFragments = 0; 96 char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");96 char filename[MAXSTRINGSIZE]; 97 97 98 98 if (FragmentList == NULL) { // check list pointer … … 106 106 if (InputFile != NULL) { 107 107 // each line represents a new fragment 108 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");108 char buffer[MAXSTRINGSIZE]; 109 109 // 1. parse keysets and insert into temp. graph 110 110 while (!InputFile.eof()) { … … 122 122 InputFile.close(); 123 123 InputFile.clear(); 124 Free(&buffer); 125 DoLog(1) && (Log() << Verbose(1) << "done." << endl); 124 DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl); 126 125 } else { 127 DoLog(1) && (Log() << Verbose(1) << " File " << filename << " not found." << endl);126 DoLog(1) && (Log() << Verbose(1) << "\t ... File " << filename << " not found." << endl); 128 127 status = false; 129 128 } 130 129 131 Free(&filename);132 130 return status; 133 131 }; … … 148 146 int NumberOfFragments = 0; 149 147 double TEFactor; 150 char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseTEFactorsFile - filename");148 char filename[MAXSTRINGSIZE]; 151 149 152 150 if (FragmentList == NULL) { // check list pointer … … 179 177 } 180 178 181 // free memory182 Free(&filename);183 184 179 return status; 185 180 }; … … 317 312 int No = 0, FragOrder = 0; 318 313 double Value = 0.; 319 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");314 char buffer[MAXSTRINGSIZE]; 320 315 sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT); 321 316 ifstream InputFile(buffer, ios::in); … … 345 340 InputFile.clear(); 346 341 } 347 Free(&buffer);348 342 349 343 return AdaptiveCriteriaList; … … 359 353 map<double, pair<int,int> > * ReMapAdaptiveCriteriaListToValue(map<int, pair<double,int> > *AdaptiveCriteriaList, molecule *mol) 360 354 { 361 atom *Walker = mol->start;355 atom *Walker = NULL; 362 356 map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ; 363 357 DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl); … … 391 385 bool MarkUpdateCandidates(bool *AtomMask, map<double, pair<int,int> > &FinalRootCandidates, int Order, molecule *mol) 392 386 { 393 atom *Walker = mol->start;387 atom *Walker = NULL; 394 388 int No = -1; 395 389 bool status = false; … … 435 429 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path) 436 430 { 437 atom *Walker = start;438 431 bool status = false; 439 432 440 433 // initialize mask list 441 for(int i= AtomCount;i--;)434 for(int i=getAtomCount();i--;) 442 435 AtomMask[i] = false; 443 436 444 437 if (Order < 0) { // adaptive increase of BondOrder per site 445 if (AtomMask[ AtomCount] == true) // break after one step438 if (AtomMask[getAtomCount()] == true) // break after one step 446 439 return false; 447 440 … … 457 450 if (AdaptiveCriteriaList->empty()) { 458 451 DoeLog(2) && (eLog()<< Verbose(2) << "Unable to parse file, incrementing all." << endl); 459 while (Walker->next != end) { 460 Walker = Walker->next; 452 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 461 453 #ifdef ADDHYDROGEN 462 if ( Walker->type->Z != 1) // skip hydrogen454 if ((*iter)->type->Z != 1) // skip hydrogen 463 455 #endif 464 456 { 465 AtomMask[ Walker->nr] = true; // include all (non-hydrogen) atoms457 AtomMask[(*iter)->nr] = true; // include all (non-hydrogen) atoms 466 458 status = true; 467 459 } … … 474 466 MarkUpdateCandidates(AtomMask, *FinalRootCandidates, Order, this); 475 467 476 Free(&IndexKeySetList);477 Free(&AdaptiveCriteriaList);478 Free(&FinalRootCandidates);468 delete[](IndexKeySetList); 469 delete[](AdaptiveCriteriaList); 470 delete[](FinalRootCandidates); 479 471 } else { // global increase of Bond Order 480 while (Walker->next != end) { 481 Walker = Walker->next; 472 for(molecule::const_iterator iter = begin(); iter != end(); ++iter) { 482 473 #ifdef ADDHYDROGEN 483 if ( Walker->type->Z != 1) // skip hydrogen474 if ((*iter)->type->Z != 1) // skip hydrogen 484 475 #endif 485 476 { 486 AtomMask[ Walker->nr] = true; // include all (non-hydrogen) atoms487 if ((Order != 0) && ( Walker->AdaptiveOrder < Order)) // && (Walker->AdaptiveOrder < MinimumRingSize[Walker->nr]))477 AtomMask[(*iter)->nr] = true; // include all (non-hydrogen) atoms 478 if ((Order != 0) && ((*iter)->AdaptiveOrder < Order)) // && ((*iter)->AdaptiveOrder < MinimumRingSize[(*iter)->nr])) 488 479 status = true; 489 480 } 490 481 } 491 if (( Order == 0) && (AtomMask[AtomCount] == false)) // single stepping, just check482 if ((!Order) && (!AtomMask[getAtomCount()])) // single stepping, just check 492 483 status = true; 493 484 … … 500 491 } 501 492 502 PrintAtomMask(AtomMask, AtomCount); // for debugging493 PrintAtomMask(AtomMask, getAtomCount()); // for debugging 503 494 504 495 return status; … … 516 507 return false; 517 508 } 518 SortIndex = Malloc<int>(AtomCount, "molecule::CreateMappingLabelsToConfigSequence: *SortIndex");519 for(int i= AtomCount;i--;)509 SortIndex = new int[getAtomCount()]; 510 for(int i=getAtomCount();i--;) 520 511 SortIndex[i] = -1; 521 512 … … 524 515 525 516 return true; 517 }; 518 519 520 521 /** Creates a lookup table for true father's Atom::Nr -> atom ptr. 522 * \param *start begin of list (STL iterator, i.e. first item) 523 * \paran *end end of list (STL iterator, i.e. one past last item) 524 * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start) 525 * \param count optional predetermined size for table (otherwise we set the count to highest true father id) 526 * \return true - success, false - failure 527 */ 528 bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count) 529 { 530 bool status = true; 531 int AtomNo; 532 533 if (LookupTable != NULL) { 534 Log() << Verbose(0) << "Pointer for Lookup table is not NULL! Aborting ..." <<endl; 535 return false; 536 } 537 538 // count them 539 if (count == 0) { 540 for (molecule::iterator iter = begin(); iter != end(); ++iter) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron 541 count = (count < (*iter)->GetTrueFather()->nr) ? (*iter)->GetTrueFather()->nr : count; 542 } 543 } 544 if (count <= 0) { 545 Log() << Verbose(0) << "Count of lookup list is 0 or less." << endl; 546 return false; 547 } 548 549 // allocate and fill 550 LookupTable = new atom *[count]; 551 if (LookupTable == NULL) { 552 eLog() << Verbose(0) << "LookupTable memory allocation failed!" << endl; 553 performCriticalExit(); 554 status = false; 555 } else { 556 for (int i=0;i<count;i++) 557 LookupTable[i] = NULL; 558 for (molecule::iterator iter = begin(); iter != end(); ++iter) { 559 AtomNo = (*iter)->GetTrueFather()->nr; 560 if ((AtomNo >= 0) && (AtomNo < count)) { 561 //*out << "Setting LookupTable[" << AtomNo << "] to " << *(*iter) << endl; 562 LookupTable[AtomNo] = (*iter); 563 } else { 564 Log() << Verbose(0) << "Walker " << *(*iter) << " exceeded range of nuclear ids [0, " << count << ")." << endl; 565 status = false; 566 break; 567 } 568 } 569 } 570 571 return status; 526 572 }; 527 573 … … 547 593 { 548 594 MoleculeListClass *BondFragments = NULL; 549 int *SortIndex = NULL; 550 int *MinimumRingSize = new int[AtomCount]; 595 int *MinimumRingSize = new int[getAtomCount()]; 551 596 int FragmentCounter; 552 597 MoleculeLeafClass *MolecularWalker = NULL; … … 576 621 577 622 // create lookup table for Atom::nr 578 FragmentationToDo = FragmentationToDo && CreateFatherLookupTable( start, end, ListOfAtoms, AtomCount);623 FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(ListOfAtoms, getAtomCount()); 579 624 580 625 // === compare it with adjacency file === 581 626 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(configuration->configpath, ListOfAtoms); 582 Free(&ListOfAtoms);627 delete[](ListOfAtoms); 583 628 584 629 // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===== … … 586 631 587 632 // analysis of the cycles (print rings, get minimum cycle length) for each subgraph 588 for(int i= AtomCount;i--;)589 MinimumRingSize[i] = AtomCount;633 for(int i=getAtomCount();i--;) 634 MinimumRingSize[i] = getAtomCount(); 590 635 MolecularWalker = Subgraphs; 591 636 FragmentCounter = 0; … … 598 643 // // check the list of local atoms for debugging 599 644 // Log() << Verbose(0) << "ListOfLocalAtoms for this subgraph is:" << endl; 600 // for (int i=0;i< AtomCount;i++)645 // for (int i=0;i<getAtomCount();i++) 601 646 // if (ListOfLocalAtoms[FragmentCounter][i] == NULL) 602 647 // Log() << Verbose(0) << "\tNULL"; … … 624 669 // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle 625 670 KeyStack *RootStack = new KeyStack[Subgraphs->next->Count()]; 626 AtomMask = new bool[ AtomCount+1];627 AtomMask[ AtomCount] = false;671 AtomMask = new bool[getAtomCount()+1]; 672 AtomMask[getAtomCount()] = false; 628 673 FragmentationToDo = false; // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards 629 674 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) { 630 675 FragmentationToDo = FragmentationToDo || CheckOrder; 631 AtomMask[ AtomCount] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()676 AtomMask[getAtomCount()] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite() 632 677 // ===== 6b. fill RootStack for each subgraph (second adaptivity check) ===== 633 678 Subgraphs->next->FillRootStackForSubgraphs(RootStack, AtomMask, (FragmentCounter = 0)); … … 640 685 DoLog(1) && (Log() << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl); 641 686 //MolecularWalker->Leaf->OutputListOfBonds(out); // output atom::ListOfBonds for debugging 642 if (MolecularWalker->Leaf-> first->next != MolecularWalker->Leaf->last) {687 if (MolecularWalker->Leaf->hasBondStructure()) { 643 688 // call BOSSANOVA method 644 689 DoLog(0) && (Log() << Verbose(0) << endl << " ========== BOND ENERGY of subgraph " << FragmentCounter << " ========================= " << endl); … … 672 717 delete(Subgraphs); 673 718 } 674 Free(&FragmentList);719 delete[](FragmentList); 675 720 676 721 // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass ===== … … 690 735 if (BondFragments->ListOfMolecules.size() != 0) { 691 736 // create the SortIndex from BFS labels to order in the config file 737 int *SortIndex = NULL; 692 738 CreateMappingLabelsToConfigSequence(SortIndex); 693 739 … … 704 750 StoreKeySetFile(TotalGraph, configuration->configpath); 705 751 706 // store Adjacency file 707 char *filename = Malloc<char> (MAXSTRINGSIZE, "molecule::FragmentMolecule - *filename"); 708 strcpy(filename, FRAGMENTPREFIX); 709 strcat(filename, ADJACENCYFILE); 710 StoreAdjacencyToFile(configuration->configpath, filename); 711 Free(&filename); 752 { 753 // store Adjacency file 754 char filename[MAXSTRINGSIZE]; 755 strcpy(filename, FRAGMENTPREFIX); 756 strcat(filename, ADJACENCYFILE); 757 StoreAdjacencyToFile(configuration->configpath, filename); 758 } 712 759 713 760 // store Hydrogen saturation correction file … … 722 769 // free memory for bond part 723 770 DoLog(1) && (Log() << Verbose(1) << "Freeing bond memory" << endl); 724 Free(&FragmentList); // remove bond molecule from memory 725 Free(&SortIndex); 771 delete[](SortIndex); 726 772 } else { 727 773 DoLog(1) && (Log() << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl); … … 768 814 bool molecule::ParseOrderAtSiteFromFile(char *path) 769 815 { 770 unsigned char *OrderArray = Calloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");771 bool *MaxArray = Calloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");816 unsigned char *OrderArray = new unsigned char[getAtomCount()]; 817 bool *MaxArray = new bool[getAtomCount()]; 772 818 bool status; 773 819 int AtomNr, value; 774 820 stringstream line; 775 821 ifstream file; 822 823 for(int i=0;i<getAtomCount();i++) { 824 OrderArray[i] = 0; 825 MaxArray[i] = false; 826 } 776 827 777 828 DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl); … … 796 847 SetAtomValueToIndexedArray( MaxArray, &atom::nr, &atom::MaxOrder ); 797 848 798 DoLog(1) && (Log() << Verbose(1) << " done." << endl);849 DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl); 799 850 status = true; 800 851 } else { 801 DoLog(1) && (Log() << Verbose(1) << " failed to open file " << line.str() << "." << endl);852 DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line.str() << "." << endl); 802 853 status = false; 803 854 } 804 Free(&OrderArray);805 Free(&MaxArray);855 delete[](OrderArray); 856 delete[](MaxArray); 806 857 807 858 DoLog(1) && (Log() << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl); … … 872 923 atom *OtherFather = NULL; 873 924 atom *FatherOfRunner = NULL; 874 Leaf->CountAtoms(); 875 876 atom *Runner = Leaf->start; 877 while (Runner->next != Leaf->end) { 878 Runner = Runner->next; 925 926 #ifdef ADDHYDROGEN 927 molecule::const_iterator runner; 928 #endif 929 // we increment the iter just before skipping the hydrogen 930 for (molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end();) { 879 931 LonelyFlag = true; 880 FatherOfRunner = Runner->father; 932 FatherOfRunner = (*iter)->father; 933 ASSERT(FatherOfRunner,"Atom without father found"); 881 934 if (SonList[FatherOfRunner->nr] != NULL) { // check if this, our father, is present in list 882 935 // create all bonds … … 889 942 // Log() << Verbose(3) << "Adding Bond: "; 890 943 // Log() << Verbose(0) << 891 Leaf->AddBond( Runner, SonList[OtherFather->nr], (*BondRunner)->BondDegree);944 Leaf->AddBond((*iter), SonList[OtherFather->nr], (*BondRunner)->BondDegree); 892 945 // Log() << Verbose(0) << "." << endl; 893 //NumBonds[ Runner->nr]++;946 //NumBonds[(*iter)->nr]++; 894 947 } else { 895 948 // Log() << Verbose(3) << "Not adding bond, labels in wrong order." << endl; … … 899 952 // Log() << Verbose(0) << ", who has no son in this fragment molecule." << endl; 900 953 #ifdef ADDHYDROGEN 901 //Log() << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;902 if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), Runner, FatherOfRunner, OtherFather, IsAngstroem))954 //Log() << Verbose(3) << "Adding Hydrogen to " << (*iter)->Name << " and a bond in between." << endl; 955 if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem)) 903 956 exit(1); 904 957 #endif 905 //NumBonds[ Runner->nr] += Binder->BondDegree;958 //NumBonds[(*iter)->nr] += Binder->BondDegree; 906 959 } 907 960 } 908 961 } else { 909 DoeLog(1) && (eLog()<< Verbose(1) << "Son " << Runner->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl); 910 } 911 if ((LonelyFlag) && (Leaf->AtomCount > 1)) { 912 DoLog(0) && (Log() << Verbose(0) << *Runner << "has got bonds only to hydrogens!" << endl); 913 } 962 DoeLog(1) && (eLog()<< Verbose(1) << "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl); 963 } 964 if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) { 965 DoLog(0) && (Log() << Verbose(0) << **iter << "has got bonds only to hydrogens!" << endl); 966 } 967 ++iter; 914 968 #ifdef ADDHYDROGEN 915 while ((Runner->next != Leaf->end) && (Runner->next->type->Z == 1)) // skip added hydrogen 916 Runner = Runner->next; 969 while ((iter != Leaf->end()) && ((*iter)->type->Z == 1)){ // skip added hydrogen 970 iter++; 971 } 917 972 #endif 918 973 } … … 929 984 molecule * molecule::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem) 930 985 { 931 atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");986 atom **SonList = new atom*[getAtomCount()]; 932 987 molecule *Leaf = World::getInstance().createMolecule(); 988 989 for(int i=0;i<getAtomCount();i++) 990 SonList[i] = NULL; 933 991 934 992 // Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl; … … 939 997 940 998 //Leaflet->Leaf->ScanForPeriodicCorrection(out); 941 Free(&SonList);999 delete[](SonList); 942 1000 // Log() << Verbose(1) << "End of StoreFragmentFromKeyset." << endl; 943 1001 return Leaf; … … 1084 1142 int bits, TouchedIndex, SubSetDimension, SP, Added; 1085 1143 int SpaceLeft; 1086 int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList"); 1087 bond **BondsList = NULL; 1144 int *TouchedList = new int[SubOrder + 1]; 1088 1145 KeySetTestPair TestKeySetInsert; 1089 1146 … … 1124 1181 1125 1182 // then allocate and fill the list 1126 BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");1183 bond *BondsList[SubSetDimension]; 1127 1184 SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex); 1128 1185 … … 1130 1187 Log() << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl; 1131 1188 SPFragmentGenerator(FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits); 1132 1133 Free(&BondsList);1134 1189 } 1135 1190 } else { … … 1153 1208 } 1154 1209 } 1155 Free(&TouchedList);1210 delete[](TouchedList); 1156 1211 Log() << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl; 1157 1212 }; … … 1165 1220 void InitialiseSPList(int Order, struct UniqueFragments &FragmentSearch) 1166 1221 { 1167 FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList");1168 FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount");1222 FragmentSearch.BondsPerSPList = new bond* [Order * 2]; 1223 FragmentSearch.BondsPerSPCount = new int[Order]; 1169 1224 for (int i=Order;i--;) { 1170 1225 FragmentSearch.BondsPerSPList[2*i] = new bond(); // start node … … 1184 1239 void FreeSPList(int Order, struct UniqueFragments &FragmentSearch) 1185 1240 { 1186 Free(&FragmentSearch.BondsPerSPCount);1241 delete[](FragmentSearch.BondsPerSPCount); 1187 1242 for (int i=Order;i--;) { 1188 1243 delete(FragmentSearch.BondsPerSPList[2*i]); 1189 1244 delete(FragmentSearch.BondsPerSPList[2*i+1]); 1190 1245 } 1191 Free(&FragmentSearch.BondsPerSPList);1246 delete[](FragmentSearch.BondsPerSPList); 1192 1247 }; 1193 1248 … … 1370 1425 int molecule::PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet) 1371 1426 { 1372 bond **BondsList = NULL;1373 1427 int Counter = FragmentSearch.FragmentCounter; // mark current value of counter 1374 1428 … … 1394 1448 1395 1449 // prepare the subset and call the generator 1396 BondsList = Calloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList"); 1450 bond* BondsList[FragmentSearch.BondsPerSPCount[0]]; 1451 for(int i=0;i<FragmentSearch.BondsPerSPCount[0];i++) 1452 BondsList[i] = NULL; 1397 1453 BondsList[0] = FragmentSearch.BondsPerSPList[0]->next; // on SP level 0 there's only the root bond 1398 1454 1399 1455 SPFragmentGenerator(&FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order); 1400 1401 Free(&BondsList);1402 1456 } else { 1403 1457 DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl); … … 1507 1561 } 1508 1562 } 1509 Free(&FragmentLowerOrdersList[RootNr]);1563 delete[](FragmentLowerOrdersList[RootNr]); 1510 1564 RootNr++; 1511 1565 } 1512 Free(&FragmentLowerOrdersList);1566 delete[](FragmentLowerOrdersList); 1513 1567 }; 1514 1568 … … 1549 1603 // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5) 1550 1604 // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5) 1551 NumMoleculesOfOrder = Calloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder"); 1552 FragmentLowerOrdersList = Calloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList"); 1605 NumMoleculesOfOrder = new int[UpgradeCount]; 1606 FragmentLowerOrdersList = new Graph**[UpgradeCount]; 1607 1608 for(int i=0;i<UpgradeCount;i++) { 1609 NumMoleculesOfOrder[i] = 0; 1610 FragmentLowerOrdersList[i] = NULL; 1611 } 1553 1612 1554 1613 // initialise the fragments structure … … 1556 1615 FragmentSearch.FragmentSet = new KeySet; 1557 1616 FragmentSearch.Root = FindAtom(RootKeyNr); 1558 FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");1559 for (int i= AtomCount;i--;) {1617 FragmentSearch.ShortestPathList = new int[getAtomCount()]; 1618 for (int i=getAtomCount();i--;) { 1560 1619 FragmentSearch.ShortestPathList[i] = -1; 1561 1620 } 1562 1621 1563 1622 // Construct the complete KeySet which we need for topmost level only (but for all Roots) 1564 atom *Walker = start;1565 1623 KeySet CompleteMolecule; 1566 while (Walker->next != end) { 1567 Walker = Walker->next; 1568 CompleteMolecule.insert(Walker->GetTrueFather()->nr); 1624 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 1625 CompleteMolecule.insert((*iter)->GetTrueFather()->nr); 1569 1626 } 1570 1627 … … 1577 1634 RootKeyNr = RootStack.front(); 1578 1635 RootStack.pop_front(); 1579 Walker = FindAtom(RootKeyNr);1636 atom *Walker = FindAtom(RootKeyNr); 1580 1637 // check cyclic lengths 1581 1638 //if ((MinimumRingSize[Walker->GetTrueFather()->nr] != -1) && (Walker->GetTrueFather()->AdaptiveOrder+1 > MinimumRingSize[Walker->GetTrueFather()->nr])) { … … 1592 1649 // allocate memory for all lower level orders in this 1D-array of ptrs 1593 1650 NumLevels = 1 << (Order-1); // (int)pow(2,Order); 1594 FragmentLowerOrdersList[RootNr] = Calloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]"); 1651 FragmentLowerOrdersList[RootNr] = new Graph*[NumLevels]; 1652 for (int i=0;i<NumLevels;i++) 1653 FragmentLowerOrdersList[RootNr][i] = NULL; 1595 1654 1596 1655 // create top order where nothing is reduced … … 1628 1687 1629 1688 // cleanup FragmentSearch structure 1630 Free(&FragmentSearch.ShortestPathList);1689 delete[](FragmentSearch.ShortestPathList); 1631 1690 delete(FragmentSearch.FragmentSet); 1632 1691 … … 1641 1700 CombineAllOrderListIntoOne(FragmentList, FragmentLowerOrdersList, RootStack, this); 1642 1701 FreeAllOrdersList(FragmentLowerOrdersList, RootStack, this); 1643 Free(&NumMoleculesOfOrder);1702 delete[](NumMoleculesOfOrder); 1644 1703 1645 1704 DoLog(0) && (Log() << Verbose(0) << "End of FragmentBOSSANOVA." << endl); … … 1664 1723 Vector Translationvector; 1665 1724 //class StackClass<atom *> *CompStack = NULL; 1666 class StackClass<atom *> *AtomStack = new StackClass<atom *>( AtomCount);1725 class StackClass<atom *> *AtomStack = new StackClass<atom *>(getAtomCount()); 1667 1726 bool flag = true; 1668 1727 1669 1728 DoLog(2) && (Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl); 1670 1729 1671 ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList"); 1730 ColorList = new enum Shading[getAtomCount()]; 1731 for (int i=0;i<getAtomCount();i++) 1732 ColorList[i] = (enum Shading)0; 1672 1733 while (flag) { 1673 1734 // remove bonds that are beyond bonddistance 1674 1735 Translationvector.Zero(); 1675 1736 // scan all bonds 1676 Binder = first;1677 1737 flag = false; 1678 while ((!flag) && (Binder->next != last)) { 1679 Binder = Binder->next; 1680 for (int i=NDIM;i--;) { 1681 tmp = fabs(Binder->leftatom->x[i] - Binder->rightatom->x[i]); 1682 //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl; 1683 if (tmp > BondDistance) { 1684 OtherBinder = Binder->next; // note down binding partner for later re-insertion 1685 unlink(Binder); // unlink bond 1686 DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl); 1687 flag = true; 1688 break; 1738 for(molecule::iterator AtomRunner = begin(); (!flag) && (AtomRunner != end()); ++AtomRunner) 1739 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); (!flag) && (BondRunner != (*AtomRunner)->ListOfBonds.end()); ++BondRunner) { 1740 Binder = (*BondRunner); 1741 for (int i=NDIM;i--;) { 1742 tmp = fabs(Binder->leftatom->x[i] - Binder->rightatom->x[i]); 1743 //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl; 1744 if (tmp > BondDistance) { 1745 OtherBinder = Binder->next; // note down binding partner for later re-insertion 1746 unlink(Binder); // unlink bond 1747 DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl); 1748 flag = true; 1749 break; 1750 } 1689 1751 } 1690 1752 } 1691 }1692 1753 if (flag) { 1693 1754 // create translation vector from their periodically modified distance … … 1701 1762 Log() << Verbose(0) << Translationvector << endl; 1702 1763 // apply to all atoms of first component via BFS 1703 for (int i= AtomCount;i--;)1764 for (int i=getAtomCount();i--;) 1704 1765 ColorList[i] = white; 1705 1766 AtomStack->Push(Binder->leftatom); … … 1727 1788 // free allocated space from ReturnFullMatrixforSymmetric() 1728 1789 delete(AtomStack); 1729 Free(&ColorList);1730 Free(&matrix);1790 delete[](ColorList); 1791 delete[](matrix); 1731 1792 DoLog(2) && (Log() << Verbose(2) << "End of ScanForPeriodicCorrection." << endl); 1732 1793 };
Note:
See TracChangeset
for help on using the changeset viewer.
