| [3ae731] | 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 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [3ae731] | 21 | 
 | 
|---|
| [ad011c] | 22 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 23 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 24 | #include "CodePatterns/toString.hpp"
 | 
|---|
 | 25 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [9dba5f] | 26 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
 | 27 | #include "World.hpp"
 | 
|---|
| [3ae731] | 28 | #include "atom.hpp"
 | 
|---|
| [129204] | 29 | #include "Bond/bond.hpp"
 | 
|---|
| [bb6193] | 30 | #include "element.hpp"
 | 
|---|
 | 31 | #include "molecule.hpp"
 | 
|---|
| [3ae731] | 32 | #include "periodentafel.hpp"
 | 
|---|
 | 33 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| [4fbca9c] | 34 | #include "Parser/PdbParser.hpp"
 | 
|---|
| [073a9e4] | 35 | #include "World.hpp"
 | 
|---|
 | 36 | #include "WorldTime.hpp"
 | 
|---|
| [bb6193] | 37 | 
 | 
|---|
| [3ae731] | 38 | #include <map>
 | 
|---|
 | 39 | #include <vector>
 | 
|---|
 | 40 | 
 | 
|---|
| [bb6193] | 41 | #include <iostream>
 | 
|---|
 | 42 | #include <iomanip>
 | 
|---|
| [3ae731] | 43 | 
 | 
|---|
 | 44 | using namespace std;
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | /**
 | 
|---|
 | 47 |  * Constructor.
 | 
|---|
 | 48 |  */
 | 
|---|
 | 49 | PdbParser::PdbParser() {
 | 
|---|
| [4fbca9c] | 50 |   knownTokens["ATOM"] = PdbKey::Atom;
 | 
|---|
| [16462f] | 51 |   knownTokens["HETATM"] = PdbKey::Atom;
 | 
|---|
| [4fbca9c] | 52 |   knownTokens["TER"] = PdbKey::Filler;
 | 
|---|
| [9dba5f] | 53 |   knownTokens["END"] = PdbKey::EndOfTimestep;
 | 
|---|
| [4fbca9c] | 54 |   knownTokens["CONECT"] = PdbKey::Connect;
 | 
|---|
 | 55 |   knownTokens["REMARK"] = PdbKey::Remark;
 | 
|---|
| [9dba5f] | 56 |   knownTokens[""] = PdbKey::EndOfTimestep;
 | 
|---|
| [16462f] | 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;
 | 
|---|
| [3ae731] | 62 | }
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 | /**
 | 
|---|
 | 65 |  * Destructor.
 | 
|---|
 | 66 |  */
 | 
|---|
 | 67 | PdbParser::~PdbParser() {
 | 
|---|
| [873037] | 68 |   PdbAtomInfoContainer::clearknownDataKeys();
 | 
|---|
| [3ae731] | 69 |   additionalAtomData.clear();
 | 
|---|
 | 70 |   atomIdMap.clear();
 | 
|---|
| [4fbca9c] | 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;
 | 
|---|
| [3ae731] | 100 | }
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 | /**
 | 
|---|
| [4fbca9c] | 103 |  * Loads atoms from a PDB-formatted file.
 | 
|---|
| [3ae731] | 104 |  *
 | 
|---|
| [4fbca9c] | 105 |  * \param PDB file
 | 
|---|
| [3ae731] | 106 |  */
 | 
|---|
 | 107 | void PdbParser::load(istream* file) {
 | 
|---|
| [4fbca9c] | 108 |   string line;
 | 
|---|
 | 109 |   size_t linecount  = 0;
 | 
|---|
 | 110 |   enum PdbKey::KnownTokens token;
 | 
|---|
 | 111 | 
 | 
|---|
| [16462f] | 112 |   // reset atomIdMap for this file (to correctly parse CONECT entries)
 | 
|---|
 | 113 |   atomIdMap.clear();
 | 
|---|
 | 114 | 
 | 
|---|
| [9dba5f] | 115 |   bool NotEndOfFile = true;
 | 
|---|
| [4fbca9c] | 116 |   molecule *newmol = World::getInstance().createMolecule();
 | 
|---|
 | 117 |   newmol->ActiveFlag = true;
 | 
|---|
| [b0a2e3] | 118 |   unsigned int step = 0;
 | 
|---|
| [4fbca9c] | 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) {
 | 
|---|
| [9dba5f] | 122 |     bool NotEndOfTimestep = true;
 | 
|---|
| [b0a2e3] | 123 |     while (NotEndOfTimestep && NotEndOfFile) {
 | 
|---|
| [9dba5f] | 124 |       std::getline(*file, line, '\n');
 | 
|---|
| [b0a2e3] | 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 |         }
 | 
|---|
| [9dba5f] | 153 |       }
 | 
|---|
 | 154 |       NotEndOfFile = NotEndOfFile && (file->good());
 | 
|---|
 | 155 |       linecount++;
 | 
|---|
| [4fbca9c] | 156 |     }
 | 
|---|
| [b0a2e3] | 157 |     ++step;
 | 
|---|
 | 158 |   }
 | 
|---|
| [48801a] | 159 |   BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms())
 | 
|---|
 | 160 |     LOG(4, "INFO: Atom " << _atom->getName() << " " << *dynamic_cast<AtomInfo *>(_atom) << ".");
 | 
|---|
| [4afa46] | 161 | 
 | 
|---|
 | 162 |   // refresh atom::nr and atom::name
 | 
|---|
 | 163 |   newmol->getAtomCount();
 | 
|---|
| [3ae731] | 164 | }
 | 
|---|
 | 165 | 
 | 
|---|
 | 166 | /**
 | 
|---|
| [73916f] | 167 |  * Saves the \a atoms into as a PDB file.
 | 
|---|
| [3ae731] | 168 |  *
 | 
|---|
 | 169 |  * \param file where to save the state
 | 
|---|
| [73916f] | 170 |  * \param atoms atoms to store
 | 
|---|
| [3ae731] | 171 |  */
 | 
|---|
| [73916f] | 172 | void PdbParser::save(ostream* file, const std::vector<atom *> &AtomList)
 | 
|---|
 | 173 | {
 | 
|---|
| [bb6193] | 174 |   DoLog(0) && (Log() << Verbose(0) << "Saving changes to pdb." << std::endl);
 | 
|---|
| [9dba5f] | 175 | 
 | 
|---|
 | 176 |   // check for maximum number of time steps
 | 
|---|
 | 177 |   size_t max_timesteps = 0;
 | 
|---|
 | 178 |   BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms()) {
 | 
|---|
| [48801a] | 179 |     LOG(4, "INFO: Atom " << _atom->getName() << " " << *dynamic_cast<AtomInfo *>(_atom) << ".");
 | 
|---|
| [9dba5f] | 180 |     if (_atom->getTrajectorySize() > max_timesteps)
 | 
|---|
 | 181 |       max_timesteps = _atom->getTrajectorySize();
 | 
|---|
| [bb6193] | 182 |   }
 | 
|---|
| [9dba5f] | 183 |   LOG(2,"INFO: Found a maximum of " << max_timesteps << " time steps to store.");
 | 
|---|
| [3ae731] | 184 | 
 | 
|---|
| [9dba5f] | 185 |   // re-distribute serials
 | 
|---|
 | 186 |   // (new atoms might have been added)
 | 
|---|
 | 187 |   // (serials must be consistent over time steps)
 | 
|---|
| [4fbca9c] | 188 |   atomIdMap.clear();
 | 
|---|
| [9dba5f] | 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;
 | 
|---|
| [16462f] | 212 |     }
 | 
|---|
| [9dba5f] | 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 |         }
 | 
|---|
| [bb6193] | 222 |       }
 | 
|---|
| [9dba5f] | 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
 | 
|---|
| [8990879] | 262 |         if (atomInfo.get<std::string>(PdbKey::element) != (*atomIt)->getType()->getSymbol()) {
 | 
|---|
 | 263 |           std::string symbol = (*atomIt)->getType()->getSymbol();
 | 
|---|
 | 264 |           if ((symbol[1] >= 'a') && (symbol[1] <= 'z'))
 | 
|---|
 | 265 |             symbol[1] = (symbol[1] - 'a') + 'A';
 | 
|---|
 | 266 |           atomInfo.set(PdbKey::element, symbol);
 | 
|---|
 | 267 |         }
 | 
|---|
| [9dba5f] | 268 | 
 | 
|---|
 | 269 |         // finally save the line
 | 
|---|
 | 270 |         saveLine(file, atomInfo);
 | 
|---|
| [16462f] | 271 |       }
 | 
|---|
| [9dba5f] | 272 |       for (size_t i = 0; i < MaxMol; ++i)
 | 
|---|
 | 273 |         delete elementNo[i];
 | 
|---|
 | 274 |       delete elementNo;
 | 
|---|
| [3ae731] | 275 | 
 | 
|---|
| [9dba5f] | 276 |       // write CONECTs
 | 
|---|
 | 277 |       for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
 | 
|---|
 | 278 |         writeNeighbors(file, 4, *atomIt);
 | 
|---|
 | 279 |       }
 | 
|---|
| [bb6193] | 280 |     }
 | 
|---|
| [9dba5f] | 281 |     // END
 | 
|---|
 | 282 |     *file << "END" << endl;
 | 
|---|
| [3ae731] | 283 |   }
 | 
|---|
 | 284 | 
 | 
|---|
 | 285 | }
 | 
|---|
 | 286 | 
 | 
|---|
| [9dba5f] | 287 | /** Checks whether there is an entry for the given atom's \a _id.
 | 
|---|
 | 288 |  *
 | 
|---|
 | 289 |  * @param _id atom's id we wish to check on
 | 
|---|
 | 290 |  * @return true - entry present, false - only for atom's father or no entry
 | 
|---|
 | 291 |  */
 | 
|---|
 | 292 | bool PdbParser::isPresentadditionalAtomData(unsigned int _id)
 | 
|---|
 | 293 | {
 | 
|---|
 | 294 |   return (additionalAtomData.find(_id) != additionalAtomData.end());
 | 
|---|
 | 295 | }
 | 
|---|
 | 296 | 
 | 
|---|
 | 297 | 
 | 
|---|
| [93fd43e] | 298 | /** Either returns reference to present entry or creates new with default values.
 | 
|---|
 | 299 |  *
 | 
|---|
 | 300 |  * @param _atom atom whose entry we desire
 | 
|---|
 | 301 |  * @return
 | 
|---|
 | 302 |  */
 | 
|---|
 | 303 | PdbAtomInfoContainer& PdbParser::getadditionalAtomData(atom *_atom)
 | 
|---|
 | 304 | {
 | 
|---|
 | 305 |   if (additionalAtomData.find(_atom->getId()) != additionalAtomData.end()) {
 | 
|---|
 | 306 |   } else if (additionalAtomData.find(_atom->father->getId()) != additionalAtomData.end()) {
 | 
|---|
 | 307 |     // use info from direct father
 | 
|---|
 | 308 |     additionalAtomData[_atom->getId()] = additionalAtomData[_atom->father->getId()];
 | 
|---|
 | 309 |   } else if (additionalAtomData.find(_atom->GetTrueFather()->getId()) != additionalAtomData.end()) {
 | 
|---|
 | 310 |     // use info from topmost father
 | 
|---|
 | 311 |     additionalAtomData[_atom->getId()] = additionalAtomData[_atom->GetTrueFather()->getId()];
 | 
|---|
 | 312 |   } else {
 | 
|---|
 | 313 |     // create new entry use default values if nothing else is known
 | 
|---|
 | 314 |     additionalAtomData[_atom->getId()] = defaultAdditionalData;
 | 
|---|
 | 315 |   }
 | 
|---|
 | 316 |   return additionalAtomData[_atom->getId()];
 | 
|---|
 | 317 | }
 | 
|---|
 | 318 | 
 | 
|---|
| [3ae731] | 319 | /**
 | 
|---|
| [4fbca9c] | 320 |  * Writes one line of PDB-formatted data to the provided stream.
 | 
|---|
| [3ae731] | 321 |  *
 | 
|---|
 | 322 |  * \param stream where to write the line to
 | 
|---|
| [bb6193] | 323 |  * \param *currentAtom the atom of which information should be written
 | 
|---|
 | 324 |  * \param AtomNo serial number of atom
 | 
|---|
| [16462f] | 325 |  * \param *name name of atom, i.e. H01
 | 
|---|
 | 326 |  * \param ResidueName Name of molecule
 | 
|---|
| [bb6193] | 327 |  * \param ResidueNo number of residue
 | 
|---|
| [3ae731] | 328 |  */
 | 
|---|
| [16462f] | 329 | void PdbParser::saveLine(
 | 
|---|
 | 330 |     ostream* file,
 | 
|---|
 | 331 |     const PdbAtomInfoContainer &atomInfo)
 | 
|---|
 | 332 | {
 | 
|---|
 | 333 |   *file << setfill(' ') << left << setw(6)
 | 
|---|
 | 334 |       << atomInfo.get<std::string>(PdbKey::token);
 | 
|---|
 | 335 |   *file << setfill(' ') << right << setw(5)
 | 
|---|
 | 336 |       << atomInfo.get<int>(PdbKey::serial); /* atom serial number */
 | 
|---|
 | 337 |   *file << " "; /* char 12 is empty */
 | 
|---|
 | 338 |   *file << setfill(' ') << left << setw(4)
 | 
|---|
 | 339 |       << atomInfo.get<std::string>(PdbKey::name);  /* atom name */
 | 
|---|
 | 340 |   *file << setfill(' ') << left << setw(1)
 | 
|---|
 | 341 |       << atomInfo.get<std::string>(PdbKey::altLoc); /* alternate location/conformation */
 | 
|---|
 | 342 |   *file << setfill(' ') << left << setw(3)
 | 
|---|
 | 343 |       << atomInfo.get<std::string>(PdbKey::resName);  /* residue name */
 | 
|---|
 | 344 |   *file << " "; /* char 21 is empty */
 | 
|---|
 | 345 |   *file << setfill(' ') << left << setw(1)
 | 
|---|
 | 346 |       << atomInfo.get<std::string>(PdbKey::chainID); /* chain identifier */
 | 
|---|
 | 347 |   *file << setfill(' ') << left << setw(4)
 | 
|---|
 | 348 |       << atomInfo.get<int>(PdbKey::resSeq); /* residue sequence number */
 | 
|---|
 | 349 |   *file << setfill(' ') << left << setw(1)
 | 
|---|
 | 350 |       << atomInfo.get<std::string>(PdbKey::iCode); /* iCode */
 | 
|---|
 | 351 |   *file << "   "; /* char 28-30 are empty */
 | 
|---|
 | 352 |   // have the following operate on stringstreams such that format specifiers
 | 
|---|
 | 353 |   // only act on these
 | 
|---|
 | 354 |   for (size_t i=0;i<NDIM;++i) {
 | 
|---|
 | 355 |     stringstream position;
 | 
|---|
 | 356 |     position << fixed << setprecision(3) << showpoint
 | 
|---|
 | 357 |         << atomInfo.get<double>(PositionEnumMap[i]);
 | 
|---|
 | 358 |     *file << setfill(' ') << right << setw(8) << position.str();
 | 
|---|
 | 359 |   }
 | 
|---|
 | 360 |   {
 | 
|---|
 | 361 |     stringstream occupancy;
 | 
|---|
 | 362 |     occupancy << fixed << setprecision(2) << showpoint
 | 
|---|
 | 363 |         << atomInfo.get<double>(PdbKey::occupancy); /* occupancy */
 | 
|---|
 | 364 |     *file << setfill(' ') << right << setw(6) << occupancy.str();
 | 
|---|
| [3ae731] | 365 |   }
 | 
|---|
| [16462f] | 366 |   {
 | 
|---|
 | 367 |     stringstream tempFactor;
 | 
|---|
 | 368 |     tempFactor << fixed << setprecision(2) << showpoint
 | 
|---|
 | 369 |         << atomInfo.get<double>(PdbKey::tempFactor); /* temperature factor */
 | 
|---|
 | 370 |     *file << setfill(' ') << right << setw(6) << tempFactor.str();
 | 
|---|
 | 371 |   }
 | 
|---|
 | 372 |   *file << "          "; /* char 68-76 are empty */
 | 
|---|
 | 373 |   *file << setfill(' ') << right << setw(2) << atomInfo.get<std::string>(PdbKey::element); /* element */
 | 
|---|
 | 374 |   *file << setfill(' ') << right << setw(2) << atomInfo.get<int>(PdbKey::charge); /* charge */
 | 
|---|
| [3ae731] | 375 | 
 | 
|---|
 | 376 |   *file << endl;
 | 
|---|
 | 377 | }
 | 
|---|
 | 378 | 
 | 
|---|
 | 379 | /**
 | 
|---|
 | 380 |  * Writes the neighbor information of one atom to the provided stream.
 | 
|---|
 | 381 |  *
 | 
|---|
| [9d83b6] | 382 |  * Note that ListOfBonds of WorldTime::CurrentTime is used.
 | 
|---|
 | 383 |  *
 | 
|---|
| [473237] | 384 |  * Also, we fill up the CONECT line to extend over 80 chars.
 | 
|---|
 | 385 |  *
 | 
|---|
| [bb6193] | 386 |  * \param *file  where to write neighbor information to
 | 
|---|
 | 387 |  * \param MaxnumberOfNeighbors of neighbors
 | 
|---|
 | 388 |  * \param *currentAtom to the atom of which to take the neighbor information
 | 
|---|
| [3ae731] | 389 |  */
 | 
|---|
| [bb6193] | 390 | void PdbParser::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
 | 
|---|
| [4c1230] | 391 |   int MaxNo = MaxnumberOfNeighbors;
 | 
|---|
| [473237] | 392 |   int charsleft = 80;
 | 
|---|
| [9d83b6] | 393 |   const BondList & ListOfBonds = currentAtom->getListOfBonds();
 | 
|---|
 | 394 |   if (!ListOfBonds.empty()) {
 | 
|---|
 | 395 |     for(BondList::const_iterator currentBond = ListOfBonds.begin(); currentBond != ListOfBonds.end(); ++currentBond) {
 | 
|---|
| [4c1230] | 396 |       if (MaxNo >= MaxnumberOfNeighbors) {
 | 
|---|
 | 397 |         *file << "CONECT";
 | 
|---|
| [16462f] | 398 |         *file << setw(5) << getSerial(currentAtom->getId());
 | 
|---|
| [473237] | 399 |         charsleft = 80-6-5;
 | 
|---|
| [4c1230] | 400 |         MaxNo = 0;
 | 
|---|
| [bb6193] | 401 |       }
 | 
|---|
| [16462f] | 402 |       *file << setw(5) << getSerial((*currentBond)->GetOtherAtom(currentAtom)->getId());
 | 
|---|
| [473237] | 403 |       charsleft -= 5;
 | 
|---|
| [bb6193] | 404 |       MaxNo++;
 | 
|---|
| [473237] | 405 |       if (MaxNo == MaxnumberOfNeighbors) {
 | 
|---|
 | 406 |         for (;charsleft > 0; charsleft--)
 | 
|---|
 | 407 |           *file << ' ';
 | 
|---|
| [4c1230] | 408 |         *file << "\n";
 | 
|---|
| [473237] | 409 |       }
 | 
|---|
| [3ae731] | 410 |     }
 | 
|---|
| [473237] | 411 |     if (MaxNo != MaxnumberOfNeighbors) {
 | 
|---|
 | 412 |       for (;charsleft > 0; charsleft--)
 | 
|---|
 | 413 |         *file << ' ';
 | 
|---|
| [4c1230] | 414 |       *file << "\n";
 | 
|---|
| [473237] | 415 |     }
 | 
|---|
| [3ae731] | 416 |   }
 | 
|---|
 | 417 | }
 | 
|---|
 | 418 | 
 | 
|---|
| [21585f] | 419 | /** Retrieves a value from PdbParser::atomIdMap.
 | 
|---|
 | 420 |  * \param atomid key
 | 
|---|
 | 421 |  * \return value
 | 
|---|
 | 422 |  */
 | 
|---|
| [4fbca9c] | 423 | size_t PdbParser::getSerial(const size_t atomid) const
 | 
|---|
| [21585f] | 424 | {
 | 
|---|
| [8990879] | 425 |   ASSERT(atomIdMap.find(atomid) != atomIdMap.end(),
 | 
|---|
 | 426 |       "PdbParser::getSerial() - atomid "+toString(atomid)+" not present in Map.");
 | 
|---|
| [21585f] | 427 |   return (atomIdMap.find(atomid)->second);
 | 
|---|
 | 428 | }
 | 
|---|
 | 429 | 
 | 
|---|
 | 430 | /** Sets an entry in PdbParser::atomIdMap.
 | 
|---|
 | 431 |  * \param localatomid key
 | 
|---|
 | 432 |  * \param atomid value
 | 
|---|
 | 433 |  * \return true - key not present, false - value present
 | 
|---|
 | 434 |  */
 | 
|---|
| [16462f] | 435 | void PdbParser::setSerial(const size_t localatomid, const size_t atomid)
 | 
|---|
| [21585f] | 436 | {
 | 
|---|
| [4fbca9c] | 437 |   pair<std::map<size_t,size_t>::iterator, bool > inserter;
 | 
|---|
| [16462f] | 438 | //  DoLog(1) && (Log() << Verbose(1) << "PdbParser::setAtomId() - Inserting ("
 | 
|---|
 | 439 | //      << localatomid << " -> " << atomid << ")." << std::endl);
 | 
|---|
| [4fbca9c] | 440 |   inserter = atomIdMap.insert( make_pair(localatomid, atomid) );
 | 
|---|
| [21585f] | 441 |   ASSERT(inserter.second, "PdbParser::setAtomId: atomId already present in Map.");
 | 
|---|
 | 442 | }
 | 
|---|
 | 443 | 
 | 
|---|
| [9dba5f] | 444 | /** Either returns present atom with given id or a newly created one.
 | 
|---|
 | 445 |  *
 | 
|---|
 | 446 |  * @param id_string
 | 
|---|
 | 447 |  * @return
 | 
|---|
 | 448 |  */
 | 
|---|
 | 449 | atom* PdbParser::getAtomToParse(std::string id_string) const
 | 
|---|
 | 450 | {
 | 
|---|
 | 451 |   // get the local ID
 | 
|---|
 | 452 |   ConvertTo<int> toInt;
 | 
|---|
 | 453 |   unsigned int AtomID = toInt(id_string);
 | 
|---|
 | 454 |   LOG(4, "INFO: Local id is "+toString(AtomID)+".");
 | 
|---|
 | 455 |   // get the atomic ID if present
 | 
|---|
 | 456 |   atom* newAtom = NULL;
 | 
|---|
 | 457 |   if (atomIdMap.count((size_t)AtomID)) {
 | 
|---|
 | 458 |     std::map<size_t, size_t>::const_iterator iter = atomIdMap.find(AtomID);
 | 
|---|
 | 459 |     AtomID = iter->second;
 | 
|---|
 | 460 |     LOG(4, "INFO: Global id present as " << AtomID << ".");
 | 
|---|
 | 461 |     // check if atom exists
 | 
|---|
 | 462 |     newAtom = World::getInstance().getAtom(AtomById(AtomID));
 | 
|---|
 | 463 |     LOG(5, "INFO: Listing all present atoms with id.");
 | 
|---|
 | 464 |     BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms())
 | 
|---|
 | 465 |       LOG(5, "INFO: " << *_atom << " with id " << _atom->getId());
 | 
|---|
 | 466 |   }
 | 
|---|
 | 467 |   // if not exists, create
 | 
|---|
 | 468 |   if (newAtom == NULL) {
 | 
|---|
 | 469 |     newAtom = World::getInstance().createAtom();
 | 
|---|
 | 470 |     LOG(4, "INFO: No association to global id present, creating atom.");
 | 
|---|
 | 471 |   } else {
 | 
|---|
 | 472 |     LOG(4, "INFO: Existing atom found: " << *newAtom << ".");
 | 
|---|
 | 473 |   }
 | 
|---|
 | 474 |   return newAtom;
 | 
|---|
 | 475 | }
 | 
|---|
 | 476 | 
 | 
|---|
 | 477 | void PdbParser::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const
 | 
|---|
 | 478 | {
 | 
|---|
 | 479 |   LOG(4,"INFO: Parsing token from "+line.substr(0,6)+".");
 | 
|---|
 | 480 |   atomInfo.set(PdbKey::token, line.substr(0,6));
 | 
|---|
 | 481 |   LOG(4,"INFO: Parsing serial from "+line.substr(6,5)+".");
 | 
|---|
 | 482 |   atomInfo.set(PdbKey::serial, line.substr(6,5));
 | 
|---|
 | 483 | 
 | 
|---|
 | 484 |   LOG(4,"INFO: Parsing name from "+line.substr(12,4)+".");
 | 
|---|
 | 485 |   atomInfo.set(PdbKey::name, line.substr(12,4));
 | 
|---|
 | 486 |   LOG(4,"INFO: Parsing altLoc from "+line.substr(16,1)+".");
 | 
|---|
 | 487 |   atomInfo.set(PdbKey::altLoc, line.substr(16,1));
 | 
|---|
 | 488 |   LOG(4,"INFO: Parsing resName from "+line.substr(17,3)+".");
 | 
|---|
 | 489 |   atomInfo.set(PdbKey::resName, line.substr(17,3));
 | 
|---|
 | 490 |   LOG(4,"INFO: Parsing chainID from "+line.substr(21,1)+".");
 | 
|---|
 | 491 |   atomInfo.set(PdbKey::chainID, line.substr(21,1));
 | 
|---|
 | 492 |   LOG(4,"INFO: Parsing resSeq from "+line.substr(22,4)+".");
 | 
|---|
 | 493 |   atomInfo.set(PdbKey::resSeq, line.substr(22,4));
 | 
|---|
 | 494 |   LOG(4,"INFO: Parsing iCode from "+line.substr(26,1)+".");
 | 
|---|
 | 495 |   atomInfo.set(PdbKey::iCode, line.substr(26,1));
 | 
|---|
 | 496 | 
 | 
|---|
 | 497 |   LOG(4,"INFO: Parsing occupancy from "+line.substr(54,6)+".");
 | 
|---|
 | 498 |   atomInfo.set(PdbKey::occupancy, line.substr(54,6));
 | 
|---|
 | 499 |   LOG(4,"INFO: Parsing tempFactor from "+line.substr(60,6)+".");
 | 
|---|
 | 500 |   atomInfo.set(PdbKey::tempFactor, line.substr(60,6));
 | 
|---|
 | 501 |   LOG(4,"INFO: Parsing charge from "+line.substr(78,2)+".");
 | 
|---|
 | 502 |   atomInfo.set(PdbKey::charge, line.substr(78,2));
 | 
|---|
 | 503 |   LOG(4,"INFO: Parsing element from "+line.substr(76,2)+".");
 | 
|---|
 | 504 |   atomInfo.set(PdbKey::element, line.substr(76,2));
 | 
|---|
 | 505 | }
 | 
|---|
 | 506 | 
 | 
|---|
| [4fbca9c] | 507 | /** Parse an ATOM line from a PDB file.
 | 
|---|
 | 508 |  *
 | 
|---|
 | 509 |  * Reads one data line of a pdstatus file and interprets it according to the
 | 
|---|
 | 510 |  * specifications of the PDB 3.2 format: http://www.wwpdb.org/docs.html
 | 
|---|
 | 511 |  *
 | 
|---|
 | 512 |  *  A new atom is created and filled with available information, non-
 | 
|---|
 | 513 |  *  standard information is placed in additionalAtomData at the atom's id.
 | 
|---|
| [3ae731] | 514 |  *
 | 
|---|
| [b0a2e3] | 515 |  * \param _step time step to use
 | 
|---|
| [3ae731] | 516 |  * \param line to parse as an atom
 | 
|---|
| [4fbca9c] | 517 |  * \param newmol molecule to add parsed atoms to
 | 
|---|
| [3ae731] | 518 |  */
 | 
|---|
| [b0a2e3] | 519 | void PdbParser::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) {
 | 
|---|
| [4fbca9c] | 520 |   vector<string>::iterator it;
 | 
|---|
| [9dba5f] | 521 | 
 | 
|---|
 | 522 |   atom* newAtom = getAtomToParse(line.substr(6,5));
 | 
|---|
 | 523 |   LOG(3,"INFO: Parsing END entry or empty line.");
 | 
|---|
 | 524 |   bool FirstTimestep = isPresentadditionalAtomData(newAtom->getId()) ? false : true;
 | 
|---|
| [b0a2e3] | 525 |   ASSERT((FirstTimestep && (_step == 0)) || (!FirstTimestep && (_step !=0)),
 | 
|---|
 | 526 |       "PdbParser::readAtomDataLine() - logig mismatch between FirstTimestep and step == 0.");
 | 
|---|
| [9dba5f] | 527 |   if (FirstTimestep) {
 | 
|---|
 | 528 |     LOG(3,"INFO: Parsing new atom.");
 | 
|---|
 | 529 |   } else {
 | 
|---|
 | 530 |     LOG(3,"INFO: Parsing present atom "+toString(*newAtom)+".");
 | 
|---|
 | 531 |   }
 | 
|---|
| [93fd43e] | 532 |   PdbAtomInfoContainer &atomInfo = getadditionalAtomData(newAtom);
 | 
|---|
| [9dba5f] | 533 |   LOG(4,"INFO: Information in container is "+toString(atomInfo)+".");
 | 
|---|
 | 534 | 
 | 
|---|
| [4fbca9c] | 535 |   string word;
 | 
|---|
 | 536 |   ConvertTo<size_t> toSize_t;
 | 
|---|
 | 537 | 
 | 
|---|
| [9dba5f] | 538 |   // assign highest+1 instead, but then beware of CONECT entries! Another map needed!
 | 
|---|
| [4fbca9c] | 539 | //  if (!Inserter.second) {
 | 
|---|
 | 540 | //    const size_t id = (*SerialSet.rbegin())+1;
 | 
|---|
 | 541 | //    SerialSet.insert(id);
 | 
|---|
 | 542 | //    atomInfo.set(PdbKey::serial, toString(id));
 | 
|---|
 | 543 | //    DoeLog(2) && (eLog() << Verbose(2)
 | 
|---|
| [16462f] | 544 | //        << "Serial " << atomInfo.get<std::string>(PdbKey::serial) << " already present, "
 | 
|---|
| [4fbca9c] | 545 | //        << "assigning " << toString(id) << " instead." << std::endl);
 | 
|---|
| [bb6193] | 546 | //  }
 | 
|---|
| [4fbca9c] | 547 | 
 | 
|---|
 | 548 |   // check whether serial exists, if so, assign next available
 | 
|---|
 | 549 | 
 | 
|---|
 | 550 | //  DoLog(2) && (Log() << Verbose(2) << "Split line:"
 | 
|---|
 | 551 | //      << line.substr(6,5) << "|"
 | 
|---|
 | 552 | //      << line.substr(12,4) << "|"
 | 
|---|
 | 553 | //      << line.substr(16,1) << "|"
 | 
|---|
 | 554 | //      << line.substr(17,3) << "|"
 | 
|---|
 | 555 | //      << line.substr(21,1) << "|"
 | 
|---|
 | 556 | //      << line.substr(22,4) << "|"
 | 
|---|
 | 557 | //      << line.substr(26,1) << "|"
 | 
|---|
 | 558 | //      << line.substr(30,8) << "|"
 | 
|---|
 | 559 | //      << line.substr(38,8) << "|"
 | 
|---|
 | 560 | //      << line.substr(46,8) << "|"
 | 
|---|
 | 561 | //      << line.substr(54,6) << "|"
 | 
|---|
 | 562 | //      << line.substr(60,6) << "|"
 | 
|---|
 | 563 | //      << line.substr(76,2) << "|"
 | 
|---|
 | 564 | //      << line.substr(78,2) << std::endl);
 | 
|---|
 | 565 | 
 | 
|---|
| [9dba5f] | 566 |   if (FirstTimestep) {
 | 
|---|
 | 567 |     // first time step
 | 
|---|
 | 568 |     // then fill info container
 | 
|---|
 | 569 |     readPdbAtomInfoContainer(atomInfo, line);
 | 
|---|
 | 570 |     // set the serial
 | 
|---|
 | 571 |     std::pair< std::set<size_t>::const_iterator, bool> Inserter =
 | 
|---|
 | 572 |       SerialSet.insert(toSize_t(atomInfo.get<std::string>(PdbKey::serial)));
 | 
|---|
 | 573 |     ASSERT(Inserter.second,
 | 
|---|
 | 574 |         "PdbParser::readAtomDataLine() - ATOM contains entry with serial "
 | 
|---|
 | 575 |         +atomInfo.get<std::string>(PdbKey::serial)+" already present!");
 | 
|---|
 | 576 |     setSerial(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId());
 | 
|---|
 | 577 |     // set position
 | 
|---|
 | 578 |     Vector tempVector;
 | 
|---|
 | 579 |     LOG(4,"INFO: Parsing position from ("
 | 
|---|
 | 580 |         +line.substr(30,8)+","
 | 
|---|
 | 581 |         +line.substr(38,8)+","
 | 
|---|
 | 582 |         +line.substr(46,8)+").");
 | 
|---|
 | 583 |     PdbAtomInfoContainer::ScanKey(tempVector[0], line.substr(30,8));
 | 
|---|
 | 584 |     PdbAtomInfoContainer::ScanKey(tempVector[1], line.substr(38,8));
 | 
|---|
 | 585 |     PdbAtomInfoContainer::ScanKey(tempVector[2], line.substr(46,8));
 | 
|---|
 | 586 |     newAtom->setPosition(tempVector);
 | 
|---|
 | 587 |     // set element
 | 
|---|
| [8990879] | 588 |     std::string value = atomInfo.get<std::string>(PdbKey::element);
 | 
|---|
 | 589 |     // make second character lower case if not
 | 
|---|
 | 590 |     if ((value[1] >= 'A') && (value[1] <= 'Z'))
 | 
|---|
 | 591 |       value[1] = (value[1] - 'A') + 'a';
 | 
|---|
| [9dba5f] | 592 |     const element *elem = World::getInstance().getPeriode()
 | 
|---|
| [8990879] | 593 |         ->FindElement(value);
 | 
|---|
| [9dba5f] | 594 |     ASSERT(elem != NULL,
 | 
|---|
 | 595 |         "PdbParser::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!");
 | 
|---|
 | 596 |     newAtom->setType(elem);
 | 
|---|
 | 597 | 
 | 
|---|
 | 598 |     if (newmol != NULL)
 | 
|---|
 | 599 |       newmol->AddAtom(newAtom);
 | 
|---|
 | 600 |   } else {
 | 
|---|
 | 601 |     // not first time step
 | 
|---|
 | 602 |     // then parse into different container
 | 
|---|
 | 603 |     PdbAtomInfoContainer consistencyInfo;
 | 
|---|
 | 604 |     readPdbAtomInfoContainer(consistencyInfo, line);
 | 
|---|
 | 605 |     // then check additional info for consistency
 | 
|---|
 | 606 |     ASSERT(atomInfo.get<std::string>(PdbKey::token) == consistencyInfo.get<std::string>(PdbKey::token),
 | 
|---|
 | 607 |         "PdbParser::readAtomDataLine() - difference in token on multiple time step for atom with id "
 | 
|---|
 | 608 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 609 |     ASSERT(atomInfo.get<std::string>(PdbKey::name) == consistencyInfo.get<std::string>(PdbKey::name),
 | 
|---|
 | 610 |         "PdbParser::readAtomDataLine() - difference in name on multiple time step for atom with id "
 | 
|---|
 | 611 |         +atomInfo.get<std::string>(PdbKey::serial)+":"
 | 
|---|
 | 612 |         +atomInfo.get<std::string>(PdbKey::name)+"!="
 | 
|---|
 | 613 |         +consistencyInfo.get<std::string>(PdbKey::name)+".");
 | 
|---|
 | 614 |     ASSERT(atomInfo.get<std::string>(PdbKey::altLoc) == consistencyInfo.get<std::string>(PdbKey::altLoc),
 | 
|---|
 | 615 |         "PdbParser::readAtomDataLine() - difference in altLoc on multiple time step for atom with id "
 | 
|---|
 | 616 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 617 |     ASSERT(atomInfo.get<std::string>(PdbKey::resName) == consistencyInfo.get<std::string>(PdbKey::resName),
 | 
|---|
 | 618 |         "PdbParser::readAtomDataLine() - difference in resName on multiple time step for atom with id "
 | 
|---|
 | 619 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 620 |     ASSERT(atomInfo.get<std::string>(PdbKey::chainID) == consistencyInfo.get<std::string>(PdbKey::chainID),
 | 
|---|
 | 621 |         "PdbParser::readAtomDataLine() - difference in chainID on multiple time step for atom with id "
 | 
|---|
 | 622 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 623 |     ASSERT(atomInfo.get<std::string>(PdbKey::resSeq) == consistencyInfo.get<std::string>(PdbKey::resSeq),
 | 
|---|
 | 624 |         "PdbParser::readAtomDataLine() - difference in resSeq on multiple time step for atom with id "
 | 
|---|
 | 625 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 626 |     ASSERT(atomInfo.get<std::string>(PdbKey::iCode) == consistencyInfo.get<std::string>(PdbKey::iCode),
 | 
|---|
 | 627 |         "PdbParser::readAtomDataLine() - difference in iCode on multiple time step for atom with id "
 | 
|---|
 | 628 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 629 |     ASSERT(atomInfo.get<std::string>(PdbKey::occupancy) == consistencyInfo.get<std::string>(PdbKey::occupancy),
 | 
|---|
 | 630 |         "PdbParser::readAtomDataLine() - difference in occupancy on multiple time step for atom with id "
 | 
|---|
 | 631 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 632 |     ASSERT(atomInfo.get<std::string>(PdbKey::tempFactor) == consistencyInfo.get<std::string>(PdbKey::tempFactor),
 | 
|---|
 | 633 |         "PdbParser::readAtomDataLine() - difference in tempFactor on multiple time step for atom with id "
 | 
|---|
 | 634 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 635 |     ASSERT(atomInfo.get<std::string>(PdbKey::charge) == consistencyInfo.get<std::string>(PdbKey::charge),
 | 
|---|
 | 636 |         "PdbParser::readAtomDataLine() - difference in charge on multiple time step for atom with id "
 | 
|---|
 | 637 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 638 |     ASSERT(atomInfo.get<std::string>(PdbKey::element) == consistencyInfo.get<std::string>(PdbKey::element),
 | 
|---|
 | 639 |         "PdbParser::readAtomDataLine() - difference in element on multiple time step for atom with id "
 | 
|---|
 | 640 |         +atomInfo.get<std::string>(PdbKey::serial)+"!");
 | 
|---|
 | 641 |     // and parse in trajectory
 | 
|---|
 | 642 |     Vector tempVector;
 | 
|---|
 | 643 |     LOG(4,"INFO: Parsing trajectory position from ("
 | 
|---|
 | 644 |         +line.substr(30,8)+","
 | 
|---|
 | 645 |         +line.substr(38,8)+","
 | 
|---|
 | 646 |         +line.substr(46,8)+").");
 | 
|---|
 | 647 |     PdbAtomInfoContainer::ScanKey(tempVector[0], line.substr(30,8));
 | 
|---|
 | 648 |     PdbAtomInfoContainer::ScanKey(tempVector[1], line.substr(38,8));
 | 
|---|
 | 649 |     PdbAtomInfoContainer::ScanKey(tempVector[2], line.substr(46,8));
 | 
|---|
| [b0a2e3] | 650 |     LOG(4,"INFO: Adding trajectory point to time step "+toString(_step)+".");
 | 
|---|
| [9dba5f] | 651 |     // and set position at new time step
 | 
|---|
| [b0a2e3] | 652 |     newAtom->setPositionAtStep(_step, tempVector);
 | 
|---|
| [9dba5f] | 653 |   }
 | 
|---|
 | 654 | 
 | 
|---|
| [4fbca9c] | 655 | 
 | 
|---|
 | 656 | //  printAtomInfo(newAtom);
 | 
|---|
| [3ae731] | 657 | }
 | 
|---|
 | 658 | 
 | 
|---|
| [4fbca9c] | 659 | /** Prints all PDB-specific information known about an atom.
 | 
|---|
| [3ae731] | 660 |  *
 | 
|---|
 | 661 |  */
 | 
|---|
| [4fbca9c] | 662 | void PdbParser::printAtomInfo(const atom * const newAtom) const
 | 
|---|
 | 663 | {
 | 
|---|
 | 664 |   const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist
 | 
|---|
 | 665 | 
 | 
|---|
 | 666 |   DoLog(1) && (Log() << Verbose(1) << "We know about atom " << newAtom->getId() << ":" << std::endl);
 | 
|---|
| [16462f] | 667 |   DoLog(1) && (Log() << Verbose(1) << "\ttoken is " << atomInfo.get<std::string>(PdbKey::token) << std::endl);
 | 
|---|
 | 668 |   DoLog(1) && (Log() << Verbose(1) << "\tserial is " << atomInfo.get<int>(PdbKey::serial) << std::endl);
 | 
|---|
 | 669 |   DoLog(1) && (Log() << Verbose(1) << "\tname is " << atomInfo.get<std::string>(PdbKey::name) << std::endl);
 | 
|---|
 | 670 |   DoLog(1) && (Log() << Verbose(1) << "\taltLoc is " << atomInfo.get<std::string>(PdbKey::altLoc) << std::endl);
 | 
|---|
 | 671 |   DoLog(1) && (Log() << Verbose(1) << "\tresName is " << atomInfo.get<std::string>(PdbKey::resName) << std::endl);
 | 
|---|
 | 672 |   DoLog(1) && (Log() << Verbose(1) << "\tchainID is " << atomInfo.get<std::string>(PdbKey::chainID) << std::endl);
 | 
|---|
 | 673 |   DoLog(1) && (Log() << Verbose(1) << "\tresSeq is " << atomInfo.get<int>(PdbKey::resSeq) << std::endl);
 | 
|---|
 | 674 |   DoLog(1) && (Log() << Verbose(1) << "\tiCode is " << atomInfo.get<std::string>(PdbKey::iCode) << std::endl);
 | 
|---|
 | 675 |   DoLog(1) && (Log() << Verbose(1) << "\tX is " << atomInfo.get<double>(PdbKey::X) << std::endl);
 | 
|---|
 | 676 |   DoLog(1) && (Log() << Verbose(1) << "\tY is " << atomInfo.get<double>(PdbKey::Y) << std::endl);
 | 
|---|
 | 677 |   DoLog(1) && (Log() << Verbose(1) << "\tZ is " << atomInfo.get<double>(PdbKey::Z) << std::endl);
 | 
|---|
 | 678 |   DoLog(1) && (Log() << Verbose(1) << "\toccupancy is " << atomInfo.get<double>(PdbKey::occupancy) << std::endl);
 | 
|---|
 | 679 |   DoLog(1) && (Log() << Verbose(1) << "\ttempFactor is " << atomInfo.get<double>(PdbKey::tempFactor) << std::endl);
 | 
|---|
| [4fbca9c] | 680 |   DoLog(1) && (Log() << Verbose(1) << "\telement is '" << *(newAtom->getType()) << "'" << std::endl);
 | 
|---|
| [16462f] | 681 |   DoLog(1) && (Log() << Verbose(1) << "\tcharge is " << atomInfo.get<int>(PdbKey::charge) << std::endl);
 | 
|---|
| [3ae731] | 682 | }
 | 
|---|
 | 683 | 
 | 
|---|
 | 684 | /**
 | 
|---|
| [4fbca9c] | 685 |  * Reads neighbor information for one atom from the input.
 | 
|---|
 | 686 |  *
 | 
|---|
| [b0a2e3] | 687 |  * \param _step time step to use
 | 
|---|
| [4fbca9c] | 688 |  * \param line to parse as an atom
 | 
|---|
| [3ae731] | 689 |  */
 | 
|---|
| [b0a2e3] | 690 | void PdbParser::readNeighbors(const unsigned int _step, std::string &line)
 | 
|---|
| [4fbca9c] | 691 | {
 | 
|---|
 | 692 |   const size_t length = line.length();
 | 
|---|
 | 693 |   std::list<size_t> ListOfNeighbors;
 | 
|---|
 | 694 |   ConvertTo<size_t> toSize_t;
 | 
|---|
 | 695 | 
 | 
|---|
 | 696 |   // obtain neighbours
 | 
|---|
 | 697 |   // show split line for debugging
 | 
|---|
 | 698 |   string output;
 | 
|---|
 | 699 |   ASSERT(length >=16,
 | 
|---|
 | 700 |       "PdbParser::readNeighbors() - CONECT entry has not enough entries: "+line+"!");
 | 
|---|
| [473237] | 701 |   output = "Split line:|";
 | 
|---|
 | 702 |   output += line.substr(6,5) + "|";
 | 
|---|
| [4fbca9c] | 703 |   const size_t id = toSize_t(line.substr(6,5));
 | 
|---|
 | 704 |   for (size_t index = 11; index <= 26; index+=5) {
 | 
|---|
 | 705 |     if (index+5 <= length) {
 | 
|---|
| [473237] | 706 |       output += line.substr(index,5) + "|";
 | 
|---|
 | 707 |       // search for digits
 | 
|---|
 | 708 |       int otherid = -1;
 | 
|---|
 | 709 |       PdbAtomInfoContainer::ScanKey(otherid, line.substr(index,5));
 | 
|---|
 | 710 |       if (otherid >= 0)
 | 
|---|
 | 711 |         ListOfNeighbors.push_back((size_t)otherid);
 | 
|---|
| [4fbca9c] | 712 |     } else  {
 | 
|---|
 | 713 |       break;
 | 
|---|
 | 714 |     }
 | 
|---|
 | 715 |   }
 | 
|---|
| [473237] | 716 |   LOG(4, output);
 | 
|---|
| [4fbca9c] | 717 | 
 | 
|---|
 | 718 |   // add neighbours
 | 
|---|
| [16462f] | 719 |   atom *_atom = World::getInstance().getAtom(AtomById(getSerial(id)));
 | 
|---|
| [473237] | 720 |   LOG(2, "STATUS: Atom " << _atom->getId() << " gets " << ListOfNeighbors.size() << " more neighbours.");
 | 
|---|
| [4fbca9c] | 721 |   for (std::list<size_t>::const_iterator iter = ListOfNeighbors.begin();
 | 
|---|
 | 722 |       iter != ListOfNeighbors.end();
 | 
|---|
 | 723 |       ++iter) {
 | 
|---|
| [16462f] | 724 |     atom * const _Otheratom = World::getInstance().getAtom(AtomById(getSerial(*iter)));
 | 
|---|
| [473237] | 725 |     LOG(3, "INFO: Adding Bond (" << *_atom << "," << *_Otheratom << ")");
 | 
|---|
| [b0a2e3] | 726 |     _atom->addBond(_step, _Otheratom);
 | 
|---|
| [4fbca9c] | 727 |   }
 | 
|---|
| [3ae731] | 728 | }
 | 
|---|
 | 729 | 
 | 
|---|
 | 730 | /**
 | 
|---|
 | 731 |  * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
 | 
|---|
 | 732 |  * IDs of the input string will be replaced; expected separating characters are
 | 
|---|
 | 733 |  * "-" and ",".
 | 
|---|
 | 734 |  *
 | 
|---|
 | 735 |  * \param string in which atom IDs should be adapted
 | 
|---|
 | 736 |  *
 | 
|---|
 | 737 |  * \return input string with modified atom IDs
 | 
|---|
 | 738 |  */
 | 
|---|
| [4fbca9c] | 739 | //string PdbParser::adaptIdDependentDataString(string data) {
 | 
|---|
| [bb6193] | 740 | //  // there might be no IDs
 | 
|---|
 | 741 | //  if (data == "-") {
 | 
|---|
 | 742 | //    return "-";
 | 
|---|
 | 743 | //  }
 | 
|---|
 | 744 | //
 | 
|---|
 | 745 | //  char separator;
 | 
|---|
 | 746 | //  int id;
 | 
|---|
 | 747 | //  stringstream line, result;
 | 
|---|
 | 748 | //  line << data;
 | 
|---|
 | 749 | //
 | 
|---|
 | 750 | //  line >> id;
 | 
|---|
 | 751 | //  result << atomIdMap[id];
 | 
|---|
 | 752 | //  while (line.good()) {
 | 
|---|
 | 753 | //    line >> separator >> id;
 | 
|---|
 | 754 | //    result << separator << atomIdMap[id];
 | 
|---|
 | 755 | //  }
 | 
|---|
 | 756 | //
 | 
|---|
 | 757 | //  return result.str();
 | 
|---|
| [4fbca9c] | 758 | //  return "";
 | 
|---|
 | 759 | //}
 | 
|---|
| [3ae731] | 760 | 
 | 
|---|
 | 761 | 
 | 
|---|
| [4fbca9c] | 762 | bool PdbParser::operator==(const PdbParser& b) const
 | 
|---|
 | 763 | {
 | 
|---|
 | 764 |   bool status = true;
 | 
|---|
 | 765 |   World::AtomComposite atoms = World::getInstance().getAllAtoms();
 | 
|---|
 | 766 |   for (World::AtomComposite::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
 | 
|---|
 | 767 |     if ((additionalAtomData.find((*iter)->getId()) != additionalAtomData.end())
 | 
|---|
 | 768 |         && (b.additionalAtomData.find((*iter)->getId()) != b.additionalAtomData.end())) {
 | 
|---|
 | 769 |       const PdbAtomInfoContainer &atomInfo = additionalAtomData.at((*iter)->getId());
 | 
|---|
 | 770 |       const PdbAtomInfoContainer &OtheratomInfo = b.additionalAtomData.at((*iter)->getId());
 | 
|---|
 | 771 | 
 | 
|---|
| [16462f] | 772 |       status = status && (atomInfo.get<std::string>(PdbKey::serial) == OtheratomInfo.get<std::string>(PdbKey::serial));
 | 
|---|
| [4fbca9c] | 773 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in serials!" << std::endl);
 | 
|---|
| [16462f] | 774 |       status = status && (atomInfo.get<std::string>(PdbKey::name) == OtheratomInfo.get<std::string>(PdbKey::name));
 | 
|---|
| [4fbca9c] | 775 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in names!" << std::endl);
 | 
|---|
| [16462f] | 776 |       status = status && (atomInfo.get<std::string>(PdbKey::altLoc) == OtheratomInfo.get<std::string>(PdbKey::altLoc));
 | 
|---|
 | 777 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in altLocs!" << std::endl);
 | 
|---|
 | 778 |       status = status && (atomInfo.get<std::string>(PdbKey::resName) == OtheratomInfo.get<std::string>(PdbKey::resName));
 | 
|---|
| [4fbca9c] | 779 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resNames!" << std::endl);
 | 
|---|
| [16462f] | 780 |       status = status && (atomInfo.get<std::string>(PdbKey::chainID) == OtheratomInfo.get<std::string>(PdbKey::chainID));
 | 
|---|
| [4fbca9c] | 781 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in chainIDs!" << std::endl);
 | 
|---|
| [16462f] | 782 |       status = status && (atomInfo.get<std::string>(PdbKey::resSeq) == OtheratomInfo.get<std::string>(PdbKey::resSeq));
 | 
|---|
| [4fbca9c] | 783 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resSeqs!" << std::endl);
 | 
|---|
| [16462f] | 784 |       status = status && (atomInfo.get<std::string>(PdbKey::iCode) == OtheratomInfo.get<std::string>(PdbKey::iCode));
 | 
|---|
| [4fbca9c] | 785 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in iCodes!" << std::endl);
 | 
|---|
| [16462f] | 786 |       status = status && (atomInfo.get<std::string>(PdbKey::occupancy) == OtheratomInfo.get<std::string>(PdbKey::occupancy));
 | 
|---|
| [4fbca9c] | 787 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in occupancies!" << std::endl);
 | 
|---|
| [16462f] | 788 |       status = status && (atomInfo.get<std::string>(PdbKey::tempFactor) == OtheratomInfo.get<std::string>(PdbKey::tempFactor));
 | 
|---|
| [4fbca9c] | 789 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in tempFactors!" << std::endl);
 | 
|---|
| [16462f] | 790 |       status = status && (atomInfo.get<std::string>(PdbKey::charge) == OtheratomInfo.get<std::string>(PdbKey::charge));
 | 
|---|
| [4fbca9c] | 791 |       if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in charges!" << std::endl);
 | 
|---|
 | 792 |     }
 | 
|---|
| [3ae731] | 793 |   }
 | 
|---|
 | 794 | 
 | 
|---|
| [4fbca9c] | 795 |   return status;
 | 
|---|
| [3ae731] | 796 | }
 | 
|---|
 | 797 | 
 | 
|---|