Changeset e39e7a for src/molecule.cpp


Ignore:
Timestamp:
Jan 31, 2016, 12:43:17 PM (9 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:
6a922b
Parents:
e3e52a
git-author:
Frederik Heber <heber@…> (08/31/15 12:38:50)
git-committer:
Frederik Heber <heber@…> (01/31/16 12:43:17)
Message:

Implemented more efficient per-molecule bounding box information.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    re3e52a re39e7a  
    3636
    3737#include <algorithm>
     38#include <boost/assign.hpp>
    3839#include <boost/bind.hpp>
    3940#include <boost/foreach.hpp>
     
    5051#include "CodePatterns/enumeration.hpp"
    5152#include "CodePatterns/Log.hpp"
     53#include "CodePatterns/Observer/Observable.hpp"
    5254#include "CodePatterns/Observer/Notification.hpp"
    5355#include "config.hpp"
     
    6769#include "WorldTime.hpp"
    6870
     71using namespace boost::assign;
     72
     73// static entities
     74static Observable::channels_t getBoundingBoxChannels()
     75{
     76  Observable::channels_t channels;
     77  channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
     78  return channels;
     79}
    6980
    7081/************************************* Functions for class molecule *********************************/
     
    8394  BondCount(this,boost::bind(&molecule::doCountBonds,this),"BondCount"),
    8495  atomIdPool(1, 20, 100),
     96  BoundingBoxSweepingAxis(std::vector<AtomDistanceMap_t>(NDIM)),
    8597  _lastchangedatomid(-1),
    8698  last_atom(0)
     
    92104    OurChannel->addChannel(type);
    93105
     106  // cannot initialize in initializer body as then channels have not been setup yet
     107  BoundingBox.reset(
     108      new Cacheable<BoundingBoxInfo>(
     109          this, boost::bind(&molecule::updateBoundingBox, boost::cref(this)), "molecule_BoundingBox", getBoundingBoxChannels()));
     110
    94111  strcpy(name,World::getInstance().getDefaultName().c_str());
    95 };
     112}
    96113
    97114molecule *NewMolecule(){
     
    177194  atomIds.erase( oldId );
    178195  atomIds.insert( newId );
     196  // also update BoundingBoxSweepingAxis
     197  for (int i=0;i<NDIM;++i) {
     198    AtomDistanceMap_t::left_iterator iter = BoundingBoxSweepingAxis[i].left.find(oldId);
     199    ASSERT(iter != BoundingBoxSweepingAxis[i].left.end(),
     200        "molecule::changeAtomId() - could not find atom "+toString(oldId)
     201        +" in BoundingBoxSweepingAxis.");
     202    const double component = iter->second;
     203    BoundingBoxSweepingAxis[i].left.erase(iter);
     204    BoundingBoxSweepingAxis[i].left.insert( std::make_pair(newId, component) );
     205  }
    179206  return true;
    180207}
     
    237264  atomIds.erase( _atom->getId() );
    238265  {
     266    BoundingBoxInfo oldinfo = updateBoundingBox();
     267    for (int i=0;i<NDIM;++i)
     268      BoundingBoxSweepingAxis[i].left.erase( _atom->getId() );
     269    BoundingBoxInfo newinfo = updateBoundingBox();
     270    if (oldinfo != newinfo)
     271      NOTIFY(BoundingBoxChanged);
     272  }
     273  {
    239274    NOTIFY(AtomNrChanged);
    240275    atomIdPool.releaseId(_atom->getNr());
     
    264299  std::pair<iterator,bool> res = atomIds.insert(key->getId());
    265300  if (res.second) { // push atom if went well
     301    {
     302      BoundingBoxInfo oldinfo = updateBoundingBox();
     303      for (int i=0;i<NDIM;++i)
     304        BoundingBoxSweepingAxis[i].left.insert( std::make_pair(key->getId(), key->getPosition()[i]));
     305      BoundingBoxInfo newinfo = updateBoundingBox();
     306      if (oldinfo != newinfo)
     307        NOTIFY(BoundingBoxChanged);
     308    }
    266309    NOTIFY(AtomNrChanged);
    267310    key->setNr(atomIdPool.getNextId());
     
    10331076}
    10341077
     1078molecule::BoundingBoxInfo molecule::updateBoundingBox() const
     1079{
     1080  BoundingBoxInfo info;
     1081  Vector min = zeroVec;
     1082  Vector max = zeroVec;
     1083  for (int i=0;i<NDIM;++i) {
     1084    if (!BoundingBoxSweepingAxis[i].right.empty()) {
     1085      min[i] = BoundingBoxSweepingAxis[i].right.begin()->first;
     1086      max[i] = BoundingBoxSweepingAxis[i].right.rbegin()->first;
     1087    }
     1088  }
     1089  info.radius = (.5*(max-min)).Norm();
     1090  info.position = .5*(max+min);
     1091  return info;
     1092}
     1093
     1094molecule::BoundingBoxInfo molecule::getBoundingBox() const
     1095{
     1096  return **BoundingBox;
     1097}
     1098
    10351099void molecule::update(Observable *publisher)
    10361100{
     
    10521116        // emit others about one of our atoms moved
    10531117        _lastchangedatomid = _atom->getId();
     1118        // update entry in map
     1119        BoundingBoxInfo oldinfo = updateBoundingBox();
     1120        for (int i=0;i<NDIM;++i) {
     1121          AtomDistanceMap_t::left_iterator iter = BoundingBoxSweepingAxis[i].left.find(_atom->getId());
     1122          ASSERT(iter != BoundingBoxSweepingAxis[i].left.end(),
     1123              "molecule::recieveNotification() - could not find atom "+toString(_atom->getId())
     1124              +" in BoundingBoxSweepingAxis.");
     1125          BoundingBoxSweepingAxis[i].left.erase(iter);
     1126          BoundingBoxSweepingAxis[i].left.insert(
     1127              std::make_pair(_atom->getId(), _atom->getPosition()[i]) );
     1128        }
     1129        BoundingBoxInfo newinfo = updateBoundingBox();
    10541130        OBSERVE;
    10551131        NOTIFY(AtomMoved);
     1132        if (oldinfo != newinfo)
     1133          NOTIFY(BoundingBoxChanged);
    10561134        break;
    10571135      }
Note: See TracChangeset for help on using the changeset viewer.