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