Changeset 35b698 for src/molecule_fragmentation.cpp
- Timestamp:
- Jun 23, 2010, 3:52:50 PM (15 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- d0fbec
- Parents:
- dc0d21
- git-author:
- Frederik Heber <heber@…> (06/23/10 15:20:35)
- git-committer:
- Frederik Heber <heber@…> (06/23/10 15:52:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_fragmentation.cpp
rdc0d21 r35b698 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 … … 658 653 659 654 // ===== 3. if structure still valid, parse key set file and others ===== 660 FragmentationToDo = FragmentationToDo && ParseKeySetFile( configuration->configpath, ParsedFragmentList);655 FragmentationToDo = FragmentationToDo && ParseKeySetFile(prefix, ParsedFragmentList); 661 656 662 657 // ===== 4. check globally whether there's something to do actually (first adaptivity check) 663 FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile( configuration->configpath);658 FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(prefix); 664 659 665 660 // =================================== Begin of FRAGMENTATION =============================== … … 672 667 AtomMask[getAtomCount()] = false; 673 668 FragmentationToDo = false; // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards 674 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) {669 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, prefix))) { 675 670 FragmentationToDo = FragmentationToDo || CheckOrder; 676 671 AtomMask[getAtomCount()] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite() … … 727 722 KeySet test = (*runner).first; 728 723 DoLog(0) && (Log() << Verbose(0) << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl); 729 BondFragments->insert(StoreFragmentFromKeySet(test, configuration));724 BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig())); 730 725 k++; 731 726 } … … 739 734 740 735 DoLog(1) && (Log() << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl); 741 if (BondFragments->OutputConfigForListOfFragments( configuration, SortIndex))736 if (BondFragments->OutputConfigForListOfFragments(prefix, SortIndex)) 742 737 DoLog(1) && (Log() << Verbose(1) << "All configs written." << endl); 743 738 else … … 745 740 746 741 // store force index reference file 747 BondFragments->StoreForcesFile( configuration->configpath, SortIndex);742 BondFragments->StoreForcesFile(prefix, SortIndex); 748 743 749 744 // store keysets file 750 StoreKeySetFile(TotalGraph, configuration->configpath);745 StoreKeySetFile(TotalGraph, prefix); 751 746 752 747 { 753 748 // store Adjacency file 754 char filename[MAXSTRINGSIZE]; 755 strcpy(filename, FRAGMENTPREFIX); 756 strcat(filename, ADJACENCYFILE); 757 StoreAdjacencyToFile(configuration->configpath, filename); 749 std::string filename = prefix + ADJACENCYFILE; 750 StoreAdjacencyToFile(filename); 758 751 } 759 752 760 753 // store Hydrogen saturation correction file 761 BondFragments->AddHydrogenCorrection( configuration->configpath);754 BondFragments->AddHydrogenCorrection(prefix); 762 755 763 756 // store adaptive orders into file 764 StoreOrderAtSiteFile( configuration->configpath);757 StoreOrderAtSiteFile(prefix); 765 758 766 759 // restore orbital and Stop values 767 CalculateOrbitals(*configuration);760 //CalculateOrbitals(*configuration); 768 761 769 762 // free memory for bond part … … 782 775 /** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file. 783 776 * Atoms not present in the file get "-1". 784 * \param *out output stream for debugging 785 * \param *path path to file ORDERATSITEFILE 777 * \param &path path to file ORDERATSITEFILE 786 778 * \return true - file writable, false - not writable 787 779 */ 788 bool molecule::StoreOrderAtSiteFile( char *path)789 { 790 string streamline;780 bool molecule::StoreOrderAtSiteFile(std::string &path) 781 { 782 string line; 791 783 ofstream file; 792 784 793 line << path << "/" << FRAGMENTPREFIX <<ORDERATSITEFILE;794 file.open(line. str().c_str());785 line = path + ORDERATSITEFILE; 786 file.open(line.c_str()); 795 787 DoLog(1) && (Log() << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl); 796 if (file != NULL) {788 if (file.good()) { 797 789 ActOnAllAtoms( &atom::OutputOrder, &file ); 798 790 file.close(); … … 800 792 return true; 801 793 } else { 802 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line .str()<< "." << endl);794 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line << "." << endl); 803 795 return false; 804 796 } … … 807 799 /** Parses pairs(Atom::nr, Atom::AdaptiveOrder) from file and stores in molecule's Atom's. 808 800 * Atoms not present in the file get "0". 809 * \param *out output stream for debugging 810 * \param *path path to file ORDERATSITEFILEe 801 * \param &path path to file ORDERATSITEFILEe 811 802 * \return true - file found and scanned, false - file not found 812 803 * \sa ParseKeySetFile() and CheckAdjacencyFileAgainstMolecule() as this is meant to be used in conjunction with the two 813 804 */ 814 bool molecule::ParseOrderAtSiteFromFile( char *path)805 bool molecule::ParseOrderAtSiteFromFile(std::string &path) 815 806 { 816 807 unsigned char *OrderArray = new unsigned char[getAtomCount()]; … … 818 809 bool status; 819 810 int AtomNr, value; 820 string streamline;811 string line; 821 812 ifstream file; 822 813 … … 827 818 828 819 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) {820 line = path + ORDERATSITEFILE; 821 file.open(line.c_str()); 822 if (file.good()) { 832 823 while (!file.eof()) { // parse from file 833 824 AtomNr = -1; … … 850 841 status = true; 851 842 } else { 852 DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line .str()<< "." << endl);843 DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line << "." << endl); 853 844 status = false; 854 845 }
Note:
See TracChangeset
for help on using the changeset viewer.