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