Changeset c0e28c for src/Parser
- Timestamp:
- Jan 6, 2012, 2:02:08 PM (13 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:
- d08ab3
- Parents:
- fbbcde
- git-author:
- Frederik Heber <heber@…> (01/04/12 18:34:22)
- git-committer:
- Frederik Heber <heber@…> (01/06/12 14:02:08)
- Location:
- src/Parser
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/FormatParser_common.cpp
rfbbcde rc0e28c 52 52 if (parameters != NULL) 53 53 delete parameters; 54 // clear id translation maps 55 LocaltoGobalIdMap.clear(); 56 GlobaltoLocalIdMap.clear(); 54 57 } 55 58 … … 95 98 * \param ostream where to save the World's state 96 99 */ 97 void FormatParser_common::setOstream(ostream* output) { 100 void FormatParser_common::setOstream(ostream* output) 101 { 98 102 saveStream = output; 99 103 } 104 105 /** Function to be called when beginning to parse a new file. 106 * 107 * Resets internal translation maps. 108 * 109 */ 110 void FormatParser_common::resetIdAssociations() 111 { 112 LocaltoGobalIdMap.clear(); 113 GlobaltoLocalIdMap.clear(); 114 } 115 116 /** Installs an association between a local id from a parsed file and the 117 * global, unique one. 118 * 119 * @param local local atom id 120 * @param global global atom id 121 */ 122 void FormatParser_common::associateLocaltoGlobalId(const int local, const int global) 123 { 124 ASSERT(LocaltoGobalIdMap.count(local) == 0, 125 "FormatParser_common::associateLocaltoGlobalId() - local id " 126 +toString(local)+" is already contained."); 127 ASSERT(GlobaltoLocalIdMap.count(global) == 0, 128 "FormatParser_common::associateLocaltoGlobalId() - global id " 129 +toString(global)+" is already contained."); 130 LocaltoGobalIdMap[local] = global; 131 GlobaltoLocalIdMap[global] = local; 132 } 133 134 /** Getter for the global id to a given \a local one. 135 * 136 * @param local local atom id 137 * @return global atom id, -1 if unknown 138 */ 139 int FormatParser_common::getGlobalId(const int local) const 140 { 141 IdtoIdMap::const_iterator iter = LocaltoGobalIdMap.find(local); 142 if(iter == LocaltoGobalIdMap.end()) 143 return -1; 144 return iter->second; 145 } 146 147 /** Getter for the local id to a given \a global one. 148 * 149 * @param global global atom id 150 * @return local atom id, -1 if unknown 151 */ 152 int FormatParser_common::getLocalId(const int global) const 153 { 154 IdtoIdMap::const_iterator iter = GlobaltoLocalIdMap.find(global); 155 if(iter == GlobaltoLocalIdMap.end()) 156 return -1; 157 return iter->second; 158 } -
src/Parser/FormatParser_common.hpp
rfbbcde rc0e28c 15 15 16 16 #include <iosfwd> 17 #include <map> 17 18 18 19 #include "CodePatterns/Observer/Observer.hpp" … … 49 50 virtual void AtomRemoved(atomId_t) {}; 50 51 52 // functions to add atoms and bonds with ids relative to the parsed file 53 void resetIdAssociations(); 54 void associateLocaltoGlobalId(const int local, const int global); 55 int getGlobalId(const int local) const; 56 int getLocalId(const int global) const; 57 51 58 private: 52 59 //!> Output stream to write to when save() is called. 53 60 std::ostream* saveStream; 61 62 //!> typedef for atomic id-to-id map 63 typedef std::map<int, int> IdtoIdMap; 64 65 //!> Maps original atom IDs received from the parsed file to atom IDs in the world. 66 IdtoIdMap LocaltoGobalIdMap; 67 68 //!> Maps atom IDs in the World to those received from the parsed file. 69 IdtoIdMap GlobaltoLocalIdMap; 54 70 }; 55 71 -
src/Parser/PdbParser.cpp
rfbbcde rc0e28c 76 76 PdbAtomInfoContainer::clearknownDataKeys(); 77 77 additionalAtomData.clear(); 78 atomIdMap.clear();79 78 } 80 79 … … 118 117 enum PdbKey::KnownTokens token; 119 118 120 // reset atomIdMapfor this file (to correctly parse CONECT entries)121 atomIdMap.clear();119 // reset id maps for this file (to correctly parse CONECT entries) 120 resetIdAssociations(); 122 121 123 122 bool NotEndOfFile = true; … … 192 191 193 192 // re-distribute serials 193 resetIdAssociations(); 194 194 // (new atoms might have been added) 195 // (serials must be consistent over time steps)196 atomIdMap.clear();197 195 int AtomNo = 1; // serial number starts at 1 in pdb 198 196 for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) { 199 197 PdbAtomInfoContainer &atomInfo = getadditionalAtomData(*atomIt); 200 setSerial((*atomIt)->getId(), AtomNo);198 associateLocaltoGlobalId(AtomNo, (*atomIt)->getId()); 201 199 atomInfo.set(PdbKey::serial, toString(AtomNo)); 202 AtomNo++;200 ++AtomNo; 203 201 } 204 202 … … 305 303 // don't insert here as this is our check whether we are in the first time step 306 304 //additionalAtomData.insert( std::make_pair(id, defaultAdditionalData) ); 307 //SerialSet.insert(id);308 305 } 309 306 … … 321 318 // +toString(id)+" to remove."); 322 319 if (iter != additionalAtomData.end()) { 323 ConvertTo<size_t> toSize_t;324 SerialSet.erase(toSize_t((iter->second).get<std::string>(PdbKey::serial)));325 320 additionalAtomData.erase(iter); 326 321 } … … 439 434 if (MaxNo >= MaxnumberOfNeighbors) { 440 435 *file << "CONECT"; 441 *file << setw(5) << get Serial(currentAtom->getId());436 *file << setw(5) << getLocalId(currentAtom->getId()); 442 437 charsleft = 80-6-5; 443 438 MaxNo = 0; 444 439 } 445 *file << setw(5) << get Serial((*currentBond)->GetOtherAtom(currentAtom)->getId());440 *file << setw(5) << getLocalId((*currentBond)->GetOtherAtom(currentAtom)->getId()); 446 441 charsleft -= 5; 447 442 MaxNo++; … … 460 455 } 461 456 462 /** Retrieves a value from FormatParser< pdb >::atomIdMap.463 * \param atomid key464 * \return value465 */466 size_t FormatParser< pdb >::getSerial(const size_t atomid) const467 {468 ASSERT(atomIdMap.find(atomid) != atomIdMap.end(),469 "FormatParser< pdb >::getAtomId: atomid "+toString(atomid)+" not present in Map.");470 return (atomIdMap.find(atomid)->second);471 }472 473 /** Sets an entry in FormatParser< pdb >::atomIdMap.474 * \param localatomid key475 * \param atomid value476 * \return true - key not present, false - value present477 */478 void FormatParser< pdb >::setSerial(const size_t localatomid, const size_t atomid)479 {480 pair<std::map<size_t,size_t>::iterator, bool > inserter;481 // LOG(1, "FormatParser< pdb >::setAtomId() - Inserting (" << localatomid << " -> " << atomid << ").");482 inserter = atomIdMap.insert( make_pair(localatomid, atomid) );483 ASSERT(inserter.second, "FormatParser< pdb >::setAtomId: atomId already present in Map.");484 }485 486 457 /** Either returns present atom with given id or a newly created one. 487 458 * … … 489 460 * @return 490 461 */ 491 atom* FormatParser< pdb >::getAtomToParse(std::string id_string) const462 atom* FormatParser< pdb >::getAtomToParse(std::string id_string) 492 463 { 493 464 // get the local ID 494 465 ConvertTo<int> toInt; 495 unsigned int AtomID= toInt(id_string);496 LOG(4, "INFO: Local id is "+toString(AtomID )+".");466 const unsigned int AtomID_local = toInt(id_string); 467 LOG(4, "INFO: Local id is "+toString(AtomID_local)+"."); 497 468 // get the atomic ID if present 498 469 atom* newAtom = NULL; 499 if (atomIdMap.count((size_t)AtomID)) { 500 std::map<size_t, size_t>::const_iterator iter = atomIdMap.find(AtomID); 501 AtomID = iter->second; 502 LOG(4, "INFO: Global id present as " << AtomID << "."); 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 << "."); 503 473 // check if atom exists 504 newAtom = World::getInstance().getAtom(AtomById(AtomID ));474 newAtom = World::getInstance().getAtom(AtomById(AtomID_global)); 505 475 LOG(5, "INFO: Listing all present atoms with id."); 506 476 BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms()) … … 510 480 if (newAtom == NULL) { 511 481 newAtom = World::getInstance().createAtom(); 482 const unsigned int AtomID_global = newAtom->getId(); 512 483 LOG(4, "INFO: No association to global id present, creating atom."); 513 484 } else { … … 607 578 "FormatParser< pdb >::readAtomDataLine() - additionalAtomData present though atom is newly parsed."); 608 579 if (FirstTimestep) { 609 LOG(3,"INFO: Parsing new atom .");580 LOG(3,"INFO: Parsing new atom "+toString(*newAtom)+" "+toString(newAtom->getId())+"."); 610 581 } else { 611 582 LOG(3,"INFO: Parsing present atom "+toString(*newAtom)+"."); … … 616 587 string word; 617 588 ConvertTo<size_t> toSize_t; 618 619 // assign highest+1 instead, but then beware of CONECT entries! Another map needed!620 // if (!Inserter.second) {621 // const size_t id = (*SerialSet.rbegin())+1;622 // SerialSet.insert(id);623 // atomInfo.set(PdbKey::serial, toString(id));624 // ELOG(2, "Serial " << atomInfo.get<std::string>(PdbKey::serial) << " already present, "625 // << "assigning " << toString(id) << " instead.");626 // }627 589 628 590 // check whether serial exists, if so, assign next available … … 648 610 // then fill info container 649 611 readPdbAtomInfoContainer(atomInfo, line); 650 // set the serial 651 std::pair< std::set<size_t>::const_iterator, bool> Inserter = 652 SerialSet.insert(toSize_t(atomInfo.get<std::string>(PdbKey::serial))); 653 ASSERT(Inserter.second, 654 "FormatParser< pdb >::readAtomDataLine() - ATOM contains entry with serial " 655 +atomInfo.get<std::string>(PdbKey::serial)+" already present!"); 656 setSerial(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId()); 612 // associate local with global id 613 associateLocaltoGlobalId(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId()); 657 614 // set position 658 615 Vector tempVector; … … 791 748 ListOfNeighbors.push_back(otherid); 792 749 else 793 ELOG(2, "FormatParser< pdb >::readNeighbors() - discarding conectentry with id 0.");750 ELOG(2, "FormatParser< pdb >::readNeighbors() - discarding CONECT entry with id 0."); 794 751 } else { 795 752 break; … … 799 756 800 757 // add neighbours 801 atom *_atom = World::getInstance().getAtom(AtomById(get Serial(id)));758 atom *_atom = World::getInstance().getAtom(AtomById(getGlobalId(id))); 802 759 LOG(2, "STATUS: Atom " << _atom->getId() << " gets " << ListOfNeighbors.size() << " more neighbours."); 803 760 for (std::list<size_t>::const_iterator iter = ListOfNeighbors.begin(); 804 761 iter != ListOfNeighbors.end(); 805 762 ++iter) { 806 atom * const _Otheratom = World::getInstance().getAtom(AtomById(get Serial(*iter)));763 atom * const _Otheratom = World::getInstance().getAtom(AtomById(getGlobalId(*iter))); 807 764 LOG(3, "INFO: Adding Bond (" << *_atom << "," << *_Otheratom << ")"); 808 765 _atom->addBond(_step, _Otheratom); 809 766 } 810 767 } 811 812 /**813 * Replaces atom IDs read from the file by the corresponding world IDs. All IDs814 * IDs of the input string will be replaced; expected separating characters are815 * "-" and ",".816 *817 * \param string in which atom IDs should be adapted818 *819 * \return input string with modified atom IDs820 */821 //string FormatParser< pdb >::adaptIdDependentDataString(string data) {822 // // there might be no IDs823 // if (data == "-") {824 // return "-";825 // }826 //827 // char separator;828 // int id;829 // stringstream line, result;830 // line << data;831 //832 // line >> id;833 // result << atomIdMap[id];834 // while (line.good()) {835 // line >> separator >> id;836 // result << separator << atomIdMap[id];837 // }838 //839 // return result.str();840 // return "";841 //}842 843 768 844 769 bool FormatParser< pdb >::operator==(const FormatParser< pdb >& b) const -
src/Parser/PdbParser.hpp
rfbbcde rc0e28c 73 73 bool isPresentadditionalAtomData(unsigned int _id); 74 74 PdbAtomInfoContainer& getadditionalAtomData(atom *_atom); 75 size_t getSerial(const size_t atomid) const;76 void setSerial(const size_t localatomid, const size_t atomid);77 75 78 76 // internal helper functions 79 atom* getAtomToParse(std::string id_string) const;77 atom* getAtomToParse(std::string id_string); 80 78 void readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const; 81 79 … … 100 98 */ 101 99 PdbAtomInfoContainer defaultAdditionalData; 102 103 /**104 * Maps original atom IDs received from the parsed file to atom IDs in the105 * world.106 */107 std::map<size_t, size_t> atomIdMap;108 109 /**110 * Ascertaining uniqueness of Ids.111 */112 std::set<size_t> SerialSet;113 100 }; 114 101 -
src/Parser/TremoloParser.cpp
rfbbcde rc0e28c 103 103 usedFields.clear(); 104 104 additionalAtomData.clear(); 105 atomIdMap.clear();106 105 knownKeys.clear(); 107 106 } … … 116 115 string::size_type location; 117 116 118 // reset atomIdMap, for we now get new serials 119 atomIdMap.clear(); 117 // reset the id maps 118 resetIdAssociations(); 119 120 120 LOG(1, "INFO: Clearing usedFields."); 121 121 usedFields.clear(); … … 444 444 ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); 445 445 LOG(4, "INFO: Parsing key " << keyName << " with next token " << *tok_iter); 446 a tomIdMap[toInt(*tok_iter)] = atomid;446 associateLocaltoGlobalId(toInt(*tok_iter), atomid); 447 447 tok_iter++; 448 448 break; … … 525 525 neighbor != currentInfo->second.neighbors.end(); neighbor++ 526 526 ) { 527 // LOG(1, "INFO: Creating bond between (" 528 // << currentInfo->first 529 // << ") and (" 530 // << atomIdMap[*neighbor] << "|" << *neighbor << ")"); 527 LOG(3, "INFO: Creating bond between (" 528 << currentInfo->first 529 << ") and (" 530 << getGlobalId(*neighbor) << "|" << *neighbor << ")"); 531 ASSERT(getGlobalId(*neighbor) != -1, 532 "FormatParser< tremolo >::processNeighborInformation() - global id to local id " 533 +toString(*neighbor)+" is unknown."); 531 534 World::getInstance().getAtom(AtomById(currentInfo->first)) 532 ->addBond(WorldTime::getTime(), World::getInstance().getAtom(AtomById( atomIdMap[*neighbor])));535 ->addBond(WorldTime::getTime(), World::getInstance().getAtom(AtomById(getGlobalId(*neighbor)))); 533 536 } 534 537 currentInfo->second.neighbors_processed = true; … … 558 561 559 562 line >> id; 560 result << atomIdMap[id];563 result << getGlobalId(id); 561 564 while (line.good()) { 562 565 line >> separator >> id; 563 result << separator << atomIdMap[id];566 result << separator << getGlobalId(id); 564 567 } 565 568 -
src/Parser/TremoloParser.hpp
rfbbcde rc0e28c 103 103 */ 104 104 TremoloAtomInfoContainer defaultAdditionalData; 105 106 /**107 * Maps original atom IDs received from the parsed file to atom IDs in the108 * world.109 */110 std::map<int, int> atomIdMap;111 105 }; 112 106 -
src/Parser/unittests/ParserPdbUnitTest.cpp
rfbbcde rc0e28c 66 66 parser = new FormatParser<pdb>(); 67 67 68 setVerbosity( 2);68 setVerbosity(3); 69 69 70 70 // we need hydrogens and oxygens in the following tests … … 94 94 parser->save(&output, atoms); 95 95 96 // std::cout << "Save PDB is:" << std::endl;96 // std::cout << "Save PDB is:" << std::endl; 97 97 // std::cout << output.str() << std::endl; 98 98
Note:
See TracChangeset
for help on using the changeset viewer.