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