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