source: src/Fragmentation/Graph.cpp@ 311137

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
Last change on this file since 311137 was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * Graph.cpp
10 *
11 * Created on: Oct 20, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <fstream>
23#include <iostream>
24#include <sstream>
25#include <string>
26
27#include "Graph.hpp"
28
29#include "CodePatterns/Log.hpp"
30
31#include "Fragmentation/AdaptivityMap.hpp"
32#include "Helpers/defs.hpp"
33#include "Helpers/helpers.hpp"
34
35/** Constructor for class Graph.
36 *
37 */
38Graph::Graph()
39{}
40
41/** Destructor for class Graph.
42 *
43 */
44Graph::~Graph()
45{}
46
47/** Inserts each KeySet in \a graph into \a this.
48 * \param graph1 graph whose KeySet are inserted into \this graph
49 * \param *counter keyset counter that gets increased
50 */
51void Graph::InsertGraph(Graph &graph, int *counter)
52{
53 GraphTestPair testGraphInsert;
54
55 for(Graph::iterator runner = graph.begin(); runner != graph.end(); runner++) {
56 testGraphInsert = insert(GraphPair ((*runner).first,pair<int,double>((*counter)++,((*runner).second).second))); // store fragment number and current factor
57 if (testGraphInsert.second) {
58 LOG(2, "INFO: KeySet " << (*counter)-1 << " successfully inserted.");
59 } else {
60 LOG(2, "INFO: KeySet " << (*counter)-1 << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first);
61 ((*(testGraphInsert.first)).second).second += (*runner).second.second;
62 LOG(2, "INFO: New factor is " << (*(testGraphInsert.first)).second.second << ".");
63 }
64 }
65};
66
67/** Parses the KeySet file and fills \a this from the known molecule structure.
68 * Does two-pass scanning:
69 * -# Scans the keyset file and initialises a temporary graph
70 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
71 * Finally, the temporary graph is inserted into the given \a FragmentList for return.
72 * \param &path path to file
73 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
74 */
75bool Graph::ParseKeySetFile(std::string &path)
76{
77 bool status = true;
78 std::ifstream InputFile;
79 std::stringstream line;
80 GraphTestPair testGraphInsert;
81 int NumberOfFragments = 0;
82 std::string filename;
83
84 // 1st pass: open file and read
85 LOG(1, "INFO: Parsing the KeySet file ... ");
86 filename = path + KEYSETFILE;
87 InputFile.open(filename.c_str());
88 if (InputFile.good()) {
89 // each line represents a new fragment
90 char buffer[MAXSTRINGSIZE];
91 // 1. parse keysets and insert into temp. graph
92 while (!InputFile.eof()) {
93 InputFile.getline(buffer, MAXSTRINGSIZE);
94 KeySet CurrentSet;
95 if ((strlen(buffer) > 0) && (CurrentSet.ScanBufferIntoKeySet(buffer))) { // if at least one valid atom was added, write config
96 testGraphInsert = insert(GraphPair (CurrentSet,pair<int,double>(NumberOfFragments++,1))); // store fragment number and current factor
97 if (!testGraphInsert.second) {
98 ELOG(0, "KeySet file must be corrupt as there are two equal key sets therein!");
99 performCriticalExit();
100 }
101 }
102 }
103 // 2. Free and done
104 InputFile.close();
105 InputFile.clear();
106 LOG(1, "INFO: ... done.");
107 } else {
108 ELOG(1, "File " << filename << " not found.");
109 status = false;
110 }
111
112 return status;
113};
114
115/** Stores key sets to file.
116 * \param &path path to file
117 * \return true - file written successfully, false - writing failed
118 */
119bool Graph::StoreKeySetFile(std::string &path)
120{
121 bool status = true;
122 std::string line = path + KEYSETFILE;
123 std::ofstream output(line.c_str());
124
125 // open KeySet file
126 LOG(1, "INFO: Saving key sets of the total graph ... ");
127 if(output.good()) {
128 for(Graph::iterator runner = begin(); runner != end(); runner++) {
129 for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
130 if (sprinter != (*runner).first.begin())
131 output << "\t";
132 output << *sprinter;
133 }
134 output << std::endl;
135 }
136 LOG(1, "INFO: done.");
137 } else {
138 ELOG(0, "Unable to open " << line << " for writing keysets!");
139 performCriticalExit();
140 status = false;
141 }
142 output.close();
143 output.clear();
144
145 return status;
146};
147
148/** Parses the TE factors file and fills \a *FragmentList from the known molecule structure.
149 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
150 * \param *path path to file
151 * \return true - parsing successfully, false - failure on parsing
152 */
153bool Graph::ParseTEFactorsFile(char *path)
154{
155 bool status = true;
156 std::ifstream InputFile;
157 std::stringstream line;
158 GraphTestPair testGraphInsert;
159 int NumberOfFragments = 0;
160 double TEFactor;
161 char filename[MAXSTRINGSIZE];
162
163 // 2nd pass: open TEFactors file and read
164 LOG(1, "INFO: Parsing the TEFactors file ... ");
165 sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, TEFACTORSFILE);
166 InputFile.open(filename);
167 if (InputFile != NULL) {
168 // 3. add found TEFactors to each keyset
169 NumberOfFragments = 0;
170 for(Graph::iterator runner = begin();runner != end(); runner++) {
171 if (!InputFile.eof()) {
172 InputFile >> TEFactor;
173 (*runner).second.second = TEFactor;
174 LOG(2, "INFO: Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << ".");
175 } else {
176 status = false;
177 break;
178 }
179 }
180 // 4. Free and done
181 InputFile.close();
182 LOG(1, "INFO: done.");
183 } else {
184 LOG(1, "INFO: File " << filename << " not found.");
185 status = false;
186 }
187
188 return status;
189};
190
191/** Stores TEFactors to file.
192 * \param *out output stream for debugging
193 * \param KeySetList Graph with factors
194 * \param *path path to file
195 * \return true - file written successfully, false - writing failed
196 */
197bool Graph::StoreTEFactorsFile(char *path)
198{
199 ofstream output;
200 bool status = true;
201 string line;
202
203 // open TEFactors file
204 line = path;
205 line.append("/");
206 line += FRAGMENTPREFIX;
207 line += TEFACTORSFILE;
208 output.open(line.c_str(), ios::out);
209 LOG(1, "INFO: Saving TEFactors of the total graph ... ");
210 if(output != NULL) {
211 for(Graph::iterator runner = begin(); runner != end(); runner++)
212 output << (*runner).second.second << endl;
213 LOG(1, "INFO: done." << endl);
214 } else {
215 ELOG(2, "INFO: failed to open " << line << "." << endl);
216 status = false;
217 }
218 output.close();
219
220 return status;
221};
222
223/** For a given graph, sorts KeySets into a (index, keyset) map.
224 * \return ref to allocated map from index to keyset
225 */
226AdaptivityMap * Graph::GraphToAdaptivityMap() const
227{
228 AdaptivityMap *IndexKeySetList = new AdaptivityMap;
229 for(const_iterator runner = begin(); runner != end(); runner++) {
230 IndexKeySetList->insert( pair<int,KeySet>(runner->second.first,runner->first) );
231 }
232 return IndexKeySetList;
233};
Note: See TracBrowser for help on using the repository browser.