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