| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * PdbParser.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: Aug 17, 2010
|
|---|
| 12 | * Author: heber
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | // include config.h
|
|---|
| 16 | #ifdef HAVE_CONFIG_H
|
|---|
| 17 | #include <config.h>
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | #include "Helpers/MemDebug.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include "Helpers/Assert.hpp"
|
|---|
| 23 | #include "Helpers/Log.hpp"
|
|---|
| 24 | #include "Helpers/toString.hpp"
|
|---|
| 25 | #include "Helpers/Verbose.hpp"
|
|---|
| 26 | #include "World.hpp"
|
|---|
| 27 | #include "atom.hpp"
|
|---|
| 28 | #include "bond.hpp"
|
|---|
| 29 | #include "element.hpp"
|
|---|
| 30 | #include "molecule.hpp"
|
|---|
| 31 | #include "periodentafel.hpp"
|
|---|
| 32 | #include "Descriptors/AtomIdDescriptor.hpp"
|
|---|
| 33 | #include "Parser/PdbParser.hpp"
|
|---|
| 34 |
|
|---|
| 35 | #include <map>
|
|---|
| 36 | #include <vector>
|
|---|
| 37 |
|
|---|
| 38 | #include <iostream>
|
|---|
| 39 | #include <iomanip>
|
|---|
| 40 |
|
|---|
| 41 | using namespace std;
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * Constructor.
|
|---|
| 45 | */
|
|---|
| 46 | PdbParser::PdbParser() {
|
|---|
| 47 | knownTokens["ATOM"] = PdbKey::Atom;
|
|---|
| 48 | knownTokens["TER"] = PdbKey::Filler;
|
|---|
| 49 | knownTokens["END"] = PdbKey::EndOfFile;
|
|---|
| 50 | knownTokens["CONECT"] = PdbKey::Connect;
|
|---|
| 51 | knownTokens["REMARK"] = PdbKey::Remark;
|
|---|
| 52 | knownTokens[""] = PdbKey::EndOfFile;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | /**
|
|---|
| 56 | * Destructor.
|
|---|
| 57 | */
|
|---|
| 58 | PdbParser::~PdbParser() {
|
|---|
| 59 | additionalAtomData.clear();
|
|---|
| 60 | atomIdMap.clear();
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | /** Parses the initial word of the given \a line and returns the token type.
|
|---|
| 65 | *
|
|---|
| 66 | * @param line line to scan
|
|---|
| 67 | * @return token type
|
|---|
| 68 | */
|
|---|
| 69 | enum PdbKey::KnownTokens PdbParser::getToken(string &line)
|
|---|
| 70 | {
|
|---|
| 71 | // look for first space
|
|---|
| 72 | const size_t space_location = line.find(' ');
|
|---|
| 73 | const size_t tab_location = line.find('\t');
|
|---|
| 74 | size_t location = space_location < tab_location ? space_location : tab_location;
|
|---|
| 75 | string token;
|
|---|
| 76 | if (location != string::npos) {
|
|---|
| 77 | //DoLog(1) && (Log() << Verbose(1) << "Found space at position " << space_location << std::endl);
|
|---|
| 78 | token = line.substr(0,space_location);
|
|---|
| 79 | } else {
|
|---|
| 80 | token = line;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | //DoLog(1) && (Log() << Verbose(1) << "Token is " << token << std::endl);
|
|---|
| 84 | if (knownTokens.count(token) == 0)
|
|---|
| 85 | return PdbKey::NoToken;
|
|---|
| 86 | else
|
|---|
| 87 | return knownTokens[token];
|
|---|
| 88 |
|
|---|
| 89 | return PdbKey::NoToken;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | /**
|
|---|
| 93 | * Loads atoms from a PDB-formatted file.
|
|---|
| 94 | *
|
|---|
| 95 | * \param PDB file
|
|---|
| 96 | */
|
|---|
| 97 | void PdbParser::load(istream* file) {
|
|---|
| 98 | string line;
|
|---|
| 99 | size_t linecount = 0;
|
|---|
| 100 | enum PdbKey::KnownTokens token;
|
|---|
| 101 |
|
|---|
| 102 | molecule *newmol = World::getInstance().createMolecule();
|
|---|
| 103 | newmol->ActiveFlag = true;
|
|---|
| 104 | bool NotEndOfFile = true;
|
|---|
| 105 | // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
|
|---|
| 106 | World::getInstance().getMolecules()->insert(newmol);
|
|---|
| 107 | while (NotEndOfFile) {
|
|---|
| 108 | std::getline(*file, line, '\n');
|
|---|
| 109 | // extract first token
|
|---|
| 110 | token = getToken(line);
|
|---|
| 111 | //DoLog(1) && (Log() << Verbose(1) << " Recognized token of type : " << token << std::endl);
|
|---|
| 112 | switch (token) {
|
|---|
| 113 | case PdbKey::Atom:
|
|---|
| 114 | readAtomDataLine(line, newmol);
|
|---|
| 115 | break;
|
|---|
| 116 | case PdbKey::Remark:
|
|---|
| 117 | break;
|
|---|
| 118 | case PdbKey::Connect:
|
|---|
| 119 | readNeighbors(line);
|
|---|
| 120 | break;
|
|---|
| 121 | case PdbKey::Filler:
|
|---|
| 122 | break;
|
|---|
| 123 | case PdbKey::EndOfFile:
|
|---|
| 124 | NotEndOfFile = false;
|
|---|
| 125 | break;
|
|---|
| 126 | default:
|
|---|
| 127 | // TODO: put a throw here
|
|---|
| 128 | DoeLog(2) && (eLog() << Verbose(2) << "Unknown token: '" << line << "'" << std::endl);
|
|---|
| 129 | //ASSERT(0, "PdbParser::load() - Unknown token in line "+toString(linecount)+": "+line+".");
|
|---|
| 130 | break;
|
|---|
| 131 | }
|
|---|
| 132 | NotEndOfFile = NotEndOfFile && (file->good());
|
|---|
| 133 | linecount++;
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | /**
|
|---|
| 138 | * Saves the World's current state into as a PDB file.
|
|---|
| 139 | *
|
|---|
| 140 | * \param file where to save the state
|
|---|
| 141 | */
|
|---|
| 142 | void PdbParser::save(ostream* file) {
|
|---|
| 143 | DoLog(0) && (Log() << Verbose(0) << "Saving changes to pdb." << std::endl);
|
|---|
| 144 |
|
|---|
| 145 | {
|
|---|
| 146 | // add initial remark
|
|---|
| 147 | *file << "REMARK created by molecuilder on ";
|
|---|
| 148 | time_t now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time'
|
|---|
| 149 | // ctime ends in \n\0, we have to cut away the newline
|
|---|
| 150 | std::string time(ctime(&now));
|
|---|
| 151 | size_t pos = time.find('\n');
|
|---|
| 152 | if (pos != 0)
|
|---|
| 153 | *file << time.substr(0,pos);
|
|---|
| 154 | else
|
|---|
| 155 | *file << time;
|
|---|
| 156 | *file << endl;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | // we distribute new atom numbers, hence clear map beforehand
|
|---|
| 160 | atomIdMap.clear();
|
|---|
| 161 | {
|
|---|
| 162 | vector<atom *> AtomList = World::getInstance().getAllAtoms();
|
|---|
| 163 |
|
|---|
| 164 | std::vector<int> elementNo(MAX_ELEMENTS,1);
|
|---|
| 165 | char name[MAXSTRINGSIZE];
|
|---|
| 166 |
|
|---|
| 167 | // write ATOMs
|
|---|
| 168 | int AtomNo = 1; // serial number starts at 1 in pdb
|
|---|
| 169 | int MolNo = 1; // residue number starts at 1 in pdb
|
|---|
| 170 | for (vector<atom *>::iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
|
|---|
| 171 | const size_t Z = (*atomIt)->getType()->getAtomicNumber();
|
|---|
| 172 | sprintf(name, "%2s%02d",(*atomIt)->getType()->getSymbol().c_str(), elementNo[Z]);
|
|---|
| 173 | elementNo[Z] = (elementNo[Z]+1) % 100; // confine to two digits
|
|---|
| 174 | const molecule *mol = (*atomIt)->getMolecule();
|
|---|
| 175 | if (mol == NULL) { // for homeless atoms, MolNo = -1 is reserved
|
|---|
| 176 | MolNo = -1;
|
|---|
| 177 | } else {
|
|---|
| 178 | MolNo = mol->getId();
|
|---|
| 179 | }
|
|---|
| 180 | saveLine(file, *atomIt, name, AtomNo, MolNo);
|
|---|
| 181 | setAtomId((*atomIt)->getId(), AtomNo);
|
|---|
| 182 | AtomNo++;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | // write CONECTs
|
|---|
| 186 | for (vector<atom *>::iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
|
|---|
| 187 | writeNeighbors(file, 4, *atomIt);
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | // END
|
|---|
| 192 | *file << "END" << endl;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | /**
|
|---|
| 196 | * Writes one line of PDB-formatted data to the provided stream.
|
|---|
| 197 | *
|
|---|
| 198 | * \param stream where to write the line to
|
|---|
| 199 | * \param *currentAtom the atom of which information should be written
|
|---|
| 200 | * \param *name name of atom, i.e. H01
|
|---|
| 201 | * \param AtomNo serial number of atom
|
|---|
| 202 | * \param ResidueNo number of residue
|
|---|
| 203 | */
|
|---|
| 204 | void PdbParser::saveLine(ostream* file, const atom* currentAtom, const char *name, const int AtomNo, const int ResidueNo) {
|
|---|
| 205 | *file << "ATOM ";
|
|---|
| 206 | *file << setw(6) << AtomNo; /* atom serial number */
|
|---|
| 207 | *file << setw(1) << " ";
|
|---|
| 208 | *file << setfill(' ') << left << setw(4) << name << right; /* atom name */
|
|---|
| 209 | *file << setw(1) << " ";
|
|---|
| 210 | *file << setfill(' ') << setw(3) << ((currentAtom->getMolecule() != NULL) ? currentAtom->getMolecule()->getName().substr(0,3) : "-"); /* residue name */
|
|---|
| 211 | *file << setw(1) << " ";
|
|---|
| 212 | *file << setfill(' ') << setw(1) << (char)('a'+(unsigned char)(AtomNo % 26)); /* letter for chain */
|
|---|
| 213 | *file << setw(4) << ResidueNo; /* residue sequence number */
|
|---|
| 214 | *file << setw(4) << " ";
|
|---|
| 215 | for (int i=0;i<NDIM;i++) {
|
|---|
| 216 | *file << setw(8) << setprecision(3) << showpoint << currentAtom->at(i); /* positional coordinate in Angstroem */
|
|---|
| 217 | }
|
|---|
| 218 | *file << setw(6) << setprecision(2) << showpoint << (double)currentAtom->getType()->getValence(); /* occupancy */
|
|---|
| 219 | *file << setw(6) << setprecision(2) << showpoint << (double)currentAtom->getType()->getNoValenceOrbitals(); /* temperature factor */
|
|---|
| 220 | *file << noshowpoint;
|
|---|
| 221 | *file << setw(6) << " ";
|
|---|
| 222 | *file << setw(4) << "0";
|
|---|
| 223 | *file << setfill(' ') << setw(2) << currentAtom->getType()->getSymbol();
|
|---|
| 224 | *file << setw(2) << "0";
|
|---|
| 225 |
|
|---|
| 226 | *file << endl;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | /**
|
|---|
| 230 | * Writes the neighbor information of one atom to the provided stream.
|
|---|
| 231 | *
|
|---|
| 232 | * \param *file where to write neighbor information to
|
|---|
| 233 | * \param MaxnumberOfNeighbors of neighbors
|
|---|
| 234 | * \param *currentAtom to the atom of which to take the neighbor information
|
|---|
| 235 | */
|
|---|
| 236 | void PdbParser::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
|
|---|
| 237 | int MaxNo = MaxnumberOfNeighbors;
|
|---|
| 238 | if (!currentAtom->ListOfBonds.empty()) {
|
|---|
| 239 | for(BondList::iterator currentBond = currentAtom->ListOfBonds.begin(); currentBond != currentAtom->ListOfBonds.end(); ++currentBond) {
|
|---|
| 240 | if (MaxNo >= MaxnumberOfNeighbors) {
|
|---|
| 241 | *file << "CONECT";
|
|---|
| 242 | *file << setw(5) << getAtomId(currentAtom->getId());
|
|---|
| 243 | MaxNo = 0;
|
|---|
| 244 | }
|
|---|
| 245 | *file << setw(5) << getAtomId((*currentBond)->GetOtherAtom(currentAtom)->getId());
|
|---|
| 246 | MaxNo++;
|
|---|
| 247 | if (MaxNo == MaxnumberOfNeighbors)
|
|---|
| 248 | *file << "\n";
|
|---|
| 249 | }
|
|---|
| 250 | if (MaxNo != MaxnumberOfNeighbors)
|
|---|
| 251 | *file << "\n";
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 | /** Retrieves a value from PdbParser::atomIdMap.
|
|---|
| 257 | * \param atomid key
|
|---|
| 258 | * \return value
|
|---|
| 259 | */
|
|---|
| 260 | size_t PdbParser::getSerial(const size_t atomid) const
|
|---|
| 261 | {
|
|---|
| 262 | ConvertTo<size_t> toSize_t;
|
|---|
| 263 | ASSERT(additionalAtomData.find(atomid) != additionalAtomData.end(),
|
|---|
| 264 | "PdbParser::getSerial: atomid "+toString(atomid)+" not present in Map.");
|
|---|
| 265 | const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(atomid);
|
|---|
| 266 |
|
|---|
| 267 | return toSize_t(atomInfo.get(PdbKey::serial));
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | /** Retrieves a value from PdbParser::atomIdMap.
|
|---|
| 271 | * \param atomid key
|
|---|
| 272 | * \return value
|
|---|
| 273 | */
|
|---|
| 274 | size_t PdbParser::getAtomId(const size_t atomid) const
|
|---|
| 275 | {
|
|---|
| 276 | ASSERT(atomIdMap.find(atomid) != atomIdMap.end(), "PdbParser::getAtomId: atomid not present in Map.");
|
|---|
| 277 | return (atomIdMap.find(atomid)->second);
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | /** Sets an entry in PdbParser::atomIdMap.
|
|---|
| 281 | * \param localatomid key
|
|---|
| 282 | * \param atomid value
|
|---|
| 283 | * \return true - key not present, false - value present
|
|---|
| 284 | */
|
|---|
| 285 | void PdbParser::setAtomId(const size_t localatomid, const size_t atomid)
|
|---|
| 286 | {
|
|---|
| 287 | pair<std::map<size_t,size_t>::iterator, bool > inserter;
|
|---|
| 288 | DoLog(1) && (Log() << Verbose(1) << "PdbParser::setAtomId() - Inserting ("
|
|---|
| 289 | << localatomid << " -> " << atomid << ")." << std::endl);
|
|---|
| 290 | inserter = atomIdMap.insert( make_pair(localatomid, atomid) );
|
|---|
| 291 | ASSERT(inserter.second, "PdbParser::setAtomId: atomId already present in Map.");
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | /** Parse an ATOM line from a PDB file.
|
|---|
| 295 | *
|
|---|
| 296 | * Reads one data line of a pdstatus file and interprets it according to the
|
|---|
| 297 | * specifications of the PDB 3.2 format: http://www.wwpdb.org/docs.html
|
|---|
| 298 | *
|
|---|
| 299 | * A new atom is created and filled with available information, non-
|
|---|
| 300 | * standard information is placed in additionalAtomData at the atom's id.
|
|---|
| 301 | *
|
|---|
| 302 | * \param line to parse as an atom
|
|---|
| 303 | * \param newmol molecule to add parsed atoms to
|
|---|
| 304 | */
|
|---|
| 305 | void PdbParser::readAtomDataLine(std::string &line, molecule *newmol = NULL) {
|
|---|
| 306 | vector<string>::iterator it;
|
|---|
| 307 | stringstream lineStream;
|
|---|
| 308 | atom* newAtom = World::getInstance().createAtom();
|
|---|
| 309 | additionalAtomData[newAtom->getId()] = *(new PdbAtomInfoContainer);
|
|---|
| 310 | PdbAtomInfoContainer &atomInfo = additionalAtomData[newAtom->getId()];
|
|---|
| 311 | string word;
|
|---|
| 312 | ConvertTo<size_t> toSize_t;
|
|---|
| 313 | double tmp;
|
|---|
| 314 |
|
|---|
| 315 | lineStream << line;
|
|---|
| 316 | atomInfo.set(PdbKey::serial, line.substr(6,5));
|
|---|
| 317 | std::pair< std::set<size_t>::const_iterator, bool> Inserter =
|
|---|
| 318 | SerialSet.insert(toSize_t(atomInfo.get(PdbKey::serial)));
|
|---|
| 319 | ASSERT(Inserter.second,
|
|---|
| 320 | "PdbParser::readAtomDataLine() - ATOM contains entry with serial "
|
|---|
| 321 | +atomInfo.get(PdbKey::serial)+" already present!");
|
|---|
| 322 | // assign hightest+1 instead, but then beware of CONECT entries! Another map needed!
|
|---|
| 323 | // if (!Inserter.second) {
|
|---|
| 324 | // const size_t id = (*SerialSet.rbegin())+1;
|
|---|
| 325 | // SerialSet.insert(id);
|
|---|
| 326 | // atomInfo.set(PdbKey::serial, toString(id));
|
|---|
| 327 | // DoeLog(2) && (eLog() << Verbose(2)
|
|---|
| 328 | // << "Serial " << atomInfo.get(PdbKey::serial) << " already present, "
|
|---|
| 329 | // << "assigning " << toString(id) << " instead." << std::endl);
|
|---|
| 330 | // }
|
|---|
| 331 |
|
|---|
| 332 | // check whether serial exists, if so, assign next available
|
|---|
| 333 |
|
|---|
| 334 | // DoLog(2) && (Log() << Verbose(2) << "Split line:"
|
|---|
| 335 | // << line.substr(6,5) << "|"
|
|---|
| 336 | // << line.substr(12,4) << "|"
|
|---|
| 337 | // << line.substr(16,1) << "|"
|
|---|
| 338 | // << line.substr(17,3) << "|"
|
|---|
| 339 | // << line.substr(21,1) << "|"
|
|---|
| 340 | // << line.substr(22,4) << "|"
|
|---|
| 341 | // << line.substr(26,1) << "|"
|
|---|
| 342 | // << line.substr(30,8) << "|"
|
|---|
| 343 | // << line.substr(38,8) << "|"
|
|---|
| 344 | // << line.substr(46,8) << "|"
|
|---|
| 345 | // << line.substr(54,6) << "|"
|
|---|
| 346 | // << line.substr(60,6) << "|"
|
|---|
| 347 | // << line.substr(76,2) << "|"
|
|---|
| 348 | // << line.substr(78,2) << std::endl);
|
|---|
| 349 |
|
|---|
| 350 | setAtomId(toSize_t(atomInfo.get(PdbKey::serial)), newAtom->getId());
|
|---|
| 351 | atomInfo.set(PdbKey::name, line.substr(12,4));
|
|---|
| 352 | atomInfo.set(PdbKey::altloc, line.substr(16,1));
|
|---|
| 353 | atomInfo.set(PdbKey::resName, line.substr(17,3));
|
|---|
| 354 | atomInfo.set(PdbKey::chainID, line.substr(21,1));
|
|---|
| 355 | atomInfo.set(PdbKey::resSeq, line.substr(22,4));
|
|---|
| 356 | atomInfo.set(PdbKey::iCode, line.substr(26,1));
|
|---|
| 357 | PdbAtomInfoContainer::ScanKey(tmp, line.substr(30,8));
|
|---|
| 358 | newAtom->set(0, tmp);
|
|---|
| 359 | PdbAtomInfoContainer::ScanKey(tmp, line.substr(38,8));
|
|---|
| 360 | newAtom->set(1, tmp);
|
|---|
| 361 | PdbAtomInfoContainer::ScanKey(tmp, line.substr(46,8));
|
|---|
| 362 | newAtom->set(2, tmp);
|
|---|
| 363 | atomInfo.set(PdbKey::occupancy, line.substr(54,6));
|
|---|
| 364 | atomInfo.set(PdbKey::tempFactor, line.substr(60,6));
|
|---|
| 365 | atomInfo.set(PdbKey::charge, line.substr(78,2));
|
|---|
| 366 | PdbAtomInfoContainer::ScanKey(word, line.substr(76,2));
|
|---|
| 367 | newAtom->setType(World::getInstance().getPeriode()->FindElement(word));
|
|---|
| 368 |
|
|---|
| 369 | if (newmol != NULL)
|
|---|
| 370 | newmol->AddAtom(newAtom);
|
|---|
| 371 |
|
|---|
| 372 | // printAtomInfo(newAtom);
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | /** Prints all PDB-specific information known about an atom.
|
|---|
| 376 | *
|
|---|
| 377 | */
|
|---|
| 378 | void PdbParser::printAtomInfo(const atom * const newAtom) const
|
|---|
| 379 | {
|
|---|
| 380 | const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist
|
|---|
| 381 |
|
|---|
| 382 | DoLog(1) && (Log() << Verbose(1) << "We know about atom " << newAtom->getId() << ":" << std::endl);
|
|---|
| 383 | DoLog(1) && (Log() << Verbose(1) << "\tserial is " << atomInfo.get(PdbKey::serial) << std::endl);
|
|---|
| 384 | DoLog(1) && (Log() << Verbose(1) << "\tname is " << atomInfo.get(PdbKey::name) << std::endl);
|
|---|
| 385 | DoLog(1) && (Log() << Verbose(1) << "\taltloc is " << atomInfo.get(PdbKey::altloc) << std::endl);
|
|---|
| 386 | DoLog(1) && (Log() << Verbose(1) << "\tresName is " << atomInfo.get(PdbKey::resName) << std::endl);
|
|---|
| 387 | DoLog(1) && (Log() << Verbose(1) << "\tchainID is " << atomInfo.get(PdbKey::chainID) << std::endl);
|
|---|
| 388 | DoLog(1) && (Log() << Verbose(1) << "\tresSeq is " << atomInfo.get(PdbKey::resSeq) << std::endl);
|
|---|
| 389 | DoLog(1) && (Log() << Verbose(1) << "\tiCode is " << atomInfo.get(PdbKey::iCode) << std::endl);
|
|---|
| 390 | DoLog(1) && (Log() << Verbose(1) << "\tx is " << newAtom->getPosition() << std::endl);
|
|---|
| 391 | DoLog(1) && (Log() << Verbose(1) << "\toccupancy is " << atomInfo.get(PdbKey::occupancy) << std::endl);
|
|---|
| 392 | DoLog(1) && (Log() << Verbose(1) << "\ttempFactor is " << atomInfo.get(PdbKey::tempFactor) << std::endl);
|
|---|
| 393 | DoLog(1) && (Log() << Verbose(1) << "\telement is '" << *(newAtom->getType()) << "'" << std::endl);
|
|---|
| 394 | DoLog(1) && (Log() << Verbose(1) << "\tcharge is " << atomInfo.get(PdbKey::charge) << std::endl);
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | /**
|
|---|
| 398 | * Reads neighbor information for one atom from the input.
|
|---|
| 399 | *
|
|---|
| 400 | * \param line to parse as an atom
|
|---|
| 401 | */
|
|---|
| 402 | void PdbParser::readNeighbors(std::string &line)
|
|---|
| 403 | {
|
|---|
| 404 | const size_t length = line.length();
|
|---|
| 405 | std::list<size_t> ListOfNeighbors;
|
|---|
| 406 | ConvertTo<size_t> toSize_t;
|
|---|
| 407 |
|
|---|
| 408 | // obtain neighbours
|
|---|
| 409 | // show split line for debugging
|
|---|
| 410 | string output;
|
|---|
| 411 | ASSERT(length >=16,
|
|---|
| 412 | "PdbParser::readNeighbors() - CONECT entry has not enough entries: "+line+"!");
|
|---|
| 413 | // output = "Split line:|";
|
|---|
| 414 | // output += line.substr(6,5) + "|";
|
|---|
| 415 | const size_t id = toSize_t(line.substr(6,5));
|
|---|
| 416 | for (size_t index = 11; index <= 26; index+=5) {
|
|---|
| 417 | if (index+5 <= length) {
|
|---|
| 418 | // output += line.substr(index,5) + "|";
|
|---|
| 419 | const size_t otherid = toSize_t(line.substr(index,5));
|
|---|
| 420 | ListOfNeighbors.push_back(otherid);
|
|---|
| 421 | } else {
|
|---|
| 422 | break;
|
|---|
| 423 | }
|
|---|
| 424 | }
|
|---|
| 425 | // DoLog(2) && (Log() << Verbose(2) << output << std::endl);
|
|---|
| 426 |
|
|---|
| 427 | // add neighbours
|
|---|
| 428 | atom *_atom = World::getInstance().getAtom(AtomById(getAtomId(id)));
|
|---|
| 429 | for (std::list<size_t>::const_iterator iter = ListOfNeighbors.begin();
|
|---|
| 430 | iter != ListOfNeighbors.end();
|
|---|
| 431 | ++iter) {
|
|---|
| 432 | // DoLog(1) && (Log() << Verbose(1) << "Adding Bond (" << getAtomId(id) << "," << getAtomId(*iter) << ")" << std::endl);
|
|---|
| 433 | atom * const _Otheratom = World::getInstance().getAtom(AtomById(getAtomId(*iter)));
|
|---|
| 434 | _atom->addBond(_Otheratom);
|
|---|
| 435 | }
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | /**
|
|---|
| 439 | * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
|
|---|
| 440 | * IDs of the input string will be replaced; expected separating characters are
|
|---|
| 441 | * "-" and ",".
|
|---|
| 442 | *
|
|---|
| 443 | * \param string in which atom IDs should be adapted
|
|---|
| 444 | *
|
|---|
| 445 | * \return input string with modified atom IDs
|
|---|
| 446 | */
|
|---|
| 447 | //string PdbParser::adaptIdDependentDataString(string data) {
|
|---|
| 448 | // // there might be no IDs
|
|---|
| 449 | // if (data == "-") {
|
|---|
| 450 | // return "-";
|
|---|
| 451 | // }
|
|---|
| 452 | //
|
|---|
| 453 | // char separator;
|
|---|
| 454 | // int id;
|
|---|
| 455 | // stringstream line, result;
|
|---|
| 456 | // line << data;
|
|---|
| 457 | //
|
|---|
| 458 | // line >> id;
|
|---|
| 459 | // result << atomIdMap[id];
|
|---|
| 460 | // while (line.good()) {
|
|---|
| 461 | // line >> separator >> id;
|
|---|
| 462 | // result << separator << atomIdMap[id];
|
|---|
| 463 | // }
|
|---|
| 464 | //
|
|---|
| 465 | // return result.str();
|
|---|
| 466 | // return "";
|
|---|
| 467 | //}
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 | bool PdbParser::operator==(const PdbParser& b) const
|
|---|
| 471 | {
|
|---|
| 472 | bool status = true;
|
|---|
| 473 | World::AtomComposite atoms = World::getInstance().getAllAtoms();
|
|---|
| 474 | for (World::AtomComposite::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
|
|---|
| 475 | if ((additionalAtomData.find((*iter)->getId()) != additionalAtomData.end())
|
|---|
| 476 | && (b.additionalAtomData.find((*iter)->getId()) != b.additionalAtomData.end())) {
|
|---|
| 477 | const PdbAtomInfoContainer &atomInfo = additionalAtomData.at((*iter)->getId());
|
|---|
| 478 | const PdbAtomInfoContainer &OtheratomInfo = b.additionalAtomData.at((*iter)->getId());
|
|---|
| 479 |
|
|---|
| 480 | status = status && (atomInfo.get(PdbKey::serial) == OtheratomInfo.get(PdbKey::serial));
|
|---|
| 481 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in serials!" << std::endl);
|
|---|
| 482 | status = status && (atomInfo.get(PdbKey::name) == OtheratomInfo.get(PdbKey::name));
|
|---|
| 483 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in names!" << std::endl);
|
|---|
| 484 | status = status && (atomInfo.get(PdbKey::altloc) == OtheratomInfo.get(PdbKey::altloc));
|
|---|
| 485 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in altlocs!" << std::endl);
|
|---|
| 486 | status = status && (atomInfo.get(PdbKey::resName) == OtheratomInfo.get(PdbKey::resName));
|
|---|
| 487 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resNames!" << std::endl);
|
|---|
| 488 | status = status && (atomInfo.get(PdbKey::chainID) == OtheratomInfo.get(PdbKey::chainID));
|
|---|
| 489 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in chainIDs!" << std::endl);
|
|---|
| 490 | status = status && (atomInfo.get(PdbKey::resSeq) == OtheratomInfo.get(PdbKey::resSeq));
|
|---|
| 491 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resSeqs!" << std::endl);
|
|---|
| 492 | status = status && (atomInfo.get(PdbKey::iCode) == OtheratomInfo.get(PdbKey::iCode));
|
|---|
| 493 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in iCodes!" << std::endl);
|
|---|
| 494 | status = status && (atomInfo.get(PdbKey::occupancy) == OtheratomInfo.get(PdbKey::occupancy));
|
|---|
| 495 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in occupancies!" << std::endl);
|
|---|
| 496 | status = status && (atomInfo.get(PdbKey::tempFactor) == OtheratomInfo.get(PdbKey::tempFactor));
|
|---|
| 497 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in tempFactors!" << std::endl);
|
|---|
| 498 | status = status && (atomInfo.get(PdbKey::charge) == OtheratomInfo.get(PdbKey::charge));
|
|---|
| 499 | if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in charges!" << std::endl);
|
|---|
| 500 | }
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | return status;
|
|---|
| 504 | }
|
|---|
| 505 |
|
|---|