source: src/datacreator.cpp@ cb2146

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 cb2146 was 1f2217, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Small fixes

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