source: src/datacreator.cpp@ eeec8f

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 eeec8f was eeec8f, checked in by Frederik Heber <heber@…>, 16 years ago

HessianMatrix implemented fully, but not yet working, probably due to wrong matrix generation in script file (convertHessian.py)

HessianMatrix::IsSymmetric was though to be needed, but is NOT. As we regard full matrices, we don't need to add onto mirrored indices as well
Joiner and Analyzer have seen some small changes and bugfixes: NoHessian was not also always looked at when needed and so on

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