source: src/Parser/PdbParser.cpp@ 512f85

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 512f85 was 93fd43e, checked in by Frederik Heber <heber@…>, 14 years ago

new function PdbParser::getadditionalAtomData() that also adds new entries.

  • either we get the present one, or create from next father, topmost father or from defaultValues a new entry.
  • Property mode set to 100644
File size: 22.5 KB
Line 
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
41using namespace std;
42
43/**
44 * Constructor.
45 */
46PdbParser::PdbParser() {
47 knownTokens["ATOM"] = PdbKey::Atom;
48 knownTokens["HETATM"] = PdbKey::Atom;
49 knownTokens["TER"] = PdbKey::Filler;
50 knownTokens["END"] = PdbKey::EndOfFile;
51 knownTokens["CONECT"] = PdbKey::Connect;
52 knownTokens["REMARK"] = PdbKey::Remark;
53 knownTokens[""] = PdbKey::EndOfFile;
54
55 // argh, why can't just PdbKey::X+(size_t)i
56 PositionEnumMap[0] = PdbKey::X;
57 PositionEnumMap[1] = PdbKey::Y;
58 PositionEnumMap[2] = PdbKey::Z;
59}
60
61/**
62 * Destructor.
63 */
64PdbParser::~PdbParser() {
65 additionalAtomData.clear();
66 atomIdMap.clear();
67}
68
69
70/** Parses the initial word of the given \a line and returns the token type.
71 *
72 * @param line line to scan
73 * @return token type
74 */
75enum PdbKey::KnownTokens PdbParser::getToken(string &line)
76{
77 // look for first space
78 const size_t space_location = line.find(' ');
79 const size_t tab_location = line.find('\t');
80 size_t location = space_location < tab_location ? space_location : tab_location;
81 string token;
82 if (location != string::npos) {
83 //DoLog(1) && (Log() << Verbose(1) << "Found space at position " << space_location << std::endl);
84 token = line.substr(0,space_location);
85 } else {
86 token = line;
87 }
88
89 //DoLog(1) && (Log() << Verbose(1) << "Token is " << token << std::endl);
90 if (knownTokens.count(token) == 0)
91 return PdbKey::NoToken;
92 else
93 return knownTokens[token];
94
95 return PdbKey::NoToken;
96}
97
98/**
99 * Loads atoms from a PDB-formatted file.
100 *
101 * \param PDB file
102 */
103void PdbParser::load(istream* file) {
104 string line;
105 size_t linecount = 0;
106 enum PdbKey::KnownTokens token;
107
108 // reset atomIdMap for this file (to correctly parse CONECT entries)
109 atomIdMap.clear();
110
111 molecule *newmol = World::getInstance().createMolecule();
112 newmol->ActiveFlag = true;
113 bool NotEndOfFile = true;
114 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
115 World::getInstance().getMolecules()->insert(newmol);
116 while (NotEndOfFile) {
117 std::getline(*file, line, '\n');
118 // extract first token
119 token = getToken(line);
120 //DoLog(1) && (Log() << Verbose(1) << " Recognized token of type : " << token << std::endl);
121 switch (token) {
122 case PdbKey::Atom:
123 readAtomDataLine(line, newmol);
124 break;
125 case PdbKey::Remark:
126 break;
127 case PdbKey::Connect:
128 readNeighbors(line);
129 break;
130 case PdbKey::Filler:
131 break;
132 case PdbKey::EndOfFile:
133 NotEndOfFile = false;
134 break;
135 default:
136 // TODO: put a throw here
137 DoeLog(2) && (eLog() << Verbose(2) << "Unknown token: '" << line << "'" << std::endl);
138 //ASSERT(0, "PdbParser::load() - Unknown token in line "+toString(linecount)+": "+line+".");
139 break;
140 }
141 NotEndOfFile = NotEndOfFile && (file->good());
142 linecount++;
143 }
144}
145
146/**
147 * Saves the World's current state into as a PDB file.
148 *
149 * \param file where to save the state
150 */
151void PdbParser::save(ostream* file) {
152 DoLog(0) && (Log() << Verbose(0) << "Saving changes to pdb." << std::endl);
153 {
154 // add initial remark
155 *file << "REMARK created by molecuilder on ";
156 time_t now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time'
157 // ctime ends in \n\0, we have to cut away the newline
158 std::string time(ctime(&now));
159 size_t pos = time.find('\n');
160 if (pos != 0)
161 *file << time.substr(0,pos);
162 else
163 *file << time;
164 *file << endl;
165 }
166
167 // we distribute serials, hence clear map beforehand
168 atomIdMap.clear();
169 {
170 std::vector<atom *> AtomList = World::getInstance().getAllAtoms();
171 std::vector<molecule *> MolList = World::getInstance().getAllMolecules();
172 std::map<size_t,size_t> MolIdMap;
173 size_t MolNo = 1; // residue number starts at 1 in pdb
174 for (std::vector<molecule *>::const_iterator iter = MolList.begin();
175 iter != MolList.end();
176 ++iter) {
177 MolIdMap[(*iter)->getId()] = MolNo++;
178 }
179 const size_t MaxMol = MolNo;
180
181 // have a count per element and per molecule (0 is for all homeless atoms)
182 std::vector<int> **elementNo = new std::vector<int>*[MaxMol];
183 for (size_t i = 0; i < MaxMol; ++i)
184 elementNo[i] = new std::vector<int>(MAX_ELEMENTS,1);
185 char name[MAXSTRINGSIZE];
186 std::string ResidueName;
187
188 // write ATOMs
189 int AtomNo = 1; // serial number starts at 1 in pdb
190 for (vector<atom *>::iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
191 PdbAtomInfoContainer &atomInfo = getadditionalAtomData(*atomIt);
192 // gather info about residue
193 const molecule *mol = (*atomIt)->getMolecule();
194 if (mol == NULL) {
195 MolNo = 0;
196 atomInfo.set(PdbKey::resSeq, "0");
197 } else {
198 ASSERT(MolIdMap.find(mol->getId()) != MolIdMap.end(),
199 "PdbParser::save() - Mol id "+toString(mol->getId())+" not present despite we set it?!");
200 MolNo = MolIdMap[mol->getId()];
201 atomInfo.set(PdbKey::resSeq, toString(MolIdMap[mol->getId()]));
202 if (atomInfo.get<std::string>(PdbKey::resName) == "-")
203 atomInfo.set(PdbKey::resName, mol->getName().substr(0,3));
204 }
205 // get info about atom
206 const size_t Z = (*atomIt)->getType()->getAtomicNumber();
207 if (atomInfo.get<std::string>(PdbKey::name) == "-") { // if no name set, give it a new name
208 sprintf(name, "%2s%02d",(*atomIt)->getType()->getSymbol().c_str(), (*elementNo[MolNo])[Z]);
209 (*elementNo[MolNo])[Z] = ((*elementNo[MolNo])[Z]+1) % 100; // confine to two digits
210 atomInfo.set(PdbKey::name, name);
211 }
212 // set position
213 for (size_t i=0; i<NDIM;++i) {
214 stringstream position;
215 position << setw(8) << fixed << setprecision(3) << (*atomIt)->getPosition().at(i);
216 atomInfo.set(PositionEnumMap[i], position.str());
217 }
218 // change element and charge if changed
219 if (atomInfo.get<std::string>(PdbKey::element) != (*atomIt)->getType()->getSymbol())
220 atomInfo.set(PdbKey::element, (*atomIt)->getType()->getSymbol());
221 setSerial((*atomIt)->getId(), AtomNo);
222 atomInfo.set(PdbKey::serial, toString(AtomNo));
223
224 // finally save the line
225 saveLine(file, atomInfo);
226 AtomNo++;
227 }
228 for (size_t i = 0; i < MaxMol; ++i)
229 delete elementNo[i];
230 delete elementNo;
231
232 // write CONECTs
233 for (vector<atom *>::iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
234 writeNeighbors(file, 4, *atomIt);
235 }
236 }
237
238 // END
239 *file << "END" << endl;
240}
241
242/** Either returns reference to present entry or creates new with default values.
243 *
244 * @param _atom atom whose entry we desire
245 * @return
246 */
247PdbAtomInfoContainer& PdbParser::getadditionalAtomData(atom *_atom)
248{
249 if (additionalAtomData.find(_atom->getId()) != additionalAtomData.end()) {
250 } else if (additionalAtomData.find(_atom->father->getId()) != additionalAtomData.end()) {
251 // use info from direct father
252 additionalAtomData[_atom->getId()] = additionalAtomData[_atom->father->getId()];
253 } else if (additionalAtomData.find(_atom->GetTrueFather()->getId()) != additionalAtomData.end()) {
254 // use info from topmost father
255 additionalAtomData[_atom->getId()] = additionalAtomData[_atom->GetTrueFather()->getId()];
256 } else {
257 // create new entry use default values if nothing else is known
258 additionalAtomData[_atom->getId()] = defaultAdditionalData;
259 }
260 return additionalAtomData[_atom->getId()];
261}
262
263/**
264 * Writes one line of PDB-formatted data to the provided stream.
265 *
266 * \param stream where to write the line to
267 * \param *currentAtom the atom of which information should be written
268 * \param AtomNo serial number of atom
269 * \param *name name of atom, i.e. H01
270 * \param ResidueName Name of molecule
271 * \param ResidueNo number of residue
272 */
273void PdbParser::saveLine(
274 ostream* file,
275 const PdbAtomInfoContainer &atomInfo)
276{
277 *file << setfill(' ') << left << setw(6)
278 << atomInfo.get<std::string>(PdbKey::token);
279 *file << setfill(' ') << right << setw(5)
280 << atomInfo.get<int>(PdbKey::serial); /* atom serial number */
281 *file << " "; /* char 12 is empty */
282 *file << setfill(' ') << left << setw(4)
283 << atomInfo.get<std::string>(PdbKey::name); /* atom name */
284 *file << setfill(' ') << left << setw(1)
285 << atomInfo.get<std::string>(PdbKey::altLoc); /* alternate location/conformation */
286 *file << setfill(' ') << left << setw(3)
287 << atomInfo.get<std::string>(PdbKey::resName); /* residue name */
288 *file << " "; /* char 21 is empty */
289 *file << setfill(' ') << left << setw(1)
290 << atomInfo.get<std::string>(PdbKey::chainID); /* chain identifier */
291 *file << setfill(' ') << left << setw(4)
292 << atomInfo.get<int>(PdbKey::resSeq); /* residue sequence number */
293 *file << setfill(' ') << left << setw(1)
294 << atomInfo.get<std::string>(PdbKey::iCode); /* iCode */
295 *file << " "; /* char 28-30 are empty */
296 // have the following operate on stringstreams such that format specifiers
297 // only act on these
298 for (size_t i=0;i<NDIM;++i) {
299 stringstream position;
300 position << fixed << setprecision(3) << showpoint
301 << atomInfo.get<double>(PositionEnumMap[i]);
302 *file << setfill(' ') << right << setw(8) << position.str();
303 }
304 {
305 stringstream occupancy;
306 occupancy << fixed << setprecision(2) << showpoint
307 << atomInfo.get<double>(PdbKey::occupancy); /* occupancy */
308 *file << setfill(' ') << right << setw(6) << occupancy.str();
309 }
310 {
311 stringstream tempFactor;
312 tempFactor << fixed << setprecision(2) << showpoint
313 << atomInfo.get<double>(PdbKey::tempFactor); /* temperature factor */
314 *file << setfill(' ') << right << setw(6) << tempFactor.str();
315 }
316 *file << " "; /* char 68-76 are empty */
317 *file << setfill(' ') << right << setw(2) << atomInfo.get<std::string>(PdbKey::element); /* element */
318 *file << setfill(' ') << right << setw(2) << atomInfo.get<int>(PdbKey::charge); /* charge */
319
320 *file << endl;
321}
322
323/**
324 * Writes the neighbor information of one atom to the provided stream.
325 *
326 * \param *file where to write neighbor information to
327 * \param MaxnumberOfNeighbors of neighbors
328 * \param *currentAtom to the atom of which to take the neighbor information
329 */
330void PdbParser::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
331 int MaxNo = MaxnumberOfNeighbors;
332 if (!currentAtom->ListOfBonds.empty()) {
333 for(BondList::iterator currentBond = currentAtom->ListOfBonds.begin(); currentBond != currentAtom->ListOfBonds.end(); ++currentBond) {
334 if (MaxNo >= MaxnumberOfNeighbors) {
335 *file << "CONECT";
336 *file << setw(5) << getSerial(currentAtom->getId());
337 MaxNo = 0;
338 }
339 *file << setw(5) << getSerial((*currentBond)->GetOtherAtom(currentAtom)->getId());
340 MaxNo++;
341 if (MaxNo == MaxnumberOfNeighbors)
342 *file << "\n";
343 }
344 if (MaxNo != MaxnumberOfNeighbors)
345 *file << "\n";
346 }
347}
348
349/** Retrieves a value from PdbParser::atomIdMap.
350 * \param atomid key
351 * \return value
352 */
353size_t PdbParser::getSerial(const size_t atomid) const
354{
355 ASSERT(atomIdMap.find(atomid) != atomIdMap.end(), "PdbParser::getAtomId: atomid not present in Map.");
356 return (atomIdMap.find(atomid)->second);
357}
358
359/** Sets an entry in PdbParser::atomIdMap.
360 * \param localatomid key
361 * \param atomid value
362 * \return true - key not present, false - value present
363 */
364void PdbParser::setSerial(const size_t localatomid, const size_t atomid)
365{
366 pair<std::map<size_t,size_t>::iterator, bool > inserter;
367// DoLog(1) && (Log() << Verbose(1) << "PdbParser::setAtomId() - Inserting ("
368// << localatomid << " -> " << atomid << ")." << std::endl);
369 inserter = atomIdMap.insert( make_pair(localatomid, atomid) );
370 ASSERT(inserter.second, "PdbParser::setAtomId: atomId already present in Map.");
371}
372
373/** Parse an ATOM line from a PDB file.
374 *
375 * Reads one data line of a pdstatus file and interprets it according to the
376 * specifications of the PDB 3.2 format: http://www.wwpdb.org/docs.html
377 *
378 * A new atom is created and filled with available information, non-
379 * standard information is placed in additionalAtomData at the atom's id.
380 *
381 * \param line to parse as an atom
382 * \param newmol molecule to add parsed atoms to
383 */
384void PdbParser::readAtomDataLine(std::string &line, molecule *newmol = NULL) {
385 vector<string>::iterator it;
386 stringstream lineStream;
387 atom* newAtom = World::getInstance().createAtom();
388 PdbAtomInfoContainer &atomInfo = getadditionalAtomData(newAtom);
389 string word;
390 ConvertTo<size_t> toSize_t;
391 double tmp;
392
393 lineStream << line;
394 atomInfo.set(PdbKey::token, line.substr(0,6));
395 atomInfo.set(PdbKey::serial, line.substr(6,5));
396 std::pair< std::set<size_t>::const_iterator, bool> Inserter =
397 SerialSet.insert(toSize_t(atomInfo.get<std::string>(PdbKey::serial)));
398 ASSERT(Inserter.second,
399 "PdbParser::readAtomDataLine() - ATOM contains entry with serial "
400 +atomInfo.get<std::string>(PdbKey::serial)+" already present!");
401 // assign hightest+1 instead, but then beware of CONECT entries! Another map needed!
402// if (!Inserter.second) {
403// const size_t id = (*SerialSet.rbegin())+1;
404// SerialSet.insert(id);
405// atomInfo.set(PdbKey::serial, toString(id));
406// DoeLog(2) && (eLog() << Verbose(2)
407// << "Serial " << atomInfo.get<std::string>(PdbKey::serial) << " already present, "
408// << "assigning " << toString(id) << " instead." << std::endl);
409// }
410
411 // check whether serial exists, if so, assign next available
412
413// DoLog(2) && (Log() << Verbose(2) << "Split line:"
414// << line.substr(6,5) << "|"
415// << line.substr(12,4) << "|"
416// << line.substr(16,1) << "|"
417// << line.substr(17,3) << "|"
418// << line.substr(21,1) << "|"
419// << line.substr(22,4) << "|"
420// << line.substr(26,1) << "|"
421// << line.substr(30,8) << "|"
422// << line.substr(38,8) << "|"
423// << line.substr(46,8) << "|"
424// << line.substr(54,6) << "|"
425// << line.substr(60,6) << "|"
426// << line.substr(76,2) << "|"
427// << line.substr(78,2) << std::endl);
428
429 setSerial(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId());
430 atomInfo.set(PdbKey::name, line.substr(12,4));
431 atomInfo.set(PdbKey::altLoc, line.substr(16,1));
432 atomInfo.set(PdbKey::resName, line.substr(17,3));
433 atomInfo.set(PdbKey::chainID, line.substr(21,1));
434 atomInfo.set(PdbKey::resSeq, line.substr(22,4));
435 atomInfo.set(PdbKey::iCode, line.substr(26,1));
436 PdbAtomInfoContainer::ScanKey(tmp, line.substr(30,8));
437 newAtom->set(0, tmp);
438 PdbAtomInfoContainer::ScanKey(tmp, line.substr(38,8));
439 newAtom->set(1, tmp);
440 PdbAtomInfoContainer::ScanKey(tmp, line.substr(46,8));
441 newAtom->set(2, tmp);
442 atomInfo.set(PdbKey::occupancy, line.substr(54,6));
443 atomInfo.set(PdbKey::tempFactor, line.substr(60,6));
444 atomInfo.set(PdbKey::charge, line.substr(78,2));
445 atomInfo.set(PdbKey::element, line.substr(76,2));
446 const element *elem = World::getInstance().getPeriode()
447 ->FindElement(atomInfo.get<std::string>(PdbKey::element));
448 ASSERT(elem != NULL,
449 "PdbParser::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!");
450 newAtom->setType(elem);
451
452 if (newmol != NULL)
453 newmol->AddAtom(newAtom);
454
455// printAtomInfo(newAtom);
456}
457
458/** Prints all PDB-specific information known about an atom.
459 *
460 */
461void PdbParser::printAtomInfo(const atom * const newAtom) const
462{
463 const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist
464
465 DoLog(1) && (Log() << Verbose(1) << "We know about atom " << newAtom->getId() << ":" << std::endl);
466 DoLog(1) && (Log() << Verbose(1) << "\ttoken is " << atomInfo.get<std::string>(PdbKey::token) << std::endl);
467 DoLog(1) && (Log() << Verbose(1) << "\tserial is " << atomInfo.get<int>(PdbKey::serial) << std::endl);
468 DoLog(1) && (Log() << Verbose(1) << "\tname is " << atomInfo.get<std::string>(PdbKey::name) << std::endl);
469 DoLog(1) && (Log() << Verbose(1) << "\taltLoc is " << atomInfo.get<std::string>(PdbKey::altLoc) << std::endl);
470 DoLog(1) && (Log() << Verbose(1) << "\tresName is " << atomInfo.get<std::string>(PdbKey::resName) << std::endl);
471 DoLog(1) && (Log() << Verbose(1) << "\tchainID is " << atomInfo.get<std::string>(PdbKey::chainID) << std::endl);
472 DoLog(1) && (Log() << Verbose(1) << "\tresSeq is " << atomInfo.get<int>(PdbKey::resSeq) << std::endl);
473 DoLog(1) && (Log() << Verbose(1) << "\tiCode is " << atomInfo.get<std::string>(PdbKey::iCode) << std::endl);
474 DoLog(1) && (Log() << Verbose(1) << "\tX is " << atomInfo.get<double>(PdbKey::X) << std::endl);
475 DoLog(1) && (Log() << Verbose(1) << "\tY is " << atomInfo.get<double>(PdbKey::Y) << std::endl);
476 DoLog(1) && (Log() << Verbose(1) << "\tZ is " << atomInfo.get<double>(PdbKey::Z) << std::endl);
477 DoLog(1) && (Log() << Verbose(1) << "\toccupancy is " << atomInfo.get<double>(PdbKey::occupancy) << std::endl);
478 DoLog(1) && (Log() << Verbose(1) << "\ttempFactor is " << atomInfo.get<double>(PdbKey::tempFactor) << std::endl);
479 DoLog(1) && (Log() << Verbose(1) << "\telement is '" << *(newAtom->getType()) << "'" << std::endl);
480 DoLog(1) && (Log() << Verbose(1) << "\tcharge is " << atomInfo.get<int>(PdbKey::charge) << std::endl);
481}
482
483/**
484 * Reads neighbor information for one atom from the input.
485 *
486 * \param line to parse as an atom
487 */
488void PdbParser::readNeighbors(std::string &line)
489{
490 const size_t length = line.length();
491 std::list<size_t> ListOfNeighbors;
492 ConvertTo<size_t> toSize_t;
493
494 // obtain neighbours
495 // show split line for debugging
496 string output;
497 ASSERT(length >=16,
498 "PdbParser::readNeighbors() - CONECT entry has not enough entries: "+line+"!");
499// output = "Split line:|";
500// output += line.substr(6,5) + "|";
501 const size_t id = toSize_t(line.substr(6,5));
502 for (size_t index = 11; index <= 26; index+=5) {
503 if (index+5 <= length) {
504// output += line.substr(index,5) + "|";
505 const size_t otherid = toSize_t(line.substr(index,5));
506 ListOfNeighbors.push_back(otherid);
507 } else {
508 break;
509 }
510 }
511// DoLog(2) && (Log() << Verbose(2) << output << std::endl);
512
513 // add neighbours
514 atom *_atom = World::getInstance().getAtom(AtomById(getSerial(id)));
515 for (std::list<size_t>::const_iterator iter = ListOfNeighbors.begin();
516 iter != ListOfNeighbors.end();
517 ++iter) {
518// DoLog(1) && (Log() << Verbose(1) << "Adding Bond (" << getAtomId(id) << "," << getAtomId(*iter) << ")" << std::endl);
519 atom * const _Otheratom = World::getInstance().getAtom(AtomById(getSerial(*iter)));
520 _atom->addBond(_Otheratom);
521 }
522}
523
524/**
525 * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
526 * IDs of the input string will be replaced; expected separating characters are
527 * "-" and ",".
528 *
529 * \param string in which atom IDs should be adapted
530 *
531 * \return input string with modified atom IDs
532 */
533//string PdbParser::adaptIdDependentDataString(string data) {
534// // there might be no IDs
535// if (data == "-") {
536// return "-";
537// }
538//
539// char separator;
540// int id;
541// stringstream line, result;
542// line << data;
543//
544// line >> id;
545// result << atomIdMap[id];
546// while (line.good()) {
547// line >> separator >> id;
548// result << separator << atomIdMap[id];
549// }
550//
551// return result.str();
552// return "";
553//}
554
555
556bool PdbParser::operator==(const PdbParser& b) const
557{
558 bool status = true;
559 World::AtomComposite atoms = World::getInstance().getAllAtoms();
560 for (World::AtomComposite::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
561 if ((additionalAtomData.find((*iter)->getId()) != additionalAtomData.end())
562 && (b.additionalAtomData.find((*iter)->getId()) != b.additionalAtomData.end())) {
563 const PdbAtomInfoContainer &atomInfo = additionalAtomData.at((*iter)->getId());
564 const PdbAtomInfoContainer &OtheratomInfo = b.additionalAtomData.at((*iter)->getId());
565
566 status = status && (atomInfo.get<std::string>(PdbKey::serial) == OtheratomInfo.get<std::string>(PdbKey::serial));
567 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in serials!" << std::endl);
568 status = status && (atomInfo.get<std::string>(PdbKey::name) == OtheratomInfo.get<std::string>(PdbKey::name));
569 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in names!" << std::endl);
570 status = status && (atomInfo.get<std::string>(PdbKey::altLoc) == OtheratomInfo.get<std::string>(PdbKey::altLoc));
571 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in altLocs!" << std::endl);
572 status = status && (atomInfo.get<std::string>(PdbKey::resName) == OtheratomInfo.get<std::string>(PdbKey::resName));
573 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resNames!" << std::endl);
574 status = status && (atomInfo.get<std::string>(PdbKey::chainID) == OtheratomInfo.get<std::string>(PdbKey::chainID));
575 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in chainIDs!" << std::endl);
576 status = status && (atomInfo.get<std::string>(PdbKey::resSeq) == OtheratomInfo.get<std::string>(PdbKey::resSeq));
577 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resSeqs!" << std::endl);
578 status = status && (atomInfo.get<std::string>(PdbKey::iCode) == OtheratomInfo.get<std::string>(PdbKey::iCode));
579 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in iCodes!" << std::endl);
580 status = status && (atomInfo.get<std::string>(PdbKey::occupancy) == OtheratomInfo.get<std::string>(PdbKey::occupancy));
581 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in occupancies!" << std::endl);
582 status = status && (atomInfo.get<std::string>(PdbKey::tempFactor) == OtheratomInfo.get<std::string>(PdbKey::tempFactor));
583 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in tempFactors!" << std::endl);
584 status = status && (atomInfo.get<std::string>(PdbKey::charge) == OtheratomInfo.get<std::string>(PdbKey::charge));
585 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in charges!" << std::endl);
586 }
587 }
588
589 return status;
590}
591
Note: See TracBrowser for help on using the repository browser.