| 1 | /** \file datacreator.cpp
 | 
|---|
| 2 |  *
 | 
|---|
| 3 |  * Declarations of assisting functions in creating data and plot files.
 | 
|---|
| 4 |  *
 | 
|---|
| 5 |  */
 | 
|---|
| 6 | 
 | 
|---|
| 7 | //============================ INCLUDES ===========================
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include "datacreator.hpp"
 | 
|---|
| 10 | #include "helpers.hpp"
 | 
|---|
| 11 | #include "parser.hpp"
 | 
|---|
| 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 |  */
 | 
|---|
| 21 | bool OpenOutputFile(ofstream &output, const char *dir, const char *filename)
 | 
|---|
| 22 | {
 | 
|---|
| 23 |   stringstream name;
 | 
|---|
| 24 |   name << dir << "/" << filename;
 | 
|---|
| 25 |   output.open(name.str().c_str(), ios::out);
 | 
|---|
| 26 |   if (output == NULL) {
 | 
|---|
| 27 |     Log() << Verbose(0) << "Unable to open " << name.str() << " for writing, is directory correct?" << endl;
 | 
|---|
| 28 |     return false;
 | 
|---|
| 29 |   }
 | 
|---|
| 30 |   return true;
 | 
|---|
| 31 | };
 | 
|---|
| 32 | 
 | 
|---|
| 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 |  */
 | 
|---|
| 39 | bool AppendOutputFile(ofstream &output, const char *dir, const char *filename)
 | 
|---|
| 40 | {
 | 
|---|
| 41 |   stringstream name;
 | 
|---|
| 42 |   name << dir << "/" << filename;
 | 
|---|
| 43 |   output.open(name.str().c_str(), ios::app);
 | 
|---|
| 44 |   if (output == NULL) {
 | 
|---|
| 45 |     Log() << Verbose(0) << "Unable to open " << name.str() << " for writing, is directory correct?" << endl;
 | 
|---|
| 46 |     return false;
 | 
|---|
| 47 |   }
 | 
|---|
| 48 |   return true;
 | 
|---|
| 49 | };
 | 
|---|
| 50 | 
 | 
|---|
| 51 | /** Plots an energy vs. order.
 | 
|---|
| 52 |  * \param &Fragments EnergyMatrix class containing matrix values
 | 
|---|
| 53 |  * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
 | 
|---|
| 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 |  */
 | 
|---|
| 58 | bool CreateDataEnergyOrder(class EnergyMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
 | 
|---|
| 59 | {
 | 
|---|
| 60 |   stringstream filename;
 | 
|---|
| 61 |   ofstream output;
 | 
|---|
| 62 | 
 | 
|---|
| 63 |   filename << prefix << ".dat";
 | 
|---|
| 64 |   if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
 | 
|---|
| 65 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 66 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 67 |   output << "#Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
 | 
|---|
| 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];
 | 
|---|
| 73 |     }
 | 
|---|
| 74 |     output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
 | 
|---|
| 75 |     for (int l=0;l<Fragments.ColumnCounter[Fragments.MatrixCounter];l++)
 | 
|---|
| 76 |       output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l];
 | 
|---|
| 77 |     output << endl;
 | 
|---|
| 78 |   }
 | 
|---|
| 79 |   output.close();
 | 
|---|
| 80 |   return true;
 | 
|---|
| 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
 | 
|---|
| 86 |  * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
 | 
|---|
| 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 |  */
 | 
|---|
| 91 | bool CreateDataDeltaEnergyOrder(class EnergyMatrix &Energy, class EnergyMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
 | 
|---|
| 92 | {
 | 
|---|
| 93 |   stringstream filename;
 | 
|---|
| 94 |   ofstream output;
 | 
|---|
| 95 | 
 | 
|---|
| 96 |   filename << prefix << ".dat";
 | 
|---|
| 97 |   if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
 | 
|---|
| 98 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 99 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 100 |   output << "#Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
 | 
|---|
| 101 |   Fragments.SetLastMatrix(Energy.Matrix[Energy.MatrixCounter],0);
 | 
|---|
| 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];
 | 
|---|
| 107 |     }
 | 
|---|
| 108 |     output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
 | 
|---|
| 109 |     for (int l=0;l<Fragments.ColumnCounter[Energy.MatrixCounter];l++)
 | 
|---|
| 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;
 | 
|---|
| 118 | };
 | 
|---|
| 119 | 
 | 
|---|
| 120 | /** Plot forces vs. order.
 | 
|---|
| 121 |  * \param &Fragments ForceMatrix class containing matrix values
 | 
|---|
| 122 |  * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
 | 
|---|
| 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
 | 
|---|
| 127 |  */
 | 
|---|
| 128 | 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))
 | 
|---|
| 129 | {
 | 
|---|
| 130 |   stringstream filename;
 | 
|---|
| 131 |   ofstream output;
 | 
|---|
| 132 | 
 | 
|---|
| 133 |   filename << prefix << ".dat";
 | 
|---|
| 134 |   if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
 | 
|---|
| 135 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 136 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 137 |   output << "# Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
 | 
|---|
| 138 |   Fragments.SetLastMatrix(0.,0);
 | 
|---|
| 139 |   for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
 | 
|---|
| 140 |     Fragments.SumSubForces(Fragments, KeySets, BondOrder, 1.);
 | 
|---|
| 141 |     output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
 | 
|---|
| 142 |     CreateForce(Fragments, Fragments.MatrixCounter);
 | 
|---|
| 143 |     for (int l=0;l<Fragments.ColumnCounter[Fragments.MatrixCounter];l++)
 | 
|---|
| 144 |        output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter] ][l];
 | 
|---|
| 145 |     output << endl;
 | 
|---|
| 146 |   }
 | 
|---|
| 147 |   output.close();
 | 
|---|
| 148 |   return true;
 | 
|---|
| 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
 | 
|---|
| 154 |  * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
 | 
|---|
| 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 |  */
 | 
|---|
| 160 | 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))
 | 
|---|
| 161 | {
 | 
|---|
| 162 |   stringstream filename;
 | 
|---|
| 163 |   ofstream output;
 | 
|---|
| 164 | 
 | 
|---|
| 165 |   filename << prefix << ".dat";
 | 
|---|
| 166 |   if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
 | 
|---|
| 167 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 168 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 169 |   output << "# Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
 | 
|---|
| 170 |   Fragments.SetLastMatrix(Force.Matrix[Force.MatrixCounter],0);
 | 
|---|
| 171 |   for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
 | 
|---|
| 172 |     Fragments.SumSubForces(Fragments, KeySets, BondOrder, -1.);
 | 
|---|
| 173 |     output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
 | 
|---|
| 174 |     CreateForce(Fragments, Fragments.MatrixCounter);
 | 
|---|
| 175 |     for (int l=0;l<Fragments.ColumnCounter[Fragments.MatrixCounter];l++)
 | 
|---|
| 176 |        output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter] ][l];
 | 
|---|
| 177 |     output << endl;
 | 
|---|
| 178 |   }
 | 
|---|
| 179 |   output.close();
 | 
|---|
| 180 |   return true;
 | 
|---|
| 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
 | 
|---|
| 186 |  * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
 | 
|---|
| 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 |  */
 | 
|---|
| 192 | bool CreateDataDeltaForcesOrderPerAtom(class ForceMatrix &Force, class ForceMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
 | 
|---|
| 193 | {
 | 
|---|
| 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;
 | 
|---|
| 200 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 201 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 202 |   output << "# AtomNo\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
 | 
|---|
| 203 |   Fragments.SetLastMatrix(Force.Matrix[Force.MatrixCounter], 0);
 | 
|---|
| 204 |   for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
 | 
|---|
| 205 |     //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
 | 
|---|
| 206 |     Fragments.SumSubForces(Fragments, KeySets, BondOrder, -1.);
 | 
|---|
| 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";
 | 
|---|
| 211 |       for (int l=0;l<Fragments.ColumnCounter[ Fragments.MatrixCounter ];l++) {
 | 
|---|
| 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);
 | 
|---|
| 217 |         }                                                                                                    
 | 
|---|
| 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;
 | 
|---|
| 229 | };
 | 
|---|
| 230 | 
 | 
|---|
| 231 | /** Plot forces error vs. vs atom vs. order.
 | 
|---|
| 232 |  * \param &Fragments ForceMatrix class containing matrix values
 | 
|---|
| 233 |  * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
 | 
|---|
| 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 |  */
 | 
|---|
| 239 | bool CreateDataForcesOrderPerAtom(class ForceMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
 | 
|---|
| 240 | {
 | 
|---|
| 241 |   stringstream filename;
 | 
|---|
| 242 |   ofstream output;
 | 
|---|
| 243 | 
 | 
|---|
| 244 |   filename << prefix << ".dat";
 | 
|---|
| 245 |   if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
 | 
|---|
| 246 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 247 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 248 |   output << "# AtomNo\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
 | 
|---|
| 249 |   for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
 | 
|---|
| 250 |     //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
 | 
|---|
| 251 |     Fragments.SumSubForces(Fragments, KeySets, BondOrder, 1.);
 | 
|---|
| 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";
 | 
|---|
| 256 |       for (int l=0;l<Fragments.ColumnCounter[ Fragments.MatrixCounter ];l++)
 | 
|---|
| 257 |         output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
 | 
|---|
| 258 |       output << endl;
 | 
|---|
| 259 |     }
 | 
|---|
| 260 |     output << endl;
 | 
|---|
| 261 |   }
 | 
|---|
| 262 |   output.close();
 | 
|---|
| 263 |   return true;
 | 
|---|
| 264 | };
 | 
|---|
| 265 | 
 | 
|---|
| 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
 | 
|---|
| 270 |  * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
 | 
|---|
| 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 |  */
 | 
|---|
| 276 | bool CreateDataDeltaHessianOrderPerAtom(class HessianMatrix &Hessian, class HessianMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
 | 
|---|
| 277 | {
 | 
|---|
| 278 |   stringstream filename;
 | 
|---|
| 279 |   ofstream output;
 | 
|---|
| 280 | 
 | 
|---|
| 281 |   filename << prefix << ".dat";
 | 
|---|
| 282 |   if (!OpenOutputFile(output, dir, filename.str().c_str())) return false; 
 | 
|---|
| 283 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 284 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 285 |   output << "# AtomNo\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
 | 
|---|
| 286 |   Fragments.SetLastMatrix(Hessian.Matrix[Hessian.MatrixCounter], 0);
 | 
|---|
| 287 |   for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
 | 
|---|
| 288 |     //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
 | 
|---|
| 289 |     Fragments.SumSubHessians(Fragments, KeySets, BondOrder, -1.);
 | 
|---|
| 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 | };
 | 
|---|
| 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
 | 
|---|
| 308 |  * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
 | 
|---|
| 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 |  */
 | 
|---|
| 314 | bool CreateDataDeltaFrobeniusOrderPerAtom(class HessianMatrix &Hessian, class HessianMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
 | 
|---|
| 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; 
 | 
|---|
| 323 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 324 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 325 |   output << "# AtomNo\t";
 | 
|---|
| 326 |   Fragments.SetLastMatrix(Hessian.Matrix[Hessian.MatrixCounter], 0);
 | 
|---|
| 327 |   for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
 | 
|---|
| 328 |     output << "Order" << BondOrder+1 << "\t";
 | 
|---|
| 329 |   }
 | 
|---|
| 330 |   output << endl;
 | 
|---|
| 331 |   output << Fragments.RowCounter[ Fragments.MatrixCounter ] << "\t";
 | 
|---|
| 332 |   for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
 | 
|---|
| 333 |     //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
 | 
|---|
| 334 |     Fragments.SumSubHessians(Fragments, KeySets, BondOrder, -1.);
 | 
|---|
| 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++) {
 | 
|---|
| 339 |         tmp = Fragments.Matrix[Fragments.MatrixCounter][ j ][l];
 | 
|---|
| 340 |         norm += tmp*tmp;
 | 
|---|
| 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 | };
 | 
|---|
| 349 | 
 | 
|---|
| 350 | /** Plot hessian error vs. vs atom vs. order.
 | 
|---|
| 351 |  * \param &Fragments HessianMatrix class containing matrix values
 | 
|---|
| 352 |  * \param KeySets KeySetContainer class holding bond KeySetContainer::Order
 | 
|---|
| 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 |  */
 | 
|---|
| 358 | bool CreateDataHessianOrderPerAtom(class HessianMatrix &Fragments, class KeySetsContainer &KeySets, const char *dir, const char *prefix, const char *msg, const char *datum)
 | 
|---|
| 359 | {
 | 
|---|
| 360 |   stringstream filename;
 | 
|---|
| 361 |   ofstream output;
 | 
|---|
| 362 | 
 | 
|---|
| 363 |   filename << prefix << ".dat";
 | 
|---|
| 364 |   if (!OpenOutputFile(output, dir, filename.str().c_str())) return false; 
 | 
|---|
| 365 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 366 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 367 |   output << "# AtomNo\t" << Fragments.Header[ Fragments.MatrixCounter ] << endl;
 | 
|---|
| 368 |   Fragments.SetLastMatrix(0., 0);
 | 
|---|
| 369 |   for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
 | 
|---|
| 370 |     //Log() << Verbose(0) << "Current order is " << BondOrder << "." << endl;
 | 
|---|
| 371 |     Fragments.SumSubHessians(Fragments, KeySets, BondOrder, 1.);
 | 
|---|
| 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++)
 | 
|---|
| 377 |         output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
 | 
|---|
| 378 |       output << endl;
 | 
|---|
| 379 |     }
 | 
|---|
| 380 |     output << endl;
 | 
|---|
| 381 |   }
 | 
|---|
| 382 |   output.close();
 | 
|---|
| 383 |   return true;
 | 
|---|
| 384 | };
 | 
|---|
| 385 | 
 | 
|---|
| 386 | /** Plot matrix vs. fragment.
 | 
|---|
| 387 |  */
 | 
|---|
| 388 | 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))
 | 
|---|
| 389 | {
 | 
|---|
| 390 |   stringstream filename;
 | 
|---|
| 391 |   ofstream output;
 | 
|---|
| 392 | 
 | 
|---|
| 393 |   filename << prefix << ".dat";
 | 
|---|
| 394 |   if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
 | 
|---|
| 395 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 396 |   output << "# " << msg << ", created on " << datum << endl;
 | 
|---|
| 397 |   output << "#Order\tFrag.No.\t" << Fragment.Header[ Fragment.MatrixCounter ] << endl;
 | 
|---|
| 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];
 | 
|---|
| 404 |       output << endl;
 | 
|---|
| 405 |     }
 | 
|---|
| 406 |   }
 | 
|---|
| 407 |   output.close();
 | 
|---|
| 408 |   return true;
 | 
|---|
| 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
 | 
|---|
| 413 |  * \param &KeySets KeySetsContainer with associations of each fragment to a bond order
 | 
|---|
| 414 |  * \param BondOrder current bond order
 | 
|---|
| 415 |  */
 | 
|---|
| 416 | void CreateMaxFragmentOrder(class MatrixContainer &Fragments, class KeySetsContainer &KeySets, int BondOrder)
 | 
|---|
| 417 | {
 | 
|---|
| 418 |   for(int j=Fragments.RowCounter[ Fragments.MatrixCounter ];j--;) {
 | 
|---|
| 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])) {
 | 
|---|
| 421 |         for (int k=Fragments.ColumnCounter[ Fragments.MatrixCounter ];k--;)
 | 
|---|
| 422 |           Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][k];
 | 
|---|
| 423 |       }
 | 
|---|
| 424 |     }
 | 
|---|
| 425 |   }
 | 
|---|
| 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
 | 
|---|
| 430 |  * \param &KeySets KeySetsContainer with associations of each fragment to a bond order
 | 
|---|
| 431 |  * \param BondOrder current bond order
 | 
|---|
| 432 |  */
 | 
|---|
| 433 | void CreateMinFragmentOrder(class MatrixContainer &Fragments, class KeySetsContainer &KeySets, int BondOrder)
 | 
|---|
| 434 | {
 | 
|---|
| 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
 | 
|---|
| 438 |       for (int k=Fragments.ColumnCounter[ Fragments.MatrixCounter ];k--;)
 | 
|---|
| 439 |         Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][k];
 | 
|---|
| 440 |       i++;
 | 
|---|
| 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])) {
 | 
|---|
| 444 |         for (int k=Fragments.ColumnCounter[ Fragments.MatrixCounter ];k--;)
 | 
|---|
| 445 |           Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySets.OrderSet[BondOrder][i] ][j][k];
 | 
|---|
| 446 |       }
 | 
|---|
| 447 |     }
 | 
|---|
| 448 |   }
 | 
|---|
| 449 | };
 | 
|---|
| 450 | 
 | 
|---|
| 451 | /** Plot matrix vs. fragment.
 | 
|---|
| 452 |  */
 | 
|---|
| 453 | 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))
 | 
|---|
| 454 | {
 | 
|---|
| 455 |   stringstream filename;
 | 
|---|
| 456 |   ofstream output;
 | 
|---|
| 457 | 
 | 
|---|
| 458 |   filename << prefix << ".dat";
 | 
|---|
| 459 |   if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
 | 
|---|
| 460 |   Log() << Verbose(0) << msg << endl;
 | 
|---|
| 461 |   output << "# " << msg << ", created on " << datum;
 | 
|---|
| 462 |   output << "#Order\tFrag.No.\t" << Fragment.Header[ Fragment.MatrixCounter ] << endl;
 | 
|---|
| 463 |   // max
 | 
|---|
| 464 |   for (int BondOrder=0;BondOrder<KeySets.Order;BondOrder++) {
 | 
|---|
| 465 |     Fragment.SetLastMatrix(0.,0);
 | 
|---|
| 466 |     CreateFragmentOrder(Fragment, KeySets, BondOrder);
 | 
|---|
| 467 |     output << BondOrder+1 << "\t" << KeySets.FragmentsPerOrder[BondOrder];
 | 
|---|
| 468 |     for (int l=0;l<Fragment.ColumnCounter[ Fragment.MatrixCounter ];l++)
 | 
|---|
| 469 |       output << scientific << "\t" << Fragment.Matrix[ Fragment.MatrixCounter ][ Fragment.RowCounter[ Fragment.MatrixCounter ]-1 ][l];
 | 
|---|
| 470 |     output << endl;
 | 
|---|
| 471 |   }
 | 
|---|
| 472 |   output.close();
 | 
|---|
| 473 |   return true;
 | 
|---|
| 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 |  */
 | 
|---|
| 480 | void CreateEnergy(class MatrixContainer &Energy, int MatrixNumber)
 | 
|---|
| 481 | {
 | 
|---|
| 482 |   for(int k=0;k<Energy.ColumnCounter[MatrixNumber];k++)
 | 
|---|
| 483 |     Energy.Matrix[MatrixNumber][ Energy.RowCounter[MatrixNumber] ] [k] =  Energy.Matrix[MatrixNumber][ Energy.RowCounter[MatrixNumber]-1 ] [k];
 | 
|---|
| 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 |  */
 | 
|---|
| 491 | void CreateMinimumForce(class MatrixContainer &Force, int MatrixNumber)
 | 
|---|
| 492 | {
 | 
|---|
| 493 |   for (int l=Force.ColumnCounter[MatrixNumber];l--;)
 | 
|---|
| 494 |     Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
 | 
|---|
| 495 |   for (int l=5;l<Force.ColumnCounter[MatrixNumber];l+=3) {
 | 
|---|
| 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 |   }
 | 
|---|
| 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
 | 
|---|
| 523 |   * \param MatrixNumber the index for the ForceMatrix::matrix array
 | 
|---|
| 524 |  */
 | 
|---|
| 525 | void CreateMeanForce(class MatrixContainer &Force, int MatrixNumber)
 | 
|---|
| 526 | {
 | 
|---|
| 527 |   int divisor = 0;
 | 
|---|
| 528 |   for (int l=Force.ColumnCounter[MatrixNumber];l--;)
 | 
|---|
| 529 |     Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
 | 
|---|
| 530 |   for (int l=5;l<Force.ColumnCounter[MatrixNumber];l+=3) {
 | 
|---|
| 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 |   }
 | 
|---|
| 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 |  */
 | 
|---|
| 550 | void CreateMaximumForce(class MatrixContainer &Force, int MatrixNumber)
 | 
|---|
| 551 | {
 | 
|---|
| 552 |   for (int l=5;l<Force.ColumnCounter[MatrixNumber];l+=3) {
 | 
|---|
| 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 |   }
 | 
|---|
| 566 | };
 | 
|---|
| 567 | 
 | 
|---|
| 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 | */
 | 
|---|
| 572 | void CreateSameForce(class MatrixContainer &Force, int MatrixNumber)
 | 
|---|
| 573 | {
 | 
|---|
| 574 |   // does nothing
 | 
|---|
| 575 | };
 | 
|---|
| 576 | 
 | 
|---|
| 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 |  */
 | 
|---|
| 582 | void CreateVectorSumForce(class MatrixContainer &Force, int MatrixNumber)
 | 
|---|
| 583 | {
 | 
|---|
| 584 |   for (int l=Force.ColumnCounter[MatrixNumber];l--;)
 | 
|---|
| 585 |     Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
 | 
|---|
| 586 |   for (int l=0;l<Force.ColumnCounter[MatrixNumber];l++) {
 | 
|---|
| 587 |     for (int k=Force.RowCounter[MatrixNumber];k--;)
 | 
|---|
| 588 |       Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] += Force.Matrix[MatrixNumber][k][l];
 | 
|---|
| 589 |   }
 | 
|---|
| 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
 | 
|---|
| 596 |  * \param *extraline extra set lines if desired
 | 
|---|
| 597 |  * \param mxtics small tics at ...
 | 
|---|
| 598 |  * \param xtics large tics at ...
 | 
|---|
| 599 |  * \param *xlabel label for x axis
 | 
|---|
| 600 |  * \param *ylabel label for y axis
 | 
|---|
| 601 |  */
 | 
|---|
| 602 | 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)
 | 
|---|
| 603 | {
 | 
|---|
| 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;
 | 
|---|
| 618 | };
 | 
|---|
| 619 | 
 | 
|---|
| 620 | /** Creates the pyxplotfile for energy data.
 | 
|---|
| 621 |  * \param Matrix MatrixContainer with matrix values
 | 
|---|
| 622 |  * \param KeySets contains bond order
 | 
|---|
| 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 ...
 | 
|---|
| 630 |  * \param xlabel label for x axis
 | 
|---|
| 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
 | 
|---|
| 638 |  */
 | 
|---|
| 639 | 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 *))
 | 
|---|
| 640 | {
 | 
|---|
| 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;
 | 
|---|
| 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 |  */
 | 
|---|
| 660 | void AbsEnergyPlotLine(ofstream &output, class MatrixContainer &Energy, const char *prefix, const char *xargument, const char *uses)
 | 
|---|
| 661 | {
 | 
|---|
| 662 |   stringstream line(Energy.Header[ Energy.MatrixCounter ]);
 | 
|---|
| 663 |   string token;
 | 
|---|
| 664 | 
 | 
|---|
| 665 |   getline(line, token, '\t');
 | 
|---|
| 666 |   for (int i=2; i<= Energy.ColumnCounter[Energy.MatrixCounter];i++) {
 | 
|---|
| 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;
 | 
|---|
| 671 |     if (i != (Energy.ColumnCounter[Energy.MatrixCounter]))
 | 
|---|
| 672 |       output << ", \\";
 | 
|---|
| 673 |     output << endl;
 | 
|---|
| 674 |   }
 | 
|---|
| 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 |  */
 | 
|---|
| 684 | void EnergyPlotLine(ofstream &output, class MatrixContainer &Energy, const char *prefix, const char *xargument, const char *uses)
 | 
|---|
| 685 | {
 | 
|---|
| 686 |   stringstream line(Energy.Header[Energy.MatrixCounter]);
 | 
|---|
| 687 |   string token;
 | 
|---|
| 688 | 
 | 
|---|
| 689 |   getline(line, token, '\t');
 | 
|---|
| 690 |   for (int i=1; i<= Energy.ColumnCounter[Energy.MatrixCounter];i++) {
 | 
|---|
| 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;
 | 
|---|
| 695 |     if (i != (Energy.ColumnCounter[Energy.MatrixCounter]))
 | 
|---|
| 696 |       output << ", \\";
 | 
|---|
| 697 |     output << endl;
 | 
|---|
| 698 |   }
 | 
|---|
| 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 |  */
 | 
|---|
| 708 | void ForceMagnitudePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
 | 
|---|
| 709 | {
 | 
|---|
| 710 |   stringstream line(Force.Header[Force.MatrixCounter]);
 | 
|---|
| 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');
 | 
|---|
| 718 |   for (int i=7; i< Force.ColumnCounter[Force.MatrixCounter];i+=NDIM) {
 | 
|---|
| 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;
 | 
|---|
| 724 |     if (i != (Force.ColumnCounter[Force.MatrixCounter]-1))
 | 
|---|
| 725 |       output << ", \\";
 | 
|---|
| 726 |     output << endl;
 | 
|---|
| 727 |     getline(line, token, '\t');
 | 
|---|
| 728 |     getline(line, token, '\t');
 | 
|---|
| 729 |   }
 | 
|---|
| 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 |  */
 | 
|---|
| 739 | void AbsFirstForceValuePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
 | 
|---|
| 740 | {
 | 
|---|
| 741 |   stringstream line(Force.Header[Force.MatrixCounter]);
 | 
|---|
| 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');
 | 
|---|
| 749 |   for (int i=7; i< Force.ColumnCounter[Force.MatrixCounter];i+=NDIM) {
 | 
|---|
| 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;
 | 
|---|
| 755 |     if (i != (Force.ColumnCounter[Force.MatrixCounter]-1))
 | 
|---|
| 756 |       output << ", \\";
 | 
|---|
| 757 |     output << endl;
 | 
|---|
| 758 |     getline(line, token, '\t');
 | 
|---|
| 759 |     getline(line, token, '\t');
 | 
|---|
| 760 |   }
 | 
|---|
| 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 |  */
 | 
|---|
| 770 | void BoxesForcePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
 | 
|---|
| 771 | {
 | 
|---|
| 772 |   stringstream line(Force.Header[Force.MatrixCounter]);
 | 
|---|
| 773 |   char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
 | 
|---|
| 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');
 | 
|---|
| 781 |   for (int i=7; i< Force.ColumnCounter[Force.MatrixCounter];i+=NDIM) {
 | 
|---|
| 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];
 | 
|---|
| 787 |     if (i != (Force.ColumnCounter[Force.MatrixCounter]-1))
 | 
|---|
| 788 |       output << ", \\";
 | 
|---|
| 789 |     output << endl;
 | 
|---|
| 790 |     getline(line, token, '\t');
 | 
|---|
| 791 |     getline(line, token, '\t');
 | 
|---|
| 792 |   }
 | 
|---|
| 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 |  */
 | 
|---|
| 802 | void BoxesFirstForceValuePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses)
 | 
|---|
| 803 | {
 | 
|---|
| 804 |   stringstream line(Force.Header[Force.MatrixCounter]);
 | 
|---|
| 805 |   char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
 | 
|---|
| 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');
 | 
|---|
| 813 |   for (int i=7; i< Force.ColumnCounter[Force.MatrixCounter];i+=NDIM) {
 | 
|---|
| 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];
 | 
|---|
| 819 |     if (i != (Force.ColumnCounter[Force.MatrixCounter]-1))
 | 
|---|
| 820 |       output << ", \\";
 | 
|---|
| 821 |     output << endl;
 | 
|---|
| 822 |     getline(line, token, '\t');
 | 
|---|
| 823 |     getline(line, token, '\t');
 | 
|---|
| 824 |   }
 | 
|---|
| 825 | };
 | 
|---|