Changeset e6a9c1 for src/World.cpp


Ignore:
Timestamp:
Mar 4, 2010, 10:40:52 AM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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:
63b56a7
Parents:
6a661c (diff), 66e95e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'MenuRefactoring' into QT4Refactoring

Conflicts:

molecuilder/src/Makefile.am

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/World.cpp

    r6a661c re6a9c1  
    1313#include "Descriptors/AtomDescriptor.hpp"
    1414#include "Descriptors/AtomDescriptor_impl.hpp"
     15#include "Descriptors/MoleculeDescriptor.hpp"
     16#include "Descriptors/MoleculeDescriptor_impl.hpp"
    1517#include "Actions/ManipulateAtomsProcess.hpp"
    1618
     
    2224}
    2325
     26// Atoms
     27
    2428atom* World::getAtom(AtomDescriptor descriptor){
    2529  return descriptor.find();
     
    3640int World::numAtoms(){
    3741  return atoms.size();
     42}
     43
     44// Molecules
     45
     46molecule *World::getMolecule(MoleculeDescriptor descriptor){
     47  return descriptor.find();
     48}
     49
     50std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
     51  return descriptor.findAll();
    3852}
    3953
     
    7286atom *World::createAtom(){
    7387  OBSERVE;
    74   atom *res = NewAtom();
    75   assert(!atoms.count(currAtomId));
    76   res->setId(currAtomId++);
     88  atomId_t id = getNextAtomId();
     89  atom *res = NewAtom(id);
    7790  res->setWorld(this);
    7891  // store the atom by ID
     
    8396int World::registerAtom(atom *atom){
    8497  OBSERVE;
    85   assert(!atoms.count(currAtomId));
    86   atom->setId(currAtomId++);
     98  atomId_t id = getNextAtomId();
     99  atom->setId(id);
    87100  atom->setWorld(this);
    88101  atoms[atom->getId()] = atom;
     
    102115  DeleteAtom(atom);
    103116  atoms.erase(id);
     117  releaseAtomId(id);
     118}
     119
     120bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
     121  OBSERVE;
     122  // in case this call did not originate from inside the atom, we redirect it,
     123  // to also let it know that it has changed
     124  if(!target){
     125    target = atoms[oldId];
     126    assert(target && "Atom with that ID not found");
     127    return target->changeId(newId);
     128  }
     129  else{
     130    if(reserveAtomId(newId)){
     131      atoms.erase(oldId);
     132      atoms.insert(pair<atomId_t,atom*>(newId,target));
     133      return true;
     134    }
     135    else{
     136      return false;
     137    }
     138  }
    104139}
    105140
     
    122157  proc->signOff(this);
    123158}
     159/******************************* IDManagement *****************************/
     160
     161// Atoms
     162
     163atomId_t World::getNextAtomId(){
     164  // see if we can reuse some Id
     165  if(atomIdPool.empty()){
     166    return currAtomId++;
     167  }
     168  else{
     169    // we give out the first ID from the pool
     170    atomId_t id = *(atomIdPool.begin());
     171    atomIdPool.erase(id);
     172  }
     173}
     174
     175void World::releaseAtomId(atomId_t id){
     176  atomIdPool.insert(id);
     177  // defragmentation of the pool
     178  set<atomId_t>::reverse_iterator iter;
     179  // go through all Ids in the pool that lie immediately below the border
     180  while(!atomIdPool.empty() && *(atomIdPool.rbegin())==(currAtomId-1)){
     181    atomIdPool.erase(--currAtomId);
     182  }
     183}
     184
     185bool World::reserveAtomId(atomId_t id){
     186  if(id>=currAtomId ){
     187    // add all ids between the new one and current border as available
     188    for(atomId_t pos=currAtomId; pos<id; ++pos){
     189      atomIdPool.insert(pos);
     190    }
     191    currAtomId=id+1;
     192    return true;
     193  }
     194  else if(atomIdPool.count(id)){
     195    atomIdPool.erase(id);
     196    return true;
     197  }
     198  else{
     199    // this ID could not be reserved
     200    return false;
     201  }
     202}
     203
     204// Molecules
    124205
    125206/******************************* Iterators ********************************/
     
    135216World::AtomSet::iterator World::atomEnd(){
    136217  return atoms.end();
     218}
     219
     220World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
     221  return MoleculeIterator(descr,this);
     222}
     223
     224World::MoleculeSet::iterator World::moleculeEnd(){
     225  return molecules.end();
    137226}
    138227
Note: See TracChangeset for help on using the changeset viewer.