| [6bc51d] | 1 | /*
 | 
|---|
 | 2 |  * TremoloParser.cpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Mar 2, 2010
 | 
|---|
 | 5 |  *      Author: metzler
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [112b09] | 8 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 9 | 
 | 
|---|
| [b8d4a3] | 10 | #include "Helpers/Assert.hpp"
 | 
|---|
| [e97a44] | 11 | #include "Helpers/Log.hpp"
 | 
|---|
 | 12 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [9131f3] | 13 | #include "TremoloParser.hpp"
 | 
|---|
 | 14 | #include "World.hpp"
 | 
|---|
 | 15 | #include "atom.hpp"
 | 
|---|
 | 16 | #include "element.hpp"
 | 
|---|
| [b8d4a3] | 17 | #include "bond.hpp"
 | 
|---|
| [9131f3] | 18 | #include "periodentafel.hpp"
 | 
|---|
| [b8d4a3] | 19 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| [9131f3] | 20 | #include <map>
 | 
|---|
 | 21 | #include <vector>
 | 
|---|
 | 22 | 
 | 
|---|
| [b8d4a3] | 23 | 
 | 
|---|
| [9131f3] | 24 | using namespace std;
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | /**
 | 
|---|
 | 27 |  * Constructor.
 | 
|---|
 | 28 |  */
 | 
|---|
 | 29 | TremoloParser::TremoloParser() {
 | 
|---|
| [b8d4a3] | 30 |   knownKeys[" "] = TremoloKey::noKey; // with this we can detect invalid keys
 | 
|---|
 | 31 |   knownKeys["x"] = TremoloKey::x;
 | 
|---|
 | 32 |   knownKeys["u"] = TremoloKey::u;
 | 
|---|
 | 33 |   knownKeys["F"] = TremoloKey::F;
 | 
|---|
 | 34 |   knownKeys["stress"] = TremoloKey::stress;
 | 
|---|
 | 35 |   knownKeys["Id"] = TremoloKey::Id;
 | 
|---|
 | 36 |   knownKeys["neighbors"] = TremoloKey::neighbors;
 | 
|---|
 | 37 |   knownKeys["imprData"] = TremoloKey::imprData;
 | 
|---|
 | 38 |   knownKeys["GroupMeasureTypeNo"] = TremoloKey::GroupMeasureTypeNo;
 | 
|---|
 | 39 |   knownKeys["Type"] = TremoloKey::Type;
 | 
|---|
 | 40 |   knownKeys["extType"] = TremoloKey::extType;
 | 
|---|
 | 41 |   knownKeys["name"] = TremoloKey::name;
 | 
|---|
 | 42 |   knownKeys["resName"] = TremoloKey::resName;
 | 
|---|
 | 43 |   knownKeys["chainID"] = TremoloKey::chainID;
 | 
|---|
 | 44 |   knownKeys["resSeq"] = TremoloKey::resSeq;
 | 
|---|
 | 45 |   knownKeys["occupancy"] = TremoloKey::occupancy;
 | 
|---|
 | 46 |   knownKeys["tempFactor"] = TremoloKey::tempFactor;
 | 
|---|
 | 47 |   knownKeys["segID"] = TremoloKey::segID;
 | 
|---|
 | 48 |   knownKeys["Charge"] = TremoloKey::Charge;
 | 
|---|
 | 49 |   knownKeys["charge"] = TremoloKey::charge;
 | 
|---|
 | 50 |   knownKeys["GrpTypeNo"] = TremoloKey::GrpTypeNo;
 | 
|---|
 | 51 |   knownKeys["torsion"] = TremoloKey::torsion;
 | 
|---|
| [52baf9] | 52 | 
 | 
|---|
 | 53 |   // default behavior: use all possible keys on output
 | 
|---|
 | 54 |   for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); iter != knownKeys.end(); ++iter)
 | 
|---|
 | 55 |     usedFields.push_back(iter->first);
 | 
|---|
| [9131f3] | 56 | }
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | /**
 | 
|---|
 | 59 |  * Destructor.
 | 
|---|
 | 60 |  */
 | 
|---|
 | 61 | TremoloParser::~TremoloParser() {
 | 
|---|
| [b8d4a3] | 62 |   usedFields.clear();
 | 
|---|
 | 63 |   additionalAtomData.clear();
 | 
|---|
 | 64 |   atomIdMap.clear();
 | 
|---|
 | 65 |   knownKeys.clear();
 | 
|---|
 | 66 | }
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 | /**
 | 
|---|
 | 69 |  * Loads atoms from a tremolo-formatted file.
 | 
|---|
 | 70 |  *
 | 
|---|
 | 71 |  * \param tremolo file
 | 
|---|
 | 72 |  */
 | 
|---|
 | 73 | void TremoloParser::load(istream* file) {
 | 
|---|
 | 74 |   string line;
 | 
|---|
 | 75 |   string::size_type location;
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 |   usedFields.clear();
 | 
|---|
 | 78 |   while (file->good()) {
 | 
|---|
 | 79 |     std::getline(*file, line, '\n');
 | 
|---|
 | 80 |     if (usedFields.empty()) {
 | 
|---|
 | 81 |       location = line.find("ATOMDATA", 0);
 | 
|---|
 | 82 |       if (location != string::npos) {
 | 
|---|
 | 83 |        parseAtomDataKeysLine(line, location + 8);
 | 
|---|
 | 84 |       }
 | 
|---|
 | 85 |     }
 | 
|---|
 | 86 |     if (line.length() > 0 && line.at(0) != '#') {
 | 
|---|
 | 87 |       readAtomDataLine(line);
 | 
|---|
 | 88 |     }
 | 
|---|
 | 89 |   }
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 |   processNeighborInformation();
 | 
|---|
 | 92 |   adaptImprData();
 | 
|---|
 | 93 |   adaptTorsion();
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | /**
 | 
|---|
 | 97 |  * Saves the World's current state into as a tremolo file.
 | 
|---|
 | 98 |  *
 | 
|---|
 | 99 |  * \param file where to save the state
 | 
|---|
 | 100 |  */
 | 
|---|
 | 101 | void TremoloParser::save(ostream* file) {
 | 
|---|
| [e97a44] | 102 |   DoLog(0) && (Log() << Verbose(0) << "Saving changes to tremolo." << std::endl);
 | 
|---|
 | 103 | 
 | 
|---|
| [b8d4a3] | 104 |   vector<atom*>::iterator atomIt;
 | 
|---|
 | 105 |   vector<string>::iterator it;
 | 
|---|
 | 106 | 
 | 
|---|
 | 107 |   *file << "# ATOMDATA";
 | 
|---|
 | 108 |   for (it=usedFields.begin(); it < usedFields.end(); it++) {
 | 
|---|
 | 109 |     *file << "\t" << *it;
 | 
|---|
 | 110 |   }
 | 
|---|
 | 111 |   *file << endl;
 | 
|---|
 | 112 |   vector<atom *> AtomList = World::getInstance().getAllAtoms();
 | 
|---|
 | 113 |   for (atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
 | 
|---|
 | 114 |     saveLine(file, *atomIt);
 | 
|---|
 | 115 |   }
 | 
|---|
 | 116 | }
 | 
|---|
 | 117 | 
 | 
|---|
 | 118 | /**
 | 
|---|
 | 119 |  * Sets the keys for which data should be written to the stream when save is
 | 
|---|
 | 120 |  * called.
 | 
|---|
 | 121 |  *
 | 
|---|
 | 122 |  * \param string of field names with the same syntax as for an ATOMDATA line
 | 
|---|
 | 123 |  *        but without the prexix "ATOMDATA"
 | 
|---|
 | 124 |  */
 | 
|---|
 | 125 | void TremoloParser::setFieldsForSave(std::string atomDataLine) {
 | 
|---|
 | 126 |   parseAtomDataKeysLine(atomDataLine, 0);
 | 
|---|
 | 127 | }
 | 
|---|
 | 128 | 
 | 
|---|
 | 129 | 
 | 
|---|
 | 130 | /**
 | 
|---|
 | 131 |  * Writes one line of tremolo-formatted data to the provided stream.
 | 
|---|
 | 132 |  *
 | 
|---|
 | 133 |  * \param stream where to write the line to
 | 
|---|
 | 134 |  * \param reference to the atom of which information should be written
 | 
|---|
 | 135 |  */
 | 
|---|
 | 136 | void TremoloParser::saveLine(ostream* file, atom* currentAtom) {
 | 
|---|
 | 137 |   vector<string>::iterator it;
 | 
|---|
 | 138 |   TremoloKey::atomDataKey currentField;
 | 
|---|
 | 139 | 
 | 
|---|
 | 140 |   for (it = usedFields.begin(); it != usedFields.end(); it++) {
 | 
|---|
 | 141 |     currentField = knownKeys[it->substr(0, it->find("="))];
 | 
|---|
 | 142 |     switch (currentField) {
 | 
|---|
 | 143 |       case TremoloKey::x :
 | 
|---|
 | 144 |         // for the moment, assume there are always three dimensions
 | 
|---|
| [d74077] | 145 |         *file << currentAtom->at(0) << "\t";
 | 
|---|
 | 146 |         *file << currentAtom->at(1) << "\t";
 | 
|---|
 | 147 |         *file << currentAtom->at(2) << "\t";
 | 
|---|
| [b8d4a3] | 148 |         break;
 | 
|---|
 | 149 |       case TremoloKey::u :
 | 
|---|
 | 150 |         // for the moment, assume there are always three dimensions
 | 
|---|
| [d74077] | 151 |         *file << currentAtom->AtomicVelocity[0] << "\t";
 | 
|---|
 | 152 |         *file << currentAtom->AtomicVelocity[1] << "\t";
 | 
|---|
 | 153 |         *file << currentAtom->AtomicVelocity[2] << "\t";
 | 
|---|
| [b8d4a3] | 154 |         break;
 | 
|---|
 | 155 |       case TremoloKey::Type :
 | 
|---|
 | 156 |         *file << currentAtom->getType()->getSymbol() << "\t";
 | 
|---|
 | 157 |         break;
 | 
|---|
 | 158 |       case TremoloKey::Id :
 | 
|---|
 | 159 |         *file << currentAtom->getId() << "\t";
 | 
|---|
 | 160 |         break;
 | 
|---|
 | 161 |       case TremoloKey::neighbors :
 | 
|---|
 | 162 |         writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom);
 | 
|---|
 | 163 |         break;
 | 
|---|
 | 164 |       default :
 | 
|---|
 | 165 |         *file << (additionalAtomData.find(currentAtom->getId()) != additionalAtomData.end()
 | 
|---|
 | 166 |           ? additionalAtomData[currentAtom->getId()].get(currentField)
 | 
|---|
 | 167 |           : defaultAdditionalData.get(currentField));
 | 
|---|
 | 168 |         *file << "\t";
 | 
|---|
 | 169 |         break;
 | 
|---|
 | 170 |     }
 | 
|---|
 | 171 |   }
 | 
|---|
 | 172 | 
 | 
|---|
 | 173 |   *file << endl;
 | 
|---|
 | 174 | }
 | 
|---|
 | 175 | 
 | 
|---|
 | 176 | /**
 | 
|---|
 | 177 |  * Writes the neighbor information of one atom to the provided stream.
 | 
|---|
 | 178 |  *
 | 
|---|
 | 179 |  * \param stream where to write neighbor information to
 | 
|---|
 | 180 |  * \param number of neighbors
 | 
|---|
 | 181 |  * \param reference to the atom of which to take the neighbor information
 | 
|---|
 | 182 |  */
 | 
|---|
 | 183 | void TremoloParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
 | 
|---|
 | 184 |   BondList::iterator currentBond = currentAtom->ListOfBonds.begin();
 | 
|---|
 | 185 |   for (int i = 0; i < numberOfNeighbors; i++) {
 | 
|---|
 | 186 |     *file << (currentBond != currentAtom->ListOfBonds.end()
 | 
|---|
 | 187 |         ? (*currentBond)->GetOtherAtom(currentAtom)->getId() : 0) << "\t";
 | 
|---|
 | 188 |   }
 | 
|---|
| [9131f3] | 189 | }
 | 
|---|
 | 190 | 
 | 
|---|
 | 191 | /**
 | 
|---|
 | 192 |  * Stores keys from the ATOMDATA line.
 | 
|---|
 | 193 |  *
 | 
|---|
 | 194 |  * \param line to parse the keys from
 | 
|---|
 | 195 |  * \param with which offset the keys begin within the line
 | 
|---|
 | 196 |  */
 | 
|---|
 | 197 | void TremoloParser::parseAtomDataKeysLine(string line, int offset) {
 | 
|---|
 | 198 |   string keyword;
 | 
|---|
 | 199 |   stringstream lineStream;
 | 
|---|
 | 200 | 
 | 
|---|
 | 201 |   lineStream << line.substr(offset);
 | 
|---|
| [52baf9] | 202 |   usedFields.clear();
 | 
|---|
| [9131f3] | 203 |   while (lineStream.good()) {
 | 
|---|
 | 204 |     lineStream >> keyword;
 | 
|---|
| [b8d4a3] | 205 |     if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) {
 | 
|---|
| [ecb799] | 206 |       // TODO: throw exception about unknown key
 | 
|---|
| [4415da] | 207 |       cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl;
 | 
|---|
 | 208 |       break;
 | 
|---|
 | 209 |     }
 | 
|---|
| [9131f3] | 210 |     usedFields.push_back(keyword);
 | 
|---|
 | 211 |   }
 | 
|---|
 | 212 | }
 | 
|---|
 | 213 | 
 | 
|---|
 | 214 | /**
 | 
|---|
 | 215 |  * Reads one data line of a tremolo file and interprets it according to the keys
 | 
|---|
 | 216 |  * obtained from the ATOMDATA line.
 | 
|---|
 | 217 |  *
 | 
|---|
 | 218 |  * \param line to parse as an atom
 | 
|---|
 | 219 |  */
 | 
|---|
 | 220 | void TremoloParser::readAtomDataLine(string line) {
 | 
|---|
 | 221 |   vector<string>::iterator it;
 | 
|---|
 | 222 |   stringstream lineStream;
 | 
|---|
| [4415da] | 223 |   atom* newAtom = World::getInstance().createAtom();
 | 
|---|
| [b8d4a3] | 224 |   TremoloAtomInfoContainer *atomInfo = NULL;
 | 
|---|
 | 225 |   additionalAtomData[newAtom->getId()] = *(new TremoloAtomInfoContainer);
 | 
|---|
 | 226 |   atomInfo = &additionalAtomData[newAtom->getId()];
 | 
|---|
 | 227 |   TremoloKey::atomDataKey currentField;
 | 
|---|
| [9131f3] | 228 |   string word;
 | 
|---|
| [b8d4a3] | 229 |   int oldId;
 | 
|---|
| [d74077] | 230 |   double tmp;
 | 
|---|
| [9131f3] | 231 | 
 | 
|---|
 | 232 |   lineStream << line;
 | 
|---|
| [b8d4a3] | 233 |   for (it = usedFields.begin(); it < usedFields.end(); it++) {
 | 
|---|
| [4415da] | 234 |     currentField = knownKeys[it->substr(0, it->find("="))];
 | 
|---|
 | 235 |     switch (currentField) {
 | 
|---|
| [b8d4a3] | 236 |       case TremoloKey::x :
 | 
|---|
| [4415da] | 237 |         // for the moment, assume there are always three dimensions
 | 
|---|
| [d74077] | 238 |         for (int i=0;i<NDIM;i++) {
 | 
|---|
 | 239 |           lineStream >> tmp;
 | 
|---|
 | 240 |           newAtom->set(i, tmp);
 | 
|---|
 | 241 |         }
 | 
|---|
| [4415da] | 242 |         break;
 | 
|---|
| [b8d4a3] | 243 |       case TremoloKey::u :
 | 
|---|
| [4415da] | 244 |         // for the moment, assume there are always three dimensions
 | 
|---|
| [d74077] | 245 |         lineStream >> newAtom->AtomicVelocity[0];
 | 
|---|
 | 246 |         lineStream >> newAtom->AtomicVelocity[1];
 | 
|---|
 | 247 |         lineStream >> newAtom->AtomicVelocity[2];
 | 
|---|
| [4415da] | 248 |         break;
 | 
|---|
| [b8d4a3] | 249 |       case TremoloKey::Type :
 | 
|---|
| [4415da] | 250 |         char type[3];
 | 
|---|
 | 251 |         lineStream >> type;
 | 
|---|
 | 252 |         newAtom->setType(World::getInstance().getPeriode()->FindElement(type));
 | 
|---|
| [b8d4a3] | 253 |         ASSERT(newAtom->getType(), "Type was not set for this atom");
 | 
|---|
| [4415da] | 254 |         break;
 | 
|---|
| [b8d4a3] | 255 |       case TremoloKey::Id :
 | 
|---|
 | 256 |         lineStream >> oldId;
 | 
|---|
 | 257 |         atomIdMap[oldId] = newAtom->getId();
 | 
|---|
| [4415da] | 258 |         break;
 | 
|---|
| [b8d4a3] | 259 |       case TremoloKey::neighbors :
 | 
|---|
 | 260 |         readNeighbors(&lineStream,
 | 
|---|
 | 261 |             atoi(it->substr(it->find("=") + 1, 1).c_str()), newAtom->getId());
 | 
|---|
| [9131f3] | 262 |         break;
 | 
|---|
 | 263 |       default :
 | 
|---|
 | 264 |         lineStream >> word;
 | 
|---|
| [b8d4a3] | 265 |         atomInfo->set(currentField, word);
 | 
|---|
| [9131f3] | 266 |         break;
 | 
|---|
 | 267 |     }
 | 
|---|
 | 268 |   }
 | 
|---|
| [6bc51d] | 269 | }
 | 
|---|
| [9131f3] | 270 | 
 | 
|---|
| [b8d4a3] | 271 | /**
 | 
|---|
 | 272 |  * Reads neighbor information for one atom from the input.
 | 
|---|
 | 273 |  *
 | 
|---|
 | 274 |  * \param stream where to read the information from
 | 
|---|
 | 275 |  * \param number of neighbors to read
 | 
|---|
 | 276 |  * \param world id of the atom the information belongs to
 | 
|---|
 | 277 |  */
 | 
|---|
 | 278 | void TremoloParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
 | 
|---|
 | 279 |   int neighborId = 0;
 | 
|---|
 | 280 |   for (int i = 0; i < numberOfNeighbors; i++) {
 | 
|---|
 | 281 |     *line >> neighborId;
 | 
|---|
 | 282 |     // 0 is used to fill empty neighbor positions in the tremolo file.
 | 
|---|
 | 283 |     if (neighborId > 0) {
 | 
|---|
 | 284 |       additionalAtomData[atomId].neighbors.push_back(neighborId);
 | 
|---|
 | 285 |     }
 | 
|---|
 | 286 |   }
 | 
|---|
 | 287 | }
 | 
|---|
| [9131f3] | 288 | 
 | 
|---|
 | 289 | /**
 | 
|---|
| [b8d4a3] | 290 |  * Checks whether the provided name is within the list of used fields.
 | 
|---|
| [9131f3] | 291 |  *
 | 
|---|
| [b8d4a3] | 292 |  * \param field name to check
 | 
|---|
 | 293 |  *
 | 
|---|
 | 294 |  * \return true if the field name is used
 | 
|---|
| [9131f3] | 295 |  */
 | 
|---|
| [b8d4a3] | 296 | bool TremoloParser::isUsedField(string fieldName) {
 | 
|---|
 | 297 |   bool fieldNameExists = false;
 | 
|---|
 | 298 |   for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) {
 | 
|---|
 | 299 |     if (usedField->substr(0, usedField->find("=")) == fieldName)
 | 
|---|
 | 300 |       fieldNameExists = true;
 | 
|---|
 | 301 |   }
 | 
|---|
| [9131f3] | 302 | 
 | 
|---|
| [b8d4a3] | 303 |   return fieldNameExists;
 | 
|---|
 | 304 | }
 | 
|---|
 | 305 | 
 | 
|---|
 | 306 | 
 | 
|---|
 | 307 | /**
 | 
|---|
 | 308 |  * Adds the collected neighbor information to the atoms in the world. The atoms
 | 
|---|
 | 309 |  * are found by their current ID and mapped to the corresponding atoms with the
 | 
|---|
 | 310 |  * Id found in the parsed file.
 | 
|---|
 | 311 |  */
 | 
|---|
 | 312 | void TremoloParser::processNeighborInformation() {
 | 
|---|
 | 313 |   if (!isUsedField("neighbors")) {
 | 
|---|
 | 314 |     return;
 | 
|---|
 | 315 |   }
 | 
|---|
 | 316 | 
 | 
|---|
 | 317 |   for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
 | 
|---|
 | 318 |     currentInfo != additionalAtomData.end(); currentInfo++
 | 
|---|
 | 319 |   ) {
 | 
|---|
 | 320 |     for(vector<int>::iterator neighbor = currentInfo->second.neighbors.begin();
 | 
|---|
 | 321 |       neighbor != currentInfo->second.neighbors.end(); neighbor++
 | 
|---|
 | 322 |     ) {
 | 
|---|
 | 323 |       World::getInstance().getAtom(AtomById(currentInfo->first))
 | 
|---|
 | 324 |           ->addBond(World::getInstance().getAtom(AtomById(atomIdMap[*neighbor])));
 | 
|---|
| [9131f3] | 325 |     }
 | 
|---|
 | 326 |   }
 | 
|---|
| [6bc51d] | 327 | }
 | 
|---|
 | 328 | 
 | 
|---|
| [9131f3] | 329 | /**
 | 
|---|
| [b8d4a3] | 330 |  * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
 | 
|---|
 | 331 |  * IDs of the input string will be replaced; expected separating characters are
 | 
|---|
 | 332 |  * "-" and ",".
 | 
|---|
| [9131f3] | 333 |  *
 | 
|---|
| [b8d4a3] | 334 |  * \param string in which atom IDs should be adapted
 | 
|---|
 | 335 |  *
 | 
|---|
 | 336 |  * \return input string with modified atom IDs
 | 
|---|
| [9131f3] | 337 |  */
 | 
|---|
| [b8d4a3] | 338 | string TremoloParser::adaptIdDependentDataString(string data) {
 | 
|---|
 | 339 |   // there might be no IDs
 | 
|---|
 | 340 |   if (data == "-") {
 | 
|---|
 | 341 |     return "-";
 | 
|---|
 | 342 |   }
 | 
|---|
 | 343 | 
 | 
|---|
 | 344 |   char separator;
 | 
|---|
 | 345 |   int id;
 | 
|---|
 | 346 |   stringstream line, result;
 | 
|---|
 | 347 |   line << data;
 | 
|---|
 | 348 | 
 | 
|---|
 | 349 |   line >> id;
 | 
|---|
 | 350 |   result << atomIdMap[id];
 | 
|---|
 | 351 |   while (line.good()) {
 | 
|---|
 | 352 |     line >> separator >> id;
 | 
|---|
 | 353 |     result << separator << atomIdMap[id];
 | 
|---|
 | 354 |   }
 | 
|---|
 | 355 | 
 | 
|---|
 | 356 |   return result.str();
 | 
|---|
| [6bc51d] | 357 | }
 | 
|---|
| [b8d4a3] | 358 | 
 | 
|---|
 | 359 | /**
 | 
|---|
 | 360 |  * Corrects the atom IDs in each imprData entry to the corresponding world IDs
 | 
|---|
 | 361 |  * as they might differ from the originally read IDs.
 | 
|---|
 | 362 |  */
 | 
|---|
 | 363 | void TremoloParser::adaptImprData() {
 | 
|---|
 | 364 |   if (!isUsedField("imprData")) {
 | 
|---|
 | 365 |     return;
 | 
|---|
 | 366 |   }
 | 
|---|
 | 367 | 
 | 
|---|
 | 368 |   for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
 | 
|---|
 | 369 |     currentInfo != additionalAtomData.end(); currentInfo++
 | 
|---|
 | 370 |   ) {
 | 
|---|
 | 371 |     currentInfo->second.imprData = adaptIdDependentDataString(currentInfo->second.imprData);
 | 
|---|
 | 372 |   }
 | 
|---|
| [6bc51d] | 373 | }
 | 
|---|
| [4415da] | 374 | 
 | 
|---|
| [b8d4a3] | 375 | /**
 | 
|---|
 | 376 |  * Corrects the atom IDs in each torsion entry to the corresponding world IDs
 | 
|---|
 | 377 |  * as they might differ from the originally read IDs.
 | 
|---|
 | 378 |  */
 | 
|---|
 | 379 | void TremoloParser::adaptTorsion() {
 | 
|---|
 | 380 |   if (!isUsedField("torsion")) {
 | 
|---|
 | 381 |     return;
 | 
|---|
 | 382 |   }
 | 
|---|
 | 383 | 
 | 
|---|
 | 384 |   for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
 | 
|---|
 | 385 |     currentInfo != additionalAtomData.end(); currentInfo++
 | 
|---|
 | 386 |   ) {
 | 
|---|
 | 387 |     currentInfo->second.torsion = adaptIdDependentDataString(currentInfo->second.torsion);
 | 
|---|
 | 388 |   }
 | 
|---|
 | 389 | }
 | 
|---|
 | 390 | 
 | 
|---|
 | 391 | 
 | 
|---|
| [97b825] | 392 | TremoloAtomInfoContainer::TremoloAtomInfoContainer() :
 | 
|---|
 | 393 |   F("0"),
 | 
|---|
 | 394 |   stress("0"),
 | 
|---|
 | 395 |   imprData("-"),
 | 
|---|
 | 396 |   GroupMeasureTypeNo("0"),
 | 
|---|
 | 397 |   extType("-"),
 | 
|---|
 | 398 |   name("-"),
 | 
|---|
 | 399 |   resName("-"),
 | 
|---|
 | 400 |   chainID("0"),
 | 
|---|
 | 401 |   resSeq("0"),
 | 
|---|
 | 402 |   occupancy("0"),
 | 
|---|
 | 403 |   tempFactor("0"),
 | 
|---|
 | 404 |   segID("0"),
 | 
|---|
 | 405 |   Charge("0"),
 | 
|---|
 | 406 |   charge("0"),
 | 
|---|
 | 407 |   GrpTypeNo("0"),
 | 
|---|
 | 408 |   torsion("-"),
 | 
|---|
 | 409 |   neighbors(vector<int>(0, 5))
 | 
|---|
 | 410 | {}
 | 
|---|
| [b8d4a3] | 411 | 
 | 
|---|
 | 412 | void TremoloAtomInfoContainer::set(TremoloKey::atomDataKey key, string value) {
 | 
|---|
 | 413 |   switch (key) {
 | 
|---|
 | 414 |     case TremoloKey::F :
 | 
|---|
 | 415 |       F = value;
 | 
|---|
 | 416 |       break;
 | 
|---|
 | 417 |     case TremoloKey::stress :
 | 
|---|
 | 418 |       stress = value;
 | 
|---|
 | 419 |      break;
 | 
|---|
 | 420 |     case TremoloKey::imprData :
 | 
|---|
 | 421 |       imprData = value;
 | 
|---|
 | 422 |       break;
 | 
|---|
 | 423 |     case TremoloKey::GroupMeasureTypeNo :
 | 
|---|
 | 424 |       GroupMeasureTypeNo = value;
 | 
|---|
 | 425 |       break;
 | 
|---|
 | 426 |     case TremoloKey::extType :
 | 
|---|
 | 427 |       extType = value;
 | 
|---|
 | 428 |       break;
 | 
|---|
 | 429 |     case TremoloKey::name :
 | 
|---|
 | 430 |       name = value;
 | 
|---|
 | 431 |       break;
 | 
|---|
 | 432 |     case TremoloKey::resName :
 | 
|---|
 | 433 |       resName = value;
 | 
|---|
 | 434 |       break;
 | 
|---|
 | 435 |     case TremoloKey::chainID :
 | 
|---|
 | 436 |       chainID = value;
 | 
|---|
 | 437 |       break;
 | 
|---|
 | 438 |     case TremoloKey::resSeq :
 | 
|---|
 | 439 |       resSeq = value;
 | 
|---|
 | 440 |       break;
 | 
|---|
 | 441 |     case TremoloKey::occupancy :
 | 
|---|
 | 442 |       occupancy = value;
 | 
|---|
 | 443 |       break;
 | 
|---|
 | 444 |     case TremoloKey::tempFactor :
 | 
|---|
 | 445 |       tempFactor = value;
 | 
|---|
 | 446 |       break;
 | 
|---|
 | 447 |     case TremoloKey::segID :
 | 
|---|
 | 448 |       segID = value;
 | 
|---|
 | 449 |       break;
 | 
|---|
 | 450 |     case TremoloKey::Charge :
 | 
|---|
 | 451 |       Charge = value;
 | 
|---|
 | 452 |       break;
 | 
|---|
 | 453 |     case TremoloKey::charge :
 | 
|---|
 | 454 |       charge = value;
 | 
|---|
 | 455 |       break;
 | 
|---|
 | 456 |     case TremoloKey::GrpTypeNo :
 | 
|---|
 | 457 |       GrpTypeNo = value;
 | 
|---|
 | 458 |       break;
 | 
|---|
 | 459 |     case TremoloKey::torsion :
 | 
|---|
 | 460 |       torsion = value;
 | 
|---|
 | 461 |       break;
 | 
|---|
 | 462 |     default :
 | 
|---|
 | 463 |       cout << "Unknown key: " << key << ", value: " << value << endl;
 | 
|---|
 | 464 |       break;
 | 
|---|
 | 465 |   }
 | 
|---|
 | 466 | }
 | 
|---|
 | 467 | 
 | 
|---|
 | 468 | string TremoloAtomInfoContainer::get(TremoloKey::atomDataKey key) {
 | 
|---|
 | 469 |   switch (key) {
 | 
|---|
 | 470 |     case TremoloKey::F :
 | 
|---|
 | 471 |       return F;
 | 
|---|
 | 472 |     case TremoloKey::stress :
 | 
|---|
 | 473 |       return stress;
 | 
|---|
 | 474 |     case TremoloKey::imprData :
 | 
|---|
 | 475 |       return imprData;
 | 
|---|
 | 476 |     case TremoloKey::GroupMeasureTypeNo :
 | 
|---|
 | 477 |       return GroupMeasureTypeNo;
 | 
|---|
 | 478 |     case TremoloKey::extType :
 | 
|---|
 | 479 |       return extType;
 | 
|---|
 | 480 |     case TremoloKey::name :
 | 
|---|
 | 481 |       return name;
 | 
|---|
 | 482 |     case TremoloKey::resName :
 | 
|---|
 | 483 |       return resName;
 | 
|---|
 | 484 |     case TremoloKey::chainID :
 | 
|---|
 | 485 |       return chainID;
 | 
|---|
 | 486 |     case TremoloKey::resSeq :
 | 
|---|
 | 487 |       return resSeq;
 | 
|---|
 | 488 |     case TremoloKey::occupancy :
 | 
|---|
 | 489 |       return occupancy;
 | 
|---|
 | 490 |     case TremoloKey::tempFactor :
 | 
|---|
 | 491 |       return tempFactor;
 | 
|---|
 | 492 |     case TremoloKey::segID :
 | 
|---|
 | 493 |       return segID;
 | 
|---|
 | 494 |     case TremoloKey::Charge :
 | 
|---|
 | 495 |       return Charge;
 | 
|---|
 | 496 |     case TremoloKey::charge :
 | 
|---|
 | 497 |       return charge;
 | 
|---|
 | 498 |     case TremoloKey::GrpTypeNo :
 | 
|---|
 | 499 |       return GrpTypeNo;
 | 
|---|
 | 500 |     case TremoloKey::torsion :
 | 
|---|
 | 501 |       return torsion;
 | 
|---|
 | 502 |     default :
 | 
|---|
 | 503 |       cout << "Unknown key: " << key << endl;
 | 
|---|
 | 504 |       return "";
 | 
|---|
 | 505 |   }
 | 
|---|
 | 506 | }
 | 
|---|
 | 507 | 
 | 
|---|