Changeset 9131f3


Ignore:
Timestamp:
Mar 30, 2010, 1:22:20 PM (15 years ago)
Author:
Saskia Metzler <metzler@…>
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:
4415da
Parents:
cb2146
Message:

WIP tremolo parser

Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    rcb2146 r9131f3  
    1111ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/Calculation.hpp Actions/Calculation_impl.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ManipulateAtomsProcess.hpp Actions/ActionRegistry.hpp
    1212
    13 PARSERSOURCE = Parser/ChangeTracker.cpp Parser/FormatParser.cpp Parser/XyzParser.cpp
    14 PARSERHEADER = Parser/ChangeTracker.hpp Parser/FormatParser.hpp Parser/XyzParser.hpp
     13PARSERSOURCE = Parser/ChangeTracker.cpp Parser/FormatParser.cpp Parser/TremoloParser.cpp Parser/XyzParser.cpp
     14PARSERHEADER = Parser/ChangeTracker.hpp Parser/FormatParser.hpp Parser/TremoloParser.hpp Parser/XyzParser.hpp
    1515
    1616PATTERNSOURCE = Patterns/Observer.cpp
  • src/Parser/FormatParser.cpp

    rcb2146 r9131f3  
    77
    88#include "FormatParser.hpp"
     9#include <iostream>
    910
    1011using namespace std;
     
    3132void FormatParser::update(Observable *publisher) {
    3233  if (!saveStream) {
    33 //    throw new Exception("Please invoke setOfstream() so the parser knows where to save the World's data.");
     34    cerr << "Please invoke setOstream() so the parser knows where to save the World's data." << endl;
     35    return;
    3436  }
    3537
  • src/Parser/TremoloParser.cpp

    rcb2146 r9131f3  
    66 */
    77
    8 void TremoloParser::load(char* fileName) {
    9 MatrixContainer* data = readData(fileName, getHeaderSize('#'), 0);
    10 store additional data
    11 for (each line in matrix) {
    12   add atom to the world
    13 }
     8#include "TremoloParser.hpp"
     9#include "World.hpp"
     10#include "atom.hpp"
     11#include "element.hpp"
     12#include "periodentafel.hpp"
     13#include <map>
     14#include <vector>
     15
     16using namespace std;
     17
     18/**
     19 * Constructor.
     20 */
     21TremoloParser::TremoloParser() {
     22  knownKeys["x"] = x;
     23  knownKeys["u"] = u;
     24  knownKeys["F"] = F;
     25  knownKeys["stress"] = stress;
     26  knownKeys["Id"] = Id;
     27  knownKeys["neighbors"] = neighbors;
     28  knownKeys["imprData"] = imprData;
     29  knownKeys["GroupMeasureTypeNo"] = GroupMeasureTypeNo;
     30  knownKeys["Type"] = Type;
     31  knownKeys["extType"] = extType;
     32  knownKeys["name"] = name;
     33  knownKeys["resName"] = resName;
     34  knownKeys["chainID"] = chainID;
     35  knownKeys["resSeq"] = resSeq;
     36  knownKeys["occupancy"] = occupancy;
     37  knownKeys["tempFactor"] = tempFactor;
     38  knownKeys["segID"] = segID;
     39  knownKeys["Charge"] = Charge;
     40  knownKeys["charge"] = charge;
     41  knownKeys["GrpTypeNo"] = GrpTypeNo;
    1442}
    1543
    16 void TremoloParser::save(char* fileName) {
     44/**
     45 * Destructor.
     46 */
     47TremoloParser::~TremoloParser() {
     48}
     49
     50/**
     51 * Stores keys from the ATOMDATA line.
     52 *
     53 * \param line to parse the keys from
     54 * \param with which offset the keys begin within the line
     55 */
     56void TremoloParser::parseAtomDataKeysLine(string line, int offset) {
     57  string keyword;
     58  stringstream lineStream;
     59
     60  lineStream << line.substr(offset);
     61  while (lineStream.good()) {
     62    lineStream >> keyword;
     63    usedFields.push_back(keyword);
     64  }
     65}
     66
     67/**
     68 * Reads one data line of a tremolo file and interprets it according to the keys
     69 * obtained from the ATOMDATA line.
     70 *
     71 * \param line to parse as an atom
     72 */
     73void TremoloParser::readAtomDataLine(string line) {
     74  vector<string>::iterator it;
     75  stringstream lineStream;
     76  string word;
     77
     78  lineStream << line;
     79  for (it=usedFields.begin(); it < usedFields.end(); it++) {
     80    cout << *it << " -- " << it->substr(0, it->find("=")) << " -- " << knownKeys[it->substr(0, it->find("="))] << endl;
     81    switch (knownKeys[it->substr(0, it->find("="))]) {
     82      case x :
     83        lineStream >> word;
     84        cout<< "Found an x: word: " << word << endl;
     85        break;
     86      default :
     87        lineStream >> word;
     88        cout << "Unknown key: " << *it << ", word: " << word << endl;
     89        break;
     90    }
     91  }
     92}
     93
     94
     95/**
     96 * Loads atoms from a tremolo-formatted file.
     97 *
     98 * \param tremolo file
     99 */
     100void TremoloParser::load(istream* file) {
     101  string line;
     102  string::size_type location;
     103
     104  usedFields.clear();
     105  while (file->good()) {
     106    std::getline(*file, line, '\n');
     107    if (usedFields.empty()) {
     108      location = line.find("ATOMDATA", 0);
     109      if (location != string::npos) {
     110       parseAtomDataKeysLine(line, location + 8);
     111      }
     112    }
     113    if (line.length() > 0 && line.at(0) != '#') {
     114      readAtomDataLine(line);
     115    }
     116  }
     117}
     118
     119/*
     120#ATOMDATA  <record_entry_1> ... <record_entry_n>
     121# <record_entry>: <dataname>[=<n>]
     122# <dataname>    : x | u | F | stress | Id | neighbors | imprData
     123#               | GroupMeasureTypeNo | Type | extType
     124#               | name | resName | chainID | resSeq
     125#               | occupancy | tempFactor | segID | Charge
     126#               | charge
     127ATOMDATA name Id x=3 mass charge epsilon sigma eps14 sig14 name type protein protno neighbors=4
     128*/
     129
     130//MatrixContainer* data = readData(fileName, getHeaderSize('#'), 0);
     131
     132
     133/**
     134 * Saves the World's current state into as a tremolo file.
     135 *
     136 * \param file where to save the state
     137 */
     138void TremoloParser::save(ostream* file) {
     139/*
    17140write header
    18141for (each atom in world) {
    19142  write coordinates and additional data
    20143}
     144*/
    21145}
  • src/Parser/TremoloParser.hpp

    rcb2146 r9131f3  
    99#define TREMOLOPARSER_HPP_
    1010
     11#include <string>
    1112#include "FormatParser.hpp"
    12 #include "World.hpp"
    1313
    14 class TremoloParser : public FormatParser {
     14class TremoloParser:public FormatParser
     15{
    1516public:
    16   void load(char* fileName);
    17   void save(char* fileName);
     17  TremoloParser();
     18  ~TremoloParser();
     19  void load(std::istream* file);
     20  void save(std::ostream* file);
    1821
    1922private:
    20   map<std::string, std::string> moreData;
     23  void readAtomDataLine(string line);
     24  void parseAtomDataKeysLine(string line, int offset);
     25
     26  /**
     27   * Known keys for the ATOMDATA line.
     28   */
     29  enum StringValue {
     30    x,
     31    u,
     32    F,
     33    stress,
     34    Id,
     35    neighbors,
     36    imprData,
     37    GroupMeasureTypeNo,
     38    Type,
     39    extType,
     40    name,
     41    resName,
     42    chainID,
     43    resSeq,
     44    occupancy,
     45    tempFactor,
     46    segID,
     47    Charge,
     48    charge,
     49    GrpTypeNo
     50  };
     51
     52  /**
     53   * Map to associate the known keys with numbers.
     54   */
     55  std::map<std::string, StringValue> knownKeys;
     56
     57  /**
     58   * Fields used in the tremolo file.
     59   */
     60  std::vector<std::string> usedFields;
     61
     62  /**
     63   * Data which is currently not stored in atoms but was provided by the input
     64   * file.
     65   */
     66  std::map<std::string, std::string> moreData;
    2167};
    2268
  • src/unittests/Makefile.am

    rcb2146 r9131f3  
    5555  bondgraphunittest.cpp \
    5656  CacheableTest.cpp \
    57   DescriptorUnittest.cpp \
    5857  gslmatrixsymmetricunittest.cpp \
    5958  gslmatrixunittest.cpp \
  • src/unittests/ParserUnitTest.cpp

    rcb2146 r9131f3  
    1313
    1414#include "Parser/XyzParser.hpp"
     15#include "Parser/TremoloParser.hpp"
    1516#include "World.hpp"
    1617#include "element.hpp"
     
    4546
    4647void ParserUnitTest::rewriteAnXyzTest() {
     48  cout << "Testing the XYZ parser." << endl;
    4749  XyzParser* testParser = new XyzParser();
    4850  string waterXyz = "3\nH2O: water molecule\nO\t0.000000\t0.000000\t0.000000\nH\t0.758602\t0.000000\t0.504284\nH\t0.758602\t0.000000\t-0.504284\n";
     
    6163}
    6264
     65void ParserUnitTest::rewriteTremoloTest() {
     66  cout << "Testing the tremolo parser." << endl;
     67  TremoloParser* testParser = new TremoloParser();
     68  string waterTremolo = "#\n# ATOMDATA Id name Type x=3\n\n\n";
     69  stringstream input;
     70  input << waterTremolo;
     71  testParser->load(&input);
     72  waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n";
     73  input.clear();
     74  input << waterTremolo;
     75  testParser->load(&input);
     76  cout << "testing the tremolo parser is done" << endl;
     77}
  • src/unittests/ParserUnitTest.hpp

    rcb2146 r9131f3  
    1515  CPPUNIT_TEST_SUITE( ParserUnitTest ) ;
    1616  CPPUNIT_TEST ( rewriteAnXyzTest );
     17  CPPUNIT_TEST ( rewriteTremoloTest );
    1718  CPPUNIT_TEST_SUITE_END();
    1819
     
    2223
    2324  void rewriteAnXyzTest();
     25  void rewriteTremoloTest();
    2426};
    2527
Note: See TracChangeset for help on using the changeset viewer.