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