Changes in src/molecule_fragmentation.cpp [35b698:112b09]
- File:
-
- 1 edited
-
src/molecule_fragmentation.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_fragmentation.cpp
r35b698 r112b09 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 &path path to file 84 * \param *out output stream for debugging 85 * \param *path path to file 85 86 * \param *FragmentList empty, filled on return 86 87 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL) 87 88 */ 88 bool ParseKeySetFile( std::string &path, Graph *&FragmentList)89 bool ParseKeySetFile(char *path, Graph *&FragmentList) 89 90 { 90 91 bool status = true; … … 93 94 GraphTestPair testGraphInsert; 94 95 int NumberOfFragments = 0; 95 string filename;96 char filename[MAXSTRINGSIZE]; 96 97 97 98 if (FragmentList == NULL) { // check list pointer … … 101 102 // 1st pass: open file and read 102 103 DoLog(1) && (Log() << Verbose(1) << "Parsing the KeySet file ... " << endl); 103 filename = path + KEYSETFILE;104 InputFile.open(filename .c_str());105 if (InputFile .good()) {104 sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, KEYSETFILE); 105 InputFile.open(filename); 106 if (InputFile != NULL) { 106 107 // each line represents a new fragment 107 108 char buffer[MAXSTRINGSIZE]; … … 180 181 181 182 /** Stores key sets to file. 183 * \param *out output stream for debugging 182 184 * \param KeySetList Graph with Keysets 183 * \param &path path to file185 * \param *path path to file 184 186 * \return true - file written successfully, false - writing failed 185 187 */ 186 bool StoreKeySetFile(Graph &KeySetList, std::string &path) 187 { 188 bool StoreKeySetFile(Graph &KeySetList, char *path) 189 { 190 ofstream output; 188 191 bool status = true; 189 string line = path + KEYSETFILE; 190 ofstream output(line.c_str()); 192 string line; 191 193 192 194 // open KeySet file 195 line = path; 196 line.append("/"); 197 line += FRAGMENTPREFIX; 198 line += KEYSETFILE; 199 output.open(line.c_str(), ios::out); 193 200 DoLog(1) && (Log() << Verbose(1) << "Saving key sets of the total graph ... "); 194 if(output .good()) {201 if(output != NULL) { 195 202 for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) { 196 203 for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) { … … 295 302 296 303 /** Scans the adaptive order file and insert (index, value) into map. 297 * \param &path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative) 304 * \param *out output stream for debugging 305 * \param *path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative) 298 306 * \param &IndexedKeySetList list to find key set for a given index \a No 299 307 * \return adaptive criteria list from file 300 308 */ 301 map<int, pair<double,int> > * ScanAdaptiveFileIntoMap( std::string &path, map<int,KeySet> &IndexKeySetList)309 map<int, pair<double,int> > * ScanAdaptiveFileIntoMap(char *path, map<int,KeySet> &IndexKeySetList) 302 310 { 303 311 map<int, pair<double,int> > *AdaptiveCriteriaList = new map<int, pair<double,int> >; … … 305 313 double Value = 0.; 306 314 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 } 315 sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT); 316 ifstream InputFile(buffer, ios::in); 314 317 315 318 if (CountLinesinFile(InputFile) > 0) { … … 416 419 417 420 /** Checks whether the OrderAtSite is still below \a Order at some site. 421 * \param *out output stream for debugging 418 422 * \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 419 423 * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase 420 424 * \param Order desired Order if positive, desired exponent in threshold criteria if negative (0 is single-step) 421 425 * \param *MinimumRingSize array of max. possible order to avoid loops 422 * \param path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)426 * \param *path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative) 423 427 * \return true - needs further fragmentation, false - does not need fragmentation 424 428 */ 425 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::stringpath)429 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path) 426 430 { 427 431 bool status = false; … … 581 585 * of vertex indices: Global always means the index in "this" molecule, whereas local refers to the molecule or 582 586 * subgraph in the MoleculeListClass. 587 * \param *out output stream for debugging 583 588 * \param Order up to how many neighbouring bonds a fragment contains in BondOrderScheme::BottumUp scheme 584 * \param &prefix path and prefix of the bond order configs to be written589 * \param *configuration configuration for writing config files for each fragment 585 590 * \return 1 - continue, 2 - stop (no fragmentation occured) 586 591 */ 587 int molecule::FragmentMolecule(int Order, std::string &prefix)592 int molecule::FragmentMolecule(int Order, config *configuration) 588 593 { 589 594 MoleculeListClass *BondFragments = NULL; … … 619 624 620 625 // === compare it with adjacency file === 621 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule( prefix, ListOfAtoms);626 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(configuration->configpath, ListOfAtoms); 622 627 delete[](ListOfAtoms); 623 628 … … 653 658 654 659 // ===== 3. if structure still valid, parse key set file and others ===== 655 FragmentationToDo = FragmentationToDo && ParseKeySetFile( prefix, ParsedFragmentList);660 FragmentationToDo = FragmentationToDo && ParseKeySetFile(configuration->configpath, ParsedFragmentList); 656 661 657 662 // ===== 4. check globally whether there's something to do actually (first adaptivity check) 658 FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile( prefix);663 FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(configuration->configpath); 659 664 660 665 // =================================== Begin of FRAGMENTATION =============================== … … 667 672 AtomMask[getAtomCount()] = false; 668 673 FragmentationToDo = false; // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards 669 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, prefix))) {674 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) { 670 675 FragmentationToDo = FragmentationToDo || CheckOrder; 671 676 AtomMask[getAtomCount()] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite() … … 722 727 KeySet test = (*runner).first; 723 728 DoLog(0) && (Log() << Verbose(0) << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl); 724 BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));729 BondFragments->insert(StoreFragmentFromKeySet(test, configuration)); 725 730 k++; 726 731 } … … 734 739 735 740 DoLog(1) && (Log() << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl); 736 if (BondFragments->OutputConfigForListOfFragments( prefix, SortIndex))741 if (BondFragments->OutputConfigForListOfFragments(configuration, SortIndex)) 737 742 DoLog(1) && (Log() << Verbose(1) << "All configs written." << endl); 738 743 else … … 740 745 741 746 // store force index reference file 742 BondFragments->StoreForcesFile( prefix, SortIndex);747 BondFragments->StoreForcesFile(configuration->configpath, SortIndex); 743 748 744 749 // store keysets file 745 StoreKeySetFile(TotalGraph, prefix);750 StoreKeySetFile(TotalGraph, configuration->configpath); 746 751 747 752 { 748 753 // store Adjacency file 749 std::string filename = prefix + ADJACENCYFILE; 750 StoreAdjacencyToFile(filename); 754 char filename[MAXSTRINGSIZE]; 755 strcpy(filename, FRAGMENTPREFIX); 756 strcat(filename, ADJACENCYFILE); 757 StoreAdjacencyToFile(configuration->configpath, filename); 751 758 } 752 759 753 760 // store Hydrogen saturation correction file 754 BondFragments->AddHydrogenCorrection( prefix);761 BondFragments->AddHydrogenCorrection(configuration->configpath); 755 762 756 763 // store adaptive orders into file 757 StoreOrderAtSiteFile( prefix);764 StoreOrderAtSiteFile(configuration->configpath); 758 765 759 766 // restore orbital and Stop values 760 //CalculateOrbitals(*configuration);767 CalculateOrbitals(*configuration); 761 768 762 769 // free memory for bond part … … 775 782 /** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file. 776 783 * Atoms not present in the file get "-1". 777 * \param &path path to file ORDERATSITEFILE 784 * \param *out output stream for debugging 785 * \param *path path to file ORDERATSITEFILE 778 786 * \return true - file writable, false - not writable 779 787 */ 780 bool molecule::StoreOrderAtSiteFile( std::string &path)781 { 782 string line;788 bool molecule::StoreOrderAtSiteFile(char *path) 789 { 790 stringstream line; 783 791 ofstream file; 784 792 785 line = path +ORDERATSITEFILE;786 file.open(line. c_str());793 line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE; 794 file.open(line.str().c_str()); 787 795 DoLog(1) && (Log() << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl); 788 if (file .good()) {796 if (file != NULL) { 789 797 ActOnAllAtoms( &atom::OutputOrder, &file ); 790 798 file.close(); … … 792 800 return true; 793 801 } else { 794 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line << "." << endl);802 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl); 795 803 return false; 796 804 } … … 799 807 /** Parses pairs(Atom::nr, Atom::AdaptiveOrder) from file and stores in molecule's Atom's. 800 808 * Atoms not present in the file get "0". 801 * \param &path path to file ORDERATSITEFILEe 809 * \param *out output stream for debugging 810 * \param *path path to file ORDERATSITEFILEe 802 811 * \return true - file found and scanned, false - file not found 803 812 * \sa ParseKeySetFile() and CheckAdjacencyFileAgainstMolecule() as this is meant to be used in conjunction with the two 804 813 */ 805 bool molecule::ParseOrderAtSiteFromFile( std::string &path)814 bool molecule::ParseOrderAtSiteFromFile(char *path) 806 815 { 807 816 unsigned char *OrderArray = new unsigned char[getAtomCount()]; … … 809 818 bool status; 810 819 int AtomNr, value; 811 string line;820 stringstream line; 812 821 ifstream file; 813 822 … … 818 827 819 828 DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl); 820 line = path +ORDERATSITEFILE;821 file.open(line. c_str());822 if (file .good()) {829 line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE; 830 file.open(line.str().c_str()); 831 if (file != NULL) { 823 832 while (!file.eof()) { // parse from file 824 833 AtomNr = -1; … … 841 850 status = true; 842 851 } else { 843 DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line << "." << endl);852 DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line.str() << "." << endl); 844 853 status = false; 845 854 }
Note:
See TracChangeset
for help on using the changeset viewer.
