| 1 | /* | 
|---|
| 2 | * PdbParser.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Aug 17, 2010 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef PDBPARSER_HPP_ | 
|---|
| 9 | #define PDBPARSER_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 | #include "types.hpp" | 
|---|
| 24 |  | 
|---|
| 25 | #include "PdbAtomInfoContainer.hpp" | 
|---|
| 26 | #include "PdbKey.hpp" | 
|---|
| 27 |  | 
|---|
| 28 | class molecule; | 
|---|
| 29 |  | 
|---|
| 30 | // declaration of specialized FormatParserTrait | 
|---|
| 31 | template<> | 
|---|
| 32 | struct FormatParserTrait<pdb> | 
|---|
| 33 | { | 
|---|
| 34 | //!> Name of the parser | 
|---|
| 35 | static const std::string name; | 
|---|
| 36 | //!> suffix of the files the parser understands to read and write | 
|---|
| 37 | static const std::string suffix; | 
|---|
| 38 | //!> ParserTypes enumeration for the parser | 
|---|
| 39 | static const enum ParserTypes type; | 
|---|
| 40 | }; | 
|---|
| 41 |  | 
|---|
| 42 | /** | 
|---|
| 43 | * Loads a PDB format 3.2 file into the World and saves the World as a PDB file. | 
|---|
| 44 | */ | 
|---|
| 45 | template <> | 
|---|
| 46 | class FormatParser< pdb >  : virtual public FormatParserInterface, public FormatParser_common | 
|---|
| 47 | { | 
|---|
| 48 | public: | 
|---|
| 49 | FormatParser(); | 
|---|
| 50 | virtual ~FormatParser(); | 
|---|
| 51 | void load(std::istream* file); | 
|---|
| 52 | void save(std::ostream* file, const std::vector<atom *> &atoms); | 
|---|
| 53 |  | 
|---|
| 54 | bool operator==(const FormatParser< pdb>& b) const; | 
|---|
| 55 | void printAtomInfo(const atom *newAtom) const; | 
|---|
| 56 |  | 
|---|
| 57 | protected: | 
|---|
| 58 | void AtomInserted(atomId_t); | 
|---|
| 59 | void AtomRemoved(atomId_t); | 
|---|
| 60 |  | 
|---|
| 61 | private: | 
|---|
| 62 | enum PdbKey::KnownTokens getToken(std::string &line); | 
|---|
| 63 | void readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol); | 
|---|
| 64 | void parseAtomDataKeysLine(std::string line, int offset); | 
|---|
| 65 | void readNeighbors(const unsigned int _step, std::string &line); | 
|---|
| 66 | //  void adaptImprData(); | 
|---|
| 67 | //  void adaptTorsion(); | 
|---|
| 68 | //  std::string adaptIdDependentDataString(std::string data); | 
|---|
| 69 | bool isUsedField(std::string fieldName); | 
|---|
| 70 | void writeNeighbors(std::ostream* file, int numberOfNeighbors, atom* currentAtom); | 
|---|
| 71 | void saveLine(std::ostream* file, const PdbAtomInfoContainer &atomInfo); | 
|---|
| 72 |  | 
|---|
| 73 | // internal getter and setter | 
|---|
| 74 | bool isPresentadditionalAtomData(const atomId_t _id) const; | 
|---|
| 75 | PdbAtomInfoContainer& getadditionalAtomData(atom *_atom); | 
|---|
| 76 |  | 
|---|
| 77 | // internal helper functions | 
|---|
| 78 | atom* getAtomToParse(std::string id_string); | 
|---|
| 79 | void readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const; | 
|---|
| 80 |  | 
|---|
| 81 | /** | 
|---|
| 82 | * argh, why can't just PdbKey::X+(size_t)i | 
|---|
| 83 | */ | 
|---|
| 84 | std::map<size_t, PdbKey::PdbDataKey> PositionEnumMap; | 
|---|
| 85 |  | 
|---|
| 86 | /** | 
|---|
| 87 | * Map to associate the known keys with numbers. | 
|---|
| 88 | */ | 
|---|
| 89 | std::map<std::string, PdbKey::KnownTokens> knownTokens; | 
|---|
| 90 |  | 
|---|
| 91 | /** | 
|---|
| 92 | * Data which is currently not stored in atoms but was provided by the input | 
|---|
| 93 | * file. | 
|---|
| 94 | */ | 
|---|
| 95 | std::map<const atomId_t, PdbAtomInfoContainer> additionalAtomData; | 
|---|
| 96 |  | 
|---|
| 97 | /** | 
|---|
| 98 | * Default additional atom data. | 
|---|
| 99 | */ | 
|---|
| 100 | PdbAtomInfoContainer defaultAdditionalData; | 
|---|
| 101 | }; | 
|---|
| 102 |  | 
|---|
| 103 | #endif /* PDBPARSER_HPP_ */ | 
|---|