Changeset c6ab91 for src


Ignore:
Timestamp:
Apr 14, 2013, 6:35:27 PM (12 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:
78ca37
Parents:
356ae4
git-author:
Frederik Heber <heber@…> (03/04/13 17:40:55)
git-committer:
Frederik Heber <heber@…> (04/14/13 18:35:27)
Message:

Wrote faster molecule::FindAtom().

  • due to local id nature in Fragmentation many functions there make heavy use of this function. However, has it scales linearly, this severly limits the abilitiy to tackle large molecules.
  • as quick short-cut we installed a map from local to global ids, updated by insert() and erase() and used by FindAtom().
Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    r356ae4 rc6ab91  
    132132}
    133133
     134void molecule::InsertLocalToGlobalId(atom * const pointer)
     135{
     136#ifndef NDEBUG
     137  std::pair< LocalToGlobalId_t::iterator, bool > inserter =
     138#endif
     139      LocalToGlobalId.insert( std::make_pair(pointer->getNr(), pointer) );
     140  ASSERT( inserter.second,
     141      "molecule::AddAtom() - local number "+toString(pointer->getNr())+" appears twice.");
     142}
     143
    134144bool molecule::changeAtomNr(int oldNr, int newNr, atom* target){
    135145  OBSERVE;
     
    138148    if (oldNr != -1)  // -1 is reserved and indicates no number
    139149      atomIdPool.releaseId(oldNr);
     150    LocalToGlobalId.erase(oldNr);
    140151    ASSERT (target,
    141152        "molecule::changeAtomNr() - given target is NULL, cannot set Nr or name.");
    142153    target->setNr(newNr);
     154    InsertLocalToGlobalId(target);
    143155    setAtomName(target);
    144156    return true;
     
    202214    NOTIFY(AtomNrChanged);
    203215    atomIdPool.releaseId(_atom->getNr());
     216    LocalToGlobalId.erase(_atom->getNr());
    204217    _atom->setNr(-1);
    205218  }
     
    220233      NOTIFY(AtomNrChanged);
    221234      atomIdPool.releaseId(key->getNr());
     235      LocalToGlobalId.erase(key->getNr());
    222236      key->setNr(-1);
    223237    }
     
    236250    NOTIFY(AtomNrChanged);
    237251    key->setNr(atomIdPool.getNextId());
     252    InsertLocalToGlobalId(key);
    238253    setAtomName(key);
    239254    formula+=key->getType();
     
    283298  if (pointer != NULL) {
    284299    atom *walker = pointer->clone();
    285     walker->setName(pointer->getName());
    286     walker->setNr(last_atom++);  // increase number within molecule
    287     insert(walker);
    288     walker->setMolecule(this);
     300    AddAtom(walker);
    289301    retval=walker;
    290302  }
     
    777789atom * molecule::FindAtom(int Nr)  const
    778790{
    779   molecule::iterator iter = begin();
    780   for (; iter != end(); ++iter)
    781   if ((*iter)->getNr() == Nr)
    782     break;
    783   if (iter != end()) {
     791  LocalToGlobalId_t::const_iterator iter = LocalToGlobalId.find(Nr);
     792  if (iter != LocalToGlobalId.end()) {
    784793    //LOG(0, "Found Atom Nr. " << walker->getNr());
    785     return (*iter);
     794    return iter->second;
    786795  } else {
    787796    ELOG(1, "Atom with Nr " << Nr << " not found in molecule " << getName() << "'s list.");
  • src/molecule.hpp

    r356ae4 rc6ab91  
    8888  AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
    8989  IdPool<atomId_t, uniqueId> atomIdPool;  //!< pool of internal ids such that way may guarantee uniqueness
     90  typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
     91  LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
    9092
    9193protected:
     
    220222   */
    221223  bool changeAtomNr(int oldNr, int newNr, atom* target=0);
     224
     225  /** Updates the internal lookup fro local to global indices.
     226   *
     227   * \param pointer pointer to atom
     228   */
     229  void InsertLocalToGlobalId(atom * const pointer);
    222230
    223231  /** Sets the name of the atom.
Note: See TracChangeset for help on using the changeset viewer.