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