Changeset 7e27e7 for src


Ignore:
Timestamp:
Sep 3, 2008, 5:28:31 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, 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:
ed060e
Parents:
dd8cf8
Message:

BUGFIX: config::load() parses endlessly if there are no atoms in the config file.

Since MaxTypes is 0, we check for it and don't scan if there are none according to it. If MaxTypes != 0 however there are no ions given, we break with an error message (which was missing before in config:ParseForParameters()).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/config.cpp

    rdd8cf8 r7e27e7  
    635635  if (!ParseForParameter(verbose,file,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
    636636    config::StructOpt = 0;
    637   // prescan number of ions per type
    638   cout << Verbose(0) << "Prescanning ions per type: " << endl;
    639   for (int i=0; i < config::MaxTypes; i++) {
    640     sprintf(name,"Ion_Type%i",i+1);
    641     ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
    642     ParseForParameter(verbose,file, name, 0, 2, 1, int_type, &Z, 1, critical);
    643     elementhash[i] = periode->FindElement(Z);
    644     cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl;
    645   }
    646   int repetition = 0; // which repeated keyword shall be read
    647 
    648   map<int, atom *> AtomList[config::MaxTypes];
    649   if (!FastParsing) {
    650     // parse in trajectories
    651     bool status = true;
    652     atom *neues = NULL;
    653     while (status) {
    654       cout << "Currently parsing MD step " << repetition << "." << endl;
     637  if (MaxTypes == 0) {
     638    cerr << "There are no atoms according to MaxTypes in this config file." << endl;
     639  } else {
     640    // prescan number of ions per type
     641    cout << Verbose(0) << "Prescanning ions per type: " << endl;
     642    for (int i=0; i < config::MaxTypes; i++) {
     643      sprintf(name,"Ion_Type%i",i+1);
     644      ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
     645      ParseForParameter(verbose,file, name, 0, 2, 1, int_type, &Z, 1, critical);
     646      elementhash[i] = periode->FindElement(Z);
     647      cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl;
     648    }
     649    int repetition = 0; // which repeated keyword shall be read
     650 
     651    map<int, atom *> AtomList[config::MaxTypes];
     652    if (!FastParsing) {
     653      // parse in trajectories
     654      bool status = true;
     655      atom *neues = NULL;
     656      while (status) {
     657        cout << "Currently parsing MD step " << repetition << "." << endl;
     658        for (int i=0; i < config::MaxTypes; i++) {
     659          sprintf(name,"Ion_Type%i",i+1);
     660          for(int j=0;j<No[i];j++) {
     661            sprintf(keyword,"%s_%i",name, j+1);
     662            if (repetition == 0) {
     663              neues = new atom();
     664              AtomList[i][j] = neues;
     665              neues->type = elementhash[i]; // find element type
     666              mol->AddAtom(neues);
     667            } else
     668              neues = AtomList[i][j];
     669            status = (status &&
     670                    ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&
     671                    ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&
     672                    ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&
     673                    ParseForParameter(verbose,file, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));
     674            if (!status) break;
     675   
     676            // check size of vectors
     677            if (mol->Trajectories[neues].R.size() <= (unsigned int)(repetition)) {
     678              //cout << "Increasing size for trajectory array of " << keyword << " to " << (repetition+10) << "." << endl;
     679              mol->Trajectories[neues].R.resize(repetition+10);
     680              mol->Trajectories[neues].U.resize(repetition+10);
     681              mol->Trajectories[neues].F.resize(repetition+10);
     682            }
     683         
     684            // put into trajectories list
     685            for (int d=0;d<NDIM;d++)
     686              mol->Trajectories[neues].R.at(repetition).x[d] = neues->x.x[d];
     687           
     688            // parse velocities if present
     689            if(!ParseForParameter(verbose,file, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))
     690              neues->v.x[0] = 0.;
     691            if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))
     692              neues->v.x[1] = 0.;
     693            if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))
     694              neues->v.x[2] = 0.;
     695            for (int d=0;d<NDIM;d++)
     696              mol->Trajectories[neues].U.at(repetition).x[d] = neues->v.x[d];
     697     
     698            // parse forces if present
     699            if(!ParseForParameter(verbose,file, keyword, 0, 8, 1, double_type, &value[0], 1,optional))
     700              value[0] = 0.;
     701            if(!ParseForParameter(verbose,file, keyword, 0, 9, 1, double_type, &value[1], 1,optional))
     702              value[1] = 0.;
     703            if(!ParseForParameter(verbose,file, keyword, 1, 10, 1, double_type, &value[2], 1,optional))
     704              value[2] = 0.;
     705            for (int d=0;d<NDIM;d++)
     706              mol->Trajectories[neues].F.at(repetition).x[d] = value[d];
     707 
     708  //            cout << "Parsed position of step " << (repetition) << ": (";
     709  //            for (int d=0;d<NDIM;d++)
     710  //              cout << mol->Trajectories[neues].R.at(repetition).x[d] << " ";          // next step
     711  //            cout << ")\t(";
     712  //            for (int d=0;d<NDIM;d++)
     713  //              cout << mol->Trajectories[neues].U.at(repetition).x[d] << " ";          // next step
     714  //            cout << ")\t(";
     715  //            for (int d=0;d<NDIM;d++)
     716  //              cout << mol->Trajectories[neues].F.at(repetition).x[d] << " ";          // next step
     717  //            cout << ")" << endl;
     718          }
     719        }
     720        repetition++;
     721      }
     722      repetition--;
     723      cout << "Found " << repetition << " trajectory steps." << endl;
     724      mol->MDSteps = repetition;
     725    } else {
     726      // 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)
     727      repetition = 0;
     728      while ( ParseForParameter(verbose,file, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&
     729              ParseForParameter(verbose,file, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&
     730              ParseForParameter(verbose,file, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
     731        repetition++;
     732      cout << "I found " << repetition << " times the keyword Ion_Type1_1." << endl;
     733      // parse in molecule coordinates
    655734      for (int i=0; i < config::MaxTypes; i++) {
    656735        sprintf(name,"Ion_Type%i",i+1);
    657736        for(int j=0;j<No[i];j++) {
    658737          sprintf(keyword,"%s_%i",name, j+1);
    659           if (repetition == 0) {
    660             neues = new atom();
    661             AtomList[i][j] = neues;
    662             neues->type = elementhash[i]; // find element type
    663             mol->AddAtom(neues);
    664           } else
    665             neues = AtomList[i][j];
    666           status = (status &&
    667                   ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&
    668                   ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&
    669                   ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&
    670                   ParseForParameter(verbose,file, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));
    671           if (!status) break;
    672  
    673           // check size of vectors
    674           if (mol->Trajectories[neues].R.size() <= (unsigned int)(repetition)) {
    675             //cout << "Increasing size for trajectory array of " << keyword << " to " << (repetition+10) << "." << endl;
    676             mol->Trajectories[neues].R.resize(repetition+10);
    677             mol->Trajectories[neues].U.resize(repetition+10);
    678             mol->Trajectories[neues].F.resize(repetition+10);
    679           }
    680        
    681           // put into trajectories list
    682           for (int d=0;d<NDIM;d++)
    683             mol->Trajectories[neues].R.at(repetition).x[d] = neues->x.x[d];
    684          
    685           // parse velocities if present
    686           if(!ParseForParameter(verbose,file, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))
     738          atom *neues = new atom();
     739          // then parse for each atom the coordinates as often as present
     740          ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
     741          ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
     742          ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
     743          ParseForParameter(verbose,file, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
     744          if(!ParseForParameter(verbose,file, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
    687745            neues->v.x[0] = 0.;
    688           if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))
     746          if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
    689747            neues->v.x[1] = 0.;
    690           if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))
     748          if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
    691749            neues->v.x[2] = 0.;
    692           for (int d=0;d<NDIM;d++)
    693             mol->Trajectories[neues].U.at(repetition).x[d] = neues->v.x[d];
    694    
    695           // parse forces if present
    696           if(!ParseForParameter(verbose,file, keyword, 0, 8, 1, double_type, &value[0], 1,optional))
    697             value[0] = 0.;
    698           if(!ParseForParameter(verbose,file, keyword, 0, 9, 1, double_type, &value[1], 1,optional))
    699             value[1] = 0.;
    700           if(!ParseForParameter(verbose,file, keyword, 1, 10, 1, double_type, &value[2], 1,optional))
    701             value[2] = 0.;
    702           for (int d=0;d<NDIM;d++)
    703             mol->Trajectories[neues].F.at(repetition).x[d] = value[d];
    704 
    705 //            cout << "Parsed position of step " << (repetition) << ": (";
    706 //            for (int d=0;d<NDIM;d++)
    707 //              cout << mol->Trajectories[neues].R.at(repetition).x[d] << " ";          // next step
    708 //            cout << ")\t(";
    709 //            for (int d=0;d<NDIM;d++)
    710 //              cout << mol->Trajectories[neues].U.at(repetition).x[d] << " ";          // next step
    711 //            cout << ")\t(";
    712 //            for (int d=0;d<NDIM;d++)
    713 //              cout << mol->Trajectories[neues].F.at(repetition).x[d] << " ";          // next step
    714 //            cout << ")" << endl;
     750          // here we don't care if forces are present (last in trajectories is always equal to current position)
     751          neues->type = elementhash[i]; // find element type
     752          mol->AddAtom(neues);
    715753        }
    716       }
    717       repetition++;
    718     }
    719     repetition--;
    720     cout << "Found " << repetition << " trajectory steps." << endl;
    721     mol->MDSteps = repetition;
    722   } else {
    723     // 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)
    724     repetition = 0;
    725     while ( ParseForParameter(verbose,file, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&
    726             ParseForParameter(verbose,file, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&
    727             ParseForParameter(verbose,file, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
    728       repetition++;
    729     cout << "I found " << repetition << " times the keyword Ion_Type1_1." << endl;
    730     // parse in molecule coordinates
    731     for (int i=0; i < config::MaxTypes; i++) {
    732       sprintf(name,"Ion_Type%i",i+1);
    733       for(int j=0;j<No[i];j++) {
    734         sprintf(keyword,"%s_%i",name, j+1);
    735         atom *neues = new atom();
    736         // then parse for each atom the coordinates as often as present
    737         ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
    738         ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
    739         ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
    740         ParseForParameter(verbose,file, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
    741         if(!ParseForParameter(verbose,file, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
    742           neues->v.x[0] = 0.;
    743         if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
    744           neues->v.x[1] = 0.;
    745         if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
    746           neues->v.x[2] = 0.;
    747         // here we don't care if forces are present (last in trajectories is always equal to current position)
    748         neues->type = elementhash[i]; // find element type
    749         mol->AddAtom(neues);
    750754      }
    751755    }
     
    11551159          Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
    11561160          //Error(InitReading, name);
    1157           //fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     1161          fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
    11581162          exit(255);
    11591163        } else {
Note: See TracChangeset for help on using the changeset viewer.