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