Changeset 5a667d


Ignore:
Timestamp:
Jun 14, 2012, 9:02:58 AM (13 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:
27cfde
Parents:
2169e0
git-author:
Michael Ankele <ankele@…> (05/14/12 11:54:32)
git-committer:
Frederik Heber <heber@…> (06/14/12 09:02:58)
Message:

AtomDataValidator implemented, uses static FormatParser<tremolo>::testParseAtomDataKeysLine().

  • added static ::testParseAtomDataKeysLine() as it does not need or change any parser internal information it may as well be static and can then be used outside the FormatParserStorage. Works with or without leading ATOMDATA.
  • knownKeys is now static member of FormatParser<tremolo>, initialised by boost::assign's map_list_of().
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parameters/Validators/Specific/AtomDataValidator.cpp

    r2169e0 r5a667d  
    2323#include "AtomDataValidator.hpp"
    2424
     25#include "Parser/TremoloParser.hpp"
     26
    2527bool AtomDataValidator::isValid(const std::string & _value) const
    2628{
    27   return true; // TODO
     29  return FormatParser< tremolo >::testParseAtomDataKeysLine(_value);
    2830}
    2931
  • src/Parser/TremoloParser.cpp

    r2169e0 r5a667d  
    4949#include <vector>
    5050
     51#include <boost/assign/list_of.hpp> // for 'map_list_of()'
     52#include <boost/assert.hpp>
     53
    5154// declare specialized static variables
    5255const std::string FormatParserTrait<tremolo>::name = "tremolo";
     
    5457const ParserTypes FormatParserTrait<tremolo>::type = tremolo;
    5558
     59// static instances
     60std::map<std::string, TremoloKey::atomDataKey> FormatParser<tremolo>::knownKeys =
     61    boost::assign::map_list_of("x",TremoloKey::x)
     62    ("u",TremoloKey::u)
     63    ("F",TremoloKey::F)
     64    ("stress",TremoloKey::stress)
     65    ("Id",TremoloKey::Id)
     66    ("neighbors",TremoloKey::neighbors)
     67    ("imprData",TremoloKey::imprData)
     68    ("GroupMeasureTypeNo",TremoloKey::GroupMeasureTypeNo)
     69    ("type",TremoloKey::type)
     70    ("extType",TremoloKey::extType)
     71    ("name",TremoloKey::name)
     72    ("resName",TremoloKey::resName)
     73    ("chainID",TremoloKey::chainID)
     74    ("resSeq",TremoloKey::resSeq)
     75    ("occupancy",TremoloKey::occupancy)
     76    ("tempFactor",TremoloKey::tempFactor)
     77    ("segID",TremoloKey::segID)
     78    ("Charge",TremoloKey::Charge)
     79    ("charge",TremoloKey::charge)
     80    ("GrpTypeNo",TremoloKey::GrpTypeNo)
     81    ("torsion",TremoloKey::torsion)
     82    (" ",TremoloKey::noKey); // with this we can detect invalid keys
     83
    5684/**
    5785 * Constructor.
     
    6088  FormatParser_common(NULL)
    6189{
    62   knownKeys["x"] = TremoloKey::x;
    63   knownKeys["u"] = TremoloKey::u;
    64   knownKeys["F"] = TremoloKey::F;
    65   knownKeys["stress"] = TremoloKey::stress;
    66   knownKeys["Id"] = TremoloKey::Id;
    67   knownKeys["neighbors"] = TremoloKey::neighbors;
    68   knownKeys["imprData"] = TremoloKey::imprData;
    69   knownKeys["GroupMeasureTypeNo"] = TremoloKey::GroupMeasureTypeNo;
    70   knownKeys["type"] = TremoloKey::type;
    71   knownKeys["extType"] = TremoloKey::extType;
    72   knownKeys["name"] = TremoloKey::name;
    73   knownKeys["resName"] = TremoloKey::resName;
    74   knownKeys["chainID"] = TremoloKey::chainID;
    75   knownKeys["resSeq"] = TremoloKey::resSeq;
    76   knownKeys["occupancy"] = TremoloKey::occupancy;
    77   knownKeys["tempFactor"] = TremoloKey::tempFactor;
    78   knownKeys["segID"] = TremoloKey::segID;
    79   knownKeys["Charge"] = TremoloKey::Charge;
    80   knownKeys["charge"] = TremoloKey::charge;
    81   knownKeys["GrpTypeNo"] = TremoloKey::GrpTypeNo;
    82   knownKeys["torsion"] = TremoloKey::torsion;
    83   knownKeys[" "] = TremoloKey::noKey; // with this we can detect invalid keys
    84 
    8590  createKnownTypesByIdentity();
    8691
     
    9297}
    9398
     99
    94100/**
    95101 * Destructor.
     
    99105  usedFields_save.clear();
    100106  additionalAtomData.clear();
    101   knownKeys.clear();
    102107}
    103108
     
    441446    if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) {
    442447      // TODO: throw exception about unknown key
    443       cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl;
     448      cout << "Unknown key: " << keyword.substr(0, keyword.find("=")) << " is not part of the tremolo format specification." << endl;
     449      throw IllegalParserKeyException();
    444450      break;
    445451    }
     
    447453  }
    448454  //LOG(1, "INFO: " << fields);
     455}
     456
     457/**
     458 * Tests whether the keys from the ATOMDATA line can be read correctly.
     459 *
     460 * \param line to parse the keys from
     461 */
     462bool FormatParser< tremolo >::testParseAtomDataKeysLine(
     463    const std::string &line) {
     464  std::string keyword;
     465  std::stringstream lineStream;
     466
     467  // check string after ATOMDATA
     468  const std::string AtomData("ATOMDATA");
     469  const size_t AtomDataOffset = line.find(AtomData, 0);
     470  if (AtomDataOffset == std::string::npos)
     471    lineStream << line;
     472  else
     473    lineStream << line.substr(AtomDataOffset + AtomData.length());
     474  while (lineStream.good()) {
     475    lineStream >> keyword;
     476    //LOG(2, "DEBUG: Checking key " << keyword.substr(0, keyword.find("=")) << ".");
     477    if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey)
     478      return false;
     479  }
     480  //LOG(1, "INFO: " << fields);
     481  return true;
    449482}
    450483
  • src/Parser/TremoloParser.hpp

    r2169e0 r5a667d  
    2727
    2828class molecule;
     29class AtomDataValidator;
    2930
    3031// declaration of specialized FormatParserTrait
     
    4647class FormatParser< tremolo >  : virtual public FormatParserInterface, public FormatParser_common
    4748{
     49  friend class AtomDataValidator;
    4850public:
    4951  FormatParser();
     
    9294  void readAtomDataLine(const std::string &line, molecule *newmol);
    9395  void parseAtomDataKeysLine(const std::string &line, const int offset, usedFields_t &fields);
     96  static bool testParseAtomDataKeysLine(const std::string &line);
    9497  void readNeighbors(std::stringstream* line, const int numberOfNeighbors, const int atomId);
    9598  void processNeighborInformation(const std::vector<atomId_t> &atoms);
     
    108111   * Map to associate the known keys with numbers.
    109112   */
    110   std::map<std::string, TremoloKey::atomDataKey> knownKeys;
     113  static std::map<std::string, TremoloKey::atomDataKey> knownKeys;
    111114
    112115  /**
  • src/Parser/unittests/ParserTremoloUnitTest.cpp

    r2169e0 r5a667d  
    2323#include <cppunit/extensions/TestFactoryRegistry.h>
    2424#include <cppunit/ui/text/TestRunner.h>
     25
     26#include "CodePatterns/Log.hpp"
    2527
    2628#include "Atom/atom.hpp"
     
    9193  World::getInstance();
    9294
     95  setVerbosity(5);
     96
    9397  parser = new FormatParser<tremolo>();
    9498
     
    139143  // Invalid key in Atomdata line
    140144  input << Tremolo_invalidkey;
    141   parser->load(&input);
     145  CPPUNIT_ASSERT_THROW( parser->load(&input), IllegalParserKeyException);
    142146  //TODO: prove invalidity
    143147  input.clear();
Note: See TracChangeset for help on using the changeset viewer.