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