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