Ignore:
Timestamp:
Jan 6, 2012, 2:02:08 PM (13 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

FIX: One could not load another pdb file due to local ids messing up.

  • We enhanced FormatParser_common now contains two maps to go from local to global and back again. Thi is necessary, as ids in a file only make sense within that file. We added the following functions: resetIdAssociations(), associateLocaltoGlobalId(), getGlobalId(), getLocalId().
  • adapted TremoloParser and PdbParser because they are the only formats that also contain bond information and where the associations are needed to translate the local connections into global ones.
  • removed SerialSet entirely from PdbParser, is replaced by new construct, in similar manner AtomIdMap for TremoloParser.
  • TEST: Added regression tests for all Parser to check for loading twice the same file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/PdbParser.cpp

    rfbbcde rc0e28c  
    7676  PdbAtomInfoContainer::clearknownDataKeys();
    7777  additionalAtomData.clear();
    78   atomIdMap.clear();
    7978}
    8079
     
    118117  enum PdbKey::KnownTokens token;
    119118
    120   // reset atomIdMap for this file (to correctly parse CONECT entries)
    121   atomIdMap.clear();
     119  // reset id maps for this file (to correctly parse CONECT entries)
     120  resetIdAssociations();
    122121
    123122  bool NotEndOfFile = true;
     
    192191
    193192  // re-distribute serials
     193  resetIdAssociations();
    194194  // (new atoms might have been added)
    195   // (serials must be consistent over time steps)
    196   atomIdMap.clear();
    197195  int AtomNo = 1; // serial number starts at 1 in pdb
    198196  for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
    199197    PdbAtomInfoContainer &atomInfo = getadditionalAtomData(*atomIt);
    200     setSerial((*atomIt)->getId(), AtomNo);
     198    associateLocaltoGlobalId(AtomNo, (*atomIt)->getId());
    201199    atomInfo.set(PdbKey::serial, toString(AtomNo));
    202     AtomNo++;
     200    ++AtomNo;
    203201  }
    204202
     
    305303  // don't insert here as this is our check whether we are in the first time step
    306304  //additionalAtomData.insert( std::make_pair(id, defaultAdditionalData) );
    307   //SerialSet.insert(id);
    308305}
    309306
     
    321318//      +toString(id)+" to remove.");
    322319  if (iter != additionalAtomData.end()) {
    323     ConvertTo<size_t> toSize_t;
    324     SerialSet.erase(toSize_t((iter->second).get<std::string>(PdbKey::serial)));
    325320    additionalAtomData.erase(iter);
    326321  }
     
    439434      if (MaxNo >= MaxnumberOfNeighbors) {
    440435        *file << "CONECT";
    441         *file << setw(5) << getSerial(currentAtom->getId());
     436        *file << setw(5) << getLocalId(currentAtom->getId());
    442437        charsleft = 80-6-5;
    443438        MaxNo = 0;
    444439      }
    445       *file << setw(5) << getSerial((*currentBond)->GetOtherAtom(currentAtom)->getId());
     440      *file << setw(5) << getLocalId((*currentBond)->GetOtherAtom(currentAtom)->getId());
    446441      charsleft -= 5;
    447442      MaxNo++;
     
    460455}
    461456
    462 /** Retrieves a value from  FormatParser< pdb >::atomIdMap.
    463  * \param atomid key
    464  * \return value
    465  */
    466 size_t FormatParser< pdb >::getSerial(const size_t atomid) const
    467 {
    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 key
    475  * \param atomid value
    476  * \return true - key not present, false - value present
    477  */
    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 
    486457/** Either returns present atom with given id or a newly created one.
    487458 *
     
    489460 * @return
    490461 */
    491 atom* FormatParser< pdb >::getAtomToParse(std::string id_string) const
     462atom* FormatParser< pdb >::getAtomToParse(std::string id_string)
    492463{
    493464  // get the local ID
    494465  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)+".");
    497468  // get the atomic ID if present
    498469  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 << ".");
    503473    // check if atom exists
    504     newAtom = World::getInstance().getAtom(AtomById(AtomID));
     474    newAtom = World::getInstance().getAtom(AtomById(AtomID_global));
    505475    LOG(5, "INFO: Listing all present atoms with id.");
    506476    BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms())
     
    510480  if (newAtom == NULL) {
    511481    newAtom = World::getInstance().createAtom();
     482    const unsigned int AtomID_global = newAtom->getId();
    512483    LOG(4, "INFO: No association to global id present, creating atom.");
    513484  } else {
     
    607578      "FormatParser< pdb >::readAtomDataLine() - additionalAtomData present though atom is newly parsed.");
    608579  if (FirstTimestep) {
    609     LOG(3,"INFO: Parsing new atom.");
     580    LOG(3,"INFO: Parsing new atom "+toString(*newAtom)+" "+toString(newAtom->getId())+".");
    610581  } else {
    611582    LOG(3,"INFO: Parsing present atom "+toString(*newAtom)+".");
     
    616587  string word;
    617588  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 //  }
    627589
    628590  // check whether serial exists, if so, assign next available
     
    648610    // then fill info container
    649611    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());
    657614    // set position
    658615    Vector tempVector;
     
    791748        ListOfNeighbors.push_back(otherid);
    792749      else
    793         ELOG(2, "FormatParser< pdb >::readNeighbors() - discarding conect entry with id 0.");
     750        ELOG(2, "FormatParser< pdb >::readNeighbors() - discarding CONECT entry with id 0.");
    794751    } else  {
    795752      break;
     
    799756
    800757  // add neighbours
    801   atom *_atom = World::getInstance().getAtom(AtomById(getSerial(id)));
     758  atom *_atom = World::getInstance().getAtom(AtomById(getGlobalId(id)));
    802759  LOG(2, "STATUS: Atom " << _atom->getId() << " gets " << ListOfNeighbors.size() << " more neighbours.");
    803760  for (std::list<size_t>::const_iterator iter = ListOfNeighbors.begin();
    804761      iter != ListOfNeighbors.end();
    805762      ++iter) {
    806     atom * const _Otheratom = World::getInstance().getAtom(AtomById(getSerial(*iter)));
     763    atom * const _Otheratom = World::getInstance().getAtom(AtomById(getGlobalId(*iter)));
    807764    LOG(3, "INFO: Adding Bond (" << *_atom << "," << *_Otheratom << ")");
    808765    _atom->addBond(_step, _Otheratom);
    809766  }
    810767}
    811 
    812 /**
    813  * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
    814  * IDs of the input string will be replaced; expected separating characters are
    815  * "-" and ",".
    816  *
    817  * \param string in which atom IDs should be adapted
    818  *
    819  * \return input string with modified atom IDs
    820  */
    821 //string  FormatParser< pdb >::adaptIdDependentDataString(string data) {
    822 //  // there might be no IDs
    823 //  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 
    843768
    844769bool FormatParser< pdb >::operator==(const FormatParser< pdb >& b) const
Note: See TracChangeset for help on using the changeset viewer.