source: src/World.hpp@ 61c364

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 61c364 was 61c364, checked in by Frederik Heber <heber@…>, 13 years ago

Added AtomOrderDescription along with SelectionAtomByOrder.

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