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