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