source: src/World.cpp@ 456e78

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 456e78 was e4fe8d, checked in by Frederik Heber <heber@…>, 14 years ago

Moved defs.?pp to subdir (and library) Helpers.

  • hence, include had to be changed to Helpers/defs.hpp
  • and Makefile.am and Helpers/Makefile.am adapted
  • also in LinearAlgebra where MYEPSILON appears we have added the above include
  • Property mode set to 100644
File size: 22.4 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
[5d1611]8/*
9 * World.cpp
10 *
11 * Created on: Feb 3, 2010
12 * Author: crueger
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[112b09]20#include "Helpers/MemDebug.hpp"
21
[5d1611]22#include "World.hpp"
23
[90c4280]24#include <functional>
[5d1611]25
[d346b6]26#include "atom.hpp"
[8e1f7af]27#include "config.hpp"
[354859]28#include "molecule.hpp"
29#include "periodentafel.hpp"
[43dad6]30#include "ThermoStatContainer.hpp"
[fc1b24]31#include "Descriptors/AtomDescriptor.hpp"
[865a945]32#include "Descriptors/AtomDescriptor_impl.hpp"
[1c51c8]33#include "Descriptors/MoleculeDescriptor.hpp"
34#include "Descriptors/MoleculeDescriptor_impl.hpp"
[6e97e5]35#include "Descriptors/SelectiveIterator_impl.hpp"
[e4afb4]36#include "Actions/ActionTraits.hpp"
[7c4e29]37#include "Actions/ManipulateAtomsProcess.hpp"
[6d574a]38#include "Helpers/Assert.hpp"
[84c494]39#include "Box.hpp"
[cca9ef]40#include "LinearAlgebra/RealSpaceMatrix.hpp"
[e4fe8d]41#include "Helpers/defs.hpp"
[d346b6]42
[23b547]43#include "Patterns/Singleton_impl.hpp"
[90c4280]44#include "Patterns/ObservedContainer_impl.hpp"
[23b547]45
[d346b6]46using namespace std;
[4d9c01]47
[11e206]48const unsigned int MAX_POOL_FRAGMENTATION=20;
49const unsigned int MAX_FRAGMENTATION_SKIPS=100;
50
[5d1611]51/******************************* getter and setter ************************/
[354859]52periodentafel *&World::getPeriode(){
[5d1611]53 return periode;
54}
55
[8e1f7af]56config *&World::getConfig(){
57 return configuration;
58}
59
[1c51c8]60// Atoms
61
[7a1ce5]62atom* World::getAtom(AtomDescriptor descriptor){
[fc1b24]63 return descriptor.find();
64}
65
[4d72e4]66World::AtomComposite World::getAllAtoms(AtomDescriptor descriptor){
[fc1b24]67 return descriptor.findAll();
68}
69
[4d72e4]70World::AtomComposite World::getAllAtoms(){
[0e2a47]71 return getAllAtoms(AllAtoms());
72}
73
[354859]74int World::numAtoms(){
75 return atoms.size();
76}
77
[1c51c8]78// Molecules
79
80molecule *World::getMolecule(MoleculeDescriptor descriptor){
81 return descriptor.find();
82}
83
84std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
85 return descriptor.findAll();
86}
87
[97ebf8]88std::vector<molecule*> World::getAllMolecules(){
89 return getAllMolecules(AllMolecules());
90}
91
[354859]92int World::numMolecules(){
93 return molecules_deprecated->ListOfMolecules.size();
94}
95
[5f612ee]96// system
97
[84c494]98Box& World::getDomain() {
99 return *cell_size;
100}
101
[cca9ef]102void World::setDomain(const RealSpaceMatrix &mat){
[be97a8]103 OBSERVE;
[84c494]104 *cell_size = mat;
[5f612ee]105}
106
107void World::setDomain(double * matrix)
108{
[b9c847]109 OBSERVE;
[cca9ef]110 RealSpaceMatrix M = ReturnFullMatrixforSymmetric(matrix);
[84c494]111 cell_size->setM(M);
[5f612ee]112}
113
[387b36]114std::string World::getDefaultName() {
[5f612ee]115 return defaultName;
116}
117
[387b36]118void World::setDefaultName(std::string name)
[5f612ee]119{
[be97a8]120 OBSERVE;
[387b36]121 defaultName = name;
[5f612ee]122};
123
[43dad6]124class ThermoStatContainer * World::getThermostats()
125{
126 return Thermostats;
127}
128
129
[e4b5de]130int World::getExitFlag() {
131 return ExitFlag;
132}
133
134void World::setExitFlag(int flag) {
135 if (ExitFlag < flag)
136 ExitFlag = flag;
137}
[5f612ee]138
[afb47f]139/******************** Methods to change World state *********************/
140
[354859]141molecule* World::createMolecule(){
142 OBSERVE;
143 molecule *mol = NULL;
[cbc5fb]144 mol = NewMolecule();
[127a8e]145 moleculeId_t id = getNextMoleculeId();
146 ASSERT(!molecules.count(id),"proposed id did not specify an unused ID");
147 mol->setId(id);
[244d26]148 // store the molecule by ID
[cbc5fb]149 molecules[mol->getId()] = mol;
[354859]150 mol->signOn(this);
151 return mol;
152}
153
[cbc5fb]154void World::destroyMolecule(molecule* mol){
155 OBSERVE;
[fa7989]156 ASSERT(mol,"Molecule that was meant to be destroyed did not exist");
[cbc5fb]157 destroyMolecule(mol->getId());
158}
159
160void World::destroyMolecule(moleculeId_t id){
161 OBSERVE;
162 molecule *mol = molecules[id];
[6d574a]163 ASSERT(mol,"Molecule id that was meant to be destroyed did not exist");
[cbc5fb]164 DeleteMolecule(mol);
165 molecules.erase(id);
[127a8e]166 releaseMoleculeId(id);
[cbc5fb]167}
168
[46d958]169atom *World::createAtom(){
170 OBSERVE;
[88d586]171 atomId_t id = getNextAtomId();
[127a8e]172 ASSERT(!atoms.count(id),"proposed id did not specify an unused ID");
[88d586]173 atom *res = NewAtom(id);
[46d958]174 res->setWorld(this);
[244d26]175 // store the atom by ID
[46d958]176 atoms[res->getId()] = res;
177 return res;
178}
179
[5f612ee]180
[46d958]181int World::registerAtom(atom *atom){
182 OBSERVE;
[88d586]183 atomId_t id = getNextAtomId();
184 atom->setId(id);
[46d958]185 atom->setWorld(this);
186 atoms[atom->getId()] = atom;
187 return atom->getId();
188}
189
190void World::destroyAtom(atom* atom){
191 OBSERVE;
192 int id = atom->getId();
193 destroyAtom(id);
194}
195
[cbc5fb]196void World::destroyAtom(atomId_t id) {
[46d958]197 OBSERVE;
198 atom *atom = atoms[id];
[6d574a]199 ASSERT(atom,"Atom ID that was meant to be destroyed did not exist");
[46d958]200 DeleteAtom(atom);
201 atoms.erase(id);
[88d586]202 releaseAtomId(id);
203}
204
205bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
206 OBSERVE;
207 // in case this call did not originate from inside the atom, we redirect it,
208 // to also let it know that it has changed
209 if(!target){
210 target = atoms[oldId];
[6d574a]211 ASSERT(target,"Atom with that ID not found");
[88d586]212 return target->changeId(newId);
213 }
214 else{
215 if(reserveAtomId(newId)){
216 atoms.erase(oldId);
217 atoms.insert(pair<atomId_t,atom*>(newId,target));
218 return true;
219 }
220 else{
221 return false;
222 }
223 }
[46d958]224}
225
[a7a087]226bool World::changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target){
227 OBSERVE;
228 // in case this call did not originate from inside the atom, we redirect it,
229 // to also let it know that it has changed
230 if(!target){
231 target = molecules[oldId];
232 ASSERT(target,"Molecule with that ID not found");
233 return target->changeId(newId);
234 }
235 else{
236 if(reserveMoleculeId(newId)){
237 molecules.erase(oldId);
238 molecules.insert(pair<moleculeId_t,molecule*>(newId,target));
239 return true;
240 }
241 else{
242 return false;
243 }
244 }
245}
246
[7c4e29]247ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
[e4afb4]248 ActionTraits manipulateTrait(name);
249 return new ManipulateAtomsProcess(op, descr,manipulateTrait,false);
[7c4e29]250}
251
[0e2a47]252ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
253 return manipulateAtoms(op,name,AllAtoms());
254}
255
[afb47f]256/********************* Internal Change methods for double Callback and Observer mechanism ********/
257
258void World::doManipulate(ManipulateAtomsProcess *proc){
259 proc->signOn(this);
260 {
261 OBSERVE;
262 proc->doManipulate(this);
263 }
264 proc->signOff(this);
265}
[88d586]266/******************************* IDManagement *****************************/
267
[57adc7]268// Atoms
269
[88d586]270atomId_t World::getNextAtomId(){
[127a8e]271 // try to find an Id in the pool;
272 if(!atomIdPool.empty()){
273 atomIdPool_t::iterator iter=atomIdPool.begin();
274 atomId_t id = iter->first;
[dc11c9]275 range<atomId_t> newRange = makeRange(id+1,iter->last);
[127a8e]276 // we wont use this iterator anymore, so we don't care about invalidating
277 atomIdPool.erase(iter);
[dc11c9]278 if(newRange.first<newRange.last){
[127a8e]279 atomIdPool.insert(newRange);
280 }
[23b547]281 return id;
[88d586]282 }
[127a8e]283 // Nothing in the pool... we are out of luck
284 return currAtomId++;
[88d586]285}
286
287void World::releaseAtomId(atomId_t id){
[dc11c9]288 atomIdPool.insert(makeRange(id,id+1));
[127a8e]289 defragAtomIdPool();
[88d586]290}
[afb47f]291
[88d586]292bool World::reserveAtomId(atomId_t id){
293 if(id>=currAtomId ){
[dc11c9]294 range<atomId_t> newRange = makeRange(currAtomId,id);
295 if(newRange.first<newRange.last){
[127a8e]296 atomIdPool.insert(newRange);
[88d586]297 }
298 currAtomId=id+1;
[127a8e]299 defragAtomIdPool();
[88d586]300 return true;
301 }
[127a8e]302 // look for a range that matches the request
303 for(atomIdPool_t::iterator iter=atomIdPool.begin();iter!=atomIdPool.end();++iter){
[dc11c9]304 if(iter->isBefore(id)){
305 // we have covered all available ranges... nothing to be found here
[127a8e]306 break;
307 }
308 // no need to check first, since it has to be <=id, since otherwise we would have broken out
[dc11c9]309 if(!iter->isBeyond(id)){
[127a8e]310 // we found a matching range... get the id from this range
311
312 // split up this range at the point of id
[dc11c9]313 range<atomId_t> bottomRange = makeRange(iter->first,id);
314 range<atomId_t> topRange = makeRange(id+1,iter->last);
[127a8e]315 // remove this range
316 atomIdPool.erase(iter);
[dc11c9]317 if(bottomRange.first<bottomRange.last){
[127a8e]318 atomIdPool.insert(bottomRange);
319 }
[dc11c9]320 if(topRange.first<topRange.last){
[127a8e]321 atomIdPool.insert(topRange);
322 }
323 defragAtomIdPool();
324 return true;
325 }
[88d586]326 }
[127a8e]327 // this ID could not be reserved
328 return false;
329}
330
331void World::defragAtomIdPool(){
332 // check if the situation is bad enough to make defragging neccessary
333 if((numAtomDefragSkips<MAX_FRAGMENTATION_SKIPS) &&
334 (atomIdPool.size()<lastAtomPoolSize+MAX_POOL_FRAGMENTATION)){
335 ++numAtomDefragSkips;
336 return;
337 }
338 for(atomIdPool_t::iterator iter = atomIdPool.begin();iter!=atomIdPool.end();){
339 // see if this range is adjacent to the next one
340 atomIdPool_t::iterator next = iter;
341 next++;
[dc11c9]342 if(next!=atomIdPool.end() && (next->first==iter->last)){
[127a8e]343 // merge the two ranges
[dc11c9]344 range<atomId_t> newRange = makeRange(iter->first,next->last);
[127a8e]345 atomIdPool.erase(iter);
346 atomIdPool.erase(next);
347 pair<atomIdPool_t::iterator,bool> res = atomIdPool.insert(newRange);
348 ASSERT(res.second,"Id-Pool was confused");
349 iter=res.first;
350 continue;
351 }
352 ++iter;
353 }
354 if(!atomIdPool.empty()){
355 // check if the last range is at the border
356 atomIdPool_t::iterator iter = atomIdPool.end();
357 iter--;
[dc11c9]358 if(iter->last==currAtomId){
[127a8e]359 currAtomId=iter->first;
360 atomIdPool.erase(iter);
361 }
[88d586]362 }
[127a8e]363 lastAtomPoolSize=atomIdPool.size();
364 numAtomDefragSkips=0;
[88d586]365}
[57adc7]366
367// Molecules
368
[127a8e]369moleculeId_t World::getNextMoleculeId(){
370 // try to find an Id in the pool;
371 if(!moleculeIdPool.empty()){
372 moleculeIdPool_t::iterator iter=moleculeIdPool.begin();
373 moleculeId_t id = iter->first;
[dc11c9]374 range<moleculeId_t> newRange = makeRange(id+1,iter->last);
[127a8e]375 // we wont use this iterator anymore, so we don't care about invalidating
376 moleculeIdPool.erase(iter);
[dc11c9]377 if(newRange.first<newRange.last){
[127a8e]378 moleculeIdPool.insert(newRange);
379 }
380 return id;
381 }
382 // Nothing in the pool... we are out of luck
383 return currMoleculeId++;
384}
385
386void World::releaseMoleculeId(moleculeId_t id){
[dc11c9]387 moleculeIdPool.insert(makeRange(id,id+1));
[127a8e]388 defragMoleculeIdPool();
389}
390
391bool World::reserveMoleculeId(moleculeId_t id){
392 if(id>=currMoleculeId ){
[dc11c9]393 range<moleculeId_t> newRange = makeRange(currMoleculeId,id);
394 if(newRange.first<newRange.last){
[127a8e]395 moleculeIdPool.insert(newRange);
396 }
397 currMoleculeId=id+1;
398 defragMoleculeIdPool();
399 return true;
400 }
401 // look for a range that matches the request
402 for(moleculeIdPool_t::iterator iter=moleculeIdPool.begin();iter!=moleculeIdPool.end();++iter){
[dc11c9]403 if(iter->isBefore(id)){
[127a8e]404 // we have coverd all available ranges... nothing to be found here
405 break;
406 }
407 // no need to check first, since it has to be <=id, since otherwise we would have broken out
[dc11c9]408 if(!iter->isBeyond(id)){
[127a8e]409 // we found a matching range... get the id from this range
410
411 // split up this range at the point of id
[dc11c9]412 range<moleculeId_t> bottomRange = makeRange(iter->first,id);
413 range<moleculeId_t> topRange = makeRange(id+1,iter->last);
[127a8e]414 // remove this range
415 moleculeIdPool.erase(iter);
[dc11c9]416 if(bottomRange.first<bottomRange.last){
[127a8e]417 moleculeIdPool.insert(bottomRange);
418 }
[dc11c9]419 if(topRange.first<topRange.last){
[127a8e]420 moleculeIdPool.insert(topRange);
421 }
422 defragMoleculeIdPool();
423 return true;
424 }
425 }
426 // this ID could not be reserved
427 return false;
428}
429
430void World::defragMoleculeIdPool(){
431 // check if the situation is bad enough to make defragging neccessary
432 if((numMoleculeDefragSkips<MAX_FRAGMENTATION_SKIPS) &&
433 (moleculeIdPool.size()<lastMoleculePoolSize+MAX_POOL_FRAGMENTATION)){
434 ++numMoleculeDefragSkips;
435 return;
436 }
437 for(moleculeIdPool_t::iterator iter = moleculeIdPool.begin();iter!=moleculeIdPool.end();){
438 // see if this range is adjacent to the next one
439 moleculeIdPool_t::iterator next = iter;
440 next++;
[dc11c9]441 if(next!=moleculeIdPool.end() && (next->first==iter->last)){
[127a8e]442 // merge the two ranges
[dc11c9]443 range<moleculeId_t> newRange = makeRange(iter->first,next->last);
[127a8e]444 moleculeIdPool.erase(iter);
445 moleculeIdPool.erase(next);
446 pair<moleculeIdPool_t::iterator,bool> res = moleculeIdPool.insert(newRange);
447 ASSERT(res.second,"Id-Pool was confused");
448 iter=res.first;
449 continue;
450 }
451 ++iter;
452 }
453 if(!moleculeIdPool.empty()){
454 // check if the last range is at the border
455 moleculeIdPool_t::iterator iter = moleculeIdPool.end();
456 iter--;
[dc11c9]457 if(iter->last==currMoleculeId){
[127a8e]458 currMoleculeId=iter->first;
459 moleculeIdPool.erase(iter);
460 }
461 }
462 lastMoleculePoolSize=moleculeIdPool.size();
463 numMoleculeDefragSkips=0;
464}
465
[865a945]466/******************************* Iterators ********************************/
467
[fa0b18]468// external parts with observers
469
[6e97e5]470CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor);
471
[fa0b18]472World::AtomIterator
473World::getAtomIter(AtomDescriptor descr){
474 return AtomIterator(descr,atoms);
475}
[865a945]476
[fa0b18]477World::AtomIterator
478World::getAtomIter(){
479 return AtomIterator(AllAtoms(),atoms);
[865a945]480}
[354859]481
[fa0b18]482World::AtomIterator
483World::atomEnd(){
[6e97e5]484 return AtomIterator(AllAtoms(),atoms,atoms.end());
[7c4e29]485}
486
[6e97e5]487CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor);
488
[5d880e]489World::MoleculeIterator
490World::getMoleculeIter(MoleculeDescriptor descr){
491 return MoleculeIterator(descr,molecules);
492}
493
494World::MoleculeIterator
495World::getMoleculeIter(){
496 return MoleculeIterator(AllMolecules(),molecules);
[1c51c8]497}
498
[5d880e]499World::MoleculeIterator
500World::moleculeEnd(){
[6e97e5]501 return MoleculeIterator(AllMolecules(),molecules,molecules.end());
[1c51c8]502}
503
[fa0b18]504// Internal parts, without observers
505
506// Build the AtomIterator from template
507CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet::set_t,AtomDescriptor);
508
509
510World::internal_AtomIterator
511World::getAtomIter_internal(AtomDescriptor descr){
512 return internal_AtomIterator(descr,atoms.getContent());
513}
514
515World::internal_AtomIterator
516World::atomEnd_internal(){
517 return internal_AtomIterator(AllAtoms(),atoms.getContent(),atoms.end_internal());
518}
519
[6e97e5]520// build the MoleculeIterator from template
[e3d865]521CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet::set_t,MoleculeDescriptor);
[6e97e5]522
[e3d865]523World::internal_MoleculeIterator World::getMoleculeIter_internal(MoleculeDescriptor descr){
524 return internal_MoleculeIterator(descr,molecules.getContent());
[1c51c8]525}
526
[e3d865]527World::internal_MoleculeIterator World::moleculeEnd_internal(){
528 return internal_MoleculeIterator(AllMolecules(),molecules.getContent(),molecules.end_internal());
[1c51c8]529}
530
[90c4280]531/************************** Selection of Atoms and molecules ******************/
532
533// Atoms
534
535void World::clearAtomSelection(){
536 selectedAtoms.clear();
537}
538
[e4afb4]539void World::selectAtom(const atom *_atom){
540 // atom * is unchanged in this function, but we do store entity as changeable
541 ASSERT(_atom,"Invalid pointer in selection of atom");
542 selectedAtoms[_atom->getId()]=const_cast<atom *>(_atom);
[90c4280]543}
544
[e4afb4]545void World::selectAtom(const atomId_t id){
[90c4280]546 ASSERT(atoms.count(id),"Atom Id selected that was not in the world");
547 selectedAtoms[id]=atoms[id];
548}
549
550void World::selectAllAtoms(AtomDescriptor descr){
551 internal_AtomIterator begin = getAtomIter_internal(descr);
552 internal_AtomIterator end = atomEnd_internal();
[e4afb4]553 void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
[90c4280]554 for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
555}
556
[e4afb4]557void World::selectAtomsOfMolecule(const molecule *_mol){
[90c4280]558 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
559 // need to make it const to get the fast iterators
560 const molecule *mol = _mol;
[e4afb4]561 void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
[90c4280]562 for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is select... see above
563}
564
[e4afb4]565void World::selectAtomsOfMolecule(const moleculeId_t id){
[90c4280]566 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
567 selectAtomsOfMolecule(molecules[id]);
568}
569
[e4afb4]570void World::unselectAtom(const atom *_atom){
571 ASSERT(_atom,"Invalid pointer in unselection of atom");
572 unselectAtom(_atom->getId());
[61d655e]573}
574
[e4afb4]575void World::unselectAtom(const atomId_t id){
[61d655e]576 ASSERT(atoms.count(id),"Atom Id unselected that was not in the world");
577 selectedAtoms.erase(id);
578}
579
580void World::unselectAllAtoms(AtomDescriptor descr){
581 internal_AtomIterator begin = getAtomIter_internal(descr);
582 internal_AtomIterator end = atomEnd_internal();
[e4afb4]583 void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
[61d655e]584 for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
585}
586
[e4afb4]587void World::unselectAtomsOfMolecule(const molecule *_mol){
[61d655e]588 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
589 // need to make it const to get the fast iterators
590 const molecule *mol = _mol;
[e4afb4]591 void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
[61d655e]592 for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is unsselect... see above
593}
594
[e4afb4]595void World::unselectAtomsOfMolecule(const moleculeId_t id){
[61d655e]596 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
597 unselectAtomsOfMolecule(molecules[id]);
598}
599
[e472eab]600size_t World::countSelectedAtoms() const {
[eacc3b]601 size_t count = 0;
[e472eab]602 for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
[eacc3b]603 count++;
604 return count;
605}
606
[e4afb4]607bool World::isSelected(const atom *_atom) const {
608 return selectedAtoms.find(_atom->getId()) != selectedAtoms.end();
[e0e156]609}
610
[e472eab]611const std::vector<atom *> World::getSelectedAtoms() const {
612 std::vector<atom *> returnAtoms;
613 returnAtoms.resize(countSelectedAtoms());
614 int count = 0;
615 for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
616 returnAtoms[count++] = iter->second;
617 return returnAtoms;
618}
619
620
[90c4280]621// Molecules
622
623void World::clearMoleculeSelection(){
624 selectedMolecules.clear();
625}
626
[e4afb4]627void World::selectMolecule(const molecule *_mol){
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){
[90c4280]634 ASSERT(molecules.count(id),"Molecule Id selected that was not in the world");
635 selectedMolecules[id]=molecules[id];
636}
637
[e472eab]638void World::selectAllMolecules(MoleculeDescriptor descr){
[90c4280]639 internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
640 internal_MoleculeIterator end = moleculeEnd_internal();
[e4afb4]641 void (World::*func)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
[90c4280]642 for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
643}
644
[e4afb4]645void World::selectMoleculeOfAtom(const atom *_atom){
646 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
647 molecule *mol=_atom->getMolecule();
[90c4280]648 // the atom might not be part of a molecule
649 if(mol){
650 selectMolecule(mol);
651 }
652}
653
[e4afb4]654void World::selectMoleculeOfAtom(const atomId_t id){
[90c4280]655 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
656 selectMoleculeOfAtom(atoms[id]);
657}
658
[e4afb4]659void World::unselectMolecule(const molecule *_mol){
660 ASSERT(_mol,"invalid pointer in unselection of molecule");
661 unselectMolecule(_mol->getId());
[61d655e]662}
663
[e4afb4]664void World::unselectMolecule(const moleculeId_t id){
[61d655e]665 ASSERT(molecules.count(id),"No such molecule with ID in unselection");
666 selectedMolecules.erase(id);
667}
668
[e472eab]669void World::unselectAllMolecules(MoleculeDescriptor descr){
[61d655e]670 internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
671 internal_MoleculeIterator end = moleculeEnd_internal();
[e4afb4]672 void (World::*func)(const molecule*) = &World::unselectMolecule; // needed for type resolution of overloaded function
[61d655e]673 for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
674}
675
[e4afb4]676void World::unselectMoleculeOfAtom(const atom *_atom){
677 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
678 molecule *mol=_atom->getMolecule();
[61d655e]679 // the atom might not be part of a molecule
680 if(mol){
681 unselectMolecule(mol);
682 }
683}
684
[e4afb4]685void World::unselectMoleculeOfAtom(const atomId_t id){
[61d655e]686 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
687 unselectMoleculeOfAtom(atoms[id]);
688}
689
[e472eab]690size_t World::countSelectedMolecules() const {
[eacc3b]691 size_t count = 0;
[e472eab]692 for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
[eacc3b]693 count++;
694 return count;
695}
696
[e4afb4]697bool World::isSelected(const molecule *_mol) const {
698 return selectedMolecules.find(_mol->getId()) != selectedMolecules.end();
[e0e156]699}
700
[e472eab]701const std::vector<molecule *> World::getSelectedMolecules() const {
702 std::vector<molecule *> returnMolecules;
703 returnMolecules.resize(countSelectedMolecules());
704 int count = 0;
705 for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
706 returnMolecules[count++] = iter->second;
707 return returnMolecules;
708}
709
[3839e5]710/******************* Iterators over Selection *****************************/
711World::AtomSelectionIterator World::beginAtomSelection(){
712 return selectedAtoms.begin();
713}
714
715World::AtomSelectionIterator World::endAtomSelection(){
716 return selectedAtoms.end();
717}
718
719
720World::MoleculeSelectionIterator World::beginMoleculeSelection(){
721 return selectedMolecules.begin();
722}
723
724World::MoleculeSelectionIterator World::endMoleculeSelection(){
725 return selectedMolecules.end();
726}
727
[5d1611]728/******************************* Singleton Stuff **************************/
729
[7a1ce5]730World::World() :
[cd5047]731 Observable("World"),
[354859]732 periode(new periodentafel),
[8e1f7af]733 configuration(new config),
[43dad6]734 Thermostats(new ThermoStatContainer),
[e4b5de]735 ExitFlag(0),
[fa0b18]736 atoms(this),
[90c4280]737 selectedAtoms(this),
[24a5e0]738 currAtomId(0),
[127a8e]739 lastAtomPoolSize(0),
740 numAtomDefragSkips(0),
[51be2a]741 molecules(this),
[90c4280]742 selectedMolecules(this),
[24a5e0]743 currMoleculeId(0),
[654394]744 lastMoleculePoolSize(0),
745 numMoleculeDefragSkips(0),
[24a5e0]746 molecules_deprecated(new MoleculeListClass(this))
[7dad10]747{
[84c494]748 cell_size = new Box;
[cca9ef]749 RealSpaceMatrix domain;
[84c494]750 domain.at(0,0) = 20;
751 domain.at(1,1) = 20;
752 domain.at(2,2) = 20;
753 cell_size->setM(domain);
[387b36]754 defaultName = "none";
[7dad10]755 molecules_deprecated->signOn(this);
756}
[5d1611]757
758World::~World()
[354859]759{
[028c2e]760 molecules_deprecated->signOff(this);
[84c494]761 delete cell_size;
[46d958]762 delete molecules_deprecated;
[cbc5fb]763 MoleculeSet::iterator molIter;
764 for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
765 DeleteMolecule((*molIter).second);
766 }
767 molecules.clear();
768 AtomSet::iterator atIter;
769 for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
770 DeleteAtom((*atIter).second);
[46d958]771 }
772 atoms.clear();
[6cb9c76]773 delete periode;
774 delete configuration;
775 delete Thermostats;
[354859]776}
[5d1611]777
[23b547]778// Explicit instantiation of the singleton mechanism at this point
[5d1611]779
[23b547]780CONSTRUCT_SINGLETON(World)
[5d1611]781
[5f1d5b8]782CONSTRUCT_OBSERVEDCONTAINER(World::AtomSTLSet)
783
784CONSTRUCT_OBSERVEDCONTAINER(World::MoleculeSTLSet)
785
[5d1611]786/******************************* deprecated Legacy Stuff ***********************/
787
[354859]788MoleculeListClass *&World::getMolecules() {
789 return molecules_deprecated;
[5d1611]790}
Note: See TracBrowser for help on using the repository browser.