source: src/World.hpp@ 6f0841

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 6f0841 was 6f0841, checked in by Frederik Heber <heber@…>, 13 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
Line 
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
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16/*********************************************** includes ***********************************/
17
18#include <string>
19#include <map>
20#include <vector>
21#include <set>
22#include <boost/thread.hpp>
23#include <boost/shared_ptr.hpp>
24
25#include "Actions/ActionTrait.hpp"
26#include "Atom/AtomSet.hpp"
27#include "Descriptors/SelectiveIterator.hpp"
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"
33#include "IdPool.hpp"
34#include "types.hpp"
35
36// forward declarations
37class atom;
38class AtomDescriptor;
39class AtomDescriptor_impl;
40class BondGraph;
41class Box;
42class config;
43class RealSpaceMatrix;
44class molecule;
45class MoleculeDescriptor;
46class MoleculeDescriptor_impl;
47class MoleculeListClass;
48class periodentafel;
49class ThermoStatContainer;
50
51namespace MoleCuilder {
52 class ManipulateAtomsProcess;
53 template<typename T> class AtomsCalculation;
54}
55
56/****************************************** forward declarations *****************************/
57
58/********************************************** Class World *******************************/
59
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
68class World : public Singleton<World>, public Observable
69{
70
71// Make access to constructor and destructor possible from inside the singleton
72friend class Singleton<World>;
73
74// necessary for coupling with descriptors
75friend class AtomDescriptor_impl;
76friend class AtomDescriptor;
77friend class MoleculeDescriptor_impl;
78friend class MoleculeDescriptor;
79// coupling with descriptors over selection
80friend class AtomSelectionDescriptor_impl;
81friend class MoleculeSelectionDescriptor_impl;
82
83// Actions, calculations etc associated with the World
84friend class MoleCuilder::ManipulateAtomsProcess;
85template<typename> friend class MoleCuilder::AtomsCalculation;
86public:
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;
90
91 // Types for Atom and Molecule structures
92 typedef ObservedContainer< AtomSTLSet > AtomSet;
93 typedef ObservedContainer< MoleculeSTLSet > MoleculeSet;
94
95 typedef ATOMSET(std::vector) AtomComposite;
96
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 *****/
115 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
116 /**
117 * returns the periodentafel for the world.
118 */
119 periodentafel *&getPeriode();
120
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);
132 /**
133 * returns the configuration for the world.
134 */
135 config *&getConfig();
136
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
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 */
148 atom* getAtom(AtomDescriptor descriptor);
149
150 /**
151 * returns a vector containing all atoms that match a given descriptor
152 */
153 AtomComposite getAllAtoms(AtomDescriptor descriptor);
154 AtomComposite getAllAtoms();
155
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 */
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);
163
164 /**
165 * get the number of atoms in the World
166 */
167 int numAtoms();
168
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);
179 std::vector<molecule*> getAllMolecules();
180
181 /**
182 * get the number of molecules in the World
183 */
184 int numMolecules();
185
186 /**
187 * get the domain size as a symmetric matrix (6 components)
188 */
189 Box& getDomain();
190
191 /**
192 * Set the domain size from a matrix object
193 *
194 * Matrix needs to be symmetric
195 */
196 void setDomain(const RealSpaceMatrix &mat);
197
198 /**
199 * set the domain size as a symmetric matrix (6 components)
200 */
201 void setDomain(double * matrix);
202
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
210 /**
211 * get the default name
212 */
213 std::string getDefaultName();
214
215 /**
216 * set the default name
217 */
218 void setDefaultName(std::string name);
219
220 /**
221 * get pointer to World's ThermoStatContainer
222 */
223 ThermoStatContainer * getThermostats();
224
225 /*
226 * get the ExitFlag
227 */
228 int getExitFlag();
229
230 /*
231 * set the ExitFlag
232 */
233 void setExitFlag(int flag);
234
235 /***** Methods to work with the World *****/
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 */
241 molecule *createMolecule();
242
243 void destroyMolecule(molecule*);
244 void destroyMolecule(moleculeId_t);
245
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 */
250 atom *createAtom();
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 */
256 int registerAtom(atom*);
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 */
262 void destroyAtom(atom*);
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 */
268 void destroyAtom(atomId_t);
269
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
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
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 */
290 MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
291 MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
292
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,
297 * which can be used internally when the extra speed is needed
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
312 typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
313
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 */
319 MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
320 MoleculeIterator getMoleculeIter();
321
322 MoleculeIterator moleculeEnd();
323
324 /******** Selections of molecules and Atoms *************/
325 void clearAtomSelection();
326 void selectAtom(const atom*);
327 void selectAtom(const atomId_t);
328 void selectAllAtoms(AtomDescriptor);
329 void selectAtomsOfMolecule(const molecule*);
330 void selectAtomsOfMolecule(const moleculeId_t);
331 void unselectAtom(const atom*);
332 void unselectAtom(const atomId_t);
333 void unselectAllAtoms(AtomDescriptor);
334 void unselectAtomsOfMolecule(const molecule*);
335 void unselectAtomsOfMolecule(const moleculeId_t);
336 size_t countSelectedAtoms() const;
337 bool isSelected(const atom *_atom) const;
338 bool isAtomSelected(const atomId_t no) const;
339 const std::vector<atom *> getSelectedAtoms() const;
340
341 void clearMoleculeSelection();
342 void selectMolecule(const molecule*);
343 void selectMolecule(const moleculeId_t);
344 void selectAllMolecules(MoleculeDescriptor);
345 void selectMoleculeOfAtom(const atom*);
346 void selectMoleculeOfAtom(const atomId_t);
347 void unselectMolecule(const molecule*);
348 void unselectMolecule(const moleculeId_t);
349 void unselectAllMolecules(MoleculeDescriptor);
350 void unselectMoleculeOfAtom(const atom*);
351 void unselectMoleculeOfAtom(const atomId_t);
352 size_t countSelectedMolecules() const;
353 bool isSelected(const molecule *_mol) const;
354 bool isMoleculeSelected(const moleculeId_t no) const;
355 const std::vector<molecule *> getSelectedMolecules() const;
356
357 /******************** Iterators to selections *****************/
358 typedef AtomSet::iterator AtomSelectionIterator;
359 AtomSelectionIterator beginAtomSelection();
360 AtomSelectionIterator endAtomSelection();
361 typedef AtomSet::const_iterator AtomSelectionConstIterator;
362 AtomSelectionConstIterator beginAtomSelection() const;
363 AtomSelectionConstIterator endAtomSelection() const;
364
365 typedef MoleculeSet::iterator MoleculeSelectionIterator;
366 MoleculeSelectionIterator beginMoleculeSelection();
367 MoleculeSelectionIterator endMoleculeSelection();
368 typedef MoleculeSet::const_iterator MoleculeSelectionConstIterator;
369 MoleculeSelectionConstIterator beginMoleculeSelection() const;
370 MoleculeSelectionConstIterator endMoleculeSelection() const;
371
372protected:
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.*/
378
379 // Atoms
380 typedef SelectiveIterator<atom*,AtomSet::set_t,AtomDescriptor> internal_AtomIterator;
381
382 /**
383 * returns an iterator over all Atoms matching a given descriptor.
384 * used for internal purposes, like AtomProcesses and AtomCalculations.
385 */
386 internal_AtomIterator getAtomIter_internal(AtomDescriptor descr);
387
388 /**
389 * returns an iterator to the end of the AtomSet. Due to overloading this iterator
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 */
394 internal_AtomIterator atomEnd_internal();
395
396 // Molecules
397 typedef SelectiveIterator<molecule*,MoleculeSet::set_t,MoleculeDescriptor> internal_MoleculeIterator;
398
399
400 /**
401 * returns an iterator over all Molecules matching a given descriptor.
402 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
403 */
404 internal_MoleculeIterator getMoleculeIter_internal(MoleculeDescriptor descr);
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 */
412 internal_MoleculeIterator moleculeEnd_internal();
413
414
415 /******* Internal manipulation routines for double callback and Observer mechanism ******/
416 void doManipulate(MoleCuilder::ManipulateAtomsProcess *);
417
418private:
419
420 atomId_t getNextAtomId();
421 void releaseAtomId(atomId_t);
422 bool reserveAtomId(atomId_t);
423 void defragAtomIdPool();
424
425 moleculeId_t getNextMoleculeId();
426 void releaseMoleculeId(moleculeId_t);
427 bool reserveMoleculeId(moleculeId_t);
428 void defragMoleculeIdPool();
429
430 friend const atom *detail::lastChanged<atom>();
431 friend const molecule *detail::lastChanged<molecule>();
432 static atom *_lastchangedatom;
433 static molecule*_lastchangedmol;
434
435 BondGraph *BG;
436 periodentafel *periode;
437 config *configuration;
438 Box *cell_size;
439 std::string defaultName;
440 class ThermoStatContainer *Thermostats;
441 int ExitFlag;
442private:
443
444 AtomSet atoms;
445 AtomSet selectedAtoms;
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 */
451 IdPool<atomId_t> atomIdPool;
452
453 MoleculeSet molecules;
454 MoleculeSet selectedMolecules;
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 */
460 IdPool<moleculeId_t> moleculeIdPool;
461
462private:
463 /**
464 * private constructor to ensure creation of the world using
465 * the singleton pattern.
466 */
467 World();
468
469 /**
470 * private destructor to ensure destruction of the world using the
471 * singleton pattern.
472 */
473 virtual ~World();
474
475 /*****
476 * some legacy stuff that is include for now but will be removed later
477 *****/
478public:
479 MoleculeListClass *&getMolecules();
480
481private:
482 MoleculeListClass *molecules_deprecated;
483};
484
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
494#endif /* WORLD_HPP_ */
Note: See TracBrowser for help on using the repository browser.