Changeset e6a9c1 for src/World.cpp
- Timestamp:
- Mar 4, 2010, 10:40:52 AM (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:
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/World.cpp
r6a661c re6a9c1 13 13 #include "Descriptors/AtomDescriptor.hpp" 14 14 #include "Descriptors/AtomDescriptor_impl.hpp" 15 #include "Descriptors/MoleculeDescriptor.hpp" 16 #include "Descriptors/MoleculeDescriptor_impl.hpp" 15 17 #include "Actions/ManipulateAtomsProcess.hpp" 16 18 … … 22 24 } 23 25 26 // Atoms 27 24 28 atom* World::getAtom(AtomDescriptor descriptor){ 25 29 return descriptor.find(); … … 36 40 int World::numAtoms(){ 37 41 return atoms.size(); 42 } 43 44 // Molecules 45 46 molecule *World::getMolecule(MoleculeDescriptor descriptor){ 47 return descriptor.find(); 48 } 49 50 std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){ 51 return descriptor.findAll(); 38 52 } 39 53 … … 72 86 atom *World::createAtom(){ 73 87 OBSERVE; 74 atom *res = NewAtom(); 75 assert(!atoms.count(currAtomId)); 76 res->setId(currAtomId++); 88 atomId_t id = getNextAtomId(); 89 atom *res = NewAtom(id); 77 90 res->setWorld(this); 78 91 // store the atom by ID … … 83 96 int World::registerAtom(atom *atom){ 84 97 OBSERVE; 85 a ssert(!atoms.count(currAtomId));86 atom->setId( currAtomId++);98 atomId_t id = getNextAtomId(); 99 atom->setId(id); 87 100 atom->setWorld(this); 88 101 atoms[atom->getId()] = atom; … … 102 115 DeleteAtom(atom); 103 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 } 104 139 } 105 140 … … 122 157 proc->signOff(this); 123 158 } 159 /******************************* IDManagement *****************************/ 160 161 // Atoms 162 163 atomId_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 175 void 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 185 bool 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 124 205 125 206 /******************************* Iterators ********************************/ … … 135 216 World::AtomSet::iterator World::atomEnd(){ 136 217 return atoms.end(); 218 } 219 220 World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){ 221 return MoleculeIterator(descr,this); 222 } 223 224 World::MoleculeSet::iterator World::moleculeEnd(){ 225 return molecules.end(); 137 226 } 138 227
Note:
See TracChangeset
for help on using the changeset viewer.