Changeset a3fded for src/config.cpp


Ignore:
Timestamp:
Jun 12, 2010, 1:12:51 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Branches:
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, Candidate_v1.7.0, 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
Children:
43dad6
Parents:
88104f
git-author:
Frederik Heber <heber@…> (06/12/10 13:05:12)
git-committer:
Frederik Heber <heber@…> (06/12/10 13:12:51)
Message:

New class ThermoStatContainer containing all parameters and changes to ConfigFileBuffer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/config.cpp

    r88104f ra3fded  
    1010#include "atom.hpp"
    1111#include "bond.hpp"
     12#include "bondgraph.hpp"
    1213#include "config.hpp"
     14#include "ConfigFileBuffer.hpp"
    1315#include "element.hpp"
    1416#include "helpers.hpp"
     
    2022#include "molecule.hpp"
    2123#include "periodentafel.hpp"
     24#include "ThermoStatContainer.hpp"
    2225#include "World.hpp"
    2326
     
    2629/** Constructor for config file class.
    2730 */
    28 config::config() : BG(NULL), PsiType(0), MaxPsiDouble(0), PsiMaxNoUp(0), PsiMaxNoDown(0), MaxMinStopStep(1), InitMaxMinStopStep(1), ProcPEGamma(8), ProcPEPsi(1), configpath(NULL),
    29     configname(NULL), FastParsing(false), Deltat(0.01), basis(""), databasepath(NULL), DoConstrainedMD(0), MaxOuterStep(0), Thermostat(4), ThermostatImplemented(NULL),
    30     ThermostatNames(NULL), TempFrequency(2.5), alpha(0.), HooverMass(0.), TargetTemp(0.00095004455), ScaleTempStep(25),  mainname(NULL), defaultpath(NULL), pseudopotpath(NULL),
     31config::config() : BG(NULL), Thermostats(0), PsiType(0), MaxPsiDouble(0), PsiMaxNoUp(0), PsiMaxNoDown(0), MaxMinStopStep(1), InitMaxMinStopStep(1), ProcPEGamma(8), ProcPEPsi(1), configpath(NULL),
     32    configname(NULL), FastParsing(false), Deltat(0.01), basis(""), databasepath(NULL), DoConstrainedMD(0), MaxOuterStep(0), mainname(NULL), defaultpath(NULL), pseudopotpath(NULL),
    3133    DoOutVis(0), DoOutMes(1), DoOutNICS(0), DoOutOrbitals(0), DoOutCurrent(0), DoFullCurrent(0), DoPerturbation(0), DoWannier(0), CommonWannier(0), SawtoothStart(0.01),
    3234    VectorPlane(0), VectorCut(0.), UseAddGramSch(1), Seed(1), OutVisStep(10), OutSrcStep(5), MaxPsiStep(0), EpsWannier(1e-7), MaxMinStep(100), RelEpsTotalEnergy(1e-7),
     
    4042  configpath = new char[MAXSTRINGSIZE];
    4143  configname = new char[MAXSTRINGSIZE];
     44  Thermostats = new ThermoStatContainer();
    4245  strcpy(mainname,"pcp");
    4346  strcpy(defaultpath,"not specified");
     
    4649  configname[0]='\0';
    4750  basis = "3-21G";
    48 
    49   InitThermostats();
    5051};
    5152
     
    6061  delete[](configpath);
    6162  delete[](configname);
    62   delete[](ThermostatImplemented);
    63   for (int j=0;j<MaxThermostats;j++)
    64     delete[](ThermostatNames[j]);
    65   delete[](ThermostatNames);
     63  if (Thermostats != NULL)
     64    delete(Thermostats);
    6665
    6766  if (BG != NULL)
    6867    delete(BG);
    6968};
    70 
    71 /** Initialises variables in class config for Thermostats.
    72  */
    73 void config::InitThermostats()
    74 {
    75   ThermostatImplemented = new int[MaxThermostats];
    76   ThermostatNames = new char *[MaxThermostats];
    77   for (int j=0;j<MaxThermostats;j++)
    78     ThermostatNames[j] = new char[12];
    79 
    80   strcpy(ThermostatNames[0],"None");
    81   ThermostatImplemented[0] = 1;
    82   strcpy(ThermostatNames[1],"Woodcock");
    83   ThermostatImplemented[1] = 1;
    84   strcpy(ThermostatNames[2],"Gaussian");
    85   ThermostatImplemented[2] = 1;
    86   strcpy(ThermostatNames[3],"Langevin");
    87   ThermostatImplemented[3] = 1;
    88   strcpy(ThermostatNames[4],"Berendsen");
    89   ThermostatImplemented[4] = 1;
    90   strcpy(ThermostatNames[5],"NoseHoover");
    91   ThermostatImplemented[5] = 1;
    92 };
    93 
    94 /** Readin of Thermostat related values from parameter file.
    95  * \param *fb file buffer containing the config file
    96  */
    97 void config::ParseThermostats(class ConfigFileBuffer * const fb)
    98 {
    99   char * const thermo = new char[12];
    100   const int verbose = 0;
    101 
    102   // read desired Thermostat from file along with needed additional parameters
    103   if (ParseForParameter(verbose,fb,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
    104     if (strcmp(thermo, ThermostatNames[0]) == 0) { // None
    105       if (ThermostatImplemented[0] == 1) {
    106         Thermostat = None;
    107       } else {
    108         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    109         Thermostat = None;
    110       }
    111     } else if (strcmp(thermo, ThermostatNames[1]) == 0) { // Woodcock
    112       if (ThermostatImplemented[1] == 1) {
    113         Thermostat = Woodcock;
    114         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read scaling frequency
    115       } else {
    116         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    117         Thermostat = None;
    118       }
    119     } else if (strcmp(thermo, ThermostatNames[2]) == 0) { // Gaussian
    120       if (ThermostatImplemented[2] == 1) {
    121         Thermostat = Gaussian;
    122         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read collision rate
    123       } else {
    124         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    125         Thermostat = None;
    126       }
    127     } else if (strcmp(thermo, ThermostatNames[3]) == 0) { // Langevin
    128       if (ThermostatImplemented[3] == 1) {
    129         Thermostat = Langevin;
    130         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read gamma
    131         if (ParseForParameter(verbose,fb,"Thermostat", 0, 3, 1, double_type, &alpha, 1, optional)) {
    132           DoLog(2) && (Log() << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << "." << endl);
    133         } else {
    134           alpha = 1.;
    135         }
    136       } else {
    137         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    138         Thermostat = None;
    139       }
    140     } else if (strcmp(thermo, ThermostatNames[4]) == 0) { // Berendsen
    141       if (ThermostatImplemented[4] == 1) {
    142         Thermostat = Berendsen;
    143         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T
    144       } else {
    145         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    146         Thermostat = None;
    147       }
    148     } else if (strcmp(thermo, ThermostatNames[5]) == 0) { // Nose-Hoover
    149       if (ThermostatImplemented[5] == 1) {
    150         Thermostat = NoseHoover;
    151         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &HooverMass, 1, critical); // read Hoovermass
    152         alpha = 0.;
    153       } else {
    154         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    155         Thermostat = None;
    156       }
    157     } else {
    158       DoLog(1) && (Log() << Verbose(1) << " Warning: thermostat name was not understood!" << endl);
    159       Thermostat = None;
    160     }
    161   } else {
    162     if ((MaxOuterStep > 0) && (TargetTemp != 0))
    163       DoLog(2) && (Log() << Verbose(2) <<  "No thermostat chosen despite finite temperature MD, falling back to None." << endl);
    164     Thermostat = None;
    165   }
    166   delete[](thermo);
    167 };
    168 
    16969
    17070/** Displays menu for editing each entry of the config file.
     
    508408};
    509409
    510 /** Initializes ConfigFileBuffer from a file.
    511  * \param *file input file stream being the opened config file
    512  * \param *FileBuffer pointer to FileBuffer on return, should point to NULL
    513  */
    514 void PrepareFileBuffer(const char * const filename, struct ConfigFileBuffer *&FileBuffer)
    515 {
    516   if (FileBuffer != NULL) {
    517     DoeLog(2) && (eLog()<< Verbose(2) << "deleting present FileBuffer in PrepareFileBuffer()." << endl);
    518     delete(FileBuffer);
    519   }
    520   FileBuffer = new ConfigFileBuffer(filename);
    521 
    522   FileBuffer->InitMapping();
    523 };
    524 
    525410/** Loads a molecule from a ConfigFileBuffer.
    526411 * \param *mol molecule to load
     
    719604
    720605  // ParseParameterFile
    721   struct ConfigFileBuffer *FileBuffer = NULL;
    722   PrepareFileBuffer(filename,FileBuffer);
     606  class ConfigFileBuffer *FileBuffer = new ConfigFileBuffer(filename);
    723607
    724608  /* Oeffne Hauptparameterdatei */
     
    729613  int verbose = 0;
    730614 
    731   ParseThermostats(FileBuffer);
     615  //TODO: This is actually sensible?: if (MaxOuterStep > 0)
     616  Thermostats->ParseThermostats(FileBuffer);
    732617 
    733618  /* Namen einlesen */
     
    793678  ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
    794679  ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
    795   ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
     680  ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(Thermostats->TargetTemp), 1, optional);
    796681  //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
    797682  if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
     
    1002887  ParseForParameter(verbose,file,"VisOuterStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
    1003888  ParseForParameter(verbose,file,"VisSrcOuterStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
    1004   ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
    1005   ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
     889  ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(Thermostats->TargetTemp), 1, optional);
     890  ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(Thermostats->ScaleTempStep), 1, optional);
    1006891  config::EpsWannier = 1e-8;
    1007892
     
    11911076    *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
    11921077    *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
    1193     *output << "Thermostat\t" << ThermostatNames[Thermostat] << "\t";
    1194     switch(Thermostat) {
     1078    *output << "Thermostat\t" << Thermostats->ThermostatNames[Thermostats->Thermostat] << "\t";
     1079    switch(Thermostats->Thermostat) {
    11951080      default:
    11961081      case None:
    11971082        break;
    11981083      case Woodcock:
    1199         *output << ScaleTempStep;
     1084        *output << Thermostats->ScaleTempStep;
    12001085        break;
    12011086      case Gaussian:
    1202         *output << ScaleTempStep;
     1087        *output << Thermostats->ScaleTempStep;
    12031088        break;
    12041089      case Langevin:
    1205         *output << TempFrequency << "\t" << alpha;
     1090        *output << Thermostats->TempFrequency << "\t" << Thermostats->alpha;
    12061091        break;
    12071092      case Berendsen:
    1208         *output << TempFrequency;
     1093        *output << Thermostats->TempFrequency;
    12091094        break;
    12101095      case NoseHoover:
    1211         *output << HooverMass;
     1096        *output << Thermostats->HooverMass;
    12121097        break;
    12131098    };
     
    12241109    *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
    12251110    *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
    1226     *output << "TargetTemp\t" << config::TargetTemp << "\t# Target temperature" << endl;
     1111    *output << "TargetTemp\t" << Thermostats->TargetTemp << "\t# Target temperature" << endl;
    12271112    *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
    12281113    *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
Note: See TracChangeset for help on using the changeset viewer.