Changeset a7aebd


Ignore:
Timestamp:
Jan 11, 2015, 4:41:14 PM (10 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:
f115cc
Parents:
7b93f9
git-author:
Frederik Heber <heber@…> (12/03/14 19:20:31)
git-committer:
Frederik Heber <heber@…> (01/11/15 16:41:14)
Message:

World removes empty molecules.

  • on destroyAtom() of molecule's last atom, destroyMolecule() is called.
  • FIX: destroyMolecule(molecule *) did use OBSERVE unncessarily. This caused seg'fault.
  • extracted removeAtomsinMolecule from molecule class. This is necessary since World will automatically remove empty molecules.
Location:
src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/UndoRedoHelpers.cpp

    r7b93f9 ra7aebd  
    173173  for (std::vector<moleculeId_t>::const_iterator iter = ids.begin();
    174174      iter != ids.end(); ++iter) {
    175     molecule * const mol = World::getInstance().getMolecule(MoleculeById(*iter));
     175    molecule * mol = World::getInstance().getMolecule(MoleculeById(*iter));
    176176    if (mol != NULL) {
    177       mol->removeAtomsinMolecule();
    178       World::getInstance().destroyMolecule(mol);
     177      removeAtomsinMolecule(mol);
     178      // molecules are automatically removed when empty
    179179    }
    180180  }
  • src/Actions/WorldAction/RepeatBoxAction.cpp

    r7b93f9 ra7aebd  
    147147      iter != allmolecules.end();
    148148      ++iter) {
    149     if (state->oldmolecules.find(*iter) == state->oldmolecules.end()) {
    150       (*iter)->removeAtomsinMolecule();
    151       // TODO: Remove this when World don't has deprecated MoleculeListClass anymore
    152       molecules->erase(*iter);
    153       World::getInstance().destroyMolecule(*iter);
    154     }
     149    if (state->oldmolecules.find(*iter) == state->oldmolecules.end())
     150      removeAtomsinMolecule(*iter);
    155151  }
    156152
  • src/Fragmentation/Exporters/ExportGraph.cpp

    r7b93f9 ra7aebd  
    8080    // remove copied atoms and molecule again
    8181    molecule *mol = *iter;
    82     mol->removeAtomsinMolecule();
    83     World::getInstance().destroyMolecule(mol);
    8482    BondFragments.ListOfMolecules.erase(iter);
     83    removeAtomsinMolecule(mol);
    8584  }
    8685}
  • src/Graph/unittests/AdjacencyListUnitTest.cpp

    r7b93f9 ra7aebd  
    153153
    154154  // destroy molecule and contained atoms
    155   TestMolecule->removeAtomsinMolecule();
    156   World::getInstance().destroyMolecule(TestMolecule);
     155  removeAtomsinMolecule(TestMolecule);
    157156  // destroy World
    158157  World::purgeInstance();
  • src/MoleculeLeafClass.cpp

    r7b93f9 ra7aebd  
    8585  //  }
    8686  // remove the leaf itself
    87   if (Leaf != NULL) {
    88     Leaf->removeAtomsinMolecule();
    89     World::getInstance().destroyMolecule(Leaf);
    90     Leaf = NULL;
    91   }
     87  if (Leaf != NULL)
     88    removeAtomsinMolecule(Leaf);
    9289  // remove this Leaf from level list
    9390  if (previous != NULL)
  • src/World.cpp

    r7b93f9 ra7aebd  
    304304
    305305void World::destroyMolecule(molecule* mol){
    306   OBSERVE;
    307306  ASSERT(mol,"Molecule that was meant to be destroyed did not exist");
    308307  destroyMolecule(mol->getId());
     
    319318  }
    320319  mol->signOff(this);
     320  // TODO: removed when depcreated MoleculeListClass is gone
     321  molecules_deprecated->erase(mol);
    321322  DeleteMolecule(mol);
    322323  if (isMoleculeSelected(id))
     
    365366    NOTIFY(AtomRemoved);
    366367  }
     368  // check if it's the last atom
     369  molecule *_mol = atom->getMolecule();
     370  if ((_mol == NULL) || (_mol->getAtomCount() > (size_t)1))
     371    _mol = NULL;
    367372  DeleteAtom(atom);
    368373  if (isAtomSelected(id))
     
    370375  atoms.erase(id);
    371376  atomIdPool.releaseId(id);
     377  // remove molecule if empty
     378  if (_mol != NULL)
     379    destroyMolecule(_mol);
    372380}
    373381
  • src/molecule.cpp

    r7b93f9 ra7aebd  
    646646/** Destroys all atoms inside this molecule.
    647647 */
    648 void molecule::removeAtomsinMolecule()
     648void removeAtomsinMolecule(molecule *&_mol)
    649649{
    650650  // remove each atom from world
    651   for(iterator AtomRunner = begin(); !empty(); AtomRunner = begin())
     651  for(molecule::iterator AtomRunner = _mol->begin(); !_mol->empty(); AtomRunner = _mol->begin())
    652652    World::getInstance().destroyAtom(*AtomRunner);
     653  // make sure that pointer os not usable
     654  _mol = NULL;
    653655};
    654656
  • src/molecule.hpp

    r7b93f9 ra7aebd  
    5757/************************************* Class definitions ****************************************/
    5858
     59/** External function to remove all atoms since this will also delete the molecule
     60 *
     61 * \param _mol ref pointer to molecule to destroy
     62 */
     63void removeAtomsinMolecule(molecule *&_mol);
     64
    5965/** The complete molecule.
    6066 * Class incorporates number of types
     
    262268  bool UnlinkAtom(atom *pointer);
    263269  bool CleanupMolecule();
    264   void removeAtomsinMolecule();
    265270
    266271  /// Add/remove atoms to/from molecule.
Note: See TracChangeset for help on using the changeset viewer.