| 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 |  | 
|---|
| 8 | /* | 
|---|
| 9 | * PdbParser.cpp | 
|---|
| 10 | * | 
|---|
| 11 | *  Created on: Aug 17, 2010 | 
|---|
| 12 | *      Author: heber | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | // include config.h | 
|---|
| 16 | #ifdef HAVE_CONFIG_H | 
|---|
| 17 | #include <config.h> | 
|---|
| 18 | #endif | 
|---|
| 19 |  | 
|---|
| 20 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | #include "CodePatterns/Assert.hpp" | 
|---|
| 23 | #include "CodePatterns/Log.hpp" | 
|---|
| 24 | #include "CodePatterns/toString.hpp" | 
|---|
| 25 | #include "CodePatterns/Verbose.hpp" | 
|---|
| 26 |  | 
|---|
| 27 | #include "atom.hpp" | 
|---|
| 28 | #include "Bond/bond.hpp" | 
|---|
| 29 | #include "Descriptors/AtomIdDescriptor.hpp" | 
|---|
| 30 | #include "Element/element.hpp" | 
|---|
| 31 | #include "Element/periodentafel.hpp" | 
|---|
| 32 | #include "molecule.hpp" | 
|---|
| 33 | #include "MoleculeListClass.hpp" | 
|---|
| 34 | #include "Parser/PdbParser.hpp" | 
|---|
| 35 | #include "World.hpp" | 
|---|
| 36 | #include "WorldTime.hpp" | 
|---|
| 37 |  | 
|---|
| 38 | #include <map> | 
|---|
| 39 | #include <vector> | 
|---|
| 40 |  | 
|---|
| 41 | #include <iostream> | 
|---|
| 42 | #include <iomanip> | 
|---|
| 43 |  | 
|---|
| 44 | using namespace std; | 
|---|
| 45 |  | 
|---|
| 46 | // declare specialized static variables | 
|---|
| 47 | const std::string FormatParserTrait<pdb>::name = "pdb"; | 
|---|
| 48 | const std::string FormatParserTrait<pdb>::suffix = "pdb"; | 
|---|
| 49 | const ParserTypes FormatParserTrait<pdb>::type = pdb; | 
|---|
| 50 |  | 
|---|
| 51 | /** | 
|---|
| 52 | * Constructor. | 
|---|
| 53 | */ | 
|---|
| 54 | FormatParser< pdb >::FormatParser() : | 
|---|
| 55 | FormatParser_common(NULL) | 
|---|
| 56 | { | 
|---|
| 57 | knownTokens["ATOM"] = PdbKey::Atom; | 
|---|
| 58 | knownTokens["HETATM"] = PdbKey::Atom; | 
|---|
| 59 | knownTokens["TER"] = PdbKey::Filler; | 
|---|
| 60 | knownTokens["END"] = PdbKey::EndOfTimestep; | 
|---|
| 61 | knownTokens["CONECT"] = PdbKey::Connect; | 
|---|
| 62 | knownTokens["REMARK"] = PdbKey::Remark; | 
|---|
| 63 | knownTokens[""] = PdbKey::EndOfTimestep; | 
|---|
| 64 |  | 
|---|
| 65 | // argh, why can't just PdbKey::X+(size_t)i | 
|---|
| 66 | PositionEnumMap[0] = PdbKey::X; | 
|---|
| 67 | PositionEnumMap[1] = PdbKey::Y; | 
|---|
| 68 | PositionEnumMap[2] = PdbKey::Z; | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 | /** | 
|---|
| 72 | * Destructor. | 
|---|
| 73 | */ | 
|---|
| 74 | FormatParser< pdb >::~FormatParser() | 
|---|
| 75 | { | 
|---|
| 76 | PdbAtomInfoContainer::clearknownDataKeys(); | 
|---|
| 77 | additionalAtomData.clear(); | 
|---|
| 78 | atomIdMap.clear(); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 |  | 
|---|
| 82 | /** Parses the initial word of the given \a line and returns the token type. | 
|---|
| 83 | * | 
|---|
| 84 | * @param line line to scan | 
|---|
| 85 | * @return token type | 
|---|
| 86 | */ | 
|---|
| 87 | enum PdbKey::KnownTokens FormatParser< pdb >::getToken(string &line) | 
|---|
| 88 | { | 
|---|
| 89 | // look for first space | 
|---|
| 90 | const size_t space_location = line.find(' '); | 
|---|
| 91 | const size_t tab_location = line.find('\t'); | 
|---|
| 92 | size_t location = space_location < tab_location ? space_location : tab_location; | 
|---|
| 93 | string token; | 
|---|
| 94 | if (location != string::npos) { | 
|---|
| 95 | //LOG(1, "Found space at position " << space_location); | 
|---|
| 96 | token = line.substr(0,space_location); | 
|---|
| 97 | } else { | 
|---|
| 98 | token = line; | 
|---|
| 99 | } | 
|---|
| 100 |  | 
|---|
| 101 | //LOG(1, "Token is " << token); | 
|---|
| 102 | if (knownTokens.count(token) == 0) | 
|---|
| 103 | return PdbKey::NoToken; | 
|---|
| 104 | else | 
|---|
| 105 | return knownTokens[token]; | 
|---|
| 106 |  | 
|---|
| 107 | return PdbKey::NoToken; | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | /** | 
|---|
| 111 | * Loads atoms from a PDB-formatted file. | 
|---|
| 112 | * | 
|---|
| 113 | * \param PDB file | 
|---|
| 114 | */ | 
|---|
| 115 | void FormatParser< pdb >::load(istream* file) { | 
|---|
| 116 | string line; | 
|---|
| 117 | size_t linecount  = 0; | 
|---|
| 118 | enum PdbKey::KnownTokens token; | 
|---|
| 119 |  | 
|---|
| 120 | // reset atomIdMap for this file (to correctly parse CONECT entries) | 
|---|
| 121 | atomIdMap.clear(); | 
|---|
| 122 |  | 
|---|
| 123 | bool NotEndOfFile = true; | 
|---|
| 124 | molecule *newmol = World::getInstance().createMolecule(); | 
|---|
| 125 | newmol->ActiveFlag = true; | 
|---|
| 126 | unsigned int step = 0; | 
|---|
| 127 | // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include | 
|---|
| 128 | World::getInstance().getMolecules()->insert(newmol); | 
|---|
| 129 | while (NotEndOfFile) { | 
|---|
| 130 | bool NotEndOfTimestep = true; | 
|---|
| 131 | while (NotEndOfTimestep && NotEndOfFile) { | 
|---|
| 132 | std::getline(*file, line, '\n'); | 
|---|
| 133 | if (!line.empty()) { | 
|---|
| 134 | // extract first token | 
|---|
| 135 | token = getToken(line); | 
|---|
| 136 | switch (token) { | 
|---|
| 137 | case PdbKey::Atom: | 
|---|
| 138 | LOG(3,"INFO: Parsing ATOM entry for time step " << step << "."); | 
|---|
| 139 | readAtomDataLine(step, line, newmol); | 
|---|
| 140 | break; | 
|---|
| 141 | case PdbKey::Remark: | 
|---|
| 142 | LOG(3,"INFO: Parsing REM entry for time step " << step << "."); | 
|---|
| 143 | break; | 
|---|
| 144 | case PdbKey::Connect: | 
|---|
| 145 | LOG(3,"INFO: Parsing CONECT entry for time step " << step << "."); | 
|---|
| 146 | readNeighbors(step, line); | 
|---|
| 147 | break; | 
|---|
| 148 | case PdbKey::Filler: | 
|---|
| 149 | LOG(3,"INFO: Stumbled upon Filler entry for time step " << step << "."); | 
|---|
| 150 | break; | 
|---|
| 151 | case PdbKey::EndOfTimestep: | 
|---|
| 152 | LOG(3,"INFO: Parsing END entry or empty line for time step " << step << "."); | 
|---|
| 153 | NotEndOfTimestep = false; | 
|---|
| 154 | break; | 
|---|
| 155 | default: | 
|---|
| 156 | // TODO: put a throw here | 
|---|
| 157 | ELOG(2, "Unknown token: '" << line << "' for time step " << step << "."); | 
|---|
| 158 | //ASSERT(0, "FormatParser< pdb >::load() - Unknown token in line "+toString(linecount)+": "+line+"."); | 
|---|
| 159 | break; | 
|---|
| 160 | } | 
|---|
| 161 | } | 
|---|
| 162 | NotEndOfFile = NotEndOfFile && (file->good()); | 
|---|
| 163 | linecount++; | 
|---|
| 164 | } | 
|---|
| 165 | ++step; | 
|---|
| 166 | } | 
|---|
| 167 | BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms()) | 
|---|
| 168 | LOG(4, "INFO: Atom " << _atom->getName() << " " << *dynamic_cast<AtomInfo *>(_atom) << "."); | 
|---|
| 169 |  | 
|---|
| 170 | // refresh atom::nr and atom::name | 
|---|
| 171 | newmol->getAtomCount(); | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | /** | 
|---|
| 175 | * Saves the \a atoms into as a PDB file. | 
|---|
| 176 | * | 
|---|
| 177 | * \param file where to save the state | 
|---|
| 178 | * \param atoms atoms to store | 
|---|
| 179 | */ | 
|---|
| 180 | void FormatParser< pdb >::save(ostream* file, const std::vector<atom *> &AtomList) | 
|---|
| 181 | { | 
|---|
| 182 | LOG(0, "Saving changes to pdb."); | 
|---|
| 183 |  | 
|---|
| 184 | // check for maximum number of time steps | 
|---|
| 185 | size_t max_timesteps = 0; | 
|---|
| 186 | BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms()) { | 
|---|
| 187 | LOG(4, "INFO: Atom " << _atom->getName() << " " << *dynamic_cast<AtomInfo *>(_atom) << "."); | 
|---|
| 188 | if (_atom->getTrajectorySize() > max_timesteps) | 
|---|
| 189 | max_timesteps = _atom->getTrajectorySize(); | 
|---|
| 190 | } | 
|---|
| 191 | LOG(2,"INFO: Found a maximum of " << max_timesteps << " time steps to store."); | 
|---|
| 192 |  | 
|---|
| 193 | // re-distribute serials | 
|---|
| 194 | // (new atoms might have been added) | 
|---|
| 195 | // (serials must be consistent over time steps) | 
|---|
| 196 | atomIdMap.clear(); | 
|---|
| 197 | int AtomNo = 1; // serial number starts at 1 in pdb | 
|---|
| 198 | for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) { | 
|---|
| 199 | PdbAtomInfoContainer &atomInfo = getadditionalAtomData(*atomIt); | 
|---|
| 200 | setSerial((*atomIt)->getId(), AtomNo); | 
|---|
| 201 | atomInfo.set(PdbKey::serial, toString(AtomNo)); | 
|---|
| 202 | AtomNo++; | 
|---|
| 203 | } | 
|---|
| 204 |  | 
|---|
| 205 | // store all time steps (always do first step) | 
|---|
| 206 | for (size_t step = 0; (step == 0) || (step < max_timesteps); ++step) { | 
|---|
| 207 | { | 
|---|
| 208 | // add initial remark | 
|---|
| 209 | *file << "REMARK created by molecuilder on "; | 
|---|
| 210 | time_t now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time' | 
|---|
| 211 | // ctime ends in \n\0, we have to cut away the newline | 
|---|
| 212 | std::string time(ctime(&now)); | 
|---|
| 213 | size_t pos = time.find('\n'); | 
|---|
| 214 | if (pos != 0) | 
|---|
| 215 | *file << time.substr(0,pos); | 
|---|
| 216 | else | 
|---|
| 217 | *file << time; | 
|---|
| 218 | *file << ", time step " << step; | 
|---|
| 219 | *file << endl; | 
|---|
| 220 | } | 
|---|
| 221 |  | 
|---|
| 222 | { | 
|---|
| 223 | std::map<size_t,size_t> MolIdMap; | 
|---|
| 224 | size_t MolNo = 1;  // residue number starts at 1 in pdb | 
|---|
| 225 | for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) { | 
|---|
| 226 | const molecule *mol = (*atomIt)->getMolecule(); | 
|---|
| 227 | if ((mol != NULL) && (MolIdMap.find(mol->getId()) == MolIdMap.end())) { | 
|---|
| 228 | MolIdMap[mol->getId()] = MolNo++; | 
|---|
| 229 | } | 
|---|
| 230 | } | 
|---|
| 231 | const size_t MaxMol = MolNo; | 
|---|
| 232 |  | 
|---|
| 233 | // have a count per element and per molecule (0 is for all homeless atoms) | 
|---|
| 234 | std::vector<int> **elementNo = new std::vector<int>*[MaxMol]; | 
|---|
| 235 | for (size_t i = 0; i < MaxMol; ++i) | 
|---|
| 236 | elementNo[i] = new std::vector<int>(MAX_ELEMENTS,1); | 
|---|
| 237 | char name[MAXSTRINGSIZE]; | 
|---|
| 238 | std::string ResidueName; | 
|---|
| 239 |  | 
|---|
| 240 | // write ATOMs | 
|---|
| 241 | for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) { | 
|---|
| 242 | PdbAtomInfoContainer &atomInfo = getadditionalAtomData(*atomIt); | 
|---|
| 243 | // gather info about residue | 
|---|
| 244 | const molecule *mol = (*atomIt)->getMolecule(); | 
|---|
| 245 | if (mol == NULL) { | 
|---|
| 246 | MolNo = 0; | 
|---|
| 247 | atomInfo.set(PdbKey::resSeq, "0"); | 
|---|
| 248 | } else { | 
|---|
| 249 | ASSERT(MolIdMap.find(mol->getId()) != MolIdMap.end(), | 
|---|
| 250 | "FormatParser< pdb >::save() - Mol id "+toString(mol->getId())+" not present despite we set it?!"); | 
|---|
| 251 | MolNo = MolIdMap[mol->getId()]; | 
|---|
| 252 | atomInfo.set(PdbKey::resSeq, toString(MolIdMap[mol->getId()])); | 
|---|
| 253 | if (atomInfo.get<std::string>(PdbKey::resName) == "-") | 
|---|
| 254 | atomInfo.set(PdbKey::resName, mol->getName().substr(0,3)); | 
|---|
| 255 | } | 
|---|
| 256 | // get info about atom | 
|---|
| 257 | const size_t  Z = (*atomIt)->getType()->getAtomicNumber(); | 
|---|
| 258 | if (atomInfo.get<std::string>(PdbKey::name) == "-") {  // if no name set, give it a new name | 
|---|
| 259 | sprintf(name, "%2s%02d",(*atomIt)->getType()->getSymbol().c_str(), (*elementNo[MolNo])[Z]); | 
|---|
| 260 | (*elementNo[MolNo])[Z] = ((*elementNo[MolNo])[Z]+1) % 100;   // confine to two digits | 
|---|
| 261 | atomInfo.set(PdbKey::name, name); | 
|---|
| 262 | } | 
|---|
| 263 | // set position | 
|---|
| 264 | for (size_t i=0; i<NDIM;++i) { | 
|---|
| 265 | stringstream position; | 
|---|
| 266 | position << setw(8) << fixed << setprecision(3) << (*atomIt)->getPositionAtStep(step).at(i); | 
|---|
| 267 | atomInfo.set(PositionEnumMap[i], position.str()); | 
|---|
| 268 | } | 
|---|
| 269 | // change element and charge if changed | 
|---|
| 270 | if (atomInfo.get<std::string>(PdbKey::element) != (*atomIt)->getType()->getSymbol()) { | 
|---|
| 271 | std::string symbol = (*atomIt)->getType()->getSymbol(); | 
|---|
| 272 | if ((symbol[1] >= 'a') && (symbol[1] <= 'z')) | 
|---|
| 273 | symbol[1] = (symbol[1] - 'a') + 'A'; | 
|---|
| 274 | atomInfo.set(PdbKey::element, symbol); | 
|---|
| 275 | } | 
|---|
| 276 |  | 
|---|
| 277 | // finally save the line | 
|---|
| 278 | saveLine(file, atomInfo); | 
|---|
| 279 | } | 
|---|
| 280 | for (size_t i = 0; i < MaxMol; ++i) | 
|---|
| 281 | delete elementNo[i]; | 
|---|
| 282 | delete elementNo; | 
|---|
| 283 |  | 
|---|
| 284 | // write CONECTs | 
|---|
| 285 | for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) { | 
|---|
| 286 | writeNeighbors(file, 4, *atomIt); | 
|---|
| 287 | } | 
|---|
| 288 | } | 
|---|
| 289 | // END | 
|---|
| 290 | *file << "END" << endl; | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 | } | 
|---|
| 294 |  | 
|---|
| 295 | /** Add default info, when new atom is added to World. | 
|---|
| 296 | * | 
|---|
| 297 | * @param id of atom | 
|---|
| 298 | */ | 
|---|
| 299 | void FormatParser< pdb >::AtomInserted(atomId_t id) | 
|---|
| 300 | { | 
|---|
| 301 | //LOG(3, "FormatParser< pdb >::AtomInserted() - notified of atom " << id << "'s insertion."); | 
|---|
| 302 | ASSERT(!isPresentadditionalAtomData(id), | 
|---|
| 303 | "FormatParser< pdb >::AtomInserted() - additionalAtomData already present for newly added atom " | 
|---|
| 304 | +toString(id)+"."); | 
|---|
| 305 | // don't insert here as this is our check whether we are in the first time step | 
|---|
| 306 | //additionalAtomData.insert( std::make_pair(id, defaultAdditionalData) ); | 
|---|
| 307 | //SerialSet.insert(id); | 
|---|
| 308 | } | 
|---|
| 309 |  | 
|---|
| 310 | /** Remove additional AtomData info, when atom has been removed from World. | 
|---|
| 311 | * | 
|---|
| 312 | * @param id of atom | 
|---|
| 313 | */ | 
|---|
| 314 | void FormatParser< pdb >::AtomRemoved(atomId_t id) | 
|---|
| 315 | { | 
|---|
| 316 | //LOG(3, "FormatParser< pdb >::AtomRemoved() - notified of atom " << id << "'s removal."); | 
|---|
| 317 | std::map<size_t, PdbAtomInfoContainer>::iterator iter = additionalAtomData.find(id); | 
|---|
| 318 | // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence | 
|---|
| 319 | //  ASSERT(iter != additionalAtomData.end(), | 
|---|
| 320 | //      "FormatParser< pdb >::AtomRemoved() - additionalAtomData is not present for atom " | 
|---|
| 321 | //      +toString(id)+" to remove."); | 
|---|
| 322 | if (iter != additionalAtomData.end()) { | 
|---|
| 323 | ConvertTo<size_t> toSize_t; | 
|---|
| 324 | SerialSet.erase(toSize_t((iter->second).get<std::string>(PdbKey::serial))); | 
|---|
| 325 | additionalAtomData.erase(iter); | 
|---|
| 326 | } | 
|---|
| 327 | } | 
|---|
| 328 |  | 
|---|
| 329 |  | 
|---|
| 330 | /** Checks whether there is an entry for the given atom's \a _id. | 
|---|
| 331 | * | 
|---|
| 332 | * @param _id atom's id we wish to check on | 
|---|
| 333 | * @return true - entry present, false - only for atom's father or no entry | 
|---|
| 334 | */ | 
|---|
| 335 | bool FormatParser< pdb >::isPresentadditionalAtomData(unsigned int _id) | 
|---|
| 336 | { | 
|---|
| 337 | return (additionalAtomData.find(_id) != additionalAtomData.end()); | 
|---|
| 338 | } | 
|---|
| 339 |  | 
|---|
| 340 |  | 
|---|
| 341 | /** Either returns reference to present entry or creates new with default values. | 
|---|
| 342 | * | 
|---|
| 343 | * @param _atom atom whose entry we desire | 
|---|
| 344 | * @return | 
|---|
| 345 | */ | 
|---|
| 346 | PdbAtomInfoContainer& FormatParser< pdb >::getadditionalAtomData(atom *_atom) | 
|---|
| 347 | { | 
|---|
| 348 | if (additionalAtomData.find(_atom->getId()) != additionalAtomData.end()) { | 
|---|
| 349 | } else if (additionalAtomData.find(_atom->father->getId()) != additionalAtomData.end()) { | 
|---|
| 350 | // use info from direct father | 
|---|
| 351 | additionalAtomData[_atom->getId()] = additionalAtomData[_atom->father->getId()]; | 
|---|
| 352 | } else if (additionalAtomData.find(_atom->GetTrueFather()->getId()) != additionalAtomData.end()) { | 
|---|
| 353 | // use info from topmost father | 
|---|
| 354 | additionalAtomData[_atom->getId()] = additionalAtomData[_atom->GetTrueFather()->getId()]; | 
|---|
| 355 | } else { | 
|---|
| 356 | // create new entry use default values if nothing else is known | 
|---|
| 357 | additionalAtomData[_atom->getId()] = defaultAdditionalData; | 
|---|
| 358 | } | 
|---|
| 359 | return additionalAtomData[_atom->getId()]; | 
|---|
| 360 | } | 
|---|
| 361 |  | 
|---|
| 362 | /** | 
|---|
| 363 | * Writes one line of PDB-formatted data to the provided stream. | 
|---|
| 364 | * | 
|---|
| 365 | * \param stream where to write the line to | 
|---|
| 366 | * \param *currentAtom the atom of which information should be written | 
|---|
| 367 | * \param AtomNo serial number of atom | 
|---|
| 368 | * \param *name name of atom, i.e. H01 | 
|---|
| 369 | * \param ResidueName Name of molecule | 
|---|
| 370 | * \param ResidueNo number of residue | 
|---|
| 371 | */ | 
|---|
| 372 | void FormatParser< pdb >::saveLine( | 
|---|
| 373 | ostream* file, | 
|---|
| 374 | const PdbAtomInfoContainer &atomInfo) | 
|---|
| 375 | { | 
|---|
| 376 | *file << setfill(' ') << left << setw(6) | 
|---|
| 377 | << atomInfo.get<std::string>(PdbKey::token); | 
|---|
| 378 | *file << setfill(' ') << right << setw(5) | 
|---|
| 379 | << atomInfo.get<int>(PdbKey::serial); /* atom serial number */ | 
|---|
| 380 | *file << " "; /* char 12 is empty */ | 
|---|
| 381 | *file << setfill(' ') << left << setw(4) | 
|---|
| 382 | << atomInfo.get<std::string>(PdbKey::name);  /* atom name */ | 
|---|
| 383 | *file << setfill(' ') << left << setw(1) | 
|---|
| 384 | << atomInfo.get<std::string>(PdbKey::altLoc); /* alternate location/conformation */ | 
|---|
| 385 | *file << setfill(' ') << left << setw(3) | 
|---|
| 386 | << atomInfo.get<std::string>(PdbKey::resName);  /* residue name */ | 
|---|
| 387 | *file << " "; /* char 21 is empty */ | 
|---|
| 388 | *file << setfill(' ') << left << setw(1) | 
|---|
| 389 | << atomInfo.get<std::string>(PdbKey::chainID); /* chain identifier */ | 
|---|
| 390 | *file << setfill(' ') << left << setw(4) | 
|---|
| 391 | << atomInfo.get<int>(PdbKey::resSeq); /* residue sequence number */ | 
|---|
| 392 | *file << setfill(' ') << left << setw(1) | 
|---|
| 393 | << atomInfo.get<std::string>(PdbKey::iCode); /* iCode */ | 
|---|
| 394 | *file << "   "; /* char 28-30 are empty */ | 
|---|
| 395 | // have the following operate on stringstreams such that format specifiers | 
|---|
| 396 | // only act on these | 
|---|
| 397 | for (size_t i=0;i<NDIM;++i) { | 
|---|
| 398 | stringstream position; | 
|---|
| 399 | position << fixed << setprecision(3) << showpoint | 
|---|
| 400 | << atomInfo.get<double>(PositionEnumMap[i]); | 
|---|
| 401 | *file << setfill(' ') << right << setw(8) << position.str(); | 
|---|
| 402 | } | 
|---|
| 403 | { | 
|---|
| 404 | stringstream occupancy; | 
|---|
| 405 | occupancy << fixed << setprecision(2) << showpoint | 
|---|
| 406 | << atomInfo.get<double>(PdbKey::occupancy); /* occupancy */ | 
|---|
| 407 | *file << setfill(' ') << right << setw(6) << occupancy.str(); | 
|---|
| 408 | } | 
|---|
| 409 | { | 
|---|
| 410 | stringstream tempFactor; | 
|---|
| 411 | tempFactor << fixed << setprecision(2) << showpoint | 
|---|
| 412 | << atomInfo.get<double>(PdbKey::tempFactor); /* temperature factor */ | 
|---|
| 413 | *file << setfill(' ') << right << setw(6) << tempFactor.str(); | 
|---|
| 414 | } | 
|---|
| 415 | *file << "          "; /* char 68-76 are empty */ | 
|---|
| 416 | *file << setfill(' ') << right << setw(2) << atomInfo.get<std::string>(PdbKey::element); /* element */ | 
|---|
| 417 | *file << setfill(' ') << right << setw(2) << atomInfo.get<int>(PdbKey::charge); /* charge */ | 
|---|
| 418 |  | 
|---|
| 419 | *file << endl; | 
|---|
| 420 | } | 
|---|
| 421 |  | 
|---|
| 422 | /** | 
|---|
| 423 | * Writes the neighbor information of one atom to the provided stream. | 
|---|
| 424 | * | 
|---|
| 425 | * Note that ListOfBonds of WorldTime::CurrentTime is used. | 
|---|
| 426 | * | 
|---|
| 427 | * Also, we fill up the CONECT line to extend over 80 chars. | 
|---|
| 428 | * | 
|---|
| 429 | * \param *file  where to write neighbor information to | 
|---|
| 430 | * \param MaxnumberOfNeighbors of neighbors | 
|---|
| 431 | * \param *currentAtom to the atom of which to take the neighbor information | 
|---|
| 432 | */ | 
|---|
| 433 | void FormatParser< pdb >::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) { | 
|---|
| 434 | int MaxNo = MaxnumberOfNeighbors; | 
|---|
| 435 | int charsleft = 80; | 
|---|
| 436 | const BondList & ListOfBonds = currentAtom->getListOfBonds(); | 
|---|
| 437 | if (!ListOfBonds.empty()) { | 
|---|
| 438 | for(BondList::const_iterator currentBond = ListOfBonds.begin(); currentBond != ListOfBonds.end(); ++currentBond) { | 
|---|
| 439 | if (MaxNo >= MaxnumberOfNeighbors) { | 
|---|
| 440 | *file << "CONECT"; | 
|---|
| 441 | *file << setw(5) << getSerial(currentAtom->getId()); | 
|---|
| 442 | charsleft = 80-6-5; | 
|---|
| 443 | MaxNo = 0; | 
|---|
| 444 | } | 
|---|
| 445 | *file << setw(5) << getSerial((*currentBond)->GetOtherAtom(currentAtom)->getId()); | 
|---|
| 446 | charsleft -= 5; | 
|---|
| 447 | MaxNo++; | 
|---|
| 448 | if (MaxNo == MaxnumberOfNeighbors) { | 
|---|
| 449 | for (;charsleft > 0; charsleft--) | 
|---|
| 450 | *file << ' '; | 
|---|
| 451 | *file << "\n"; | 
|---|
| 452 | } | 
|---|
| 453 | } | 
|---|
| 454 | if (MaxNo != MaxnumberOfNeighbors) { | 
|---|
| 455 | for (;charsleft > 0; charsleft--) | 
|---|
| 456 | *file << ' '; | 
|---|
| 457 | *file << "\n"; | 
|---|
| 458 | } | 
|---|
| 459 | } | 
|---|
| 460 | } | 
|---|
| 461 |  | 
|---|
| 462 | /** Retrieves a value from  FormatParser< pdb >::atomIdMap. | 
|---|
| 463 | * \param atomid key | 
|---|
| 464 | * \return value | 
|---|
| 465 | */ | 
|---|
| 466 | size_t FormatParser< pdb >::getSerial(const size_t atomid) const | 
|---|
| 467 | { | 
|---|
| 468 | ASSERT(atomIdMap.find(atomid) != atomIdMap.end(), | 
|---|
| 469 | "FormatParser< pdb >::getAtomId: atomid "+toString(atomid)+" not present in Map."); | 
|---|
| 470 | return (atomIdMap.find(atomid)->second); | 
|---|
| 471 | } | 
|---|
| 472 |  | 
|---|
| 473 | /** Sets an entry in  FormatParser< pdb >::atomIdMap. | 
|---|
| 474 | * \param localatomid key | 
|---|
| 475 | * \param atomid value | 
|---|
| 476 | * \return true - key not present, false - value present | 
|---|
| 477 | */ | 
|---|
| 478 | void FormatParser< pdb >::setSerial(const size_t localatomid, const size_t atomid) | 
|---|
| 479 | { | 
|---|
| 480 | pair<std::map<size_t,size_t>::iterator, bool > inserter; | 
|---|
| 481 | //  LOG(1, "FormatParser< pdb >::setAtomId() - Inserting (" << localatomid << " -> " << atomid << ")."); | 
|---|
| 482 | inserter = atomIdMap.insert( make_pair(localatomid, atomid) ); | 
|---|
| 483 | ASSERT(inserter.second, "FormatParser< pdb >::setAtomId: atomId already present in Map."); | 
|---|
| 484 | } | 
|---|
| 485 |  | 
|---|
| 486 | /** Either returns present atom with given id or a newly created one. | 
|---|
| 487 | * | 
|---|
| 488 | * @param id_string | 
|---|
| 489 | * @return | 
|---|
| 490 | */ | 
|---|
| 491 | atom* FormatParser< pdb >::getAtomToParse(std::string id_string) const | 
|---|
| 492 | { | 
|---|
| 493 | // get the local ID | 
|---|
| 494 | ConvertTo<int> toInt; | 
|---|
| 495 | unsigned int AtomID = toInt(id_string); | 
|---|
| 496 | LOG(4, "INFO: Local id is "+toString(AtomID)+"."); | 
|---|
| 497 | // get the atomic ID if present | 
|---|
| 498 | atom* newAtom = NULL; | 
|---|
| 499 | if (atomIdMap.count((size_t)AtomID)) { | 
|---|
| 500 | std::map<size_t, size_t>::const_iterator iter = atomIdMap.find(AtomID); | 
|---|
| 501 | AtomID = iter->second; | 
|---|
| 502 | LOG(4, "INFO: Global id present as " << AtomID << "."); | 
|---|
| 503 | // check if atom exists | 
|---|
| 504 | newAtom = World::getInstance().getAtom(AtomById(AtomID)); | 
|---|
| 505 | LOG(5, "INFO: Listing all present atoms with id."); | 
|---|
| 506 | BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms()) | 
|---|
| 507 | LOG(5, "INFO: " << *_atom << " with id " << _atom->getId()); | 
|---|
| 508 | } | 
|---|
| 509 | // if not exists, create | 
|---|
| 510 | if (newAtom == NULL) { | 
|---|
| 511 | newAtom = World::getInstance().createAtom(); | 
|---|
| 512 | LOG(4, "INFO: No association to global id present, creating atom."); | 
|---|
| 513 | } else { | 
|---|
| 514 | LOG(4, "INFO: Existing atom found: " << *newAtom << "."); | 
|---|
| 515 | } | 
|---|
| 516 | return newAtom; | 
|---|
| 517 | } | 
|---|
| 518 |  | 
|---|
| 519 | /** read a line starting with key ATOM. | 
|---|
| 520 | * | 
|---|
| 521 | * We check for line's length and parse only up to this value. | 
|---|
| 522 | * | 
|---|
| 523 | * @param atomInfo container to put information in | 
|---|
| 524 | * @param line line containing key ATOM | 
|---|
| 525 | */ | 
|---|
| 526 | void FormatParser< pdb >::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const | 
|---|
| 527 | { | 
|---|
| 528 | const size_t length = line.length(); | 
|---|
| 529 | if (length < 80) | 
|---|
| 530 | ELOG(2, "FormatParser< pdb >::readPdbAtomInfoContainer() - pdb is mal-formed, containing less than 80 chars!"); | 
|---|
| 531 | if (length >= 6) { | 
|---|
| 532 | LOG(4,"INFO: Parsing token from "+line.substr(0,6)+"."); | 
|---|
| 533 | atomInfo.set(PdbKey::token, line.substr(0,6)); | 
|---|
| 534 | } | 
|---|
| 535 | if (length >= 11) { | 
|---|
| 536 | LOG(4,"INFO: Parsing serial from "+line.substr(6,5)+"."); | 
|---|
| 537 | atomInfo.set(PdbKey::serial, line.substr(6,5)); | 
|---|
| 538 | ASSERT(atomInfo.get<int>(PdbKey::serial) != 0, | 
|---|
| 539 | "FormatParser< pdb >::readPdbAtomInfoContainer() - serial 0 is invalid (filler id for conect entries)."); | 
|---|
| 540 | } | 
|---|
| 541 |  | 
|---|
| 542 | if (length >= 16) { | 
|---|
| 543 | LOG(4,"INFO: Parsing name from "+line.substr(12,4)+"."); | 
|---|
| 544 | atomInfo.set(PdbKey::name, line.substr(12,4)); | 
|---|
| 545 | } | 
|---|
| 546 | if (length >= 17) { | 
|---|
| 547 | LOG(4,"INFO: Parsing altLoc from "+line.substr(16,1)+"."); | 
|---|
| 548 | atomInfo.set(PdbKey::altLoc, line.substr(16,1)); | 
|---|
| 549 | } | 
|---|
| 550 | if (length >= 20) { | 
|---|
| 551 | LOG(4,"INFO: Parsing resName from "+line.substr(17,3)+"."); | 
|---|
| 552 | atomInfo.set(PdbKey::resName, line.substr(17,3)); | 
|---|
| 553 | } | 
|---|
| 554 | if (length >= 22) { | 
|---|
| 555 | LOG(4,"INFO: Parsing chainID from "+line.substr(21,1)+"."); | 
|---|
| 556 | atomInfo.set(PdbKey::chainID, line.substr(21,1)); | 
|---|
| 557 | } | 
|---|
| 558 | if (length >= 26) { | 
|---|
| 559 | LOG(4,"INFO: Parsing resSeq from "+line.substr(22,4)+"."); | 
|---|
| 560 | atomInfo.set(PdbKey::resSeq, line.substr(22,4)); | 
|---|
| 561 | } | 
|---|
| 562 | if (length >= 27) { | 
|---|
| 563 | LOG(4,"INFO: Parsing iCode from "+line.substr(26,1)+"."); | 
|---|
| 564 | atomInfo.set(PdbKey::iCode, line.substr(26,1)); | 
|---|
| 565 | } | 
|---|
| 566 |  | 
|---|
| 567 | if (length >= 60) { | 
|---|
| 568 | LOG(4,"INFO: Parsing occupancy from "+line.substr(54,6)+"."); | 
|---|
| 569 | atomInfo.set(PdbKey::occupancy, line.substr(54,6)); | 
|---|
| 570 | } | 
|---|
| 571 | if (length >= 66) { | 
|---|
| 572 | LOG(4,"INFO: Parsing tempFactor from "+line.substr(60,6)+"."); | 
|---|
| 573 | atomInfo.set(PdbKey::tempFactor, line.substr(60,6)); | 
|---|
| 574 | } | 
|---|
| 575 | if (length >= 80) { | 
|---|
| 576 | LOG(4,"INFO: Parsing charge from "+line.substr(78,2)+"."); | 
|---|
| 577 | atomInfo.set(PdbKey::charge, line.substr(78,2)); | 
|---|
| 578 | } | 
|---|
| 579 | if (length >= 78) { | 
|---|
| 580 | LOG(4,"INFO: Parsing element from "+line.substr(76,2)+"."); | 
|---|
| 581 | atomInfo.set(PdbKey::element, line.substr(76,2)); | 
|---|
| 582 | } else { | 
|---|
| 583 | LOG(4,"INFO: Trying to parse alternative element from name "+line.substr(12,4)+"."); | 
|---|
| 584 | atomInfo.set(PdbKey::element, line.substr(12,4)); | 
|---|
| 585 | } | 
|---|
| 586 | } | 
|---|
| 587 |  | 
|---|
| 588 | /** Parse an ATOM line from a PDB file. | 
|---|
| 589 | * | 
|---|
| 590 | * Reads one data line of a pdstatus file and interprets it according to the | 
|---|
| 591 | * specifications of the PDB 3.2 format: http://www.wwpdb.org/docs.html | 
|---|
| 592 | * | 
|---|
| 593 | *  A new atom is created and filled with available information, non- | 
|---|
| 594 | *  standard information is placed in additionalAtomData at the atom's id. | 
|---|
| 595 | * | 
|---|
| 596 | * \param _step time step to use | 
|---|
| 597 | * \param line to parse as an atom | 
|---|
| 598 | * \param newmol molecule to add parsed atoms to | 
|---|
| 599 | */ | 
|---|
| 600 | void FormatParser< pdb >::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) { | 
|---|
| 601 | vector<string>::iterator it; | 
|---|
| 602 |  | 
|---|
| 603 | atom* newAtom = getAtomToParse(line.substr(6,5)); | 
|---|
| 604 | LOG(3,"INFO: Parsing END entry or empty line."); | 
|---|
| 605 | bool FirstTimestep = isPresentadditionalAtomData(newAtom->getId()) ? false : true; | 
|---|
| 606 | ASSERT((FirstTimestep && (_step == 0)) || (!FirstTimestep && (_step !=0)), | 
|---|
| 607 | "FormatParser< pdb >::readAtomDataLine() - additionalAtomData present though atom is newly parsed."); | 
|---|
| 608 | if (FirstTimestep) { | 
|---|
| 609 | LOG(3,"INFO: Parsing new atom."); | 
|---|
| 610 | } else { | 
|---|
| 611 | LOG(3,"INFO: Parsing present atom "+toString(*newAtom)+"."); | 
|---|
| 612 | } | 
|---|
| 613 | PdbAtomInfoContainer &atomInfo = getadditionalAtomData(newAtom); | 
|---|
| 614 | LOG(4,"INFO: Information in container is "+toString(atomInfo)+"."); | 
|---|
| 615 |  | 
|---|
| 616 | string word; | 
|---|
| 617 | ConvertTo<size_t> toSize_t; | 
|---|
| 618 |  | 
|---|
| 619 | // assign highest+1 instead, but then beware of CONECT entries! Another map needed! | 
|---|
| 620 | //  if (!Inserter.second) { | 
|---|
| 621 | //    const size_t id = (*SerialSet.rbegin())+1; | 
|---|
| 622 | //    SerialSet.insert(id); | 
|---|
| 623 | //    atomInfo.set(PdbKey::serial, toString(id)); | 
|---|
| 624 | //    ELOG(2, "Serial " << atomInfo.get<std::string>(PdbKey::serial) << " already present, " | 
|---|
| 625 | //        << "assigning " << toString(id) << " instead."); | 
|---|
| 626 | //  } | 
|---|
| 627 |  | 
|---|
| 628 | // check whether serial exists, if so, assign next available | 
|---|
| 629 |  | 
|---|
| 630 | //  LOG(2, "Split line:" | 
|---|
| 631 | //      << line.substr(6,5) << "|" | 
|---|
| 632 | //      << line.substr(12,4) << "|" | 
|---|
| 633 | //      << line.substr(16,1) << "|" | 
|---|
| 634 | //      << line.substr(17,3) << "|" | 
|---|
| 635 | //      << line.substr(21,1) << "|" | 
|---|
| 636 | //      << line.substr(22,4) << "|" | 
|---|
| 637 | //      << line.substr(26,1) << "|" | 
|---|
| 638 | //      << line.substr(30,8) << "|" | 
|---|
| 639 | //      << line.substr(38,8) << "|" | 
|---|
| 640 | //      << line.substr(46,8) << "|" | 
|---|
| 641 | //      << line.substr(54,6) << "|" | 
|---|
| 642 | //      << line.substr(60,6) << "|" | 
|---|
| 643 | //      << line.substr(76,2) << "|" | 
|---|
| 644 | //      << line.substr(78,2)); | 
|---|
| 645 |  | 
|---|
| 646 | if (FirstTimestep) { | 
|---|
| 647 | // first time step | 
|---|
| 648 | // then fill info container | 
|---|
| 649 | readPdbAtomInfoContainer(atomInfo, line); | 
|---|
| 650 | // set the serial | 
|---|
| 651 | std::pair< std::set<size_t>::const_iterator, bool> Inserter = | 
|---|
| 652 | SerialSet.insert(toSize_t(atomInfo.get<std::string>(PdbKey::serial))); | 
|---|
| 653 | ASSERT(Inserter.second, | 
|---|
| 654 | "FormatParser< pdb >::readAtomDataLine() - ATOM contains entry with serial " | 
|---|
| 655 | +atomInfo.get<std::string>(PdbKey::serial)+" already present!"); | 
|---|
| 656 | setSerial(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId()); | 
|---|
| 657 | // set position | 
|---|
| 658 | Vector tempVector; | 
|---|
| 659 | LOG(4,"INFO: Parsing position from (" | 
|---|
| 660 | +line.substr(30,8)+"," | 
|---|
| 661 | +line.substr(38,8)+"," | 
|---|
| 662 | +line.substr(46,8)+")."); | 
|---|
| 663 | PdbAtomInfoContainer::ScanKey(tempVector[0], line.substr(30,8)); | 
|---|
| 664 | PdbAtomInfoContainer::ScanKey(tempVector[1], line.substr(38,8)); | 
|---|
| 665 | PdbAtomInfoContainer::ScanKey(tempVector[2], line.substr(46,8)); | 
|---|
| 666 | newAtom->setPosition(tempVector); | 
|---|
| 667 | // set element | 
|---|
| 668 | std::string value = atomInfo.get<std::string>(PdbKey::element); | 
|---|
| 669 | // make second character lower case if not | 
|---|
| 670 | if ((value[1] >= 'A') && (value[1] <= 'Z')) | 
|---|
| 671 | value[1] = (value[1] - 'A') + 'a'; | 
|---|
| 672 | const element *elem = World::getInstance().getPeriode() | 
|---|
| 673 | ->FindElement(value); | 
|---|
| 674 | ASSERT(elem != NULL, | 
|---|
| 675 | "FormatParser< pdb >::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!"); | 
|---|
| 676 | newAtom->setType(elem); | 
|---|
| 677 |  | 
|---|
| 678 | if (newmol != NULL) | 
|---|
| 679 | newmol->AddAtom(newAtom); | 
|---|
| 680 | } else { | 
|---|
| 681 | // not first time step | 
|---|
| 682 | // then parse into different container | 
|---|
| 683 | PdbAtomInfoContainer consistencyInfo; | 
|---|
| 684 | readPdbAtomInfoContainer(consistencyInfo, line); | 
|---|
| 685 | // then check additional info for consistency | 
|---|
| 686 | ASSERT(atomInfo.get<std::string>(PdbKey::token) == consistencyInfo.get<std::string>(PdbKey::token), | 
|---|
| 687 | "FormatParser< pdb >::readAtomDataLine() - difference in token on multiple time step for atom with id " | 
|---|
| 688 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 689 | ASSERT(atomInfo.get<std::string>(PdbKey::name) == consistencyInfo.get<std::string>(PdbKey::name), | 
|---|
| 690 | "FormatParser< pdb >::readAtomDataLine() - difference in name on multiple time step for atom with id " | 
|---|
| 691 | +atomInfo.get<std::string>(PdbKey::serial)+":" | 
|---|
| 692 | +atomInfo.get<std::string>(PdbKey::name)+"!=" | 
|---|
| 693 | +consistencyInfo.get<std::string>(PdbKey::name)+"."); | 
|---|
| 694 | ASSERT(atomInfo.get<std::string>(PdbKey::altLoc) == consistencyInfo.get<std::string>(PdbKey::altLoc), | 
|---|
| 695 | "FormatParser< pdb >::readAtomDataLine() - difference in altLoc on multiple time step for atom with id " | 
|---|
| 696 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 697 | ASSERT(atomInfo.get<std::string>(PdbKey::resName) == consistencyInfo.get<std::string>(PdbKey::resName), | 
|---|
| 698 | "FormatParser< pdb >::readAtomDataLine() - difference in resName on multiple time step for atom with id " | 
|---|
| 699 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 700 | ASSERT(atomInfo.get<std::string>(PdbKey::chainID) == consistencyInfo.get<std::string>(PdbKey::chainID), | 
|---|
| 701 | "FormatParser< pdb >::readAtomDataLine() - difference in chainID on multiple time step for atom with id " | 
|---|
| 702 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 703 | ASSERT(atomInfo.get<std::string>(PdbKey::resSeq) == consistencyInfo.get<std::string>(PdbKey::resSeq), | 
|---|
| 704 | "FormatParser< pdb >::readAtomDataLine() - difference in resSeq on multiple time step for atom with id " | 
|---|
| 705 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 706 | ASSERT(atomInfo.get<std::string>(PdbKey::iCode) == consistencyInfo.get<std::string>(PdbKey::iCode), | 
|---|
| 707 | "FormatParser< pdb >::readAtomDataLine() - difference in iCode on multiple time step for atom with id " | 
|---|
| 708 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 709 | ASSERT(atomInfo.get<std::string>(PdbKey::occupancy) == consistencyInfo.get<std::string>(PdbKey::occupancy), | 
|---|
| 710 | "FormatParser< pdb >::readAtomDataLine() - difference in occupancy on multiple time step for atom with id " | 
|---|
| 711 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 712 | ASSERT(atomInfo.get<std::string>(PdbKey::tempFactor) == consistencyInfo.get<std::string>(PdbKey::tempFactor), | 
|---|
| 713 | "FormatParser< pdb >::readAtomDataLine() - difference in tempFactor on multiple time step for atom with id " | 
|---|
| 714 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 715 | ASSERT(atomInfo.get<std::string>(PdbKey::charge) == consistencyInfo.get<std::string>(PdbKey::charge), | 
|---|
| 716 | "FormatParser< pdb >::readAtomDataLine() - difference in charge on multiple time step for atom with id " | 
|---|
| 717 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 718 | ASSERT(atomInfo.get<std::string>(PdbKey::element) == consistencyInfo.get<std::string>(PdbKey::element), | 
|---|
| 719 | "FormatParser< pdb >::readAtomDataLine() - difference in element on multiple time step for atom with id " | 
|---|
| 720 | +atomInfo.get<std::string>(PdbKey::serial)+"!"); | 
|---|
| 721 | // and parse in trajectory | 
|---|
| 722 | Vector tempVector; | 
|---|
| 723 | LOG(4,"INFO: Parsing trajectory position from (" | 
|---|
| 724 | +line.substr(30,8)+"," | 
|---|
| 725 | +line.substr(38,8)+"," | 
|---|
| 726 | +line.substr(46,8)+")."); | 
|---|
| 727 | PdbAtomInfoContainer::ScanKey(tempVector[0], line.substr(30,8)); | 
|---|
| 728 | PdbAtomInfoContainer::ScanKey(tempVector[1], line.substr(38,8)); | 
|---|
| 729 | PdbAtomInfoContainer::ScanKey(tempVector[2], line.substr(46,8)); | 
|---|
| 730 | LOG(4,"INFO: Adding trajectory point to time step "+toString(_step)+"."); | 
|---|
| 731 | // and set position at new time step | 
|---|
| 732 | newAtom->setPositionAtStep(_step, tempVector); | 
|---|
| 733 | } | 
|---|
| 734 |  | 
|---|
| 735 |  | 
|---|
| 736 | //  printAtomInfo(newAtom); | 
|---|
| 737 | } | 
|---|
| 738 |  | 
|---|
| 739 | /** Prints all PDB-specific information known about an atom. | 
|---|
| 740 | * | 
|---|
| 741 | */ | 
|---|
| 742 | void FormatParser< pdb >::printAtomInfo(const atom * const newAtom) const | 
|---|
| 743 | { | 
|---|
| 744 | const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist | 
|---|
| 745 |  | 
|---|
| 746 | LOG(1, "We know about atom " << newAtom->getId() << ":"); | 
|---|
| 747 | LOG(1, "\ttoken is " << atomInfo.get<std::string>(PdbKey::token)); | 
|---|
| 748 | LOG(1, "\tserial is " << atomInfo.get<int>(PdbKey::serial)); | 
|---|
| 749 | LOG(1, "\tname is " << atomInfo.get<std::string>(PdbKey::name)); | 
|---|
| 750 | LOG(1, "\taltLoc is " << atomInfo.get<std::string>(PdbKey::altLoc)); | 
|---|
| 751 | LOG(1, "\tresName is " << atomInfo.get<std::string>(PdbKey::resName)); | 
|---|
| 752 | LOG(1, "\tchainID is " << atomInfo.get<std::string>(PdbKey::chainID)); | 
|---|
| 753 | LOG(1, "\tresSeq is " << atomInfo.get<int>(PdbKey::resSeq)); | 
|---|
| 754 | LOG(1, "\tiCode is " << atomInfo.get<std::string>(PdbKey::iCode)); | 
|---|
| 755 | LOG(1, "\tX is " << atomInfo.get<double>(PdbKey::X)); | 
|---|
| 756 | LOG(1, "\tY is " << atomInfo.get<double>(PdbKey::Y)); | 
|---|
| 757 | LOG(1, "\tZ is " << atomInfo.get<double>(PdbKey::Z)); | 
|---|
| 758 | LOG(1, "\toccupancy is " << atomInfo.get<double>(PdbKey::occupancy)); | 
|---|
| 759 | LOG(1, "\ttempFactor is " << atomInfo.get<double>(PdbKey::tempFactor)); | 
|---|
| 760 | LOG(1, "\telement is '" << *(newAtom->getType()) << "'"); | 
|---|
| 761 | LOG(1, "\tcharge is " << atomInfo.get<int>(PdbKey::charge)); | 
|---|
| 762 | } | 
|---|
| 763 |  | 
|---|
| 764 | /** | 
|---|
| 765 | * Reads neighbor information for one atom from the input. | 
|---|
| 766 | * | 
|---|
| 767 | * \param _step time step to use | 
|---|
| 768 | * \param line to parse as an atom | 
|---|
| 769 | */ | 
|---|
| 770 | void FormatParser< pdb >::readNeighbors(const unsigned int _step, std::string &line) | 
|---|
| 771 | { | 
|---|
| 772 | const size_t length = line.length(); | 
|---|
| 773 | std::list<size_t> ListOfNeighbors; | 
|---|
| 774 | ConvertTo<size_t> toSize_t; | 
|---|
| 775 |  | 
|---|
| 776 | // obtain neighbours | 
|---|
| 777 | // show split line for debugging | 
|---|
| 778 | string output; | 
|---|
| 779 | ASSERT(length >=16, | 
|---|
| 780 | "FormatParser< pdb >::readNeighbors() - CONECT entry has not enough entries: "+line+"!"); | 
|---|
| 781 | //  output = "Split line:|"; | 
|---|
| 782 | //  output += line.substr(6,5) + "|"; | 
|---|
| 783 | const size_t id = toSize_t(line.substr(6,5)); | 
|---|
| 784 | for (size_t index = 11; index <= 26; index+=5) { | 
|---|
| 785 | if (index+5 <= length) { | 
|---|
| 786 | output += line.substr(index,5) + "|"; | 
|---|
| 787 | // search for digits | 
|---|
| 788 | int otherid = -1; | 
|---|
| 789 | PdbAtomInfoContainer::ScanKey(otherid, line.substr(index,5)); | 
|---|
| 790 | if (otherid > 0) | 
|---|
| 791 | ListOfNeighbors.push_back(otherid); | 
|---|
| 792 | else | 
|---|
| 793 | ELOG(2, "FormatParser< pdb >::readNeighbors() - discarding conect entry with id 0."); | 
|---|
| 794 | } else  { | 
|---|
| 795 | break; | 
|---|
| 796 | } | 
|---|
| 797 | } | 
|---|
| 798 | LOG(4, output); | 
|---|
| 799 |  | 
|---|
| 800 | // add neighbours | 
|---|
| 801 | atom *_atom = World::getInstance().getAtom(AtomById(getSerial(id))); | 
|---|
| 802 | LOG(2, "STATUS: Atom " << _atom->getId() << " gets " << ListOfNeighbors.size() << " more neighbours."); | 
|---|
| 803 | for (std::list<size_t>::const_iterator iter = ListOfNeighbors.begin(); | 
|---|
| 804 | iter != ListOfNeighbors.end(); | 
|---|
| 805 | ++iter) { | 
|---|
| 806 | atom * const _Otheratom = World::getInstance().getAtom(AtomById(getSerial(*iter))); | 
|---|
| 807 | LOG(3, "INFO: Adding Bond (" << *_atom << "," << *_Otheratom << ")"); | 
|---|
| 808 | _atom->addBond(_step, _Otheratom); | 
|---|
| 809 | } | 
|---|
| 810 | } | 
|---|
| 811 |  | 
|---|
| 812 | /** | 
|---|
| 813 | * Replaces atom IDs read from the file by the corresponding world IDs. All IDs | 
|---|
| 814 | * IDs of the input string will be replaced; expected separating characters are | 
|---|
| 815 | * "-" and ",". | 
|---|
| 816 | * | 
|---|
| 817 | * \param string in which atom IDs should be adapted | 
|---|
| 818 | * | 
|---|
| 819 | * \return input string with modified atom IDs | 
|---|
| 820 | */ | 
|---|
| 821 | //string  FormatParser< pdb >::adaptIdDependentDataString(string data) { | 
|---|
| 822 | //  // there might be no IDs | 
|---|
| 823 | //  if (data == "-") { | 
|---|
| 824 | //    return "-"; | 
|---|
| 825 | //  } | 
|---|
| 826 | // | 
|---|
| 827 | //  char separator; | 
|---|
| 828 | //  int id; | 
|---|
| 829 | //  stringstream line, result; | 
|---|
| 830 | //  line << data; | 
|---|
| 831 | // | 
|---|
| 832 | //  line >> id; | 
|---|
| 833 | //  result << atomIdMap[id]; | 
|---|
| 834 | //  while (line.good()) { | 
|---|
| 835 | //    line >> separator >> id; | 
|---|
| 836 | //    result << separator << atomIdMap[id]; | 
|---|
| 837 | //  } | 
|---|
| 838 | // | 
|---|
| 839 | //  return result.str(); | 
|---|
| 840 | //  return ""; | 
|---|
| 841 | //} | 
|---|
| 842 |  | 
|---|
| 843 |  | 
|---|
| 844 | bool FormatParser< pdb >::operator==(const FormatParser< pdb >& b) const | 
|---|
| 845 | { | 
|---|
| 846 | bool status = true; | 
|---|
| 847 | World::AtomComposite atoms = World::getInstance().getAllAtoms(); | 
|---|
| 848 | for (World::AtomComposite::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) { | 
|---|
| 849 | if ((additionalAtomData.find((*iter)->getId()) != additionalAtomData.end()) | 
|---|
| 850 | && (b.additionalAtomData.find((*iter)->getId()) != b.additionalAtomData.end())) { | 
|---|
| 851 | const PdbAtomInfoContainer &atomInfo = additionalAtomData.at((*iter)->getId()); | 
|---|
| 852 | const PdbAtomInfoContainer &OtheratomInfo = b.additionalAtomData.at((*iter)->getId()); | 
|---|
| 853 |  | 
|---|
| 854 | status = status && (atomInfo.get<std::string>(PdbKey::serial) == OtheratomInfo.get<std::string>(PdbKey::serial)); | 
|---|
| 855 | if (!status) ELOG(1, "Mismatch in serials!"); | 
|---|
| 856 | status = status && (atomInfo.get<std::string>(PdbKey::name) == OtheratomInfo.get<std::string>(PdbKey::name)); | 
|---|
| 857 | if (!status) ELOG(1, "Mismatch in names!"); | 
|---|
| 858 | status = status && (atomInfo.get<std::string>(PdbKey::altLoc) == OtheratomInfo.get<std::string>(PdbKey::altLoc)); | 
|---|
| 859 | if (!status) ELOG(1, "Mismatch in altLocs!"); | 
|---|
| 860 | status = status && (atomInfo.get<std::string>(PdbKey::resName) == OtheratomInfo.get<std::string>(PdbKey::resName)); | 
|---|
| 861 | if (!status) ELOG(1, "Mismatch in resNames!"); | 
|---|
| 862 | status = status && (atomInfo.get<std::string>(PdbKey::chainID) == OtheratomInfo.get<std::string>(PdbKey::chainID)); | 
|---|
| 863 | if (!status) ELOG(1, "Mismatch in chainIDs!"); | 
|---|
| 864 | status = status && (atomInfo.get<std::string>(PdbKey::resSeq) == OtheratomInfo.get<std::string>(PdbKey::resSeq)); | 
|---|
| 865 | if (!status) ELOG(1, "Mismatch in resSeqs!"); | 
|---|
| 866 | status = status && (atomInfo.get<std::string>(PdbKey::iCode) == OtheratomInfo.get<std::string>(PdbKey::iCode)); | 
|---|
| 867 | if (!status) ELOG(1, "Mismatch in iCodes!"); | 
|---|
| 868 | status = status && (atomInfo.get<std::string>(PdbKey::occupancy) == OtheratomInfo.get<std::string>(PdbKey::occupancy)); | 
|---|
| 869 | if (!status) ELOG(1, "Mismatch in occupancies!"); | 
|---|
| 870 | status = status && (atomInfo.get<std::string>(PdbKey::tempFactor) == OtheratomInfo.get<std::string>(PdbKey::tempFactor)); | 
|---|
| 871 | if (!status) ELOG(1, "Mismatch in tempFactors!"); | 
|---|
| 872 | status = status && (atomInfo.get<std::string>(PdbKey::charge) == OtheratomInfo.get<std::string>(PdbKey::charge)); | 
|---|
| 873 | if (!status) ELOG(1, "Mismatch in charges!"); | 
|---|
| 874 | } | 
|---|
| 875 | } | 
|---|
| 876 |  | 
|---|
| 877 | return status; | 
|---|
| 878 | } | 
|---|
| 879 |  | 
|---|