source: src/World.hpp@ 4d72e4

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 4d72e4 was 4d72e4, checked in by Tillmann Crueger <crueger@…>, 14 years ago

Made the World use the new mixin for sets of atoms

  • Property mode set to 100644
File size: 12.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/*********************************************** includes ***********************************/
12
13#include <string>
14#include <map>
15#include <vector>
16#include <set>
17#include <boost/thread.hpp>
18#include <boost/shared_ptr.hpp>
19
20#include "types.hpp"
21#include "Descriptors/SelectiveIterator.hpp"
22#include "Patterns/Observer.hpp"
23#include "Patterns/Cacheable.hpp"
24#include "Patterns/Singleton.hpp"
25#include "Patterns/ObservedContainer.hpp"
26#include "Helpers/Range.hpp"
27#include "AtomSet.hpp"
28
29// include config.h
30#ifdef HAVE_CONFIG_H
31#include <config.h>
32#endif
33
34// forward declarations
35class atom;
36class AtomDescriptor;
37class AtomDescriptor_impl;
38template<typename T> class AtomsCalculation;
39class Box;
40class config;
41class ManipulateAtomsProcess;
42class Matrix;
43class molecule;
44class MoleculeDescriptor;
45class MoleculeDescriptor_impl;
46class MoleculeListClass;
47class periodentafel;
48class ThermoStatContainer;
49
50
51/****************************************** forward declarations *****************************/
52
53/********************************************** Class World *******************************/
54
55class World : public Singleton<World>, public Observable
56{
57
58// Make access to constructor and destructor possible from inside the singleton
59friend class Singleton<World>;
60
61// necessary for coupling with descriptors
62friend class AtomDescriptor_impl;
63friend class AtomDescriptor;
64friend class MoleculeDescriptor_impl;
65friend class MoleculeDescriptor;
66// coupling with descriptors over selection
67friend class AtomSelectionDescriptor_impl;
68friend class MoleculeSelectionDescriptor_impl;
69
70// Actions, calculations etc associated with the World
71friend class ManipulateAtomsProcess;
72template<typename> friend class AtomsCalculation;
73public:
74
75 // Types for Atom and Molecule structures
76 typedef ObservedContainer<std::map<atomId_t,atom*> > AtomSet;
77 typedef ObservedContainer<std::map<moleculeId_t,molecule*> > MoleculeSet;
78
79 typedef ATOMSET(std::vector) AtomComposite;
80
81 /***** getter and setter *****/
82 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
83 /**
84 * returns the periodentafel for the world.
85 */
86 periodentafel *&getPeriode();
87
88 /**
89 * returns the configuration for the world.
90 */
91 config *&getConfig();
92
93 /**
94 * returns the first atom that matches a given descriptor.
95 * Do not rely on ordering for descriptors that match more than one atom.
96 */
97 atom* getAtom(AtomDescriptor descriptor);
98
99 /**
100 * returns a vector containing all atoms that match a given descriptor
101 */
102 AtomComposite getAllAtoms(AtomDescriptor descriptor);
103 AtomComposite getAllAtoms();
104
105 /**
106 * returns a calculation that calls a given function on all atoms matching a descriptor.
107 * the calculation is not called at this point and can be used as an action, i.e. be stored in
108 * menus, be kept around for later use etc.
109 */
110 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
111 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string);
112
113 /**
114 * get the number of atoms in the World
115 */
116 int numAtoms();
117
118 /**
119 * returns the first molecule that matches a given descriptor.
120 * Do not rely on ordering for descriptors that match more than one molecule.
121 */
122 molecule *getMolecule(MoleculeDescriptor descriptor);
123
124 /**
125 * returns a vector containing all molecules that match a given descriptor
126 */
127 std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor);
128 std::vector<molecule*> getAllMolecules();
129
130 /**
131 * get the number of molecules in the World
132 */
133 int numMolecules();
134
135 /**
136 * get the domain size as a symmetric matrix (6 components)
137 */
138 Box& getDomain();
139
140 /**
141 * Set the domain size from a matrix object
142 *
143 * Matrix needs to be symmetric
144 */
145 void setDomain(const Matrix &mat);
146
147 /**
148 * set the domain size as a symmetric matrix (6 components)
149 */
150 void setDomain(double * matrix);
151
152 /**
153 * get the default name
154 */
155 std::string getDefaultName();
156
157 /**
158 * set the default name
159 */
160 void setDefaultName(std::string name);
161
162 /**
163 * get pointer to World's ThermoStatContainer
164 */
165 ThermoStatContainer * getThermostats();
166
167 /*
168 * get the ExitFlag
169 */
170 int getExitFlag();
171
172 /*
173 * set the ExitFlag
174 */
175 void setExitFlag(int flag);
176
177 /***** Methods to work with the World *****/
178
179 /**
180 * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
181 * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
182 */
183 molecule *createMolecule();
184
185 void destroyMolecule(molecule*);
186 void destroyMolecule(moleculeId_t);
187
188 /**
189 * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
190 * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
191 */
192 atom *createAtom();
193
194 /**
195 * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
196 * Do not re-register Atoms already known to the world since this will cause double-frees.
197 */
198 int registerAtom(atom*);
199
200 /**
201 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
202 * atom directly since this will leave the pointer inside the world.
203 */
204 void destroyAtom(atom*);
205
206 /**
207 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
208 * atom directly since this will leave the pointer inside the world.
209 */
210 void destroyAtom(atomId_t);
211
212 /**
213 * used when changing an atom Id.
214 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
215 *
216 * Return value indicates wether the change could be done or not.
217 */
218 bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0);
219
220 /**
221 * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
222 * called at this time, so it can be passed around, stored inside menuItems etc.
223 */
224 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
225 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
226
227 /****
228 * Iterators to use internal data structures
229 * All these iterators are observed to track changes.
230 * There is a corresponding protected section with unobserved iterators,
231 * which can be used internally when the extra speed is needed
232 */
233
234 typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
235
236 /**
237 * returns an iterator over all Atoms matching a given descriptor.
238 * This iterator is observed, so don't keep it around unnecessary to
239 * avoid unintended blocking.
240 */
241 AtomIterator getAtomIter(AtomDescriptor descr);
242 AtomIterator getAtomIter();
243
244 AtomIterator atomEnd();
245
246 typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
247
248 /**
249 * returns an iterator over all Molecules matching a given descriptor.
250 * This iterator is observed, so don't keep it around unnecessary to
251 * avoid unintended blocking.
252 */
253 MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
254 MoleculeIterator getMoleculeIter();
255
256 MoleculeIterator moleculeEnd();
257
258 /******** Selections of molecules and Atoms *************/
259 void clearAtomSelection();
260 void selectAtom(atom*);
261 void selectAtom(atomId_t);
262 void selectAllAtoms(AtomDescriptor);
263 void selectAtomsOfMolecule(molecule*);
264 void selectAtomsOfMolecule(moleculeId_t);
265 void unselectAtom(atom*);
266 void unselectAtom(atomId_t);
267 void unselectAllAtoms(AtomDescriptor);
268 void unselectAtomsOfMolecule(molecule*);
269 void unselectAtomsOfMolecule(moleculeId_t);
270 size_t countSelectedAtoms() const;
271 bool isSelected(atom *_atom) const;
272 const std::vector<atom *> getSelectedAtoms() const;
273
274 void clearMoleculeSelection();
275 void selectMolecule(molecule*);
276 void selectMolecule(moleculeId_t);
277 void selectAllMolecules(MoleculeDescriptor);
278 void selectMoleculeOfAtom(atom*);
279 void selectMoleculeOfAtom(atomId_t);
280 void unselectMolecule(molecule*);
281 void unselectMolecule(moleculeId_t);
282 void unselectAllMolecules(MoleculeDescriptor);
283 void unselectMoleculeOfAtom(atom*);
284 void unselectMoleculeOfAtom(atomId_t);
285 size_t countSelectedMolecules() const;
286 bool isSelected(molecule *_mol) const;
287 const std::vector<molecule *> getSelectedMolecules() const;
288
289 /******************** Iterators to selections *****************/
290 typedef AtomSet::iterator AtomSelectionIterator;
291 AtomSelectionIterator beginAtomSelection();
292 AtomSelectionIterator endAtomSelection();
293
294 typedef MoleculeSet::iterator MoleculeSelectionIterator;
295 MoleculeSelectionIterator beginMoleculeSelection();
296 MoleculeSelectionIterator endMoleculeSelection();
297
298protected:
299 /****
300 * Iterators to use internal data structures
301 * All these iterators are unobserved for speed reasons.
302 * There is a corresponding public section to these methods,
303 * which produce observed iterators.*/
304
305 // Atoms
306 typedef SelectiveIterator<atom*,AtomSet::set_t,AtomDescriptor> internal_AtomIterator;
307
308 /**
309 * returns an iterator over all Atoms matching a given descriptor.
310 * used for internal purposes, like AtomProcesses and AtomCalculations.
311 */
312 internal_AtomIterator getAtomIter_internal(AtomDescriptor descr);
313
314 /**
315 * returns an iterator to the end of the AtomSet. Due to overloading this iterator
316 * can be compared to iterators produced by getAtomIter (see the mis-matching types).
317 * Thus it can be used to detect when such an iterator is at the end of the list.
318 * used for internal purposes, like AtomProcesses and AtomCalculations.
319 */
320 internal_AtomIterator atomEnd_internal();
321
322 // Molecules
323 typedef SelectiveIterator<molecule*,MoleculeSet::set_t,MoleculeDescriptor> internal_MoleculeIterator;
324
325
326 /**
327 * returns an iterator over all Molecules matching a given descriptor.
328 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
329 */
330 internal_MoleculeIterator getMoleculeIter_internal(MoleculeDescriptor descr);
331
332 /**
333 * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
334 * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
335 * Thus it can be used to detect when such an iterator is at the end of the list.
336 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
337 */
338 internal_MoleculeIterator moleculeEnd_internal();
339
340
341 /******* Internal manipulation routines for double callback and Observer mechanism ******/
342 void doManipulate(ManipulateAtomsProcess *);
343
344private:
345
346 atomId_t getNextAtomId();
347 void releaseAtomId(atomId_t);
348 bool reserveAtomId(atomId_t);
349 void defragAtomIdPool();
350
351 moleculeId_t getNextMoleculeId();
352 void releaseMoleculeId(moleculeId_t);
353 bool reserveMoleculeId(moleculeId_t);
354 void defragMoleculeIdPool();
355
356 periodentafel *periode;
357 config *configuration;
358 Box *cell_size;
359 std::string defaultName;
360 class ThermoStatContainer *Thermostats;
361 int ExitFlag;
362private:
363
364 AtomSet atoms;
365 AtomSet selectedAtoms;
366 typedef std::set<range<atomId_t> > atomIdPool_t;
367 /**
368 * stores the pool for all available AtomIds below currAtomId
369 *
370 * The pool contains ranges of free ids in the form [bottom,top).
371 */
372 atomIdPool_t atomIdPool;
373 atomId_t currAtomId; //!< stores the next available Id for atoms
374 size_t lastAtomPoolSize; //!< size of the pool after last defrag, to skip some defrags
375 unsigned int numAtomDefragSkips;
376
377 MoleculeSet molecules;
378 MoleculeSet selectedMolecules;
379 typedef std::set<range<atomId_t> > moleculeIdPool_t;
380 /**
381 * stores the pool for all available AtomIds below currAtomId
382 *
383 * The pool contains ranges of free ids in the form [bottom,top).
384 */
385 moleculeIdPool_t moleculeIdPool;
386 moleculeId_t currMoleculeId;
387 size_t lastMoleculePoolSize; //!< size of the pool after last defrag, to skip some defrags
388 unsigned int numMoleculeDefragSkips;
389private:
390 /**
391 * private constructor to ensure creation of the world using
392 * the singleton pattern.
393 */
394 World();
395
396 /**
397 * private destructor to ensure destruction of the world using the
398 * singleton pattern.
399 */
400 virtual ~World();
401
402 /*****
403 * some legacy stuff that is include for now but will be removed later
404 *****/
405public:
406 MoleculeListClass *&getMolecules();
407
408private:
409 MoleculeListClass *molecules_deprecated;
410};
411
412#endif /* WORLD_HPP_ */
Note: See TracBrowser for help on using the repository browser.