source: src/World.cpp@ 0773bd

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 0773bd was feb5d0, checked in by Frederik Heber <heber@…>, 12 years ago

Added SelectiveConstIterator, allows for constant iteration over Descriptor-constraint ranges.

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