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