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