source: src/World.cpp@ 1c51c8

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 1c51c8 was 1c51c8, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Added methods for querying molecules using descriptors

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