Changeset db7e6d for src


Ignore:
Timestamp:
Oct 6, 2011, 4:06:10 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:
37b2575
Parents:
7188b1
git-author:
Frederik Heber <heber@…> (09/01/11 16:25:34)
git-committer:
Frederik Heber <heber@…> (10/06/11 16:06:10)
Message:

BondedParticle:: register and unregister are private.

  • adding and removing bonds is possible via addBond(), removeBond().
  • this wat we encapsulate the register and unregister and make sure that never a lone bond remains at one side.
  • adapted:
  • Register and UnregisterBond are OBSERVEd.
  • bond::Contains() is const member function now
Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/GraphAction/CreateAdjacencyAction.cpp

    r7188b1 rdb7e6d  
    141141                            if (status) { // create bond if distance is smaller
    142142//                              Log() << Verbose(1) << "Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << "." << endl;
    143                               bond * const Binder = new bond(Walker->father, OtherWalker->father, 1);
     143                              //const bond * Binder =
     144                                  Walker->father->addBond(WorldTime::getTime(), OtherWalker->father);
    144145                              BondCount++;
    145                               Walker->father->RegisterBond(WorldTime::getTime(),Binder);
    146                               OtherWalker->father->RegisterBond(WorldTime::getTime(),Binder);
    147146                            } else {
    148147//                              Log() << Verbose(1) << "Not Adding: distance too great." << endl;
  • src/Bond/bond.cpp

    r7188b1 rdb7e6d  
    6363  // remove this node from the list structure
    6464  if (leftatom != NULL)
    65     leftatom->UnregisterBond(this);
     65    leftatom->removeBond(this);
    6666  // there might be self-bonds
    6767  if ((leftatom != rightatom) && (rightatom != NULL))
    68     rightatom->UnregisterBond(this);
     68    rightatom->removeBond(this);
    6969};
    7070
     
    9494 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
    9595 */
    96 bool bond::Contains(const ParticleInfo * const ptr)
     96bool bond::Contains(const ParticleInfo * const ptr) const
    9797{
    9898  return ((leftatom == ptr) || (rightatom == ptr));
     
    103103 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
    104104 */
    105 bool bond::Contains(const int number)
     105bool bond::Contains(const int number) const
    106106{
    107107  return ((leftatom->getNr() == number) || (rightatom->getNr() == number));
  • src/Bond/bond.hpp

    r7188b1 rdb7e6d  
    4444  atom * GetOtherAtom(const ParticleInfo * const Atom) const;
    4545
    46   bool Contains(const ParticleInfo * const ptr);
    47   bool Contains(const int nr);
     46  bool Contains(const ParticleInfo * const ptr) const;
     47  bool Contains(const int nr) const;
    4848  double GetDistance() const;
    4949  double GetDistanceSquared() const;
  • src/Graph/BondGraph.cpp

    r7188b1 rdb7e6d  
    199199                          if (status) { // create bond if distance is smaller
    200200                            LOG(1, "ACCEPT: Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << ".");
    201                             bond * Binder = new bond(Walker->father, OtherWalker->father, 1);
    202                             Walker->father->RegisterBond(WorldTime::getTime(), Binder);
    203                             OtherWalker->father->RegisterBond(WorldTime::getTime(), Binder);
     201                            //const bond * Binder =
     202                              Walker->father->addBond(WorldTime::getTime(), OtherWalker->father);
    204203                            BondCount++;
    205204                          } else {
  • src/Graph/BondGraph.hpp

    r7188b1 rdb7e6d  
    230230
    231231      LOG(3, "INFO: Creating bond between atoms " << atom1 << " and " << atom2 << ".");
    232       bond * const Binder = new bond(Walker, OtherWalker, 1);
    233       Walker->RegisterBond(WorldTime::getTime(), Binder);
    234       OtherWalker->RegisterBond(WorldTime::getTime(), Binder);
     232      //const bond * Binder =
     233          Walker->addBond(WorldTime::getTime(), OtherWalker);
    235234      bondcounter++;
    236235    }
  • src/atom_bondedparticle.cpp

    r7188b1 rdb7e6d  
    2727#include "CodePatterns/Verbose.hpp"
    2828#include "element.hpp"
     29#include "WorldTime.hpp"
    2930
    3031/** Constructor of class BondedParticle.
     
    9394
    9495/**
    95  * Adds a bond between this bonded particle and another. Does nothing if this
     96 * Adds a bond between this bonded particle and another. Returns present instance if this
    9697 * bond already exists.
    9798 *
    9899 * @param _step time step to access
    99  * \param bonding partner
    100  */
    101 void BondedParticle::addBond(const unsigned int _step, BondedParticle* Partner) {
    102   if (IsBondedTo(_step, Partner)) {
    103     return;
     100 * @param bonding partner
     101 * @return const reference to created bond or to already present bonds
     102 */
     103const bond * BondedParticle::addBond(const unsigned int _step, BondedParticle* Partner)
     104{
     105  const BondList &bondlist = getListOfBondsAtStep(_step);
     106  for (BondList::const_iterator runner = bondlist.begin();
     107      runner != bondlist.end();
     108      runner++) {
     109    if ((*runner)->Contains(Partner))
     110      return *runner;
    104111  }
    105112
     
    107114  RegisterBond(_step, newBond);
    108115  Partner->RegisterBond(_step, newBond);
     116
     117  return newBond;
     118}
     119
     120/** Removes a bond for this atom.
     121 *
     122 * @param Binder bond to remove
     123 */
     124void BondedParticle::removeBond(bond * binder)
     125{
     126  UnregisterBond(binder);
    109127}
    110128
     
    115133bool BondedParticle::RegisterBond(const unsigned int _step, bond *Binder)
    116134{
     135  OBSERVE;
    117136  bool status = false;
    118137  if (Binder != NULL) {
    119138    if (Binder->Contains(this)) {
     139      if (WorldTime::getTime() == _step)
     140        NOTIFY(AtomObservable::BondsChanged);
    120141      //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step);
    121142      BondList& ListOfBonds = getListOfBondsAtStep(_step);
     
    137158bool BondedParticle::UnregisterBond(bond *Binder)
    138159{
     160  OBSERVE;
    139161  bool status = false;
    140162  ASSERT(Binder != NULL, "BondedParticle::UnregisterBond() - Binder is NULL.");
    141163  const int step = ContainsBondAtStep(Binder);
    142164  if (step != -1) {
     165    NOTIFY(AtomObservable::BondsChanged);
    143166    //LOG(3,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step);
    144167    ListOfBonds[step].remove(Binder);
     
    164187void BondedParticle::ClearBondsAtStep(const unsigned int _step)
    165188{
     189  OBSERVE;
     190  if (WorldTime::getTime() == _step)
     191    NOTIFY(AtomObservable::BondsChanged);
    166192  //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]);
    167193  for (BondList::iterator iter = (ListOfBonds[_step]).begin();
     
    178204 * @return >=0 - first time step where bond appears, -1 - bond not present in lists
    179205 */
    180 int BondedParticle::ContainsBondAtStep(bond *Binder)
     206int BondedParticle::ContainsBondAtStep(bond *Binder) const
    181207{
    182208  int step = -1;
     
    205231int BondedParticle::CorrectBondDegree()
    206232{
     233  OBSERVE;
     234  NOTIFY(AtomObservable::BondsChanged);
    207235  int NoBonds = 0;
    208236  int OtherNoBonds = 0;
  • src/atom_bondedparticle.hpp

    r7188b1 rdb7e6d  
    3737  virtual ~BondedParticle();
    3838
    39   void addBond(const unsigned int _step, BondedParticle* Partner);
    40   bool RegisterBond(const unsigned int _step, bond *Binder);
    41   bool UnregisterBond(bond *Binder);
     39  const bond * addBond(const unsigned int _step, BondedParticle* Partner);
     40  void removeBond(bond *binder);
    4241  bool IsBondedTo(const unsigned int _step, BondedParticle * const BondPartner) const;
    43   void UnregisterAllBond(const unsigned int _step);
    4442  void ClearBondsAtStep(const unsigned int _step);
    4543  int CountBonds() const;
     
    5250  std::ostream & operator << (std::ostream &ost) const;
    5351
    54 private:
    55   int ContainsBondAtStep(bond *Binder);
     52protected:
     53  bool RegisterBond(const unsigned int _step, bond *Binder);
     54  bool UnregisterBond(bond *Binder);
     55  void UnregisterAllBond(const unsigned int _step);
     56
     57  int ContainsBondAtStep(bond *Binder) const;
    5658
    5759};
Note: See TracChangeset for help on using the changeset viewer.