source: src/Fragmentation/Graph.cpp@ d4d7a1

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 d4d7a1 was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 7.5 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 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * Graph.cpp
25 *
26 * Created on: Oct 20, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include <fstream>
38#include <iostream>
39#include <sstream>
40#include <string>
41
42#include "Graph.hpp"
43
44#include "CodePatterns/Log.hpp"
45
46#include "Fragmentation/AdaptivityMap.hpp"
47#include "Helpers/defs.hpp"
48#include "Helpers/helpers.hpp"
49
50/** Constructor for class Graph.
51 *
52 */
53Graph::Graph()
54{}
55
56/** Destructor for class Graph.
57 *
58 */
59Graph::~Graph()
60{}
61
62/** Inserts each KeySet in \a graph into \a this.
63 * \param graph1 graph whose KeySet are inserted into \this graph
64 * \param *counter keyset counter that gets increased
65 */
66void Graph::InsertGraph(Graph &graph, int *counter)
67{
68 GraphTestPair testGraphInsert;
69
70 for(Graph::iterator runner = graph.begin(); runner != graph.end(); runner++) {
71 testGraphInsert = insert(GraphPair ((*runner).first,pair<int,double>((*counter)++,((*runner).second).second))); // store fragment number and current factor
72 if (testGraphInsert.second) {
73 LOG(2, "INFO: KeySet " << (*counter)-1 << " successfully inserted.");
74 } else {
75 LOG(2, "INFO: KeySet " << (*counter)-1 << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first);
76 ((*(testGraphInsert.first)).second).second += (*runner).second.second;
77 LOG(2, "INFO: New factor is " << (*(testGraphInsert.first)).second.second << ".");
78 }
79 }
80};
81
82/** Parses the KeySet file and fills \a this from the known molecule structure.
83 * Does two-pass scanning:
84 * -# Scans the keyset file and initialises a temporary graph
85 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
86 * Finally, the temporary graph is inserted into the given \a FragmentList for return.
87 * \param &path path to file
88 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
89 */
90bool Graph::ParseKeySetFile(std::string &path)
91{
92 bool status = true;
93 std::ifstream InputFile;
94 std::stringstream line;
95 GraphTestPair testGraphInsert;
96 int NumberOfFragments = 0;
97 std::string filename;
98
99 // 1st pass: open file and read
100 LOG(1, "INFO: Parsing the KeySet file ... ");
101 filename = path + KEYSETFILE;
102 InputFile.open(filename.c_str());
103 if (InputFile.good()) {
104 // each line represents a new fragment
105 char buffer[MAXSTRINGSIZE];
106 // 1. parse keysets and insert into temp. graph
107 while (!InputFile.eof()) {
108 InputFile.getline(buffer, MAXSTRINGSIZE);
109 KeySet CurrentSet;
110 if ((strlen(buffer) > 0) && (CurrentSet.ScanBufferIntoKeySet(buffer))) { // if at least one valid atom was added, write config
111 testGraphInsert = insert(GraphPair (CurrentSet,pair<int,double>(NumberOfFragments++,1))); // store fragment number and current factor
112 if (!testGraphInsert.second) {
113 ELOG(0, "KeySet file must be corrupt as there are two equal key sets therein!");
114 performCriticalExit();
115 }
116 }
117 }
118 // 2. Free and done
119 InputFile.close();
120 InputFile.clear();
121 LOG(1, "INFO: ... done.");
122 } else {
123 ELOG(1, "File " << filename << " not found.");
124 status = false;
125 }
126
127 return status;
128};
129
130/** Stores key sets to file.
131 * \param &path path to file
132 * \return true - file written successfully, false - writing failed
133 */
134bool Graph::StoreKeySetFile(std::string &path)
135{
136 bool status = true;
137 std::string line = path + KEYSETFILE;
138 std::ofstream output(line.c_str());
139
140 // open KeySet file
141 LOG(1, "INFO: Saving key sets of the total graph ... ");
142 if(output.good()) {
143 for(Graph::iterator runner = begin(); runner != end(); runner++) {
144 for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
145 if (sprinter != (*runner).first.begin())
146 output << "\t";
147 output << *sprinter;
148 }
149 output << std::endl;
150 }
151 LOG(1, "INFO: done.");
152 } else {
153 ELOG(0, "Unable to open " << line << " for writing keysets!");
154 performCriticalExit();
155 status = false;
156 }
157 output.close();
158 output.clear();
159
160 return status;
161};
162
163/** Parses the TE factors file and fills \a *FragmentList from the known molecule structure.
164 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
165 * \param *path path to file
166 * \return true - parsing successfully, false - failure on parsing
167 */
168bool Graph::ParseTEFactorsFile(char *path)
169{
170 bool status = true;
171 std::ifstream InputFile;
172 std::stringstream line;
173 GraphTestPair testGraphInsert;
174 int NumberOfFragments = 0;
175 double TEFactor;
176 char filename[MAXSTRINGSIZE];
177
178 // 2nd pass: open TEFactors file and read
179 LOG(1, "INFO: Parsing the TEFactors file ... ");
180 sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, TEFACTORSFILE);
181 InputFile.open(filename);
182 if (InputFile != NULL) {
183 // 3. add found TEFactors to each keyset
184 NumberOfFragments = 0;
185 for(Graph::iterator runner = begin();runner != end(); runner++) {
186 if (!InputFile.eof()) {
187 InputFile >> TEFactor;
188 (*runner).second.second = TEFactor;
189 LOG(2, "INFO: Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << ".");
190 } else {
191 status = false;
192 break;
193 }
194 }
195 // 4. Free and done
196 InputFile.close();
197 LOG(1, "INFO: done.");
198 } else {
199 LOG(1, "INFO: File " << filename << " not found.");
200 status = false;
201 }
202
203 return status;
204};
205
206/** Stores TEFactors to file.
207 * \param *out output stream for debugging
208 * \param KeySetList Graph with factors
209 * \param *path path to file
210 * \return true - file written successfully, false - writing failed
211 */
212bool Graph::StoreTEFactorsFile(char *path)
213{
214 ofstream output;
215 bool status = true;
216 string line;
217
218 // open TEFactors file
219 line = path;
220 line.append("/");
221 line += FRAGMENTPREFIX;
222 line += TEFACTORSFILE;
223 output.open(line.c_str(), ios::out);
224 LOG(1, "INFO: Saving TEFactors of the total graph ... ");
225 if(output != NULL) {
226 for(Graph::iterator runner = begin(); runner != end(); runner++)
227 output << (*runner).second.second << endl;
228 LOG(1, "INFO: done." << endl);
229 } else {
230 ELOG(2, "INFO: failed to open " << line << "." << endl);
231 status = false;
232 }
233 output.close();
234
235 return status;
236};
237
238/** For a given graph, sorts KeySets into a (index, keyset) map.
239 * \return ref to allocated map from index to keyset
240 */
241AdaptivityMap * Graph::GraphToAdaptivityMap() const
242{
243 AdaptivityMap *IndexKeySetList = new AdaptivityMap;
244 for(const_iterator runner = begin(); runner != end(); runner++) {
245 IndexKeySetList->insert( pair<int,KeySet>(runner->second.first,runner->first) );
246 }
247 return IndexKeySetList;
248};
Note: See TracBrowser for help on using the repository browser.