source: src/World.cpp@ a42fee

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 a42fee was 126867, checked in by Frederik Heber <heber@…>, 11 years ago

Actions no longer register themselves, ActionQueue::addAction() introduced.

  • eventually, Actions should be constrained to the ActionQueue alone. They may be created externally but their control has to be delivered to the ActionQueue.
  • Hence, we reversed the registering process: Actions do not register themselves with the ActionRegistry but as almost all are created in ActionRegistry::fillRegistry() they are registered there as well.
  • Actions cstor and dstor are now protected, ActionRegistry is friend.
  • Action needs to befriend Registry<T> and ActionSequenceTest to grant access to dstor.
  • Property mode set to 100644
File size: 24.3 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[94d5ac6]6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
[bcf653]22 */
23
[5d1611]24/*
25 * World.cpp
26 *
27 * Created on: Feb 3, 2010
28 * Author: crueger
29 */
30
[bf3817]31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
[ad011c]36#include "CodePatterns/MemDebug.hpp"
[112b09]37
[5d1611]38#include "World.hpp"
39
[90c4280]40#include <functional>
[5d1611]41
[3139b2]42#include "Actions/ActionTrait.hpp"
[d297a3]43#include "Actions/ManipulateAtomsProcess.hpp"
[6f0841]44#include "Atom/atom.hpp"
[d297a3]45#include "Box.hpp"
46#include "CodePatterns/Assert.hpp"
[8e1f7af]47#include "config.hpp"
[fc1b24]48#include "Descriptors/AtomDescriptor.hpp"
[865a945]49#include "Descriptors/AtomDescriptor_impl.hpp"
[ebc499]50#include "Descriptors/AtomSelectionDescriptor.hpp"
[1c51c8]51#include "Descriptors/MoleculeDescriptor.hpp"
52#include "Descriptors/MoleculeDescriptor_impl.hpp"
[ebc499]53#include "Descriptors/MoleculeSelectionDescriptor.hpp"
[feb5d0]54#include "Descriptors/SelectiveConstIterator_impl.hpp"
[6e97e5]55#include "Descriptors/SelectiveIterator_impl.hpp"
[42127c]56#include "Element/periodentafel.hpp"
[98dbee]57#include "Fragmentation/Homology/HomologyContainer.hpp"
[3139b2]58#include "Graph/BondGraph.hpp"
[4b8630]59#include "Graph/DepthFirstSearchAnalysis.hpp"
[e4fe8d]60#include "Helpers/defs.hpp"
[d297a3]61#include "LinearAlgebra/RealSpaceMatrix.hpp"
[4834f4]62#include "LinkedCell/LinkedCell_Controller.hpp"
63#include "LinkedCell/PointCloudAdaptor.hpp"
[d297a3]64#include "molecule.hpp"
[42127c]65#include "MoleculeListClass.hpp"
[ab26c3]66#include "Thermostats/ThermoStatContainer.hpp"
[d297a3]67#include "WorldTime.hpp"
[d346b6]68
[3e4fb6]69#include "IdPool_impl.hpp"
70
[4834f4]71#include "CodePatterns/IteratorAdaptors.hpp"
[ad011c]72#include "CodePatterns/Singleton_impl.hpp"
[02ce36]73#include "CodePatterns/Observer/Channels.hpp"
74#include "CodePatterns/Observer/ObservedContainer_impl.hpp"
[23b547]75
[ce7fdc]76using namespace MoleCuilder;
[4d9c01]77
[7188b1]78/******************************* Notifications ************************/
79
80
81atom* World::_lastchangedatom = NULL;
82molecule* World::_lastchangedmol = NULL;
83
[5d1611]84/******************************* getter and setter ************************/
[f71baf]85periodentafel *&World::getPeriode()
86{
[5d1611]87 return periode;
88}
89
[f71baf]90BondGraph *&World::getBondGraph()
91{
92 return BG;
93}
94
[98dbee]95HomologyContainer &World::getHomologies()
96{
97 return *homologies;
98}
99
100void World::resetHomologies(HomologyContainer *&_homologies)
101{
102 HomologyContainer *oldhomologies = homologies;
103
104 // install new instance, resetting given pointer
105 homologies = _homologies;
106 _homologies = NULL;
107
108 // delete old instance which also informs all observers
109 delete oldhomologies;
110}
111
[f71baf]112void World::setBondGraph(BondGraph *_BG){
113 delete (BG);
114 BG = _BG;
115}
116
[8e1f7af]117config *&World::getConfig(){
118 return configuration;
119}
120
[1c51c8]121// Atoms
122
[7a1ce5]123atom* World::getAtom(AtomDescriptor descriptor){
[fc1b24]124 return descriptor.find();
125}
126
[4d72e4]127World::AtomComposite World::getAllAtoms(AtomDescriptor descriptor){
[fc1b24]128 return descriptor.findAll();
129}
130
[4d72e4]131World::AtomComposite World::getAllAtoms(){
[0e2a47]132 return getAllAtoms(AllAtoms());
133}
134
[354859]135int World::numAtoms(){
136 return atoms.size();
137}
138
[1c51c8]139// Molecules
140
141molecule *World::getMolecule(MoleculeDescriptor descriptor){
142 return descriptor.find();
143}
144
145std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
146 return descriptor.findAll();
147}
148
[97ebf8]149std::vector<molecule*> World::getAllMolecules(){
150 return getAllMolecules(AllMolecules());
151}
152
[354859]153int World::numMolecules(){
154 return molecules_deprecated->ListOfMolecules.size();
155}
156
[5f612ee]157// system
158
[84c494]159Box& World::getDomain() {
160 return *cell_size;
161}
162
[cca9ef]163void World::setDomain(const RealSpaceMatrix &mat){
[be97a8]164 OBSERVE;
[84c494]165 *cell_size = mat;
[5f612ee]166}
167
168void World::setDomain(double * matrix)
169{
[b9c847]170 OBSERVE;
[cca9ef]171 RealSpaceMatrix M = ReturnFullMatrixforSymmetric(matrix);
[84c494]172 cell_size->setM(M);
[5f612ee]173}
174
[03abd0]175LinkedCell::LinkedCell_View World::getLinkedCell(double distance)
[4834f4]176{
[d067e35]177 ASSERT( distance >= 0,
[03abd0]178 "World::getLinkedCell() - distance is not positive.");
179 if (distance < 1.) {
180 ELOG(2, "Linked cell grid with length less than 1. is very memory-intense!");
181 distance = 1.;
182 }
[4834f4]183 // we have to grope past the ObservedContainer mechanism and transmorph the map
184 // into a traversable list for the adaptor
185 PointCloudAdaptor< AtomSet::set_t, MapValueIterator<AtomSet::set_t::iterator> > atomset(
186 &(atoms.getContent()),
187 std::string("WorldsAtoms"));
188 return LCcontroller->getView(distance, atomset);
189}
190
[2a8731]191const unsigned World::getTime() const
192{
193 return WorldTime::getTime();
194}
195
[d297a3]196void World::setTime(const unsigned int _step)
197{
[76163d]198 if (_step != WorldTime::getTime()) {
199 // set new time
[040a5c]200 WorldTime::getInstance().setTime(_step);
[4b8630]201 // TODO: removed when BondGraph creates the adjacency
202 // 1. remove all of World's molecules
203 for (MoleculeIterator iter = getMoleculeIter();
204 getMoleculeIter() != moleculeEnd();
205 iter = getMoleculeIter()) {
206 getMolecules()->erase(*iter);
207 destroyMolecule(*iter);
208 }
209 // 2. (re-)create bondgraph
210 AtomComposite Set = getAllAtoms();
211 BG->CreateAdjacency(Set);
212
213 // 3. scan for connected subgraphs => molecules
214 DepthFirstSearchAnalysis DFS;
215 DFS();
216 DFS.UpdateMoleculeStructure();
[76163d]217 }
[d297a3]218}
219
[387b36]220std::string World::getDefaultName() {
[5f612ee]221 return defaultName;
222}
223
[387b36]224void World::setDefaultName(std::string name)
[5f612ee]225{
[be97a8]226 OBSERVE;
[387b36]227 defaultName = name;
[5f612ee]228};
229
[43dad6]230class ThermoStatContainer * World::getThermostats()
231{
232 return Thermostats;
233}
234
235
[e4b5de]236int World::getExitFlag() {
237 return ExitFlag;
238}
239
240void World::setExitFlag(int flag) {
241 if (ExitFlag < flag)
242 ExitFlag = flag;
243}
[5f612ee]244
[afb47f]245/******************** Methods to change World state *********************/
246
[354859]247molecule* World::createMolecule(){
248 OBSERVE;
249 molecule *mol = NULL;
[cbc5fb]250 mol = NewMolecule();
[3e4fb6]251 moleculeId_t id = moleculeIdPool.getNextId();
[127a8e]252 ASSERT(!molecules.count(id),"proposed id did not specify an unused ID");
253 mol->setId(id);
[244d26]254 // store the molecule by ID
[cbc5fb]255 molecules[mol->getId()] = mol;
[354859]256 mol->signOn(this);
[7188b1]257 _lastchangedmol = mol;
258 NOTIFY(MoleculeInserted);
[354859]259 return mol;
260}
261
[cbc5fb]262void World::destroyMolecule(molecule* mol){
263 OBSERVE;
[fa7989]264 ASSERT(mol,"Molecule that was meant to be destroyed did not exist");
[cbc5fb]265 destroyMolecule(mol->getId());
266}
267
268void World::destroyMolecule(moleculeId_t id){
269 molecule *mol = molecules[id];
[6d574a]270 ASSERT(mol,"Molecule id that was meant to be destroyed did not exist");
[38f991]271 // give notice about immediate removal
272 {
273 OBSERVE;
274 _lastchangedmol = mol;
275 NOTIFY(MoleculeRemoved);
276 }
[7d82a5]277 mol->signOff(this);
[cbc5fb]278 DeleteMolecule(mol);
[38f991]279 if (isMoleculeSelected(id))
280 selectedMolecules.erase(id);
[cbc5fb]281 molecules.erase(id);
[3e4fb6]282 moleculeIdPool.releaseId(id);
[cbc5fb]283}
284
[46d958]285atom *World::createAtom(){
286 OBSERVE;
[3e4fb6]287 atomId_t id = atomIdPool.getNextId();
[127a8e]288 ASSERT(!atoms.count(id),"proposed id did not specify an unused ID");
[88d586]289 atom *res = NewAtom(id);
[46d958]290 res->setWorld(this);
[244d26]291 // store the atom by ID
[46d958]292 atoms[res->getId()] = res;
[7188b1]293 _lastchangedatom = res;
294 NOTIFY(AtomInserted);
[46d958]295 return res;
296}
297
[5f612ee]298
[46d958]299int World::registerAtom(atom *atom){
300 OBSERVE;
[3e4fb6]301 atomId_t id = atomIdPool.getNextId();
[88d586]302 atom->setId(id);
[46d958]303 atom->setWorld(this);
304 atoms[atom->getId()] = atom;
[65d7ca]305 _lastchangedatom = atom;
306 NOTIFY(AtomInserted);
[46d958]307 return atom->getId();
308}
309
310void World::destroyAtom(atom* atom){
311 int id = atom->getId();
312 destroyAtom(id);
313}
314
[cbc5fb]315void World::destroyAtom(atomId_t id) {
[46d958]316 atom *atom = atoms[id];
[6d574a]317 ASSERT(atom,"Atom ID that was meant to be destroyed did not exist");
[ab4a33]318 // give notice about immediate removal
319 {
320 OBSERVE;
321 _lastchangedatom = atom;
322 NOTIFY(AtomRemoved);
323 }
[46d958]324 DeleteAtom(atom);
[38f991]325 if (isAtomSelected(id))
326 selectedAtoms.erase(id);
[46d958]327 atoms.erase(id);
[3e4fb6]328 atomIdPool.releaseId(id);
[88d586]329}
330
331bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
332 OBSERVE;
333 // in case this call did not originate from inside the atom, we redirect it,
334 // to also let it know that it has changed
335 if(!target){
336 target = atoms[oldId];
[6d574a]337 ASSERT(target,"Atom with that ID not found");
[88d586]338 return target->changeId(newId);
339 }
340 else{
[3e4fb6]341 if(atomIdPool.reserveId(newId)){
[88d586]342 atoms.erase(oldId);
343 atoms.insert(pair<atomId_t,atom*>(newId,target));
344 return true;
345 }
346 else{
347 return false;
348 }
349 }
[46d958]350}
351
[a7a087]352bool World::changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target){
353 OBSERVE;
354 // in case this call did not originate from inside the atom, we redirect it,
355 // to also let it know that it has changed
356 if(!target){
357 target = molecules[oldId];
358 ASSERT(target,"Molecule with that ID not found");
359 return target->changeId(newId);
360 }
361 else{
[3e4fb6]362 if(moleculeIdPool.reserveId(newId)){
[a7a087]363 molecules.erase(oldId);
364 molecules.insert(pair<moleculeId_t,molecule*>(newId,target));
365 return true;
366 }
367 else{
368 return false;
369 }
370 }
371}
372
[7c4e29]373ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
[3139b2]374 ActionTrait manipulateTrait(name);
[126867]375 return new ManipulateAtomsProcess(op, descr,manipulateTrait);
[7c4e29]376}
377
[0e2a47]378ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
379 return manipulateAtoms(op,name,AllAtoms());
380}
381
[afb47f]382/********************* Internal Change methods for double Callback and Observer mechanism ********/
383
384void World::doManipulate(ManipulateAtomsProcess *proc){
385 proc->signOn(this);
386 {
387 OBSERVE;
388 proc->doManipulate(this);
389 }
390 proc->signOff(this);
391}
[865a945]392/******************************* Iterators ********************************/
393
[fa0b18]394// external parts with observers
395
[feb5d0]396CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor)
397
398CONSTRUCT_SELECTIVE_CONST_ITERATOR(atom*,World::AtomSet,AtomDescriptor)
[6e97e5]399
[fa0b18]400World::AtomIterator
401World::getAtomIter(AtomDescriptor descr){
402 return AtomIterator(descr,atoms);
403}
[865a945]404
[feb5d0]405World::AtomConstIterator
406World::getAtomIter(AtomDescriptor descr) const{
407 return AtomConstIterator(descr,atoms);
408}
409
[fa0b18]410World::AtomIterator
411World::getAtomIter(){
412 return AtomIterator(AllAtoms(),atoms);
[865a945]413}
[354859]414
[feb5d0]415World::AtomConstIterator
416World::getAtomIter() const{
417 return AtomConstIterator(AllAtoms(),atoms);
418}
419
[fa0b18]420World::AtomIterator
421World::atomEnd(){
[6e97e5]422 return AtomIterator(AllAtoms(),atoms,atoms.end());
[7c4e29]423}
424
[feb5d0]425World::AtomConstIterator
426World::atomEnd() const{
427 return AtomConstIterator(AllAtoms(),atoms,atoms.end());
428}
429
430CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor)
431
432CONSTRUCT_SELECTIVE_CONST_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor)
[6e97e5]433
[5d880e]434World::MoleculeIterator
435World::getMoleculeIter(MoleculeDescriptor descr){
436 return MoleculeIterator(descr,molecules);
437}
438
[feb5d0]439World::MoleculeConstIterator
440World::getMoleculeIter(MoleculeDescriptor descr) const{
441 return MoleculeConstIterator(descr,molecules);
442}
443
[5d880e]444World::MoleculeIterator
445World::getMoleculeIter(){
446 return MoleculeIterator(AllMolecules(),molecules);
[1c51c8]447}
448
[feb5d0]449World::MoleculeConstIterator
450World::getMoleculeIter() const{
451 return MoleculeConstIterator(AllMolecules(),molecules);
452}
453
[5d880e]454World::MoleculeIterator
455World::moleculeEnd(){
[6e97e5]456 return MoleculeIterator(AllMolecules(),molecules,molecules.end());
[1c51c8]457}
458
[feb5d0]459World::MoleculeConstIterator
460World::moleculeEnd() const{
461 return MoleculeConstIterator(AllMolecules(),molecules,molecules.end());
462}
463
[fa0b18]464// Internal parts, without observers
465
466// Build the AtomIterator from template
467CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet::set_t,AtomDescriptor);
468
469
470World::internal_AtomIterator
471World::getAtomIter_internal(AtomDescriptor descr){
472 return internal_AtomIterator(descr,atoms.getContent());
473}
474
475World::internal_AtomIterator
476World::atomEnd_internal(){
477 return internal_AtomIterator(AllAtoms(),atoms.getContent(),atoms.end_internal());
478}
479
[6e97e5]480// build the MoleculeIterator from template
[e3d865]481CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet::set_t,MoleculeDescriptor);
[6e97e5]482
[e3d865]483World::internal_MoleculeIterator World::getMoleculeIter_internal(MoleculeDescriptor descr){
484 return internal_MoleculeIterator(descr,molecules.getContent());
[1c51c8]485}
486
[e3d865]487World::internal_MoleculeIterator World::moleculeEnd_internal(){
488 return internal_MoleculeIterator(AllMolecules(),molecules.getContent(),molecules.end_internal());
[1c51c8]489}
490
[90c4280]491/************************** Selection of Atoms and molecules ******************/
492
493// Atoms
494
495void World::clearAtomSelection(){
[69643a]496 OBSERVE;
497 NOTIFY(SelectionChanged);
[90c4280]498 selectedAtoms.clear();
499}
500
[ebc499]501void World::invertAtomSelection(){
502 // get all atoms not selected
503 AtomComposite invertedSelection(getAllAtoms());
504 bool (World::*predicate)(const atom*) const = &World::isSelected; // needed for type resolution of overloaded function
505 AtomComposite::iterator iter =
506 std::remove_if(invertedSelection.begin(), invertedSelection.end(),
507 std::bind1st(std::mem_fun(predicate), this));
508 invertedSelection.erase(iter, invertedSelection.end());
509 // apply new selection
510 selectedAtoms.clear();
511 void (World::*selector)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
512 std::for_each(invertedSelection.begin(),invertedSelection.end(),
513 std::bind1st(std::mem_fun(selector),this)); // func is select... see above
514}
515
[e4afb4]516void World::selectAtom(const atom *_atom){
[69643a]517 OBSERVE;
518 NOTIFY(SelectionChanged);
[e4afb4]519 // atom * is unchanged in this function, but we do store entity as changeable
520 ASSERT(_atom,"Invalid pointer in selection of atom");
521 selectedAtoms[_atom->getId()]=const_cast<atom *>(_atom);
[90c4280]522}
523
[e4afb4]524void World::selectAtom(const atomId_t id){
[69643a]525 OBSERVE;
526 NOTIFY(SelectionChanged);
[90c4280]527 ASSERT(atoms.count(id),"Atom Id selected that was not in the world");
528 selectedAtoms[id]=atoms[id];
529}
530
531void World::selectAllAtoms(AtomDescriptor descr){
[69643a]532 OBSERVE;
533 NOTIFY(SelectionChanged);
[90c4280]534 internal_AtomIterator begin = getAtomIter_internal(descr);
535 internal_AtomIterator end = atomEnd_internal();
[e4afb4]536 void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
[90c4280]537 for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
538}
539
[e4afb4]540void World::selectAtomsOfMolecule(const molecule *_mol){
[69643a]541 OBSERVE;
542 NOTIFY(SelectionChanged);
[90c4280]543 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
544 // need to make it const to get the fast iterators
545 const molecule *mol = _mol;
[e4afb4]546 void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
[90c4280]547 for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is select... see above
548}
549
[e4afb4]550void World::selectAtomsOfMolecule(const moleculeId_t id){
[69643a]551 OBSERVE;
552 NOTIFY(SelectionChanged);
[90c4280]553 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
554 selectAtomsOfMolecule(molecules[id]);
555}
556
[e4afb4]557void World::unselectAtom(const atom *_atom){
[69643a]558 OBSERVE;
559 NOTIFY(SelectionChanged);
[e4afb4]560 ASSERT(_atom,"Invalid pointer in unselection of atom");
561 unselectAtom(_atom->getId());
[61d655e]562}
563
[e4afb4]564void World::unselectAtom(const atomId_t id){
[69643a]565 OBSERVE;
566 NOTIFY(SelectionChanged);
[61d655e]567 ASSERT(atoms.count(id),"Atom Id unselected that was not in the world");
568 selectedAtoms.erase(id);
569}
570
571void World::unselectAllAtoms(AtomDescriptor descr){
[69643a]572 OBSERVE;
573 NOTIFY(SelectionChanged);
[61d655e]574 internal_AtomIterator begin = getAtomIter_internal(descr);
575 internal_AtomIterator end = atomEnd_internal();
[e4afb4]576 void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
[61d655e]577 for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
578}
579
[e4afb4]580void World::unselectAtomsOfMolecule(const molecule *_mol){
[69643a]581 OBSERVE;
582 NOTIFY(SelectionChanged);
[61d655e]583 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
584 // need to make it const to get the fast iterators
585 const molecule *mol = _mol;
[e4afb4]586 void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
[992bd5]587 for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is unselect... see above
[61d655e]588}
589
[e4afb4]590void World::unselectAtomsOfMolecule(const moleculeId_t id){
[69643a]591 OBSERVE;
592 NOTIFY(SelectionChanged);
[61d655e]593 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
594 unselectAtomsOfMolecule(molecules[id]);
595}
596
[e472eab]597size_t World::countSelectedAtoms() const {
[eacc3b]598 size_t count = 0;
[e472eab]599 for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
[eacc3b]600 count++;
601 return count;
602}
603
[e4afb4]604bool World::isSelected(const atom *_atom) const {
[89643d]605 return isAtomSelected(_atom->getId());
606}
607
608bool World::isAtomSelected(const atomId_t no) const {
609 return selectedAtoms.find(no) != selectedAtoms.end();
[e0e156]610}
611
[e472eab]612const std::vector<atom *> World::getSelectedAtoms() const {
613 std::vector<atom *> returnAtoms;
614 returnAtoms.resize(countSelectedAtoms());
615 int count = 0;
616 for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
617 returnAtoms[count++] = iter->second;
618 return returnAtoms;
619}
620
621
[90c4280]622// Molecules
623
624void World::clearMoleculeSelection(){
[69643a]625 OBSERVE;
626 NOTIFY(SelectionChanged);
[90c4280]627 selectedMolecules.clear();
628}
629
[ebc499]630void World::invertMoleculeSelection(){
631 // get all molecules not selected
632 typedef std::vector<molecule *> MoleculeVector_t;
633 MoleculeVector_t invertedSelection(getAllMolecules());
634 bool (World::*predicate)(const molecule*) const = &World::isSelected; // needed for type resolution of overloaded function
635 MoleculeVector_t::iterator iter =
636 std::remove_if(invertedSelection.begin(), invertedSelection.end(),
637 std::bind1st(std::mem_fun(predicate), this));
638 invertedSelection.erase(iter, invertedSelection.end());
639 // apply new selection
640 selectedMolecules.clear();
641 void (World::*selector)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
642 std::for_each(invertedSelection.begin(),invertedSelection.end(),
643 std::bind1st(std::mem_fun(selector),this)); // func is select... see above
644}
645
[e4afb4]646void World::selectMolecule(const molecule *_mol){
[69643a]647 OBSERVE;
648 NOTIFY(SelectionChanged);
[e4afb4]649 // molecule * is unchanged in this function, but we do store entity as changeable
650 ASSERT(_mol,"Invalid pointer to molecule in selection");
651 selectedMolecules[_mol->getId()]=const_cast<molecule *>(_mol);
[90c4280]652}
653
[e4afb4]654void World::selectMolecule(const moleculeId_t id){
[69643a]655 OBSERVE;
656 NOTIFY(SelectionChanged);
[90c4280]657 ASSERT(molecules.count(id),"Molecule Id selected that was not in the world");
658 selectedMolecules[id]=molecules[id];
659}
660
[e472eab]661void World::selectAllMolecules(MoleculeDescriptor descr){
[69643a]662 OBSERVE;
663 NOTIFY(SelectionChanged);
[90c4280]664 internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
665 internal_MoleculeIterator end = moleculeEnd_internal();
[e4afb4]666 void (World::*func)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
[90c4280]667 for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
668}
669
[e4afb4]670void World::selectMoleculeOfAtom(const atom *_atom){
[69643a]671 OBSERVE;
672 NOTIFY(SelectionChanged);
[e4afb4]673 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
674 molecule *mol=_atom->getMolecule();
[90c4280]675 // the atom might not be part of a molecule
676 if(mol){
677 selectMolecule(mol);
678 }
679}
680
[e4afb4]681void World::selectMoleculeOfAtom(const atomId_t id){
[69643a]682 OBSERVE;
683 NOTIFY(SelectionChanged);
[90c4280]684 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
685 selectMoleculeOfAtom(atoms[id]);
686}
687
[e4afb4]688void World::unselectMolecule(const molecule *_mol){
[69643a]689 OBSERVE;
690 NOTIFY(SelectionChanged);
[e4afb4]691 ASSERT(_mol,"invalid pointer in unselection of molecule");
692 unselectMolecule(_mol->getId());
[61d655e]693}
694
[e4afb4]695void World::unselectMolecule(const moleculeId_t id){
[69643a]696 OBSERVE;
697 NOTIFY(SelectionChanged);
[61d655e]698 ASSERT(molecules.count(id),"No such molecule with ID in unselection");
699 selectedMolecules.erase(id);
700}
701
[e472eab]702void World::unselectAllMolecules(MoleculeDescriptor descr){
[69643a]703 OBSERVE;
704 NOTIFY(SelectionChanged);
[61d655e]705 internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
706 internal_MoleculeIterator end = moleculeEnd_internal();
[e4afb4]707 void (World::*func)(const molecule*) = &World::unselectMolecule; // needed for type resolution of overloaded function
[61d655e]708 for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
709}
710
[e4afb4]711void World::unselectMoleculeOfAtom(const atom *_atom){
[69643a]712 OBSERVE;
713 NOTIFY(SelectionChanged);
[e4afb4]714 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
715 molecule *mol=_atom->getMolecule();
[61d655e]716 // the atom might not be part of a molecule
717 if(mol){
718 unselectMolecule(mol);
719 }
720}
721
[e4afb4]722void World::unselectMoleculeOfAtom(const atomId_t id){
[69643a]723 OBSERVE;
724 NOTIFY(SelectionChanged);
[61d655e]725 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
726 unselectMoleculeOfAtom(atoms[id]);
727}
728
[e472eab]729size_t World::countSelectedMolecules() const {
[eacc3b]730 size_t count = 0;
[e472eab]731 for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
[eacc3b]732 count++;
733 return count;
734}
735
[e4afb4]736bool World::isSelected(const molecule *_mol) const {
[89643d]737 return isMoleculeSelected(_mol->getId());
738}
739
740bool World::isMoleculeSelected(const moleculeId_t no) const {
741 return selectedMolecules.find(no) != selectedMolecules.end();
[e0e156]742}
743
[e472eab]744const std::vector<molecule *> World::getSelectedMolecules() const {
745 std::vector<molecule *> returnMolecules;
746 returnMolecules.resize(countSelectedMolecules());
747 int count = 0;
748 for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
749 returnMolecules[count++] = iter->second;
750 return returnMolecules;
751}
752
[3839e5]753/******************* Iterators over Selection *****************************/
754World::AtomSelectionIterator World::beginAtomSelection(){
755 return selectedAtoms.begin();
756}
757
758World::AtomSelectionIterator World::endAtomSelection(){
759 return selectedAtoms.end();
760}
761
[38f991]762World::AtomSelectionConstIterator World::beginAtomSelection() const{
763 return selectedAtoms.begin();
764}
765
766World::AtomSelectionConstIterator World::endAtomSelection() const{
767 return selectedAtoms.end();
768}
769
[3839e5]770
771World::MoleculeSelectionIterator World::beginMoleculeSelection(){
772 return selectedMolecules.begin();
773}
774
775World::MoleculeSelectionIterator World::endMoleculeSelection(){
776 return selectedMolecules.end();
777}
778
[38f991]779World::MoleculeSelectionConstIterator World::beginMoleculeSelection() const{
780 return selectedMolecules.begin();
781}
782
783World::MoleculeSelectionConstIterator World::endMoleculeSelection() const{
784 return selectedMolecules.end();
785}
786
[5d1611]787/******************************* Singleton Stuff **************************/
788
[7a1ce5]789World::World() :
[cd5047]790 Observable("World"),
[f71baf]791 BG(new BondGraph(true)), // assume Angstroem for the moment
[4ae823]792 periode(new periodentafel(true)),
[8e1f7af]793 configuration(new config),
[98dbee]794 homologies(new HomologyContainer()),
[43dad6]795 Thermostats(new ThermoStatContainer),
[e4b5de]796 ExitFlag(0),
[fa0b18]797 atoms(this),
[90c4280]798 selectedAtoms(this),
[3e4fb6]799 atomIdPool(0, 20, 100),
[51be2a]800 molecules(this),
[90c4280]801 selectedMolecules(this),
[3e4fb6]802 moleculeIdPool(0, 20,100),
[24a5e0]803 molecules_deprecated(new MoleculeListClass(this))
[7dad10]804{
[84c494]805 cell_size = new Box;
[cca9ef]806 RealSpaceMatrix domain;
[84c494]807 domain.at(0,0) = 20;
808 domain.at(1,1) = 20;
809 domain.at(2,2) = 20;
810 cell_size->setM(domain);
[4834f4]811 LCcontroller = new LinkedCell::LinkedCell_Controller(*cell_size);
[387b36]812 defaultName = "none";
[02ce36]813 Channels *OurChannel = new Channels;
[708277]814 NotificationChannels.insert( std::make_pair( static_cast<Observable *>(this), OurChannel) );
[7188b1]815 for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type)
[02ce36]816 OurChannel->addChannel(type);
[7dad10]817 molecules_deprecated->signOn(this);
818}
[5d1611]819
820World::~World()
[354859]821{
[028c2e]822 molecules_deprecated->signOff(this);
[4834f4]823 delete LCcontroller;
[84c494]824 delete cell_size;
[46d958]825 delete molecules_deprecated;
[cbc5fb]826 MoleculeSet::iterator molIter;
827 for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
828 DeleteMolecule((*molIter).second);
829 }
830 molecules.clear();
831 AtomSet::iterator atIter;
832 for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
833 DeleteAtom((*atIter).second);
[46d958]834 }
835 atoms.clear();
[7188b1]836
[f71baf]837 delete BG;
[6cb9c76]838 delete periode;
839 delete configuration;
840 delete Thermostats;
[354859]841}
[5d1611]842
[23b547]843// Explicit instantiation of the singleton mechanism at this point
[5d1611]844
[3e4fb6]845// moleculeId_t und atomId_t sind gleicher Basistyp, deswegen nur einen von beiden konstruieren
[b97a60]846CONSTRUCT_IDPOOL(atomId_t, uniqueId)
847CONSTRUCT_IDPOOL(moleculeId_t, continuousId)
[3e4fb6]848
[23b547]849CONSTRUCT_SINGLETON(World)
[5d1611]850
[5f1d5b8]851CONSTRUCT_OBSERVEDCONTAINER(World::AtomSTLSet)
852
853CONSTRUCT_OBSERVEDCONTAINER(World::MoleculeSTLSet)
854
[5d1611]855/******************************* deprecated Legacy Stuff ***********************/
856
[354859]857MoleculeListClass *&World::getMolecules() {
858 return molecules_deprecated;
[5d1611]859}
Note: See TracBrowser for help on using the repository browser.