| 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 <string>
 | 
|---|
| 12 | #include "Parser/FormatParser.hpp"
 | 
|---|
| 13 | 
 | 
|---|
| 14 | /**
 | 
|---|
| 15 |  * Known keys for the ATOMDATA line.
 | 
|---|
| 16 |  */
 | 
|---|
| 17 | class TremoloKey {
 | 
|---|
| 18 | public:
 | 
|---|
| 19 |   enum atomDataKey {
 | 
|---|
| 20 |     noKey,
 | 
|---|
| 21 |     x,
 | 
|---|
| 22 |     u,
 | 
|---|
| 23 |     F,
 | 
|---|
| 24 |     stress,
 | 
|---|
| 25 |     Id,
 | 
|---|
| 26 |     neighbors,
 | 
|---|
| 27 |     imprData,
 | 
|---|
| 28 |     GroupMeasureTypeNo,
 | 
|---|
| 29 |     Type,
 | 
|---|
| 30 |     extType,
 | 
|---|
| 31 |     name,
 | 
|---|
| 32 |     resName,
 | 
|---|
| 33 |     chainID,
 | 
|---|
| 34 |     resSeq,
 | 
|---|
| 35 |     occupancy,
 | 
|---|
| 36 |     tempFactor,
 | 
|---|
| 37 |     segID,
 | 
|---|
| 38 |     Charge,
 | 
|---|
| 39 |     charge,
 | 
|---|
| 40 |     GrpTypeNo,
 | 
|---|
| 41 |     torsion
 | 
|---|
| 42 |   };
 | 
|---|
| 43 | };
 | 
|---|
| 44 | 
 | 
|---|
| 45 | /**
 | 
|---|
| 46 |  * Holds tremolo-specific information which is not store in the atom class.
 | 
|---|
| 47 |  */
 | 
|---|
| 48 | class TremoloAtomInfoContainer {
 | 
|---|
| 49 | public:
 | 
|---|
| 50 |   TremoloAtomInfoContainer();
 | 
|---|
| 51 |   void set(TremoloKey::atomDataKey key, std::string value);
 | 
|---|
| 52 |   std::string get(TremoloKey::atomDataKey key);
 | 
|---|
| 53 |   std::string F;
 | 
|---|
| 54 |   std::string stress;
 | 
|---|
| 55 |   std::string imprData;
 | 
|---|
| 56 |   std::string GroupMeasureTypeNo;
 | 
|---|
| 57 |   std::string extType;
 | 
|---|
| 58 |   std::string name;
 | 
|---|
| 59 |   std::string resName;
 | 
|---|
| 60 |   std::string chainID;
 | 
|---|
| 61 |   std::string resSeq;
 | 
|---|
| 62 |   std::string occupancy;
 | 
|---|
| 63 |   std::string tempFactor;
 | 
|---|
| 64 |   std::string segID;
 | 
|---|
| 65 |   std::string Charge;
 | 
|---|
| 66 |   std::string charge;
 | 
|---|
| 67 |   std::string GrpTypeNo;
 | 
|---|
| 68 |   std::string torsion;
 | 
|---|
| 69 |   std::vector<int> neighbors;
 | 
|---|
| 70 | };
 | 
|---|
| 71 | 
 | 
|---|
| 72 | /**
 | 
|---|
| 73 |  * Loads a tremolo file into the World and saves the World as a tremolo file.
 | 
|---|
| 74 |  */
 | 
|---|
| 75 | class TremoloParser : public FormatParser
 | 
|---|
| 76 | {
 | 
|---|
| 77 | public:
 | 
|---|
| 78 |   TremoloParser();
 | 
|---|
| 79 |   ~TremoloParser();
 | 
|---|
| 80 |   void load(std::istream* file);
 | 
|---|
| 81 |   void save(std::ostream* file);
 | 
|---|
| 82 |   void setFieldsForSave(std::string atomDataLine);
 | 
|---|
| 83 | 
 | 
|---|
| 84 | 
 | 
|---|
| 85 | private:
 | 
|---|
| 86 |   void readAtomDataLine(string line);
 | 
|---|
| 87 |   void parseAtomDataKeysLine(string line, int offset);
 | 
|---|
| 88 |   void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId);
 | 
|---|
| 89 |   void processNeighborInformation();
 | 
|---|
| 90 |   void adaptImprData();
 | 
|---|
| 91 |   void adaptTorsion();
 | 
|---|
| 92 |   std::string adaptIdDependentDataString(std::string data);
 | 
|---|
| 93 |   bool isUsedField(std::string fieldName);
 | 
|---|
| 94 |   void writeNeighbors(std::ostream* file, int numberOfNeighbors, atom* currentAtom);
 | 
|---|
| 95 |   void saveLine(std::ostream* file, atom* currentAtom);
 | 
|---|
| 96 | 
 | 
|---|
| 97 |   /**
 | 
|---|
| 98 |    * Map to associate the known keys with numbers.
 | 
|---|
| 99 |    */
 | 
|---|
| 100 |   std::map<std::string, TremoloKey::atomDataKey> knownKeys;
 | 
|---|
| 101 | 
 | 
|---|
| 102 |   /**
 | 
|---|
| 103 |    * Fields used in the tremolo file.
 | 
|---|
| 104 |    */
 | 
|---|
| 105 |   std::vector<std::string> usedFields;
 | 
|---|
| 106 | 
 | 
|---|
| 107 |   /**
 | 
|---|
| 108 |    * Data which is currently not stored in atoms but was provided by the input
 | 
|---|
| 109 |    * file.
 | 
|---|
| 110 |    */
 | 
|---|
| 111 |   std::map<int, TremoloAtomInfoContainer> additionalAtomData;
 | 
|---|
| 112 | 
 | 
|---|
| 113 |   /**
 | 
|---|
| 114 |    * Default additional atom data.
 | 
|---|
| 115 |    */
 | 
|---|
| 116 |   TremoloAtomInfoContainer defaultAdditionalData;
 | 
|---|
| 117 | 
 | 
|---|
| 118 |   /**
 | 
|---|
| 119 |    * Maps original atom IDs received from the parsed file to atom IDs in the
 | 
|---|
| 120 |    * world.
 | 
|---|
| 121 |    */
 | 
|---|
| 122 |   std::map<int, int> atomIdMap;
 | 
|---|
| 123 | };
 | 
|---|
| 124 | 
 | 
|---|
| 125 | #endif /* TREMOLOPARSER_HPP_ */
 | 
|---|