- Timestamp:
- Dec 5, 2010, 12:01:43 AM (14 years ago)
- Branches:
- 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
- Children:
- cabb46
- Parents:
- e828c0
- git-author:
- Frederik Heber <heber@…> (12/04/10 18:05:33)
- git-committer:
- Frederik Heber <heber@…> (12/05/10 00:01:43)
- Location:
- src
- Files:
-
- 5 added
- 4 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/Makefile.am
re828c0 r4fbca9c 14 14 MpqcParser.cpp \ 15 15 PcpParser.cpp \ 16 PdbAtomInfoContainer.cpp \ 16 17 PdbParser.cpp \ 17 18 TremoloParser.cpp \ … … 24 25 MpqcParser.hpp \ 25 26 PcpParser.hpp \ 27 PdbAtomInfoContainer.hpp \ 28 PdbKey.hpp \ 26 29 PdbParser.hpp \ 27 30 TremoloParser.hpp \ -
src/Parser/PdbParser.cpp
re828c0 r4fbca9c 22 22 #include "Helpers/Assert.hpp" 23 23 #include "Helpers/Log.hpp" 24 #include "Helpers/toString.hpp" 24 25 #include "Helpers/Verbose.hpp" 25 #include "PdbParser.hpp"26 26 #include "World.hpp" 27 27 #include "atom.hpp" … … 31 31 #include "periodentafel.hpp" 32 32 #include "Descriptors/AtomIdDescriptor.hpp" 33 #include "Parser/PdbParser.hpp" 33 34 34 35 #include <map> … … 44 45 */ 45 46 PdbParser::PdbParser() { 46 knownKeys[" "] = PdbKey::noKey; // with this we can detect invalid keys 47 knownKeys["x"] = PdbKey::x; 48 knownKeys["Id"] = PdbKey::Id; 49 knownKeys["Type"] = PdbKey::Type; 50 knownKeys["extType"] = PdbKey::extType; 51 knownKeys["name"] = PdbKey::name; 52 knownKeys["resName"] = PdbKey::resName; 53 knownKeys["chainID"] = PdbKey::chainID; 54 knownKeys["resSeq"] = PdbKey::resSeq; 55 knownKeys["occupancy"] = PdbKey::occupancy; 56 knownKeys["tempFactor"] = PdbKey::tempFactor; 57 knownKeys["segID"] = PdbKey::segID; 58 knownKeys["charge"] = PdbKey::charge; 47 knownTokens["ATOM"] = PdbKey::Atom; 48 knownTokens["TER"] = PdbKey::Filler; 49 knownTokens["END"] = PdbKey::EndOfFile; 50 knownTokens["CONECT"] = PdbKey::Connect; 51 knownTokens["REMARK"] = PdbKey::Remark; 52 knownTokens[""] = PdbKey::EndOfFile; 59 53 } 60 54 … … 65 59 additionalAtomData.clear(); 66 60 atomIdMap.clear(); 67 knownKeys.clear(); 68 } 69 70 /** 71 * Loads atoms from a tremolo-formatted file. 72 * 73 * \param tremolo file 61 } 62 63 64 /** Parses the initial word of the given \a line and returns the token type. 65 * 66 * @param line line to scan 67 * @return token type 68 */ 69 enum PdbKey::KnownTokens PdbParser::getToken(string &line) 70 { 71 // look for first space 72 const size_t space_location = line.find(' '); 73 const size_t tab_location = line.find('\t'); 74 size_t location = space_location < tab_location ? space_location : tab_location; 75 string token; 76 if (location != string::npos) { 77 //DoLog(1) && (Log() << Verbose(1) << "Found space at position " << space_location << std::endl); 78 token = line.substr(0,space_location); 79 } else { 80 token = line; 81 } 82 83 //DoLog(1) && (Log() << Verbose(1) << "Token is " << token << std::endl); 84 if (knownTokens.count(token) == 0) 85 return PdbKey::NoToken; 86 else 87 return knownTokens[token]; 88 89 return PdbKey::NoToken; 90 } 91 92 /** 93 * Loads atoms from a PDB-formatted file. 94 * 95 * \param PDB file 74 96 */ 75 97 void PdbParser::load(istream* file) { 76 // TODO: PdbParser::load implementation 77 ASSERT(false, "Not implemented yet"); 78 // string line; 79 // string::size_type location; 80 // 81 // usedFields.clear(); 82 // while (file->good()) { 83 // std::getline(*file, line, '\n'); 84 // if (usedFields.empty()) { 85 // location = line.find("ATOMDATA", 0); 86 // if (location != string::npos) { 87 // parseAtomDataKeysLine(line, location + 8); 88 // } 89 // } 90 // if (line.length() > 0 && line.at(0) != '#') { 91 // readAtomDataLine(line); 92 // } 93 // } 94 // 95 // processNeighborInformation(); 96 // adaptImprData(); 97 // adaptTorsion(); 98 } 99 100 /** 101 * Saves the World's current state into as a tremolo file. 98 string line; 99 size_t linecount = 0; 100 enum PdbKey::KnownTokens token; 101 102 molecule *newmol = World::getInstance().createMolecule(); 103 newmol->ActiveFlag = true; 104 bool NotEndOfFile = true; 105 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include 106 World::getInstance().getMolecules()->insert(newmol); 107 while (NotEndOfFile) { 108 std::getline(*file, line, '\n'); 109 // extract first token 110 token = getToken(line); 111 //DoLog(1) && (Log() << Verbose(1) << " Recognized token of type : " << token << std::endl); 112 switch (token) { 113 case PdbKey::Atom: 114 readAtomDataLine(line, newmol); 115 break; 116 case PdbKey::Remark: 117 break; 118 case PdbKey::Connect: 119 readNeighbors(line); 120 break; 121 case PdbKey::Filler: 122 break; 123 case PdbKey::EndOfFile: 124 NotEndOfFile = false; 125 break; 126 default: 127 // TODO: put a throw here 128 DoeLog(2) && (eLog() << Verbose(2) << "Unknown token: '" << line << "'" << std::endl); 129 //ASSERT(0, "PdbParser::load() - Unknown token in line "+toString(linecount)+": "+line+"."); 130 break; 131 } 132 NotEndOfFile = NotEndOfFile && (file->good()); 133 linecount++; 134 } 135 } 136 137 /** 138 * Saves the World's current state into as a PDB file. 102 139 * 103 140 * \param file where to save the state … … 120 157 } 121 158 159 // we distribute new atom numbers, hence clear map beforehand 160 atomIdMap.clear(); 122 161 { 123 162 vector<atom *> AtomList = World::getInstance().getAllAtoms(); … … 155 194 156 195 /** 157 * Writes one line of tremolo-formatted data to the provided stream.196 * Writes one line of PDB-formatted data to the provided stream. 158 197 * 159 198 * \param stream where to write the line to … … 198 237 if (!currentAtom->ListOfBonds.empty()) { 199 238 *file << "CONECT"; 200 *file << setw(5) << get AtomId(currentAtom->getId());239 *file << setw(5) << getSerial(currentAtom->getId()); 201 240 int MaxNo = 0; 202 241 for(BondList::iterator currentBond = currentAtom->ListOfBonds.begin(); currentBond != currentAtom->ListOfBonds.end(); ++currentBond) { 203 242 if (MaxNo < MaxnumberOfNeighbors) { 204 *file << setw(5) << get AtomId((*currentBond)->GetOtherAtom(currentAtom)->getId());243 *file << setw(5) << getSerial((*currentBond)->GetOtherAtom(currentAtom)->getId()); 205 244 } 206 245 MaxNo++; … … 215 254 * \return value 216 255 */ 217 int PdbParser::getAtomId(int atomid) const 256 size_t PdbParser::getSerial(const size_t atomid) const 257 { 258 ConvertTo<size_t> toSize_t; 259 ASSERT(additionalAtomData.find(atomid) != additionalAtomData.end(), 260 "PdbParser::getSerial: atomid "+toString(atomid)+" not present in Map."); 261 const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(atomid); 262 263 return toSize_t(atomInfo.get(PdbKey::serial)); 264 } 265 266 /** Retrieves a value from PdbParser::atomIdMap. 267 * \param atomid key 268 * \return value 269 */ 270 size_t PdbParser::getAtomId(const size_t atomid) const 218 271 { 219 272 ASSERT(atomIdMap.find(atomid) != atomIdMap.end(), "PdbParser::getAtomId: atomid not present in Map."); … … 226 279 * \return true - key not present, false - value present 227 280 */ 228 void PdbParser::setAtomId( int localatomid, int atomid)229 { 230 pair<std::map< int,int>::iterator, bool > inserter;231 inserter = atomIdMap.insert( pair<int, int>(localatomid, atomid) );281 void PdbParser::setAtomId(const size_t localatomid, const size_t atomid) 282 { 283 pair<std::map<size_t,size_t>::iterator, bool > inserter; 284 inserter = atomIdMap.insert( make_pair(localatomid, atomid) ); 232 285 ASSERT(inserter.second, "PdbParser::setAtomId: atomId already present in Map."); 233 286 } 234 287 235 /** 236 * Reads one data line of a tremolo file and interprets it according to the keys 237 * obtained from the ATOMDATA line. 288 /** Parse an ATOM line from a PDB file. 289 * 290 * Reads one data line of a pdstatus file and interprets it according to the 291 * specifications of the PDB 3.2 format: http://www.wwpdb.org/docs.html 292 * 293 * A new atom is created and filled with available information, non- 294 * standard information is placed in additionalAtomData at the atom's id. 238 295 * 239 296 * \param line to parse as an atom 240 */ 241 void PdbParser::readAtomDataLine(string line) { 242 // vector<string>::iterator it; 243 // stringstream lineStream; 244 // atom* newAtom = World::getInstance().createAtom(); 245 // PdbAtomInfoContainer *atomInfo = NULL; 246 // additionalAtomData[newAtom->getId()] = *(new PdbAtomInfoContainer); 247 // atomInfo = &additionalAtomData[newAtom->getId()]; 248 // PdbKey::atomDataKey currentField; 249 // string word; 250 // int oldId; 251 // double tmp; 252 // 253 // lineStream << line; 254 // for (it = usedFields.begin(); it < usedFields.end(); it++) { 255 // currentField = knownKeys[it->substr(0, it->find("="))]; 256 // switch (currentField) { 257 // case PdbKey::x : 258 // // for the moment, assume there are always three dimensions 259 // for (int i=0;i<NDIM;i++) { 260 // lineStream >> tmp; 261 // newAtom->set(i, tmp); 262 // } 263 // break; 264 // case PdbKey::u : 265 // // for the moment, assume there are always three dimensions 266 // lineStream >> newAtom->AtomicVelocity[0]; 267 // lineStream >> newAtom->AtomicVelocity[1]; 268 // lineStream >> newAtom->AtomicVelocity[2]; 269 // break; 270 // case PdbKey::Type : 271 // char type[3]; 272 // lineStream >> type; 273 // newAtom->setType(World::getInstance().getPeriode()->FindElement(type)); 274 // ASSERT(newAtom->getType(), "Type was not set for this atom"); 275 // break; 276 // case PdbKey::Id : 277 // lineStream >> oldId; 278 // atomIdMap[oldId] = newAtom->getId(); 279 // break; 280 // case PdbKey::neighbors : 281 // readNeighbors(&lineStream, 282 // atoi(it->substr(it->find("=") + 1, 1).c_str()), newAtom->getId()); 283 // break; 284 // default : 285 // lineStream >> word; 286 // atomInfo->set(currentField, word); 287 // break; 288 // } 297 * \param newmol molecule to add parsed atoms to 298 */ 299 void PdbParser::readAtomDataLine(std::string &line, molecule *newmol = NULL) { 300 vector<string>::iterator it; 301 stringstream lineStream; 302 atom* newAtom = World::getInstance().createAtom(); 303 additionalAtomData[newAtom->getId()] = *(new PdbAtomInfoContainer); 304 PdbAtomInfoContainer &atomInfo = additionalAtomData[newAtom->getId()]; 305 string word; 306 ConvertTo<size_t> toSize_t; 307 double tmp; 308 309 lineStream << line; 310 atomInfo.set(PdbKey::serial, line.substr(6,5)); 311 std::pair< std::set<size_t>::const_iterator, bool> Inserter = 312 SerialSet.insert(toSize_t(atomInfo.get(PdbKey::serial))); 313 ASSERT(Inserter.second, 314 "PdbParser::readAtomDataLine() - ATOM contains entry with serial " 315 +atomInfo.get(PdbKey::serial)+" already present!"); 316 // assign hightest+1 instead, but then beware of CONECT entries! Another map needed! 317 // if (!Inserter.second) { 318 // const size_t id = (*SerialSet.rbegin())+1; 319 // SerialSet.insert(id); 320 // atomInfo.set(PdbKey::serial, toString(id)); 321 // DoeLog(2) && (eLog() << Verbose(2) 322 // << "Serial " << atomInfo.get(PdbKey::serial) << " already present, " 323 // << "assigning " << toString(id) << " instead." << std::endl); 289 324 // } 325 326 // check whether serial exists, if so, assign next available 327 328 // DoLog(2) && (Log() << Verbose(2) << "Split line:" 329 // << line.substr(6,5) << "|" 330 // << line.substr(12,4) << "|" 331 // << line.substr(16,1) << "|" 332 // << line.substr(17,3) << "|" 333 // << line.substr(21,1) << "|" 334 // << line.substr(22,4) << "|" 335 // << line.substr(26,1) << "|" 336 // << line.substr(30,8) << "|" 337 // << line.substr(38,8) << "|" 338 // << line.substr(46,8) << "|" 339 // << line.substr(54,6) << "|" 340 // << line.substr(60,6) << "|" 341 // << line.substr(76,2) << "|" 342 // << line.substr(78,2) << std::endl); 343 344 setAtomId(toSize_t(atomInfo.get(PdbKey::serial)), newAtom->getId()); 345 atomInfo.set(PdbKey::name, line.substr(12,4)); 346 atomInfo.set(PdbKey::altloc, line.substr(16,1)); 347 atomInfo.set(PdbKey::resName, line.substr(17,3)); 348 atomInfo.set(PdbKey::chainID, line.substr(21,1)); 349 atomInfo.set(PdbKey::resSeq, line.substr(22,4)); 350 atomInfo.set(PdbKey::iCode, line.substr(26,1)); 351 PdbAtomInfoContainer::ScanKey(tmp, line.substr(30,8)); 352 newAtom->set(0, tmp); 353 PdbAtomInfoContainer::ScanKey(tmp, line.substr(38,8)); 354 newAtom->set(1, tmp); 355 PdbAtomInfoContainer::ScanKey(tmp, line.substr(46,8)); 356 newAtom->set(2, tmp); 357 atomInfo.set(PdbKey::occupancy, line.substr(54,6)); 358 atomInfo.set(PdbKey::tempFactor, line.substr(60,6)); 359 atomInfo.set(PdbKey::charge, line.substr(78,2)); 360 PdbAtomInfoContainer::ScanKey(word, line.substr(76,2)); 361 newAtom->setType(World::getInstance().getPeriode()->FindElement(word)); 362 363 if (newmol != NULL) 364 newmol->AddAtom(newAtom); 365 366 // printAtomInfo(newAtom); 367 } 368 369 /** Prints all PDB-specific information known about an atom. 370 * 371 */ 372 void PdbParser::printAtomInfo(const atom * const newAtom) const 373 { 374 const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist 375 376 DoLog(1) && (Log() << Verbose(1) << "We know about atom " << newAtom->getId() << ":" << std::endl); 377 DoLog(1) && (Log() << Verbose(1) << "\tserial is " << atomInfo.get(PdbKey::serial) << std::endl); 378 DoLog(1) && (Log() << Verbose(1) << "\tname is " << atomInfo.get(PdbKey::name) << std::endl); 379 DoLog(1) && (Log() << Verbose(1) << "\taltloc is " << atomInfo.get(PdbKey::altloc) << std::endl); 380 DoLog(1) && (Log() << Verbose(1) << "\tresName is " << atomInfo.get(PdbKey::resName) << std::endl); 381 DoLog(1) && (Log() << Verbose(1) << "\tchainID is " << atomInfo.get(PdbKey::chainID) << std::endl); 382 DoLog(1) && (Log() << Verbose(1) << "\tresSeq is " << atomInfo.get(PdbKey::resSeq) << std::endl); 383 DoLog(1) && (Log() << Verbose(1) << "\tiCode is " << atomInfo.get(PdbKey::iCode) << std::endl); 384 DoLog(1) && (Log() << Verbose(1) << "\tx is " << newAtom->getPosition() << std::endl); 385 DoLog(1) && (Log() << Verbose(1) << "\toccupancy is " << atomInfo.get(PdbKey::occupancy) << std::endl); 386 DoLog(1) && (Log() << Verbose(1) << "\ttempFactor is " << atomInfo.get(PdbKey::tempFactor) << std::endl); 387 DoLog(1) && (Log() << Verbose(1) << "\telement is '" << *(newAtom->getType()) << "'" << std::endl); 388 DoLog(1) && (Log() << Verbose(1) << "\tcharge is " << atomInfo.get(PdbKey::charge) << std::endl); 290 389 } 291 390 … … 293 392 * Reads neighbor information for one atom from the input. 294 393 * 295 * \param stream where to read the information from 296 * \param number of neighbors to read 297 * \param world id of the atom the information belongs to 298 */ 299 void PdbParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) { 300 // int neighborId = 0; 301 // for (int i = 0; i < numberOfNeighbors; i++) { 302 // *line >> neighborId; 303 // // 0 is used to fill empty neighbor positions in the tremolo file. 304 // if (neighborId > 0) { 305 // additionalAtomData[atomId].neighbors.push_back(neighborId); 306 // } 307 // } 308 } 309 310 /** 311 * Adds the collected neighbor information to the atoms in the world. The atoms 312 * are found by their current ID and mapped to the corresponding atoms with the 313 * Id found in the parsed file. 314 */ 315 void PdbParser::processNeighborInformation() { 316 // if (!isUsedField("neighbors")) { 317 // return; 318 // } 319 // 320 // for(map<int, PdbAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin(); 321 // currentInfo != additionalAtomData.end(); currentInfo++ 322 // ) { 323 // for(vector<int>::iterator neighbor = currentInfo->second.neighbors.begin(); 324 // neighbor != currentInfo->second.neighbors.end(); neighbor++ 325 // ) { 326 // World::getInstance().getAtom(AtomById(currentInfo->first)) 327 // ->addBond(World::getInstance().getAtom(AtomById(atomIdMap[*neighbor]))); 328 // } 329 // } 394 * \param line to parse as an atom 395 */ 396 void PdbParser::readNeighbors(std::string &line) 397 { 398 const size_t length = line.length(); 399 std::list<size_t> ListOfNeighbors; 400 ConvertTo<size_t> toSize_t; 401 402 // obtain neighbours 403 // show split line for debugging 404 string output; 405 ASSERT(length >=16, 406 "PdbParser::readNeighbors() - CONECT entry has not enough entries: "+line+"!"); 407 // output = "Split line:|"; 408 // output += line.substr(6,5) + "|"; 409 const size_t id = toSize_t(line.substr(6,5)); 410 for (size_t index = 11; index <= 26; index+=5) { 411 if (index+5 <= length) { 412 // output += line.substr(index,5) + "|"; 413 const size_t otherid = toSize_t(line.substr(index,5)); 414 ListOfNeighbors.push_back(otherid); 415 } else { 416 break; 417 } 418 } 419 // DoLog(2) && (Log() << Verbose(2) << output << std::endl); 420 421 // add neighbours 422 atom *_atom = World::getInstance().getAtom(AtomById(getAtomId(id))); 423 for (std::list<size_t>::const_iterator iter = ListOfNeighbors.begin(); 424 iter != ListOfNeighbors.end(); 425 ++iter) { 426 // DoLog(1) && (Log() << Verbose(1) << "Adding Bond (" << getAtomId(id) << "," << getAtomId(*iter) << ")" << std::endl); 427 atom * const _Otheratom = World::getInstance().getAtom(AtomById(getAtomId(*iter))); 428 _atom->addBond(_Otheratom); 429 } 330 430 } 331 431 … … 339 439 * \return input string with modified atom IDs 340 440 */ 341 string PdbParser::adaptIdDependentDataString(string data) {441 //string PdbParser::adaptIdDependentDataString(string data) { 342 442 // // there might be no IDs 343 443 // if (data == "-") { … … 358 458 // 359 459 // return result.str(); 360 return ""; 361 } 362 363 364 PdbAtomInfoContainer::PdbAtomInfoContainer() : 365 name("-"), 366 resName("-"), 367 chainID("0"), 368 resSeq("0"), 369 occupancy("0"), 370 tempFactor("0"), 371 segID("0"), 372 charge("0") 373 {} 374 375 void PdbAtomInfoContainer::set(PdbKey::PdbDataKey key, string value) { 376 switch (key) { 377 case PdbKey::extType : 378 extType = value; 379 break; 380 case PdbKey::name : 381 name = value; 382 break; 383 case PdbKey::resName : 384 resName = value; 385 break; 386 case PdbKey::chainID : 387 chainID = value; 388 break; 389 case PdbKey::resSeq : 390 resSeq = value; 391 break; 392 case PdbKey::occupancy : 393 occupancy = value; 394 break; 395 case PdbKey::tempFactor : 396 tempFactor = value; 397 break; 398 case PdbKey::segID : 399 segID = value; 400 break; 401 case PdbKey::charge : 402 charge = value; 403 break; 404 default : 405 cout << "Unknown key: " << key << ", value: " << value << endl; 406 break; 407 } 408 } 409 410 string PdbAtomInfoContainer::get(PdbKey::PdbDataKey key) { 411 switch (key) { 412 case PdbKey::extType : 413 return extType; 414 case PdbKey::name : 415 return name; 416 case PdbKey::resName : 417 return resName; 418 case PdbKey::chainID : 419 return chainID; 420 case PdbKey::resSeq : 421 return resSeq; 422 case PdbKey::occupancy : 423 return occupancy; 424 case PdbKey::tempFactor : 425 return tempFactor; 426 case PdbKey::segID : 427 return segID; 428 case PdbKey::charge : 429 return charge; 430 default : 431 cout << "Unknown key: " << key << endl; 432 return ""; 433 } 434 } 435 460 // return ""; 461 //} 462 463 464 bool PdbParser::operator==(const PdbParser& b) const 465 { 466 bool status = true; 467 World::AtomComposite atoms = World::getInstance().getAllAtoms(); 468 for (World::AtomComposite::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) { 469 if ((additionalAtomData.find((*iter)->getId()) != additionalAtomData.end()) 470 && (b.additionalAtomData.find((*iter)->getId()) != b.additionalAtomData.end())) { 471 const PdbAtomInfoContainer &atomInfo = additionalAtomData.at((*iter)->getId()); 472 const PdbAtomInfoContainer &OtheratomInfo = b.additionalAtomData.at((*iter)->getId()); 473 474 status = status && (atomInfo.get(PdbKey::serial) == OtheratomInfo.get(PdbKey::serial)); 475 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in serials!" << std::endl); 476 status = status && (atomInfo.get(PdbKey::name) == OtheratomInfo.get(PdbKey::name)); 477 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in names!" << std::endl); 478 status = status && (atomInfo.get(PdbKey::altloc) == OtheratomInfo.get(PdbKey::altloc)); 479 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in altlocs!" << std::endl); 480 status = status && (atomInfo.get(PdbKey::resName) == OtheratomInfo.get(PdbKey::resName)); 481 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resNames!" << std::endl); 482 status = status && (atomInfo.get(PdbKey::chainID) == OtheratomInfo.get(PdbKey::chainID)); 483 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in chainIDs!" << std::endl); 484 status = status && (atomInfo.get(PdbKey::resSeq) == OtheratomInfo.get(PdbKey::resSeq)); 485 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in resSeqs!" << std::endl); 486 status = status && (atomInfo.get(PdbKey::iCode) == OtheratomInfo.get(PdbKey::iCode)); 487 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in iCodes!" << std::endl); 488 status = status && (atomInfo.get(PdbKey::occupancy) == OtheratomInfo.get(PdbKey::occupancy)); 489 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in occupancies!" << std::endl); 490 status = status && (atomInfo.get(PdbKey::tempFactor) == OtheratomInfo.get(PdbKey::tempFactor)); 491 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in tempFactors!" << std::endl); 492 status = status && (atomInfo.get(PdbKey::charge) == OtheratomInfo.get(PdbKey::charge)); 493 if (!status) DoeLog(1) && (eLog() << Verbose(1) << "Mismatch in charges!" << std::endl); 494 } 495 } 496 497 return status; 498 } 499 -
src/Parser/PdbParser.hpp
re828c0 r4fbca9c 10 10 11 11 #include <string> 12 #include "Parser/FormatParser.hpp" 12 #include "FormatParser.hpp" 13 #include "PdbAtomInfoContainer.hpp" 14 #include "PdbKey.hpp" 13 15 14 16 /** 15 * Known keys for the Pdb line. 16 */ 17 class PdbKey { 18 public: 19 enum PdbDataKey { 20 noKey, 21 x, 22 Id, 23 Type, 24 extType, 25 name, 26 resName, 27 chainID, 28 resSeq, 29 occupancy, 30 tempFactor, 31 segID, 32 charge 33 }; 34 }; 35 36 /** 37 * Holds tremolo-specific information which is not store in the atom class. 38 */ 39 class PdbAtomInfoContainer { 40 public: 41 PdbAtomInfoContainer(); 42 void set(PdbKey::PdbDataKey key, std::string value); 43 std::string get(PdbKey::PdbDataKey key); 44 std::string name; 45 std::string extType; 46 std::string resName; 47 std::string chainID; 48 std::string resSeq; 49 std::string occupancy; 50 std::string tempFactor; 51 std::string segID; 52 std::string charge; 53 }; 54 55 /** 56 * Loads a tremolo file into the World and saves the World as a tremolo file. 17 * Loads a PDB format 3.2 file into the World and saves the World as a PDB file. 57 18 */ 58 19 class PdbParser : public FormatParser … … 64 25 void save(std::ostream* file); 65 26 27 bool operator==(const PdbParser& b) const; 28 void printAtomInfo(const atom *newAtom) const; 66 29 67 30 private: 68 void readAtomDataLine(string line); 31 enum PdbKey::KnownTokens getToken(string &line); 32 void readAtomDataLine(string &line, molecule *newmol); 69 33 void parseAtomDataKeysLine(string line, int offset); 70 void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId); 71 void processNeighborInformation(); 72 void adaptImprData(); 73 void adaptTorsion(); 74 std::string adaptIdDependentDataString(std::string data); 34 void readNeighbors(std::string &line); 35 // void adaptImprData(); 36 // void adaptTorsion(); 37 // std::string adaptIdDependentDataString(std::string data); 75 38 bool isUsedField(std::string fieldName); 76 39 void writeNeighbors(std::ostream* file, int numberOfNeighbors, atom* currentAtom); 77 40 void saveLine(ostream* file, const atom* currentAtom, const char *name, const int AtomNo, const int ResdueNo); 78 int getAtomId(int atomid) const; 79 void setAtomId(int localatomid, int atomid); 41 42 // internal getter and setter 43 size_t getSerial(const size_t atomid) const; 44 size_t getAtomId(const size_t atomid) const; 45 void setAtomId(const size_t localatomid, const size_t atomid); 80 46 81 47 /** 82 48 * Map to associate the known keys with numbers. 83 49 */ 84 std::map<std::string, PdbKey:: PdbDataKey> knownKeys;50 std::map<std::string, PdbKey::KnownTokens> knownTokens; 85 51 86 52 /** … … 88 54 * file. 89 55 */ 90 std::map< int, PdbAtomInfoContainer> additionalAtomData;56 std::map<size_t, PdbAtomInfoContainer> additionalAtomData; 91 57 92 58 /** … … 99 65 * world. 100 66 */ 101 std::map<int, int> atomIdMap; 67 std::map<size_t, size_t> atomIdMap; 68 69 /** 70 * Maps original atom IDs received from the parsed file to atom IDs in the 71 * world. 72 */ 73 std::set<size_t> SerialSet; 74 102 75 }; 103 76 -
src/unittests/Makefile.am
re828c0 r4fbca9c 35 35 MoleculeDescriptorTest \ 36 36 ObserverTest \ 37 ParserUnitTest \ 37 ParserCommonUnitTest \ 38 ParserTremoloUnitTest \ 38 39 periodentafelTest \ 39 40 PlaneUnittest \ … … 48 49 VectorContentUnitTest \ 49 50 VectorUnitTest 50 51 51 52 52 53 check_PROGRAMS = $(TESTS) 53 54 noinst_PROGRAMS = $(TESTS) TestRunner … … 96 97 MoleculeDescriptorTest.cpp \ 97 98 ObserverTest.cpp \ 98 ParserUnitTest.cpp \ 99 ParserCommonUnitTest.cpp \ 100 ParserTremoloUnitTest.cpp \ 99 101 periodentafelTest.cpp \ 100 102 PlaneUnittest.cpp \ … … 137 139 ObserverTest.hpp \ 138 140 periodentafelTest.hpp \ 139 ParserUnitTest.hpp \ 141 ParserCommonUnitTest.hpp \ 142 ParserTremoloUnitTest.hpp \ 140 143 PlaneUnittest.hpp \ 141 144 RegistryUnitTest.hpp \ … … 203 206 LineUnittest_LDADD = ${ALLLIBS} 204 207 205 LinkedCellUnitTest_SOURCES = UnitTestMain.cpp LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp 208 LinkedCellUnitTest_SOURCES = UnitTestMain.cpp LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp 206 209 LinkedCellUnitTest_LDADD = ${ALLLIBS} 207 210 … … 209 212 ListOfBondsUnitTest_LDADD = ${ALLLIBS} 210 213 211 LogUnitTest_SOURCES = UnitTestMain.cpp logunittest.cpp logunittest.hpp 214 LogUnitTest_SOURCES = UnitTestMain.cpp logunittest.cpp logunittest.hpp 212 215 LogUnitTest_LDADD = ${ALLLIBS} 213 216 … … 227 230 ObserverTest_LDADD = ${ALLLIBS} 228 231 229 ParserUnitTest_SOURCES = UnitTestMain.cpp ParserUnitTest.cpp ParserUnitTest.hpp 230 ParserUnitTest_LDADD = ${ALLLIBS} 232 ParserCommonUnitTest_SOURCES = UnitTestMain.cpp ParserCommonUnitTest.cpp ParserCommonUnitTest.hpp 233 ParserCommonUnitTest_LDADD = ${ALLLIBS} 234 235 ParserTremoloUnitTest_SOURCES = UnitTestMain.cpp ParserTremoloUnitTest.cpp ParserTremoloUnitTest.hpp 236 ParserTremoloUnitTest_LDADD = ${ALLLIBS} 231 237 232 238 periodentafelTest_SOURCES = UnitTestMain.cpp periodentafelTest.cpp periodentafelTest.hpp -
src/unittests/ParserCommonUnitTest.cpp
re828c0 r4fbca9c 7 7 8 8 /* 9 * Parser UnitTest.cpp9 * ParserCommonUnitTest.cpp 10 10 * 11 11 * Created on: Mar 3, 2010 … … 18 18 #endif 19 19 20 #include "Parser UnitTest.hpp"20 #include "ParserCommonUnitTest.hpp" 21 21 22 22 #include <cppunit/CompilerOutputter.h> … … 25 25 26 26 #include "Parser/MpqcParser.hpp" 27 #include "Parser/PdbParser.hpp" 27 28 #include "Parser/PcpParser.hpp" 28 29 #include "Parser/TremoloParser.hpp" … … 41 42 42 43 // Registers the fixture into the 'registry' 43 CPPUNIT_TEST_SUITE_REGISTRATION( Parser UnitTest );44 CPPUNIT_TEST_SUITE_REGISTRATION( ParserCommonUnitTest ); 44 45 45 46 static string waterPcp = "# ParallelCarParinello - main configuration file - created with molecuilder\n\ … … 117 118 Ion_Type1_1\t0.758602\t0.000000000\t0.504284\t0 # molecule nr 1\n\ 118 119 Ion_Type1_2\t0.758602\t0.000000000\t-0.504284\t0 # molecule nr 2\n"; 120 //----|----*|---||--*||---|***|-------|-------|-------|-----|---------------|-|- 121 //000000011111111112222222222333333333344444444445555555555666666666677777777778 122 //345678901234567890123456789012345678901234567890123456789012345678901234567890 123 static string waterPdb = "\ 124 REMARK This is a test water molecule as written by TREMOLO.\n\ 125 ATOM 1 OT GMT- 0 1.583 1.785 1.480 1.00178.02 O-2\n\ 126 ATOM 2 HT GMT- 0 1.186 1.643 2.213 1.00103.58 H+1\n\ 127 ATOM 3 HT GMT- 0 2.642 1.896 1.730 1.00126.00 H+1\n\ 128 ATOM 4 OT GMT- 1 3.583 1.785 1.480 1.00178.02 O-2\n\ 129 ATOM 5 HT GMT- 1 3.186 1.643 2.213 1.00103.58 H+1\n\ 130 ATOM 6 HT GMT- 1 4.642 1.896 1.730 1.00126.00 H+1\n\ 131 CONECT 1 2 3\n\ 132 CONECT 2 1\n\ 133 CONECT 3 1\n\ 134 CONECT 4 5 6\n\ 135 CONECT 5 4\n\ 136 CONECT 6 4\n\ 137 END"; 119 138 static string waterMpqc ="% Created by MoleCuilder\n\ 120 139 mpqc: (\n\ … … 144 163 )\n"; 145 164 static string waterXyz = "3\n\tH2O: water molecule\nO\t0\t0\t0\nH\t0.758602\t0\t0.504284\nH\t0.758602\t0\t-0.504284\n"; 146 static string Tremolo_Atomdata1 = "# ATOMDATA\tId\tname\tType\tx=3\n"; 147 static string Tremolo_Atomdata2 = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n"; 148 static string Tremolo_invalidkey = "#\n#ATOMDATA Id name foo Type x=3\n\n\n"; 149 static string Tremolo_velocity = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n"; 150 static string Tremolo_neighbours = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n"; 151 static string Tremolo_improper = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n"; 152 static string Tremolo_torsion = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n"; 153 static string Tremolo_full = "# ATOMDATA\tx=3\tu=3\tF\tstress\tId\tneighbors=5\timprData\tGroupMeasureTypeNo\tType\textType\tname\tresName\tchainID\tresSeq\toccupancy\ttempFactor\tsegID\tCharge\tcharge\tGrpTypeNo\ttorsion\n0\t0\t0\t0\t0\t0\t0\t0\t1\t0\t0\t0\t0\t0\t-\t0\tH\t-\t-\t-\t0\t0\t0\t0\t0\t0\t0\t0\t-\t\n"; 154 155 void ParserUnitTest::setUp() { 165 166 void ParserCommonUnitTest::setUp() { 156 167 World::getInstance(); 168 169 setVerbosity(2); 157 170 158 171 // we need hydrogens and oxygens in the following tests … … 161 174 } 162 175 163 void Parser UnitTest::tearDown() {176 void ParserCommonUnitTest::tearDown() { 164 177 ChangeTracker::purgeInstance(); 165 178 World::purgeInstance(); … … 168 181 /************************************ tests ***********************************/ 169 182 170 void Parser UnitTest::rewriteAnXyzTest() {183 void ParserCommonUnitTest::rewriteAnXyzTest() { 171 184 cout << "Testing the XYZ parser." << endl; 172 185 XyzParser* testParser = new XyzParser(); … … 185 198 } 186 199 187 void ParserUnitTest::readTremoloPreliminaryCommentsTest() { 188 cout << "Testing the tremolo parser." << endl; 189 TremoloParser* testParser = new TremoloParser(); 190 stringstream input, output; 191 192 // Atomdata beginning with "# ATOMDATA" 193 input << Tremolo_Atomdata1; 194 testParser->load(&input); 195 testParser->save(&output); 196 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str()); 197 input.clear(); 198 output.clear(); 199 200 // Atomdata beginning with "#ATOMDATA" 201 input << Tremolo_Atomdata2; 202 testParser->load(&input); 203 testParser->save(&output); 204 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos); 205 input.clear(); 206 output.clear(); 207 208 // Invalid key in Atomdata line 209 input << Tremolo_invalidkey; 210 testParser->load(&input); 211 //TODO: proove invalidity 212 input.clear(); 213 } 214 215 void ParserUnitTest::readTremoloCoordinatesTest() { 216 TremoloParser* testParser = new TremoloParser(); 217 stringstream input; 218 219 // One simple data line 220 input << Tremolo_Atomdata2; 221 testParser->load(&input); 222 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0); 223 input.clear(); 224 } 225 226 void ParserUnitTest::readTremoloVelocityTest() { 227 TremoloParser* testParser = new TremoloParser(); 228 stringstream input; 229 230 // One simple data line 231 input << Tremolo_velocity; 232 testParser->load(&input); 233 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->AtomicVelocity[0] == 3.0); 234 input.clear(); 235 } 236 237 void ParserUnitTest::readTremoloNeighborInformationTest() { 238 TremoloParser* testParser = new TremoloParser(); 239 stringstream input; 240 241 // Neighbor data 242 input << Tremolo_neighbours; 243 testParser->load(&input); 244 245 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 246 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))-> 247 IsBondedTo(World::getInstance().getAtom(AtomByType(1)))); 248 input.clear(); 249 } 250 251 void ParserUnitTest::readAndWriteTremoloImprDataInformationTest() { 252 TremoloParser* testParser = new TremoloParser(); 253 stringstream input, output; 254 255 // Neighbor data 256 input << Tremolo_improper; 257 testParser->load(&input); 258 testParser->save(&output); 259 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 260 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos); 261 input.clear(); 262 output.clear(); 263 } 264 265 void ParserUnitTest::readAndWriteTremoloTorsionInformationTest() { 266 TremoloParser* testParser = new TremoloParser(); 267 stringstream input, output; 268 269 // Neighbor data 270 input << Tremolo_torsion; 271 testParser->load(&input); 272 testParser->save(&output); 273 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 274 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos); 275 input.clear(); 276 output.clear(); 277 } 278 279 void ParserUnitTest::writeTremoloTest() { 280 TremoloParser* testParser = new TremoloParser(); 281 stringstream output; 282 283 // with the maximum number of fields and minimal information, default values are printed 284 atom* newAtom = World::getInstance().createAtom(); 285 newAtom->setType(1); 286 testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo Type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion"); 287 testParser->save(&output); 288 CPPUNIT_ASSERT(output.str() == Tremolo_full); 289 290 cout << "testing the tremolo parser is done" << endl; 291 } 292 293 void ParserUnitTest::readwritePcpTest() { 200 void ParserCommonUnitTest::readwritePcpTest() { 294 201 stringstream input(waterPcp); 295 202 PcpParser* testParser = new PcpParser(); … … 299 206 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 300 207 301 string newWaterPcp = ""; 302 stringstream output; 303 testParser->save(&output); 304 305 input << output; 208 // check that equality function is ok 209 CPPUNIT_ASSERT(*testParser == *testParser); 210 211 stringstream output; 212 testParser->save(&output); 213 214 input << output.str(); 306 215 PcpParser* testParser2 = new PcpParser(); 307 216 testParser2->load(&input); … … 312 221 } 313 222 314 void ParserUnitTest::writeMpqcTest() { 223 void ParserCommonUnitTest::readwritePdbTest() { 224 stringstream input; 225 input << waterPdb; 226 PdbParser* testParser = new PdbParser(); 227 testParser->load(&input); 228 input.clear(); 229 230 CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms()); 231 232 stringstream output; 233 testParser->save(&output); 234 235 // std::cout << "Save PDB is:" << std::endl; 236 // std::cout << output.str() << std::endl; 237 238 input << output.str(); 239 PdbParser* testParser2 = new PdbParser(); 240 testParser2->load(&input); 241 242 CPPUNIT_ASSERT_EQUAL(12, World::getInstance().numAtoms()); 243 } 244 245 void ParserCommonUnitTest::writeMpqcTest() { 315 246 // build up water molecule 316 247 atom *Walker = NULL; -
src/unittests/ParserTremoloUnitTest.hpp
re828c0 r4fbca9c 1 1 /* 2 * Parser UnitTest.hpp2 * ParserTremoloUnitTest.hpp 3 3 * 4 4 * Created on: Mar 3, 2010 5 5 * Author: metzler 6 6 */ 7 #ifndef PARSER UNITTEST_HPP_8 #define PARSER UNITTEST_HPP_7 #ifndef PARSERTREMOLOUNITTEST_HPP_ 8 #define PARSERTREMOLOUNITTEST_HPP_ 9 9 10 10 #include <cppunit/extensions/HelperMacros.h> 11 11 #include <string> 12 12 13 class Parser UnitTest : public CppUnit::TestFixture13 class ParserTremoloUnitTest : public CppUnit::TestFixture 14 14 { 15 CPPUNIT_TEST_SUITE( ParserUnitTest ) ; 16 CPPUNIT_TEST ( rewriteAnXyzTest ); 15 CPPUNIT_TEST_SUITE( ParserTremoloUnitTest ) ; 17 16 CPPUNIT_TEST ( readTremoloPreliminaryCommentsTest ); 18 17 CPPUNIT_TEST ( readTremoloCoordinatesTest ); … … 22 21 CPPUNIT_TEST ( readAndWriteTremoloTorsionInformationTest ); 23 22 CPPUNIT_TEST ( writeTremoloTest ); 24 CPPUNIT_TEST ( readwritePcpTest );25 CPPUNIT_TEST ( writeMpqcTest );26 23 CPPUNIT_TEST_SUITE_END(); 27 24 … … 30 27 void tearDown(); 31 28 32 void rewriteAnXyzTest();33 29 void readTremoloPreliminaryCommentsTest(); 34 30 void readTremoloCoordinatesTest(); … … 38 34 void readAndWriteTremoloTorsionInformationTest(); 39 35 void writeTremoloTest(); 40 void readwritePcpTest();41 void writeMpqcTest();42 36 }; 43 37 44 #endif /* PARSER UNITTEST_HPP_ */38 #endif /* PARSERTREMOLOUNITTEST_HPP_ */
Note:
See TracChangeset
for help on using the changeset viewer.