source: src/datacreator.cpp@ 72d108

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 72d108 was ad011c, checked in by Frederik Heber <heber@…>, 14 years ago

CodePatterns places all includes now in subfolder CodePatterns/.

  • change all includes accordingly.
  • this was necessary as Helpers and Patterns are not very distinctive names for include folders. Already now, we had a conflict between Helpers from CodePatterns and Helpers from this project.
  • changed compilation test in ax_codepatterns.m4 when changing CodePatterns includes.
  • Property mode set to 100755
File size: 36.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/** \file datacreator.cpp
9 *
10 * Declarations of assisting functions in creating data and plot files.
11 *
12 */
13
14//============================ INCLUDES ===========================
15
16// include config.h
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include "CodePatterns/MemDebug.hpp"
22
23#include "datacreator.hpp"
24#include "Helpers/helpers.hpp"
25#include "parser.hpp"
26#include "CodePatterns/Verbose.hpp"
27
28#include <iomanip>
29
30//=========================== FUNCTIONS============================
31
32/** Opens a file with \a *filename in \a *dir.
33 * \param output file handle on return
34 * \param *dir directory
35 * \param *filename name of file
36 * \return true if file has been opened
37 */
38bool OpenOutputFile(ofstream &output, const char *dir, const char *filename)
39{
40 stringstream name;
41 name << dir << "/" << filename;
42 output.open(name.str().c_str(), ios::out);
43 if (output == NULL) {
44 DoLog(0) && (Log() << Verbose(0) << "Unable to open " << name.str() << " for writing, is directory correct?" << endl);
45 return false;
46 }
47 return true;
48};
49
50/** Opens a file for appending with \a *filename in \a *dir.
51 * \param output file handle on return
52 * \param *dir directory
53 * \param *filename name of file
54 * \return true if file has been opened
55 */
56bool AppendOutputFile(ofstream &output, const char *dir, const char *filename)
57{
58 stringstream name;
59 name << dir << "/" << filename;
60 output.open(name.str().c_str(), ios::app);
61 if (output == NULL) {
62 DoLog(0) && (Log() << Verbose(0) << "Unable to open " << name.str() << " for writing, is directory correct?" << endl);
63 return false;
64 }
65 return true;
66};
67
68/** Plots an energy vs. order.
69 * \param &Fragments EnergyMatrix class containing matrix values
70 * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
71 * \param *prefix prefix in filename (without ending)
72 * \param *msg message to be place in first line as a comment
73 * \return true if file was written successfully
74 */
75bool CreateDataEnergyOrder(class EnergyMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
76{
77 stringstream filename;
78 ofstream output;
79
80 filename << prefix << ".dat";
81 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
82 DoLog(0) && (Log() << Verbose(0) << msg << endl);
83 output << "# " << msg << ", created on " << datum;
84 output << "#Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
85 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
86 for(int i=KeySets.FragmentsPerOrder[BondOrder];i--;) {
87 for(int j=Fragments.RowCounter[ KeySets.OrderSet[BondOrder][i] ];j--;)
88 for(int k=Fragments.ColumnCounter[ KeySets.OrderSet[BondOrder][i] ];k--;)
89 Fragments.Matrix[Fragments.MatrixCounter][j][k] += Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][k];
90 }
91 output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
92 for (int l=0;l<Fragments.ColumnCounter[Fragments.MatrixCounter];l++)
93 output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l];
94 output << endl;
95 }
96 output.close();
97 return true;
98};
99
100/** Plots an energy error vs. order.
101 * \param &Energy EnergyMatrix class containing reference values (in MatrixCounter matrix)
102 * \param &Fragments EnergyMatrix class containing matrix values
103 * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
104 * \param *prefix prefix in filename (without ending)
105 * \param *msg message to be place in first line as a comment
106 * \return true if file was written successfully
107 */
108bool CreateDataDeltaEnergyOrder(class EnergyMatrix &Energy, class EnergyMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
109{
110 stringstream filename;
111 ofstream output;
112
113 filename << prefix << ".dat";
114 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
115 DoLog(0) && (Log() << Verbose(0) << msg << endl);
116 output << "# " << msg << ", created on " << datum;
117 output << "#Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
118 Fragments.SetLastMatrix(Energy.Matrix[Energy.MatrixCounter],0);
119 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
120 for(int i=KeySets.FragmentsPerOrder[BondOrder];i--;) {
121 for(int j=Fragments.RowCounter[ KeySets.OrderSet[BondOrder][i] ];j--;)
122 for(int k=Fragments.ColumnCounter[ KeySets.OrderSet[BondOrder][i] ];k--;)
123 Fragments.Matrix[Fragments.MatrixCounter][j][k] -= Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][k];
124 }
125 output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
126 for (int l=0;l<Fragments.ColumnCounter[Energy.MatrixCounter];l++)
127 if (fabs(Energy.Matrix[Energy.MatrixCounter][ Energy.RowCounter[Energy.MatrixCounter]-1 ][l]) < MYEPSILON)
128 output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l];
129 else
130 output << scientific << "\t" << (Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l] / Energy.Matrix[Energy.MatrixCounter][ Energy.RowCounter[Energy.MatrixCounter]-1 ][l]);
131 output << endl;
132 }
133 output.close();
134 return true;
135};
136
137/** Plot forces vs. order.
138 * \param &Fragments ForceMatrix class containing matrix values
139 * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
140 * \param *prefix prefix in filename (without ending)
141 * \param *msg message to be place in first line as a comment
142 * \param *datum current date and time
143 * \return true if file was written successfully
144 */
145bool CreateDataForcesOrder(class ForceMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix,const char *msg, const char *datum, void (*CreateForce)(class MatrixContainer &, int))
146{
147 stringstream filename;
148 ofstream output;
149
150 filename << prefix << ".dat";
151 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
152 DoLog(0) && (Log() << Verbose(0) << msg << endl);
153 output << "# " << msg << ", created on " << datum;
154 output << "# Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
155 Fragments.SetLastMatrix(0.,0);
156 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
157 Fragments.SumSubForces(Fragments, KeySets, BondOrder, 1.);
158 output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
159 CreateForce(Fragments, Fragments.MatrixCounter);
160 for (int l=0;l<Fragments.ColumnCounter[Fragments.MatrixCounter];l++)
161 output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter] ][l];
162 output << endl;
163 }
164 output.close();
165 return true;
166};
167
168/** Plot forces error vs. order.
169 * \param &Force ForceMatrix containing reference values (in MatrixCounter matrix)
170 * \param &Fragments ForceMatrix class containing matrix values
171 * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
172 * \param *prefix prefix in filename (without ending)
173 * \param *msg message to be place in first line as a comment
174 * \param *datum current date and time
175 * \return true if file was written successfully
176 */
177bool CreateDataDeltaForcesOrder(class ForceMatrix &Force, class ForceMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum, void (*CreateForce)(class MatrixContainer &, int))
178{
179 stringstream filename;
180 ofstream output;
181
182 filename << prefix << ".dat";
183 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
184 DoLog(0) && (Log() << Verbose(0) << msg << endl);
185 output << "# " << msg << ", created on " << datum;
186 output << "# Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
187 Fragments.SetLastMatrix(Force.Matrix[Force.MatrixCounter],0);
188 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
189 Fragments.SumSubForces(Fragments, KeySets, BondOrder, -1.);
190 output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
191 CreateForce(Fragments, Fragments.MatrixCounter);
192 for (int l=0;l<Fragments.ColumnCounter[Fragments.MatrixCounter];l++)
193 output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter] ][l];
194 output << endl;
195 }
196 output.close();
197 return true;
198};
199
200/** Plot forces error vs. vs atom vs. order.
201 * \param &Force ForceMatrix containing reference values (in MatrixCounter matrix)
202 * \param &Fragments ForceMatrix class containing matrix values
203 * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
204 * \param *prefix prefix in filename (without ending)
205 * \param *msg message to be place in first line as a comment
206 * \param *datum current date and time
207 * \return true if file was written successfully
208 */
209bool CreateDataDeltaForcesOrderPerAtom(class ForceMatrix &Force, class ForceMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
210{
211 stringstream filename;
212 ofstream output;
213 double norm = 0.;
214
215 filename << prefix << ".dat";
216 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
217 DoLog(0) && (Log() << Verbose(0) << msg << endl);
218 output << "# " << msg << ", created on " << datum;
219 output << "# AtomNo\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
220 Fragments.SetLastMatrix(Force.Matrix[Force.MatrixCounter], 0);
221 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
222 //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
223 Fragments.SumSubForces(Fragments, KeySets, BondOrder, -1.);
224 // errors per atom
225 output << endl << "#Order\t" << BondOrder+1 << endl;
226 for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
227 output << Fragments.Indices[Fragments.MatrixCounter][j] << "\t";
228 for (int l=0;l<Fragments.ColumnCounter[ Fragments.MatrixCounter ];l++) {
229 if (((l+1) % 3) == 0) {
230 norm = 0.;
231 for (int m=0;m<NDIM;m++)
232 norm += Force.Matrix[Force.MatrixCounter][ j ][l+m]*Force.Matrix[Force.MatrixCounter][ j ][l+m];
233 norm = sqrt(norm);
234 }
235// if (norm < MYEPSILON)
236 output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
237// else
238// output << scientific << (Fragments.Matrix[Fragments.MatrixCounter][ j ][l] / norm) << "\t";
239 }
240 output << endl;
241 }
242 output << endl;
243 }
244 output.close();
245 return true;
246};
247
248/** Plot forces error vs. vs atom vs. order.
249 * \param &Fragments ForceMatrix class containing matrix values
250 * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
251 * \param *prefix prefix in filename (without ending)
252 * \param *msg message to be place in first line as a comment
253 * \param *datum current date and time
254 * \return true if file was written successfully
255 */
256bool CreateDataForcesOrderPerAtom(class ForceMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
257{
258 stringstream filename;
259 ofstream output;
260
261 filename << prefix << ".dat";
262 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
263 DoLog(0) && (Log() << Verbose(0) << msg << endl);
264 output << "# " << msg << ", created on " << datum;
265 output << "# AtomNo\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
266 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
267 //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
268 Fragments.SumSubForces(Fragments, KeySets, BondOrder, 1.);
269 // errors per atom
270 output << endl << "#Order\t" << BondOrder+1 << endl;
271 for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
272 output << Fragments.Indices[Fragments.MatrixCounter][j] << "\t";
273 for (int l=0;l<Fragments.ColumnCounter[ Fragments.MatrixCounter ];l++)
274 output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
275 output << endl;
276 }
277 output << endl;
278 }
279 output.close();
280 return true;
281};
282
283
284/** Plot hessian error vs. vs atom vs. order.
285 * \param &Hessian HessianMatrix containing reference values (in MatrixCounter matrix)
286 * \param &Fragments HessianMatrix class containing matrix values
287 * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
288 * \param *prefix prefix in filename (without ending)
289 * \param *msg message to be place in first line as a comment
290 * \param *datum current date and time
291 * \return true if file was written successfully
292 */
293bool CreateDataDeltaHessianOrderPerAtom(class HessianMatrix &Hessian, class HessianMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
294{
295 stringstream filename;
296 ofstream output;
297
298 filename << prefix << ".dat";
299 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
300 DoLog(0) && (Log() << Verbose(0) << msg << endl);
301 output << "# " << msg << ", created on " << datum;
302 output << "# AtomNo\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
303 Fragments.SetLastMatrix(Hessian.Matrix[Hessian.MatrixCounter], 0);
304 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
305 //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
306 Fragments.SumSubHessians(Fragments, KeySets, BondOrder, -1.);
307 // errors per atom
308 output << endl << "#Order\t" << BondOrder+1 << endl;
309 for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
310 output << Fragments.Indices[Fragments.MatrixCounter][j] << "\t";
311 for (int l=0;l<Fragments.ColumnCounter[ Fragments.MatrixCounter ];l++) {
312 output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
313 }
314 output << endl;
315 }
316 output << endl;
317 }
318 output.close();
319 return true;
320};
321
322/** Plot hessian error vs. vs atom vs. order in the frobenius norm.
323 * \param &Hessian HessianMatrix containing reference values (in MatrixCounter matrix)
324 * \param &Fragments HessianMatrix class containing matrix values
325 * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
326 * \param *prefix prefix in filename (without ending)
327 * \param *msg message to be place in first line as a comment
328 * \param *datum current date and time
329 * \return true if file was written successfully
330 */
331bool CreateDataDeltaFrobeniusOrderPerAtom(class HessianMatrix &Hessian, class HessianMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
332{
333 stringstream filename;
334 ofstream output;
335 double norm = 0;
336 double tmp;
337
338 filename << prefix << ".dat";
339 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
340 DoLog(0) && (Log() << Verbose(0) << msg << endl);
341 output << "# " << msg << ", created on " << datum;
342 output << "# AtomNo\t";
343 Fragments.SetLastMatrix(Hessian.Matrix[Hessian.MatrixCounter], 0);
344 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
345 output << "Order" << BondOrder+1 << "\t";
346 }
347 output << endl;
348 output << Fragments.RowCounter[ Fragments.MatrixCounter ] << "\t";
349 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
350 //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
351 Fragments.SumSubHessians(Fragments, KeySets, BondOrder, -1.);
352 // frobenius norm of errors per atom
353 norm = 0.;
354 for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
355 for (int l=0;l<Fragments.ColumnCounter[ Fragments.MatrixCounter ];l++) {
356 tmp = Fragments.Matrix[Fragments.MatrixCounter][ j ][l];
357 norm += tmp*tmp;
358 }
359 }
360 output << scientific << sqrt(norm)/(Fragments.RowCounter[ Fragments.MatrixCounter ]*Fragments.ColumnCounter[ Fragments.MatrixCounter] ) << "\t";
361 }
362 output << endl;
363 output.close();
364 return true;
365};
366
367/** Plot hessian error vs. vs atom vs. order.
368 * \param &Fragments HessianMatrix class containing matrix values
369 * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
370 * \param *prefix prefix in filename (without ending)
371 * \param *msg message to be place in first line as a comment
372 * \param *datum current date and time
373 * \return true if file was written successfully
374 */
375bool CreateDataHessianOrderPerAtom(class HessianMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
376{
377 stringstream filename;
378 ofstream output;
379
380 filename << prefix << ".dat";
381 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
382 DoLog(0) && (Log() << Verbose(0) << msg << endl);
383 output << "# " << msg << ", created on " << datum;
384 output << "# AtomNo\t" << Fragments.Header[ Fragments.MatrixCounter ] << endl;
385 Fragments.SetLastMatrix(0., 0);
386 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
387 //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
388 Fragments.SumSubHessians(Fragments, KeySets, BondOrder, 1.);
389 // errors per atom
390 output << endl << "#Order\t" << BondOrder+1 << endl;
391 for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
392 output << Fragments.Indices[Fragments.MatrixCounter][j] << "\t";
393 for (int l=0;l<Fragments.ColumnCounter[ Fragments.MatrixCounter ];l++)
394 output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
395 output << endl;
396 }
397 output << endl;
398 }
399 output.close();
400 return true;
401};
402
403/** Plot matrix vs. fragment.
404 */
405bool CreateDataFragment(class MatrixContainer &Fragment, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum, void (*CreateFragment)(class MatrixContainer &, int))
406{
407 stringstream filename;
408 ofstream output;
409
410 filename << prefix << ".dat";
411 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
412 DoLog(0) && (Log() << Verbose(0) << msg << endl);
413 output << "# " << msg << ", created on " << datum << endl;
414 output << "#Order\tFrag.No.\t" << Fragment.Header[ Fragment.MatrixCounter ] << endl;
415 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
416 for(int i=0;i<KeySets.FragmentsPerOrder[BondOrder];i++) {
417 output << BondOrder+1 << "\t" << KeySets.OrderSet[BondOrder][i]+1;
418 CreateFragment(Fragment, KeySets.OrderSet[BondOrder][i]);
419 for (int l=0;l<Fragment.ColumnCounter[ KeySets.OrderSet[BondOrder][i] ];l++)
420 output << scientific << "\t" << Fragment.Matrix[ KeySets.OrderSet[BondOrder][i] ][ Fragment.RowCounter[ KeySets.OrderSet[BondOrder][i] ] ][l];
421 output << endl;
422 }
423 }
424 output.close();
425 return true;
426};
427
428/** Copies fragment energy values into last matrix of \a Matrix with greatest total energy.
429 * \param &Matrix MatrixContainer with all fragment energy values
430 * \param &KeySets KeySetsContainer with associations of each fragment to a bond order
431 * \param BondOrder current bond order
432 */
433void CreateMaxFragmentOrder(class MatrixContainer &Fragments, class KeySetsContainer &KeySets, int BondOrder)
434{
435 for(int j=Fragments.RowCounter[ Fragments.MatrixCounter ];j--;) {
436 for(int i=KeySets.FragmentsPerOrder[BondOrder];i--;) {
437 if (fabs(Fragments.Matrix[ Fragments.MatrixCounter ][j][1]) < fabs(Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][1])) {
438 for (int k=Fragments.ColumnCounter[ Fragments.MatrixCounter ];k--;)
439 Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][k];
440 }
441 }
442 }
443};
444
445/** Copies fragment energy values into last matrix of \a Matrix with smallest total energy.
446 * \param &Matrix MatrixContainer with all fragment energy values
447 * \param &KeySets KeySetsContainer with associations of each fragment to a bond order
448 * \param BondOrder current bond order
449 */
450void CreateMinFragmentOrder(class MatrixContainer &Fragments, class KeySetsContainer &KeySets, int BondOrder)
451{
452 for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
453 int i=0;
454 do { // first get a minimum value unequal to 0
455 for (int k=Fragments.ColumnCounter[ Fragments.MatrixCounter ];k--;)
456 Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][k];
457 i++;
458 } while ((fabs(Fragments.Matrix[ Fragments.MatrixCounter ][j][1]) < MYEPSILON) && (i<KeySets.FragmentsPerOrder[BondOrder]));
459 for(;i<KeySets.FragmentsPerOrder[BondOrder];i++) { // then find lowest
460 if (fabs(Fragments.Matrix[ Fragments.MatrixCounter ][j][1]) > fabs(Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][1])) {
461 for (int k=Fragments.ColumnCounter[ Fragments.MatrixCounter ];k--;)
462 Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][k];
463 }
464 }
465 }
466};
467
468/** Plot matrix vs. fragment.
469 */
470bool CreateDataFragmentOrder(class MatrixContainer &Fragment, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum, void (*CreateFragmentOrder)(class MatrixContainer &, class KeySetsContainer &, int))
471{
472 stringstream filename;
473 ofstream output;
474
475 filename << prefix << ".dat";
476 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
477 DoLog(0) && (Log() << Verbose(0) << msg << endl);
478 output << "# " << msg << ", created on " << datum;
479 output << "#Order\tFrag.No.\t" << Fragment.Header[ Fragment.MatrixCounter ] << endl;
480 // max
481 for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
482 Fragment.SetLastMatrix(0.,0);
483 CreateFragmentOrder(Fragment, KeySets, BondOrder);
484 output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
485 for (int l=0;l<Fragment.ColumnCounter[ Fragment.MatrixCounter ];l++)
486 output << scientific << "\t" << Fragment.Matrix[ Fragment.MatrixCounter ][ Fragment.RowCounter[ Fragment.MatrixCounter ]-1 ][l];
487 output << endl;
488 }
489 output.close();
490 return true;
491};
492
493/** Takes last but one row and copies into final row.
494 * \param Energy MatrixContainer with matrix values
495 * \param MatrixNumber the index for the ForceMatrix::matrix array
496 */
497void CreateEnergy(class MatrixContainer &Energy, int MatrixNumber)
498{
499 for(int k=0;k<Energy.ColumnCounter[MatrixNumber];k++)
500 Energy.Matrix[MatrixNumber][ Energy.RowCounter[MatrixNumber] ] [k] = Energy.Matrix[MatrixNumber][ Energy.RowCounter[MatrixNumber]-1 ] [k];
501};
502
503/** Scans forces for the minimum in magnitude.
504 * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force.
505 * \param Force ForceMatrix class containing matrix values
506 * \param MatrixNumber the index for the ForceMatrix::matrix array
507 */
508void CreateMinimumForce(class MatrixContainer &Force, int MatrixNumber)
509{
510 for (int l=Force.ColumnCounter[MatrixNumber];l--;)
511 Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
512 for (int l=5;l<Force.ColumnCounter[MatrixNumber];l+=3) {
513 double stored = 0;
514 int k=0;
515 do {
516 for (int m=NDIM;m--;) {
517 stored += Force.Matrix[MatrixNumber][ k ][l+m]
518 * Force.Matrix[MatrixNumber][ k ][l+m];
519 Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m] = Force.Matrix[MatrixNumber][ k ][l+m];
520 }
521 k++;
522 } while ((fabs(stored) < MYEPSILON) && (k<Force.RowCounter[MatrixNumber]));
523 for (;k<Force.RowCounter[MatrixNumber];k++) {
524 double tmp = 0;
525 for (int m=NDIM;m--;)
526 tmp += Force.Matrix[MatrixNumber][ k ][l+m]
527 * Force.Matrix[MatrixNumber][ k ][l+m];
528 if ((fabs(tmp) > MYEPSILON) && (tmp < stored)) { // current force is greater than stored
529 for (int m=NDIM;m--;)
530 Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m] = Force.Matrix[MatrixNumber][ k ][l+m];
531 stored = tmp;
532 }
533 }
534 }
535};
536
537/** Scans forces for the mean in magnitude.
538 * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force.
539 * \param Force ForceMatrix class containing matrix values
540 * \param MatrixNumber the index for the ForceMatrix::matrix array
541 */
542void CreateMeanForce(class MatrixContainer &Force, int MatrixNumber)
543{
544 int divisor = 0;
545 for (int l=Force.ColumnCounter[MatrixNumber];l--;)
546 Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
547 for (int l=5;l<Force.ColumnCounter[MatrixNumber];l+=3) {
548 double tmp = 0;
549 for (int k=Force.RowCounter[MatrixNumber];k--;) {
550 double norm = 0.;
551 for (int m=NDIM;m--;)
552 norm += Force.Matrix[MatrixNumber][ k ][l+m]
553 * Force.Matrix[MatrixNumber][ k ][l+m];
554 tmp += sqrt(norm);
555 if (fabs(norm) > MYEPSILON) divisor++;
556 }
557 tmp /= (double)divisor;
558 Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = tmp;
559 }
560};
561
562/** Scans forces for the maximum in magnitude.
563 * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force.
564 * \param Force ForceMatrix class containing matrix values
565 * \param MatrixNumber the index for the ForceMatrix::matrix array
566 */
567void CreateMaximumForce(class MatrixContainer &Force, int MatrixNumber)
568{
569 for (int l=5;l<Force.ColumnCounter[MatrixNumber];l+=3) {
570 double stored = 0;
571 for (int k=Force.RowCounter[MatrixNumber];k--;) {
572 double tmp = 0;
573 for (int m=NDIM;m--;)
574 tmp += Force.Matrix[MatrixNumber][ k ][l+m]
575 * Force.Matrix[MatrixNumber][ k ][l+m];
576 if (tmp > stored) { // current force is greater than stored
577 for (int m=NDIM;m--;)
578 Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m] = Force.Matrix[MatrixNumber][ k ][l+m];
579 stored = tmp;
580 }
581 }
582 }
583};
584
585/** Leaves the Force.Matrix as it is.
586 * \param Force ForceMatrix class containing matrix values
587 * \param MatrixNumber the index for the ForceMatrix::matrix array
588*/
589void CreateSameForce(class MatrixContainer &Force, int MatrixNumber)
590{
591 // does nothing
592};
593
594/** Adds vectorwise all forces.
595 * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force.
596 * \param Force ForceMatrix class containing matrix values
597 * \param MatrixNumber the index for the ForceMatrix::matrix array
598 */
599void CreateVectorSumForce(class MatrixContainer &Force, int MatrixNumber)
600{
601 for (int l=Force.ColumnCounter[MatrixNumber];l--;)
602 Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
603 for (int l=0;l<Force.ColumnCounter[MatrixNumber];l++) {
604 for (int k=Force.RowCounter[MatrixNumber];k--;)
605 Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] += Force.Matrix[MatrixNumber][k][l];
606 }
607};
608
609/** Writes the standard pyxplot header info.
610 * \param keycolumns number of columns of the key
611 * \param *key position of key
612 * \param *logscale axis for logscale
613 * \param *extraline extra set lines if desired
614 * \param mxtics small tics at ...
615 * \param xtics large tics at ...
616 * \param *xlabel label for x axis
617 * \param *ylabel label for y axis
618 */
619void CreatePlotHeader(ofstream &output, const char *prefix, const int keycolumns, const char *key, const char *logscale, const char *extraline, const int mxtics, const int xtics, const char *xlabel, const char *ylabel)
620{
621 //output << "#!/home/heber/build/pyxplot/pyxplot" << endl << endl;
622 output << "reset" << endl;
623 output << "set keycolumns "<< keycolumns << endl;
624 output << "set key " << key << endl;
625 output << "set mxtics "<< mxtics << endl;
626 output << "set xtics "<< xtics << endl;
627 if (logscale != NULL)
628 output << "set logscale " << logscale << endl;
629 if (extraline != NULL)
630 output << extraline << endl;
631 output << "set xlabel '" << xlabel << "'" << endl;
632 output << "set ylabel '" << ylabel << "'" << endl;
633 output << "set terminal eps color" << endl;
634 output << "set output '"<< prefix << ".eps'" << endl;
635};
636
637/** Creates the pyxplotfile for energy data.
638 * \param Matrix MatrixContainer with matrix values
639 * \param KeySets contains bond order
640 * \param *dir directory
641 * \param *prefix prefix for all filenames (without ending)
642 * \param keycolumns number of columns of the key
643 * \param *key position of key
644 * \param logscale axis for logscale
645 * \param mxtics small tics at ...
646 * \param xtics large tics at ...
647 * \param xlabel label for x axis
648 * \param xlabel label for x axis
649 * \param *xrange xrange
650 * \param *yrange yrange
651 * \param *xargument number of column to plot against (x axis)
652 * \param uses using string for plot command
653 * \param (*CreatePlotLines) function reference that writes a single plot line
654 * \return true if file was written successfully
655 */
656bool CreatePlotOrder(class MatrixContainer &Matrix, const class KeySetsContainer &KeySets, const char *dir, const char *prefix, const int keycolumns, const char *key, const char *logscale, const char *extraline, const int mxtics, const int xtics, const char *xlabel, const char *ylabel, const char *xrange, const char *yrange, const char *xargument, const char *uses, void (*CreatePlotLines)(ofstream &, class MatrixContainer &, const char *, const char *, const char *))
657{
658 stringstream filename;
659 ofstream output;
660
661 filename << prefix << ".pyx";
662 if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
663 CreatePlotHeader(output, prefix, keycolumns, key, logscale, extraline, mxtics, xtics, xlabel, ylabel);
664 output << "plot " << xrange << " " << yrange << " \\" << endl;
665 CreatePlotLines(output, Matrix, prefix, xargument, uses);
666 output.close();
667 return true;
668};
669
670/** Writes plot lines for absolute energies.
671 * \param output file handler
672 * \param Energy MatrixContainer with matrix values
673 * \param *prefix prefix of data file
674 * \param *xargument number of column to plot against (x axis)
675 * \param *uses uses command
676 */
677void AbsEnergyPlotLine(ofstream &output, class MatrixContainer &Energy, const char *prefix, const char *xargument, const char *uses)
678{
679 stringstream line(Energy.Header[ Energy.MatrixCounter ]);
680 string token;
681
682 getline(line, token, '\t');
683 for (int i=2; i<= Energy.ColumnCounter[Energy.MatrixCounter];i++) {
684 getline(line, token, '\t');
685 while (token[0] == ' ') // remove leading white spaces
686 token.erase(0,1);
687 output << "'" << prefix << ".dat' title '" << token << "' using " << xargument << ":(abs($" << i+2 << ")) " << uses;
688 if (i != (Energy.ColumnCounter[Energy.MatrixCounter]))
689 output << ", \\";
690 output << endl;
691 }
692};
693
694/** Writes plot lines for energies.
695 * \param output file handler
696 * \param Energy MatrixContainer with matrix values
697 * \param *prefix prefix of data file
698 * \param *xargument number of column to plot against (x axis)
699 * \param *uses uses command
700 */
701void EnergyPlotLine(ofstream &output, class MatrixContainer &Energy, const char *prefix, const char *xargument, const char *uses)
702{
703 stringstream line(Energy.Header[Energy.MatrixCounter]);
704 string token;
705
706 getline(line, token, '\t');
707 for (int i=1; i<= Energy.ColumnCounter[Energy.MatrixCounter];i++) {
708 getline(line, token, '\t');
709 while (token[0] == ' ') // remove leading white spaces
710 token.erase(0,1);
711 output << "'" << prefix << ".dat' title '" << token << "' using " << xargument << ":" << i+2 << " " << uses;
712 if (i != (Energy.ColumnCounter[Energy.MatrixCounter]))
713 output << ", \\";
714 output << endl;
715 }
716};
717
718/** Writes plot lines for absolute force magnitudes.
719 * \param output file handler
720 * \param Force MatrixContainer with matrix values
721 * \param *prefix prefix of data file
722 * \param *xargument number of column to plot against (x axis)
723 * \param *uses uses command
724 */
725void ForceMagnitudePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
726{
727 stringstream line(Force.Header[Force.MatrixCounter]);
728 string token;
729
730 getline(line, token, '\t');
731 getline(line, token, '\t');
732 getline(line, token, '\t');
733 getline(line, token, '\t');
734 getline(line, token, '\t');
735 for (int i=7; i< Force.ColumnCounter[Force.MatrixCounter];i+=NDIM) {
736 getline(line, token, '\t');
737 while (token[0] == ' ') // remove leading white spaces
738 token.erase(0,1);
739 token.erase(token.length(), 1); // kill residual index char (the '0')
740 output << "'" << prefix << ".dat' title '" << token << "' using " << xargument << ":(sqrt($" << i+1 << "*$" << i+1 << "+$" << i+2 << "*$" << i+2 << "+$" << i+3 << "*$" << i+3 << ")) " << uses;
741 if (i != (Force.ColumnCounter[Force.MatrixCounter]-1))
742 output << ", \\";
743 output << endl;
744 getline(line, token, '\t');
745 getline(line, token, '\t');
746 }
747};
748
749/** Writes plot lines for first component of force vector.
750 * \param output file handler
751 * \param Force MatrixContainer with matrix values
752 * \param *prefix prefix of data file
753 * \param *xargument number of column to plot against (x axis)
754 * \param *uses uses command
755 */
756void AbsFirstForceValuePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
757{
758 stringstream line(Force.Header[Force.MatrixCounter]);
759 string token;
760
761 getline(line, token, '\t');
762 getline(line, token, '\t');
763 getline(line, token, '\t');
764 getline(line, token, '\t');
765 getline(line, token, '\t');
766 for (int i=7; i< Force.ColumnCounter[Force.MatrixCounter];i+=NDIM) {
767 getline(line, token, '\t');
768 while (token[0] == ' ') // remove leading white spaces
769 token.erase(0,1);
770 token.erase(token.length(), 1); // kill residual index char (the '0')
771 output << "'" << prefix << ".dat' title '" << token << "' using " << xargument << ":(abs($" << i+1 << ")) " << uses;
772 if (i != (Force.ColumnCounter[Force.MatrixCounter]-1))
773 output << ", \\";
774 output << endl;
775 getline(line, token, '\t');
776 getline(line, token, '\t');
777 }
778};
779
780/** Writes plot lines for force vector as boxes with a fillcolor.
781 * \param output file handler
782 * \param Force MatrixContainer with matrix values
783 * \param *prefix prefix of data file
784 * \param *xargument number of column to plot against (x axis)
785 * \param *uses uses command
786 */
787void BoxesForcePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
788{
789 stringstream line(Force.Header[Force.MatrixCounter]);
790 const char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
791 string token;
792
793 getline(line, token, '\t');
794 getline(line, token, '\t');
795 getline(line, token, '\t');
796 getline(line, token, '\t');
797 getline(line, token, '\t');
798 for (int i=7; i< Force.ColumnCounter[Force.MatrixCounter];i+=NDIM) {
799 getline(line, token, '\t');
800 while (token[0] == ' ') // remove leading white spaces
801 token.erase(0,1);
802 token.erase(token.length(), 1); // kill residual index char (the '0')
803 output << "'" << prefix << ".dat' title '" << token << "' using ($" << xargument << "+" << fixed << setprecision(1) << (double)((i-7)/3)*0.2 << "):(sqrt($" << i+1 << "*$" << i+1 << "+$" << i+2 << "*$" << i+2 << "+$" << i+3 << "*$" << i+3 << ")) " << uses << " " << fillcolor[(i-7)/3];
804 if (i != (Force.ColumnCounter[Force.MatrixCounter]-1))
805 output << ", \\";
806 output << endl;
807 getline(line, token, '\t');
808 getline(line, token, '\t');
809 }
810};
811
812/** Writes plot lines for first force vector component as boxes with a fillcolor.
813 * \param output file handler
814 * \param Force MatrixContainer with matrix values
815 * \param *prefix prefix of data file
816 * \param *xargument number of column to plot against (x axis)
817 * \param *uses uses command
818 */
819void BoxesFirstForceValuePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
820{
821 stringstream line(Force.Header[Force.MatrixCounter]);
822 const char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
823 string token;
824
825 getline(line, token, '\t');
826 getline(line, token, '\t');
827 getline(line, token, '\t');
828 getline(line, token, '\t');
829 getline(line, token, '\t');
830 for (int i=7; i< Force.ColumnCounter[Force.MatrixCounter];i+=NDIM) {
831 getline(line, token, '\t');
832 while (token[0] == ' ') // remove leading white spaces
833 token.erase(0,1);
834 token.erase(token.length(), 1); // kill residual index char (the '0')
835 output << "'" << prefix << ".dat' title '" << token << "' using ($" << xargument << "+" << fixed << setprecision(1) << (double)((i-7)/3)*0.2 << "):" << i+1 << " " << uses << " " << fillcolor[(i-7)/3];
836 if (i != (Force.ColumnCounter[Force.MatrixCounter]-1))
837 output << ", \\";
838 output << endl;
839 getline(line, token, '\t');
840 getline(line, token, '\t');
841 }
842};
Note: See TracBrowser for help on using the repository browser.