Changeset 75363b for src/Fragmentation/Graph.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/Graph.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Graph.cpp
r42127c r75363b 20 20 #include "CodePatterns/MemDebug.hpp" 21 21 22 #include <fstream> 23 #include <iostream> 24 #include <sstream> 25 #include <string> 26 22 27 #include "Graph.hpp" 23 28 24 29 #include "CodePatterns/Log.hpp" 30 31 #include "Helpers/defs.hpp" 32 #include "Helpers/helpers.hpp" 25 33 26 34 /** Constructor for class Graph. … … 56 64 }; 57 65 66 /** Parses the KeySet file and fills \a this from the known molecule structure. 67 * Does two-pass scanning: 68 * -# Scans the keyset file and initialises a temporary graph 69 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly 70 * Finally, the temporary graph is inserted into the given \a FragmentList for return. 71 * \param &path path to file 72 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL) 73 */ 74 bool Graph::ParseKeySetFile(std::string &path) 75 { 76 bool status = true; 77 std::ifstream InputFile; 78 std::stringstream line; 79 GraphTestPair testGraphInsert; 80 int NumberOfFragments = 0; 81 std::string filename; 82 83 // 1st pass: open file and read 84 LOG(1, "INFO: Parsing the KeySet file ... "); 85 filename = path + KEYSETFILE; 86 InputFile.open(filename.c_str()); 87 if (InputFile.good()) { 88 // each line represents a new fragment 89 char buffer[MAXSTRINGSIZE]; 90 // 1. parse keysets and insert into temp. graph 91 while (!InputFile.eof()) { 92 InputFile.getline(buffer, MAXSTRINGSIZE); 93 KeySet CurrentSet; 94 if ((strlen(buffer) > 0) && (CurrentSet.ScanBufferIntoKeySet(buffer))) { // if at least one valid atom was added, write config 95 testGraphInsert = insert(GraphPair (CurrentSet,pair<int,double>(NumberOfFragments++,1))); // store fragment number and current factor 96 if (!testGraphInsert.second) { 97 ELOG(0, "KeySet file must be corrupt as there are two equal key sets therein!"); 98 performCriticalExit(); 99 } 100 } 101 } 102 // 2. Free and done 103 InputFile.close(); 104 InputFile.clear(); 105 LOG(1, "INFO: ... done."); 106 } else { 107 ELOG(1, "File " << filename << " not found."); 108 status = false; 109 } 110 111 return status; 112 }; 113 114 /** Stores key sets to file. 115 * \param &path path to file 116 * \return true - file written successfully, false - writing failed 117 */ 118 bool Graph::StoreKeySetFile(std::string &path) 119 { 120 bool status = true; 121 std::string line = path + KEYSETFILE; 122 std::ofstream output(line.c_str()); 123 124 // open KeySet file 125 LOG(1, "INFO: Saving key sets of the total graph ... "); 126 if(output.good()) { 127 for(Graph::iterator runner = begin(); runner != end(); runner++) { 128 for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) { 129 if (sprinter != (*runner).first.begin()) 130 output << "\t"; 131 output << *sprinter; 132 } 133 output << std::endl; 134 } 135 LOG(1, "INFO: done."); 136 } else { 137 ELOG(0, "Unable to open " << line << " for writing keysets!"); 138 performCriticalExit(); 139 status = false; 140 } 141 output.close(); 142 output.clear(); 143 144 return status; 145 }; 146 147 /** Parses the TE factors file and fills \a *FragmentList from the known molecule structure. 148 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly 149 * \param *path path to file 150 * \return true - parsing successfully, false - failure on parsing 151 */ 152 bool Graph::ParseTEFactorsFile(char *path) 153 { 154 bool status = true; 155 std::ifstream InputFile; 156 std::stringstream line; 157 GraphTestPair testGraphInsert; 158 int NumberOfFragments = 0; 159 double TEFactor; 160 char filename[MAXSTRINGSIZE]; 161 162 // 2nd pass: open TEFactors file and read 163 LOG(1, "INFO: Parsing the TEFactors file ... "); 164 sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, TEFACTORSFILE); 165 InputFile.open(filename); 166 if (InputFile != NULL) { 167 // 3. add found TEFactors to each keyset 168 NumberOfFragments = 0; 169 for(Graph::iterator runner = begin();runner != end(); runner++) { 170 if (!InputFile.eof()) { 171 InputFile >> TEFactor; 172 (*runner).second.second = TEFactor; 173 LOG(2, "INFO: Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << "."); 174 } else { 175 status = false; 176 break; 177 } 178 } 179 // 4. Free and done 180 InputFile.close(); 181 LOG(1, "INFO: done."); 182 } else { 183 LOG(1, "INFO: File " << filename << " not found."); 184 status = false; 185 } 186 187 return status; 188 }; 189 190 /** Stores TEFactors to file. 191 * \param *out output stream for debugging 192 * \param KeySetList Graph with factors 193 * \param *path path to file 194 * \return true - file written successfully, false - writing failed 195 */ 196 bool Graph::StoreTEFactorsFile(char *path) 197 { 198 ofstream output; 199 bool status = true; 200 string line; 201 202 // open TEFactors file 203 line = path; 204 line.append("/"); 205 line += FRAGMENTPREFIX; 206 line += TEFACTORSFILE; 207 output.open(line.c_str(), ios::out); 208 LOG(1, "INFO: Saving TEFactors of the total graph ... "); 209 if(output != NULL) { 210 for(Graph::iterator runner = begin(); runner != end(); runner++) 211 output << (*runner).second.second << endl; 212 LOG(1, "INFO: done." << endl); 213 } else { 214 ELOG(2, "INFO: failed to open " << line << "." << endl); 215 status = false; 216 } 217 output.close(); 218 219 return status; 220 }; 221 222 /** For a given graph, sorts KeySets into a (index, keyset) map. 223 * \return ref to allocated map from index to keyset 224 */ 225 std::map<int,KeySet> * Graph::GraphToIndexedKeySet() const 226 { 227 map<int,KeySet> *IndexKeySetList = new map<int,KeySet>; 228 for(const_iterator runner = begin(); runner != end(); runner++) { 229 IndexKeySetList->insert( pair<int,KeySet>(runner->second.first,runner->first) ); 230 } 231 return IndexKeySetList; 232 };
Note:
See TracChangeset
for help on using the changeset viewer.
