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