- 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, 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)
- Location:
- src/Fragmentation
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Fragmentation.cpp
r42127c r75363b 83 83 bool CheckOrder = false; 84 84 Graph **FragmentList = NULL; 85 Graph *ParsedFragmentList = NULL;86 85 Graph TotalGraph; // graph with all keysets however local numbers 87 86 int TotalNumberOfKeySets = 0; … … 126 125 127 126 // ===== 3. if structure still valid, parse key set file and others ===== 128 FragmentationToDo = FragmentationToDo && ParseKeySetFile(prefix, ParsedFragmentList); 127 Graph ParsedFragmentList; 128 FragmentationToDo = FragmentationToDo && ParsedFragmentList.ParseKeySetFile(prefix); 129 129 130 130 // ===== 4. check globally whether there's something to do actually (first adaptivity check) … … 138 138 ListOfLocalAtoms[i] = NULL; 139 139 FragmentCounter = 0; 140 Subgraphs->next->AssignKeySetsToFragment(mol, ParsedFragmentList, ListOfLocalAtoms, FragmentList, FragmentCounter, true);140 Subgraphs->next->AssignKeySetsToFragment(mol, &ParsedFragmentList, ListOfLocalAtoms, FragmentList, FragmentCounter, true); 141 141 delete[](ListOfLocalAtoms); 142 142 … … 146 146 AtomMask[mol->getAtomCount()] = false; 147 147 FragmentationToDo = false; // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards 148 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, prefix))) {148 while ((CheckOrder = CheckOrderAtSite(AtomMask, &ParsedFragmentList, Order, prefix))) { 149 149 FragmentationToDo = FragmentationToDo || CheckOrder; 150 150 AtomMask[mol->getAtomCount()] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite() … … 171 171 delete[](RootStack); 172 172 delete[](AtomMask); 173 delete(ParsedFragmentList);174 173 175 174 // ==================================== End of FRAGMENTATION ============================================ … … 224 223 225 224 // store keysets file 226 StoreKeySetFile(TotalGraph,prefix);225 TotalGraph.StoreKeySetFile(prefix); 227 226 228 227 { … … 465 464 return false; 466 465 } 467 map<int,KeySet> *IndexKeySetList = G raphToIndexedKeySet(GlobalKeySetList);466 map<int,KeySet> *IndexKeySetList = GlobalKeySetList->GraphToIndexedKeySet(); 468 467 469 468 // parse the EnergyPerFragment file -
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 }; -
src/Fragmentation/Graph.hpp
r42127c r75363b 15 15 16 16 #include <map> 17 #include <string> 17 18 18 19 #include "Fragmentation/KeySet.hpp" … … 28 29 29 30 void InsertGraph(Graph &graph, int *counter); 31 32 bool ParseKeySetFile(std::string &path); 33 bool StoreKeySetFile(std::string &path); 34 bool ParseTEFactorsFile(char *path); 35 bool StoreTEFactorsFile(char *path); 36 37 std::map<int,KeySet> * GraphToIndexedKeySet() const; 30 38 }; 31 39 -
src/Fragmentation/KeySet.cpp
r42127c r75363b 18 18 19 19 #include "CodePatterns/MemDebug.hpp" 20 21 #include <sstream> 22 23 #include "CodePatterns/Log.hpp" 20 24 21 25 #include "KeySet.hpp" … … 66 70 return false; // if we reach this point, they are equal 67 71 } 72 73 /** Scans a single line for number and puts them into \a KeySet. 74 * \param *buffer buffer to scan 75 * \return true - at least one valid atom id parsed, false - CurrentSet is empty 76 */ 77 bool KeySet::ScanBufferIntoKeySet(char *buffer) 78 { 79 std::stringstream line; 80 int AtomNr; 81 int status = 0; 82 83 line.str(buffer); 84 while (!line.eof()) { 85 line >> AtomNr; 86 if (AtomNr >= 0) { 87 insert(AtomNr); // insert at end, hence in same order as in file! 88 status++; 89 } // else it's "-1" or else and thus must not be added 90 } 91 std::stringstream output; 92 for(KeySet::iterator runner = begin(); runner != end(); runner++) 93 output << (runner == begin() ? "" : " " ) << (*runner); 94 LOG(2, "INFO: The scanned KeySet is " << output.str()); 95 return (status != 0); 96 } -
src/Fragmentation/KeySet.hpp
r42127c r75363b 23 23 24 24 bool operator<(const KeySet &a) const; 25 26 bool ScanBufferIntoKeySet(char *buffer); 25 27 }; 26 28 -
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. -
src/Fragmentation/fragmentation_helpers.hpp
r42127c r75363b 27 27 class molecule; 28 28 29 bool ScanBufferIntoKeySet(char *buffer, KeySet &CurrentSet);30 bool ParseKeySetFile(std::string &path, Graph *&FragmentList);31 bool ParseTEFactorsFile(char *path, Graph *FragmentList);32 bool StoreKeySetFile(Graph &KeySetList, std::string &path);33 bool StoreTEFactorsFile(Graph &KeySetList, char *path);34 std::map<int,KeySet> * GraphToIndexedKeySet(Graph *GlobalKeySetList);35 29 void InsertIntoAdaptiveCriteriaList(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, std::map<int,KeySet> &IndexKeySetList, int FragOrder, int No, double Value); 36 30 int CountLinesinFile(std::ifstream &InputFile);
Note:
See TracChangeset
for help on using the changeset viewer.