- Timestamp:
- Feb 13, 2013, 3:47:38 PM (12 years ago)
- 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:
- b4b364
- Parents:
- c8302f3
- git-author:
- Frederik Heber <heber@…> (11/02/12 13:38:08)
- git-committer:
- Frederik Heber <heber@…> (02/13/13 15:47:38)
- Location:
- src/Atom
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Atom/atom_bondedparticle.cpp
rc8302f3 r7d82a5 114 114 } 115 115 116 bond * newBond = new bond((atom*) this, (atom*) Partner, 1);116 bond::ptr newBond(new bond((atom*) this, (atom*) Partner, 1)); 117 117 RegisterBond(_step, newBond); 118 118 Partner->RegisterBond(_step, newBond); … … 121 121 } 122 122 123 /** Removes a bond of this atom to a given \a Partner. 124 * 125 * @param _step time step 126 * @param Partner bond partner 127 */ 128 void BondedParticle::removeBond(const unsigned int _step, BondedParticle * const Partner) 123 /** Helper function to find the time step to a given bond in \a Binder. 124 * 125 * \param Binder bond to look for 126 * \return ListOfBonds::size() - not found, else - step containing \a Binder 127 */ 128 unsigned int BondedParticle::findBondsStep(bond::ptr const Binder) const 129 { 130 131 size_t _step = 0; 132 for (;_step < ListOfBonds.size();++_step) { 133 const BondList& ListOfBonds = getListOfBondsAtStep(_step); 134 if (std::find(ListOfBonds.begin(), ListOfBonds.end(), Binder) != ListOfBonds.end()) 135 break; 136 } 137 return _step; 138 } 139 140 /** Helper function to find the iterator to a bond at a given time \a step to 141 * a given bond partner in \a Partner. 142 * 143 * \param _step time step to look at 144 * \param Partner bond partner to look for 145 * \return ListOfBonds::end() - not found, else - iterator pointing \a Binder 146 */ 147 BondList::const_iterator BondedParticle::findBondPartnerAtStep( 148 const unsigned int _step, 149 BondedParticle * const Partner) const 129 150 { 130 151 const BondList& ListOfBonds = getListOfBondsAtStep(_step); … … 134 155 _1, 135 156 boost::cref(Partner))); 136 if (iter != ListOfBonds.end()) { 137 delete *iter; //dstor takes care of unregistering and all 157 return iter; 158 } 159 160 /** Removes a bond of this atom to a given \a Partner. 161 * 162 * @param _step time step 163 * @param Partner bond partner 164 */ 165 void BondedParticle::removeBond(const unsigned int _step, BondedParticle * const Partner) 166 { 167 BondList::const_iterator iter = findBondPartnerAtStep(_step, Partner); 168 if (iter != getListOfBondsAtStep(_step).end()) { 169 // iter becomes invalid upon first unregister, 170 // hence store the bond someplace else first 171 bond::ptr const Binder = *iter; 172 UnregisterBond(_step, Binder); 173 Partner->UnregisterBond(_step, Binder); 138 174 } else 139 175 ELOG(1, "BondedParticle::removeBond() - I cannot find the bond in between " … … 145 181 * @param Binder bond to remove 146 182 */ 147 void BondedParticle::removeBond(bond::ptr binder) 148 { 149 UnregisterBond(binder); 183 void BondedParticle::removeBond(bond::ptr &binder) 184 { 185 if (binder != NULL) { 186 atom * const Other = binder->GetOtherAtom(this); 187 ASSERT( Other != NULL, 188 "BondedParticle::removeBonds() - cannot find bond partner for " 189 +toString(*binder)+"."); 190 // find bond at step 191 unsigned int step = findBondsStep(binder); 192 if (step != ListOfBonds.size()) { 193 UnregisterBond(step, binder); 194 Other->UnregisterBond(step, binder); 195 binder.reset(); 196 } 197 } 150 198 } 151 199 … … 165 213 void BondedParticle::removeAllBonds(const unsigned int _step) 166 214 { 167 for (BondList::iterator iter = ListOfBonds[_step].begin(); 168 !ListOfBonds[_step].empty(); 169 iter = ListOfBonds[_step].begin()) { 170 delete (*iter); 171 // unregister/NOTIFY is done by bond::~bond() 215 //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]); 216 for (BondList::iterator iter = (ListOfBonds[_step]).begin(); 217 !(ListOfBonds[_step]).empty(); 218 iter = (ListOfBonds[_step]).begin()) { 219 //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds); 220 atom * const Other = (*iter)->GetOtherAtom(this); 221 ASSERT( Other != NULL, 222 "BondedParticle::removeAllBonds() - cannot find bond partner for " 223 +toString(**iter)+"."); 224 Other->UnregisterBond(_step, *iter); 225 UnregisterBond(_step, *iter); 172 226 } 173 227 } … … 179 233 bool BondedParticle::RegisterBond(const unsigned int _step, bond::ptr const Binder) 180 234 { 181 OBSERVE;182 235 bool status = false; 183 236 if (Binder != NULL) { 237 OBSERVE; 184 238 if (Binder->Contains(this)) { 185 239 //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step); … … 200 254 201 255 /** Removes a given bond from atom::ListOfBonds. 256 * 257 * \warning This only removes this atom not its bond partner, i.e. 258 * both atoms need to call this function to fully empty a bond. 259 * 202 260 * @param _step time step to access 203 261 * \param *Binder bond to remove 204 262 */ 205 bool BondedParticle::UnregisterBond(bond::ptr const Binder) 206 { 207 OBSERVE; 263 bool BondedParticle::UnregisterBond(const unsigned int _step, bond::ptr const Binder) 264 { 208 265 bool status = false; 209 ASSERT(Binder != NULL, "BondedParticle::UnregisterBond() - Binder is NULL."); 210 const int step = ContainsBondAtStep(Binder); 211 if (step != -1) { 212 //LOG(0,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step); 213 ListOfBonds[step].remove(Binder); 214 if (WorldTime::getTime() == step) 215 NOTIFY(AtomObservable::BondsRemoved); 216 status = true; 266 if (Binder != NULL) { 267 if (Binder->Contains(this)) { 268 OBSERVE; 269 //LOG(0,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step); 270 #ifndef NDEBUG 271 BondList::const_iterator iter = 272 std::find(ListOfBonds[_step].begin(), ListOfBonds[_step].end(), Binder); 273 ASSERT( iter != ListOfBonds[_step].end(), 274 "BondedParticle::UnregisterBond() - "+toString(*Binder)+" not contained at " 275 +toString(_step)); 276 #endif 277 Binder->removeAtom(this); 278 ListOfBonds[_step].remove(Binder); 279 if (WorldTime::getTime() == _step) 280 NOTIFY(AtomObservable::BondsRemoved); 281 status = true; 282 } else { 283 ELOG(1, *Binder << " does not contain " << *this << "."); 284 } 217 285 } else { 218 ELOG(1, *Binder << " does not contain " << *this<< ".");286 ELOG(1, "Binder is " << Binder << "."); 219 287 } 220 288 return status; 221 289 }; 222 290 223 /** Removes all bonds from atom::ListOfBonds.224 * \note Does not do any memory de-allocation.225 */226 void BondedParticle::UnregisterAllBond(const unsigned int _step)227 {228 OBSERVE;229 NOTIFY(AtomObservable::BondsRemoved);230 ListOfBonds[_step].clear();231 }232 233 291 /** Removes all bonds of given \a _step with freeing memory. 234 292 * … … 237 295 void BondedParticle::ClearBondsAtStep(const unsigned int _step) 238 296 { 239 OBSERVE; 240 NOTIFY(AtomObservable::BondsRemoved); 241 //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]); 242 for (BondList::iterator iter = (ListOfBonds[_step]).begin(); 243 !(ListOfBonds[_step]).empty(); 244 iter = (ListOfBonds[_step]).begin()) { 245 //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds); 246 delete((*iter)); // will also unregister with us and remove from list 247 } 297 removeAllBonds(_step); 248 298 } 249 299 … … 286 336 int FalseBondDegree = 0; 287 337 atom *OtherWalker = NULL; 288 bond::ptr CandidateBond = NULL;338 bond::ptr CandidateBond; 289 339 290 340 NoBonds = CountBonds(); -
src/Atom/atom_bondedparticle.hpp
rc8302f3 r7d82a5 24 24 #include "atom_atominfo.hpp" 25 25 #include "atom_bondedparticleinfo.hpp" 26 #include "atom_observable.hpp" 26 27 #include "atom_particleinfo.hpp" 28 #include "atom_observable.hpp" 27 29 28 30 /****************************************** forward declarations *****************************/ … … 32 34 /********************************************** declarations *******************************/ 33 35 34 class BondedParticle : public BondedParticleInfo, public virtual ParticleInfo, public virtual AtomInfo { 36 class BondedParticle : 37 public BondedParticleInfo, 38 public virtual ParticleInfo, 39 public virtual AtomInfo, 40 public virtual AtomObservable 41 { 35 42 public: 36 43 BondedParticle(); … … 39 46 bond::ptr const addBond(const unsigned int _step, BondedParticle* Partner); 40 47 void removeBond(const unsigned int _step, BondedParticle* Partner); 41 void removeBond(bond::ptr binder);48 void removeBond(bond::ptr &binder); 42 49 void removeAllBonds(); 43 50 void removeAllBonds(const unsigned int _step); … … 55 62 protected: 56 63 bool RegisterBond(const unsigned int _step, bond::ptr const Binder); 57 bool UnregisterBond(bond::ptr const Binder); 58 void UnregisterAllBond(const unsigned int _step); 64 bool UnregisterBond(const unsigned int _step, bond::ptr const Binder); 59 65 60 66 int ContainsBondAtStep(bond::ptr Binder) const; 61 67 68 private: 69 unsigned int findBondsStep(bond::ptr const Binder) const; 70 BondList::const_iterator findBondPartnerAtStep( 71 const unsigned int _step, 72 BondedParticle * const Partner) const; 62 73 }; 63 74 -
src/Atom/atom_bondedparticleinfo.hpp
rc8302f3 r7d82a5 19 19 #endif 20 20 21 #include "atom_observable.hpp"21 //#include "atom_observable.hpp" 22 22 #include "Bond/bond.hpp" 23 23 … … 32 32 /********************************************** declarations *******************************/ 33 33 34 class BondedParticleInfo : public virtual AtomObservable { 34 class BondedParticleInfo // : public virtual AtomObservable // must be virtual(!) 35 { 35 36 friend class BondedParticle; 36 37 public:
Note:
See TracChangeset
for help on using the changeset viewer.