source: src/World.cpp@ d2dbac0

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 Candidate_v1.7.0 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
Last change on this file since d2dbac0 was d2dbac0, checked in by Tillmann Crueger <crueger@…>, 16 years ago

moved Iterators for the World to a seperate file

  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[5d1611]1/*
2 * World.cpp
3 *
4 * Created on: Feb 3, 2010
5 * Author: crueger
6 */
7
8#include "World.hpp"
9
[d346b6]10#include "atom.hpp"
[354859]11#include "molecule.hpp"
12#include "periodentafel.hpp"
[fc1b24]13#include "Descriptors/AtomDescriptor.hpp"
[865a945]14#include "Descriptors/AtomDescriptor_impl.hpp"
[7c4e29]15#include "Actions/ManipulateAtomsProcess.hpp"
[d346b6]16
17using namespace std;
[4d9c01]18
[5d1611]19/******************************* getter and setter ************************/
[354859]20periodentafel *&World::getPeriode(){
[5d1611]21 return periode;
22}
23
[7a1ce5]24atom* World::getAtom(AtomDescriptor descriptor){
[fc1b24]25 return descriptor.find();
26}
27
[7a1ce5]28vector<atom*> World::getAllAtoms(AtomDescriptor descriptor){
[fc1b24]29 return descriptor.findAll();
30}
31
[0e2a47]32vector<atom*> World::getAllAtoms(){
33 return getAllAtoms(AllAtoms());
34}
35
[354859]36int World::numAtoms(){
37 return atoms.size();
38}
39
40int World::numMolecules(){
41 return molecules_deprecated->ListOfMolecules.size();
42}
43
[afb47f]44/******************** Methods to change World state *********************/
45
[354859]46molecule* World::createMolecule(){
47 OBSERVE;
48 molecule *mol = NULL;
49 mol = new molecule(periode);
50 molecules_deprecated->insert(mol);
[d2dbac0]51 assert(!molecules.count(currMoleculeId));
52 molecules[currMoleculeId++] = mol;
[354859]53 mol->signOn(this);
54 return mol;
55}
56
[7c4e29]57
[46d958]58atom *World::createAtom(){
59 OBSERVE;
60 atom *res = NewAtom();
[d2dbac0]61 assert(!atoms.count(currAtomId));
[46d958]62 res->setId(currAtomId++);
63 res->setWorld(this);
64 atoms[res->getId()] = res;
65 return res;
66}
67
68int World::registerAtom(atom *atom){
69 OBSERVE;
[d2dbac0]70 assert(!atoms.count(currAtomId));
[46d958]71 atom->setId(currAtomId++);
72 atom->setWorld(this);
73 atoms[atom->getId()] = atom;
74 return atom->getId();
75}
76
77void World::destroyAtom(atom* atom){
78 OBSERVE;
79 int id = atom->getId();
80 destroyAtom(id);
81}
82
83void World::destroyAtom(int id) {
84 OBSERVE;
85 atom *atom = atoms[id];
86 assert(atom);
87 DeleteAtom(atom);
88 atoms.erase(id);
89}
90
[7c4e29]91ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
92 return new ManipulateAtomsProcess(op, descr,name,true);
93}
94
[0e2a47]95ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
96 return manipulateAtoms(op,name,AllAtoms());
97}
98
[afb47f]99/********************* Internal Change methods for double Callback and Observer mechanism ********/
100
101void World::doManipulate(ManipulateAtomsProcess *proc){
102 proc->signOn(this);
103 {
104 OBSERVE;
105 proc->doManipulate(this);
106 }
107 proc->signOff(this);
108}
109
[865a945]110/******************************* Iterators ********************************/
111
[d2dbac0]112/*
113 * Actual Implementation of the iterators can be found in WorldIterators.cpp
114 */
[865a945]115
116World::AtomIterator World::getAtomIter(AtomDescriptor descr){
117 return AtomIterator(descr,this);
118}
[354859]119
[d2dbac0]120World::AtomSet::iterator World::atomEnd(){
[7c4e29]121 return atoms.end();
122}
123
[5d1611]124/******************************* Singleton Stuff **************************/
125
[4d9c01]126// TODO: Hide boost-thread using Autotools stuff when no threads are used
[5d1611]127World* World::theWorld = 0;
[4d9c01]128boost::mutex World::worldLock;
129
[5d1611]130
131
[7a1ce5]132World::World() :
[46d958]133 currAtomId(0),
[d2dbac0]134 currMoleculeId(0),
[354859]135 periode(new periodentafel),
[7c4e29]136 molecules_deprecated(new MoleculeListClass),
[d2dbac0]137 atoms(),
138 molecules()
[7dad10]139{
140 molecules_deprecated->signOn(this);
141}
[5d1611]142
143World::~World()
[354859]144{
[46d958]145 delete molecules_deprecated;
[354859]146 delete periode;
[d2dbac0]147 AtomSet::iterator iter;
[46d958]148 for(iter=atoms.begin();iter!=atoms.end();++iter){
149 DeleteAtom((*iter).second);
150 }
151 atoms.clear();
[354859]152}
[5d1611]153
154World* World::get(){
155 // boost supports RAII-Style locking, so we don't need to unlock
156 boost::mutex::scoped_lock guard(worldLock);
157 if(!theWorld) {
158 theWorld = new World();
159 }
160 return theWorld;
161}
162
163void World::destroy(){
164 // boost supports RAII-Style locking, so we don't need to unlock
165 boost::mutex::scoped_lock guard(worldLock);
166 delete theWorld;
167 theWorld = 0;
168}
169
170World* World::reset(){
171 World* oldWorld = 0;
172 {
173 // boost supports RAII-Style locking, so we don't need to unlock
174 boost::mutex::scoped_lock guard(worldLock);
175
176 oldWorld = theWorld;
177 theWorld = new World();
178 // oldworld does not need protection any more,
179 // since we should have the only reference
180
181 // worldLock handles access to the pointer,
182 // not to the object
183 } // scope-end releases the lock
184
185 // we have to let all the observers know that the
186 // oldWorld was destroyed. oldWorld calls subjectKilled
187 // upon destruction. Every Observer getting that signal
188 // should see that it gets the updated new world
189 delete oldWorld;
190}
191
192/******************************* deprecated Legacy Stuff ***********************/
193
[354859]194MoleculeListClass *&World::getMolecules() {
195 return molecules_deprecated;
[5d1611]196}
Note: See TracBrowser for help on using the repository browser.