source: src/World.hpp@ 97445f

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 97445f was 97445f, checked in by Frederik Heber <heber@…>, 9 years ago

World::getMolecules..() now has const versions as well.

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