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