source: src/World.cpp@ c4a323

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 c4a323 was 98dbee, checked in by Frederik Heber <heber@…>, 12 years ago

World now maintains HomologyContainer instance.

  • Property mode set to 100644
File size: 24.2 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{
[03abd0]177 ASSERT( distance > 0,
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
[d297a3]191void World::setTime(const unsigned int _step)
192{
[76163d]193 if (_step != WorldTime::getTime()) {
194 // set new time
[040a5c]195 WorldTime::getInstance().setTime(_step);
[4b8630]196 // TODO: removed when BondGraph creates the adjacency
197 // 1. remove all of World's molecules
198 for (MoleculeIterator iter = getMoleculeIter();
199 getMoleculeIter() != moleculeEnd();
200 iter = getMoleculeIter()) {
201 getMolecules()->erase(*iter);
202 destroyMolecule(*iter);
203 }
204 // 2. (re-)create bondgraph
205 AtomComposite Set = getAllAtoms();
206 BG->CreateAdjacency(Set);
207
208 // 3. scan for connected subgraphs => molecules
209 DepthFirstSearchAnalysis DFS;
210 DFS();
211 DFS.UpdateMoleculeStructure();
[76163d]212 }
[d297a3]213}
214
[387b36]215std::string World::getDefaultName() {
[5f612ee]216 return defaultName;
217}
218
[387b36]219void World::setDefaultName(std::string name)
[5f612ee]220{
[be97a8]221 OBSERVE;
[387b36]222 defaultName = name;
[5f612ee]223};
224
[43dad6]225class ThermoStatContainer * World::getThermostats()
226{
227 return Thermostats;
228}
229
230
[e4b5de]231int World::getExitFlag() {
232 return ExitFlag;
233}
234
235void World::setExitFlag(int flag) {
236 if (ExitFlag < flag)
237 ExitFlag = flag;
238}
[5f612ee]239
[afb47f]240/******************** Methods to change World state *********************/
241
[354859]242molecule* World::createMolecule(){
243 OBSERVE;
244 molecule *mol = NULL;
[cbc5fb]245 mol = NewMolecule();
[3e4fb6]246 moleculeId_t id = moleculeIdPool.getNextId();
[127a8e]247 ASSERT(!molecules.count(id),"proposed id did not specify an unused ID");
248 mol->setId(id);
[244d26]249 // store the molecule by ID
[cbc5fb]250 molecules[mol->getId()] = mol;
[354859]251 mol->signOn(this);
[7188b1]252 _lastchangedmol = mol;
253 NOTIFY(MoleculeInserted);
[354859]254 return mol;
255}
256
[cbc5fb]257void World::destroyMolecule(molecule* mol){
258 OBSERVE;
[fa7989]259 ASSERT(mol,"Molecule that was meant to be destroyed did not exist");
[cbc5fb]260 destroyMolecule(mol->getId());
261}
262
263void World::destroyMolecule(moleculeId_t id){
264 molecule *mol = molecules[id];
[6d574a]265 ASSERT(mol,"Molecule id that was meant to be destroyed did not exist");
[38f991]266 // give notice about immediate removal
267 {
268 OBSERVE;
269 _lastchangedmol = mol;
270 NOTIFY(MoleculeRemoved);
271 }
[7d82a5]272 mol->signOff(this);
[cbc5fb]273 DeleteMolecule(mol);
[38f991]274 if (isMoleculeSelected(id))
275 selectedMolecules.erase(id);
[cbc5fb]276 molecules.erase(id);
[3e4fb6]277 moleculeIdPool.releaseId(id);
[cbc5fb]278}
279
[46d958]280atom *World::createAtom(){
281 OBSERVE;
[3e4fb6]282 atomId_t id = atomIdPool.getNextId();
[127a8e]283 ASSERT(!atoms.count(id),"proposed id did not specify an unused ID");
[88d586]284 atom *res = NewAtom(id);
[46d958]285 res->setWorld(this);
[244d26]286 // store the atom by ID
[46d958]287 atoms[res->getId()] = res;
[7188b1]288 _lastchangedatom = res;
289 NOTIFY(AtomInserted);
[46d958]290 return res;
291}
292
[5f612ee]293
[46d958]294int World::registerAtom(atom *atom){
295 OBSERVE;
[3e4fb6]296 atomId_t id = atomIdPool.getNextId();
[88d586]297 atom->setId(id);
[46d958]298 atom->setWorld(this);
299 atoms[atom->getId()] = atom;
[65d7ca]300 _lastchangedatom = atom;
301 NOTIFY(AtomInserted);
[46d958]302 return atom->getId();
303}
304
305void World::destroyAtom(atom* atom){
306 int id = atom->getId();
307 destroyAtom(id);
308}
309
[cbc5fb]310void World::destroyAtom(atomId_t id) {
[46d958]311 atom *atom = atoms[id];
[6d574a]312 ASSERT(atom,"Atom ID that was meant to be destroyed did not exist");
[ab4a33]313 // give notice about immediate removal
314 {
315 OBSERVE;
316 _lastchangedatom = atom;
317 NOTIFY(AtomRemoved);
318 }
[46d958]319 DeleteAtom(atom);
[38f991]320 if (isAtomSelected(id))
321 selectedAtoms.erase(id);
[46d958]322 atoms.erase(id);
[3e4fb6]323 atomIdPool.releaseId(id);
[88d586]324}
325
326bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
327 OBSERVE;
328 // in case this call did not originate from inside the atom, we redirect it,
329 // to also let it know that it has changed
330 if(!target){
331 target = atoms[oldId];
[6d574a]332 ASSERT(target,"Atom with that ID not found");
[88d586]333 return target->changeId(newId);
334 }
335 else{
[3e4fb6]336 if(atomIdPool.reserveId(newId)){
[88d586]337 atoms.erase(oldId);
338 atoms.insert(pair<atomId_t,atom*>(newId,target));
339 return true;
340 }
341 else{
342 return false;
343 }
344 }
[46d958]345}
346
[a7a087]347bool World::changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target){
348 OBSERVE;
349 // in case this call did not originate from inside the atom, we redirect it,
350 // to also let it know that it has changed
351 if(!target){
352 target = molecules[oldId];
353 ASSERT(target,"Molecule with that ID not found");
354 return target->changeId(newId);
355 }
356 else{
[3e4fb6]357 if(moleculeIdPool.reserveId(newId)){
[a7a087]358 molecules.erase(oldId);
359 molecules.insert(pair<moleculeId_t,molecule*>(newId,target));
360 return true;
361 }
362 else{
363 return false;
364 }
365 }
366}
367
[7c4e29]368ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
[3139b2]369 ActionTrait manipulateTrait(name);
[e4afb4]370 return new ManipulateAtomsProcess(op, descr,manipulateTrait,false);
[7c4e29]371}
372
[0e2a47]373ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
374 return manipulateAtoms(op,name,AllAtoms());
375}
376
[afb47f]377/********************* Internal Change methods for double Callback and Observer mechanism ********/
378
379void World::doManipulate(ManipulateAtomsProcess *proc){
380 proc->signOn(this);
381 {
382 OBSERVE;
383 proc->doManipulate(this);
384 }
385 proc->signOff(this);
386}
[865a945]387/******************************* Iterators ********************************/
388
[fa0b18]389// external parts with observers
390
[feb5d0]391CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor)
392
393CONSTRUCT_SELECTIVE_CONST_ITERATOR(atom*,World::AtomSet,AtomDescriptor)
[6e97e5]394
[fa0b18]395World::AtomIterator
396World::getAtomIter(AtomDescriptor descr){
397 return AtomIterator(descr,atoms);
398}
[865a945]399
[feb5d0]400World::AtomConstIterator
401World::getAtomIter(AtomDescriptor descr) const{
402 return AtomConstIterator(descr,atoms);
403}
404
[fa0b18]405World::AtomIterator
406World::getAtomIter(){
407 return AtomIterator(AllAtoms(),atoms);
[865a945]408}
[354859]409
[feb5d0]410World::AtomConstIterator
411World::getAtomIter() const{
412 return AtomConstIterator(AllAtoms(),atoms);
413}
414
[fa0b18]415World::AtomIterator
416World::atomEnd(){
[6e97e5]417 return AtomIterator(AllAtoms(),atoms,atoms.end());
[7c4e29]418}
419
[feb5d0]420World::AtomConstIterator
421World::atomEnd() const{
422 return AtomConstIterator(AllAtoms(),atoms,atoms.end());
423}
424
425CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor)
426
427CONSTRUCT_SELECTIVE_CONST_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor)
[6e97e5]428
[5d880e]429World::MoleculeIterator
430World::getMoleculeIter(MoleculeDescriptor descr){
431 return MoleculeIterator(descr,molecules);
432}
433
[feb5d0]434World::MoleculeConstIterator
435World::getMoleculeIter(MoleculeDescriptor descr) const{
436 return MoleculeConstIterator(descr,molecules);
437}
438
[5d880e]439World::MoleculeIterator
440World::getMoleculeIter(){
441 return MoleculeIterator(AllMolecules(),molecules);
[1c51c8]442}
443
[feb5d0]444World::MoleculeConstIterator
445World::getMoleculeIter() const{
446 return MoleculeConstIterator(AllMolecules(),molecules);
447}
448
[5d880e]449World::MoleculeIterator
450World::moleculeEnd(){
[6e97e5]451 return MoleculeIterator(AllMolecules(),molecules,molecules.end());
[1c51c8]452}
453
[feb5d0]454World::MoleculeConstIterator
455World::moleculeEnd() const{
456 return MoleculeConstIterator(AllMolecules(),molecules,molecules.end());
457}
458
[fa0b18]459// Internal parts, without observers
460
461// Build the AtomIterator from template
462CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet::set_t,AtomDescriptor);
463
464
465World::internal_AtomIterator
466World::getAtomIter_internal(AtomDescriptor descr){
467 return internal_AtomIterator(descr,atoms.getContent());
468}
469
470World::internal_AtomIterator
471World::atomEnd_internal(){
472 return internal_AtomIterator(AllAtoms(),atoms.getContent(),atoms.end_internal());
473}
474
[6e97e5]475// build the MoleculeIterator from template
[e3d865]476CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet::set_t,MoleculeDescriptor);
[6e97e5]477
[e3d865]478World::internal_MoleculeIterator World::getMoleculeIter_internal(MoleculeDescriptor descr){
479 return internal_MoleculeIterator(descr,molecules.getContent());
[1c51c8]480}
481
[e3d865]482World::internal_MoleculeIterator World::moleculeEnd_internal(){
483 return internal_MoleculeIterator(AllMolecules(),molecules.getContent(),molecules.end_internal());
[1c51c8]484}
485
[90c4280]486/************************** Selection of Atoms and molecules ******************/
487
488// Atoms
489
490void World::clearAtomSelection(){
[69643a]491 OBSERVE;
492 NOTIFY(SelectionChanged);
[90c4280]493 selectedAtoms.clear();
494}
495
[ebc499]496void World::invertAtomSelection(){
497 // get all atoms not selected
498 AtomComposite invertedSelection(getAllAtoms());
499 bool (World::*predicate)(const atom*) const = &World::isSelected; // needed for type resolution of overloaded function
500 AtomComposite::iterator iter =
501 std::remove_if(invertedSelection.begin(), invertedSelection.end(),
502 std::bind1st(std::mem_fun(predicate), this));
503 invertedSelection.erase(iter, invertedSelection.end());
504 // apply new selection
505 selectedAtoms.clear();
506 void (World::*selector)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
507 std::for_each(invertedSelection.begin(),invertedSelection.end(),
508 std::bind1st(std::mem_fun(selector),this)); // func is select... see above
509}
510
[e4afb4]511void World::selectAtom(const atom *_atom){
[69643a]512 OBSERVE;
513 NOTIFY(SelectionChanged);
[e4afb4]514 // atom * is unchanged in this function, but we do store entity as changeable
515 ASSERT(_atom,"Invalid pointer in selection of atom");
516 selectedAtoms[_atom->getId()]=const_cast<atom *>(_atom);
[90c4280]517}
518
[e4afb4]519void World::selectAtom(const atomId_t id){
[69643a]520 OBSERVE;
521 NOTIFY(SelectionChanged);
[90c4280]522 ASSERT(atoms.count(id),"Atom Id selected that was not in the world");
523 selectedAtoms[id]=atoms[id];
524}
525
526void World::selectAllAtoms(AtomDescriptor descr){
[69643a]527 OBSERVE;
528 NOTIFY(SelectionChanged);
[90c4280]529 internal_AtomIterator begin = getAtomIter_internal(descr);
530 internal_AtomIterator end = atomEnd_internal();
[e4afb4]531 void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
[90c4280]532 for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
533}
534
[e4afb4]535void World::selectAtomsOfMolecule(const molecule *_mol){
[69643a]536 OBSERVE;
537 NOTIFY(SelectionChanged);
[90c4280]538 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
539 // need to make it const to get the fast iterators
540 const molecule *mol = _mol;
[e4afb4]541 void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
[90c4280]542 for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is select... see above
543}
544
[e4afb4]545void World::selectAtomsOfMolecule(const moleculeId_t id){
[69643a]546 OBSERVE;
547 NOTIFY(SelectionChanged);
[90c4280]548 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
549 selectAtomsOfMolecule(molecules[id]);
550}
551
[e4afb4]552void World::unselectAtom(const atom *_atom){
[69643a]553 OBSERVE;
554 NOTIFY(SelectionChanged);
[e4afb4]555 ASSERT(_atom,"Invalid pointer in unselection of atom");
556 unselectAtom(_atom->getId());
[61d655e]557}
558
[e4afb4]559void World::unselectAtom(const atomId_t id){
[69643a]560 OBSERVE;
561 NOTIFY(SelectionChanged);
[61d655e]562 ASSERT(atoms.count(id),"Atom Id unselected that was not in the world");
563 selectedAtoms.erase(id);
564}
565
566void World::unselectAllAtoms(AtomDescriptor descr){
[69643a]567 OBSERVE;
568 NOTIFY(SelectionChanged);
[61d655e]569 internal_AtomIterator begin = getAtomIter_internal(descr);
570 internal_AtomIterator end = atomEnd_internal();
[e4afb4]571 void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
[61d655e]572 for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
573}
574
[e4afb4]575void World::unselectAtomsOfMolecule(const molecule *_mol){
[69643a]576 OBSERVE;
577 NOTIFY(SelectionChanged);
[61d655e]578 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
579 // need to make it const to get the fast iterators
580 const molecule *mol = _mol;
[e4afb4]581 void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
[992bd5]582 for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is unselect... see above
[61d655e]583}
584
[e4afb4]585void World::unselectAtomsOfMolecule(const moleculeId_t id){
[69643a]586 OBSERVE;
587 NOTIFY(SelectionChanged);
[61d655e]588 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
589 unselectAtomsOfMolecule(molecules[id]);
590}
591
[e472eab]592size_t World::countSelectedAtoms() const {
[eacc3b]593 size_t count = 0;
[e472eab]594 for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
[eacc3b]595 count++;
596 return count;
597}
598
[e4afb4]599bool World::isSelected(const atom *_atom) const {
[89643d]600 return isAtomSelected(_atom->getId());
601}
602
603bool World::isAtomSelected(const atomId_t no) const {
604 return selectedAtoms.find(no) != selectedAtoms.end();
[e0e156]605}
606
[e472eab]607const std::vector<atom *> World::getSelectedAtoms() const {
608 std::vector<atom *> returnAtoms;
609 returnAtoms.resize(countSelectedAtoms());
610 int count = 0;
611 for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
612 returnAtoms[count++] = iter->second;
613 return returnAtoms;
614}
615
616
[90c4280]617// Molecules
618
619void World::clearMoleculeSelection(){
[69643a]620 OBSERVE;
621 NOTIFY(SelectionChanged);
[90c4280]622 selectedMolecules.clear();
623}
624
[ebc499]625void World::invertMoleculeSelection(){
626 // get all molecules not selected
627 typedef std::vector<molecule *> MoleculeVector_t;
628 MoleculeVector_t invertedSelection(getAllMolecules());
629 bool (World::*predicate)(const molecule*) const = &World::isSelected; // needed for type resolution of overloaded function
630 MoleculeVector_t::iterator iter =
631 std::remove_if(invertedSelection.begin(), invertedSelection.end(),
632 std::bind1st(std::mem_fun(predicate), this));
633 invertedSelection.erase(iter, invertedSelection.end());
634 // apply new selection
635 selectedMolecules.clear();
636 void (World::*selector)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
637 std::for_each(invertedSelection.begin(),invertedSelection.end(),
638 std::bind1st(std::mem_fun(selector),this)); // func is select... see above
639}
640
[e4afb4]641void World::selectMolecule(const molecule *_mol){
[69643a]642 OBSERVE;
643 NOTIFY(SelectionChanged);
[e4afb4]644 // molecule * is unchanged in this function, but we do store entity as changeable
645 ASSERT(_mol,"Invalid pointer to molecule in selection");
646 selectedMolecules[_mol->getId()]=const_cast<molecule *>(_mol);
[90c4280]647}
648
[e4afb4]649void World::selectMolecule(const moleculeId_t id){
[69643a]650 OBSERVE;
651 NOTIFY(SelectionChanged);
[90c4280]652 ASSERT(molecules.count(id),"Molecule Id selected that was not in the world");
653 selectedMolecules[id]=molecules[id];
654}
655
[e472eab]656void World::selectAllMolecules(MoleculeDescriptor descr){
[69643a]657 OBSERVE;
658 NOTIFY(SelectionChanged);
[90c4280]659 internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
660 internal_MoleculeIterator end = moleculeEnd_internal();
[e4afb4]661 void (World::*func)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
[90c4280]662 for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
663}
664
[e4afb4]665void World::selectMoleculeOfAtom(const atom *_atom){
[69643a]666 OBSERVE;
667 NOTIFY(SelectionChanged);
[e4afb4]668 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
669 molecule *mol=_atom->getMolecule();
[90c4280]670 // the atom might not be part of a molecule
671 if(mol){
672 selectMolecule(mol);
673 }
674}
675
[e4afb4]676void World::selectMoleculeOfAtom(const atomId_t id){
[69643a]677 OBSERVE;
678 NOTIFY(SelectionChanged);
[90c4280]679 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
680 selectMoleculeOfAtom(atoms[id]);
681}
682
[e4afb4]683void World::unselectMolecule(const molecule *_mol){
[69643a]684 OBSERVE;
685 NOTIFY(SelectionChanged);
[e4afb4]686 ASSERT(_mol,"invalid pointer in unselection of molecule");
687 unselectMolecule(_mol->getId());
[61d655e]688}
689
[e4afb4]690void World::unselectMolecule(const moleculeId_t id){
[69643a]691 OBSERVE;
692 NOTIFY(SelectionChanged);
[61d655e]693 ASSERT(molecules.count(id),"No such molecule with ID in unselection");
694 selectedMolecules.erase(id);
695}
696
[e472eab]697void World::unselectAllMolecules(MoleculeDescriptor descr){
[69643a]698 OBSERVE;
699 NOTIFY(SelectionChanged);
[61d655e]700 internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
701 internal_MoleculeIterator end = moleculeEnd_internal();
[e4afb4]702 void (World::*func)(const molecule*) = &World::unselectMolecule; // needed for type resolution of overloaded function
[61d655e]703 for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
704}
705
[e4afb4]706void World::unselectMoleculeOfAtom(const atom *_atom){
[69643a]707 OBSERVE;
708 NOTIFY(SelectionChanged);
[e4afb4]709 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
710 molecule *mol=_atom->getMolecule();
[61d655e]711 // the atom might not be part of a molecule
712 if(mol){
713 unselectMolecule(mol);
714 }
715}
716
[e4afb4]717void World::unselectMoleculeOfAtom(const atomId_t id){
[69643a]718 OBSERVE;
719 NOTIFY(SelectionChanged);
[61d655e]720 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
721 unselectMoleculeOfAtom(atoms[id]);
722}
723
[e472eab]724size_t World::countSelectedMolecules() const {
[eacc3b]725 size_t count = 0;
[e472eab]726 for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
[eacc3b]727 count++;
728 return count;
729}
730
[e4afb4]731bool World::isSelected(const molecule *_mol) const {
[89643d]732 return isMoleculeSelected(_mol->getId());
733}
734
735bool World::isMoleculeSelected(const moleculeId_t no) const {
736 return selectedMolecules.find(no) != selectedMolecules.end();
[e0e156]737}
738
[e472eab]739const std::vector<molecule *> World::getSelectedMolecules() const {
740 std::vector<molecule *> returnMolecules;
741 returnMolecules.resize(countSelectedMolecules());
742 int count = 0;
743 for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
744 returnMolecules[count++] = iter->second;
745 return returnMolecules;
746}
747
[3839e5]748/******************* Iterators over Selection *****************************/
749World::AtomSelectionIterator World::beginAtomSelection(){
750 return selectedAtoms.begin();
751}
752
753World::AtomSelectionIterator World::endAtomSelection(){
754 return selectedAtoms.end();
755}
756
[38f991]757World::AtomSelectionConstIterator World::beginAtomSelection() const{
758 return selectedAtoms.begin();
759}
760
761World::AtomSelectionConstIterator World::endAtomSelection() const{
762 return selectedAtoms.end();
763}
764
[3839e5]765
766World::MoleculeSelectionIterator World::beginMoleculeSelection(){
767 return selectedMolecules.begin();
768}
769
770World::MoleculeSelectionIterator World::endMoleculeSelection(){
771 return selectedMolecules.end();
772}
773
[38f991]774World::MoleculeSelectionConstIterator World::beginMoleculeSelection() const{
775 return selectedMolecules.begin();
776}
777
778World::MoleculeSelectionConstIterator World::endMoleculeSelection() const{
779 return selectedMolecules.end();
780}
781
[5d1611]782/******************************* Singleton Stuff **************************/
783
[7a1ce5]784World::World() :
[cd5047]785 Observable("World"),
[f71baf]786 BG(new BondGraph(true)), // assume Angstroem for the moment
[4ae823]787 periode(new periodentafel(true)),
[8e1f7af]788 configuration(new config),
[98dbee]789 homologies(new HomologyContainer()),
[43dad6]790 Thermostats(new ThermoStatContainer),
[e4b5de]791 ExitFlag(0),
[fa0b18]792 atoms(this),
[90c4280]793 selectedAtoms(this),
[3e4fb6]794 atomIdPool(0, 20, 100),
[51be2a]795 molecules(this),
[90c4280]796 selectedMolecules(this),
[3e4fb6]797 moleculeIdPool(0, 20,100),
[24a5e0]798 molecules_deprecated(new MoleculeListClass(this))
[7dad10]799{
[84c494]800 cell_size = new Box;
[cca9ef]801 RealSpaceMatrix domain;
[84c494]802 domain.at(0,0) = 20;
803 domain.at(1,1) = 20;
804 domain.at(2,2) = 20;
805 cell_size->setM(domain);
[4834f4]806 LCcontroller = new LinkedCell::LinkedCell_Controller(*cell_size);
[387b36]807 defaultName = "none";
[02ce36]808 Channels *OurChannel = new Channels;
[708277]809 NotificationChannels.insert( std::make_pair( static_cast<Observable *>(this), OurChannel) );
[7188b1]810 for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type)
[02ce36]811 OurChannel->addChannel(type);
[7dad10]812 molecules_deprecated->signOn(this);
813}
[5d1611]814
815World::~World()
[354859]816{
[028c2e]817 molecules_deprecated->signOff(this);
[4834f4]818 delete LCcontroller;
[84c494]819 delete cell_size;
[46d958]820 delete molecules_deprecated;
[cbc5fb]821 MoleculeSet::iterator molIter;
822 for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
823 DeleteMolecule((*molIter).second);
824 }
825 molecules.clear();
826 AtomSet::iterator atIter;
827 for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
828 DeleteAtom((*atIter).second);
[46d958]829 }
830 atoms.clear();
[7188b1]831
[f71baf]832 delete BG;
[6cb9c76]833 delete periode;
834 delete configuration;
835 delete Thermostats;
[354859]836}
[5d1611]837
[23b547]838// Explicit instantiation of the singleton mechanism at this point
[5d1611]839
[3e4fb6]840// moleculeId_t und atomId_t sind gleicher Basistyp, deswegen nur einen von beiden konstruieren
[b97a60]841CONSTRUCT_IDPOOL(atomId_t, uniqueId)
842CONSTRUCT_IDPOOL(moleculeId_t, continuousId)
[3e4fb6]843
[23b547]844CONSTRUCT_SINGLETON(World)
[5d1611]845
[5f1d5b8]846CONSTRUCT_OBSERVEDCONTAINER(World::AtomSTLSet)
847
848CONSTRUCT_OBSERVEDCONTAINER(World::MoleculeSTLSet)
849
[5d1611]850/******************************* deprecated Legacy Stuff ***********************/
851
[354859]852MoleculeListClass *&World::getMolecules() {
853 return molecules_deprecated;
[5d1611]854}
Note: See TracBrowser for help on using the repository browser.