Changes in src/molecule_fragmentation.cpp [112b09:c27778]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_fragmentation.cpp
r112b09 rc27778 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[MAXSTRINGSIZE];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 107 char buffer[MAXSTRINGSIZE]; … … 181 180 182 181 /** Stores key sets to file. 183 * \param *out output stream for debugging184 182 * \param KeySetList Graph with Keysets 185 * \param *path path to file183 * \param &path path to file 186 184 * \return true - file written successfully, false - writing failed 187 185 */ 188 bool StoreKeySetFile(Graph &KeySetList, char *path) 189 { 190 ofstream output; 186 bool StoreKeySetFile(Graph &KeySetList, std::string &path) 187 { 191 188 bool status = true; 192 string line; 189 string line = path + KEYSETFILE; 190 ofstream output(line.c_str()); 193 191 194 192 // open KeySet file 195 line = path;196 line.append("/");197 line += FRAGMENTPREFIX;198 line += KEYSETFILE;199 output.open(line.c_str(), ios::out);200 193 DoLog(1) && (Log() << Verbose(1) << "Saving key sets of the total graph ... "); 201 if(output != NULL) {194 if(output.good()) { 202 195 for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) { 203 196 for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) { … … 302 295 303 296 /** Scans the adaptive order file and insert (index, value) into map. 304 * \param *out output stream for debugging 305 * \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) 306 298 * \param &IndexedKeySetList list to find key set for a given index \a No 307 299 * \return adaptive criteria list from file 308 300 */ 309 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) 310 302 { 311 303 map<int, pair<double,int> > *AdaptiveCriteriaList = new map<int, pair<double,int> >; … … 313 305 double Value = 0.; 314 306 char buffer[MAXSTRINGSIZE]; 315 sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT); 316 ifstream InputFile(buffer, ios::in); 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 } 317 314 318 315 if (CountLinesinFile(InputFile) > 0) { … … 419 416 420 417 /** Checks whether the OrderAtSite is still below \a Order at some site. 421 * \param *out output stream for debugging422 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 423 419 * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase 424 420 * \param Order desired Order if positive, desired exponent in threshold criteria if negative (0 is single-step) 425 421 * \param *MinimumRingSize array of max. possible order to avoid loops 426 * \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) 427 423 * \return true - needs further fragmentation, false - does not need fragmentation 428 424 */ 429 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path)425 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path) 430 426 { 431 427 bool status = false; … … 585 581 * of vertex indices: Global always means the index in "this" molecule, whereas local refers to the molecule or 586 582 * subgraph in the MoleculeListClass. 587 * \param *out output stream for debugging588 583 * \param Order up to how many neighbouring bonds a fragment contains in BondOrderScheme::BottumUp scheme 589 * \param *configuration configuration for writing config files for each fragment584 * \param &prefix path and prefix of the bond order configs to be written 590 585 * \return 1 - continue, 2 - stop (no fragmentation occured) 591 586 */ 592 int molecule::FragmentMolecule(int Order, config *configuration)587 int molecule::FragmentMolecule(int Order, std::string &prefix) 593 588 { 594 589 MoleculeListClass *BondFragments = NULL; … … 624 619 625 620 // === compare it with adjacency file === 626 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule( configuration->configpath, ListOfAtoms);621 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(prefix, ListOfAtoms); 627 622 delete[](ListOfAtoms); 628 623 … … 634 629 MinimumRingSize[i] = getAtomCount(); 635 630 MolecularWalker = Subgraphs; 631 const int LeafCount = Subgraphs->next->Count(); 636 632 FragmentCounter = 0; 637 633 while (MolecularWalker->next != NULL) { 638 634 MolecularWalker = MolecularWalker->next; 639 635 // fill the bond structure of the individually stored subgraphs 640 MolecularWalker->FillBondStructureFromReference(this, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms 636 ListOfAtoms = NULL; 637 MolecularWalker->FillBondStructureFromReference(this, ListOfAtoms, false); // we want to keep the created ListOfLocalAtoms 641 638 DoLog(0) && (Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl); 642 639 LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount); … … 649 646 // Log() << Verbose(0) << "\t" << ListOfLocalAtoms[FragmentCounter][i]->Name; 650 647 DoLog(0) && (Log() << Verbose(0) << "Gathering local back edges for subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl); 651 MolecularWalker->Leaf->PickLocalBackEdges(ListOf LocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack);648 MolecularWalker->Leaf->PickLocalBackEdges(ListOfAtoms, BackEdgeStack, LocalBackEdgeStack); 652 649 DoLog(0) && (Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl); 653 650 MolecularWalker->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize); 654 651 DoLog(0) && (Log() << Verbose(0) << "Done with Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl); 655 652 delete(LocalBackEdgeStack); 653 delete(ListOfAtoms); 654 FragmentCounter++; 656 655 } 657 656 delete(BackEdgeStack); 658 657 659 658 // ===== 3. if structure still valid, parse key set file and others ===== 660 FragmentationToDo = FragmentationToDo && ParseKeySetFile( configuration->configpath, ParsedFragmentList);659 FragmentationToDo = FragmentationToDo && ParseKeySetFile(prefix, ParsedFragmentList); 661 660 662 661 // ===== 4. check globally whether there's something to do actually (first adaptivity check) 663 FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile( configuration->configpath);662 FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(prefix); 664 663 665 664 // =================================== Begin of FRAGMENTATION =============================== 666 665 // ===== 6a. assign each keyset to its respective subgraph ===== 667 Subgraphs->next->AssignKeySetsToFragment(this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), true); 666 ListOfLocalAtoms = new atom **[LeafCount]; 667 for (int i=0;i<LeafCount;i++) 668 ListOfLocalAtoms[i] = NULL; 669 FragmentCounter = 0; 670 Subgraphs->next->AssignKeySetsToFragment(this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, FragmentCounter, true); 671 delete[](ListOfLocalAtoms); 668 672 669 673 // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle … … 672 676 AtomMask[getAtomCount()] = false; 673 677 FragmentationToDo = false; // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards 674 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) {678 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, prefix))) { 675 679 FragmentationToDo = FragmentationToDo || CheckOrder; 676 680 AtomMask[getAtomCount()] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite() … … 701 705 delete[](MinimumRingSize); 702 706 703 704 707 // ==================================== End of FRAGMENTATION ============================================ 705 708 … … 727 730 KeySet test = (*runner).first; 728 731 DoLog(0) && (Log() << Verbose(0) << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl); 729 BondFragments->insert(StoreFragmentFromKeySet(test, configuration));732 BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig())); 730 733 k++; 731 734 } … … 739 742 740 743 DoLog(1) && (Log() << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl); 741 if (BondFragments->OutputConfigForListOfFragments( configuration, SortIndex))744 if (BondFragments->OutputConfigForListOfFragments(prefix, SortIndex)) 742 745 DoLog(1) && (Log() << Verbose(1) << "All configs written." << endl); 743 746 else … … 745 748 746 749 // store force index reference file 747 BondFragments->StoreForcesFile( configuration->configpath, SortIndex);750 BondFragments->StoreForcesFile(prefix, SortIndex); 748 751 749 752 // store keysets file 750 StoreKeySetFile(TotalGraph, configuration->configpath);753 StoreKeySetFile(TotalGraph, prefix); 751 754 752 755 { 753 756 // store Adjacency file 754 char filename[MAXSTRINGSIZE]; 755 strcpy(filename, FRAGMENTPREFIX); 756 strcat(filename, ADJACENCYFILE); 757 StoreAdjacencyToFile(configuration->configpath, filename); 757 std::string filename = prefix + ADJACENCYFILE; 758 StoreAdjacencyToFile(filename); 758 759 } 759 760 760 761 // store Hydrogen saturation correction file 761 BondFragments->AddHydrogenCorrection( configuration->configpath);762 BondFragments->AddHydrogenCorrection(prefix); 762 763 763 764 // store adaptive orders into file 764 StoreOrderAtSiteFile( configuration->configpath);765 StoreOrderAtSiteFile(prefix); 765 766 766 767 // restore orbital and Stop values 767 CalculateOrbitals(*configuration);768 //CalculateOrbitals(*configuration); 768 769 769 770 // free memory for bond part … … 782 783 /** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file. 783 784 * Atoms not present in the file get "-1". 784 * \param *out output stream for debugging 785 * \param *path path to file ORDERATSITEFILE 785 * \param &path path to file ORDERATSITEFILE 786 786 * \return true - file writable, false - not writable 787 787 */ 788 bool molecule::StoreOrderAtSiteFile( char *path)789 { 790 string streamline;788 bool molecule::StoreOrderAtSiteFile(std::string &path) 789 { 790 string line; 791 791 ofstream file; 792 792 793 line << path << "/" << FRAGMENTPREFIX <<ORDERATSITEFILE;794 file.open(line. str().c_str());793 line = path + ORDERATSITEFILE; 794 file.open(line.c_str()); 795 795 DoLog(1) && (Log() << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl); 796 if (file != NULL) {796 if (file.good()) { 797 797 ActOnAllAtoms( &atom::OutputOrder, &file ); 798 798 file.close(); … … 800 800 return true; 801 801 } else { 802 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line .str()<< "." << endl);802 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line << "." << endl); 803 803 return false; 804 804 } … … 807 807 /** Parses pairs(Atom::nr, Atom::AdaptiveOrder) from file and stores in molecule's Atom's. 808 808 * Atoms not present in the file get "0". 809 * \param *out output stream for debugging 810 * \param *path path to file ORDERATSITEFILEe 809 * \param &path path to file ORDERATSITEFILEe 811 810 * \return true - file found and scanned, false - file not found 812 811 * \sa ParseKeySetFile() and CheckAdjacencyFileAgainstMolecule() as this is meant to be used in conjunction with the two 813 812 */ 814 bool molecule::ParseOrderAtSiteFromFile( char *path)813 bool molecule::ParseOrderAtSiteFromFile(std::string &path) 815 814 { 816 815 unsigned char *OrderArray = new unsigned char[getAtomCount()]; … … 818 817 bool status; 819 818 int AtomNr, value; 820 string streamline;819 string line; 821 820 ifstream file; 822 821 … … 827 826 828 827 DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl); 829 line << path << "/" << FRAGMENTPREFIX <<ORDERATSITEFILE;830 file.open(line. str().c_str());831 if (file != NULL) {828 line = path + ORDERATSITEFILE; 829 file.open(line.c_str()); 830 if (file.good()) { 832 831 while (!file.eof()) { // parse from file 833 832 AtomNr = -1; … … 850 849 status = true; 851 850 } else { 852 DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line .str()<< "." << endl);851 DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line << "." << endl); 853 852 status = false; 854 853 }
Note:
See TracChangeset
for help on using the changeset viewer.