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