source: src/config.cpp@ 0dc86e2

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 0dc86e2 was 0dc86e2, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Removed unused AtomNo parameter in atom::OutputMPQCLine()

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