Ignore:
Timestamp:
Feb 24, 2011, 7:47:41 PM (14 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:
fcac72
Parents:
03c77c
git-author:
Frederik Heber <heber@…> (02/24/11 11:20:52)
git-committer:
Frederik Heber <heber@…> (02/24/11 19:47:41)
Message:

Rewrote LoadMolecule() for PcpParser.

  • LoadMolecule() rewritten as only because of getter/setter introduction the PcpParser did not work properly anymore. Used boost::tokenizer for parsing all Ion_Type stuff.
  • TESTFIX: Molecules/SaveTemperature - has been buggy since a long time! LoadMolecule() did the messed up sequence of Ion_Type right only for the first step not for all subsequent steps. Hence, we lacked the velocities of all non-hydrogen atoms and obtained a different (wrong) temperature.
  • TESTFIX: ParserPcpUnitTest made first atom at (1,0,0) instead of (0,0,0) as this rather shows up parsing errors than zero vector which is default value.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ConfigFileBuffer.cpp

    r03c77c r6a465e  
    2020#include "CodePatterns/MemDebug.hpp"
    2121
     22#include <iostream>
     23#include <boost/tokenizer.hpp>
     24#include <string>
     25
    2226#include "ConfigFileBuffer.hpp"
    2327#include "Helpers/helpers.hpp"
     
    3135 */
    3236struct IonTypeCompare {
    33   bool operator()(const char* s1, const char *s2) const {
    34     char number1[8];
    35     char number2[8];
    36     const char *dummy1, *dummy2;
    37     //Log() << Verbose(0) << s1 << "  " << s2 << endl;
    38     dummy1 = strchr(s1, '_')+sizeof(char)*5;  // go just after "Ion_Type"
    39     dummy2 = strchr(dummy1, '_');
    40     strncpy(number1, dummy1, dummy2-dummy1); // copy the number
    41     number1[dummy2-dummy1]='\0';
    42     dummy1 = strchr(s2, '_')+sizeof(char)*5;  // go just after "Ion_Type"
    43     dummy2 = strchr(dummy1, '_');
    44     strncpy(number2, dummy1, dummy2-dummy1); // copy the number
    45     number2[dummy2-dummy1]='\0';
    46     if (atoi(number1) != atoi(number2))
    47       return (atoi(number1) < atoi(number2));
     37  bool operator()(std::string s1, std::string s2) const {
     38    ConvertTo<int> toInt;
     39    boost::char_separator<char> sep("_");
     40    tokenizer tokens1(s1,sep);
     41    tokenizer tokens2(s2,sep);
     42    tokenizer::iterator tok_iter1 = tokens1.begin();
     43    tokenizer::iterator tok_iter2 = tokens2.begin();
     44    ++tok_iter1;
     45    ++tok_iter2;
     46
     47    std::string element1(*tok_iter1++);
     48    std::string element2(*tok_iter2++);
     49    int elementno1 = toInt(element1.substr(4,string::npos));
     50    int elementno2 = toInt(element2.substr(4,string::npos));
     51    if (elementno1 != elementno2)
     52      return elementno1 < elementno2;
    4853    else {
    49       dummy1 = strchr(s1, '_')+sizeof(char);
    50       dummy1 = strchr(dummy1, '_')+sizeof(char);
    51       dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
    52       strncpy(number1, dummy1, dummy2-dummy1); // copy the number
    53       number1[dummy2-dummy1]='\0';
    54       dummy1 = strchr(s2, '_')+sizeof(char);
    55       dummy1 = strchr(dummy1, '_')+sizeof(char);
    56       dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
    57       strncpy(number2, dummy1, dummy2-dummy1); // copy the number
    58       number2[dummy2-dummy1]='\0';
    59       return (atoi(number1) < atoi(number2));
     54      std::string atom1(*tok_iter1);
     55      std::string atom2(*tok_iter2);
     56      int atomno1 = toInt(atom1);
     57      int atomno2 = toInt(atom2);
     58      return atomno1 < atomno2;
    6059    }
    61   }
     60
     61//    char number1[8];
     62//    char number2[8];
     63//    const char *dummy1 = s1.c_str();
     64//    const char *dummy2 = s2.c_str();
     65//    //Log() << Verbose(0) << s1 << "  " << s2 << endl;
     66//    dummy1 = strchr(s1, '_')+sizeof(char)*5;  // go just after "Ion_Type"
     67//    dummy2 = strchr(dummy1, '_');
     68//    strncpy(number1, dummy1, dummy2-dummy1); // copy the number
     69//    number1[dummy2-dummy1]='\0';
     70//    dummy1 = strchr(s2, '_')+sizeof(char)*5;  // go just after "Ion_Type"
     71//    dummy2 = strchr(dummy1, '_');
     72//    strncpy(number2, dummy1, dummy2-dummy1); // copy the number
     73//    number2[dummy2-dummy1]='\0';
     74//    if (atoi(number1) != atoi(number2))
     75//      return (atoi(number1) < atoi(number2));
     76//    else {
     77//      dummy1 = strchr(s1, '_')+sizeof(char);
     78//      dummy1 = strchr(dummy1, '_')+sizeof(char);
     79//      dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
     80//      strncpy(number1, dummy1, dummy2-dummy1); // copy the number
     81//      number1[dummy2-dummy1]='\0';
     82//      dummy1 = strchr(s2, '_')+sizeof(char);
     83//      dummy1 = strchr(dummy1, '_')+sizeof(char);
     84//      dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
     85//      strncpy(number2, dummy1, dummy2-dummy1); // copy the number
     86//      number2[dummy2-dummy1]='\0';
     87//      return (atoi(number1) < atoi(number2));
     88//    }
     89  }
     90
     91  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
    6292};
     93
    6394
    6495/** Constructor for ConfigFileBuffer class.
     
    182213void ConfigFileBuffer::MapIonTypesInBuffer(const int NoAtoms)
    183214{
    184   map<const char *, int, IonTypeCompare> IonTypeLineMap;
     215  std::multimap<std::string, int, IonTypeCompare> IonTypeLineMap;
    185216  if (!MappingAllocated) {
    186217    InitMapping();
    187218  }
    188219
     220  typedef boost::tokenizer<boost::char_separator<char> >
     221      tokenizer;
     222  boost::char_separator<char> sep("\t ");
     223
    189224  // put all into hashed map
    190   for (int i=0; i<NoAtoms; ++i) {
    191     IonTypeLineMap.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
    192   }
    193 
    194   // fill map
     225  for (int i=CurrentLine; i<NoLines; ++i) {
     226    std::string line(buffer[i]);
     227    tokenizer tokens(line, sep);
     228    if (tokens.begin() != tokens.end()) {
     229      const std::string token = *tokens.begin();
     230      if (token.find("Ion_Type") != string::npos) {
     231        IonTypeLineMap.insert(pair<std::string, int> (token, i));
     232      }
     233    }
     234  }
     235
     236  // fill map (aka IonType1_1, IonType1_1, IonType1_1, IonType1_2, IonType1_2, IonType1_2, ...
     237  // ..., IonType2_1, IonType2_1, IonType2_1, ...)
    195238  int nr=0;
    196   for (map<const char *, int, IonTypeCompare>::iterator runner = IonTypeLineMap.begin(); runner != IonTypeLineMap.end(); ++runner) {
     239  for (map<std::string, int, IonTypeCompare>::iterator runner = IonTypeLineMap.begin(); runner != IonTypeLineMap.end(); ++runner) {
    197240    if (CurrentLine+nr < NoLines)
    198241      LineMapping[CurrentLine+(nr++)] = runner->second;
    199242    else {
    200       DoeLog(0) && (eLog()<< Verbose(0) << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl);
     243      DoeLog(0) && (eLog()<< Verbose(0) << "config::MapIonTypesInBuffer - NoLines is wrong: We are past the end of the file!" << endl);
    201244      performCriticalExit();
    202245    }
Note: See TracChangeset for help on using the changeset viewer.