[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 |
|
---|
[fa649a] | 8 | /** \file config.cpp
|
---|
| 9 | *
|
---|
| 10 | * Function implementations for the class config.
|
---|
| 11 | *
|
---|
| 12 | */
|
---|
| 13 |
|
---|
[bf3817] | 14 | // include config.h
|
---|
| 15 | #ifdef HAVE_CONFIG_H
|
---|
| 16 | #include <config.h>
|
---|
| 17 | #endif
|
---|
| 18 |
|
---|
[ad011c] | 19 | #include "CodePatterns/MemDebug.hpp"
|
---|
[112b09] | 20 |
|
---|
[568be7] | 21 | #include <stdio.h>
|
---|
[49e1ae] | 22 | #include <cstring>
|
---|
[6a465e] | 23 | #include <iostream>
|
---|
| 24 | #include <boost/tokenizer.hpp>
|
---|
| 25 | #include <string>
|
---|
[568be7] | 26 |
|
---|
[2b7d1b] | 27 | //#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
|
---|
[fa649a] | 28 | #include "atom.hpp"
|
---|
[568be7] | 29 | #include "bond.hpp"
|
---|
[a3fded] | 30 | #include "bondgraph.hpp"
|
---|
[fa649a] | 31 | #include "config.hpp"
|
---|
[a3fded] | 32 | #include "ConfigFileBuffer.hpp"
|
---|
[fa649a] | 33 | #include "element.hpp"
|
---|
[952f38] | 34 | #include "Helpers/helpers.hpp"
|
---|
[ad011c] | 35 | #include "CodePatterns/Info.hpp"
|
---|
| 36 | #include "CodePatterns/Log.hpp"
|
---|
[03c77c] | 37 | #include "CodePatterns/toString.hpp"
|
---|
| 38 | #include "CodePatterns/Verbose.hpp"
|
---|
[fa649a] | 39 | #include "molecule.hpp"
|
---|
| 40 | #include "molecule.hpp"
|
---|
| 41 | #include "periodentafel.hpp"
|
---|
[a3fded] | 42 | #include "ThermoStatContainer.hpp"
|
---|
[b34306] | 43 | #include "World.hpp"
|
---|
[cca9ef] | 44 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
[84c494] | 45 | #include "Box.hpp"
|
---|
[fa649a] | 46 |
|
---|
| 47 | /************************************* Functions for class config ***************************/
|
---|
| 48 |
|
---|
| 49 | /** Constructor for config file class.
|
---|
| 50 | */
|
---|
[97b825] | 51 | config::config() :
|
---|
| 52 | BG(NULL),
|
---|
| 53 | PsiType(0),
|
---|
| 54 | MaxPsiDouble(0),
|
---|
| 55 | PsiMaxNoUp(0),
|
---|
| 56 | PsiMaxNoDown(0),
|
---|
| 57 | MaxMinStopStep(1),
|
---|
| 58 | InitMaxMinStopStep(1),
|
---|
| 59 | ProcPEGamma(8),
|
---|
| 60 | ProcPEPsi(1),
|
---|
| 61 | configname(NULL),
|
---|
| 62 | FastParsing(false),
|
---|
| 63 | Deltat(0.01),
|
---|
| 64 | databasepath(NULL),
|
---|
| 65 | DoConstrainedMD(0),
|
---|
| 66 | MaxOuterStep(0),
|
---|
| 67 | mainname(NULL),
|
---|
| 68 | defaultpath(NULL),
|
---|
| 69 | pseudopotpath(NULL),
|
---|
| 70 | DoOutVis(0),
|
---|
| 71 | DoOutMes(1),
|
---|
| 72 | DoOutNICS(0),
|
---|
| 73 | DoOutOrbitals(0),
|
---|
| 74 | DoOutCurrent(0),
|
---|
| 75 | DoFullCurrent(0),
|
---|
| 76 | DoPerturbation(0),
|
---|
| 77 | DoWannier(0),
|
---|
| 78 | CommonWannier(0),
|
---|
| 79 | SawtoothStart(0.01),
|
---|
| 80 | VectorPlane(0),
|
---|
| 81 | VectorCut(0.),
|
---|
| 82 | UseAddGramSch(1),
|
---|
| 83 | Seed(1),
|
---|
| 84 | OutVisStep(10),
|
---|
| 85 | OutSrcStep(5),
|
---|
| 86 | MaxPsiStep(0),
|
---|
| 87 | EpsWannier(1e-7),
|
---|
| 88 | MaxMinStep(100),
|
---|
| 89 | RelEpsTotalEnergy(1e-7),
|
---|
| 90 | RelEpsKineticEnergy(1e-5),
|
---|
| 91 | MaxMinGapStopStep(0),
|
---|
| 92 | MaxInitMinStep(100),
|
---|
| 93 | InitRelEpsTotalEnergy(1e-5),
|
---|
| 94 | InitRelEpsKineticEnergy(1e-4),
|
---|
| 95 | InitMaxMinGapStopStep(0),
|
---|
| 96 | ECut(128.),
|
---|
| 97 | MaxLevel(5),
|
---|
| 98 | RiemannTensor(0),
|
---|
| 99 | LevRFactor(0),
|
---|
| 100 | RiemannLevel(0),
|
---|
| 101 | Lev0Factor(2),
|
---|
| 102 | RTActualUse(0),
|
---|
| 103 | AddPsis(0),
|
---|
| 104 | RCut(20.),
|
---|
| 105 | StructOpt(0),
|
---|
| 106 | IsAngstroem(1),
|
---|
| 107 | RelativeCoord(0),
|
---|
| 108 | MaxTypes(0)
|
---|
| 109 | {
|
---|
[920c70] | 110 | mainname = new char[MAXSTRINGSIZE];
|
---|
| 111 | defaultpath = new char[MAXSTRINGSIZE];
|
---|
| 112 | pseudopotpath = new char[MAXSTRINGSIZE];
|
---|
| 113 | databasepath = new char[MAXSTRINGSIZE];
|
---|
| 114 | configname = new char[MAXSTRINGSIZE];
|
---|
[fa649a] | 115 | strcpy(mainname,"pcp");
|
---|
| 116 | strcpy(defaultpath,"not specified");
|
---|
| 117 | strcpy(pseudopotpath,"not specified");
|
---|
| 118 | configname[0]='\0';
|
---|
| 119 | };
|
---|
| 120 |
|
---|
| 121 | /** Destructor for config file class.
|
---|
| 122 | */
|
---|
| 123 | config::~config()
|
---|
| 124 | {
|
---|
[920c70] | 125 | delete[](mainname);
|
---|
| 126 | delete[](defaultpath);
|
---|
| 127 | delete[](pseudopotpath);
|
---|
| 128 | delete[](databasepath);
|
---|
| 129 | delete[](configname);
|
---|
[568be7] | 130 |
|
---|
| 131 | if (BG != NULL)
|
---|
| 132 | delete(BG);
|
---|
[fa649a] | 133 | };
|
---|
| 134 |
|
---|
| 135 | /** Displays menu for editing each entry of the config file.
|
---|
[e138de] | 136 | * Nothing fancy here, just lots of Log() << Verbose(0)s for the menu and a switch/case
|
---|
[fa649a] | 137 | * for each entry of the config file structure.
|
---|
| 138 | */
|
---|
| 139 | void config::Edit()
|
---|
| 140 | {
|
---|
| 141 | char choice;
|
---|
| 142 |
|
---|
| 143 | do {
|
---|
[a67d19] | 144 | DoLog(0) && (Log() << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl);
|
---|
| 145 | DoLog(0) && (Log() << Verbose(0) << " A - mainname (prefix for all runtime files)" << endl);
|
---|
| 146 | DoLog(0) && (Log() << Verbose(0) << " B - Default path (for runtime files)" << endl);
|
---|
| 147 | DoLog(0) && (Log() << Verbose(0) << " C - Path of pseudopotential files" << endl);
|
---|
| 148 | DoLog(0) && (Log() << Verbose(0) << " D - Number of coefficient sharing processes" << endl);
|
---|
| 149 | DoLog(0) && (Log() << Verbose(0) << " E - Number of wave function sharing processes" << endl);
|
---|
| 150 | DoLog(0) && (Log() << Verbose(0) << " F - 0: Don't output density for OpenDX, 1: do" << endl);
|
---|
| 151 | DoLog(0) && (Log() << Verbose(0) << " G - 0: Don't output physical data, 1: do" << endl);
|
---|
| 152 | DoLog(0) && (Log() << Verbose(0) << " H - 0: Don't output densities of each unperturbed orbital for OpenDX, 1: do" << endl);
|
---|
| 153 | DoLog(0) && (Log() << Verbose(0) << " I - 0: Don't output current density for OpenDX, 1: do" << endl);
|
---|
| 154 | DoLog(0) && (Log() << Verbose(0) << " J - 0: Don't do the full current calculation, 1: do" << endl);
|
---|
| 155 | DoLog(0) && (Log() << Verbose(0) << " K - 0: Don't do perturbation calculation to obtain susceptibility and shielding, 1: do" << endl);
|
---|
| 156 | DoLog(0) && (Log() << Verbose(0) << " L - 0: Wannier centres as calculated, 1: common centre for all, 2: unite centres according to spread, 3: cell centre, 4: shifted to nearest grid point" << endl);
|
---|
| 157 | DoLog(0) && (Log() << Verbose(0) << " M - Absolute begin of unphysical sawtooth transfer for position operator within cell" << endl);
|
---|
| 158 | DoLog(0) && (Log() << Verbose(0) << " N - (0,1,2) x,y,z-plane to do two-dimensional current vector cut" << endl);
|
---|
| 159 | DoLog(0) && (Log() << Verbose(0) << " O - Absolute position along vector cut axis for cut plane" << endl);
|
---|
| 160 | DoLog(0) && (Log() << Verbose(0) << " P - Additional Gram-Schmidt-Orthonormalization to stabilize numerics" << endl);
|
---|
| 161 | DoLog(0) && (Log() << Verbose(0) << " Q - Initial integer value of random number generator" << endl);
|
---|
| 162 | DoLog(0) && (Log() << Verbose(0) << " R - for perturbation 0, for structure optimization defines upper limit of iterations" << endl);
|
---|
| 163 | DoLog(0) && (Log() << Verbose(0) << " T - Output visual after ...th step" << endl);
|
---|
| 164 | DoLog(0) && (Log() << Verbose(0) << " U - Output source densities of wave functions after ...th step" << endl);
|
---|
| 165 | DoLog(0) && (Log() << Verbose(0) << " X - minimization iterations per wave function, if unsure leave at default value 0" << endl);
|
---|
| 166 | DoLog(0) && (Log() << Verbose(0) << " Y - tolerance value for total spread in iterative Jacobi diagonalization" << endl);
|
---|
| 167 | DoLog(0) && (Log() << Verbose(0) << " Z - Maximum number of minimization iterations" << endl);
|
---|
| 168 | DoLog(0) && (Log() << Verbose(0) << " a - Relative change in total energy to stop min. iteration" << endl);
|
---|
| 169 | DoLog(0) && (Log() << Verbose(0) << " b - Relative change in kinetic energy to stop min. iteration" << endl);
|
---|
| 170 | DoLog(0) && (Log() << Verbose(0) << " c - Check stop conditions every ..th step during min. iteration" << endl);
|
---|
| 171 | DoLog(0) && (Log() << Verbose(0) << " e - Maximum number of minimization iterations during initial level" << endl);
|
---|
| 172 | DoLog(0) && (Log() << Verbose(0) << " f - Relative change in total energy to stop min. iteration during initial level" << endl);
|
---|
| 173 | DoLog(0) && (Log() << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl);
|
---|
| 174 | DoLog(0) && (Log() << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl);
|
---|
[e138de] | 175 | // Log() << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
|
---|
[a67d19] | 176 | DoLog(0) && (Log() << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl);
|
---|
| 177 | DoLog(0) && (Log() << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl);
|
---|
| 178 | DoLog(0) && (Log() << Verbose(0) << " m - Factor by which grid nodes increase between standard and upper level" << endl);
|
---|
| 179 | DoLog(0) && (Log() << Verbose(0) << " n - 0: Don't use RiemannTensor, 1: Do" << endl);
|
---|
| 180 | DoLog(0) && (Log() << Verbose(0) << " o - Factor by which grid nodes increase between Riemann and standard(?) level" << endl);
|
---|
| 181 | DoLog(0) && (Log() << Verbose(0) << " p - Number of Riemann levels" << endl);
|
---|
| 182 | DoLog(0) && (Log() << Verbose(0) << " r - 0: Don't Use RiemannTensor, 1: Do" << endl);
|
---|
| 183 | DoLog(0) && (Log() << Verbose(0) << " s - 0: Doubly occupied orbitals, 1: Up-/Down-Orbitals" << endl);
|
---|
| 184 | DoLog(0) && (Log() << Verbose(0) << " t - Number of orbitals (depends pn SpinType)" << endl);
|
---|
| 185 | DoLog(0) && (Log() << Verbose(0) << " u - Number of SpinUp orbitals (depends on SpinType)" << endl);
|
---|
| 186 | DoLog(0) && (Log() << Verbose(0) << " v - Number of SpinDown orbitals (depends on SpinType)" << endl);
|
---|
| 187 | DoLog(0) && (Log() << Verbose(0) << " w - Number of additional, unoccupied orbitals" << endl);
|
---|
| 188 | DoLog(0) && (Log() << Verbose(0) << " x - radial cutoff for ewald summation in Bohrradii" << endl);
|
---|
| 189 | DoLog(0) && (Log() << Verbose(0) << " y - 0: Don't do structure optimization beforehand, 1: Do" << endl);
|
---|
| 190 | DoLog(0) && (Log() << Verbose(0) << " z - 0: Units are in Bohr radii, 1: units are in Aengstrom" << endl);
|
---|
| 191 | DoLog(0) && (Log() << Verbose(0) << " i - 0: Coordinates given in file are absolute, 1: ... are relative to unit cell" << endl);
|
---|
| 192 | DoLog(0) && (Log() << Verbose(0) << "=========================================================" << endl);
|
---|
| 193 | DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
|
---|
[fa649a] | 194 | cin >> choice;
|
---|
| 195 |
|
---|
| 196 | switch (choice) {
|
---|
| 197 | case 'A': // mainname
|
---|
[a67d19] | 198 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::mainname << "\t new: ");
|
---|
[fa649a] | 199 | cin >> config::mainname;
|
---|
| 200 | break;
|
---|
| 201 | case 'B': // defaultpath
|
---|
[a67d19] | 202 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::defaultpath << "\t new: ");
|
---|
[fa649a] | 203 | cin >> config::defaultpath;
|
---|
| 204 | break;
|
---|
| 205 | case 'C': // pseudopotpath
|
---|
[a67d19] | 206 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::pseudopotpath << "\t new: ");
|
---|
[fa649a] | 207 | cin >> config::pseudopotpath;
|
---|
| 208 | break;
|
---|
| 209 |
|
---|
| 210 | case 'D': // ProcPEGamma
|
---|
[a67d19] | 211 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ProcPEGamma << "\t new: ");
|
---|
[fa649a] | 212 | cin >> config::ProcPEGamma;
|
---|
| 213 | break;
|
---|
| 214 | case 'E': // ProcPEPsi
|
---|
[a67d19] | 215 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ProcPEPsi << "\t new: ");
|
---|
[fa649a] | 216 | cin >> config::ProcPEPsi;
|
---|
| 217 | break;
|
---|
| 218 | case 'F': // DoOutVis
|
---|
[a67d19] | 219 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutVis << "\t new: ");
|
---|
[fa649a] | 220 | cin >> config::DoOutVis;
|
---|
| 221 | break;
|
---|
| 222 | case 'G': // DoOutMes
|
---|
[a67d19] | 223 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutMes << "\t new: ");
|
---|
[fa649a] | 224 | cin >> config::DoOutMes;
|
---|
| 225 | break;
|
---|
| 226 | case 'H': // DoOutOrbitals
|
---|
[a67d19] | 227 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutOrbitals << "\t new: ");
|
---|
[fa649a] | 228 | cin >> config::DoOutOrbitals;
|
---|
| 229 | break;
|
---|
| 230 | case 'I': // DoOutCurrent
|
---|
[a67d19] | 231 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutCurrent << "\t new: ");
|
---|
[fa649a] | 232 | cin >> config::DoOutCurrent;
|
---|
| 233 | break;
|
---|
| 234 | case 'J': // DoFullCurrent
|
---|
[a67d19] | 235 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoFullCurrent << "\t new: ");
|
---|
[fa649a] | 236 | cin >> config::DoFullCurrent;
|
---|
| 237 | break;
|
---|
| 238 | case 'K': // DoPerturbation
|
---|
[a67d19] | 239 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoPerturbation << "\t new: ");
|
---|
[fa649a] | 240 | cin >> config::DoPerturbation;
|
---|
| 241 | break;
|
---|
| 242 | case 'L': // CommonWannier
|
---|
[a67d19] | 243 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::CommonWannier << "\t new: ");
|
---|
[fa649a] | 244 | cin >> config::CommonWannier;
|
---|
| 245 | break;
|
---|
| 246 | case 'M': // SawtoothStart
|
---|
[a67d19] | 247 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::SawtoothStart << "\t new: ");
|
---|
[fa649a] | 248 | cin >> config::SawtoothStart;
|
---|
| 249 | break;
|
---|
| 250 | case 'N': // VectorPlane
|
---|
[a67d19] | 251 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::VectorPlane << "\t new: ");
|
---|
[fa649a] | 252 | cin >> config::VectorPlane;
|
---|
| 253 | break;
|
---|
| 254 | case 'O': // VectorCut
|
---|
[a67d19] | 255 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::VectorCut << "\t new: ");
|
---|
[fa649a] | 256 | cin >> config::VectorCut;
|
---|
| 257 | break;
|
---|
| 258 | case 'P': // UseAddGramSch
|
---|
[a67d19] | 259 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::UseAddGramSch << "\t new: ");
|
---|
[fa649a] | 260 | cin >> config::UseAddGramSch;
|
---|
| 261 | break;
|
---|
| 262 | case 'Q': // Seed
|
---|
[a67d19] | 263 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::Seed << "\t new: ");
|
---|
[fa649a] | 264 | cin >> config::Seed;
|
---|
| 265 | break;
|
---|
| 266 |
|
---|
| 267 | case 'R': // MaxOuterStep
|
---|
[a67d19] | 268 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxOuterStep << "\t new: ");
|
---|
[fa649a] | 269 | cin >> config::MaxOuterStep;
|
---|
| 270 | break;
|
---|
| 271 | case 'T': // OutVisStep
|
---|
[a67d19] | 272 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::OutVisStep << "\t new: ");
|
---|
[fa649a] | 273 | cin >> config::OutVisStep;
|
---|
| 274 | break;
|
---|
| 275 | case 'U': // OutSrcStep
|
---|
[a67d19] | 276 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::OutSrcStep << "\t new: ");
|
---|
[fa649a] | 277 | cin >> config::OutSrcStep;
|
---|
| 278 | break;
|
---|
| 279 | case 'X': // MaxPsiStep
|
---|
[a67d19] | 280 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxPsiStep << "\t new: ");
|
---|
[fa649a] | 281 | cin >> config::MaxPsiStep;
|
---|
| 282 | break;
|
---|
| 283 | case 'Y': // EpsWannier
|
---|
[a67d19] | 284 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::EpsWannier << "\t new: ");
|
---|
[fa649a] | 285 | cin >> config::EpsWannier;
|
---|
| 286 | break;
|
---|
| 287 |
|
---|
| 288 | case 'Z': // MaxMinStep
|
---|
[a67d19] | 289 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxMinStep << "\t new: ");
|
---|
[fa649a] | 290 | cin >> config::MaxMinStep;
|
---|
| 291 | break;
|
---|
| 292 | case 'a': // RelEpsTotalEnergy
|
---|
[a67d19] | 293 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelEpsTotalEnergy << "\t new: ");
|
---|
[fa649a] | 294 | cin >> config::RelEpsTotalEnergy;
|
---|
| 295 | break;
|
---|
| 296 | case 'b': // RelEpsKineticEnergy
|
---|
[a67d19] | 297 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelEpsKineticEnergy << "\t new: ");
|
---|
[fa649a] | 298 | cin >> config::RelEpsKineticEnergy;
|
---|
| 299 | break;
|
---|
| 300 | case 'c': // MaxMinStopStep
|
---|
[a67d19] | 301 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxMinStopStep << "\t new: ");
|
---|
[fa649a] | 302 | cin >> config::MaxMinStopStep;
|
---|
| 303 | break;
|
---|
| 304 | case 'e': // MaxInitMinStep
|
---|
[a67d19] | 305 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxInitMinStep << "\t new: ");
|
---|
[fa649a] | 306 | cin >> config::MaxInitMinStep;
|
---|
| 307 | break;
|
---|
| 308 | case 'f': // InitRelEpsTotalEnergy
|
---|
[a67d19] | 309 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitRelEpsTotalEnergy << "\t new: ");
|
---|
[fa649a] | 310 | cin >> config::InitRelEpsTotalEnergy;
|
---|
| 311 | break;
|
---|
| 312 | case 'g': // InitRelEpsKineticEnergy
|
---|
[a67d19] | 313 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitRelEpsKineticEnergy << "\t new: ");
|
---|
[fa649a] | 314 | cin >> config::InitRelEpsKineticEnergy;
|
---|
| 315 | break;
|
---|
| 316 | case 'h': // InitMaxMinStopStep
|
---|
[a67d19] | 317 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitMaxMinStopStep << "\t new: ");
|
---|
[fa649a] | 318 | cin >> config::InitMaxMinStopStep;
|
---|
| 319 | break;
|
---|
| 320 |
|
---|
| 321 | // case 'j': // BoxLength
|
---|
[e138de] | 322 | // Log() << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
|
---|
[5f612ee] | 323 | // double * const cell_size = World::getInstance().getDomain();
|
---|
[fa649a] | 324 | // for (int i=0;i<6;i++) {
|
---|
[e138de] | 325 | // Log() << Verbose(0) << "Cell size" << i << ": ";
|
---|
[b34306] | 326 | // cin >> cell_size[i];
|
---|
[fa649a] | 327 | // }
|
---|
| 328 | // break;
|
---|
| 329 |
|
---|
| 330 | case 'k': // ECut
|
---|
[a67d19] | 331 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ECut << "\t new: ");
|
---|
[fa649a] | 332 | cin >> config::ECut;
|
---|
| 333 | break;
|
---|
| 334 | case 'l': // MaxLevel
|
---|
[a67d19] | 335 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxLevel << "\t new: ");
|
---|
[fa649a] | 336 | cin >> config::MaxLevel;
|
---|
| 337 | break;
|
---|
| 338 | case 'm': // RiemannTensor
|
---|
[a67d19] | 339 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RiemannTensor << "\t new: ");
|
---|
[fa649a] | 340 | cin >> config::RiemannTensor;
|
---|
| 341 | break;
|
---|
| 342 | case 'n': // LevRFactor
|
---|
[a67d19] | 343 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::LevRFactor << "\t new: ");
|
---|
[fa649a] | 344 | cin >> config::LevRFactor;
|
---|
| 345 | break;
|
---|
| 346 | case 'o': // RiemannLevel
|
---|
[a67d19] | 347 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RiemannLevel << "\t new: ");
|
---|
[fa649a] | 348 | cin >> config::RiemannLevel;
|
---|
| 349 | break;
|
---|
| 350 | case 'p': // Lev0Factor
|
---|
[a67d19] | 351 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::Lev0Factor << "\t new: ");
|
---|
[fa649a] | 352 | cin >> config::Lev0Factor;
|
---|
| 353 | break;
|
---|
| 354 | case 'r': // RTActualUse
|
---|
[a67d19] | 355 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RTActualUse << "\t new: ");
|
---|
[fa649a] | 356 | cin >> config::RTActualUse;
|
---|
| 357 | break;
|
---|
| 358 | case 's': // PsiType
|
---|
[a67d19] | 359 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiType << "\t new: ");
|
---|
[fa649a] | 360 | cin >> config::PsiType;
|
---|
| 361 | break;
|
---|
| 362 | case 't': // MaxPsiDouble
|
---|
[a67d19] | 363 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxPsiDouble << "\t new: ");
|
---|
[fa649a] | 364 | cin >> config::MaxPsiDouble;
|
---|
| 365 | break;
|
---|
| 366 | case 'u': // PsiMaxNoUp
|
---|
[a67d19] | 367 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiMaxNoUp << "\t new: ");
|
---|
[fa649a] | 368 | cin >> config::PsiMaxNoUp;
|
---|
| 369 | break;
|
---|
| 370 | case 'v': // PsiMaxNoDown
|
---|
[a67d19] | 371 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiMaxNoDown << "\t new: ");
|
---|
[fa649a] | 372 | cin >> config::PsiMaxNoDown;
|
---|
| 373 | break;
|
---|
| 374 | case 'w': // AddPsis
|
---|
[a67d19] | 375 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::AddPsis << "\t new: ");
|
---|
[fa649a] | 376 | cin >> config::AddPsis;
|
---|
| 377 | break;
|
---|
| 378 |
|
---|
| 379 | case 'x': // RCut
|
---|
[a67d19] | 380 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RCut << "\t new: ");
|
---|
[fa649a] | 381 | cin >> config::RCut;
|
---|
| 382 | break;
|
---|
| 383 | case 'y': // StructOpt
|
---|
[a67d19] | 384 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::StructOpt << "\t new: ");
|
---|
[fa649a] | 385 | cin >> config::StructOpt;
|
---|
| 386 | break;
|
---|
| 387 | case 'z': // IsAngstroem
|
---|
[a67d19] | 388 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::IsAngstroem << "\t new: ");
|
---|
[fa649a] | 389 | cin >> config::IsAngstroem;
|
---|
| 390 | break;
|
---|
| 391 | case 'i': // RelativeCoord
|
---|
[a67d19] | 392 | DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelativeCoord << "\t new: ");
|
---|
[fa649a] | 393 | cin >> config::RelativeCoord;
|
---|
| 394 | break;
|
---|
| 395 | };
|
---|
| 396 | } while (choice != 'q');
|
---|
| 397 | };
|
---|
| 398 |
|
---|
| 399 | /** Tests whether a given configuration file adhears to old or new syntax.
|
---|
| 400 | * \param *filename filename of config file to be tested
|
---|
| 401 | * \param *periode pointer to a periodentafel class with all elements
|
---|
| 402 | * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
|
---|
| 403 | */
|
---|
| 404 | int config::TestSyntax(const char * const filename, const periodentafel * const periode) const
|
---|
| 405 | {
|
---|
| 406 | int test;
|
---|
| 407 | ifstream file(filename);
|
---|
| 408 |
|
---|
| 409 | // search file for keyword: ProcPEGamma (new syntax)
|
---|
| 410 | if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) {
|
---|
| 411 | file.close();
|
---|
| 412 | return 1;
|
---|
| 413 | }
|
---|
| 414 | // search file for keyword: ProcsGammaPsi (old syntax)
|
---|
| 415 | if (ParseForParameter(1,&file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional)) {
|
---|
| 416 | file.close();
|
---|
| 417 | return 0;
|
---|
| 418 | }
|
---|
| 419 | file.close();
|
---|
| 420 | return -1;
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | /** Returns private config::IsAngstroem.
|
---|
| 424 | * \return IsAngstroem
|
---|
| 425 | */
|
---|
| 426 | bool config::GetIsAngstroem() const
|
---|
| 427 | {
|
---|
| 428 | return (IsAngstroem == 1);
|
---|
| 429 | };
|
---|
| 430 |
|
---|
| 431 | /** Returns private config::*defaultpath.
|
---|
| 432 | * \return *defaultpath
|
---|
| 433 | */
|
---|
| 434 | char * config::GetDefaultPath() const
|
---|
| 435 | {
|
---|
| 436 | return defaultpath;
|
---|
| 437 | };
|
---|
| 438 |
|
---|
| 439 |
|
---|
| 440 | /** Returns private config::*defaultpath.
|
---|
| 441 | * \return *defaultpath
|
---|
| 442 | */
|
---|
| 443 | void config::SetDefaultPath(const char * const path)
|
---|
| 444 | {
|
---|
| 445 | strcpy(defaultpath, path);
|
---|
| 446 | };
|
---|
| 447 |
|
---|
| 448 | /** Loads a molecule from a ConfigFileBuffer.
|
---|
| 449 | * \param *mol molecule to load
|
---|
| 450 | * \param *FileBuffer ConfigFileBuffer to use
|
---|
| 451 | * \param *periode periodentafel for finding elements
|
---|
[3a9fe9] | 452 | * \param FastParsing whether to parse trajectories or not
|
---|
[fa649a] | 453 | */
|
---|
| 454 | void LoadMolecule(molecule * const &mol, struct ConfigFileBuffer * const &FileBuffer, const periodentafel * const periode, const bool FastParsing)
|
---|
| 455 | {
|
---|
| 456 | int MaxTypes = 0;
|
---|
[ead4e6] | 457 | const element *elementhash[MAX_ELEMENTS];
|
---|
[6a465e] | 458 | char name[MAXSTRINGSIZE];
|
---|
[fa649a] | 459 | int Z = -1;
|
---|
| 460 | int No[MAX_ELEMENTS];
|
---|
[6a465e] | 461 | int verbose = DoLog(4);
|
---|
[fa649a] | 462 | double value[3];
|
---|
| 463 |
|
---|
| 464 | if (mol == NULL) {
|
---|
[4d5553] | 465 | ELOG(0, "Molecule is not allocated in LoadMolecule(), exit.");
|
---|
[fa649a] | 466 | performCriticalExit();
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(MaxTypes), 1, critical);
|
---|
| 470 | if (MaxTypes == 0) {
|
---|
[4d5553] | 471 | ELOG(1, "There are no atoms according to MaxTypes in this config file." << endl);
|
---|
[c5805a] | 472 | //performCriticalExit();
|
---|
[fa649a] | 473 | } else {
|
---|
| 474 | // prescan number of ions per type
|
---|
[4d5553] | 475 | LOG(0, "STATUS: Prescanning ions per type: " << endl);
|
---|
[fa649a] | 476 | int NoAtoms = 0;
|
---|
| 477 | for (int i=0; i < MaxTypes; i++) {
|
---|
| 478 | sprintf(name,"Ion_Type%i",i+1);
|
---|
| 479 | ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
|
---|
| 480 | ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical);
|
---|
| 481 | elementhash[i] = periode->FindElement(Z);
|
---|
[83f176] | 482 | DoLog(1) && (Log() << Verbose(1) << i << ". Z = " << elementhash[i]->getAtomicNumber() << " with " << No[i] << " ions." << endl);
|
---|
[fa649a] | 483 | NoAtoms += No[i];
|
---|
| 484 | }
|
---|
[6a465e] | 485 | int repetition = -1; // which repeated keyword shall be read
|
---|
[fa649a] | 486 |
|
---|
| 487 | // sort the lines via the LineMapping
|
---|
| 488 | sprintf(name,"Ion_Type%i",MaxTypes);
|
---|
| 489 | if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) {
|
---|
[4d5553] | 490 | ELOG(0, "There are no atoms in the config file!" << endl);
|
---|
[e359a8] | 491 | performCriticalExit();
|
---|
[fa649a] | 492 | return;
|
---|
| 493 | }
|
---|
[fcac72] | 494 |
|
---|
| 495 | FileBuffer->CurrentLine++; // skip to next line
|
---|
[fa649a] | 496 | FileBuffer->MapIonTypesInBuffer(NoAtoms);
|
---|
[6a465e] | 497 | for (int i=FileBuffer->CurrentLine; i<FileBuffer->NoLines;++i) {
|
---|
[4d5553] | 498 | LOG(4, FileBuffer->buffer[ FileBuffer->LineMapping[i] ]);
|
---|
[6a465e] | 499 | }
|
---|
[fa649a] | 500 |
|
---|
| 501 | map<int, atom *> AtomList[MaxTypes];
|
---|
| 502 | map<int, atom *> LinearList;
|
---|
| 503 | atom *neues = NULL;
|
---|
[6a465e] | 504 | Vector tempVector;
|
---|
| 505 | int _fixedion;
|
---|
| 506 |
|
---|
| 507 | typedef boost::tokenizer<boost::char_separator<char> >
|
---|
| 508 | tokenizer;
|
---|
| 509 | boost::char_separator<char> sep("\t ");
|
---|
| 510 | ConvertTo<double> toDouble;
|
---|
| 511 | ConvertTo<int> toInt;
|
---|
[fa649a] | 512 |
|
---|
[6a465e] | 513 | for (int i=0; i < MaxTypes; i++) {
|
---|
| 514 | for(int j=0;j<No[i];j++) {
|
---|
| 515 | int step = 0;
|
---|
| 516 | std::stringstream keyword_stream;
|
---|
| 517 | keyword_stream << "Ion_Type" << i+1 << "_" << j+1;
|
---|
| 518 | const std::string keyword = keyword_stream.str();
|
---|
[4d5553] | 519 | LOG(3, "INFO: Parsing for " << keyword << "." << std::endl);
|
---|
[6a465e] | 520 | while (true) {
|
---|
| 521 | const std::string line(FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ]);
|
---|
| 522 | const std::string line_without_comment = line.substr(0,line.find("#"));
|
---|
| 523 | tokenizer tokens(line_without_comment, sep);
|
---|
| 524 | if (tokens.begin() != tokens.end()) {
|
---|
| 525 | tokenizer::iterator tok_iter = tokens.begin();
|
---|
| 526 | const std::string token = *tok_iter++;
|
---|
| 527 | if (token == keyword) {
|
---|
[4d5553] | 528 | LOG(3, "INFO: Found keyword " << keyword << " in line " << FileBuffer->CurrentLine << std::endl);
|
---|
[6a465e] | 529 | if (step == 0) {
|
---|
| 530 | neues = World::getInstance().createAtom();
|
---|
| 531 | AtomList[i][j] = neues;
|
---|
[4d5553] | 532 | LOG(4, "Filling LinearList [ (FileBuffer->LineMapping[" << FileBuffer->CurrentLine << "]) = " << FileBuffer->LineMapping[FileBuffer->CurrentLine] << " with " << neues << endl);
|
---|
[6a465e] | 533 | LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
|
---|
| 534 | neues->setType(elementhash[i]); // find element type
|
---|
| 535 | } else
|
---|
| 536 | neues = AtomList[i][j];
|
---|
| 537 |
|
---|
| 538 | // count tokens
|
---|
| 539 | size_t tokens_size = 0;
|
---|
| 540 | for (tokenizer::iterator tokiter = tokens.begin(); tokiter != tokens.end(); ++tokiter)
|
---|
| 541 | ++tokens_size;
|
---|
[4d5553] | 542 | LOG(3, "INFO: Line contains " << tokens_size << " tokens." << std::endl);
|
---|
[6a465e] | 543 | // and parse
|
---|
[fcac72] | 544 | tempVector.Zero();
|
---|
[6a465e] | 545 | if (tokens_size >= 5) { // only AtomicPosition and FixedIon
|
---|
| 546 | for (int i=0;i<NDIM;++i)
|
---|
| 547 | tempVector[i] = toDouble(*tok_iter++);
|
---|
| 548 | neues->setPositionAtStep(step, tempVector);
|
---|
| 549 | _fixedion = toInt(*tok_iter++);
|
---|
| 550 | neues->setFixedIon(_fixedion == 1);
|
---|
[4d5553] | 551 | LOG(3, "INFO: Parsing AtomicPosition " << tempVector << " and FixedIon " << _fixedion << "." << std::endl);
|
---|
[6a465e] | 552 | }
|
---|
[fcac72] | 553 | tempVector.Zero();
|
---|
[6a465e] | 554 | if (tokens_size >= 8) { // AtomicVelocity
|
---|
| 555 | for (int i=0;i<NDIM;++i)
|
---|
| 556 | tempVector[i] = toDouble(*tok_iter++);
|
---|
[4d5553] | 557 | LOG(3, "INFO: Parsing AtomicVelocity " << tempVector << "." << std::endl);
|
---|
[6a465e] | 558 | }
|
---|
[fcac72] | 559 | neues->setAtomicVelocityAtStep(step, tempVector);
|
---|
| 560 | tempVector.Zero();
|
---|
[6a465e] | 561 | if (tokens_size >= 11) { // AtomicForce
|
---|
[4d5553] | 562 | LOG(3, "INFO: Parsing AtomicForce" << std::endl);
|
---|
[6a465e] | 563 | for (int i=0;i<NDIM;++i)
|
---|
| 564 | tempVector[i] = toDouble(*tok_iter++);
|
---|
| 565 | }
|
---|
[fcac72] | 566 | neues->setAtomicForceAtStep(step, tempVector);
|
---|
[6a465e] | 567 | std::stringstream output;
|
---|
| 568 | output << "Parsed position of step " << (step+1) << ": ";
|
---|
| 569 | output << neues->getPositionAtStep(step); // next step
|
---|
| 570 | output << "\t";
|
---|
| 571 | output << (neues->getFixedIon() ? "true" : "false");
|
---|
| 572 | output << "\t";
|
---|
| 573 | output << neues->getAtomicVelocityAtStep(step); // next step
|
---|
| 574 | output << "\t";
|
---|
| 575 | output << neues->getAtomicForceAtStep(step); // next step
|
---|
| 576 | DoLog(2) && (Log() << Verbose(2) << output.str() << endl);
|
---|
| 577 |
|
---|
| 578 | step++;
|
---|
| 579 | } else {
|
---|
| 580 | if ((repetition > step) || (repetition == -1))
|
---|
| 581 | repetition = step;
|
---|
| 582 | break;
|
---|
[fa649a] | 583 | }
|
---|
| 584 | }
|
---|
[6a465e] | 585 | FileBuffer->CurrentLine++;
|
---|
[fa649a] | 586 | }
|
---|
| 587 | }
|
---|
| 588 | }
|
---|
[6a465e] | 589 |
|
---|
| 590 | if (repetition <= 1) // if onyl one step, desactivate use of trajectories
|
---|
| 591 | mol->MDSteps = 0;
|
---|
| 592 | else {
|
---|
| 593 | DoLog(0) && (Log() << Verbose(0) << "Found " << repetition << " trajectory step(s)." << endl);
|
---|
| 594 | mol->MDSteps = repetition;
|
---|
| 595 | }
|
---|
| 596 |
|
---|
[fa649a] | 597 | // put atoms into the molecule in their original order
|
---|
| 598 | for(map<int, atom*>::iterator runner = LinearList.begin(); runner != LinearList.end(); ++runner) {
|
---|
| 599 | mol->AddAtom(runner->second);
|
---|
| 600 | }
|
---|
| 601 | }
|
---|
| 602 | };
|
---|
| 603 |
|
---|
| 604 | /** Stores all elements of config structure from which they can be re-read.
|
---|
| 605 | * \param *filename name of file
|
---|
| 606 | * \param *periode pointer to a periodentafel class with all elements
|
---|
| 607 | * \param *mol pointer to molecule containing all atoms of the molecule
|
---|
| 608 | */
|
---|
| 609 | bool config::Save(const char * const filename, const periodentafel * const periode, molecule * const mol) const
|
---|
| 610 | {
|
---|
| 611 | bool result = true;
|
---|
[cca9ef] | 612 | const RealSpaceMatrix &domain = World::getInstance().getDomain().getM();
|
---|
[1bfc8e] | 613 | ThermoStatContainer *Thermostats = World::getInstance().getThermostats();
|
---|
[fa649a] | 614 | ofstream * const output = new ofstream(filename, ios::out);
|
---|
| 615 | if (output != NULL) {
|
---|
| 616 | *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
|
---|
| 617 | *output << endl;
|
---|
| 618 | *output << "mainname\t" << config::mainname << "\t# programm name (for runtime files)" << endl;
|
---|
| 619 | *output << "defaultpath\t" << config::defaultpath << "\t# where to put files during runtime" << endl;
|
---|
| 620 | *output << "pseudopotpath\t" << config::pseudopotpath << "\t# where to find pseudopotentials" << endl;
|
---|
| 621 | *output << endl;
|
---|
| 622 | *output << "ProcPEGamma\t" << config::ProcPEGamma << "\t# for parallel computing: share constants" << endl;
|
---|
| 623 | *output << "ProcPEPsi\t" << config::ProcPEPsi << "\t# for parallel computing: share wave functions" << endl;
|
---|
| 624 | *output << "DoOutVis\t" << config::DoOutVis << "\t# Output data for OpenDX" << endl;
|
---|
| 625 | *output << "DoOutMes\t" << config::DoOutMes << "\t# Output data for measurements" << endl;
|
---|
| 626 | *output << "DoOutOrbitals\t" << config::DoOutOrbitals << "\t# Output all Orbitals" << endl;
|
---|
| 627 | *output << "DoOutCurr\t" << config::DoOutCurrent << "\t# Ouput current density for OpenDx" << endl;
|
---|
| 628 | *output << "DoOutNICS\t" << config::DoOutNICS << "\t# Output Nucleus independent current shieldings" << endl;
|
---|
| 629 | *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
|
---|
| 630 | *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
|
---|
| 631 | *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
|
---|
[14c57a] | 632 | *output << "Thermostat\t" << Thermostats->activeThermostat->name() << "\t";
|
---|
| 633 | *output << Thermostats->activeThermostat->writeParams();
|
---|
[fa649a] | 634 | *output << "\t# Which Thermostat and its parameters to use in MD case." << endl;
|
---|
| 635 | *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
|
---|
| 636 | *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
|
---|
| 637 | *output << "VectorPlane\t" << config::VectorPlane << "\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot" << endl;
|
---|
| 638 | *output << "VectorCut\t" << config::VectorCut << "\t# Cut plane axis value" << endl;
|
---|
| 639 | *output << "AddGramSch\t" << config::UseAddGramSch << "\t# Additional GramSchmidtOrtogonalization to be safe" << endl;
|
---|
| 640 | *output << "Seed\t\t" << config::Seed << "\t# initial value for random seed for Psi coefficients" << endl;
|
---|
| 641 | *output << endl;
|
---|
| 642 | *output << "MaxOuterStep\t" << config::MaxOuterStep << "\t# number of MolecularDynamics/Structure optimization steps" << endl;
|
---|
| 643 | *output << "Deltat\t" << config::Deltat << "\t# time per MD step" << endl;
|
---|
| 644 | *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
|
---|
| 645 | *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
|
---|
[a3fded] | 646 | *output << "TargetTemp\t" << Thermostats->TargetTemp << "\t# Target temperature" << endl;
|
---|
[fa649a] | 647 | *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
|
---|
| 648 | *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
|
---|
| 649 | *output << endl;
|
---|
| 650 | *output << "# Values specifying when to stop" << endl;
|
---|
| 651 | *output << "MaxMinStep\t" << config::MaxMinStep << "\t# Maximum number of steps" << endl;
|
---|
| 652 | *output << "RelEpsTotalE\t" << config::RelEpsTotalEnergy << "\t# relative change in total energy" << endl;
|
---|
| 653 | *output << "RelEpsKineticE\t" << config::RelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
|
---|
| 654 | *output << "MaxMinStopStep\t" << config::MaxMinStopStep << "\t# check every ..th steps" << endl;
|
---|
| 655 | *output << "MaxMinGapStopStep\t" << config::MaxMinGapStopStep << "\t# check every ..th steps" << endl;
|
---|
| 656 | *output << endl;
|
---|
| 657 | *output << "# Values specifying when to stop for INIT, otherwise same as above" << endl;
|
---|
| 658 | *output << "MaxInitMinStep\t" << config::MaxInitMinStep << "\t# Maximum number of steps" << endl;
|
---|
| 659 | *output << "InitRelEpsTotalE\t" << config::InitRelEpsTotalEnergy << "\t# relative change in total energy" << endl;
|
---|
| 660 | *output << "InitRelEpsKineticE\t" << config::InitRelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
|
---|
| 661 | *output << "InitMaxMinStopStep\t" << config::InitMaxMinStopStep << "\t# check every ..th steps" << endl;
|
---|
| 662 | *output << "InitMaxMinGapStopStep\t" << config::InitMaxMinGapStopStep << "\t# check every ..th steps" << endl;
|
---|
| 663 | *output << endl;
|
---|
| 664 | *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
|
---|
[84c494] | 665 | *output << domain.at(0,0) << "\t" << endl;
|
---|
| 666 | *output << domain.at(1,0) << "\t" << domain.at(1,1) << "\t" << endl;
|
---|
| 667 | *output << domain.at(2,0) << "\t" << domain.at(2,1) << "\t" << domain.at(2,2) << "\t" << endl;
|
---|
[fa649a] | 668 | // FIXME
|
---|
| 669 | *output << endl;
|
---|
| 670 | *output << "ECut\t\t" << config::ECut << "\t# energy cutoff for discretization in Hartrees" << endl;
|
---|
| 671 | *output << "MaxLevel\t" << config::MaxLevel << "\t# number of different levels in the code, >=2" << endl;
|
---|
| 672 | *output << "Level0Factor\t" << config::Lev0Factor << "\t# factor by which node number increases from S to 0 level" << endl;
|
---|
| 673 | *output << "RiemannTensor\t" << config::RiemannTensor << "\t# (Use metric)" << endl;
|
---|
| 674 | switch (config::RiemannTensor) {
|
---|
| 675 | case 0: //UseNoRT
|
---|
| 676 | break;
|
---|
| 677 | case 1: // UseRT
|
---|
| 678 | *output << "RiemannLevel\t" << config::RiemannLevel << "\t# Number of Riemann Levels" << endl;
|
---|
| 679 | *output << "LevRFactor\t" << config::LevRFactor << "\t# factor by which node number increases from 0 to R level from" << endl;
|
---|
| 680 | break;
|
---|
| 681 | }
|
---|
| 682 | *output << "PsiType\t\t" << config::PsiType << "\t# 0 - doubly occupied, 1 - SpinUp,SpinDown" << endl;
|
---|
| 683 | // write out both types for easier changing afterwards
|
---|
| 684 | // switch (PsiType) {
|
---|
| 685 | // case 0:
|
---|
| 686 | *output << "MaxPsiDouble\t" << config::MaxPsiDouble << "\t# here: specifying both maximum number of SpinUp- and -Down-states" << endl;
|
---|
| 687 | // break;
|
---|
| 688 | // case 1:
|
---|
| 689 | *output << "PsiMaxNoUp\t" << config::PsiMaxNoUp << "\t# here: specifying maximum number of SpinUp-states" << endl;
|
---|
| 690 | *output << "PsiMaxNoDown\t" << config::PsiMaxNoDown << "\t# here: specifying maximum number of SpinDown-states" << endl;
|
---|
| 691 | // break;
|
---|
| 692 | // }
|
---|
| 693 | *output << "AddPsis\t\t" << config::AddPsis << "\t# Additional unoccupied Psis for bandgap determination" << endl;
|
---|
| 694 | *output << endl;
|
---|
| 695 | *output << "RCut\t\t" << config::RCut << "\t# R-cut for the ewald summation" << endl;
|
---|
| 696 | *output << "StructOpt\t" << config::StructOpt << "\t# Do structure optimization beforehand" << endl;
|
---|
| 697 | *output << "IsAngstroem\t" << config::IsAngstroem << "\t# 0 - Bohr, 1 - Angstroem" << endl;
|
---|
| 698 | *output << "RelativeCoord\t" << config::RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
|
---|
[389cc8] | 699 | *output << "MaxTypes\t" << mol->getElementCount() << "\t# maximum number of different ion types" << endl;
|
---|
[fa649a] | 700 | *output << endl;
|
---|
| 701 | result = result && mol->Checkout(output);
|
---|
| 702 | if (mol->MDSteps <=1 )
|
---|
| 703 | result = result && mol->Output(output);
|
---|
| 704 | else
|
---|
| 705 | result = result && mol->OutputTrajectories(output);
|
---|
| 706 | output->close();
|
---|
| 707 | output->clear();
|
---|
| 708 | delete(output);
|
---|
| 709 | return result;
|
---|
[568be7] | 710 | } else {
|
---|
[58ed4a] | 711 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open output file:" << filename << endl);
|
---|
[fa649a] | 712 | return false;
|
---|
[568be7] | 713 | }
|
---|
[fa649a] | 714 | };
|
---|
| 715 |
|
---|
| 716 | /** Stores all elements in a MPQC input file.
|
---|
| 717 | * Note that this format cannot be parsed again.
|
---|
| 718 | * \param *filename name of file (without ".in" suffix!)
|
---|
| 719 | * \param *mol pointer to molecule containing all atoms of the molecule
|
---|
| 720 | */
|
---|
| 721 | bool config::SaveMPQC(const char * const filename, const molecule * const mol) const
|
---|
| 722 | {
|
---|
| 723 | Vector *center = NULL;
|
---|
| 724 | ofstream *output = NULL;
|
---|
| 725 |
|
---|
| 726 | // first without hessian
|
---|
| 727 | {
|
---|
| 728 | stringstream * const fname = new stringstream;;
|
---|
| 729 | *fname << filename << ".in";
|
---|
| 730 | output = new ofstream(fname->str().c_str(), ios::out);
|
---|
[568be7] | 731 | if (output == NULL) {
|
---|
[58ed4a] | 732 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file:" << fname << endl);
|
---|
[568be7] | 733 | delete(fname);
|
---|
| 734 | return false;
|
---|
| 735 | }
|
---|
[fa649a] | 736 | *output << "% Created by MoleCuilder" << endl;
|
---|
| 737 | *output << "mpqc: (" << endl;
|
---|
| 738 | *output << "\tsavestate = no" << endl;
|
---|
| 739 | *output << "\tdo_gradient = yes" << endl;
|
---|
| 740 | *output << "\tmole<MBPT2>: (" << endl;
|
---|
| 741 | *output << "\t\tmaxiter = 200" << endl;
|
---|
| 742 | *output << "\t\tbasis = $:basis" << endl;
|
---|
| 743 | *output << "\t\tmolecule = $:molecule" << endl;
|
---|
| 744 | *output << "\t\treference<CLHF>: (" << endl;
|
---|
| 745 | *output << "\t\t\tbasis = $:basis" << endl;
|
---|
| 746 | *output << "\t\t\tmolecule = $:molecule" << endl;
|
---|
| 747 | *output << "\t\t)" << endl;
|
---|
| 748 | *output << "\t)" << endl;
|
---|
| 749 | *output << ")" << endl;
|
---|
| 750 | *output << "molecule<Molecule>: (" << endl;
|
---|
| 751 | *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
|
---|
| 752 | *output << "\t{ atoms geometry } = {" << endl;
|
---|
[e138de] | 753 | center = mol->DetermineCenterOfAll();
|
---|
[fa649a] | 754 | // output of atoms
|
---|
[9e7813] | 755 | for(molecule::const_iterator iter = mol->begin(); iter!=mol->end();++iter){
|
---|
| 756 | (*iter)->OutputMPQCLine(output,center);
|
---|
| 757 | }
|
---|
[fa649a] | 758 | delete(center);
|
---|
| 759 | *output << "\t}" << endl;
|
---|
| 760 | *output << ")" << endl;
|
---|
| 761 | *output << "basis<GaussianBasisSet>: (" << endl;
|
---|
[1a6bda] | 762 | *output << "\tname = \"3-21G\"" << endl;
|
---|
[fa649a] | 763 | *output << "\tmolecule = $:molecule" << endl;
|
---|
| 764 | *output << ")" << endl;
|
---|
| 765 | output->close();
|
---|
| 766 | delete(output);
|
---|
| 767 | delete(fname);
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | // second with hessian
|
---|
| 771 | {
|
---|
| 772 | stringstream * const fname = new stringstream;
|
---|
| 773 | *fname << filename << ".hess.in";
|
---|
| 774 | output = new ofstream(fname->str().c_str(), ios::out);
|
---|
[568be7] | 775 | if (output == NULL) {
|
---|
[58ed4a] | 776 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc hessian output file:" << fname << endl);
|
---|
[568be7] | 777 | delete(fname);
|
---|
| 778 | return false;
|
---|
| 779 | }
|
---|
[fa649a] | 780 | *output << "% Created by MoleCuilder" << endl;
|
---|
| 781 | *output << "mpqc: (" << endl;
|
---|
| 782 | *output << "\tsavestate = no" << endl;
|
---|
| 783 | *output << "\tdo_gradient = yes" << endl;
|
---|
| 784 | *output << "\tmole<CLHF>: (" << endl;
|
---|
| 785 | *output << "\t\tmaxiter = 200" << endl;
|
---|
| 786 | *output << "\t\tbasis = $:basis" << endl;
|
---|
| 787 | *output << "\t\tmolecule = $:molecule" << endl;
|
---|
| 788 | *output << "\t)" << endl;
|
---|
| 789 | *output << "\tfreq<MolecularFrequencies>: (" << endl;
|
---|
| 790 | *output << "\t\tmolecule=$:molecule" << endl;
|
---|
| 791 | *output << "\t)" << endl;
|
---|
| 792 | *output << ")" << endl;
|
---|
| 793 | *output << "molecule<Molecule>: (" << endl;
|
---|
| 794 | *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
|
---|
| 795 | *output << "\t{ atoms geometry } = {" << endl;
|
---|
[e138de] | 796 | center = mol->DetermineCenterOfAll();
|
---|
[fa649a] | 797 | // output of atoms
|
---|
[9e7813] | 798 | for(molecule::const_iterator iter = mol->begin(); iter!=mol->end();++iter){
|
---|
| 799 | (*iter)->OutputMPQCLine(output,center);
|
---|
| 800 | }
|
---|
[fa649a] | 801 | delete(center);
|
---|
| 802 | *output << "\t}" << endl;
|
---|
| 803 | *output << ")" << endl;
|
---|
| 804 | *output << "basis<GaussianBasisSet>: (" << endl;
|
---|
| 805 | *output << "\tname = \"3-21G\"" << endl;
|
---|
| 806 | *output << "\tmolecule = $:molecule" << endl;
|
---|
| 807 | *output << ")" << endl;
|
---|
| 808 | output->close();
|
---|
| 809 | delete(output);
|
---|
| 810 | delete(fname);
|
---|
| 811 | }
|
---|
| 812 |
|
---|
| 813 | return true;
|
---|
| 814 | };
|
---|
| 815 |
|
---|
[568be7] | 816 | /** Stores all atoms from all molecules in a PDB input file.
|
---|
| 817 | * Note that this format cannot be parsed again.
|
---|
| 818 | * \param *filename name of file (without ".in" suffix!)
|
---|
| 819 | * \param *MolList pointer to MoleculeListClass containing all atoms
|
---|
| 820 | */
|
---|
| 821 | bool config::SavePDB(const char * const filename, const MoleculeListClass * const MolList) const
|
---|
| 822 | {
|
---|
| 823 | int AtomNo = -1;
|
---|
| 824 | int MolNo = 0;
|
---|
| 825 | FILE *f = NULL;
|
---|
| 826 |
|
---|
| 827 | char name[MAXSTRINGSIZE];
|
---|
| 828 | strncpy(name, filename, MAXSTRINGSIZE-1);
|
---|
| 829 | strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
|
---|
| 830 | f = fopen(name, "w" );
|
---|
| 831 | if (f == NULL) {
|
---|
[58ed4a] | 832 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
|
---|
[568be7] | 833 | return false;
|
---|
| 834 | }
|
---|
| 835 | fprintf(f, "# Created by MoleCuilder\n");
|
---|
| 836 |
|
---|
[9879f6] | 837 | for (MoleculeList::const_iterator MolRunner = MolList->ListOfMolecules.begin(); MolRunner != MolList->ListOfMolecules.end(); MolRunner++) {
|
---|
[920c70] | 838 | int *elementNo = new int[MAX_ELEMENTS];
|
---|
| 839 | for (int i=0;i<MAX_ELEMENTS;i++)
|
---|
| 840 | elementNo[i] = 0;
|
---|
[568be7] | 841 | AtomNo = 0;
|
---|
[9879f6] | 842 | for (molecule::const_iterator iter = (*MolRunner)->begin(); iter != (*MolRunner)->end(); ++iter) {
|
---|
[83f176] | 843 | sprintf(name, "%2s%2d",(*iter)->getType()->getSymbol().c_str(), elementNo[(*iter)->getType()->getAtomicNumber()]);
|
---|
| 844 | elementNo[(*iter)->getType()->getAtomicNumber()] = (elementNo[(*iter)->getType()->getAtomicNumber()]+1) % 100; // confine to two digits
|
---|
[568be7] | 845 | fprintf(f,
|
---|
| 846 | "ATOM %6u %-4s %4s%c%4u %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%2s\n",
|
---|
[735b1c] | 847 | (*iter)->getNr(), /* atom serial number */
|
---|
[568be7] | 848 | name, /* atom name */
|
---|
[9879f6] | 849 | (*MolRunner)->name, /* residue name */
|
---|
[568be7] | 850 | 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */
|
---|
| 851 | MolNo, /* residue sequence number */
|
---|
[d74077] | 852 | (*iter)->at(0), /* position X in Angstroem */
|
---|
| 853 | (*iter)->at(1), /* position Y in Angstroem */
|
---|
| 854 | (*iter)->at(2), /* position Z in Angstroem */
|
---|
[83f176] | 855 | (double)(*iter)->getType()->getValence(), /* occupancy */
|
---|
| 856 | (double)(*iter)->getType()->getNoValenceOrbitals(), /* temperature factor */
|
---|
[568be7] | 857 | "0", /* segment identifier */
|
---|
[b5c53d] | 858 | (*iter)->getType()->getSymbol().c_str(), /* element symbol */
|
---|
[568be7] | 859 | "0"); /* charge */
|
---|
| 860 | AtomNo++;
|
---|
| 861 | }
|
---|
[920c70] | 862 | delete[](elementNo);
|
---|
[568be7] | 863 | MolNo++;
|
---|
| 864 | }
|
---|
| 865 | fclose(f);
|
---|
| 866 |
|
---|
| 867 | return true;
|
---|
| 868 | };
|
---|
| 869 |
|
---|
| 870 | /** Stores all atoms in a PDB input file.
|
---|
| 871 | * Note that this format cannot be parsed again.
|
---|
| 872 | * \param *filename name of file (without ".in" suffix!)
|
---|
| 873 | * \param *mol pointer to molecule
|
---|
| 874 | */
|
---|
| 875 | bool config::SavePDB(const char * const filename, const molecule * const mol) const
|
---|
| 876 | {
|
---|
| 877 | int AtomNo = -1;
|
---|
| 878 | FILE *f = NULL;
|
---|
| 879 |
|
---|
[920c70] | 880 | int *elementNo = new int[MAX_ELEMENTS];
|
---|
| 881 | for (int i=0;i<MAX_ELEMENTS;i++)
|
---|
| 882 | elementNo[i] = 0;
|
---|
[568be7] | 883 | char name[MAXSTRINGSIZE];
|
---|
| 884 | strncpy(name, filename, MAXSTRINGSIZE-1);
|
---|
| 885 | strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
|
---|
| 886 | f = fopen(name, "w" );
|
---|
| 887 | if (f == NULL) {
|
---|
[58ed4a] | 888 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
|
---|
[920c70] | 889 | delete[](elementNo);
|
---|
[568be7] | 890 | return false;
|
---|
| 891 | }
|
---|
| 892 | fprintf(f, "# Created by MoleCuilder\n");
|
---|
| 893 |
|
---|
| 894 | AtomNo = 0;
|
---|
[9879f6] | 895 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
[83f176] | 896 | sprintf(name, "%2s%2d",(*iter)->getType()->getSymbol().c_str(), elementNo[(*iter)->getType()->getAtomicNumber()]);
|
---|
| 897 | elementNo[(*iter)->getType()->getAtomicNumber()] = (elementNo[(*iter)->getType()->getAtomicNumber()]+1) % 100; // confine to two digits
|
---|
[568be7] | 898 | fprintf(f,
|
---|
| 899 | "ATOM %6u %-4s %4s%c%4u %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%2s\n",
|
---|
[735b1c] | 900 | (*iter)->getNr(), /* atom serial number */
|
---|
[568be7] | 901 | name, /* atom name */
|
---|
| 902 | mol->name, /* residue name */
|
---|
| 903 | 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */
|
---|
| 904 | 0, /* residue sequence number */
|
---|
[d74077] | 905 | (*iter)->at(0), /* position X in Angstroem */
|
---|
| 906 | (*iter)->at(1), /* position Y in Angstroem */
|
---|
| 907 | (*iter)->at(2), /* position Z in Angstroem */
|
---|
[83f176] | 908 | (double)(*iter)->getType()->getValence(), /* occupancy */
|
---|
| 909 | (double)(*iter)->getType()->getNoValenceOrbitals(), /* temperature factor */
|
---|
[568be7] | 910 | "0", /* segment identifier */
|
---|
[b5c53d] | 911 | (*iter)->getType()->getSymbol().c_str(), /* element symbol */
|
---|
[568be7] | 912 | "0"); /* charge */
|
---|
| 913 | AtomNo++;
|
---|
| 914 | }
|
---|
| 915 | fclose(f);
|
---|
[920c70] | 916 | delete[](elementNo);
|
---|
[568be7] | 917 |
|
---|
| 918 | return true;
|
---|
| 919 | };
|
---|
| 920 |
|
---|
| 921 | /** Stores all atoms in a TREMOLO data input file.
|
---|
| 922 | * Note that this format cannot be parsed again.
|
---|
[6e6e10] | 923 | * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
|
---|
[568be7] | 924 | * \param *filename name of file (without ".in" suffix!)
|
---|
| 925 | * \param *mol pointer to molecule
|
---|
| 926 | */
|
---|
| 927 | bool config::SaveTREMOLO(const char * const filename, const molecule * const mol) const
|
---|
| 928 | {
|
---|
| 929 | ofstream *output = NULL;
|
---|
| 930 | stringstream * const fname = new stringstream;
|
---|
| 931 |
|
---|
| 932 | *fname << filename << ".data";
|
---|
| 933 | output = new ofstream(fname->str().c_str(), ios::out);
|
---|
| 934 | if (output == NULL) {
|
---|
[58ed4a] | 935 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
|
---|
[568be7] | 936 | delete(fname);
|
---|
| 937 | return false;
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | // scan maximum number of neighbours
|
---|
| 941 | int MaxNeighbours = 0;
|
---|
[9879f6] | 942 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
[9d83b6] | 943 | const int count = (*iter)->getListOfBonds().size();
|
---|
[568be7] | 944 | if (MaxNeighbours < count)
|
---|
| 945 | MaxNeighbours = count;
|
---|
| 946 | }
|
---|
[9879f6] | 947 | *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
|
---|
[568be7] | 948 |
|
---|
[9879f6] | 949 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
[735b1c] | 950 | *output << (*iter)->getNr() << "\t";
|
---|
[a7b761b] | 951 | *output << (*iter)->getName() << "\t";
|
---|
[568be7] | 952 | *output << mol->name << "\t";
|
---|
| 953 | *output << 0 << "\t";
|
---|
[d74077] | 954 | *output << (*iter)->at(0) << "\t" << (*iter)->at(1) << "\t" << (*iter)->at(2) << "\t";
|
---|
[83f176] | 955 | *output << static_cast<double>((*iter)->getType()->getValence()) << "\t";
|
---|
[b5c53d] | 956 | *output << (*iter)->getType()->getSymbol() << "\t";
|
---|
[9d83b6] | 957 | const BondList& ListOfBonds = (*iter)->getListOfBonds();
|
---|
| 958 | for (BondList::const_iterator runner = ListOfBonds.begin();
|
---|
| 959 | runner != ListOfBonds.end();
|
---|
| 960 | runner++) {
|
---|
[735b1c] | 961 | *output << (*runner)->GetOtherAtom(*iter)->getNr() << "\t";
|
---|
[9d83b6] | 962 | }
|
---|
| 963 | for(int i = ListOfBonds.size(); i < MaxNeighbours; i++)
|
---|
[568be7] | 964 | *output << "-\t";
|
---|
| 965 | *output << endl;
|
---|
| 966 | }
|
---|
| 967 | output->flush();
|
---|
| 968 | output->close();
|
---|
| 969 | delete(output);
|
---|
| 970 | delete(fname);
|
---|
| 971 |
|
---|
| 972 | return true;
|
---|
| 973 | };
|
---|
| 974 |
|
---|
| 975 | /** Stores all atoms from all molecules in a TREMOLO data input file.
|
---|
| 976 | * Note that this format cannot be parsed again.
|
---|
[6e6e10] | 977 | * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
|
---|
[568be7] | 978 | * \param *filename name of file (without ".in" suffix!)
|
---|
| 979 | * \param *MolList pointer to MoleculeListClass containing all atoms
|
---|
| 980 | */
|
---|
| 981 | bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const
|
---|
| 982 | {
|
---|
[42af9e] | 983 | Info FunctionInfo(__func__);
|
---|
[568be7] | 984 | ofstream *output = NULL;
|
---|
| 985 | stringstream * const fname = new stringstream;
|
---|
| 986 |
|
---|
| 987 | *fname << filename << ".data";
|
---|
| 988 | output = new ofstream(fname->str().c_str(), ios::out);
|
---|
| 989 | if (output == NULL) {
|
---|
[58ed4a] | 990 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
|
---|
[568be7] | 991 | delete(fname);
|
---|
| 992 | return false;
|
---|
| 993 | }
|
---|
| 994 |
|
---|
| 995 | // scan maximum number of neighbours
|
---|
| 996 | int MaxNeighbours = 0;
|
---|
| 997 | for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
|
---|
[9879f6] | 998 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
[9d83b6] | 999 | const int count = (*iter)->getListOfBonds().size();
|
---|
[568be7] | 1000 | if (MaxNeighbours < count)
|
---|
| 1001 | MaxNeighbours = count;
|
---|
| 1002 | }
|
---|
| 1003 | }
|
---|
[9879f6] | 1004 | *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
|
---|
[568be7] | 1005 |
|
---|
| 1006 | // create global to local id map
|
---|
[42af9e] | 1007 | map<int, int> LocalNotoGlobalNoMap;
|
---|
[568be7] | 1008 | {
|
---|
[42af9e] | 1009 | unsigned int MolCounter = 0;
|
---|
| 1010 | int AtomNo = 1;
|
---|
[568be7] | 1011 | for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
|
---|
[1024cb] | 1012 | for(molecule::iterator AtomRunner = (*MolWalker)->begin(); AtomRunner != (*MolWalker)->end(); ++AtomRunner) {
|
---|
| 1013 | LocalNotoGlobalNoMap.insert( pair<int,int>((*AtomRunner)->getId(), AtomNo++) );
|
---|
[42af9e] | 1014 | }
|
---|
[568be7] | 1015 | MolCounter++;
|
---|
| 1016 | }
|
---|
[42af9e] | 1017 | ASSERT(MolCounter == MolList->ListOfMolecules.size(), "SaveTREMOLO: LocalNotoGlobalNoMap[] has not been correctly initialized for each molecule");
|
---|
[568be7] | 1018 | }
|
---|
| 1019 |
|
---|
| 1020 | // write the file
|
---|
| 1021 | {
|
---|
| 1022 | int MolCounter = 0;
|
---|
| 1023 | int AtomNo = 0;
|
---|
| 1024 | for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
|
---|
[9879f6] | 1025 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
[1024cb] | 1026 | *output << LocalNotoGlobalNoMap[ (*iter)->getId() ] << "\t";
|
---|
[a7b761b] | 1027 | *output << (*iter)->getName() << "\t";
|
---|
[568be7] | 1028 | *output << (*MolWalker)->name << "\t";
|
---|
[6e6e10] | 1029 | *output << MolCounter+1 << "\t";
|
---|
[d74077] | 1030 | *output << (*iter)->at(0) << "\t" << (*iter)->at(1) << "\t" << (*iter)->at(2) << "\t";
|
---|
[83f176] | 1031 | *output << (double)(*iter)->getType()->getValence() << "\t";
|
---|
[b5c53d] | 1032 | *output << (*iter)->getType()->getSymbol() << "\t";
|
---|
[9d83b6] | 1033 | const BondList& ListOfBonds = (*iter)->getListOfBonds();
|
---|
| 1034 | for (BondList::const_iterator runner = ListOfBonds.begin();
|
---|
| 1035 | runner != ListOfBonds.end();
|
---|
| 1036 | runner++) {
|
---|
[1024cb] | 1037 | *output << LocalNotoGlobalNoMap[ (*runner)->GetOtherAtom((*iter))->getId() ] << "\t";
|
---|
[9d83b6] | 1038 | }
|
---|
| 1039 | for(int i = ListOfBonds.size(); i < MaxNeighbours; i++)
|
---|
[568be7] | 1040 | *output << "-\t";
|
---|
| 1041 | *output << endl;
|
---|
| 1042 | AtomNo++;
|
---|
| 1043 | }
|
---|
| 1044 | MolCounter++;
|
---|
| 1045 | }
|
---|
| 1046 | }
|
---|
| 1047 |
|
---|
| 1048 | // store & free
|
---|
| 1049 | output->flush();
|
---|
| 1050 | output->close();
|
---|
| 1051 | delete(output);
|
---|
| 1052 | delete(fname);
|
---|
| 1053 |
|
---|
| 1054 | return true;
|
---|
| 1055 | };
|
---|
| 1056 |
|
---|
[235bed] | 1057 |
|
---|
| 1058 | /** Tries given filename or standard on saving the config file.
|
---|
| 1059 | * \param *ConfigFileName name of file
|
---|
| 1060 | * \param *periode pointer to periodentafel structure with all the elements
|
---|
| 1061 | * \param *molecules list of molecules structure with all the atoms and coordinates
|
---|
| 1062 | */
|
---|
| 1063 | void config::SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules)
|
---|
| 1064 | {
|
---|
| 1065 | char filename[MAXSTRINGSIZE];
|
---|
| 1066 | ofstream output;
|
---|
[274d45] | 1067 | molecule *mol = NULL;
|
---|
[235bed] | 1068 |
|
---|
| 1069 | // first save as PDB data
|
---|
| 1070 | if (ConfigFileName != NULL)
|
---|
| 1071 | strcpy(filename, ConfigFileName);
|
---|
[1ca488] | 1072 | if (output == NULL)
|
---|
[235bed] | 1073 | strcpy(filename,"main_pcp_linux");
|
---|
[1024cb] | 1074 | Log() << Verbose(0) << "Saving as pdb input ... " << endl;
|
---|
[04b6f9] | 1075 | if (SavePDB(filename, molecules))
|
---|
[1024cb] | 1076 | Log() << Verbose(0) << "\t... done." << endl;
|
---|
[235bed] | 1077 | else
|
---|
[1024cb] | 1078 | Log() << Verbose(0) << "\t... failed." << endl;
|
---|
[235bed] | 1079 |
|
---|
| 1080 | // then save as tremolo data file
|
---|
| 1081 | if (ConfigFileName != NULL)
|
---|
| 1082 | strcpy(filename, ConfigFileName);
|
---|
[1ca488] | 1083 | if (output == NULL)
|
---|
[235bed] | 1084 | strcpy(filename,"main_pcp_linux");
|
---|
[1024cb] | 1085 | Log() << Verbose(0) << "Saving as tremolo data input ... " << endl;
|
---|
[04b6f9] | 1086 | if (SaveTREMOLO(filename, molecules))
|
---|
[1024cb] | 1087 | Log() << Verbose(0) << "\t... done." << endl;
|
---|
[235bed] | 1088 | else
|
---|
[1024cb] | 1089 | Log() << Verbose(0) << "\t... failed." << endl;
|
---|
[235bed] | 1090 |
|
---|
| 1091 | // translate each to its center and merge all molecules in MoleculeListClass into this molecule
|
---|
| 1092 | int N = molecules->ListOfMolecules.size();
|
---|
[274d45] | 1093 | if (N != 1) { // don't do anything in case of only one molecule (shifts mol ids otherwise)
|
---|
| 1094 | int *src = new int[N];
|
---|
| 1095 | N=0;
|
---|
| 1096 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
|
---|
| 1097 | src[N++] = (*ListRunner)->IndexNr;
|
---|
| 1098 | }
|
---|
| 1099 | mol = World::getInstance().createMolecule();
|
---|
| 1100 | mol->SetNameFromFilename(ConfigFileName);
|
---|
[35b698] | 1101 | //mol->CalculateOrbitals(*this);
|
---|
[274d45] | 1102 | delete[](src);
|
---|
| 1103 | } else {
|
---|
| 1104 | if (!molecules->ListOfMolecules.empty()) {
|
---|
| 1105 | mol = *(molecules->ListOfMolecules.begin());
|
---|
| 1106 | mol->doCountAtoms();
|
---|
[35b698] | 1107 | //mol->CalculateOrbitals(*this);
|
---|
[274d45] | 1108 | } else {
|
---|
| 1109 | DoeLog(1) && (eLog() << Verbose(1) << "There are no molecules to save!" << endl);
|
---|
| 1110 | }
|
---|
[235bed] | 1111 | }
|
---|
| 1112 |
|
---|
| 1113 | Log() << Verbose(0) << "Storing configuration ... " << endl;
|
---|
| 1114 | // get correct valence orbitals
|
---|
| 1115 | if (ConfigFileName != NULL) { // test the file name
|
---|
| 1116 | strcpy(filename, ConfigFileName);
|
---|
| 1117 | output.open(filename, ios::trunc);
|
---|
[04b6f9] | 1118 | } else if (strlen(configname) != 0) {
|
---|
| 1119 | strcpy(filename, configname);
|
---|
| 1120 | output.open(configname, ios::trunc);
|
---|
[235bed] | 1121 | } else {
|
---|
| 1122 | strcpy(filename, DEFAULTCONFIG);
|
---|
| 1123 | output.open(DEFAULTCONFIG, ios::trunc);
|
---|
| 1124 | }
|
---|
| 1125 | output.close();
|
---|
| 1126 | output.clear();
|
---|
[1024cb] | 1127 | Log() << Verbose(0) << "Saving of config file ... " << endl;
|
---|
[04b6f9] | 1128 | if (Save(filename, periode, mol))
|
---|
[1024cb] | 1129 | Log() << Verbose(0) << "\t... successful." << endl;
|
---|
[235bed] | 1130 | else
|
---|
[1024cb] | 1131 | Log() << Verbose(0) << "\t... failed." << endl;
|
---|
[235bed] | 1132 |
|
---|
| 1133 | // and save to xyz file
|
---|
| 1134 | if (ConfigFileName != NULL) {
|
---|
| 1135 | strcpy(filename, ConfigFileName);
|
---|
| 1136 | strcat(filename, ".xyz");
|
---|
| 1137 | output.open(filename, ios::trunc);
|
---|
| 1138 | }
|
---|
[1ca488] | 1139 | if (output == NULL) {
|
---|
[235bed] | 1140 | strcpy(filename,"main_pcp_linux");
|
---|
| 1141 | strcat(filename, ".xyz");
|
---|
| 1142 | output.open(filename, ios::trunc);
|
---|
| 1143 | }
|
---|
[1024cb] | 1144 | Log() << Verbose(0) << "Saving of XYZ file ... " << endl;
|
---|
[235bed] | 1145 | if (mol->MDSteps <= 1) {
|
---|
| 1146 | if (mol->OutputXYZ(&output))
|
---|
[1024cb] | 1147 | Log() << Verbose(0) << "\t... successful." << endl;
|
---|
[235bed] | 1148 | else
|
---|
[1024cb] | 1149 | Log() << Verbose(0) << "\t... failed." << endl;
|
---|
[235bed] | 1150 | } else {
|
---|
| 1151 | if (mol->OutputTrajectoriesXYZ(&output))
|
---|
[1024cb] | 1152 | Log() << Verbose(0) << "\t... successful." << endl;
|
---|
[235bed] | 1153 | else
|
---|
[1024cb] | 1154 | Log() << Verbose(0) << "\t... failed." << endl;
|
---|
[235bed] | 1155 | }
|
---|
| 1156 | output.close();
|
---|
| 1157 | output.clear();
|
---|
| 1158 |
|
---|
| 1159 | // and save as MPQC configuration
|
---|
| 1160 | if (ConfigFileName != NULL)
|
---|
| 1161 | strcpy(filename, ConfigFileName);
|
---|
[1ca488] | 1162 | if (output == NULL)
|
---|
[235bed] | 1163 | strcpy(filename,"main_pcp_linux");
|
---|
[1024cb] | 1164 | Log() << Verbose(0) << "Saving as mpqc input .. " << endl;
|
---|
[04b6f9] | 1165 | if (SaveMPQC(filename, mol))
|
---|
[1024cb] | 1166 | Log() << Verbose(0) << "\t... done." << endl;
|
---|
[235bed] | 1167 | else
|
---|
[1024cb] | 1168 | Log() << Verbose(0) << "\t... failed." << endl;
|
---|
[235bed] | 1169 |
|
---|
[274d45] | 1170 | // don't destroy molecule as it contains all our atoms
|
---|
| 1171 | //World::getInstance().destroyMolecule(mol);
|
---|
[235bed] | 1172 | };
|
---|
| 1173 |
|
---|
[fa649a] | 1174 | /** Reads parameter from a parsed file.
|
---|
| 1175 | * The file is either parsed for a certain keyword or if null is given for
|
---|
| 1176 | * the value in row yth and column xth. If the keyword was necessity#critical,
|
---|
| 1177 | * then an error is thrown and the programme aborted.
|
---|
| 1178 | * \warning value is modified (both in contents and position)!
|
---|
| 1179 | * \param verbose 1 - print found value to stderr, 0 - don't
|
---|
| 1180 | * \param *file file to be parsed
|
---|
| 1181 | * \param name Name of value in file (at least 3 chars!)
|
---|
| 1182 | * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
|
---|
| 1183 | * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
|
---|
| 1184 | * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
|
---|
| 1185 | * counted from this unresetted position!)
|
---|
| 1186 | * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
|
---|
| 1187 | * \param yth In grid case specifying column number, otherwise the yth \a name matching line
|
---|
| 1188 | * \param type Type of the Parameter to be read
|
---|
| 1189 | * \param value address of the value to be read (must have been allocated)
|
---|
| 1190 | * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
|
---|
| 1191 | * \param critical necessity of this keyword being specified (optional, critical)
|
---|
| 1192 | * \return 1 - found, 0 - not found
|
---|
| 1193 | * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
|
---|
| 1194 | */
|
---|
| 1195 | int ParseForParameter(const int verbose, ifstream * const file, const char * const name, const int sequential, const int xth, const int yth, const int type, void * value, const int repetition, const int critical) {
|
---|
| 1196 | int i = 0;
|
---|
| 1197 | int j = 0; // loop variables
|
---|
| 1198 | int length = 0;
|
---|
| 1199 | int maxlength = -1;
|
---|
| 1200 | long file_position = file->tellg(); // mark current position
|
---|
| 1201 | char *dummy1 = NULL;
|
---|
| 1202 | char *dummy = NULL;
|
---|
[920c70] | 1203 | char free_dummy[MAXSTRINGSIZE]; // pointers in the line that is read in per step
|
---|
[fa649a] | 1204 | dummy1 = free_dummy;
|
---|
| 1205 |
|
---|
| 1206 | //fprintf(stderr,"Parsing for %s\n",name);
|
---|
| 1207 | if (repetition == 0)
|
---|
| 1208 | //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
|
---|
| 1209 | return 0;
|
---|
| 1210 |
|
---|
| 1211 | int line = 0; // marks line where parameter was found
|
---|
| 1212 | int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
|
---|
| 1213 | while((found != repetition)) {
|
---|
| 1214 | dummy1 = dummy = free_dummy;
|
---|
| 1215 | do {
|
---|
| 1216 | file->getline(dummy1, 256); // Read the whole line
|
---|
| 1217 | if (file->eof()) {
|
---|
| 1218 | if ((critical) && (found == 0)) {
|
---|
| 1219 | //Error(InitReading, name);
|
---|
| 1220 | fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
|
---|
| 1221 | exit(255);
|
---|
| 1222 | } else {
|
---|
| 1223 | //if (!sequential)
|
---|
| 1224 | file->clear();
|
---|
| 1225 | file->seekg(file_position, ios::beg); // rewind to start position
|
---|
| 1226 | return 0;
|
---|
| 1227 | }
|
---|
| 1228 | }
|
---|
| 1229 | line++;
|
---|
| 1230 | } while (dummy != NULL && dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
|
---|
| 1231 |
|
---|
| 1232 | // C++ getline removes newline at end, thus re-add
|
---|
| 1233 | if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
|
---|
| 1234 | i = strlen(dummy1);
|
---|
| 1235 | dummy1[i] = '\n';
|
---|
| 1236 | dummy1[i+1] = '\0';
|
---|
| 1237 | }
|
---|
| 1238 | //fprintf(stderr,"line %i ends at %i, newline at %i\n", line, strlen(dummy1), strchr(dummy1,'\n')-free_dummy);
|
---|
| 1239 |
|
---|
| 1240 | if (dummy1 == NULL) {
|
---|
| 1241 | if (verbose) fprintf(stderr,"Error reading line %i\n",line);
|
---|
| 1242 | } else {
|
---|
| 1243 | //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
|
---|
| 1244 | }
|
---|
| 1245 | // Seek for possible end of keyword on line if given ...
|
---|
| 1246 | if (name != NULL) {
|
---|
| 1247 | dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
|
---|
| 1248 | if (dummy == NULL) {
|
---|
| 1249 | dummy = strchr(dummy1, ' '); // if not found seek for space
|
---|
| 1250 | while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
|
---|
| 1251 | dummy++;
|
---|
| 1252 | }
|
---|
| 1253 | if (dummy == NULL) {
|
---|
| 1254 | dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
|
---|
| 1255 | //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
|
---|
| 1256 | //Error(FileOpenParams, NULL);
|
---|
| 1257 | } else {
|
---|
| 1258 | //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
|
---|
| 1259 | }
|
---|
| 1260 | } else dummy = dummy1;
|
---|
| 1261 | // ... and check if it is the keyword!
|
---|
| 1262 | //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
|
---|
| 1263 | if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
|
---|
| 1264 | found++; // found the parameter!
|
---|
| 1265 | //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
|
---|
| 1266 |
|
---|
| 1267 | if (found == repetition) {
|
---|
| 1268 | for (i=0;i<xth;i++) { // i = rows
|
---|
| 1269 | if (type >= grid) {
|
---|
| 1270 | // grid structure means that grid starts on the next line, not right after keyword
|
---|
| 1271 | dummy1 = dummy = free_dummy;
|
---|
| 1272 | do {
|
---|
| 1273 | file->getline(dummy1, 256); // Read the whole line, skip commentary and empty ones
|
---|
| 1274 | if (file->eof()) {
|
---|
| 1275 | if ((critical) && (found == 0)) {
|
---|
| 1276 | //Error(InitReading, name);
|
---|
| 1277 | fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
|
---|
| 1278 | exit(255);
|
---|
| 1279 | } else {
|
---|
| 1280 | //if (!sequential)
|
---|
| 1281 | file->clear();
|
---|
| 1282 | file->seekg(file_position, ios::beg); // rewind to start position
|
---|
| 1283 | return 0;
|
---|
| 1284 | }
|
---|
| 1285 | }
|
---|
| 1286 | line++;
|
---|
| 1287 | } while ((dummy1[0] == '#') || (dummy1[0] == '\n'));
|
---|
| 1288 | if (dummy1 == NULL){
|
---|
| 1289 | if (verbose) fprintf(stderr,"Error reading line %i\n", line);
|
---|
| 1290 | } else {
|
---|
| 1291 | //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
|
---|
| 1292 | }
|
---|
| 1293 | } else { // simple int, strings or doubles start in the same line
|
---|
| 1294 | while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
|
---|
| 1295 | dummy++;
|
---|
| 1296 | }
|
---|
| 1297 | // C++ getline removes newline at end, thus re-add
|
---|
| 1298 | if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
|
---|
| 1299 | j = strlen(dummy1);
|
---|
| 1300 | dummy1[j] = '\n';
|
---|
| 1301 | dummy1[j+1] = '\0';
|
---|
| 1302 | }
|
---|
| 1303 |
|
---|
| 1304 | int start = (type >= grid) ? 0 : yth-1 ;
|
---|
| 1305 | for (j=start;j<yth;j++) { // j = columns
|
---|
| 1306 | // check for lower triangular area and upper triangular area
|
---|
| 1307 | if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
|
---|
| 1308 | *((double *)value) = 0.0;
|
---|
| 1309 | fprintf(stderr,"%f\t",*((double *)value));
|
---|
| 1310 | value = (void *)((long)value + sizeof(double));
|
---|
| 1311 | //value += sizeof(double);
|
---|
| 1312 | } else {
|
---|
| 1313 | // otherwise we must skip all interjacent tabs and spaces and find next value
|
---|
| 1314 | dummy1 = dummy;
|
---|
| 1315 | dummy = strchr(dummy1, '\t'); // seek for tab or space
|
---|
| 1316 | if (dummy == NULL)
|
---|
| 1317 | dummy = strchr(dummy1, ' '); // if not found seek for space
|
---|
| 1318 | if (dummy == NULL) { // if still zero returned ...
|
---|
| 1319 | dummy = strchr(dummy1, '\n'); // ... at line end then
|
---|
| 1320 | if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
|
---|
| 1321 | if (critical) {
|
---|
| 1322 | if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
|
---|
| 1323 | //return 0;
|
---|
| 1324 | exit(255);
|
---|
| 1325 | //Error(FileOpenParams, NULL);
|
---|
| 1326 | } else {
|
---|
| 1327 | //if (!sequential)
|
---|
| 1328 | file->clear();
|
---|
| 1329 | file->seekg(file_position, ios::beg); // rewind to start position
|
---|
| 1330 | return 0;
|
---|
| 1331 | }
|
---|
| 1332 | }
|
---|
| 1333 | } else {
|
---|
| 1334 | //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
|
---|
| 1335 | }
|
---|
| 1336 | if (*dummy1 == '#') {
|
---|
| 1337 | // found comment, skipping rest of line
|
---|
| 1338 | //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
|
---|
| 1339 | if (!sequential) { // here we need it!
|
---|
| 1340 | file->seekg(file_position, ios::beg); // rewind to start position
|
---|
| 1341 | }
|
---|
| 1342 | return 0;
|
---|
| 1343 | }
|
---|
| 1344 | //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
|
---|
| 1345 | switch(type) {
|
---|
| 1346 | case (row_int):
|
---|
| 1347 | *((int *)value) = atoi(dummy1);
|
---|
| 1348 | if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
|
---|
| 1349 | if (verbose) fprintf(stderr,"%i\t",*((int *)value));
|
---|
| 1350 | value = (void *)((long)value + sizeof(int));
|
---|
| 1351 | //value += sizeof(int);
|
---|
| 1352 | break;
|
---|
| 1353 | case(row_double):
|
---|
| 1354 | case(grid):
|
---|
| 1355 | case(lower_trigrid):
|
---|
| 1356 | case(upper_trigrid):
|
---|
| 1357 | *((double *)value) = atof(dummy1);
|
---|
| 1358 | if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
|
---|
| 1359 | if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
|
---|
| 1360 | value = (void *)((long)value + sizeof(double));
|
---|
| 1361 | //value += sizeof(double);
|
---|
| 1362 | break;
|
---|
| 1363 | case(double_type):
|
---|
| 1364 | *((double *)value) = atof(dummy1);
|
---|
| 1365 | if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
|
---|
| 1366 | //value += sizeof(double);
|
---|
| 1367 | break;
|
---|
| 1368 | case(int_type):
|
---|
| 1369 | *((int *)value) = atoi(dummy1);
|
---|
| 1370 | if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
|
---|
| 1371 | //value += sizeof(int);
|
---|
| 1372 | break;
|
---|
| 1373 | default:
|
---|
| 1374 | case(string_type):
|
---|
| 1375 | if (value != NULL) {
|
---|
| 1376 | //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
|
---|
| 1377 | maxlength = MAXSTRINGSIZE;
|
---|
| 1378 | length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
|
---|
| 1379 | strncpy((char *)value, dummy1, length); // copy as much
|
---|
| 1380 | ((char *)value)[length] = '\0'; // and set end marker
|
---|
| 1381 | if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
|
---|
| 1382 | //value += sizeof(char);
|
---|
| 1383 | } else {
|
---|
| 1384 | }
|
---|
| 1385 | break;
|
---|
| 1386 | }
|
---|
| 1387 | }
|
---|
| 1388 | while (*dummy == '\t')
|
---|
| 1389 | dummy++;
|
---|
| 1390 | }
|
---|
| 1391 | }
|
---|
| 1392 | }
|
---|
| 1393 | }
|
---|
| 1394 | }
|
---|
| 1395 | if ((type >= row_int) && (verbose))
|
---|
| 1396 | fprintf(stderr,"\n");
|
---|
| 1397 | if (!sequential) {
|
---|
| 1398 | file->clear();
|
---|
| 1399 | file->seekg(file_position, ios::beg); // rewind to start position
|
---|
| 1400 | }
|
---|
| 1401 | //fprintf(stderr, "End of Parsing\n\n");
|
---|
| 1402 |
|
---|
| 1403 | return (found); // true if found, false if not
|
---|
| 1404 | }
|
---|
| 1405 |
|
---|
| 1406 |
|
---|
| 1407 | /** Reads parameter from a parsed file.
|
---|
| 1408 | * The file is either parsed for a certain keyword or if null is given for
|
---|
| 1409 | * the value in row yth and column xth. If the keyword was necessity#critical,
|
---|
| 1410 | * then an error is thrown and the programme aborted.
|
---|
| 1411 | * \warning value is modified (both in contents and position)!
|
---|
| 1412 | * \param verbose 1 - print found value to stderr, 0 - don't
|
---|
| 1413 | * \param *FileBuffer pointer to buffer structure
|
---|
| 1414 | * \param name Name of value in file (at least 3 chars!)
|
---|
| 1415 | * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
|
---|
| 1416 | * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
|
---|
| 1417 | * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
|
---|
| 1418 | * counted from this unresetted position!)
|
---|
| 1419 | * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
|
---|
| 1420 | * \param yth In grid case specifying column number, otherwise the yth \a name matching line
|
---|
| 1421 | * \param type Type of the Parameter to be read
|
---|
| 1422 | * \param value address of the value to be read (must have been allocated)
|
---|
| 1423 | * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
|
---|
| 1424 | * \param critical necessity of this keyword being specified (optional, critical)
|
---|
| 1425 | * \return 1 - found, 0 - not found
|
---|
| 1426 | * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
|
---|
| 1427 | */
|
---|
| 1428 | int ParseForParameter(const int verbose, struct ConfigFileBuffer * const FileBuffer, const char * const name, const int sequential, const int xth, const int yth, const int type, void * value, const int repetition, const int critical) {
|
---|
| 1429 | int i = 0;
|
---|
| 1430 | int j = 0; // loop variables
|
---|
| 1431 | int length = 0;
|
---|
| 1432 | int maxlength = -1;
|
---|
| 1433 | int OldCurrentLine = FileBuffer->CurrentLine;
|
---|
| 1434 | char *dummy1 = NULL;
|
---|
| 1435 | char *dummy = NULL; // pointers in the line that is read in per step
|
---|
[6a465e] | 1436 | char *free_dummy = NULL;
|
---|
[fa649a] | 1437 |
|
---|
[6a465e] | 1438 | if (verbose) fprintf(stderr,"Begin of Parsing for %s\n",name);
|
---|
[fa649a] | 1439 | if (repetition == 0)
|
---|
| 1440 | //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
|
---|
| 1441 | return 0;
|
---|
| 1442 |
|
---|
| 1443 | int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
|
---|
| 1444 | while((found != repetition)) {
|
---|
| 1445 | dummy1 = dummy = NULL;
|
---|
| 1446 | do {
|
---|
[6a465e] | 1447 | free_dummy = dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ];
|
---|
[fa649a] | 1448 | if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
|
---|
| 1449 | if ((critical) && (found == 0)) {
|
---|
| 1450 | //Error(InitReading, name);
|
---|
| 1451 | fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
|
---|
| 1452 | exit(255);
|
---|
| 1453 | } else {
|
---|
[6a465e] | 1454 | //fprintf(stdout,"Rewinding to OldCurrentLine due to search till end of file.\n");
|
---|
[fa649a] | 1455 | FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
|
---|
| 1456 | return 0;
|
---|
| 1457 | }
|
---|
| 1458 | }
|
---|
| 1459 | if (dummy1 == NULL) {
|
---|
[6a465e] | 1460 | if (verbose) fprintf(stderr,"Error reading line %i\n",FileBuffer->CurrentLine);
|
---|
[fa649a] | 1461 | } else {
|
---|
[6a465e] | 1462 | if (verbose) fprintf(stderr,"Now parsing the line %i: %s\n", FileBuffer->CurrentLine, dummy1);
|
---|
[fa649a] | 1463 | }
|
---|
[6a465e] | 1464 | //FileBuffer->CurrentLine++;
|
---|
[fa649a] | 1465 | } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
|
---|
| 1466 |
|
---|
| 1467 | // Seek for possible end of keyword on line if given ...
|
---|
| 1468 | if (name != NULL) {
|
---|
| 1469 | dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
|
---|
| 1470 | if (dummy == NULL) {
|
---|
| 1471 | dummy = strchr(dummy1, ' '); // if not found seek for space
|
---|
| 1472 | while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
|
---|
| 1473 | dummy++;
|
---|
| 1474 | }
|
---|
| 1475 | if (dummy == NULL) {
|
---|
| 1476 | dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
|
---|
| 1477 | //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
|
---|
| 1478 | //Error(FileOpenParams, NULL);
|
---|
| 1479 | } else {
|
---|
[6a465e] | 1480 | if (verbose) fprintf(stderr,"found tab at line %i at position %li\n",FileBuffer->CurrentLine, (char *)dummy-(char *)dummy1);
|
---|
[fa649a] | 1481 | }
|
---|
| 1482 | } else dummy = dummy1;
|
---|
| 1483 | // ... and check if it is the keyword!
|
---|
| 1484 | //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
|
---|
| 1485 | if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
|
---|
| 1486 | found++; // found the parameter!
|
---|
[6a465e] | 1487 | if (verbose) fprintf(stderr,"found %s at line %i between %li and %li\n", name, FileBuffer->CurrentLine, (unsigned long)dummy1, (unsigned long)dummy);
|
---|
[fa649a] | 1488 |
|
---|
| 1489 | if (found == repetition) {
|
---|
| 1490 | for (i=0;i<xth;i++) { // i = rows
|
---|
| 1491 | if (type >= grid) {
|
---|
| 1492 | // grid structure means that grid starts on the next line, not right after keyword
|
---|
| 1493 | dummy1 = dummy = NULL;
|
---|
| 1494 | do {
|
---|
| 1495 | dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ];
|
---|
| 1496 | if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
|
---|
| 1497 | if ((critical) && (found == 0)) {
|
---|
| 1498 | //Error(InitReading, name);
|
---|
| 1499 | fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
|
---|
| 1500 | exit(255);
|
---|
| 1501 | } else {
|
---|
[6a465e] | 1502 | //fprintf(stdout,"Rewinding to OldCurrentLine due to search till end of line.\n");
|
---|
[fa649a] | 1503 | FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
|
---|
| 1504 | return 0;
|
---|
| 1505 | }
|
---|
| 1506 | }
|
---|
| 1507 | if (dummy1 == NULL) {
|
---|
[6a465e] | 1508 | if (verbose) fprintf(stderr,"Error reading line %i\n", FileBuffer->CurrentLine);
|
---|
[fa649a] | 1509 | } else {
|
---|
[6a465e] | 1510 | if (verbose) fprintf(stderr,"Reading next line %i: %s\n", FileBuffer->CurrentLine, dummy1);
|
---|
[fa649a] | 1511 | }
|
---|
[6a465e] | 1512 | //FileBuffer->CurrentLine++;
|
---|
[49e1ae] | 1513 | } while ((dummy1 != NULL) && ((dummy1[0] == '#') || (dummy1[0] == '\n')));
|
---|
[fa649a] | 1514 | dummy = dummy1;
|
---|
| 1515 | } else { // simple int, strings or doubles start in the same line
|
---|
| 1516 | while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
|
---|
| 1517 | dummy++;
|
---|
| 1518 | }
|
---|
| 1519 |
|
---|
| 1520 | for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns
|
---|
| 1521 | // check for lower triangular area and upper triangular area
|
---|
| 1522 | if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
|
---|
| 1523 | *((double *)value) = 0.0;
|
---|
| 1524 | fprintf(stderr,"%f\t",*((double *)value));
|
---|
| 1525 | value = (void *)((long)value + sizeof(double));
|
---|
| 1526 | //value += sizeof(double);
|
---|
| 1527 | } else {
|
---|
| 1528 | // otherwise we must skip all interjacent tabs and spaces and find next value
|
---|
| 1529 | dummy1 = dummy;
|
---|
| 1530 | dummy = strchr(dummy1, '\t'); // seek for tab or space
|
---|
| 1531 | if (dummy == NULL)
|
---|
| 1532 | dummy = strchr(dummy1, ' '); // if not found seek for space
|
---|
| 1533 | if (dummy == NULL) { // if still zero returned ...
|
---|
| 1534 | dummy = strchr(dummy1, '\n'); // ... at line end then
|
---|
| 1535 | if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
|
---|
| 1536 | if (critical) {
|
---|
[6a465e] | 1537 | if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", FileBuffer->CurrentLine, yth-j, name);
|
---|
[fa649a] | 1538 | //return 0;
|
---|
| 1539 | exit(255);
|
---|
| 1540 | //Error(FileOpenParams, NULL);
|
---|
| 1541 | } else {
|
---|
| 1542 | if (!sequential) { // here we need it!
|
---|
[6a465e] | 1543 | //fprintf(stdout,"Rewinding to OldCurrentLine due to end of line and sequential %d.\n", sequential);
|
---|
[fa649a] | 1544 | FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
|
---|
| 1545 | }
|
---|
| 1546 | return 0;
|
---|
| 1547 | }
|
---|
| 1548 | }
|
---|
| 1549 | } else {
|
---|
[6a465e] | 1550 | if (verbose) fprintf(stderr,"found tab at line %i at position %li\n",FileBuffer->CurrentLine, (char *)dummy-(char *)free_dummy);
|
---|
[fa649a] | 1551 | }
|
---|
| 1552 | if (*dummy1 == '#') {
|
---|
| 1553 | // found comment, skipping rest of line
|
---|
| 1554 | //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
|
---|
| 1555 | if (!sequential) { // here we need it!
|
---|
[6a465e] | 1556 | //fprintf(stdout,"Rewinding to OldCurrentLine due to comment and sequential %d.\n", sequential);
|
---|
[fa649a] | 1557 | FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
|
---|
| 1558 | }
|
---|
| 1559 | return 0;
|
---|
| 1560 | }
|
---|
[6a465e] | 1561 | if (verbose) fprintf(stderr,"value from %li to %li\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
|
---|
[fa649a] | 1562 | switch(type) {
|
---|
| 1563 | case (row_int):
|
---|
| 1564 | *((int *)value) = atoi(dummy1);
|
---|
| 1565 | if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
|
---|
| 1566 | if (verbose) fprintf(stderr,"%i\t",*((int *)value));
|
---|
| 1567 | value = (void *)((long)value + sizeof(int));
|
---|
| 1568 | //value += sizeof(int);
|
---|
| 1569 | break;
|
---|
| 1570 | case(row_double):
|
---|
| 1571 | case(grid):
|
---|
| 1572 | case(lower_trigrid):
|
---|
| 1573 | case(upper_trigrid):
|
---|
| 1574 | *((double *)value) = atof(dummy1);
|
---|
| 1575 | if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
|
---|
| 1576 | if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
|
---|
| 1577 | value = (void *)((long)value + sizeof(double));
|
---|
| 1578 | //value += sizeof(double);
|
---|
| 1579 | break;
|
---|
| 1580 | case(double_type):
|
---|
| 1581 | *((double *)value) = atof(dummy1);
|
---|
| 1582 | if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
|
---|
| 1583 | //value += sizeof(double);
|
---|
| 1584 | break;
|
---|
| 1585 | case(int_type):
|
---|
| 1586 | *((int *)value) = atoi(dummy1);
|
---|
| 1587 | if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
|
---|
| 1588 | //value += sizeof(int);
|
---|
| 1589 | break;
|
---|
| 1590 | default:
|
---|
| 1591 | case(string_type):
|
---|
| 1592 | if (value != NULL) {
|
---|
| 1593 | //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
|
---|
| 1594 | maxlength = MAXSTRINGSIZE;
|
---|
| 1595 | length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
|
---|
| 1596 | strncpy((char *)value, dummy1, length); // copy as much
|
---|
| 1597 | ((char *)value)[length] = '\0'; // and set end marker
|
---|
| 1598 | if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
|
---|
| 1599 | //value += sizeof(char);
|
---|
| 1600 | } else {
|
---|
| 1601 | }
|
---|
| 1602 | break;
|
---|
| 1603 | }
|
---|
| 1604 | }
|
---|
| 1605 | while (*dummy == '\t')
|
---|
| 1606 | dummy++;
|
---|
| 1607 | }
|
---|
| 1608 | }
|
---|
| 1609 | }
|
---|
| 1610 | }
|
---|
| 1611 | }
|
---|
| 1612 | if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
|
---|
| 1613 | if (!sequential) {
|
---|
[6a465e] | 1614 | //fprintf(stdout,"Rewinding to OldCurrentLine due to sequential %d.\n", sequential);
|
---|
[fa649a] | 1615 | FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
|
---|
| 1616 | }
|
---|
[6a465e] | 1617 | if (verbose) fprintf(stderr, "End of Parsing for %s\n\n",name);
|
---|
[fa649a] | 1618 |
|
---|
| 1619 | return (found); // true if found, false if not
|
---|
| 1620 | }
|
---|
[43dad6] | 1621 |
|
---|
| 1622 | /** Reading of Thermostat related values from parameter file.
|
---|
| 1623 | * \param *fb file buffer containing the config file
|
---|
| 1624 | */
|
---|
| 1625 | void config::ParseThermostats(class ConfigFileBuffer * const fb)
|
---|
| 1626 | {
|
---|
| 1627 | char * const thermo = new char[12];
|
---|
| 1628 | const int verbose = 0;
|
---|
[1bfc8e] | 1629 | ThermoStatContainer *Thermostats = World::getInstance().getThermostats();
|
---|
[43dad6] | 1630 |
|
---|
| 1631 | // read desired Thermostat from file along with needed additional parameters
|
---|
| 1632 | if (ParseForParameter(verbose,fb,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
|
---|
[14c57a] | 1633 | Thermostats->makeActive(thermo,fb);
|
---|
[43dad6] | 1634 | } else {
|
---|
| 1635 | if ((Thermostats->TargetTemp != 0))
|
---|
| 1636 | DoLog(2) && (Log() << Verbose(2) << "No thermostat chosen despite finite temperature MD, falling back to None." << endl);
|
---|
[14c57a] | 1637 | Thermostats->chooseNone();
|
---|
[43dad6] | 1638 | }
|
---|
| 1639 | delete[](thermo);
|
---|
| 1640 | };
|
---|
| 1641 |
|
---|