source: src/World.hpp@ 71d81a

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 71d81a was 6f0841, checked in by Frederik Heber <heber@…>, 14 years ago

Shifted all modules related to atoms into own subfolder src/Atom/

  • also created own convenience library for this. This makes unit testing on list containing TesselPoint or atom a lot easier.
  • shifted TesselPoint to src/Atom from src/Tesselation and adapted include's.
  • Property mode set to 100644
File size: 15.1 KB
RevLine 
[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>
[7c4e29]22#include <boost/thread.hpp>
[865a945]23#include <boost/shared_ptr.hpp>
[5d1611]24
[3139b2]25#include "Actions/ActionTrait.hpp"
[6f0841]26#include "Atom/AtomSet.hpp"
[6e97e5]27#include "Descriptors/SelectiveIterator.hpp"
[ad011c]28#include "CodePatterns/Observer.hpp"
29#include "CodePatterns/Cacheable.hpp"
30#include "CodePatterns/Singleton.hpp"
31#include "CodePatterns/ObservedContainer.hpp"
32#include "CodePatterns/Range.hpp"
[3e4fb6]33#include "IdPool.hpp"
34#include "types.hpp"
[5d1611]35
36// forward declarations
[4d9c01]37class atom;
[fc1b24]38class AtomDescriptor;
[7a1ce5]39class AtomDescriptor_impl;
[f71baf]40class BondGraph;
[84c494]41class Box;
[43dad6]42class config;
[cca9ef]43class RealSpaceMatrix;
[43dad6]44class molecule;
[1c51c8]45class MoleculeDescriptor;
46class MoleculeDescriptor_impl;
[43dad6]47class MoleculeListClass;
48class periodentafel;
49class ThermoStatContainer;
[5d1611]50
[ce7fdc]51namespace MoleCuilder {
52 class ManipulateAtomsProcess;
53 template<typename T> class AtomsCalculation;
54}
[fa0b18]55
[b34306]56/****************************************** forward declarations *****************************/
[23b547]57
[b34306]58/********************************************** Class World *******************************/
[23b547]59
[7188b1]60namespace detail {
61 template <class T> const T* lastChanged()
62 {
63 ASSERT(0, "detail::lastChanged() - only specializations may be used.");
64 return NULL;
65 }
66}
67
[23b547]68class World : public Singleton<World>, public Observable
[5d1611]69{
[23b547]70
71// Make access to constructor and destructor possible from inside the singleton
72friend class Singleton<World>;
73
[b54ac8]74// necessary for coupling with descriptors
[7a1ce5]75friend class AtomDescriptor_impl;
[865a945]76friend class AtomDescriptor;
[1c51c8]77friend class MoleculeDescriptor_impl;
78friend class MoleculeDescriptor;
[41aa39]79// coupling with descriptors over selection
80friend class AtomSelectionDescriptor_impl;
[cf0ca1]81friend class MoleculeSelectionDescriptor_impl;
[865a945]82
[b54ac8]83// Actions, calculations etc associated with the World
[ce7fdc]84friend class MoleCuilder::ManipulateAtomsProcess;
85template<typename> friend class MoleCuilder::AtomsCalculation;
[5d1611]86public:
[5f1d5b8]87 // some typedefs for the CONSTRUCT_... macros (no "," allows in a single parameter name)
88 typedef std::map<atomId_t,atom*> AtomSTLSet;
89 typedef std::map<moleculeId_t,molecule*> MoleculeSTLSet;
[23b547]90
91 // Types for Atom and Molecule structures
[5f1d5b8]92 typedef ObservedContainer< AtomSTLSet > AtomSet;
93 typedef ObservedContainer< MoleculeSTLSet > MoleculeSet;
[5d1611]94
[4d72e4]95 typedef ATOMSET(std::vector) AtomComposite;
96
[7188b1]97 /******* Notifications *******/
98
99 //!> enumeration of present notification types
100 enum NotificationType {
101 AtomInserted,
102 AtomRemoved,
103 AtomChanged,
104 MoleculeInserted,
105 MoleculeRemoved,
106 MoleculeChanged,
107 NotificationType_MAX
108 };
109
110 //>! access to last changed element (atom or molecule)
111 template <class T> const T* lastChanged() const
112 { return detail::lastChanged<T>(); }
113
114 /***** getter and setter *****/
[354859]115 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
[02ee15]116 /**
117 * returns the periodentafel for the world.
118 */
[354859]119 periodentafel *&getPeriode();
[02ee15]120
[f71baf]121 /** Returns the BondGraph for the World.
122 *
123 * @return reference to BondGraph
124 */
125 BondGraph *&getBondGraph();
126
127 /** Sets the World's BondGraph.
128 *
129 * @param _BG new BondGraph
130 */
131 void setBondGraph(BondGraph *_BG);
[8e1f7af]132 /**
133 * returns the configuration for the world.
134 */
135 config *&getConfig();
136
[7188b1]137 /** Returns a notification_ptr for a specific type.
138 *
139 * @param type request type
140 * @return reference to instance
141 */
142 Notification_ptr getNotification(enum NotificationType type) const;
143
[02ee15]144 /**
145 * returns the first atom that matches a given descriptor.
146 * Do not rely on ordering for descriptors that match more than one atom.
147 */
[7a1ce5]148 atom* getAtom(AtomDescriptor descriptor);
[02ee15]149
150 /**
151 * returns a vector containing all atoms that match a given descriptor
152 */
[4d72e4]153 AtomComposite getAllAtoms(AtomDescriptor descriptor);
154 AtomComposite getAllAtoms();
[b54ac8]155
[02ee15]156 /**
157 * returns a calculation that calls a given function on all atoms matching a descriptor.
158 * the calculation is not called at this point and can be used as an action, i.e. be stored in
159 * menus, be kept around for later use etc.
160 */
[3139b2]161 template<typename T> MoleCuilder::AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,const MoleCuilder::ActionTrait &_trait,AtomDescriptor);
162 template<typename T> MoleCuilder::AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,const MoleCuilder::ActionTrait &_trait);
[b54ac8]163
[02ee15]164 /**
165 * get the number of atoms in the World
166 */
[354859]167 int numAtoms();
[02ee15]168
[1c51c8]169 /**
170 * returns the first molecule that matches a given descriptor.
171 * Do not rely on ordering for descriptors that match more than one molecule.
172 */
173 molecule *getMolecule(MoleculeDescriptor descriptor);
174
175 /**
176 * returns a vector containing all molecules that match a given descriptor
177 */
178 std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor);
[97ebf8]179 std::vector<molecule*> getAllMolecules();
[1c51c8]180
[02ee15]181 /**
182 * get the number of molecules in the World
183 */
[354859]184 int numMolecules();
185
[5f612ee]186 /**
187 * get the domain size as a symmetric matrix (6 components)
188 */
[84c494]189 Box& getDomain();
190
191 /**
192 * Set the domain size from a matrix object
193 *
194 * Matrix needs to be symmetric
195 */
[cca9ef]196 void setDomain(const RealSpaceMatrix &mat);
[5f612ee]197
198 /**
199 * set the domain size as a symmetric matrix (6 components)
200 */
201 void setDomain(double * matrix);
202
[d297a3]203 /**
204 * set the current time of the world.
205 *
206 * @param _step time step to set to
207 */
208 void setTime(const unsigned int _step);
209
[5f612ee]210 /**
211 * get the default name
212 */
[387b36]213 std::string getDefaultName();
[5f612ee]214
215 /**
216 * set the default name
217 */
[387b36]218 void setDefaultName(std::string name);
[5f612ee]219
[43dad6]220 /**
221 * get pointer to World's ThermoStatContainer
222 */
223 ThermoStatContainer * getThermostats();
224
[e4b5de]225 /*
226 * get the ExitFlag
227 */
228 int getExitFlag();
229
230 /*
231 * set the ExitFlag
232 */
233 void setExitFlag(int flag);
234
[354859]235 /***** Methods to work with the World *****/
[02ee15]236
237 /**
238 * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
239 * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
240 */
[354859]241 molecule *createMolecule();
[02ee15]242
[cbc5fb]243 void destroyMolecule(molecule*);
244 void destroyMolecule(moleculeId_t);
245
[02ee15]246 /**
247 * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
248 * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
249 */
[46d958]250 atom *createAtom();
[02ee15]251
252 /**
253 * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
254 * Do not re-register Atoms already known to the world since this will cause double-frees.
255 */
[46d958]256 int registerAtom(atom*);
[02ee15]257
258 /**
259 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
260 * atom directly since this will leave the pointer inside the world.
261 */
[46d958]262 void destroyAtom(atom*);
[02ee15]263
264 /**
265 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
266 * atom directly since this will leave the pointer inside the world.
267 */
[cbc5fb]268 void destroyAtom(atomId_t);
[865a945]269
[88d586]270 /**
271 * used when changing an atom Id.
272 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
273 *
274 * Return value indicates wether the change could be done or not.
275 */
276 bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0);
277
[a7a087]278 /**
279 * used when changing an molecule Id.
280 * Unless you are calling this method from inside an moleucle don't fiddle with the third parameter.
281 *
282 * Return value indicates wether the change could be done or not.
283 */
284 bool changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target=0);
285
[02ee15]286 /**
287 * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
288 * called at this time, so it can be passed around, stored inside menuItems etc.
289 */
[ce7fdc]290 MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
291 MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
[7c4e29]292
[fa0b18]293 /****
294 * Iterators to use internal data structures
295 * All these iterators are observed to track changes.
296 * There is a corresponding protected section with unobserved iterators,
[90c4280]297 * which can be used internally when the extra speed is needed
[fa0b18]298 */
299
300 typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
301
302 /**
303 * returns an iterator over all Atoms matching a given descriptor.
304 * This iterator is observed, so don't keep it around unnecessary to
305 * avoid unintended blocking.
306 */
307 AtomIterator getAtomIter(AtomDescriptor descr);
308 AtomIterator getAtomIter();
309
310 AtomIterator atomEnd();
311
[e3d865]312 typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
[51be2a]313
[90c4280]314 /**
315 * returns an iterator over all Molecules matching a given descriptor.
316 * This iterator is observed, so don't keep it around unnecessary to
317 * avoid unintended blocking.
318 */
[5d880e]319 MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
320 MoleculeIterator getMoleculeIter();
321
322 MoleculeIterator moleculeEnd();
323
[90c4280]324 /******** Selections of molecules and Atoms *************/
325 void clearAtomSelection();
[e4afb4]326 void selectAtom(const atom*);
327 void selectAtom(const atomId_t);
[90c4280]328 void selectAllAtoms(AtomDescriptor);
[e4afb4]329 void selectAtomsOfMolecule(const molecule*);
330 void selectAtomsOfMolecule(const moleculeId_t);
331 void unselectAtom(const atom*);
332 void unselectAtom(const atomId_t);
[61d655e]333 void unselectAllAtoms(AtomDescriptor);
[e4afb4]334 void unselectAtomsOfMolecule(const molecule*);
335 void unselectAtomsOfMolecule(const moleculeId_t);
[e472eab]336 size_t countSelectedAtoms() const;
[e4afb4]337 bool isSelected(const atom *_atom) const;
[89643d]338 bool isAtomSelected(const atomId_t no) const;
[e472eab]339 const std::vector<atom *> getSelectedAtoms() const;
[90c4280]340
341 void clearMoleculeSelection();
[e4afb4]342 void selectMolecule(const molecule*);
343 void selectMolecule(const moleculeId_t);
[e472eab]344 void selectAllMolecules(MoleculeDescriptor);
[e4afb4]345 void selectMoleculeOfAtom(const atom*);
346 void selectMoleculeOfAtom(const atomId_t);
347 void unselectMolecule(const molecule*);
348 void unselectMolecule(const moleculeId_t);
[e472eab]349 void unselectAllMolecules(MoleculeDescriptor);
[e4afb4]350 void unselectMoleculeOfAtom(const atom*);
351 void unselectMoleculeOfAtom(const atomId_t);
[e472eab]352 size_t countSelectedMolecules() const;
[e4afb4]353 bool isSelected(const molecule *_mol) const;
[89643d]354 bool isMoleculeSelected(const moleculeId_t no) const;
[e472eab]355 const std::vector<molecule *> getSelectedMolecules() const;
[90c4280]356
[3839e5]357 /******************** Iterators to selections *****************/
358 typedef AtomSet::iterator AtomSelectionIterator;
359 AtomSelectionIterator beginAtomSelection();
360 AtomSelectionIterator endAtomSelection();
[38f991]361 typedef AtomSet::const_iterator AtomSelectionConstIterator;
362 AtomSelectionConstIterator beginAtomSelection() const;
363 AtomSelectionConstIterator endAtomSelection() const;
[3839e5]364
365 typedef MoleculeSet::iterator MoleculeSelectionIterator;
366 MoleculeSelectionIterator beginMoleculeSelection();
367 MoleculeSelectionIterator endMoleculeSelection();
[38f991]368 typedef MoleculeSet::const_iterator MoleculeSelectionConstIterator;
369 MoleculeSelectionConstIterator beginMoleculeSelection() const;
370 MoleculeSelectionConstIterator endMoleculeSelection() const;
[3839e5]371
[865a945]372protected:
[fa0b18]373 /****
374 * Iterators to use internal data structures
375 * All these iterators are unobserved for speed reasons.
376 * There is a corresponding public section to these methods,
377 * which produce observed iterators.*/
[1c51c8]378
379 // Atoms
[e3d865]380 typedef SelectiveIterator<atom*,AtomSet::set_t,AtomDescriptor> internal_AtomIterator;
[865a945]381
[02ee15]382 /**
383 * returns an iterator over all Atoms matching a given descriptor.
384 * used for internal purposes, like AtomProcesses and AtomCalculations.
385 */
[fa0b18]386 internal_AtomIterator getAtomIter_internal(AtomDescriptor descr);
[02ee15]387
388 /**
[d2dbac0]389 * returns an iterator to the end of the AtomSet. Due to overloading this iterator
[02ee15]390 * can be compared to iterators produced by getAtomIter (see the mis-matching types).
391 * Thus it can be used to detect when such an iterator is at the end of the list.
392 * used for internal purposes, like AtomProcesses and AtomCalculations.
393 */
[fa0b18]394 internal_AtomIterator atomEnd_internal();
[865a945]395
[1c51c8]396 // Molecules
[e3d865]397 typedef SelectiveIterator<molecule*,MoleculeSet::set_t,MoleculeDescriptor> internal_MoleculeIterator;
[51be2a]398
[1c51c8]399
400 /**
401 * returns an iterator over all Molecules matching a given descriptor.
402 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
403 */
[e3d865]404 internal_MoleculeIterator getMoleculeIter_internal(MoleculeDescriptor descr);
[1c51c8]405
406 /**
407 * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
408 * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
409 * Thus it can be used to detect when such an iterator is at the end of the list.
410 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
411 */
[e3d865]412 internal_MoleculeIterator moleculeEnd_internal();
[1c51c8]413
414
[afb47f]415 /******* Internal manipulation routines for double callback and Observer mechanism ******/
[ce7fdc]416 void doManipulate(MoleCuilder::ManipulateAtomsProcess *);
[afb47f]417
[5d1611]418private:
[88d586]419
420 atomId_t getNextAtomId();
421 void releaseAtomId(atomId_t);
422 bool reserveAtomId(atomId_t);
[127a8e]423 void defragAtomIdPool();
424
425 moleculeId_t getNextMoleculeId();
426 void releaseMoleculeId(moleculeId_t);
427 bool reserveMoleculeId(moleculeId_t);
428 void defragMoleculeIdPool();
[88d586]429
[7188b1]430 friend const atom *detail::lastChanged<atom>();
431 friend const molecule *detail::lastChanged<molecule>();
432 static atom *_lastchangedatom;
433 static molecule*_lastchangedmol;
434
[f71baf]435 BondGraph *BG;
[5d1611]436 periodentafel *periode;
[8e1f7af]437 config *configuration;
[84c494]438 Box *cell_size;
[387b36]439 std::string defaultName;
[43dad6]440 class ThermoStatContainer *Thermostats;
[e4b5de]441 int ExitFlag;
[6e97e5]442private:
[127a8e]443
[1a76a6]444 AtomSet atoms;
[90c4280]445 AtomSet selectedAtoms;
[127a8e]446 /**
447 * stores the pool for all available AtomIds below currAtomId
448 *
449 * The pool contains ranges of free ids in the form [bottom,top).
450 */
[3e4fb6]451 IdPool<atomId_t> atomIdPool;
[127a8e]452
[d2dbac0]453 MoleculeSet molecules;
[90c4280]454 MoleculeSet selectedMolecules;
[1a76a6]455 /**
456 * stores the pool for all available AtomIds below currAtomId
457 *
458 * The pool contains ranges of free ids in the form [bottom,top).
459 */
[3e4fb6]460 IdPool<moleculeId_t> moleculeIdPool;
461
[5d1611]462private:
[02ee15]463 /**
464 * private constructor to ensure creation of the world using
465 * the singleton pattern.
466 */
[5d1611]467 World();
[02ee15]468
469 /**
470 * private destructor to ensure destruction of the world using the
471 * singleton pattern.
472 */
[5d1611]473 virtual ~World();
474
475 /*****
476 * some legacy stuff that is include for now but will be removed later
477 *****/
478public:
[354859]479 MoleculeListClass *&getMolecules();
[4d9c01]480
[5d1611]481private:
[354859]482 MoleculeListClass *molecules_deprecated;
[5d1611]483};
484
[7188b1]485/** Externalized stuff as member functions cannot be specialized without
486 * specializing the class, too.
487 */
488namespace detail {
489 template <> inline const atom* lastChanged<atom>() { return World::_lastchangedatom; }
490 template <> inline const molecule* lastChanged<molecule>() { return World::_lastchangedmol; }
491}
492
493
[5d1611]494#endif /* WORLD_HPP_ */
Note: See TracBrowser for help on using the repository browser.