Changeset 5e2f80


Ignore:
Timestamp:
Oct 6, 2011, 4:06:10 PM (14 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:
9c18e4
Parents:
37b2575
git-author:
Frederik Heber <heber@…> (09/01/11 17:06:04)
git-committer:
Frederik Heber <heber@…> (10/06/11 16:06:10)
Message:

BondedParticle no more hands out non-const ListOfBonds.

  • the few required instances were always for removing all bonds inL
    • GraphCreateAdjacencyAction::performCall(),
    • MoleculeCopyAction::performUndo(),
    • BondGraph::cleanAdjacencyList(),
    • BondGraph::resetBondDegree(),
    • molecule::removeBonds(),
    • MoleculeListClass::AddHydrogenCorrection(),
    • ListOfBondsTest::AddingBondTest().
  • added BondedParticle::removeAllBonds().
  • added BondedParticle::resetBondDegree().
  • BondedParticleInfo::getListOfBonds...() now returns empty list if out of bounds (emptylist is static member variable of the class).
  • ListOfBondsUnitTest runs fine.
Location:
src
Files:
11 edited

Legend:

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

    r37b2575 r5e2f80  
    7272      ++AtomRunner) {
    7373    AtomCount++;
    74     BondList& ListOfBonds = (AtomRunner->second)->getListOfBonds();
    75     for(BondList::iterator BondRunner = ListOfBonds.begin();
    76         !ListOfBonds.empty();
    77         BondRunner = ListOfBonds.begin())
    78       if ((*BondRunner)->leftatom == AtomRunner->second)
    79         delete((*BondRunner));
     74    (AtomRunner->second)->removeAllBonds();
     75//    BondList& ListOfBonds = (AtomRunner->second)->getListOfBonds();
     76//    for(BondList::iterator BondRunner = ListOfBonds.begin();
     77//        !ListOfBonds.empty();
     78//        BondRunner = ListOfBonds.begin())
     79//      if ((*BondRunner)->leftatom == AtomRunner->second)
     80//        delete((*BondRunner));
    8081  }
    8182  int BondCount = 0;
  • src/Actions/MoleculeAction/CopyAction.cpp

    r37b2575 r5e2f80  
    6262      !state->copy->empty();
    6363      AtomRunner = state->copy->begin()) {
    64     BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
    65     for(BondList::iterator BondRunner = ListOfBonds.begin();
    66         !ListOfBonds.empty();
    67         BondRunner = ListOfBonds.begin()) {
    68       delete(*BondRunner);
    69     }
     64    (*AtomRunner)->removeAllBonds();
     65//    BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
     66//    for(BondList::iterator BondRunner = ListOfBonds.begin();
     67//        !ListOfBonds.empty();
     68//        BondRunner = ListOfBonds.begin()) {
     69//      delete(*BondRunner);
     70//    }
    7071    atom *Walker = *AtomRunner;
    7172    World::getInstance().destroyAtom(Walker);
  • src/Graph/BondGraph.hpp

    r37b2575 r5e2f80  
    266266    // remove every bond from the list
    267267    for(iterator_type AtomRunner = Set.begin(); AtomRunner != Set.end(); ++AtomRunner) {
    268       BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
    269       for(BondList::iterator BondRunner = ListOfBonds.begin();
    270           !ListOfBonds.empty();
    271           BondRunner = ListOfBonds.begin()) {
    272         ASSERT((*BondRunner)->Contains(*AtomRunner),
    273             "BondGraph::cleanAdjacencyList() - "+
    274             toString(*BondRunner)+" does not contain "+
    275             toString(*AtomRunner)+".");
    276         delete((*BondRunner));
    277       }
     268      (*AtomRunner)->removeAllBonds();
     269//      BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
     270//      for(BondList::iterator BondRunner = ListOfBonds.begin();
     271//          !ListOfBonds.empty();
     272//          BondRunner = ListOfBonds.begin()) {
     273//        ASSERT((*BondRunner)->Contains(*AtomRunner),
     274//            "BondGraph::cleanAdjacencyList() - "+
     275//            toString(*BondRunner)+" does not contain "+
     276//            toString(*AtomRunner)+".");
     277//        delete((*BondRunner));
     278//      }
    278279    }
    279280  }
     
    354355    // reset bond degrees
    355356    for(iterator_type AtomRunner = Set.begin(); AtomRunner != Set.end(); ++AtomRunner) {
    356       BondList &ListOfBonds = (*AtomRunner)->getListOfBonds();
    357       for (BondList::iterator BondIter = ListOfBonds.begin();
    358           BondIter != ListOfBonds.end();
    359           ++BondIter)
    360         (*BondIter)->BondDegree = 1;
     357      (*AtomRunner)->resetBondDegree();
    361358    }
    362359  }
  • src/atom_bondedparticle.cpp

    r37b2575 r5e2f80  
    4040BondedParticle::~BondedParticle()
    4141{
    42   const size_t max = ListOfBonds.size();
    43   for (size_t i = 0; i < max; ++i) {
    44     ClearBondsAtStep(i);
    45   }
     42  removeAllBonds();
    4643};
    4744
     
    127124}
    128125
     126/** Removes all bonds and their instances, too.
     127 *
     128 */
     129void BondedParticle::removeAllBonds()
     130{
     131  OBSERVE;
     132  NOTIFY(BondedParticle::BondsChanged);
     133  for (size_t index = 0; index < ListOfBonds.size(); ++index)
     134  {
     135    for (BondList::iterator iter = ListOfBonds[index].begin();
     136        !ListOfBonds[index].empty();
     137        iter = ListOfBonds[index].begin()) {
     138      delete (*iter);
     139      // erase is done by bond::~bond()
     140    }
     141  }
     142}
     143
    129144/** Puts a given bond into atom::ListOfBonds.
    130145 * @param _step time step to access
     
    140155        NOTIFY(AtomObservable::BondsChanged);
    141156      //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step);
    142       BondList& ListOfBonds = getListOfBondsAtStep(_step);
    143       ListOfBonds.push_back(Binder);
     157      if (ListOfBonds.size() <= _step)
     158        ListOfBonds.resize(_step+1);
     159      ListOfBonds[_step].push_back(Binder);
    144160      status = true;
    145161    } else {
     
    164180  if (step != -1) {
    165181    NOTIFY(AtomObservable::BondsChanged);
    166     //LOG(3,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step);
     182    //LOG(0,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step);
    167183    ListOfBonds[step].remove(Binder);
    168184    status = true;
     
    266282};
    267283
     284/** Sets the weight of all connected bonds to one.
     285 */
     286void BondedParticle::resetBondDegree()
     287{
     288  OBSERVE;
     289  NOTIFY(BondedParticle::BondsChanged);
     290  for (std::vector<BondList>::iterator Runner = ListOfBonds.begin();
     291      Runner != ListOfBonds.end();
     292      ++Runner)
     293    for (BondList::iterator BondRunner = (*Runner).begin();
     294        BondRunner != (*Runner).end();
     295        ++BondRunner)
     296      (*BondRunner)->BondDegree = 1;
     297};
     298
    268299/** Counts the number of bonds weighted by bond::BondDegree.
    269300   * @param _step time step to access
  • src/atom_bondedparticle.hpp

    r37b2575 r5e2f80  
    3939  const bond * addBond(const unsigned int _step, BondedParticle* Partner);
    4040  void removeBond(bond *binder);
     41  void removeAllBonds();
    4142  bool IsBondedTo(const unsigned int _step, BondedParticle * const BondPartner) const;
    4243  void ClearBondsAtStep(const unsigned int _step);
    4344  int CountBonds() const;
    4445  int CorrectBondDegree();
     46  void resetBondDegree();
    4547  void OutputBondOfAtom(std::ostream &ost) const;
    4648  void OutputAdjacency(ofstream * const AdjacencyFile) const;
  • src/atom_bondedparticleinfo.cpp

    r37b2575 r5e2f80  
    2727#include "atom_bondedparticleinfo.hpp"
    2828
     29
     30BondList BondedParticleInfo::emptyList;
     31
    2932/** Constructor of class BondedParticleInfo.
    3033 */
     
    4750const BondList& BondedParticleInfo::getListOfBonds() const
    4851{
    49   ASSERT(WorldTime::getTime() < ListOfBonds.size(),
    50       "BondedParticleInfo::getBondsAtStep() - Access out of range: "
    51       +toString(WorldTime::getTime())
    52       +" not in [0,"+toString(ListOfBonds.size())+").");
    53   return ListOfBonds[WorldTime::getTime()];
     52  if(WorldTime::getTime() < ListOfBonds.size())
     53    return ListOfBonds[WorldTime::getTime()];
     54  else
     55    return emptyList;
    5456}
    5557
    56 BondList& BondedParticleInfo::getListOfBonds()
    57 {
    58   // todo: here we actually need a container on whose destruction notifiy is emitted, i.e.
    59   // similar or simply an ObservedContainer.
    60   OBSERVE;
    61   NOTIFY(AtomObservable::BondsChanged);
    62   const unsigned int size = ListOfBonds.size();
    63   ASSERT(WorldTime::getTime() <= size,
    64       "BondedParticleInfo::getBondsAtStep() - Access out of range: "
    65       +toString(WorldTime::getTime())
    66       +" not in [0,"+toString(size)+"].");
    67   if (WorldTime::getTime() == size) {
    68     UpdateSteps();
    69   }
    70   return ListOfBonds[WorldTime::getTime()];
    71 }
     58//BondList& BondedParticleInfo::getListOfBonds()
     59//{
     60//  // todo: here we actually need a container on whose destruction notifiy is emitted, i.e.
     61//  // similar or simply an ObservedContainer.
     62//  OBSERVE;
     63//  NOTIFY(AtomObservable::BondsChanged);
     64//  const unsigned int size = ListOfBonds.size();
     65//  ASSERT(WorldTime::getTime() <= size,
     66//      "BondedParticleInfo::getBondsAtStep() - Access out of range: "
     67//      +toString(WorldTime::getTime())
     68//      +" not in [0,"+toString(size)+"].");
     69//  if (WorldTime::getTime() == size) {
     70//    UpdateSteps();
     71//  }
     72//  return ListOfBonds[WorldTime::getTime()];
     73//}
    7274
    7375const BondList& BondedParticleInfo::getListOfBondsAtStep(unsigned int _step) const
    7476{
    75   ASSERT(_step < ListOfBonds.size(),
    76       "BondedParticleInfo::getBondsAtStep() - Access out of range: "
    77       +toString(_step)
    78       +" not in [0,"+toString(ListOfBonds.size())+").");
    79   return ListOfBonds[_step];
     77  if(_step < ListOfBonds.size())
     78    return ListOfBonds[_step];
     79  else
     80    return emptyList;
    8081}
    8182
    82 BondList& BondedParticleInfo::getListOfBondsAtStep(unsigned int _step)
    83 {
    84   const unsigned int size = ListOfBonds.size();
    85   ASSERT(_step <= size,
    86       "BondedParticleInfo::getBondsAtStep() - Access out of range: "
    87       +toString(_step)
    88       +" not in [0,"+toString(size)+"].");
    89   if (_step == size) {
    90     UpdateSteps();
    91   }
    92   return ListOfBonds[_step];
    93 }
     83//BondList& BondedParticleInfo::getListOfBondsAtStep(unsigned int _step)
     84//{
     85//  const unsigned int size = ListOfBonds.size();
     86//  ASSERT(_step <= size,
     87//      "BondedParticleInfo::getBondsAtStep() - Access out of range: "
     88//      +toString(_step)
     89//      +" not in [0,"+toString(size)+"].");
     90//  if (_step == size) {
     91//    UpdateSteps();
     92//  }
     93//  return ListOfBonds[_step];
     94//}
  • src/atom_bondedparticleinfo.hpp

    r37b2575 r5e2f80  
    5454   */
    5555  const BondList& getListOfBonds() const;
     56
    5657  /** Accessor to ListOfBonds of WorldTime::CurrentTime.
    5758   *
     
    6162   * @return ListOfBonds[WorldTime::CurrentTime]
    6263   */
    63   BondList& getListOfBonds();
     64//  BondList& getListOfBonds();
    6465
    6566  /** Const Accessor ListOfBonds of any present time step.
     
    6970   */
    7071  const BondList& getListOfBondsAtStep(unsigned int _step) const;
     72
    7173  /** Accessor ListOfBonds of any present time step.
    7274   *
     
    7779   * @return ListOfBonds[_step].
    7880   */
    79   BondList& getListOfBondsAtStep(unsigned int _step);
     81//  BondList& getListOfBondsAtStep(unsigned int _step);
    8082
    8183protected:
     
    8688
    8789  std::vector<BondList> ListOfBonds; //!< list of all bonds
    88 
     90  static BondList emptyList;  //!< empty list to return when step is not present
    8991};
    9092
  • src/molecule.cpp

    r37b2575 r5e2f80  
    772772{
    773773  //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl);
    774   BondList::const_iterator ForeRunner;
    775   BondList& ListOfBonds = BondPartner->getListOfBonds();
    776   while (!ListOfBonds.empty()) {
    777     ForeRunner = ListOfBonds.begin();
    778     RemoveBond(*ForeRunner);
    779   }
     774  BondPartner->removeAllBonds();
    780775  return false;
    781776};
  • src/molecule_graph.cpp

    r37b2575 r5e2f80  
    104104{
    105105  for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
     106    //LOG(0, "molecule::hasBondStructure() - checking bond list of atom " << (*AtomRunner)->getId() << ".");
    106107    const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
    107108    if (!ListOfBonds.empty())
  • src/moleculelist.cpp

    r37b2575 r5e2f80  
    283283bool MoleculeListClass::AddHydrogenCorrection(std::string &path)
    284284{
    285   bond *Binder = NULL;
     285  const bond *Binder = NULL;
    286286  double ***FitConstant = NULL, **correction = NULL;
    287287  int a, b;
     
    395395          //Log() << Verbose(2) << "Runner: " << *(*runner) << " with first bond " << *((*iter)->getListOfBonds().begin()) << "." << endl;
    396396          // 3. take every other hydrogen that is the not the first and not bound to same bonding partner
    397           Binder = *((*runner)->getListOfBonds().begin());
     397          const BondList &bondlist = (*runner)->getListOfBonds();
     398          Binder = *(bondlist.begin());
    398399          if (((*runner)->getType()->getAtomicNumber() == 1) && ((*runner)->getNr() > (*iter)->getNr()) && (Binder->GetOtherAtom((*runner)) != Binder->GetOtherAtom((*iter)))) { // (hydrogens have only one bonding partner!)
    399400            // 4. evaluate the morse potential for each matrix component and add up
  • src/unittests/ListOfBondsUnitTest.cpp

    r37b2575 r5e2f80  
    5151{
    5252  atom *Walker = NULL;
     53
     54  WorldTime::setTime(0);
    5355
    5456  // construct element
     
    127129
    128130  // check that bond is present in both atoms
     131  const BondList &bondlist1 = atom1->getListOfBonds();
    129132  BondList::const_iterator bonditer;
    130   bonditer = atom1->getListOfBonds().begin();
     133  bonditer = bondlist1.begin();
    131134  bond *TestBond1 = *bonditer;
    132135  CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
    133   bonditer = atom2->getListOfBonds().begin();
     136  const BondList &bondlist2 = atom2->getListOfBonds();
     137  bonditer = bondlist2.begin();
    134138  bond *TestBond2 = *bonditer;
    135139  CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
Note: See TracChangeset for help on using the changeset viewer.