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