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