source: src/World.cpp@ 6a661c

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
Last change on this file since 6a661c was a1510d, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'FreddiesRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Patterns/Observer.cpp
molecuilder/src/World.cpp
molecuilder/src/boundary.cpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/AnalysisPairCorrelationUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

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