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