source: molecuilder/src/Parser/TremoloParser.cpp@ 2704e2

Last change on this file since 2704e2 was 2704e2, checked in by Saskia Metzler <metzler@…>, 16 years ago

WIP tremolo parser

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * TremoloParser.cpp
3 *
4 * Created on: Mar 2, 2010
5 * Author: metzler
6 */
7
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;
42}
43
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/*
140write header
141for (each atom in world) {
142 write coordinates and additional data
143}
144*/
145}
Note: See TracBrowser for help on using the repository browser.