Changeset cbd409 for src/molecule.cpp


Ignore:
Timestamp:
Feb 11, 2016, 8:06:48 AM (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:
687ef1
Parents:
d93d2c
git-author:
Frederik Heber <heber@…> (01/20/16 20:02:03)
git-committer:
Frederik Heber <heber@…> (02/11/16 08:06:48)
Message:

Added Cacheable MoleculeCenter to molecule which is cleverly updated.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    rd93d2c rcbd409  
    7272
    7373// static entities
    74 static Observable::channels_t getBoundingBoxChannels()
     74static Observable::channels_t getAtomPositionsChannels()
    7575{
    7676  Observable::channels_t channels;
     
    9696  BoundingBoxSweepingAxis(std::vector<AtomDistanceMap_t>(NDIM)),
    9797  _lastchangedatomid(-1),
    98   last_atom(0)
     98  last_atom(0),
     99  molcenter(zeroVec)
    99100{
    100101  // add specific channels
     
    107108  BoundingBox.reset(
    108109      new Cacheable<BoundingBoxInfo>(
    109           this, boost::bind(&molecule::updateBoundingBox, this), "molecule_BoundingBox", getBoundingBoxChannels()));
     110          this, boost::bind(&molecule::updateBoundingBox, this), "molecule_BoundingBox", getAtomPositionsChannels()));
     111  MoleculeCenter.reset(
     112      new Cacheable<Vector>(
     113          this, boost::bind(&molecule::updateMoleculeCenter, this), "molecule_center", getAtomPositionsChannels()));
    110114
    111115  strcpy(name,World::getInstance().getDefaultName().c_str());
     
    272276  }
    273277  {
     278    molcenter -= _atom->getPosition();
     279  }
     280  {
    274281    NOTIFY(AtomNrChanged);
    275282    atomIdPool.releaseId(_atom->getNr());
     
    306313      if (oldinfo != newinfo)
    307314        NOTIFY(BoundingBoxChanged);
     315    }
     316    {
     317      molcenter += key->getPosition();
    308318    }
    309319    NOTIFY(AtomNrChanged);
     
    10921102}
    10931103
     1104Vector molecule::updateMoleculeCenter() const
     1105{
     1106  return (1./(double)getAtomCount())*molcenter;
     1107}
     1108
    10941109molecule::BoundingBoxInfo molecule::getBoundingBox() const
    10951110{
    10961111  return **BoundingBox;
     1112}
     1113
     1114Vector molecule::getMoleculeCenter() const
     1115{
     1116  return **MoleculeCenter;
    10971117}
    10981118
     
    11161136        // emit others about one of our atoms moved
    11171137        _lastchangedatomid = _atom->getId();
    1118         // update entry in map
     1138        // update entry in map and also molecule center
    11191139        BoundingBoxInfo oldinfo = updateBoundingBox();
    11201140        for (int i=0;i<NDIM;++i) {
     
    11231143              "molecule::recieveNotification() - could not find atom "+toString(_atom->getId())
    11241144              +" in BoundingBoxSweepingAxis.");
     1145          molcenter[i] -= iter->second;
    11251146          BoundingBoxSweepingAxis[i].left.erase(iter);
     1147          const Vector &position = _atom->getPosition();
    11261148          BoundingBoxSweepingAxis[i].left.insert(
    1127               std::make_pair(_atom->getId(), _atom->getPosition()[i]) );
     1149              std::make_pair(_atom->getId(), position[i]) );
     1150          molcenter[i] += position[i];
    11281151        }
    11291152        BoundingBoxInfo newinfo = updateBoundingBox();
    11301153        OBSERVE;
    11311154        NOTIFY(AtomMoved);
     1155        NOTIFY(MoleculeCenterChanged);
    11321156        if (oldinfo != newinfo)
    11331157          NOTIFY(BoundingBoxChanged);
Note: See TracChangeset for help on using the changeset viewer.