source: src/World.cpp@ 53d894

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 53d894 was 5dfabd, checked in by Frederik Heber <heber@…>, 13 years ago

Added singleton class AtomObserver that acts as relay station to all atom changes.

  • uses Relay pattern.
  • is called in World::createAtom() to signOn on time.
  • update() relays the update call on to true observer.
  • Property mode set to 100644
File size: 19.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2011 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * World.cpp
10 *
11 * Created on: Feb 3, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "World.hpp"
23
24#include <functional>
25
26#include "Actions/ActionTrait.hpp"
27#include "Actions/ManipulateAtomsProcess.hpp"
28#include "Atom/atom.hpp"
29#include "Atom/AtomObserver.hpp"
30#include "Box.hpp"
31#include "CodePatterns/Assert.hpp"
32#include "config.hpp"
33#include "Descriptors/AtomDescriptor.hpp"
34#include "Descriptors/AtomDescriptor_impl.hpp"
35#include "Descriptors/MoleculeDescriptor.hpp"
36#include "Descriptors/MoleculeDescriptor_impl.hpp"
37#include "Descriptors/SelectiveIterator_impl.hpp"
38#include "Element/periodentafel.hpp"
39#include "Graph/BondGraph.hpp"
40#include "Graph/DepthFirstSearchAnalysis.hpp"
41#include "Helpers/defs.hpp"
42#include "LinearAlgebra/RealSpaceMatrix.hpp"
43#include "molecule.hpp"
44#include "MoleculeListClass.hpp"
45#include "Thermostats/ThermoStatContainer.hpp"
46#include "WorldTime.hpp"
47
48#include "IdPool_impl.hpp"
49
50#include "CodePatterns/Singleton_impl.hpp"
51#include "CodePatterns/Observer/Channels.hpp"
52#include "CodePatterns/Observer/ObservedContainer_impl.hpp"
53
54using namespace MoleCuilder;
55
56/******************************* Notifications ************************/
57
58
59atom* World::_lastchangedatom = NULL;
60molecule* World::_lastchangedmol = NULL;
61
62/******************************* getter and setter ************************/
63periodentafel *&World::getPeriode()
64{
65 return periode;
66}
67
68BondGraph *&World::getBondGraph()
69{
70 return BG;
71}
72
73void World::setBondGraph(BondGraph *_BG){
74 delete (BG);
75 BG = _BG;
76}
77
78config *&World::getConfig(){
79 return configuration;
80}
81
82// Atoms
83
84atom* World::getAtom(AtomDescriptor descriptor){
85 return descriptor.find();
86}
87
88World::AtomComposite World::getAllAtoms(AtomDescriptor descriptor){
89 return descriptor.findAll();
90}
91
92World::AtomComposite World::getAllAtoms(){
93 return getAllAtoms(AllAtoms());
94}
95
96int World::numAtoms(){
97 return atoms.size();
98}
99
100// Molecules
101
102molecule *World::getMolecule(MoleculeDescriptor descriptor){
103 return descriptor.find();
104}
105
106std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
107 return descriptor.findAll();
108}
109
110std::vector<molecule*> World::getAllMolecules(){
111 return getAllMolecules(AllMolecules());
112}
113
114int World::numMolecules(){
115 return molecules_deprecated->ListOfMolecules.size();
116}
117
118// system
119
120Box& World::getDomain() {
121 return *cell_size;
122}
123
124void World::setDomain(const RealSpaceMatrix &mat){
125 OBSERVE;
126 *cell_size = mat;
127}
128
129void World::setDomain(double * matrix)
130{
131 OBSERVE;
132 RealSpaceMatrix M = ReturnFullMatrixforSymmetric(matrix);
133 cell_size->setM(M);
134}
135
136void World::setTime(const unsigned int _step)
137{
138 if (_step != WorldTime::getTime()) {
139 // set new time
140 WorldTime::setTime(_step);
141 // TODO: removed when BondGraph creates the adjacency
142 // 1. remove all of World's molecules
143 for (MoleculeIterator iter = getMoleculeIter();
144 getMoleculeIter() != moleculeEnd();
145 iter = getMoleculeIter()) {
146 getMolecules()->erase(*iter);
147 destroyMolecule(*iter);
148 }
149 // 2. (re-)create bondgraph
150 AtomComposite Set = getAllAtoms();
151 BG->CreateAdjacency(Set);
152
153 // 3. scan for connected subgraphs => molecules
154 DepthFirstSearchAnalysis DFS;
155 DFS();
156 DFS.UpdateMoleculeStructure();
157 }
158}
159
160std::string World::getDefaultName() {
161 return defaultName;
162}
163
164void World::setDefaultName(std::string name)
165{
166 OBSERVE;
167 defaultName = name;
168};
169
170class ThermoStatContainer * World::getThermostats()
171{
172 return Thermostats;
173}
174
175
176int World::getExitFlag() {
177 return ExitFlag;
178}
179
180void World::setExitFlag(int flag) {
181 if (ExitFlag < flag)
182 ExitFlag = flag;
183}
184
185/******************** Methods to change World state *********************/
186
187molecule* World::createMolecule(){
188 OBSERVE;
189 molecule *mol = NULL;
190 mol = NewMolecule();
191 moleculeId_t id = moleculeIdPool.getNextId();
192 ASSERT(!molecules.count(id),"proposed id did not specify an unused ID");
193 mol->setId(id);
194 // store the molecule by ID
195 molecules[mol->getId()] = mol;
196 mol->signOn(this);
197 _lastchangedmol = mol;
198 NOTIFY(MoleculeInserted);
199 return mol;
200}
201
202void World::destroyMolecule(molecule* mol){
203 OBSERVE;
204 ASSERT(mol,"Molecule that was meant to be destroyed did not exist");
205 destroyMolecule(mol->getId());
206}
207
208void World::destroyMolecule(moleculeId_t id){
209 molecule *mol = molecules[id];
210 ASSERT(mol,"Molecule id that was meant to be destroyed did not exist");
211 // give notice about immediate removal
212 {
213 OBSERVE;
214 _lastchangedmol = mol;
215 NOTIFY(MoleculeRemoved);
216 }
217 DeleteMolecule(mol);
218 if (isMoleculeSelected(id))
219 selectedMolecules.erase(id);
220 molecules.erase(id);
221 moleculeIdPool.releaseId(id);
222}
223
224atom *World::createAtom(){
225 OBSERVE;
226 atomId_t id = atomIdPool.getNextId();
227 ASSERT(!atoms.count(id),"proposed id did not specify an unused ID");
228 atom *res = NewAtom(id);
229 res->setWorld(this);
230 // sign on to global atom change tracker
231 AtomObserver::getInstance().AtomInserted(res);
232 // store the atom by ID
233 atoms[res->getId()] = res;
234 _lastchangedatom = res;
235 NOTIFY(AtomInserted);
236 return res;
237}
238
239
240int World::registerAtom(atom *atom){
241 OBSERVE;
242 atomId_t id = atomIdPool.getNextId();
243 atom->setId(id);
244 atom->setWorld(this);
245 atoms[atom->getId()] = atom;
246 return atom->getId();
247}
248
249void World::destroyAtom(atom* atom){
250 int id = atom->getId();
251 destroyAtom(id);
252}
253
254void World::destroyAtom(atomId_t id) {
255 atom *atom = atoms[id];
256 ASSERT(atom,"Atom ID that was meant to be destroyed did not exist");
257 // give notice about immediate removal
258 {
259 OBSERVE;
260 _lastchangedatom = atom;
261 NOTIFY(AtomRemoved);
262 }
263 DeleteAtom(atom);
264 if (isAtomSelected(id))
265 selectedAtoms.erase(id);
266 atoms.erase(id);
267 atomIdPool.releaseId(id);
268}
269
270bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
271 OBSERVE;
272 // in case this call did not originate from inside the atom, we redirect it,
273 // to also let it know that it has changed
274 if(!target){
275 target = atoms[oldId];
276 ASSERT(target,"Atom with that ID not found");
277 return target->changeId(newId);
278 }
279 else{
280 if(atomIdPool.reserveId(newId)){
281 atoms.erase(oldId);
282 atoms.insert(pair<atomId_t,atom*>(newId,target));
283 return true;
284 }
285 else{
286 return false;
287 }
288 }
289}
290
291bool World::changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target){
292 OBSERVE;
293 // in case this call did not originate from inside the atom, we redirect it,
294 // to also let it know that it has changed
295 if(!target){
296 target = molecules[oldId];
297 ASSERT(target,"Molecule with that ID not found");
298 return target->changeId(newId);
299 }
300 else{
301 if(moleculeIdPool.reserveId(newId)){
302 molecules.erase(oldId);
303 molecules.insert(pair<moleculeId_t,molecule*>(newId,target));
304 return true;
305 }
306 else{
307 return false;
308 }
309 }
310}
311
312ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
313 ActionTrait manipulateTrait(name);
314 return new ManipulateAtomsProcess(op, descr,manipulateTrait,false);
315}
316
317ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
318 return manipulateAtoms(op,name,AllAtoms());
319}
320
321/********************* Internal Change methods for double Callback and Observer mechanism ********/
322
323void World::doManipulate(ManipulateAtomsProcess *proc){
324 proc->signOn(this);
325 {
326 OBSERVE;
327 proc->doManipulate(this);
328 }
329 proc->signOff(this);
330}
331/******************************* Iterators ********************************/
332
333// external parts with observers
334
335CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor);
336
337World::AtomIterator
338World::getAtomIter(AtomDescriptor descr){
339 return AtomIterator(descr,atoms);
340}
341
342World::AtomIterator
343World::getAtomIter(){
344 return AtomIterator(AllAtoms(),atoms);
345}
346
347World::AtomIterator
348World::atomEnd(){
349 return AtomIterator(AllAtoms(),atoms,atoms.end());
350}
351
352CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor);
353
354World::MoleculeIterator
355World::getMoleculeIter(MoleculeDescriptor descr){
356 return MoleculeIterator(descr,molecules);
357}
358
359World::MoleculeIterator
360World::getMoleculeIter(){
361 return MoleculeIterator(AllMolecules(),molecules);
362}
363
364World::MoleculeIterator
365World::moleculeEnd(){
366 return MoleculeIterator(AllMolecules(),molecules,molecules.end());
367}
368
369// Internal parts, without observers
370
371// Build the AtomIterator from template
372CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet::set_t,AtomDescriptor);
373
374
375World::internal_AtomIterator
376World::getAtomIter_internal(AtomDescriptor descr){
377 return internal_AtomIterator(descr,atoms.getContent());
378}
379
380World::internal_AtomIterator
381World::atomEnd_internal(){
382 return internal_AtomIterator(AllAtoms(),atoms.getContent(),atoms.end_internal());
383}
384
385// build the MoleculeIterator from template
386CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet::set_t,MoleculeDescriptor);
387
388World::internal_MoleculeIterator World::getMoleculeIter_internal(MoleculeDescriptor descr){
389 return internal_MoleculeIterator(descr,molecules.getContent());
390}
391
392World::internal_MoleculeIterator World::moleculeEnd_internal(){
393 return internal_MoleculeIterator(AllMolecules(),molecules.getContent(),molecules.end_internal());
394}
395
396/************************** Selection of Atoms and molecules ******************/
397
398// Atoms
399
400void World::clearAtomSelection(){
401 selectedAtoms.clear();
402}
403
404void World::selectAtom(const atom *_atom){
405 // atom * is unchanged in this function, but we do store entity as changeable
406 ASSERT(_atom,"Invalid pointer in selection of atom");
407 selectedAtoms[_atom->getId()]=const_cast<atom *>(_atom);
408}
409
410void World::selectAtom(const atomId_t id){
411 ASSERT(atoms.count(id),"Atom Id selected that was not in the world");
412 selectedAtoms[id]=atoms[id];
413}
414
415void World::selectAllAtoms(AtomDescriptor descr){
416 internal_AtomIterator begin = getAtomIter_internal(descr);
417 internal_AtomIterator end = atomEnd_internal();
418 void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
419 for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
420}
421
422void World::selectAtomsOfMolecule(const molecule *_mol){
423 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
424 // need to make it const to get the fast iterators
425 const molecule *mol = _mol;
426 void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
427 for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is select... see above
428}
429
430void World::selectAtomsOfMolecule(const moleculeId_t id){
431 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
432 selectAtomsOfMolecule(molecules[id]);
433}
434
435void World::unselectAtom(const atom *_atom){
436 ASSERT(_atom,"Invalid pointer in unselection of atom");
437 unselectAtom(_atom->getId());
438}
439
440void World::unselectAtom(const atomId_t id){
441 ASSERT(atoms.count(id),"Atom Id unselected that was not in the world");
442 selectedAtoms.erase(id);
443}
444
445void World::unselectAllAtoms(AtomDescriptor descr){
446 internal_AtomIterator begin = getAtomIter_internal(descr);
447 internal_AtomIterator end = atomEnd_internal();
448 void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
449 for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
450}
451
452void World::unselectAtomsOfMolecule(const molecule *_mol){
453 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
454 // need to make it const to get the fast iterators
455 const molecule *mol = _mol;
456 void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
457 for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is unsselect... see above
458}
459
460void World::unselectAtomsOfMolecule(const moleculeId_t id){
461 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
462 unselectAtomsOfMolecule(molecules[id]);
463}
464
465size_t World::countSelectedAtoms() const {
466 size_t count = 0;
467 for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
468 count++;
469 return count;
470}
471
472bool World::isSelected(const atom *_atom) const {
473 return isAtomSelected(_atom->getId());
474}
475
476bool World::isAtomSelected(const atomId_t no) const {
477 return selectedAtoms.find(no) != selectedAtoms.end();
478}
479
480const std::vector<atom *> World::getSelectedAtoms() const {
481 std::vector<atom *> returnAtoms;
482 returnAtoms.resize(countSelectedAtoms());
483 int count = 0;
484 for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
485 returnAtoms[count++] = iter->second;
486 return returnAtoms;
487}
488
489
490// Molecules
491
492void World::clearMoleculeSelection(){
493 selectedMolecules.clear();
494}
495
496void World::selectMolecule(const molecule *_mol){
497 // molecule * is unchanged in this function, but we do store entity as changeable
498 ASSERT(_mol,"Invalid pointer to molecule in selection");
499 selectedMolecules[_mol->getId()]=const_cast<molecule *>(_mol);
500}
501
502void World::selectMolecule(const moleculeId_t id){
503 ASSERT(molecules.count(id),"Molecule Id selected that was not in the world");
504 selectedMolecules[id]=molecules[id];
505}
506
507void World::selectAllMolecules(MoleculeDescriptor descr){
508 internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
509 internal_MoleculeIterator end = moleculeEnd_internal();
510 void (World::*func)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
511 for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
512}
513
514void World::selectMoleculeOfAtom(const atom *_atom){
515 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
516 molecule *mol=_atom->getMolecule();
517 // the atom might not be part of a molecule
518 if(mol){
519 selectMolecule(mol);
520 }
521}
522
523void World::selectMoleculeOfAtom(const atomId_t id){
524 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
525 selectMoleculeOfAtom(atoms[id]);
526}
527
528void World::unselectMolecule(const molecule *_mol){
529 ASSERT(_mol,"invalid pointer in unselection of molecule");
530 unselectMolecule(_mol->getId());
531}
532
533void World::unselectMolecule(const moleculeId_t id){
534 ASSERT(molecules.count(id),"No such molecule with ID in unselection");
535 selectedMolecules.erase(id);
536}
537
538void World::unselectAllMolecules(MoleculeDescriptor descr){
539 internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
540 internal_MoleculeIterator end = moleculeEnd_internal();
541 void (World::*func)(const molecule*) = &World::unselectMolecule; // needed for type resolution of overloaded function
542 for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
543}
544
545void World::unselectMoleculeOfAtom(const atom *_atom){
546 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
547 molecule *mol=_atom->getMolecule();
548 // the atom might not be part of a molecule
549 if(mol){
550 unselectMolecule(mol);
551 }
552}
553
554void World::unselectMoleculeOfAtom(const atomId_t id){
555 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
556 unselectMoleculeOfAtom(atoms[id]);
557}
558
559size_t World::countSelectedMolecules() const {
560 size_t count = 0;
561 for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
562 count++;
563 return count;
564}
565
566bool World::isSelected(const molecule *_mol) const {
567 return isMoleculeSelected(_mol->getId());
568}
569
570bool World::isMoleculeSelected(const moleculeId_t no) const {
571 return selectedMolecules.find(no) != selectedMolecules.end();
572}
573
574const std::vector<molecule *> World::getSelectedMolecules() const {
575 std::vector<molecule *> returnMolecules;
576 returnMolecules.resize(countSelectedMolecules());
577 int count = 0;
578 for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
579 returnMolecules[count++] = iter->second;
580 return returnMolecules;
581}
582
583/******************* Iterators over Selection *****************************/
584World::AtomSelectionIterator World::beginAtomSelection(){
585 return selectedAtoms.begin();
586}
587
588World::AtomSelectionIterator World::endAtomSelection(){
589 return selectedAtoms.end();
590}
591
592World::AtomSelectionConstIterator World::beginAtomSelection() const{
593 return selectedAtoms.begin();
594}
595
596World::AtomSelectionConstIterator World::endAtomSelection() const{
597 return selectedAtoms.end();
598}
599
600
601World::MoleculeSelectionIterator World::beginMoleculeSelection(){
602 return selectedMolecules.begin();
603}
604
605World::MoleculeSelectionIterator World::endMoleculeSelection(){
606 return selectedMolecules.end();
607}
608
609World::MoleculeSelectionConstIterator World::beginMoleculeSelection() const{
610 return selectedMolecules.begin();
611}
612
613World::MoleculeSelectionConstIterator World::endMoleculeSelection() const{
614 return selectedMolecules.end();
615}
616
617/******************************* Singleton Stuff **************************/
618
619World::World() :
620 Observable("World"),
621 BG(new BondGraph(true)), // assume Angstroem for the moment
622 periode(new periodentafel(true)),
623 configuration(new config),
624 Thermostats(new ThermoStatContainer),
625 ExitFlag(0),
626 atoms(this),
627 selectedAtoms(this),
628 atomIdPool(0, 20, 100),
629 molecules(this),
630 selectedMolecules(this),
631 moleculeIdPool(0, 20,100),
632 molecules_deprecated(new MoleculeListClass(this))
633{
634 cell_size = new Box;
635 RealSpaceMatrix domain;
636 domain.at(0,0) = 20;
637 domain.at(1,1) = 20;
638 domain.at(2,2) = 20;
639 cell_size->setM(domain);
640 defaultName = "none";
641 Channels *OurChannel = new Channels;
642 NotificationChannels.insert( std::make_pair( this, OurChannel) );
643 for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type)
644 OurChannel->addChannel(type);
645 molecules_deprecated->signOn(this);
646}
647
648World::~World()
649{
650 molecules_deprecated->signOff(this);
651 delete cell_size;
652 delete molecules_deprecated;
653 MoleculeSet::iterator molIter;
654 for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
655 DeleteMolecule((*molIter).second);
656 }
657 molecules.clear();
658 AtomSet::iterator atIter;
659 for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
660 DeleteAtom((*atIter).second);
661 }
662 atoms.clear();
663
664 // empty notifications
665 std::map<Observable *, Channels*>::iterator iter = NotificationChannels.find(this);
666 ASSERT(iter != NotificationChannels.end(),
667 "World::~World() - cannot find our Channels in NotificationChannels.");
668 delete iter->second;
669 NotificationChannels.erase(iter);
670
671 delete BG;
672 delete periode;
673 delete configuration;
674 delete Thermostats;
675}
676
677// Explicit instantiation of the singleton mechanism at this point
678
679// moleculeId_t und atomId_t sind gleicher Basistyp, deswegen nur einen von beiden konstruieren
680CONSTRUCT_IDPOOL(moleculeId_t)
681
682CONSTRUCT_SINGLETON(World)
683
684CONSTRUCT_OBSERVEDCONTAINER(World::AtomSTLSet)
685
686CONSTRUCT_OBSERVEDCONTAINER(World::MoleculeSTLSet)
687
688/******************************* deprecated Legacy Stuff ***********************/
689
690MoleculeListClass *&World::getMolecules() {
691 return molecules_deprecated;
692}
Note: See TracBrowser for help on using the repository browser.