Changeset 88d586
- Timestamp:
- Mar 3, 2010, 5:47:40 PM (15 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:
- 57adc7, 57f5cf
- Parents:
- 1c51c8
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/World.cpp
r1c51c8 r88d586 86 86 atom *World::createAtom(){ 87 87 OBSERVE; 88 atom *res = NewAtom(); 89 assert(!atoms.count(currAtomId)); 90 res->setId(currAtomId++); 88 atomId_t id = getNextAtomId(); 89 atom *res = NewAtom(id); 91 90 res->setWorld(this); 92 91 // store the atom by ID … … 97 96 int World::registerAtom(atom *atom){ 98 97 OBSERVE; 99 a ssert(!atoms.count(currAtomId));100 atom->setId( currAtomId++);98 atomId_t id = getNextAtomId(); 99 atom->setId(id); 101 100 atom->setWorld(this); 102 101 atoms[atom->getId()] = atom; … … 116 115 DeleteAtom(atom); 117 116 atoms.erase(id); 117 releaseAtomId(id); 118 } 119 120 bool 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 } 118 139 } 119 140 … … 136 157 proc->signOff(this); 137 158 } 138 159 /******************************* IDManagement *****************************/ 160 161 atomId_t World::getNextAtomId(){ 162 // see if we can reuse some Id 163 if(atomIdPool.empty()){ 164 return currAtomId++; 165 } 166 else{ 167 // we give out the first ID from the pool 168 atomId_t id = *(atomIdPool.begin()); 169 atomIdPool.erase(id); 170 } 171 } 172 173 void World::releaseAtomId(atomId_t id){ 174 atomIdPool.insert(id); 175 // defragmentation of the pool 176 set<atomId_t>::reverse_iterator iter; 177 // go through all Ids in the pool that lie immediately below the border 178 while(!atomIdPool.empty() && *(atomIdPool.rbegin())==(currAtomId-1)){ 179 atomIdPool.erase(--currAtomId); 180 } 181 } 182 183 bool World::reserveAtomId(atomId_t id){ 184 if(id>=currAtomId ){ 185 // add all ids between the new one and current border as available 186 for(atomId_t pos=currAtomId; pos<id; ++pos){ 187 atomIdPool.insert(pos); 188 } 189 currAtomId=id+1; 190 return true; 191 } 192 else if(atomIdPool.count(id)){ 193 atomIdPool.erase(id); 194 return true; 195 } 196 else{ 197 // this ID could not be reserved 198 return false; 199 } 200 } 139 201 /******************************* Iterators ********************************/ 140 202 -
src/World.hpp
r1c51c8 r88d586 130 130 */ 131 131 void destroyAtom(atomId_t); 132 133 /** 134 * used when changing an atom Id. 135 * Unless you are calling this method from inside an atom don't fiddle with the third parameter. 136 * 137 * Return value indicates wether the change could be done or not. 138 */ 139 bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0); 132 140 133 141 /** … … 226 234 227 235 private: 236 237 atomId_t getNextAtomId(); 238 void releaseAtomId(atomId_t); 239 bool reserveAtomId(atomId_t); 240 228 241 periodentafel *periode; 229 242 AtomSet atoms; 243 std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId 230 244 atomId_t currAtomId; //!< stores the next available Id for atoms 231 245 MoleculeSet molecules; -
src/atom.cpp
r1c51c8 r88d586 290 290 } 291 291 292 void atom::setId(int _id) { 292 bool atom::changeId(atomId_t newId){ 293 // first we move ourselves in the world 294 // the world lets us know if that succeeded 295 if(world->changeAtomId(id,newId,this)){ 296 id = newId; 297 return true; 298 } 299 else{ 300 return false; 301 } 302 } 303 304 void atom::setId(atomId_t _id) { 293 305 id=_id; 294 306 } … … 298 310 } 299 311 300 atom* NewAtom(){ 301 return new atom(); 302 } 303 304 void DeleteAtom(atom* atom){ 312 atom* NewAtom(atomId_t _id){ 313 atom * res =new atom(); 314 res->setId(_id); 315 return res; 316 } 317 318 void DeleteAtom(atom* atom){ 305 319 delete atom; 306 320 } -
src/atom.hpp
r1c51c8 r88d586 40 40 */ 41 41 class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo { 42 friend atom* NewAtom( );42 friend atom* NewAtom(atomId_t); 43 43 friend void DeleteAtom(atom*); 44 44 public: … … 80 80 81 81 virtual int getId(); 82 virtual void setId(int); 82 virtual bool changeId(atomId_t newId); 83 84 /** 85 * this function sets the Id without notifying the world. Only use it, if the world has already 86 * gotten an ID for this Atom. 87 */ 88 virtual void setId(atomId_t); 89 83 90 protected: 84 91 /** … … 101 108 private: 102 109 World* world; 103 int id;110 atomId_t id; 104 111 }; 105 112 … … 109 116 * Use World::createAtom() instead. 110 117 */ 111 atom* NewAtom( );118 atom* NewAtom(atomId_t _id); 112 119 113 120 /**
Note:
See TracChangeset
for help on using the changeset viewer.