Changes in src/molecule_fragmentation.cpp [d4c9ae:35b698]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_fragmentation.cpp
rd4c9ae r35b698 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)); … … 82 82 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly 83 83 * Finally, the temporary graph is inserted into the given \a FragmentList for return. 84 * \param *out output stream for debugging 85 * \param *path path to file 84 * \param &path path to file 86 85 * \param *FragmentList empty, filled on return 87 86 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL) 88 87 */ 89 bool ParseKeySetFile( char *path, Graph *&FragmentList)88 bool ParseKeySetFile(std::string &path, Graph *&FragmentList) 90 89 { 91 90 bool status = true; … … 94 93 GraphTestPair testGraphInsert; 95 94 int NumberOfFragments = 0; 96 char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");95 string filename; 97 96 98 97 if (FragmentList == NULL) { // check list pointer … … 102 101 // 1st pass: open file and read 103 102 DoLog(1) && (Log() << Verbose(1) << "Parsing the KeySet file ... " << endl); 104 sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, KEYSETFILE);105 InputFile.open(filename );106 if (InputFile != NULL) {103 filename = path + KEYSETFILE; 104 InputFile.open(filename.c_str()); 105 if (InputFile.good()) { 107 106 // each line represents a new fragment 108 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");107 char buffer[MAXSTRINGSIZE]; 109 108 // 1. parse keysets and insert into temp. graph 110 109 while (!InputFile.eof()) { … … 122 121 InputFile.close(); 123 122 InputFile.clear(); 124 Free(&buffer); 125 DoLog(1) && (Log() << Verbose(1) << "done." << endl); 123 DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl); 126 124 } else { 127 DoLog(1) && (Log() << Verbose(1) << " File " << filename << " not found." << endl);125 DoLog(1) && (Log() << Verbose(1) << "\t ... File " << filename << " not found." << endl); 128 126 status = false; 129 127 } 130 128 131 Free(&filename);132 129 return status; 133 130 }; … … 148 145 int NumberOfFragments = 0; 149 146 double TEFactor; 150 char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseTEFactorsFile - filename");147 char filename[MAXSTRINGSIZE]; 151 148 152 149 if (FragmentList == NULL) { // check list pointer … … 179 176 } 180 177 181 // free memory182 Free(&filename);183 184 178 return status; 185 179 }; 186 180 187 181 /** Stores key sets to file. 188 * \param *out output stream for debugging189 182 * \param KeySetList Graph with Keysets 190 * \param *path path to file183 * \param &path path to file 191 184 * \return true - file written successfully, false - writing failed 192 185 */ 193 bool StoreKeySetFile(Graph &KeySetList, char *path) 194 { 195 ofstream output; 186 bool StoreKeySetFile(Graph &KeySetList, std::string &path) 187 { 196 188 bool status = true; 197 string line; 189 string line = path + KEYSETFILE; 190 ofstream output(line.c_str()); 198 191 199 192 // open KeySet file 200 line = path;201 line.append("/");202 line += FRAGMENTPREFIX;203 line += KEYSETFILE;204 output.open(line.c_str(), ios::out);205 193 DoLog(1) && (Log() << Verbose(1) << "Saving key sets of the total graph ... "); 206 if(output != NULL) {194 if(output.good()) { 207 195 for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) { 208 196 for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) { … … 307 295 308 296 /** Scans the adaptive order file and insert (index, value) into map. 309 * \param *out output stream for debugging 310 * \param *path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative) 297 * \param &path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative) 311 298 * \param &IndexedKeySetList list to find key set for a given index \a No 312 299 * \return adaptive criteria list from file 313 300 */ 314 map<int, pair<double,int> > * ScanAdaptiveFileIntoMap( char *path, map<int,KeySet> &IndexKeySetList)301 map<int, pair<double,int> > * ScanAdaptiveFileIntoMap(std::string &path, map<int,KeySet> &IndexKeySetList) 315 302 { 316 303 map<int, pair<double,int> > *AdaptiveCriteriaList = new map<int, pair<double,int> >; 317 304 int No = 0, FragOrder = 0; 318 305 double Value = 0.; 319 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer"); 320 sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT); 321 ifstream InputFile(buffer, ios::in); 306 char buffer[MAXSTRINGSIZE]; 307 string filename = path + ENERGYPERFRAGMENT; 308 ifstream InputFile(filename.c_str()); 309 310 if (InputFile.fail()) { 311 DoeLog(1) && (eLog() << Verbose(1) << "Cannot find file " << filename << "." << endl); 312 return AdaptiveCriteriaList; 313 } 322 314 323 315 if (CountLinesinFile(InputFile) > 0) { … … 345 337 InputFile.clear(); 346 338 } 347 Free(&buffer);348 339 349 340 return AdaptiveCriteriaList; … … 359 350 map<double, pair<int,int> > * ReMapAdaptiveCriteriaListToValue(map<int, pair<double,int> > *AdaptiveCriteriaList, molecule *mol) 360 351 { 361 atom *Walker = mol->start;352 atom *Walker = NULL; 362 353 map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ; 363 354 DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl); … … 391 382 bool MarkUpdateCandidates(bool *AtomMask, map<double, pair<int,int> > &FinalRootCandidates, int Order, molecule *mol) 392 383 { 393 atom *Walker = mol->start;384 atom *Walker = NULL; 394 385 int No = -1; 395 386 bool status = false; … … 425 416 426 417 /** Checks whether the OrderAtSite is still below \a Order at some site. 427 * \param *out output stream for debugging428 418 * \param *AtomMask defines true/false per global Atom::nr to mask in/out each nuclear site, used to activate given number of site to increment order adaptively 429 419 * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase 430 420 * \param Order desired Order if positive, desired exponent in threshold criteria if negative (0 is single-step) 431 421 * \param *MinimumRingSize array of max. possible order to avoid loops 432 * \param *path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)422 * \param path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative) 433 423 * \return true - needs further fragmentation, false - does not need fragmentation 434 424 */ 435 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path) 436 { 437 atom *Walker = start; 425 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path) 426 { 438 427 bool status = false; 439 428 440 429 // initialize mask list 441 for(int i= AtomCount;i--;)430 for(int i=getAtomCount();i--;) 442 431 AtomMask[i] = false; 443 432 444 433 if (Order < 0) { // adaptive increase of BondOrder per site 445 if (AtomMask[ AtomCount] == true) // break after one step434 if (AtomMask[getAtomCount()] == true) // break after one step 446 435 return false; 447 436 … … 457 446 if (AdaptiveCriteriaList->empty()) { 458 447 DoeLog(2) && (eLog()<< Verbose(2) << "Unable to parse file, incrementing all." << endl); 459 while (Walker->next != end) { 460 Walker = Walker->next; 448 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 461 449 #ifdef ADDHYDROGEN 462 if ( Walker->type->Z != 1) // skip hydrogen450 if ((*iter)->type->Z != 1) // skip hydrogen 463 451 #endif 464 452 { 465 AtomMask[ Walker->nr] = true; // include all (non-hydrogen) atoms453 AtomMask[(*iter)->nr] = true; // include all (non-hydrogen) atoms 466 454 status = true; 467 455 } … … 474 462 MarkUpdateCandidates(AtomMask, *FinalRootCandidates, Order, this); 475 463 476 Free(&IndexKeySetList);477 Free(&AdaptiveCriteriaList);478 Free(&FinalRootCandidates);464 delete[](IndexKeySetList); 465 delete[](AdaptiveCriteriaList); 466 delete[](FinalRootCandidates); 479 467 } else { // global increase of Bond Order 480 while (Walker->next != end) { 481 Walker = Walker->next; 468 for(molecule::const_iterator iter = begin(); iter != end(); ++iter) { 482 469 #ifdef ADDHYDROGEN 483 if ( Walker->type->Z != 1) // skip hydrogen470 if ((*iter)->type->Z != 1) // skip hydrogen 484 471 #endif 485 472 { 486 AtomMask[ Walker->nr] = true; // include all (non-hydrogen) atoms487 if ((Order != 0) && ( Walker->AdaptiveOrder < Order)) // && (Walker->AdaptiveOrder < MinimumRingSize[Walker->nr]))473 AtomMask[(*iter)->nr] = true; // include all (non-hydrogen) atoms 474 if ((Order != 0) && ((*iter)->AdaptiveOrder < Order)) // && ((*iter)->AdaptiveOrder < MinimumRingSize[(*iter)->nr])) 488 475 status = true; 489 476 } 490 477 } 491 if (( Order == 0) && (AtomMask[AtomCount] == false)) // single stepping, just check478 if ((!Order) && (!AtomMask[getAtomCount()])) // single stepping, just check 492 479 status = true; 493 480 … … 500 487 } 501 488 502 PrintAtomMask(AtomMask, AtomCount); // for debugging489 PrintAtomMask(AtomMask, getAtomCount()); // for debugging 503 490 504 491 return status; … … 516 503 return false; 517 504 } 518 SortIndex = Malloc<int>(AtomCount, "molecule::CreateMappingLabelsToConfigSequence: *SortIndex");519 for(int i= AtomCount;i--;)505 SortIndex = new int[getAtomCount()]; 506 for(int i=getAtomCount();i--;) 520 507 SortIndex[i] = -1; 521 508 … … 524 511 525 512 return true; 513 }; 514 515 516 517 /** Creates a lookup table for true father's Atom::Nr -> atom ptr. 518 * \param *start begin of list (STL iterator, i.e. first item) 519 * \paran *end end of list (STL iterator, i.e. one past last item) 520 * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start) 521 * \param count optional predetermined size for table (otherwise we set the count to highest true father id) 522 * \return true - success, false - failure 523 */ 524 bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count) 525 { 526 bool status = true; 527 int AtomNo; 528 529 if (LookupTable != NULL) { 530 Log() << Verbose(0) << "Pointer for Lookup table is not NULL! Aborting ..." <<endl; 531 return false; 532 } 533 534 // count them 535 if (count == 0) { 536 for (molecule::iterator iter = begin(); iter != end(); ++iter) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron 537 count = (count < (*iter)->GetTrueFather()->nr) ? (*iter)->GetTrueFather()->nr : count; 538 } 539 } 540 if (count <= 0) { 541 Log() << Verbose(0) << "Count of lookup list is 0 or less." << endl; 542 return false; 543 } 544 545 // allocate and fill 546 LookupTable = new atom *[count]; 547 if (LookupTable == NULL) { 548 eLog() << Verbose(0) << "LookupTable memory allocation failed!" << endl; 549 performCriticalExit(); 550 status = false; 551 } else { 552 for (int i=0;i<count;i++) 553 LookupTable[i] = NULL; 554 for (molecule::iterator iter = begin(); iter != end(); ++iter) { 555 AtomNo = (*iter)->GetTrueFather()->nr; 556 if ((AtomNo >= 0) && (AtomNo < count)) { 557 //*out << "Setting LookupTable[" << AtomNo << "] to " << *(*iter) << endl; 558 LookupTable[AtomNo] = (*iter); 559 } else { 560 Log() << Verbose(0) << "Walker " << *(*iter) << " exceeded range of nuclear ids [0, " << count << ")." << endl; 561 status = false; 562 break; 563 } 564 } 565 } 566 567 return status; 526 568 }; 527 569 … … 539 581 * of vertex indices: Global always means the index in "this" molecule, whereas local refers to the molecule or 540 582 * subgraph in the MoleculeListClass. 541 * \param *out output stream for debugging542 583 * \param Order up to how many neighbouring bonds a fragment contains in BondOrderScheme::BottumUp scheme 543 * \param *configuration configuration for writing config files for each fragment584 * \param &prefix path and prefix of the bond order configs to be written 544 585 * \return 1 - continue, 2 - stop (no fragmentation occured) 545 586 */ 546 int molecule::FragmentMolecule(int Order, config *configuration)587 int molecule::FragmentMolecule(int Order, std::string &prefix) 547 588 { 548 589 MoleculeListClass *BondFragments = NULL; 549 int *SortIndex = NULL; 550 int *MinimumRingSize = new int[AtomCount]; 590 int *MinimumRingSize = new int[getAtomCount()]; 551 591 int FragmentCounter; 552 592 MoleculeLeafClass *MolecularWalker = NULL; … … 576 616 577 617 // create lookup table for Atom::nr 578 FragmentationToDo = FragmentationToDo && CreateFatherLookupTable( start, end, ListOfAtoms, AtomCount);618 FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(ListOfAtoms, getAtomCount()); 579 619 580 620 // === compare it with adjacency file === 581 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule( configuration->configpath, ListOfAtoms);582 Free(&ListOfAtoms);621 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(prefix, ListOfAtoms); 622 delete[](ListOfAtoms); 583 623 584 624 // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===== … … 586 626 587 627 // analysis of the cycles (print rings, get minimum cycle length) for each subgraph 588 for(int i= AtomCount;i--;)589 MinimumRingSize[i] = AtomCount;628 for(int i=getAtomCount();i--;) 629 MinimumRingSize[i] = getAtomCount(); 590 630 MolecularWalker = Subgraphs; 591 631 FragmentCounter = 0; … … 598 638 // // check the list of local atoms for debugging 599 639 // Log() << Verbose(0) << "ListOfLocalAtoms for this subgraph is:" << endl; 600 // for (int i=0;i< AtomCount;i++)640 // for (int i=0;i<getAtomCount();i++) 601 641 // if (ListOfLocalAtoms[FragmentCounter][i] == NULL) 602 642 // Log() << Verbose(0) << "\tNULL"; … … 613 653 614 654 // ===== 3. if structure still valid, parse key set file and others ===== 615 FragmentationToDo = FragmentationToDo && ParseKeySetFile( configuration->configpath, ParsedFragmentList);655 FragmentationToDo = FragmentationToDo && ParseKeySetFile(prefix, ParsedFragmentList); 616 656 617 657 // ===== 4. check globally whether there's something to do actually (first adaptivity check) 618 FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile( configuration->configpath);658 FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(prefix); 619 659 620 660 // =================================== Begin of FRAGMENTATION =============================== … … 624 664 // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle 625 665 KeyStack *RootStack = new KeyStack[Subgraphs->next->Count()]; 626 AtomMask = new bool[ AtomCount+1];627 AtomMask[ AtomCount] = false;666 AtomMask = new bool[getAtomCount()+1]; 667 AtomMask[getAtomCount()] = false; 628 668 FragmentationToDo = false; // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards 629 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) {669 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, prefix))) { 630 670 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()671 AtomMask[getAtomCount()] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite() 632 672 // ===== 6b. fill RootStack for each subgraph (second adaptivity check) ===== 633 673 Subgraphs->next->FillRootStackForSubgraphs(RootStack, AtomMask, (FragmentCounter = 0)); … … 640 680 DoLog(1) && (Log() << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl); 641 681 //MolecularWalker->Leaf->OutputListOfBonds(out); // output atom::ListOfBonds for debugging 642 if (MolecularWalker->Leaf-> first->next != MolecularWalker->Leaf->last) {682 if (MolecularWalker->Leaf->hasBondStructure()) { 643 683 // call BOSSANOVA method 644 684 DoLog(0) && (Log() << Verbose(0) << endl << " ========== BOND ENERGY of subgraph " << FragmentCounter << " ========================= " << endl); … … 672 712 delete(Subgraphs); 673 713 } 674 Free(&FragmentList);714 delete[](FragmentList); 675 715 676 716 // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass ===== … … 682 722 KeySet test = (*runner).first; 683 723 DoLog(0) && (Log() << Verbose(0) << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl); 684 BondFragments->insert(StoreFragmentFromKeySet(test, configuration));724 BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig())); 685 725 k++; 686 726 } … … 690 730 if (BondFragments->ListOfMolecules.size() != 0) { 691 731 // create the SortIndex from BFS labels to order in the config file 732 int *SortIndex = NULL; 692 733 CreateMappingLabelsToConfigSequence(SortIndex); 693 734 694 735 DoLog(1) && (Log() << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl); 695 if (BondFragments->OutputConfigForListOfFragments( configuration, SortIndex))736 if (BondFragments->OutputConfigForListOfFragments(prefix, SortIndex)) 696 737 DoLog(1) && (Log() << Verbose(1) << "All configs written." << endl); 697 738 else … … 699 740 700 741 // store force index reference file 701 BondFragments->StoreForcesFile( configuration->configpath, SortIndex);742 BondFragments->StoreForcesFile(prefix, SortIndex); 702 743 703 744 // store keysets file 704 StoreKeySetFile(TotalGraph, configuration->configpath); 705 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); 745 StoreKeySetFile(TotalGraph, prefix); 746 747 { 748 // store Adjacency file 749 std::string filename = prefix + ADJACENCYFILE; 750 StoreAdjacencyToFile(filename); 751 } 712 752 713 753 // store Hydrogen saturation correction file 714 BondFragments->AddHydrogenCorrection( configuration->configpath);754 BondFragments->AddHydrogenCorrection(prefix); 715 755 716 756 // store adaptive orders into file 717 StoreOrderAtSiteFile( configuration->configpath);757 StoreOrderAtSiteFile(prefix); 718 758 719 759 // restore orbital and Stop values 720 CalculateOrbitals(*configuration);760 //CalculateOrbitals(*configuration); 721 761 722 762 // free memory for bond part 723 763 DoLog(1) && (Log() << Verbose(1) << "Freeing bond memory" << endl); 724 Free(&FragmentList); // remove bond molecule from memory 725 Free(&SortIndex); 764 delete[](SortIndex); 726 765 } else { 727 766 DoLog(1) && (Log() << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl); … … 736 775 /** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file. 737 776 * Atoms not present in the file get "-1". 738 * \param *out output stream for debugging 739 * \param *path path to file ORDERATSITEFILE 777 * \param &path path to file ORDERATSITEFILE 740 778 * \return true - file writable, false - not writable 741 779 */ 742 bool molecule::StoreOrderAtSiteFile( char *path)743 { 744 string streamline;780 bool molecule::StoreOrderAtSiteFile(std::string &path) 781 { 782 string line; 745 783 ofstream file; 746 784 747 line << path << "/" << FRAGMENTPREFIX <<ORDERATSITEFILE;748 file.open(line. str().c_str());785 line = path + ORDERATSITEFILE; 786 file.open(line.c_str()); 749 787 DoLog(1) && (Log() << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl); 750 if (file != NULL) {788 if (file.good()) { 751 789 ActOnAllAtoms( &atom::OutputOrder, &file ); 752 790 file.close(); … … 754 792 return true; 755 793 } else { 756 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line .str()<< "." << endl);794 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line << "." << endl); 757 795 return false; 758 796 } … … 761 799 /** Parses pairs(Atom::nr, Atom::AdaptiveOrder) from file and stores in molecule's Atom's. 762 800 * Atoms not present in the file get "0". 763 * \param *out output stream for debugging 764 * \param *path path to file ORDERATSITEFILEe 801 * \param &path path to file ORDERATSITEFILEe 765 802 * \return true - file found and scanned, false - file not found 766 803 * \sa ParseKeySetFile() and CheckAdjacencyFileAgainstMolecule() as this is meant to be used in conjunction with the two 767 804 */ 768 bool molecule::ParseOrderAtSiteFromFile( char *path)769 { 770 unsigned char *OrderArray = Calloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");771 bool *MaxArray = Calloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");805 bool molecule::ParseOrderAtSiteFromFile(std::string &path) 806 { 807 unsigned char *OrderArray = new unsigned char[getAtomCount()]; 808 bool *MaxArray = new bool[getAtomCount()]; 772 809 bool status; 773 810 int AtomNr, value; 774 string streamline;811 string line; 775 812 ifstream file; 776 813 814 for(int i=0;i<getAtomCount();i++) { 815 OrderArray[i] = 0; 816 MaxArray[i] = false; 817 } 818 777 819 DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl); 778 line << path << "/" << FRAGMENTPREFIX <<ORDERATSITEFILE;779 file.open(line. str().c_str());780 if (file != NULL) {820 line = path + ORDERATSITEFILE; 821 file.open(line.c_str()); 822 if (file.good()) { 781 823 while (!file.eof()) { // parse from file 782 824 AtomNr = -1; … … 796 838 SetAtomValueToIndexedArray( MaxArray, &atom::nr, &atom::MaxOrder ); 797 839 798 DoLog(1) && (Log() << Verbose(1) << " done." << endl);840 DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl); 799 841 status = true; 800 842 } else { 801 DoLog(1) && (Log() << Verbose(1) << " failed to open file " << line.str()<< "." << endl);843 DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line << "." << endl); 802 844 status = false; 803 845 } 804 Free(&OrderArray);805 Free(&MaxArray);846 delete[](OrderArray); 847 delete[](MaxArray); 806 848 807 849 DoLog(1) && (Log() << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl); … … 872 914 atom *OtherFather = NULL; 873 915 atom *FatherOfRunner = NULL; 874 Leaf->CountAtoms(); 875 876 atom *Runner = Leaf->start; 877 while (Runner->next != Leaf->end) { 878 Runner = Runner->next; 916 917 #ifdef ADDHYDROGEN 918 molecule::const_iterator runner; 919 #endif 920 // we increment the iter just before skipping the hydrogen 921 for (molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end();) { 879 922 LonelyFlag = true; 880 FatherOfRunner = Runner->father; 923 FatherOfRunner = (*iter)->father; 924 ASSERT(FatherOfRunner,"Atom without father found"); 881 925 if (SonList[FatherOfRunner->nr] != NULL) { // check if this, our father, is present in list 882 926 // create all bonds … … 889 933 // Log() << Verbose(3) << "Adding Bond: "; 890 934 // Log() << Verbose(0) << 891 Leaf->AddBond( Runner, SonList[OtherFather->nr], (*BondRunner)->BondDegree);935 Leaf->AddBond((*iter), SonList[OtherFather->nr], (*BondRunner)->BondDegree); 892 936 // Log() << Verbose(0) << "." << endl; 893 //NumBonds[ Runner->nr]++;937 //NumBonds[(*iter)->nr]++; 894 938 } else { 895 939 // Log() << Verbose(3) << "Not adding bond, labels in wrong order." << endl; … … 899 943 // Log() << Verbose(0) << ", who has no son in this fragment molecule." << endl; 900 944 #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))945 //Log() << Verbose(3) << "Adding Hydrogen to " << (*iter)->Name << " and a bond in between." << endl; 946 if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem)) 903 947 exit(1); 904 948 #endif 905 //NumBonds[ Runner->nr] += Binder->BondDegree;949 //NumBonds[(*iter)->nr] += Binder->BondDegree; 906 950 } 907 951 } 908 952 } 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 } 953 DoeLog(1) && (eLog()<< Verbose(1) << "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl); 954 } 955 if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) { 956 DoLog(0) && (Log() << Verbose(0) << **iter << "has got bonds only to hydrogens!" << endl); 957 } 958 ++iter; 914 959 #ifdef ADDHYDROGEN 915 while ((Runner->next != Leaf->end) && (Runner->next->type->Z == 1)) // skip added hydrogen 916 Runner = Runner->next; 960 while ((iter != Leaf->end()) && ((*iter)->type->Z == 1)){ // skip added hydrogen 961 iter++; 962 } 917 963 #endif 918 964 } … … 929 975 molecule * molecule::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem) 930 976 { 931 atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");977 atom **SonList = new atom*[getAtomCount()]; 932 978 molecule *Leaf = World::getInstance().createMolecule(); 979 980 for(int i=0;i<getAtomCount();i++) 981 SonList[i] = NULL; 933 982 934 983 // Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl; … … 939 988 940 989 //Leaflet->Leaf->ScanForPeriodicCorrection(out); 941 Free(&SonList);990 delete[](SonList); 942 991 // Log() << Verbose(1) << "End of StoreFragmentFromKeyset." << endl; 943 992 return Leaf; … … 1084 1133 int bits, TouchedIndex, SubSetDimension, SP, Added; 1085 1134 int SpaceLeft; 1086 int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList"); 1087 bond **BondsList = NULL; 1135 int *TouchedList = new int[SubOrder + 1]; 1088 1136 KeySetTestPair TestKeySetInsert; 1089 1137 … … 1124 1172 1125 1173 // then allocate and fill the list 1126 BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");1174 bond *BondsList[SubSetDimension]; 1127 1175 SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex); 1128 1176 … … 1130 1178 Log() << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl; 1131 1179 SPFragmentGenerator(FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits); 1132 1133 Free(&BondsList);1134 1180 } 1135 1181 } else { … … 1153 1199 } 1154 1200 } 1155 Free(&TouchedList);1201 delete[](TouchedList); 1156 1202 Log() << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl; 1157 1203 }; … … 1165 1211 void InitialiseSPList(int Order, struct UniqueFragments &FragmentSearch) 1166 1212 { 1167 FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList");1168 FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount");1213 FragmentSearch.BondsPerSPList = new bond* [Order * 2]; 1214 FragmentSearch.BondsPerSPCount = new int[Order]; 1169 1215 for (int i=Order;i--;) { 1170 1216 FragmentSearch.BondsPerSPList[2*i] = new bond(); // start node … … 1184 1230 void FreeSPList(int Order, struct UniqueFragments &FragmentSearch) 1185 1231 { 1186 Free(&FragmentSearch.BondsPerSPCount);1232 delete[](FragmentSearch.BondsPerSPCount); 1187 1233 for (int i=Order;i--;) { 1188 1234 delete(FragmentSearch.BondsPerSPList[2*i]); 1189 1235 delete(FragmentSearch.BondsPerSPList[2*i+1]); 1190 1236 } 1191 Free(&FragmentSearch.BondsPerSPList);1237 delete[](FragmentSearch.BondsPerSPList); 1192 1238 }; 1193 1239 … … 1370 1416 int molecule::PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet) 1371 1417 { 1372 bond **BondsList = NULL;1373 1418 int Counter = FragmentSearch.FragmentCounter; // mark current value of counter 1374 1419 … … 1394 1439 1395 1440 // prepare the subset and call the generator 1396 BondsList = Calloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList"); 1441 bond* BondsList[FragmentSearch.BondsPerSPCount[0]]; 1442 for(int i=0;i<FragmentSearch.BondsPerSPCount[0];i++) 1443 BondsList[i] = NULL; 1397 1444 BondsList[0] = FragmentSearch.BondsPerSPList[0]->next; // on SP level 0 there's only the root bond 1398 1445 1399 1446 SPFragmentGenerator(&FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order); 1400 1401 Free(&BondsList);1402 1447 } else { 1403 1448 DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl); … … 1507 1552 } 1508 1553 } 1509 Free(&FragmentLowerOrdersList[RootNr]);1554 delete[](FragmentLowerOrdersList[RootNr]); 1510 1555 RootNr++; 1511 1556 } 1512 Free(&FragmentLowerOrdersList);1557 delete[](FragmentLowerOrdersList); 1513 1558 }; 1514 1559 … … 1549 1594 // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5) 1550 1595 // 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"); 1596 NumMoleculesOfOrder = new int[UpgradeCount]; 1597 FragmentLowerOrdersList = new Graph**[UpgradeCount]; 1598 1599 for(int i=0;i<UpgradeCount;i++) { 1600 NumMoleculesOfOrder[i] = 0; 1601 FragmentLowerOrdersList[i] = NULL; 1602 } 1553 1603 1554 1604 // initialise the fragments structure … … 1556 1606 FragmentSearch.FragmentSet = new KeySet; 1557 1607 FragmentSearch.Root = FindAtom(RootKeyNr); 1558 FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");1559 for (int i= AtomCount;i--;) {1608 FragmentSearch.ShortestPathList = new int[getAtomCount()]; 1609 for (int i=getAtomCount();i--;) { 1560 1610 FragmentSearch.ShortestPathList[i] = -1; 1561 1611 } 1562 1612 1563 1613 // Construct the complete KeySet which we need for topmost level only (but for all Roots) 1564 atom *Walker = start;1565 1614 KeySet CompleteMolecule; 1566 while (Walker->next != end) { 1567 Walker = Walker->next; 1568 CompleteMolecule.insert(Walker->GetTrueFather()->nr); 1615 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 1616 CompleteMolecule.insert((*iter)->GetTrueFather()->nr); 1569 1617 } 1570 1618 … … 1577 1625 RootKeyNr = RootStack.front(); 1578 1626 RootStack.pop_front(); 1579 Walker = FindAtom(RootKeyNr);1627 atom *Walker = FindAtom(RootKeyNr); 1580 1628 // check cyclic lengths 1581 1629 //if ((MinimumRingSize[Walker->GetTrueFather()->nr] != -1) && (Walker->GetTrueFather()->AdaptiveOrder+1 > MinimumRingSize[Walker->GetTrueFather()->nr])) { … … 1592 1640 // allocate memory for all lower level orders in this 1D-array of ptrs 1593 1641 NumLevels = 1 << (Order-1); // (int)pow(2,Order); 1594 FragmentLowerOrdersList[RootNr] = Calloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]"); 1642 FragmentLowerOrdersList[RootNr] = new Graph*[NumLevels]; 1643 for (int i=0;i<NumLevels;i++) 1644 FragmentLowerOrdersList[RootNr][i] = NULL; 1595 1645 1596 1646 // create top order where nothing is reduced … … 1628 1678 1629 1679 // cleanup FragmentSearch structure 1630 Free(&FragmentSearch.ShortestPathList);1680 delete[](FragmentSearch.ShortestPathList); 1631 1681 delete(FragmentSearch.FragmentSet); 1632 1682 … … 1641 1691 CombineAllOrderListIntoOne(FragmentList, FragmentLowerOrdersList, RootStack, this); 1642 1692 FreeAllOrdersList(FragmentLowerOrdersList, RootStack, this); 1643 Free(&NumMoleculesOfOrder);1693 delete[](NumMoleculesOfOrder); 1644 1694 1645 1695 DoLog(0) && (Log() << Verbose(0) << "End of FragmentBOSSANOVA." << endl); … … 1664 1714 Vector Translationvector; 1665 1715 //class StackClass<atom *> *CompStack = NULL; 1666 class StackClass<atom *> *AtomStack = new StackClass<atom *>( AtomCount);1716 class StackClass<atom *> *AtomStack = new StackClass<atom *>(getAtomCount()); 1667 1717 bool flag = true; 1668 1718 1669 1719 DoLog(2) && (Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl); 1670 1720 1671 ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList"); 1721 ColorList = new enum Shading[getAtomCount()]; 1722 for (int i=0;i<getAtomCount();i++) 1723 ColorList[i] = (enum Shading)0; 1672 1724 while (flag) { 1673 1725 // remove bonds that are beyond bonddistance 1674 1726 Translationvector.Zero(); 1675 1727 // scan all bonds 1676 Binder = first;1677 1728 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; 1729 for(molecule::iterator AtomRunner = begin(); (!flag) && (AtomRunner != end()); ++AtomRunner) 1730 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); (!flag) && (BondRunner != (*AtomRunner)->ListOfBonds.end()); ++BondRunner) { 1731 Binder = (*BondRunner); 1732 for (int i=NDIM;i--;) { 1733 tmp = fabs(Binder->leftatom->x[i] - Binder->rightatom->x[i]); 1734 //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl; 1735 if (tmp > BondDistance) { 1736 OtherBinder = Binder->next; // note down binding partner for later re-insertion 1737 unlink(Binder); // unlink bond 1738 DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl); 1739 flag = true; 1740 break; 1741 } 1689 1742 } 1690 1743 } 1691 }1692 1744 if (flag) { 1693 1745 // create translation vector from their periodically modified distance … … 1701 1753 Log() << Verbose(0) << Translationvector << endl; 1702 1754 // apply to all atoms of first component via BFS 1703 for (int i= AtomCount;i--;)1755 for (int i=getAtomCount();i--;) 1704 1756 ColorList[i] = white; 1705 1757 AtomStack->Push(Binder->leftatom); … … 1727 1779 // free allocated space from ReturnFullMatrixforSymmetric() 1728 1780 delete(AtomStack); 1729 Free(&ColorList);1730 Free(&matrix);1781 delete[](ColorList); 1782 delete[](matrix); 1731 1783 DoLog(2) && (Log() << Verbose(2) << "End of ScanForPeriodicCorrection." << endl); 1732 1784 };
Note:
See TracChangeset
for help on using the changeset viewer.