1 | /*
|
---|
2 | * TremoloParser.hpp
|
---|
3 | *
|
---|
4 | * Created on: Mar 2, 2010
|
---|
5 | * Author: metzler
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef TREMOLOPARSER_HPP_
|
---|
9 | #define TREMOLOPARSER_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include <string>
|
---|
17 |
|
---|
18 | #include "FormatParser.hpp"
|
---|
19 | #include "FormatParserTrait.hpp"
|
---|
20 | #include "FormatParserInterface.hpp"
|
---|
21 | #include "FormatParser_common.hpp"
|
---|
22 | #include "ParserTypes.hpp"
|
---|
23 |
|
---|
24 | #include "TremoloParser_ElementKeys.hpp"
|
---|
25 | #include "TremoloKey.hpp"
|
---|
26 | #include "TremoloAtomInfoContainer.hpp"
|
---|
27 |
|
---|
28 | class molecule;
|
---|
29 | class AtomDataValidator;
|
---|
30 |
|
---|
31 | // declaration of specialized FormatParserTrait
|
---|
32 | template<>
|
---|
33 | struct FormatParserTrait<tremolo>
|
---|
34 | {
|
---|
35 | //!> Name of the parser
|
---|
36 | static const std::string name;
|
---|
37 | //!> suffix of the files the parser understands to read and write
|
---|
38 | static const std::string suffix;
|
---|
39 | //!> ParserTypes enumeration for the parser
|
---|
40 | static const enum ParserTypes type;
|
---|
41 | };
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Loads a tremolo file into the World and saves the World as a tremolo file.
|
---|
45 | */
|
---|
46 | template <>
|
---|
47 | class FormatParser< tremolo > : virtual public FormatParserInterface, public FormatParser_common
|
---|
48 | {
|
---|
49 | friend class AtomDataValidator;
|
---|
50 | public:
|
---|
51 | FormatParser();
|
---|
52 | virtual ~FormatParser();
|
---|
53 | void load(std::istream* file);
|
---|
54 | void save(std::ostream* file, const std::vector<atom *> &atoms);
|
---|
55 | void setAtomData(const std::string &atomdata_string);
|
---|
56 |
|
---|
57 | private:
|
---|
58 | /**
|
---|
59 | * Map to associate element keys with the respective elements.
|
---|
60 | */
|
---|
61 | struct ElementKeys knownTypes;
|
---|
62 |
|
---|
63 | public:
|
---|
64 |
|
---|
65 | void parseKnownTypes(std::istream &file)
|
---|
66 | {
|
---|
67 | knownTypes.parseKnownTypes(file);
|
---|
68 | }
|
---|
69 | void createKnownTypesByIdentity()
|
---|
70 | {
|
---|
71 | knownTypes.createKnownTypesByIdentity();
|
---|
72 | }
|
---|
73 |
|
---|
74 | /** Save given \a atoms in tremolo's exttypes file
|
---|
75 | *
|
---|
76 | * \note You should have stored the atoms beforehand to give them unique
|
---|
77 | * and sensible ids.
|
---|
78 | *
|
---|
79 | * @param output output stream
|
---|
80 | * @param atoms vector of atoms whose ids to store
|
---|
81 | * @param id id to given this exttypes group
|
---|
82 | * @return true - all atomic ids are valid, false - one id was not set (-1)
|
---|
83 | */
|
---|
84 | bool saveAtomsInExttypes(std::ostream &output, const std::vector<atom*> &atoms, const int id) const;
|
---|
85 |
|
---|
86 | protected:
|
---|
87 | void AtomInserted(atomId_t);
|
---|
88 | void AtomRemoved(atomId_t);
|
---|
89 |
|
---|
90 | private:
|
---|
91 | //!> typedef for usedFields' vector of strings
|
---|
92 | typedef std::vector<std::string> usedFields_t;
|
---|
93 |
|
---|
94 | void readAtomDataLine(const std::string &line, molecule *newmol);
|
---|
95 | void parseAtomDataKeysLine(const std::string &line, const int offset, usedFields_t &fields);
|
---|
96 | static bool testParseAtomDataKeysLine(const std::string &line);
|
---|
97 | void readNeighbors(std::stringstream* line, const int numberOfNeighbors, const int atomId);
|
---|
98 | void processNeighborInformation(const std::vector<atomId_t> &atoms);
|
---|
99 | void adaptImprData();
|
---|
100 | void adaptTorsion();
|
---|
101 | std::string adaptIdDependentDataString(std::string data);
|
---|
102 | bool isUsedField(const usedFields_t &fields, const std::string &fieldName) const;
|
---|
103 | void writeNeighbors(std::ostream* file, const int numberOfNeighbors, const atom* currentAtom);
|
---|
104 | void saveLine(std::ostream* file, const atom* currentAtom);
|
---|
105 | void save_AtomDataLine(std::ostream* file) const;
|
---|
106 | void save_BoxLine(std::ostream* file) const;
|
---|
107 | void distributeContinuousIds(const std::vector<atom *> &AtomList);
|
---|
108 | void makeUsedFieldsUnique(usedFields_t &fields);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Map to associate the known keys with numbers.
|
---|
112 | */
|
---|
113 | static std::map<std::string, TremoloKey::atomDataKey> knownKeys;
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Inverse Map to have a name to each known keys.
|
---|
117 | */
|
---|
118 | std::map<TremoloKey::atomDataKey, std::string> knownKeyNames;
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Fields used globally when storing to a tremolo file.
|
---|
122 | */
|
---|
123 | usedFields_t usedFields_save;
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Fields used locally when parsing in a tremolo file.
|
---|
127 | */
|
---|
128 | usedFields_t usedFields_load;
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Data which is currently not stored in atoms but was provided by the input
|
---|
132 | * file.
|
---|
133 | */
|
---|
134 | std::map<const atomId_t, TremoloAtomInfoContainer> additionalAtomData;
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Default additional atom data.
|
---|
138 | */
|
---|
139 | TremoloAtomInfoContainer defaultAdditionalData;
|
---|
140 | };
|
---|
141 |
|
---|
142 | #endif /* TREMOLOPARSER_HPP_ */
|
---|