Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Atom/atom_bondedparticle.cpp

    r5aaa43 r8cc22f  
    5252BondedParticle::BondedParticle()
    5353{
    54   ListOfBonds.push_back(BondList());
     54  ListOfBonds.insert( std::make_pair(0, emptyList) );
    5555};
    5656
     
    5959BondedParticle::~BondedParticle()
    6060{
    61   removeAllBonds();
     61  for(BondTrajectory_t::iterator iter = ListOfBonds.begin(); !ListOfBonds.empty();
     62      iter = ListOfBonds.begin()) {
     63    removeAllBonds(iter->first);
     64    ListOfBonds.erase(iter);
     65  }
    6266};
    6367
     
    220224}
    221225
    222 /** Removes all bonds in all timesteps and their instances, too.
     226/** Removes all bonds in current timestep and their instances, too.
    223227 *
    224228 */
    225229void BondedParticle::removeAllBonds()
    226230{
    227   for (size_t index = 0; index < ListOfBonds.size(); ++index)
    228     removeAllBonds(index);
     231  removeAllBonds(WorldTime::getTime());
    229232}
    230233
     
    236239{
    237240  //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]);
    238   for (BondList::iterator iter = (ListOfBonds[_step]).begin();
    239       !(ListOfBonds[_step]).empty();
    240       iter = (ListOfBonds[_step]).begin()) {
    241     //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds);
    242     atom * const Other = (*iter)->GetOtherAtom(this);
    243     ASSERT( Other != NULL,
    244         "BondedParticle::removeAllBonds() - cannot find bond partner for "
    245         +toString(**iter)+".");
    246     Other->UnregisterBond(_step, *iter);
    247     UnregisterBond(_step, *iter);
    248   }
     241  BondTrajectory_t::iterator listiter = ListOfBonds.find(_step);
     242  if (listiter != ListOfBonds.end())
     243    for (BondList::iterator iter = listiter->second.begin();
     244        !listiter->second.empty();
     245        iter = listiter->second.begin()) {
     246      //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds);
     247      atom * const Other = (*iter)->GetOtherAtom(this);
     248      ASSERT( Other != NULL,
     249          "BondedParticle::removeAllBonds() - cannot find bond partner for "
     250          +toString(**iter)+".");
     251      Other->UnregisterBond(_step, *iter);
     252      UnregisterBond(_step, *iter);
     253    }
    249254}
    250255
     
    260265    if (Binder->Contains(this)) {
    261266      //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step);
    262       if (ListOfBonds.size() <= _step)
    263         ListOfBonds.resize(_step+1);
    264       ListOfBonds[_step].push_back(Binder);
     267      std::pair< BondTrajectory_t::iterator, bool> inserter =
     268          ListOfBonds.insert( std::make_pair( _step, BondList(1, Binder)) );
     269      if (!inserter.second)
     270        inserter.first->second.push_back(Binder);
    265271      if (WorldTime::getTime() == _step)
    266272        NOTIFY(AtomObservable::BondsAdded);
     
    290296      OBSERVE;
    291297      //LOG(0,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step);
     298      BondTrajectory_t::iterator listiter = ListOfBonds.find(_step);
     299      if (listiter != ListOfBonds.end()) {
    292300#ifndef NDEBUG
    293       BondList::const_iterator iter =
    294           std::find(ListOfBonds[_step].begin(), ListOfBonds[_step].end(), Binder);
    295       ASSERT( iter != ListOfBonds[_step].end(),
    296           "BondedParticle::UnregisterBond() - "+toString(*Binder)+" not contained at "
    297           +toString(_step));
     301        BondList::const_iterator iter =
     302            std::find(listiter->second.begin(), listiter->second.end(), Binder);
     303        ASSERT( iter != listiter->second.end(),
     304            "BondedParticle::UnregisterBond() - "+toString(*Binder)+" not contained at "
     305            +toString(_step));
    298306#endif
    299       Binder->removeAtom(this);
    300       ListOfBonds[_step].remove(Binder);
    301       if (WorldTime::getTime() == _step)
    302         NOTIFY(AtomObservable::BondsRemoved);
    303       status = true;
     307        Binder->removeAtom(this);
     308        listiter->second.remove(Binder);
     309        if (WorldTime::getTime() == _step)
     310          NOTIFY(AtomObservable::BondsRemoved);
     311        status = true;
     312      }
    304313    } else {
    305314      ELOG(1, *Binder << " does not contain " << *this << ".");
     
    328337{
    329338  int step = -1;
    330   int tempstep = 0;
    331   for(std::vector<BondList>::const_iterator iter = ListOfBonds.begin();
    332       iter != ListOfBonds.end();
    333       ++iter,++tempstep) {
    334     for (BondList::const_iterator bonditer = iter->begin();
    335         bonditer != iter->end();
     339  for(BondTrajectory_t::const_iterator listiter = ListOfBonds.begin();
     340      listiter != ListOfBonds.end();
     341      ++listiter) {
     342    for (BondList::const_iterator bonditer = listiter->second.begin();
     343        bonditer != listiter->second.end();
    336344        ++bonditer) {
    337345      if ((*bonditer) == Binder) {
    338         step = tempstep;
     346        step = listiter->first;
    339347        break;
    340348      }
Note: See TracChangeset for help on using the changeset viewer.