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