Changeset 75363b for src/Fragmentation/fragmentation_helpers.cpp
- Timestamp:
- Oct 25, 2011, 12:08:03 PM (14 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, Candidate_v1.7.0, 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:
- 730d7a
- Parents:
- 42127c
- git-author:
- Frederik Heber <heber@…> (10/20/11 10:17:10)
- git-committer:
- Frederik Heber <heber@…> (10/25/11 12:08:03)
- File:
-
- 1 edited
-
src/Fragmentation/fragmentation_helpers.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/fragmentation_helpers.cpp
r42127c r75363b 36 36 37 37 using namespace std; 38 39 /** Scans a single line for number and puts them into \a KeySet.40 * \param *out output stream for debugging41 * \param *buffer buffer to scan42 * \param &CurrentSet filled KeySet on return43 * \return true - at least one valid atom id parsed, false - CurrentSet is empty44 */45 bool ScanBufferIntoKeySet(char *buffer, KeySet &CurrentSet)46 {47 stringstream line;48 int AtomNr;49 int status = 0;50 51 line.str(buffer);52 while (!line.eof()) {53 line >> AtomNr;54 if (AtomNr >= 0) {55 CurrentSet.insert(AtomNr); // insert at end, hence in same order as in file!56 status++;57 } // else it's "-1" or else and thus must not be added58 }59 DoLog(1) && (Log() << Verbose(1) << "The scanned KeySet is ");60 for(KeySet::iterator runner = CurrentSet.begin(); runner != CurrentSet.end(); runner++) {61 DoLog(0) && (Log() << Verbose(0) << (*runner) << "\t");62 }63 DoLog(0) && (Log() << Verbose(0) << endl);64 return (status != 0);65 };66 67 /** Parses the KeySet file and fills \a *FragmentList from the known molecule structure.68 * Does two-pass scanning:69 * -# Scans the keyset file and initialises a temporary graph70 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly71 * Finally, the temporary graph is inserted into the given \a FragmentList for return.72 * \param &path path to file73 * \param *FragmentList empty, filled on return74 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)75 */76 bool ParseKeySetFile(std::string &path, Graph *&FragmentList)77 {78 bool status = true;79 ifstream InputFile;80 stringstream line;81 GraphTestPair testGraphInsert;82 int NumberOfFragments = 0;83 string filename;84 85 if (FragmentList == NULL) { // check list pointer86 FragmentList = new Graph;87 }88 89 // 1st pass: open file and read90 DoLog(1) && (Log() << Verbose(1) << "Parsing the KeySet file ... " << endl);91 filename = path + KEYSETFILE;92 InputFile.open(filename.c_str());93 if (InputFile.good()) {94 // each line represents a new fragment95 char buffer[MAXSTRINGSIZE];96 // 1. parse keysets and insert into temp. graph97 while (!InputFile.eof()) {98 InputFile.getline(buffer, MAXSTRINGSIZE);99 KeySet CurrentSet;100 if ((strlen(buffer) > 0) && (ScanBufferIntoKeySet(buffer, CurrentSet))) { // if at least one valid atom was added, write config101 testGraphInsert = FragmentList->insert(GraphPair (CurrentSet,pair<int,double>(NumberOfFragments++,1))); // store fragment number and current factor102 if (!testGraphInsert.second) {103 DoeLog(0) && (eLog()<< Verbose(0) << "KeySet file must be corrupt as there are two equal key sets therein!" << endl);104 performCriticalExit();105 }106 }107 }108 // 2. Free and done109 InputFile.close();110 InputFile.clear();111 DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl);112 } else {113 DoLog(1) && (Log() << Verbose(1) << "\t ... File " << filename << " not found." << endl);114 status = false;115 }116 117 return status;118 };119 120 /** Parses the TE factors file and fills \a *FragmentList from the known molecule structure.121 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly122 * \param *out output stream for debugging123 * \param *path path to file124 * \param *FragmentList graph whose nodes's TE factors are set on return125 * \return true - parsing successfully, false - failure on parsing126 */127 bool ParseTEFactorsFile(char *path, Graph *FragmentList)128 {129 bool status = true;130 ifstream InputFile;131 stringstream line;132 GraphTestPair testGraphInsert;133 int NumberOfFragments = 0;134 double TEFactor;135 char filename[MAXSTRINGSIZE];136 137 if (FragmentList == NULL) { // check list pointer138 FragmentList = new Graph;139 }140 141 // 2nd pass: open TEFactors file and read142 DoLog(1) && (Log() << Verbose(1) << "Parsing the TEFactors file ... " << endl);143 sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, TEFACTORSFILE);144 InputFile.open(filename);145 if (InputFile != NULL) {146 // 3. add found TEFactors to each keyset147 NumberOfFragments = 0;148 for(Graph::iterator runner = FragmentList->begin();runner != FragmentList->end(); runner++) {149 if (!InputFile.eof()) {150 InputFile >> TEFactor;151 (*runner).second.second = TEFactor;152 DoLog(2) && (Log() << Verbose(2) << "Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << "." << endl);153 } else {154 status = false;155 break;156 }157 }158 // 4. Free and done159 InputFile.close();160 DoLog(1) && (Log() << Verbose(1) << "done." << endl);161 } else {162 DoLog(1) && (Log() << Verbose(1) << "File " << filename << " not found." << endl);163 status = false;164 }165 166 return status;167 };168 169 /** Stores key sets to file.170 * \param KeySetList Graph with Keysets171 * \param &path path to file172 * \return true - file written successfully, false - writing failed173 */174 bool StoreKeySetFile(Graph &KeySetList, std::string &path)175 {176 bool status = true;177 string line = path + KEYSETFILE;178 ofstream output(line.c_str());179 180 // open KeySet file181 DoLog(1) && (Log() << Verbose(1) << "Saving key sets of the total graph ... ");182 if(output.good()) {183 for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) {184 for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {185 if (sprinter != (*runner).first.begin())186 output << "\t";187 output << *sprinter;188 }189 output << endl;190 }191 DoLog(0) && (Log() << Verbose(0) << "done." << endl);192 } else {193 DoeLog(0) && (eLog()<< Verbose(0) << "Unable to open " << line << " for writing keysets!" << endl);194 performCriticalExit();195 status = false;196 }197 output.close();198 output.clear();199 200 return status;201 };202 203 204 /** Stores TEFactors to file.205 * \param *out output stream for debugging206 * \param KeySetList Graph with factors207 * \param *path path to file208 * \return true - file written successfully, false - writing failed209 */210 bool StoreTEFactorsFile(Graph &KeySetList, char *path)211 {212 ofstream output;213 bool status = true;214 string line;215 216 // open TEFactors file217 line = path;218 line.append("/");219 line += FRAGMENTPREFIX;220 line += TEFACTORSFILE;221 output.open(line.c_str(), ios::out);222 DoLog(1) && (Log() << Verbose(1) << "Saving TEFactors of the total graph ... ");223 if(output != NULL) {224 for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++)225 output << (*runner).second.second << endl;226 DoLog(1) && (Log() << Verbose(1) << "done." << endl);227 } else {228 DoLog(1) && (Log() << Verbose(1) << "failed to open " << line << "." << endl);229 status = false;230 }231 output.close();232 233 return status;234 };235 236 /** For a given graph, sorts KeySets into a (index, keyset) map.237 * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase238 * \return map from index to keyset239 */240 std::map<int,KeySet> * GraphToIndexedKeySet(Graph *GlobalKeySetList)241 {242 map<int,KeySet> *IndexKeySetList = new map<int,KeySet>;243 for(Graph::iterator runner = GlobalKeySetList->begin(); runner != GlobalKeySetList->end(); runner++) {244 IndexKeySetList->insert( pair<int,KeySet>(runner->second.first,runner->first) );245 }246 return IndexKeySetList;247 };248 38 249 39 /** Inserts a (\a No, \a value) pair into the list, overwriting present one.
Note:
See TracChangeset
for help on using the changeset viewer.
