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