| [5d1611] | 1 | /* | 
|---|
|  | 2 | * World.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Feb 3, 2010 | 
|---|
|  | 5 | *      Author: crueger | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef WORLD_HPP_ | 
|---|
|  | 9 | #define WORLD_HPP_ | 
|---|
|  | 10 |  | 
|---|
| [3e4fb6] | 11 | // include config.h | 
|---|
|  | 12 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 13 | #include <config.h> | 
|---|
|  | 14 | #endif | 
|---|
|  | 15 |  | 
|---|
| [b34306] | 16 | /*********************************************** includes ***********************************/ | 
|---|
|  | 17 |  | 
|---|
| [7c4e29] | 18 | #include <string> | 
|---|
| [d346b6] | 19 | #include <map> | 
|---|
| [fc1b24] | 20 | #include <vector> | 
|---|
| [354859] | 21 | #include <set> | 
|---|
| [cad383] | 22 | #include <stack> | 
|---|
| [7c4e29] | 23 | #include <boost/thread.hpp> | 
|---|
| [865a945] | 24 | #include <boost/shared_ptr.hpp> | 
|---|
| [5d1611] | 25 |  | 
|---|
| [3139b2] | 26 | #include "Actions/ActionTrait.hpp" | 
|---|
| [6f0841] | 27 | #include "Atom/AtomSet.hpp" | 
|---|
| [feb5d0] | 28 | #include "Descriptors/SelectiveConstIterator.hpp" | 
|---|
| [6e97e5] | 29 | #include "Descriptors/SelectiveIterator.hpp" | 
|---|
| [02ce36] | 30 | #include "CodePatterns/Observer/Observable.hpp" | 
|---|
|  | 31 | #include "CodePatterns/Observer/Observer.hpp" | 
|---|
| [ad011c] | 32 | #include "CodePatterns/Cacheable.hpp" | 
|---|
|  | 33 | #include "CodePatterns/Singleton.hpp" | 
|---|
| [02ce36] | 34 | #include "CodePatterns/Observer/ObservedContainer.hpp" | 
|---|
| [ad011c] | 35 | #include "CodePatterns/Range.hpp" | 
|---|
| [b97a60] | 36 | #include "IdPool_policy.hpp" | 
|---|
| [3e4fb6] | 37 | #include "IdPool.hpp" | 
|---|
| [4834f4] | 38 | #include "LinkedCell/LinkedCell_View.hpp" | 
|---|
| [3e4fb6] | 39 | #include "types.hpp" | 
|---|
| [5d1611] | 40 |  | 
|---|
| [4834f4] | 41 |  | 
|---|
| [5d1611] | 42 | // forward declarations | 
|---|
| [4d9c01] | 43 | class atom; | 
|---|
| [fc1b24] | 44 | class AtomDescriptor; | 
|---|
| [7a1ce5] | 45 | class AtomDescriptor_impl; | 
|---|
| [f71baf] | 46 | class BondGraph; | 
|---|
| [84c494] | 47 | class Box; | 
|---|
| [43dad6] | 48 | class config; | 
|---|
| [98dbee] | 49 | class HomologyContainer; | 
|---|
| [cca9ef] | 50 | class RealSpaceMatrix; | 
|---|
| [43dad6] | 51 | class molecule; | 
|---|
| [1c51c8] | 52 | class MoleculeDescriptor; | 
|---|
|  | 53 | class MoleculeDescriptor_impl; | 
|---|
| [43dad6] | 54 | class MoleculeListClass; | 
|---|
|  | 55 | class periodentafel; | 
|---|
|  | 56 | class ThermoStatContainer; | 
|---|
| [5d1611] | 57 |  | 
|---|
| [4834f4] | 58 | namespace LinkedCell { | 
|---|
|  | 59 | class LinkedCell_Controller; | 
|---|
|  | 60 | } | 
|---|
|  | 61 |  | 
|---|
| [ce7fdc] | 62 | namespace MoleCuilder { | 
|---|
|  | 63 | class ManipulateAtomsProcess; | 
|---|
|  | 64 | template<typename T> class AtomsCalculation; | 
|---|
|  | 65 | } | 
|---|
| [fa0b18] | 66 |  | 
|---|
| [b34306] | 67 | /****************************************** forward declarations *****************************/ | 
|---|
| [23b547] | 68 |  | 
|---|
| [b34306] | 69 | /********************************************** Class World *******************************/ | 
|---|
| [23b547] | 70 |  | 
|---|
| [7188b1] | 71 | namespace detail { | 
|---|
|  | 72 | template <class T> const T* lastChanged() | 
|---|
|  | 73 | { | 
|---|
|  | 74 | ASSERT(0, "detail::lastChanged() - only specializations may be used."); | 
|---|
|  | 75 | return NULL; | 
|---|
|  | 76 | } | 
|---|
|  | 77 | } | 
|---|
|  | 78 |  | 
|---|
| [23b547] | 79 | class World : public Singleton<World>, public Observable | 
|---|
| [5d1611] | 80 | { | 
|---|
| [23b547] | 81 |  | 
|---|
|  | 82 | // Make access to constructor and destructor possible from inside the singleton | 
|---|
|  | 83 | friend class Singleton<World>; | 
|---|
|  | 84 |  | 
|---|
| [b54ac8] | 85 | // necessary for coupling with descriptors | 
|---|
| [7a1ce5] | 86 | friend class AtomDescriptor_impl; | 
|---|
| [865a945] | 87 | friend class AtomDescriptor; | 
|---|
| [1c51c8] | 88 | friend class MoleculeDescriptor_impl; | 
|---|
|  | 89 | friend class MoleculeDescriptor; | 
|---|
| [41aa39] | 90 | // coupling with descriptors over selection | 
|---|
|  | 91 | friend class AtomSelectionDescriptor_impl; | 
|---|
| [ea7a50] | 92 | friend class AtomOfMoleculeSelectionDescriptor_impl; | 
|---|
| [61c364] | 93 | friend class AtomOrderDescriptor_impl; | 
|---|
| [ea7a50] | 94 | friend class MoleculeOfAtomSelectionDescriptor_impl; | 
|---|
|  | 95 | friend class MoleculeOrderDescriptor_impl; | 
|---|
| [cf0ca1] | 96 | friend class MoleculeSelectionDescriptor_impl; | 
|---|
| [865a945] | 97 |  | 
|---|
| [b54ac8] | 98 | // Actions, calculations etc associated with the World | 
|---|
| [ce7fdc] | 99 | friend class MoleCuilder::ManipulateAtomsProcess; | 
|---|
|  | 100 | template<typename> friend class MoleCuilder::AtomsCalculation; | 
|---|
| [5d1611] | 101 | public: | 
|---|
| [5f1d5b8] | 102 | // some typedefs for the CONSTRUCT_... macros (no "," allows in a single parameter name) | 
|---|
|  | 103 | typedef std::map<atomId_t,atom*> AtomSTLSet; | 
|---|
|  | 104 | typedef std::map<moleculeId_t,molecule*> MoleculeSTLSet; | 
|---|
| [23b547] | 105 |  | 
|---|
|  | 106 | // Types for Atom and Molecule structures | 
|---|
| [5f1d5b8] | 107 | typedef ObservedContainer< AtomSTLSet > AtomSet; | 
|---|
|  | 108 | typedef ObservedContainer< MoleculeSTLSet > MoleculeSet; | 
|---|
| [5d1611] | 109 |  | 
|---|
| [4d72e4] | 110 | typedef ATOMSET(std::vector) AtomComposite; | 
|---|
| [795c0f] | 111 | typedef CONSTATOMSET(std::vector) ConstAtomComposite; | 
|---|
| [4d72e4] | 112 |  | 
|---|
| [7188b1] | 113 | /******* Notifications *******/ | 
|---|
|  | 114 |  | 
|---|
| [d25bec] | 115 | //!> enumeration of present notification types: only insertion/removal of atoms or molecules | 
|---|
| [7188b1] | 116 | enum NotificationType { | 
|---|
|  | 117 | AtomInserted, | 
|---|
|  | 118 | AtomRemoved, | 
|---|
|  | 119 | MoleculeInserted, | 
|---|
|  | 120 | MoleculeRemoved, | 
|---|
| [69643a] | 121 | SelectionChanged, | 
|---|
| [7188b1] | 122 | NotificationType_MAX | 
|---|
|  | 123 | }; | 
|---|
|  | 124 |  | 
|---|
|  | 125 | //>! access to last changed element (atom or molecule) | 
|---|
|  | 126 | template <class T> const T* lastChanged() const | 
|---|
|  | 127 | { return detail::lastChanged<T>(); } | 
|---|
|  | 128 |  | 
|---|
| [fb95a5] | 129 | const atomId_t lastChangedAtomId() const | 
|---|
|  | 130 | { return _lastchangedatomid; } | 
|---|
|  | 131 |  | 
|---|
|  | 132 | const moleculeId_t lastChangedMolId() const | 
|---|
|  | 133 | { return _lastchangedmolid; } | 
|---|
|  | 134 |  | 
|---|
| [7188b1] | 135 | /***** getter and setter *****/ | 
|---|
| [354859] | 136 | // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object | 
|---|
| [02ee15] | 137 | /** | 
|---|
|  | 138 | * returns the periodentafel for the world. | 
|---|
|  | 139 | */ | 
|---|
| [354859] | 140 | periodentafel *&getPeriode(); | 
|---|
| [02ee15] | 141 |  | 
|---|
| [f71baf] | 142 | /** Returns the BondGraph for the World. | 
|---|
|  | 143 | * | 
|---|
|  | 144 | * @return reference to BondGraph | 
|---|
|  | 145 | */ | 
|---|
|  | 146 | BondGraph *&getBondGraph(); | 
|---|
|  | 147 |  | 
|---|
|  | 148 | /** Sets the World's BondGraph. | 
|---|
|  | 149 | * | 
|---|
|  | 150 | * @param _BG new BondGraph | 
|---|
|  | 151 | */ | 
|---|
|  | 152 | void setBondGraph(BondGraph *_BG); | 
|---|
| [98dbee] | 153 |  | 
|---|
|  | 154 | /** Getter for homology container. | 
|---|
|  | 155 | * | 
|---|
|  | 156 | * \return const reference to homology container. | 
|---|
|  | 157 | */ | 
|---|
|  | 158 | HomologyContainer &getHomologies(); | 
|---|
|  | 159 |  | 
|---|
|  | 160 | /** Setter for homology container. | 
|---|
|  | 161 | * | 
|---|
|  | 162 | * \param homologies reference to homologies, set to NULL | 
|---|
|  | 163 | */ | 
|---|
|  | 164 | void resetHomologies(HomologyContainer *&homologies); | 
|---|
|  | 165 |  | 
|---|
| [8e1f7af] | 166 | /** | 
|---|
|  | 167 | * returns the configuration for the world. | 
|---|
|  | 168 | */ | 
|---|
|  | 169 | config *&getConfig(); | 
|---|
|  | 170 |  | 
|---|
| [7188b1] | 171 | /** Returns a notification_ptr for a specific type. | 
|---|
|  | 172 | * | 
|---|
|  | 173 | * @param type request type | 
|---|
|  | 174 | * @return reference to instance | 
|---|
|  | 175 | */ | 
|---|
|  | 176 | Notification_ptr getNotification(enum NotificationType type) const; | 
|---|
|  | 177 |  | 
|---|
| [02ee15] | 178 | /** | 
|---|
|  | 179 | * returns the first atom that matches a given descriptor. | 
|---|
|  | 180 | * Do not rely on ordering for descriptors that match more than one atom. | 
|---|
|  | 181 | */ | 
|---|
| [7a1ce5] | 182 | atom* getAtom(AtomDescriptor descriptor); | 
|---|
| [02ee15] | 183 |  | 
|---|
| [795c0f] | 184 | /** | 
|---|
|  | 185 | * returns the first atom that matches a given descriptor. | 
|---|
|  | 186 | * Do not rely on ordering for descriptors that match more than one atom. | 
|---|
|  | 187 | */ | 
|---|
|  | 188 | const atom* getAtom(AtomDescriptor descriptor) const; | 
|---|
|  | 189 |  | 
|---|
| [02ee15] | 190 | /** | 
|---|
|  | 191 | * returns a vector containing all atoms that match a given descriptor | 
|---|
|  | 192 | */ | 
|---|
| [4d72e4] | 193 | AtomComposite getAllAtoms(AtomDescriptor descriptor); | 
|---|
| [795c0f] | 194 |  | 
|---|
|  | 195 | /** | 
|---|
|  | 196 | * returns a vector containing all atoms that match a given descriptor | 
|---|
|  | 197 | */ | 
|---|
|  | 198 | ConstAtomComposite getAllAtoms(AtomDescriptor descriptor) const; | 
|---|
|  | 199 |  | 
|---|
|  | 200 | /** | 
|---|
|  | 201 | * returns a vector containing all atoms that match a given descriptor | 
|---|
|  | 202 | */ | 
|---|
| [4d72e4] | 203 | AtomComposite getAllAtoms(); | 
|---|
| [b54ac8] | 204 |  | 
|---|
| [795c0f] | 205 | /** | 
|---|
|  | 206 | * returns a vector containing all atoms that match a given descriptor | 
|---|
|  | 207 | */ | 
|---|
|  | 208 | ConstAtomComposite getAllAtoms() const; | 
|---|
|  | 209 |  | 
|---|
| [02ee15] | 210 | /** | 
|---|
|  | 211 | * returns a calculation that calls a given function on all atoms matching a descriptor. | 
|---|
|  | 212 | * the calculation is not called at this point and can be used as an action, i.e. be stored in | 
|---|
|  | 213 | * menus, be kept around for later use etc. | 
|---|
|  | 214 | */ | 
|---|
| [3139b2] | 215 | template<typename T> MoleCuilder::AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,const MoleCuilder::ActionTrait &_trait,AtomDescriptor); | 
|---|
|  | 216 | template<typename T> MoleCuilder::AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,const MoleCuilder::ActionTrait &_trait); | 
|---|
| [b54ac8] | 217 |  | 
|---|
| [02ee15] | 218 | /** | 
|---|
|  | 219 | * get the number of atoms in the World | 
|---|
|  | 220 | */ | 
|---|
| [795c0f] | 221 | int numAtoms() const; | 
|---|
| [02ee15] | 222 |  | 
|---|
| [1c51c8] | 223 | /** | 
|---|
|  | 224 | * returns the first molecule that matches a given descriptor. | 
|---|
|  | 225 | * Do not rely on ordering for descriptors that match more than one molecule. | 
|---|
|  | 226 | */ | 
|---|
|  | 227 | molecule *getMolecule(MoleculeDescriptor descriptor); | 
|---|
|  | 228 |  | 
|---|
| [97445f] | 229 | /** | 
|---|
|  | 230 | * returns the first molecule that matches a given descriptor. | 
|---|
|  | 231 | * Do not rely on ordering for descriptors that match more than one molecule. | 
|---|
|  | 232 | */ | 
|---|
|  | 233 | const molecule *getMolecule(MoleculeDescriptor descriptor) const; | 
|---|
|  | 234 |  | 
|---|
| [1c51c8] | 235 | /** | 
|---|
|  | 236 | * returns a vector containing all molecules that match a given descriptor | 
|---|
|  | 237 | */ | 
|---|
|  | 238 | std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor); | 
|---|
| [97445f] | 239 |  | 
|---|
|  | 240 | /** | 
|---|
|  | 241 | * returns a vector containing all molecules that match a given descriptor | 
|---|
|  | 242 | */ | 
|---|
|  | 243 | std::vector<const molecule*> getAllMolecules(MoleculeDescriptor descriptor) const; | 
|---|
|  | 244 |  | 
|---|
|  | 245 | /** | 
|---|
|  | 246 | * returns a vector containing all molecules that match a given descriptor | 
|---|
|  | 247 | */ | 
|---|
| [97ebf8] | 248 | std::vector<molecule*> getAllMolecules(); | 
|---|
| [97445f] | 249 | /** | 
|---|
|  | 250 | * returns a vector containing all molecules that match a given descriptor | 
|---|
|  | 251 | */ | 
|---|
|  | 252 | std::vector<const molecule*> getAllMolecules() const; | 
|---|
| [1c51c8] | 253 |  | 
|---|
| [02ee15] | 254 | /** | 
|---|
|  | 255 | * get the number of molecules in the World | 
|---|
|  | 256 | */ | 
|---|
| [97445f] | 257 | int numMolecules() const; | 
|---|
| [354859] | 258 |  | 
|---|
| [5f612ee] | 259 | /** | 
|---|
|  | 260 | * get the domain size as a symmetric matrix (6 components) | 
|---|
|  | 261 | */ | 
|---|
| [84c494] | 262 | Box& getDomain(); | 
|---|
|  | 263 |  | 
|---|
|  | 264 | /** | 
|---|
|  | 265 | * Set the domain size from a matrix object | 
|---|
|  | 266 | * | 
|---|
|  | 267 | * Matrix needs to be symmetric | 
|---|
|  | 268 | */ | 
|---|
| [cca9ef] | 269 | void setDomain(const RealSpaceMatrix &mat); | 
|---|
| [5f612ee] | 270 |  | 
|---|
|  | 271 | /** | 
|---|
|  | 272 | * set the domain size as a symmetric matrix (6 components) | 
|---|
|  | 273 | */ | 
|---|
|  | 274 | void setDomain(double * matrix); | 
|---|
|  | 275 |  | 
|---|
| [4834f4] | 276 | /** Returns a LinkedCell structure for obtaining neighbors quickly. | 
|---|
|  | 277 | * | 
|---|
|  | 278 | * @param distance desired linked cell edge length | 
|---|
|  | 279 | * @return view of restricted underlying LinkedCell_Model | 
|---|
|  | 280 | */ | 
|---|
|  | 281 | LinkedCell::LinkedCell_View getLinkedCell(const double distance); | 
|---|
|  | 282 |  | 
|---|
| [d297a3] | 283 | /** | 
|---|
|  | 284 | * set the current time of the world. | 
|---|
|  | 285 | * | 
|---|
|  | 286 | * @param _step time step to set to | 
|---|
|  | 287 | */ | 
|---|
|  | 288 | void setTime(const unsigned int _step); | 
|---|
|  | 289 |  | 
|---|
| [2a8731] | 290 | /** | 
|---|
|  | 291 | * get the current time of the world. | 
|---|
|  | 292 | * | 
|---|
|  | 293 | * @return current time step | 
|---|
|  | 294 | */ | 
|---|
|  | 295 | const unsigned getTime() const; | 
|---|
|  | 296 |  | 
|---|
| [5f612ee] | 297 | /** | 
|---|
|  | 298 | * get the default name | 
|---|
|  | 299 | */ | 
|---|
| [387b36] | 300 | std::string getDefaultName(); | 
|---|
| [5f612ee] | 301 |  | 
|---|
|  | 302 | /** | 
|---|
|  | 303 | * set the default name | 
|---|
|  | 304 | */ | 
|---|
| [387b36] | 305 | void setDefaultName(std::string name); | 
|---|
| [5f612ee] | 306 |  | 
|---|
| [43dad6] | 307 | /** | 
|---|
|  | 308 | * get pointer to World's ThermoStatContainer | 
|---|
|  | 309 | */ | 
|---|
|  | 310 | ThermoStatContainer * getThermostats(); | 
|---|
|  | 311 |  | 
|---|
| [e4b5de] | 312 | /* | 
|---|
|  | 313 | * get the ExitFlag | 
|---|
|  | 314 | */ | 
|---|
|  | 315 | int getExitFlag(); | 
|---|
|  | 316 |  | 
|---|
|  | 317 | /* | 
|---|
|  | 318 | * set the ExitFlag | 
|---|
|  | 319 | */ | 
|---|
|  | 320 | void setExitFlag(int flag); | 
|---|
|  | 321 |  | 
|---|
| [354859] | 322 | /***** Methods to work with the World *****/ | 
|---|
| [02ee15] | 323 |  | 
|---|
|  | 324 | /** | 
|---|
|  | 325 | * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique | 
|---|
|  | 326 | * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly. | 
|---|
|  | 327 | */ | 
|---|
| [354859] | 328 | molecule *createMolecule(); | 
|---|
| [02ee15] | 329 |  | 
|---|
| [cbc5fb] | 330 | void destroyMolecule(molecule*); | 
|---|
|  | 331 | void destroyMolecule(moleculeId_t); | 
|---|
|  | 332 |  | 
|---|
| [02ee15] | 333 | /** | 
|---|
|  | 334 | * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores | 
|---|
|  | 335 | * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends. | 
|---|
|  | 336 | */ | 
|---|
| [46d958] | 337 | atom *createAtom(); | 
|---|
| [02ee15] | 338 |  | 
|---|
|  | 339 | /** | 
|---|
|  | 340 | * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests. | 
|---|
|  | 341 | * Do not re-register Atoms already known to the world since this will cause double-frees. | 
|---|
|  | 342 | */ | 
|---|
| [46d958] | 343 | int registerAtom(atom*); | 
|---|
| [02ee15] | 344 |  | 
|---|
|  | 345 | /** | 
|---|
|  | 346 | * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on | 
|---|
|  | 347 | * atom directly since this will leave the pointer inside the world. | 
|---|
|  | 348 | */ | 
|---|
| [46d958] | 349 | void destroyAtom(atom*); | 
|---|
| [02ee15] | 350 |  | 
|---|
|  | 351 | /** | 
|---|
|  | 352 | * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on | 
|---|
|  | 353 | * atom directly since this will leave the pointer inside the world. | 
|---|
|  | 354 | */ | 
|---|
| [cbc5fb] | 355 | void destroyAtom(atomId_t); | 
|---|
| [865a945] | 356 |  | 
|---|
| [88d586] | 357 | /** | 
|---|
|  | 358 | * used when changing an atom Id. | 
|---|
|  | 359 | * Unless you are calling this method from inside an atom don't fiddle with the third parameter. | 
|---|
|  | 360 | * | 
|---|
| [992bd5] | 361 | * Return value indicates whether the change could be done or not. | 
|---|
| [88d586] | 362 | */ | 
|---|
|  | 363 | bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0); | 
|---|
|  | 364 |  | 
|---|
| [a7a087] | 365 | /** | 
|---|
|  | 366 | * used when changing an molecule Id. | 
|---|
| [992bd5] | 367 | * Unless you are calling this method from inside an molecule don't fiddle with the third parameter. | 
|---|
| [a7a087] | 368 | * | 
|---|
| [992bd5] | 369 | * Return value indicates whether the change could be done or not. | 
|---|
| [a7a087] | 370 | */ | 
|---|
|  | 371 | bool changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target=0); | 
|---|
|  | 372 |  | 
|---|
| [02ee15] | 373 | /** | 
|---|
|  | 374 | * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not | 
|---|
|  | 375 | * called at this time, so it can be passed around, stored inside menuItems etc. | 
|---|
|  | 376 | */ | 
|---|
| [ce7fdc] | 377 | MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor); | 
|---|
|  | 378 | MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string); | 
|---|
| [7c4e29] | 379 |  | 
|---|
| [fa0b18] | 380 | /**** | 
|---|
|  | 381 | * Iterators to use internal data structures | 
|---|
|  | 382 | * All these iterators are observed to track changes. | 
|---|
|  | 383 | * There is a corresponding protected section with unobserved iterators, | 
|---|
| [90c4280] | 384 | * which can be used internally when the extra speed is needed | 
|---|
| [fa0b18] | 385 | */ | 
|---|
|  | 386 |  | 
|---|
|  | 387 | typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor>       AtomIterator; | 
|---|
| [feb5d0] | 388 | typedef SelectiveConstIterator<atom*,AtomSet,AtomDescriptor>       AtomConstIterator; | 
|---|
| [fa0b18] | 389 |  | 
|---|
|  | 390 | /** | 
|---|
|  | 391 | * returns an iterator over all Atoms matching a given descriptor. | 
|---|
|  | 392 | * This iterator is observed, so don't keep it around unnecessary to | 
|---|
|  | 393 | * avoid unintended blocking. | 
|---|
|  | 394 | */ | 
|---|
|  | 395 | AtomIterator getAtomIter(AtomDescriptor descr); | 
|---|
| [feb5d0] | 396 | AtomConstIterator getAtomIter(AtomDescriptor descr) const; | 
|---|
| [fa0b18] | 397 | AtomIterator getAtomIter(); | 
|---|
| [feb5d0] | 398 | AtomConstIterator getAtomIter() const; | 
|---|
| [fa0b18] | 399 |  | 
|---|
|  | 400 | AtomIterator atomEnd(); | 
|---|
| [feb5d0] | 401 | AtomConstIterator atomEnd() const; | 
|---|
| [fa0b18] | 402 |  | 
|---|
| [e3d865] | 403 | typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor>   MoleculeIterator; | 
|---|
| [feb5d0] | 404 | typedef SelectiveConstIterator<molecule*,MoleculeSet,MoleculeDescriptor>   MoleculeConstIterator; | 
|---|
| [51be2a] | 405 |  | 
|---|
| [90c4280] | 406 | /** | 
|---|
|  | 407 | * returns an iterator over all Molecules matching a given descriptor. | 
|---|
|  | 408 | * This iterator is observed, so don't keep it around unnecessary to | 
|---|
|  | 409 | * avoid unintended blocking. | 
|---|
|  | 410 | */ | 
|---|
| [5d880e] | 411 | MoleculeIterator getMoleculeIter(MoleculeDescriptor descr); | 
|---|
| [feb5d0] | 412 | MoleculeConstIterator getMoleculeIter(MoleculeDescriptor descr) const; | 
|---|
| [5d880e] | 413 | MoleculeIterator getMoleculeIter(); | 
|---|
| [feb5d0] | 414 | MoleculeConstIterator getMoleculeIter() const; | 
|---|
| [5d880e] | 415 |  | 
|---|
|  | 416 | MoleculeIterator moleculeEnd(); | 
|---|
| [feb5d0] | 417 | MoleculeConstIterator moleculeEnd() const; | 
|---|
| [5d880e] | 418 |  | 
|---|
| [90c4280] | 419 | /******** Selections of molecules and Atoms *************/ | 
|---|
|  | 420 | void clearAtomSelection(); | 
|---|
| [ebc499] | 421 | void invertAtomSelection(); | 
|---|
| [cad383] | 422 | void popAtomSelection(); | 
|---|
|  | 423 | void pushAtomSelection(); | 
|---|
| [e4afb4] | 424 | void selectAtom(const atom*); | 
|---|
|  | 425 | void selectAtom(const atomId_t); | 
|---|
| [90c4280] | 426 | void selectAllAtoms(AtomDescriptor); | 
|---|
| [e4afb4] | 427 | void selectAtomsOfMolecule(const molecule*); | 
|---|
|  | 428 | void selectAtomsOfMolecule(const moleculeId_t); | 
|---|
|  | 429 | void unselectAtom(const atom*); | 
|---|
|  | 430 | void unselectAtom(const atomId_t); | 
|---|
| [61d655e] | 431 | void unselectAllAtoms(AtomDescriptor); | 
|---|
| [e4afb4] | 432 | void unselectAtomsOfMolecule(const molecule*); | 
|---|
|  | 433 | void unselectAtomsOfMolecule(const moleculeId_t); | 
|---|
| [e472eab] | 434 | size_t countSelectedAtoms() const; | 
|---|
| [e4afb4] | 435 | bool isSelected(const atom *_atom) const; | 
|---|
| [89643d] | 436 | bool isAtomSelected(const atomId_t no) const; | 
|---|
| [99db9b] | 437 | std::vector<atom *> getSelectedAtoms(); | 
|---|
|  | 438 | std::vector<const atom *> getSelectedAtoms() const; | 
|---|
| [143263] | 439 | std::vector<atomId_t> getSelectedAtomIds() const; | 
|---|
| [90c4280] | 440 |  | 
|---|
|  | 441 | void clearMoleculeSelection(); | 
|---|
| [ebc499] | 442 | void invertMoleculeSelection(); | 
|---|
| [cad383] | 443 | void popMoleculeSelection(); | 
|---|
|  | 444 | void pushMoleculeSelection(); | 
|---|
| [e4afb4] | 445 | void selectMolecule(const molecule*); | 
|---|
|  | 446 | void selectMolecule(const moleculeId_t); | 
|---|
| [e472eab] | 447 | void selectAllMolecules(MoleculeDescriptor); | 
|---|
| [e4afb4] | 448 | void selectMoleculeOfAtom(const atom*); | 
|---|
|  | 449 | void selectMoleculeOfAtom(const atomId_t); | 
|---|
|  | 450 | void unselectMolecule(const molecule*); | 
|---|
|  | 451 | void unselectMolecule(const moleculeId_t); | 
|---|
| [e472eab] | 452 | void unselectAllMolecules(MoleculeDescriptor); | 
|---|
| [e4afb4] | 453 | void unselectMoleculeOfAtom(const atom*); | 
|---|
|  | 454 | void unselectMoleculeOfAtom(const atomId_t); | 
|---|
| [e472eab] | 455 | size_t countSelectedMolecules() const; | 
|---|
| [e4afb4] | 456 | bool isSelected(const molecule *_mol) const; | 
|---|
| [89643d] | 457 | bool isMoleculeSelected(const moleculeId_t no) const; | 
|---|
| [97445f] | 458 | std::vector<molecule *> getSelectedMolecules(); | 
|---|
|  | 459 | std::vector<const molecule *> getSelectedMolecules() const; | 
|---|
| [143263] | 460 | std::vector<moleculeId_t> getSelectedMoleculeIds() const; | 
|---|
| [90c4280] | 461 |  | 
|---|
| [3839e5] | 462 | /******************** Iterators to selections *****************/ | 
|---|
|  | 463 | typedef AtomSet::iterator AtomSelectionIterator; | 
|---|
|  | 464 | AtomSelectionIterator beginAtomSelection(); | 
|---|
|  | 465 | AtomSelectionIterator endAtomSelection(); | 
|---|
| [38f991] | 466 | typedef AtomSet::const_iterator AtomSelectionConstIterator; | 
|---|
|  | 467 | AtomSelectionConstIterator beginAtomSelection() const; | 
|---|
|  | 468 | AtomSelectionConstIterator endAtomSelection() const; | 
|---|
| [3839e5] | 469 |  | 
|---|
|  | 470 | typedef MoleculeSet::iterator MoleculeSelectionIterator; | 
|---|
|  | 471 | MoleculeSelectionIterator beginMoleculeSelection(); | 
|---|
|  | 472 | MoleculeSelectionIterator endMoleculeSelection(); | 
|---|
| [38f991] | 473 | typedef MoleculeSet::const_iterator MoleculeSelectionConstIterator; | 
|---|
|  | 474 | MoleculeSelectionConstIterator beginMoleculeSelection() const; | 
|---|
|  | 475 | MoleculeSelectionConstIterator endMoleculeSelection() const; | 
|---|
| [3839e5] | 476 |  | 
|---|
| [865a945] | 477 | protected: | 
|---|
| [fa0b18] | 478 | /**** | 
|---|
|  | 479 | * Iterators to use internal data structures | 
|---|
|  | 480 | * All these iterators are unobserved for speed reasons. | 
|---|
|  | 481 | * There is a corresponding public section to these methods, | 
|---|
|  | 482 | * which produce observed iterators.*/ | 
|---|
| [1c51c8] | 483 |  | 
|---|
|  | 484 | // Atoms | 
|---|
| [e3d865] | 485 | typedef SelectiveIterator<atom*,AtomSet::set_t,AtomDescriptor>        internal_AtomIterator; | 
|---|
| [865a945] | 486 |  | 
|---|
| [02ee15] | 487 | /** | 
|---|
|  | 488 | * returns an iterator over all Atoms matching a given descriptor. | 
|---|
|  | 489 | * used for internal purposes, like AtomProcesses and AtomCalculations. | 
|---|
|  | 490 | */ | 
|---|
| [fa0b18] | 491 | internal_AtomIterator getAtomIter_internal(AtomDescriptor descr); | 
|---|
| [02ee15] | 492 |  | 
|---|
|  | 493 | /** | 
|---|
| [d2dbac0] | 494 | * returns an iterator to the end of the AtomSet. Due to overloading this iterator | 
|---|
| [02ee15] | 495 | * can be compared to iterators produced by getAtomIter (see the mis-matching types). | 
|---|
|  | 496 | * Thus it can be used to detect when such an iterator is at the end of the list. | 
|---|
|  | 497 | * used for internal purposes, like AtomProcesses and AtomCalculations. | 
|---|
|  | 498 | */ | 
|---|
| [fa0b18] | 499 | internal_AtomIterator atomEnd_internal(); | 
|---|
| [865a945] | 500 |  | 
|---|
| [1c51c8] | 501 | // Molecules | 
|---|
| [e3d865] | 502 | typedef SelectiveIterator<molecule*,MoleculeSet::set_t,MoleculeDescriptor>   internal_MoleculeIterator; | 
|---|
| [51be2a] | 503 |  | 
|---|
| [1c51c8] | 504 |  | 
|---|
|  | 505 | /** | 
|---|
|  | 506 | * returns an iterator over all Molecules matching a given descriptor. | 
|---|
|  | 507 | * used for internal purposes, like MoleculeProcesses and MoleculeCalculations. | 
|---|
|  | 508 | */ | 
|---|
| [e3d865] | 509 | internal_MoleculeIterator getMoleculeIter_internal(MoleculeDescriptor descr); | 
|---|
| [1c51c8] | 510 |  | 
|---|
|  | 511 | /** | 
|---|
|  | 512 | * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator | 
|---|
|  | 513 | * can be compared to iterators produced by getMoleculeIter (see the mis-matching types). | 
|---|
|  | 514 | * Thus it can be used to detect when such an iterator is at the end of the list. | 
|---|
|  | 515 | * used for internal purposes, like MoleculeProcesses and MoleculeCalculations. | 
|---|
|  | 516 | */ | 
|---|
| [e3d865] | 517 | internal_MoleculeIterator moleculeEnd_internal(); | 
|---|
| [1c51c8] | 518 |  | 
|---|
|  | 519 |  | 
|---|
| [afb47f] | 520 | /******* Internal manipulation routines for double callback and Observer mechanism ******/ | 
|---|
| [ce7fdc] | 521 | void doManipulate(MoleCuilder::ManipulateAtomsProcess *); | 
|---|
| [afb47f] | 522 |  | 
|---|
| [5d1611] | 523 | private: | 
|---|
| [88d586] | 524 |  | 
|---|
| [7188b1] | 525 | friend const atom *detail::lastChanged<atom>(); | 
|---|
|  | 526 | friend const molecule *detail::lastChanged<molecule>(); | 
|---|
|  | 527 | static atom *_lastchangedatom; | 
|---|
| [fb95a5] | 528 | static atomId_t _lastchangedatomid; | 
|---|
| [7188b1] | 529 | static molecule*_lastchangedmol; | 
|---|
| [fb95a5] | 530 | static moleculeId_t _lastchangedmolid; | 
|---|
| [7188b1] | 531 |  | 
|---|
| [f71baf] | 532 | BondGraph *BG; | 
|---|
| [5d1611] | 533 | periodentafel *periode; | 
|---|
| [8e1f7af] | 534 | config *configuration; | 
|---|
| [98dbee] | 535 | HomologyContainer *homologies; | 
|---|
| [84c494] | 536 | Box *cell_size; | 
|---|
| [4834f4] | 537 | LinkedCell::LinkedCell_Controller *LCcontroller; | 
|---|
| [387b36] | 538 | std::string defaultName; | 
|---|
| [43dad6] | 539 | class ThermoStatContainer *Thermostats; | 
|---|
| [e4b5de] | 540 | int ExitFlag; | 
|---|
| [6e97e5] | 541 | private: | 
|---|
| [127a8e] | 542 |  | 
|---|
| [1a76a6] | 543 | AtomSet atoms; | 
|---|
| [90c4280] | 544 | AtomSet selectedAtoms; | 
|---|
| [c1d837] | 545 | typedef std::vector<atomId_t> atomIdsVector_t; | 
|---|
|  | 546 | std::stack<atomIdsVector_t> selectedAtoms_Stack; | 
|---|
| [127a8e] | 547 | /** | 
|---|
|  | 548 | * stores the pool for all available AtomIds below currAtomId | 
|---|
|  | 549 | * | 
|---|
|  | 550 | * The pool contains ranges of free ids in the form [bottom,top). | 
|---|
|  | 551 | */ | 
|---|
| [b97a60] | 552 | IdPool<atomId_t, uniqueId> atomIdPool; | 
|---|
| [127a8e] | 553 |  | 
|---|
| [d2dbac0] | 554 | MoleculeSet molecules; | 
|---|
| [90c4280] | 555 | MoleculeSet selectedMolecules; | 
|---|
| [c1d837] | 556 | typedef std::vector<moleculeId_t> moleculeIdsVector_t; | 
|---|
|  | 557 | std::stack<moleculeIdsVector_t> selectedMolecules_Stack; | 
|---|
| [1a76a6] | 558 | /** | 
|---|
|  | 559 | * stores the pool for all available AtomIds below currAtomId | 
|---|
|  | 560 | * | 
|---|
|  | 561 | * The pool contains ranges of free ids in the form [bottom,top). | 
|---|
|  | 562 | */ | 
|---|
| [b97a60] | 563 | IdPool<moleculeId_t, continuousId> moleculeIdPool; | 
|---|
| [3e4fb6] | 564 |  | 
|---|
| [5d1611] | 565 | private: | 
|---|
| [02ee15] | 566 | /** | 
|---|
|  | 567 | * private constructor to ensure creation of the world using | 
|---|
|  | 568 | * the singleton pattern. | 
|---|
|  | 569 | */ | 
|---|
| [5d1611] | 570 | World(); | 
|---|
| [02ee15] | 571 |  | 
|---|
|  | 572 | /** | 
|---|
|  | 573 | * private destructor to ensure destruction of the world using the | 
|---|
|  | 574 | * singleton pattern. | 
|---|
|  | 575 | */ | 
|---|
| [5d1611] | 576 | virtual ~World(); | 
|---|
|  | 577 |  | 
|---|
|  | 578 | /***** | 
|---|
|  | 579 | * some legacy stuff that is include for now but will be removed later | 
|---|
|  | 580 | *****/ | 
|---|
|  | 581 | public: | 
|---|
| [354859] | 582 | MoleculeListClass *&getMolecules(); | 
|---|
| [4d9c01] | 583 |  | 
|---|
| [5d1611] | 584 | private: | 
|---|
| [354859] | 585 | MoleculeListClass *molecules_deprecated; | 
|---|
| [5d1611] | 586 | }; | 
|---|
|  | 587 |  | 
|---|
| [7188b1] | 588 | /** Externalized stuff as member functions cannot be specialized without | 
|---|
|  | 589 | *  specializing the class, too. | 
|---|
|  | 590 | */ | 
|---|
|  | 591 | namespace detail { | 
|---|
|  | 592 | template <>       inline  const atom* lastChanged<atom>() { return World::_lastchangedatom; } | 
|---|
|  | 593 | template <>       inline  const molecule* lastChanged<molecule>() { return World::_lastchangedmol; } | 
|---|
|  | 594 | } | 
|---|
|  | 595 |  | 
|---|
|  | 596 |  | 
|---|
| [5d1611] | 597 | #endif /* WORLD_HPP_ */ | 
|---|