source: src/World.cpp@ fea945

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 fea945 was 02ce36, checked in by Frederik Heber <heber@…>, 13 years ago

We now require CodePatterns 1.2.0.

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