[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 |
|
---|
[6bc86c] | 287 | /** Add default info, when new atom is added to World.
|
---|
| 288 | *
|
---|
| 289 | * @param id of atom
|
---|
| 290 | */
|
---|
| 291 | void PdbParser::AtomInserted(atomId_t id)
|
---|
| 292 | {
|
---|
| 293 | //LOG(3, "PdbParser::AtomInserted() - notified of atom " << id << "'s insertion.");
|
---|
| 294 | ASSERT(!isPresentadditionalAtomData(id),
|
---|
| 295 | "PdbParser::AtomInserted() - additionalAtomData already present for newly added atom "
|
---|
| 296 | +toString(id)+".");
|
---|
| 297 | // don't insert here as this is our check whether we are in the first time step
|
---|
| 298 | //additionalAtomData.insert( std::make_pair(id, defaultAdditionalData) );
|
---|
| 299 | //SerialSet.insert(id);
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | /** Remove additional AtomData info, when atom has been removed from World.
|
---|
| 303 | *
|
---|
| 304 | * @param id of atom
|
---|
| 305 | */
|
---|
| 306 | void PdbParser::AtomRemoved(atomId_t id)
|
---|
| 307 | {
|
---|
| 308 | //LOG(3, "PdbParser::AtomRemoved() - notified of atom " << id << "'s removal.");
|
---|
| 309 | std::map<size_t, PdbAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
|
---|
| 310 | // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence
|
---|
| 311 | // ASSERT(iter != additionalAtomData.end(),
|
---|
| 312 | // "PdbParser::AtomRemoved() - additionalAtomData is not present for atom "
|
---|
| 313 | // +toString(id)+" to remove.");
|
---|
| 314 | if (iter != additionalAtomData.end()) {
|
---|
| 315 | ConvertTo<size_t> toSize_t;
|
---|
| 316 | SerialSet.erase(toSize_t((iter->second).get<std::string>(PdbKey::serial)));
|
---|
| 317 | additionalAtomData.erase(iter);
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 |
|
---|
[9dba5f] | 322 | /** Checks whether there is an entry for the given atom's \a _id.
|
---|
| 323 | *
|
---|
| 324 | * @param _id atom's id we wish to check on
|
---|
| 325 | * @return true - entry present, false - only for atom's father or no entry
|
---|
| 326 | */
|
---|
| 327 | bool PdbParser::isPresentadditionalAtomData(unsigned int _id)
|
---|
| 328 | {
|
---|
| 329 | return (additionalAtomData.find(_id) != additionalAtomData.end());
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 |
|
---|
[93fd43e] | 333 | /** Either returns reference to present entry or creates new with default values.
|
---|
| 334 | *
|
---|
| 335 | * @param _atom atom whose entry we desire
|
---|
| 336 | * @return
|
---|
| 337 | */
|
---|
| 338 | PdbAtomInfoContainer& PdbParser::getadditionalAtomData(atom *_atom)
|
---|
| 339 | {
|
---|
| 340 | if (additionalAtomData.find(_atom->getId()) != additionalAtomData.end()) {
|
---|
| 341 | } else if (additionalAtomData.find(_atom->father->getId()) != additionalAtomData.end()) {
|
---|
| 342 | // use info from direct father
|
---|
| 343 | additionalAtomData[_atom->getId()] = additionalAtomData[_atom->father->getId()];
|
---|
| 344 | } else if (additionalAtomData.find(_atom->GetTrueFather()->getId()) != additionalAtomData.end()) {
|
---|
| 345 | // use info from topmost father
|
---|
| 346 | additionalAtomData[_atom->getId()] = additionalAtomData[_atom->GetTrueFather()->getId()];
|
---|
| 347 | } else {
|
---|
| 348 | // create new entry use default values if nothing else is known
|
---|
| 349 | additionalAtomData[_atom->getId()] = defaultAdditionalData;
|
---|
| 350 | }
|
---|
| 351 | return additionalAtomData[_atom->getId()];
|
---|
| 352 | }
|
---|
| 353 |
|
---|
[3ae731] | 354 | /**
|
---|
[4fbca9c] | 355 | * Writes one line of PDB-formatted data to the provided stream.
|
---|
[3ae731] | 356 | *
|
---|
| 357 | * \param stream where to write the line to
|
---|
[bb6193] | 358 | * \param *currentAtom the atom of which information should be written
|
---|
| 359 | * \param AtomNo serial number of atom
|
---|
[16462f] | 360 | * \param *name name of atom, i.e. H01
|
---|
| 361 | * \param ResidueName Name of molecule
|
---|
[bb6193] | 362 | * \param ResidueNo number of residue
|
---|
[3ae731] | 363 | */
|
---|
[16462f] | 364 | void PdbParser::saveLine(
|
---|
| 365 | ostream* file,
|
---|
| 366 | const PdbAtomInfoContainer &atomInfo)
|
---|
| 367 | {
|
---|
| 368 | *file << setfill(' ') << left << setw(6)
|
---|
| 369 | << atomInfo.get<std::string>(PdbKey::token);
|
---|
| 370 | *file << setfill(' ') << right << setw(5)
|
---|
| 371 | << atomInfo.get<int>(PdbKey::serial); /* atom serial number */
|
---|
| 372 | *file << " "; /* char 12 is empty */
|
---|
| 373 | *file << setfill(' ') << left << setw(4)
|
---|
| 374 | << atomInfo.get<std::string>(PdbKey::name); /* atom name */
|
---|
| 375 | *file << setfill(' ') << left << setw(1)
|
---|
| 376 | << atomInfo.get<std::string>(PdbKey::altLoc); /* alternate location/conformation */
|
---|
| 377 | *file << setfill(' ') << left << setw(3)
|
---|
| 378 | << atomInfo.get<std::string>(PdbKey::resName); /* residue name */
|
---|
| 379 | *file << " "; /* char 21 is empty */
|
---|
| 380 | *file << setfill(' ') << left << setw(1)
|
---|
| 381 | << atomInfo.get<std::string>(PdbKey::chainID); /* chain identifier */
|
---|
| 382 | *file << setfill(' ') << left << setw(4)
|
---|
| 383 | << atomInfo.get<int>(PdbKey::resSeq); /* residue sequence number */
|
---|
| 384 | *file << setfill(' ') << left << setw(1)
|
---|
| 385 | << atomInfo.get<std::string>(PdbKey::iCode); /* iCode */
|
---|
| 386 | *file << " "; /* char 28-30 are empty */
|
---|
| 387 | // have the following operate on stringstreams such that format specifiers
|
---|
| 388 | // only act on these
|
---|
| 389 | for (size_t i=0;i<NDIM;++i) {
|
---|
| 390 | stringstream position;
|
---|
| 391 | position << fixed << setprecision(3) << showpoint
|
---|
| 392 | << atomInfo.get<double>(PositionEnumMap[i]);
|
---|
| 393 | *file << setfill(' ') << right << setw(8) << position.str();
|
---|
| 394 | }
|
---|
| 395 | {
|
---|
| 396 | stringstream occupancy;
|
---|
| 397 | occupancy << fixed << setprecision(2) << showpoint
|
---|
| 398 | << atomInfo.get<double>(PdbKey::occupancy); /* occupancy */
|
---|
| 399 | *file << setfill(' ') << right << setw(6) << occupancy.str();
|
---|
[3ae731] | 400 | }
|
---|
[16462f] | 401 | {
|
---|
| 402 | stringstream tempFactor;
|
---|
| 403 | tempFactor << fixed << setprecision(2) << showpoint
|
---|
| 404 | << atomInfo.get<double>(PdbKey::tempFactor); /* temperature factor */
|
---|
| 405 | *file << setfill(' ') << right << setw(6) << tempFactor.str();
|
---|
| 406 | }
|
---|
| 407 | *file << " "; /* char 68-76 are empty */
|
---|
| 408 | *file << setfill(' ') << right << setw(2) << atomInfo.get<std::string>(PdbKey::element); /* element */
|
---|
| 409 | *file << setfill(' ') << right << setw(2) << atomInfo.get<int>(PdbKey::charge); /* charge */
|
---|
[3ae731] | 410 |
|
---|
| 411 | *file << endl;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | /**
|
---|
| 415 | * Writes the neighbor information of one atom to the provided stream.
|
---|
| 416 | *
|
---|
[9d83b6] | 417 | * Note that ListOfBonds of WorldTime::CurrentTime is used.
|
---|
| 418 | *
|
---|
[473237] | 419 | * Also, we fill up the CONECT line to extend over 80 chars.
|
---|
| 420 | *
|
---|
[bb6193] | 421 | * \param *file where to write neighbor information to
|
---|
| 422 | * \param MaxnumberOfNeighbors of neighbors
|
---|
| 423 | * \param *currentAtom to the atom of which to take the neighbor information
|
---|
[3ae731] | 424 | */
|
---|
[bb6193] | 425 | void PdbParser::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
|
---|
[4c1230] | 426 | int MaxNo = MaxnumberOfNeighbors;
|
---|
[473237] | 427 | int charsleft = 80;
|
---|
[9d83b6] | 428 | const BondList & ListOfBonds = currentAtom->getListOfBonds();
|
---|
| 429 | if (!ListOfBonds.empty()) {
|
---|
| 430 | for(BondList::const_iterator currentBond = ListOfBonds.begin(); currentBond != ListOfBonds.end(); ++currentBond) {
|
---|
[4c1230] | 431 | if (MaxNo >= MaxnumberOfNeighbors) {
|
---|
| 432 | *file << "CONECT";
|
---|
[16462f] | 433 | *file << setw(5) << getSerial(currentAtom->getId());
|
---|
[473237] | 434 | charsleft = 80-6-5;
|
---|
[4c1230] | 435 | MaxNo = 0;
|
---|
[bb6193] | 436 | }
|
---|
[16462f] | 437 | *file << setw(5) << getSerial((*currentBond)->GetOtherAtom(currentAtom)->getId());
|
---|
[473237] | 438 | charsleft -= 5;
|
---|
[bb6193] | 439 | MaxNo++;
|
---|
[473237] | 440 | if (MaxNo == MaxnumberOfNeighbors) {
|
---|
| 441 | for (;charsleft > 0; charsleft--)
|
---|
| 442 | *file << ' ';
|
---|
[4c1230] | 443 | *file << "\n";
|
---|
[473237] | 444 | }
|
---|
[3ae731] | 445 | }
|
---|
[473237] | 446 | if (MaxNo != MaxnumberOfNeighbors) {
|
---|
| 447 | for (;charsleft > 0; charsleft--)
|
---|
| 448 | *file << ' ';
|
---|
[4c1230] | 449 | *file << "\n";
|
---|
[473237] | 450 | }
|
---|
[3ae731] | 451 | }
|
---|
| 452 | }
|
---|
| 453 |
|
---|
[21585f] | 454 | /** Retrieves a value from PdbParser::atomIdMap.
|
---|
| 455 | * \param atomid key
|
---|
| 456 | * \return value
|
---|
| 457 | */
|
---|
[4fbca9c] | 458 | size_t PdbParser::getSerial(const size_t atomid) const
|
---|
[21585f] | 459 | {
|
---|
[8990879] | 460 | ASSERT(atomIdMap.find(atomid) != atomIdMap.end(),
|
---|
| 461 | "PdbParser::getSerial() - atomid "+toString(atomid)+" not present in Map.");
|
---|
[21585f] | 462 | return (atomIdMap.find(atomid)->second);
|
---|
| 463 | }
|
---|
| 464 |
|
---|
| 465 | /** Sets an entry in PdbParser::atomIdMap.
|
---|
| 466 | * \param localatomid key
|
---|
| 467 | * \param atomid value
|
---|
| 468 | * \return true - key not present, false - value present
|
---|
| 469 | */
|
---|
[16462f] | 470 | void PdbParser::setSerial(const size_t localatomid, const size_t atomid)
|
---|
[21585f] | 471 | {
|
---|
[4fbca9c] | 472 | pair<std::map<size_t,size_t>::iterator, bool > inserter;
|
---|
[16462f] | 473 | // DoLog(1) && (Log() << Verbose(1) << "PdbParser::setAtomId() - Inserting ("
|
---|
| 474 | // << localatomid << " -> " << atomid << ")." << std::endl);
|
---|
[4fbca9c] | 475 | inserter = atomIdMap.insert( make_pair(localatomid, atomid) );
|
---|
[21585f] | 476 | ASSERT(inserter.second, "PdbParser::setAtomId: atomId already present in Map.");
|
---|
| 477 | }
|
---|
| 478 |
|
---|
[9dba5f] | 479 | /** Either returns present atom with given id or a newly created one.
|
---|
| 480 | *
|
---|
| 481 | * @param id_string
|
---|
| 482 | * @return
|
---|
| 483 | */
|
---|
| 484 | atom* PdbParser::getAtomToParse(std::string id_string) const
|
---|
| 485 | {
|
---|
| 486 | // get the local ID
|
---|
| 487 | ConvertTo<int> toInt;
|
---|
| 488 | unsigned int AtomID = toInt(id_string);
|
---|
| 489 | LOG(4, "INFO: Local id is "+toString(AtomID)+".");
|
---|
| 490 | // get the atomic ID if present
|
---|
| 491 | atom* newAtom = NULL;
|
---|
| 492 | if (atomIdMap.count((size_t)AtomID)) {
|
---|
| 493 | std::map<size_t, size_t>::const_iterator iter = atomIdMap.find(AtomID);
|
---|
| 494 | AtomID = iter->second;
|
---|
| 495 | LOG(4, "INFO: Global id present as " << AtomID << ".");
|
---|
| 496 | // check if atom exists
|
---|
| 497 | newAtom = World::getInstance().getAtom(AtomById(AtomID));
|
---|
| 498 | LOG(5, "INFO: Listing all present atoms with id.");
|
---|
| 499 | BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms())
|
---|
| 500 | LOG(5, "INFO: " << *_atom << " with id " << _atom->getId());
|
---|
| 501 | }
|
---|
| 502 | // if not exists, create
|
---|
| 503 | if (newAtom == NULL) {
|
---|
| 504 | newAtom = World::getInstance().createAtom();
|
---|
| 505 | LOG(4, "INFO: No association to global id present, creating atom.");
|
---|
| 506 | } else {
|
---|
| 507 | LOG(4, "INFO: Existing atom found: " << *newAtom << ".");
|
---|
| 508 | }
|
---|
| 509 | return newAtom;
|
---|
| 510 | }
|
---|
| 511 |
|
---|
[5fa2ba] | 512 | /** read a line starting with key ATOM.
|
---|
| 513 | *
|
---|
| 514 | * We check for line's length and parse only up to this value.
|
---|
| 515 | *
|
---|
| 516 | * @param atomInfo container to put information in
|
---|
| 517 | * @param line line containing key ATOM
|
---|
| 518 | */
|
---|
[9dba5f] | 519 | void PdbParser::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const
|
---|
| 520 | {
|
---|
[5fa2ba] | 521 | const size_t length = line.length();
|
---|
| 522 | if (length < 80)
|
---|
| 523 | ELOG(2, "PdbParser::readPdbAtomInfoContainer() - pdb is mal-formed, containing less than 80 chars!");
|
---|
| 524 | if (length >= 6) {
|
---|
| 525 | LOG(4,"INFO: Parsing token from "+line.substr(0,6)+".");
|
---|
| 526 | atomInfo.set(PdbKey::token, line.substr(0,6));
|
---|
| 527 | }
|
---|
| 528 | if (length >= 11) {
|
---|
| 529 | LOG(4,"INFO: Parsing serial from "+line.substr(6,5)+".");
|
---|
| 530 | atomInfo.set(PdbKey::serial, line.substr(6,5));
|
---|
| 531 | ASSERT(atomInfo.get<int>(PdbKey::serial) != 0,
|
---|
| 532 | "PdbParser::readPdbAtomInfoContainer() - serial 0 is invalid (filler id for conect entries).");
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 | if (length >= 16) {
|
---|
| 536 | LOG(4,"INFO: Parsing name from "+line.substr(12,4)+".");
|
---|
| 537 | atomInfo.set(PdbKey::name, line.substr(12,4));
|
---|
| 538 | }
|
---|
| 539 | if (length >= 17) {
|
---|
| 540 | LOG(4,"INFO: Parsing altLoc from "+line.substr(16,1)+".");
|
---|
| 541 | atomInfo.set(PdbKey::altLoc, line.substr(16,1));
|
---|
| 542 | }
|
---|
| 543 | if (length >= 20) {
|
---|
| 544 | LOG(4,"INFO: Parsing resName from "+line.substr(17,3)+".");
|
---|
| 545 | atomInfo.set(PdbKey::resName, line.substr(17,3));
|
---|
| 546 | }
|
---|
| 547 | if (length >= 22) {
|
---|
| 548 | LOG(4,"INFO: Parsing chainID from "+line.substr(21,1)+".");
|
---|
| 549 | atomInfo.set(PdbKey::chainID, line.substr(21,1));
|
---|
| 550 | }
|
---|
| 551 | if (length >= 26) {
|
---|
| 552 | LOG(4,"INFO: Parsing resSeq from "+line.substr(22,4)+".");
|
---|
| 553 | atomInfo.set(PdbKey::resSeq, line.substr(22,4));
|
---|
| 554 | }
|
---|
| 555 | if (length >= 27) {
|
---|
| 556 | LOG(4,"INFO: Parsing iCode from "+line.substr(26,1)+".");
|
---|
| 557 | atomInfo.set(PdbKey::iCode, line.substr(26,1));
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 | if (length >= 60) {
|
---|
| 561 | LOG(4,"INFO: Parsing occupancy from "+line.substr(54,6)+".");
|
---|
| 562 | atomInfo.set(PdbKey::occupancy, line.substr(54,6));
|
---|
| 563 | }
|
---|
| 564 | if (length >= 66) {
|
---|
| 565 | LOG(4,"INFO: Parsing tempFactor from "+line.substr(60,6)+".");
|
---|
| 566 | atomInfo.set(PdbKey::tempFactor, line.substr(60,6));
|
---|
| 567 | }
|
---|
| 568 | if (length >= 80) {
|
---|
| 569 | LOG(4,"INFO: Parsing charge from "+line.substr(78,2)+".");
|
---|
| 570 | atomInfo.set(PdbKey::charge, line.substr(78,2));
|
---|
| 571 | }
|
---|
| 572 | if (length >= 78) {
|
---|
| 573 | LOG(4,"INFO: Parsing element from "+line.substr(76,2)+".");
|
---|
| 574 | atomInfo.set(PdbKey::element, line.substr(76,2));
|
---|
| 575 | } else {
|
---|
| 576 | LOG(4,"INFO: Trying to parse alternative element from name "+line.substr(12,4)+".");
|
---|
| 577 | atomInfo.set(PdbKey::element, line.substr(12,4));
|
---|
| 578 | }
|
---|
[9dba5f] | 579 | }
|
---|
| 580 |
|
---|
[4fbca9c] | 581 | /** Parse an ATOM line from a PDB file.
|
---|
| 582 | *
|
---|
| 583 | * Reads one data line of a pdstatus file and interprets it according to the
|
---|
| 584 | * specifications of the PDB 3.2 format: http://www.wwpdb.org/docs.html
|
---|
| 585 | *
|
---|
| 586 | * A new atom is created and filled with available information, non-
|
---|
| 587 | * standard information is placed in additionalAtomData at the atom's id.
|
---|
[3ae731] | 588 | *
|
---|
[b0a2e3] | 589 | * \param _step time step to use
|
---|
[3ae731] | 590 | * \param line to parse as an atom
|
---|
[4fbca9c] | 591 | * \param newmol molecule to add parsed atoms to
|
---|
[3ae731] | 592 | */
|
---|
[b0a2e3] | 593 | void PdbParser::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) {
|
---|
[4fbca9c] | 594 | vector<string>::iterator it;
|
---|
[9dba5f] | 595 |
|
---|
| 596 | atom* newAtom = getAtomToParse(line.substr(6,5));
|
---|
| 597 | LOG(3,"INFO: Parsing END entry or empty line.");
|
---|
| 598 | bool FirstTimestep = isPresentadditionalAtomData(newAtom->getId()) ? false : true;
|
---|
[b0a2e3] | 599 | ASSERT((FirstTimestep && (_step == 0)) || (!FirstTimestep && (_step !=0)),
|
---|
[6bc86c] | 600 | "PdbParser::readAtomDataLine() - additionalAtomData present though atom is newly parsed.");
|
---|
[9dba5f] | 601 | if (FirstTimestep) {
|
---|
| 602 | LOG(3,"INFO: Parsing new atom.");
|
---|
| 603 | } else {
|
---|
| 604 | LOG(3,"INFO: Parsing present atom "+toString(*newAtom)+".");
|
---|
| 605 | }
|
---|
[93fd43e] | 606 | PdbAtomInfoContainer &atomInfo = getadditionalAtomData(newAtom);
|
---|
[9dba5f] | 607 | LOG(4,"INFO: Information in container is "+toString(atomInfo)+".");
|
---|
| 608 |
|
---|
[4fbca9c] | 609 | string word;
|
---|
| 610 | ConvertTo<size_t> toSize_t;
|
---|
| 611 |
|
---|
[9dba5f] | 612 | // assign highest+1 instead, but then beware of CONECT entries! Another map needed!
|
---|
[4fbca9c] | 613 | // if (!Inserter.second) {
|
---|
| 614 | // const size_t id = (*SerialSet.rbegin())+1;
|
---|
| 615 | // SerialSet.insert(id);
|
---|
| 616 | // atomInfo.set(PdbKey::serial, toString(id));
|
---|
| 617 | // DoeLog(2) && (eLog() << Verbose(2)
|
---|
[16462f] | 618 | // << "Serial " << atomInfo.get<std::string>(PdbKey::serial) << " already present, "
|
---|
[4fbca9c] | 619 | // << "assigning " << toString(id) << " instead." << std::endl);
|
---|
[bb6193] | 620 | // }
|
---|
[4fbca9c] | 621 |
|
---|
| 622 | // check whether serial exists, if so, assign next available
|
---|
| 623 |
|
---|
| 624 | // DoLog(2) && (Log() << Verbose(2) << "Split line:"
|
---|
| 625 | // << line.substr(6,5) << "|"
|
---|
| 626 | // << line.substr(12,4) << "|"
|
---|
| 627 | // << line.substr(16,1) << "|"
|
---|
| 628 | // << line.substr(17,3) << "|"
|
---|
| 629 | // << line.substr(21,1) << "|"
|
---|
| 630 | // << line.substr(22,4) << "|"
|
---|
| 631 | // << line.substr(26,1) << "|"
|
---|
| 632 | // << line.substr(30,8) << "|"
|
---|
| 633 | // << line.substr(38,8) << "|"
|
---|
| 634 | // << line.substr(46,8) << "|"
|
---|
| 635 | // << line.substr(54,6) << "|"
|
---|
| 636 | // << line.substr(60,6) << "|"
|
---|
| 637 | // << line.substr(76,2) << "|"
|
---|
| 638 | // << line.substr(78,2) << std::endl);
|
---|
| 639 |
|
---|
[9dba5f] | 640 | if (FirstTimestep) {
|
---|
| 641 | // first time step
|
---|
| 642 | // then fill info container
|
---|
| 643 | readPdbAtomInfoContainer(atomInfo, line);
|
---|
| 644 | // set the serial
|
---|
| 645 | std::pair< std::set<size_t>::const_iterator, bool> Inserter =
|
---|
| 646 | SerialSet.insert(toSize_t(atomInfo.get<std::string>(PdbKey::serial)));
|
---|
| 647 | ASSERT(Inserter.second,
|
---|
| 648 | "PdbParser::readAtomDataLine() - ATOM contains entry with serial "
|
---|
| 649 | +atomInfo.get<std::string>(PdbKey::serial)+" already present!");
|
---|
| 650 | setSerial(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId());
|
---|
| 651 | // set position
|
---|
| 652 | Vector tempVector;
|
---|
| 653 | LOG(4,"INFO: Parsing position from ("
|
---|
| 654 | +line.substr(30,8)+","
|
---|
| 655 | +line.substr(38,8)+","
|
---|
| 656 | +line.substr(46,8)+").");
|
---|
| 657 | PdbAtomInfoContainer::ScanKey(tempVector[0], line.substr(30,8));
|
---|
| 658 | PdbAtomInfoContainer::ScanKey(tempVector[1], line.substr(38,8));
|
---|
| 659 | PdbAtomInfoContainer::ScanKey(tempVector[2], line.substr(46,8));
|
---|
| 660 | newAtom->setPosition(tempVector);
|
---|
| 661 | // set element
|
---|
[8990879] | 662 | std::string value = atomInfo.get<std::string>(PdbKey::element);
|
---|
| 663 | // make second character lower case if not
|
---|
| 664 | if ((value[1] >= 'A') && (value[1] <= 'Z'))
|
---|
| 665 | value[1] = (value[1] - 'A') + 'a';
|
---|
[9dba5f] | 666 | const element *elem = World::getInstance().getPeriode()
|
---|
[8990879] | 667 | ->FindElement(value);
|
---|
[9dba5f] | 668 | ASSERT(elem != NULL,
|
---|
| 669 | "PdbParser::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!");
|
---|
| 670 | newAtom->setType(elem);
|
---|
| 671 |
|
---|
| 672 | if (newmol != NULL)
|
---|
| 673 | newmol->AddAtom(newAtom);
|
---|
| 674 | } else {
|
---|
| 675 | // not first time step
|
---|
| 676 | // then parse into different container
|
---|
| 677 | PdbAtomInfoContainer consistencyInfo;
|
---|
| 678 | readPdbAtomInfoContainer(consistencyInfo, line);
|
---|
| 679 | // then check additional info for consistency
|
---|
| 680 | ASSERT(atomInfo.get<std::string>(PdbKey::token) == consistencyInfo.get<std::string>(PdbKey::token),
|
---|
| 681 | "PdbParser::readAtomDataLine() - difference in token on multiple time step for atom with id "
|
---|
| 682 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 683 | ASSERT(atomInfo.get<std::string>(PdbKey::name) == consistencyInfo.get<std::string>(PdbKey::name),
|
---|
| 684 | "PdbParser::readAtomDataLine() - difference in name on multiple time step for atom with id "
|
---|
| 685 | +atomInfo.get<std::string>(PdbKey::serial)+":"
|
---|
| 686 | +atomInfo.get<std::string>(PdbKey::name)+"!="
|
---|
| 687 | +consistencyInfo.get<std::string>(PdbKey::name)+".");
|
---|
| 688 | ASSERT(atomInfo.get<std::string>(PdbKey::altLoc) == consistencyInfo.get<std::string>(PdbKey::altLoc),
|
---|
| 689 | "PdbParser::readAtomDataLine() - difference in altLoc on multiple time step for atom with id "
|
---|
| 690 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 691 | ASSERT(atomInfo.get<std::string>(PdbKey::resName) == consistencyInfo.get<std::string>(PdbKey::resName),
|
---|
| 692 | "PdbParser::readAtomDataLine() - difference in resName on multiple time step for atom with id "
|
---|
| 693 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 694 | ASSERT(atomInfo.get<std::string>(PdbKey::chainID) == consistencyInfo.get<std::string>(PdbKey::chainID),
|
---|
| 695 | "PdbParser::readAtomDataLine() - difference in chainID on multiple time step for atom with id "
|
---|
| 696 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 697 | ASSERT(atomInfo.get<std::string>(PdbKey::resSeq) == consistencyInfo.get<std::string>(PdbKey::resSeq),
|
---|
| 698 | "PdbParser::readAtomDataLine() - difference in resSeq on multiple time step for atom with id "
|
---|
| 699 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 700 | ASSERT(atomInfo.get<std::string>(PdbKey::iCode) == consistencyInfo.get<std::string>(PdbKey::iCode),
|
---|
| 701 | "PdbParser::readAtomDataLine() - difference in iCode on multiple time step for atom with id "
|
---|
| 702 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 703 | ASSERT(atomInfo.get<std::string>(PdbKey::occupancy) == consistencyInfo.get<std::string>(PdbKey::occupancy),
|
---|
| 704 | "PdbParser::readAtomDataLine() - difference in occupancy on multiple time step for atom with id "
|
---|
| 705 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 706 | ASSERT(atomInfo.get<std::string>(PdbKey::tempFactor) == consistencyInfo.get<std::string>(PdbKey::tempFactor),
|
---|
| 707 | "PdbParser::readAtomDataLine() - difference in tempFactor on multiple time step for atom with id "
|
---|
| 708 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 709 | ASSERT(atomInfo.get<std::string>(PdbKey::charge) == consistencyInfo.get<std::string>(PdbKey::charge),
|
---|
| 710 | "PdbParser::readAtomDataLine() - difference in charge on multiple time step for atom with id "
|
---|
| 711 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 712 | ASSERT(atomInfo.get<std::string>(PdbKey::element) == consistencyInfo.get<std::string>(PdbKey::element),
|
---|
| 713 | "PdbParser::readAtomDataLine() - difference in element on multiple time step for atom with id "
|
---|
| 714 | +atomInfo.get<std::string>(PdbKey::serial)+"!");
|
---|
| 715 | // and parse in trajectory
|
---|
| 716 | Vector tempVector;
|
---|
| 717 | LOG(4,"INFO: Parsing trajectory position from ("
|
---|
| 718 | +line.substr(30,8)+","
|
---|
| 719 | +line.substr(38,8)+","
|
---|
| 720 | +line.substr(46,8)+").");
|
---|
| 721 | PdbAtomInfoContainer::ScanKey(tempVector[0], line.substr(30,8));
|
---|
| 722 | PdbAtomInfoContainer::ScanKey(tempVector[1], line.substr(38,8));
|
---|
| 723 | PdbAtomInfoContainer::ScanKey(tempVector[2], line.substr(46,8));
|
---|
[b0a2e3] | 724 | LOG(4,"INFO: Adding trajectory point to time step "+toString(_step)+".");
|
---|
[9dba5f] | 725 | // and set position at new time step
|
---|
[b0a2e3] | 726 | newAtom->setPositionAtStep(_step, tempVector);
|
---|
[9dba5f] | 727 | }
|
---|
| 728 |
|
---|
[4fbca9c] | 729 |
|
---|
| 730 | // printAtomInfo(newAtom);
|
---|
[3ae731] | 731 | }
|
---|
| 732 |
|
---|
[4fbca9c] | 733 | /** Prints all PDB-specific information known about an atom.
|
---|
[3ae731] | 734 | *
|
---|
| 735 | */
|
---|
[4fbca9c] | 736 | void PdbParser::printAtomInfo(const atom * const newAtom) const
|
---|
| 737 | {
|
---|
| 738 | const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist
|
---|
| 739 |
|
---|
| 740 | DoLog(1) && (Log() << Verbose(1) << "We know about atom " << newAtom->getId() << ":" << std::endl);
|
---|
[16462f] | 741 | DoLog(1) && (Log() << Verbose(1) << "\ttoken is " << atomInfo.get<std::string>(PdbKey::token) << std::endl);
|
---|
| 742 | DoLog(1) && (Log() << Verbose(1) << "\tserial is " << atomInfo.get<int>(PdbKey::serial) << std::endl);
|
---|
| 743 | DoLog(1) && (Log() << Verbose(1) << "\tname is " << atomInfo.get<std::string>(PdbKey::name) << std::endl);
|
---|
| 744 | DoLog(1) && (Log() << Verbose(1) << "\taltLoc is " << atomInfo.get<std::string>(PdbKey::altLoc) << std::endl);
|
---|
| 745 | DoLog(1) && (Log() << Verbose(1) << "\tresName is " << atomInfo.get<std::string>(PdbKey::resName) << std::endl);
|
---|
| 746 | DoLog(1) && (Log() << Verbose(1) << "\tchainID is " << atomInfo.get<std::string>(PdbKey::chainID) << std::endl);
|
---|
| 747 | DoLog(1) && (Log() << Verbose(1) << "\tresSeq is " << atomInfo.get<int>(PdbKey::resSeq) << std::endl);
|
---|
| 748 | DoLog(1) && (Log() << Verbose(1) << "\tiCode is " << atomInfo.get<std::string>(PdbKey::iCode) << std::endl);
|
---|
| 749 | DoLog(1) && (Log() << Verbose(1) << "\tX is " << atomInfo.get<double>(PdbKey::X) << std::endl);
|
---|
| 750 | DoLog(1) && (Log() << Verbose(1) << "\tY is " << atomInfo.get<double>(PdbKey::Y) << std::endl);
|
---|
| 751 | DoLog(1) && (Log() << Verbose(1) << "\tZ is " << atomInfo.get<double>(PdbKey::Z) << std::endl);
|
---|
| 752 | DoLog(1) && (Log() << Verbose(1) << "\toccupancy is " << atomInfo.get<double>(PdbKey::occupancy) << std::endl);
|
---|
| 753 | DoLog(1) && (Log() << Verbose(1) << "\ttempFactor is " << atomInfo.get<double>(PdbKey::tempFactor) << std::endl);
|
---|
[4fbca9c] | 754 | DoLog(1) && (Log() << Verbose(1) << "\telement is '" << *(newAtom->getType()) << "'" << std::endl);
|
---|
[16462f] | 755 | DoLog(1) && (Log() << Verbose(1) << "\tcharge is " << atomInfo.get<int>(PdbKey::charge) << std::endl);
|
---|
[3ae731] | 756 | }
|
---|
| 757 |
|
---|
| 758 | /**
|
---|
[4fbca9c] | 759 | * Reads neighbor information for one atom from the input.
|
---|
| 760 | *
|
---|
[b0a2e3] | 761 | * \param _step time step to use
|
---|
[4fbca9c] | 762 | * \param line to parse as an atom
|
---|
[3ae731] | 763 | */
|
---|
[b0a2e3] | 764 | void PdbParser::readNeighbors(const unsigned int _step, std::string &line)
|
---|
[4fbca9c] | 765 | {
|
---|
| 766 | const size_t length = line.length();
|
---|
| 767 | std::list<size_t> ListOfNeighbors;
|
---|
| 768 | ConvertTo<size_t> toSize_t;
|
---|
| 769 |
|
---|
| 770 | // obtain neighbours
|
---|
| 771 | // show split line for debugging
|
---|
| 772 | string output;
|
---|
| 773 | ASSERT(length >=16,
|
---|
| 774 | "PdbParser::readNeighbors() - CONECT entry has not enough entries: "+line+"!");
|
---|
[473237] | 775 | output = "Split line:|";
|
---|
| 776 | output += line.substr(6,5) + "|";
|
---|
[4fbca9c] | 777 | const size_t id = toSize_t(line.substr(6,5));
|
---|
| 778 | for (size_t index = 11; index <= 26; index+=5) {
|
---|
| 779 | if (index+5 <= length) {
|
---|
[473237] | 780 | output += line.substr(index,5) + "|";
|
---|
| 781 | // search for digits
|
---|
| 782 | int otherid = -1;
|
---|
| 783 | PdbAtomInfoContainer::ScanKey(otherid, line.substr(index,5));
|
---|
[5fa2ba] | 784 | if (otherid > 0)
|
---|
| 785 | ListOfNeighbors.push_back(otherid);
|
---|
| 786 | else
|
---|
| 787 | ELOG(2, "PdbParser::readNeighbors() - discarding conect entry with id 0.");
|
---|
[4fbca9c] | 788 | } else {
|
---|
| 789 | break;
|
---|
| 790 | }
|
---|
| 791 | }
|
---|
[473237] | 792 | LOG(4, output);
|
---|
[4fbca9c] | 793 |
|
---|
| 794 | // add neighbours
|
---|
[16462f] | 795 | atom *_atom = World::getInstance().getAtom(AtomById(getSerial(id)));
|
---|
[473237] | 796 | LOG(2, "STATUS: Atom " << _atom->getId() << " gets " << ListOfNeighbors.size() << " more neighbours.");
|
---|
[4fbca9c] | 797 | for (std::list<size_t>::const_iterator iter = ListOfNeighbors.begin();
|
---|
| 798 | iter != ListOfNeighbors.end();
|
---|
| 799 | ++iter) {
|
---|
[16462f] | 800 | atom * const _Otheratom = World::getInstance().getAtom(AtomById(getSerial(*iter)));
|
---|
[473237] | 801 | LOG(3, "INFO: Adding Bond (" << *_atom << "," << *_Otheratom << ")");
|
---|
[b0a2e3] | 802 | _atom->addBond(_step, _Otheratom);
|
---|
[4fbca9c] | 803 | }
|
---|
[3ae731] | 804 | }
|
---|
| 805 |
|
---|
| 806 | /**
|
---|
| 807 | * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
|
---|
| 808 | * IDs of the input string will be replaced; expected separating characters are
|
---|
| 809 | * "-" and ",".
|
---|
| 810 | *
|
---|
| 811 | * \param string in which atom IDs should be adapted
|
---|
| 812 | *
|
---|
| 813 | * \return input string with modified atom IDs
|
---|
| 814 | */
|
---|
[4fbca9c] | 815 | //string PdbParser::adaptIdDependentDataString(string data) {
|
---|
[bb6193] | 816 | // // there might be no IDs
|
---|
| 817 | // if (data == "-") {
|
---|
| 818 | // return "-";
|
---|
| 819 | // }
|
---|
| 820 | //
|
---|
| 821 | // char separator;
|
---|
| 822 | // int id;
|
---|
| 823 | // stringstream line, result;
|
---|
| 824 | // line << data;
|
---|
| 825 | //
|
---|
| 826 | // line >> id;
|
---|
| 827 | // result << atomIdMap[id];
|
---|
| 828 | // while (line.good()) {
|
---|
| 829 | // line >> separator >> id;
|
---|
| 830 | // result << separator << atomIdMap[id];
|
---|
| 831 | // }
|
---|
| 832 | //
|
---|
| 833 | // return result.str();
|
---|
[4fbca9c] | 834 | // return "";
|
---|
| 835 | //}
|
---|
[3ae731] | 836 |
|
---|
| 837 |
|
---|
[4fbca9c] | 838 | bool PdbParser::operator==(const PdbParser& b) const
|
---|
| 839 | {
|
---|
| 840 | bool status = true;
|
---|
| 841 | World::AtomComposite atoms = World::getInstance().getAllAtoms();
|
---|
| 842 | for (World::AtomComposite::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
|
---|
| 843 | if ((additionalAtomData.find((*iter)->getId()) != additionalAtomData.end())
|
---|
| 844 | && (b.additionalAtomData.find((*iter)->getId()) != b.additionalAtomData.end())) {
|
---|
| 845 | const PdbAtomInfoContainer &atomInfo = additionalAtomData.at((*iter)->getId());
|
---|
| 846 | const PdbAtomInfoContainer &OtheratomInfo = b.additionalAtomData.at((*iter)->getId());
|
---|
| 847 |
|
---|
[16462f] | 848 | status = status && (atomInfo.get<std::string>(PdbKey::serial) == OtheratomInfo.get<std::string>(PdbKey::serial));
|
---|
[4fbca9c] | 849 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in serials!" << std::endl);
|
---|
[16462f] | 850 | status = status && (atomInfo.get<std::string>(PdbKey::name) == OtheratomInfo.get<std::string>(PdbKey::name));
|
---|
[4fbca9c] | 851 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in names!" << std::endl);
|
---|
[16462f] | 852 | status = status && (atomInfo.get<std::string>(PdbKey::altLoc) == OtheratomInfo.get<std::string>(PdbKey::altLoc));
|
---|
| 853 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in altLocs!" << std::endl);
|
---|
| 854 | status = status && (atomInfo.get<std::string>(PdbKey::resName) == OtheratomInfo.get<std::string>(PdbKey::resName));
|
---|
[4fbca9c] | 855 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resNames!" << std::endl);
|
---|
[16462f] | 856 | status = status && (atomInfo.get<std::string>(PdbKey::chainID) == OtheratomInfo.get<std::string>(PdbKey::chainID));
|
---|
[4fbca9c] | 857 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in chainIDs!" << std::endl);
|
---|
[16462f] | 858 | status = status && (atomInfo.get<std::string>(PdbKey::resSeq) == OtheratomInfo.get<std::string>(PdbKey::resSeq));
|
---|
[4fbca9c] | 859 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resSeqs!" << std::endl);
|
---|
[16462f] | 860 | status = status && (atomInfo.get<std::string>(PdbKey::iCode) == OtheratomInfo.get<std::string>(PdbKey::iCode));
|
---|
[4fbca9c] | 861 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in iCodes!" << std::endl);
|
---|
[16462f] | 862 | status = status && (atomInfo.get<std::string>(PdbKey::occupancy) == OtheratomInfo.get<std::string>(PdbKey::occupancy));
|
---|
[4fbca9c] | 863 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in occupancies!" << std::endl);
|
---|
[16462f] | 864 | status = status && (atomInfo.get<std::string>(PdbKey::tempFactor) == OtheratomInfo.get<std::string>(PdbKey::tempFactor));
|
---|
[4fbca9c] | 865 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in tempFactors!" << std::endl);
|
---|
[16462f] | 866 | status = status && (atomInfo.get<std::string>(PdbKey::charge) == OtheratomInfo.get<std::string>(PdbKey::charge));
|
---|
[4fbca9c] | 867 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in charges!" << std::endl);
|
---|
| 868 | }
|
---|
[3ae731] | 869 | }
|
---|
| 870 |
|
---|
[4fbca9c] | 871 | return status;
|
---|
[3ae731] | 872 | }
|
---|
| 873 |
|
---|