source: src/World.hpp@ fa0b18

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

Added Observed and Selectiv iterators over internal Structures of the World.

  • Property mode set to 100644
File size: 9.4 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 "AtomSet.hpp"
26
27// include config.h
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32// forward declarations
33class atom;
34class AtomDescriptor;
35class AtomDescriptor_impl;
36template<typename T> class AtomsCalculation;
37class Box;
38class config;
39class ManipulateAtomsProcess;
40class Matrix;
41class molecule;
42class MoleculeDescriptor;
43class MoleculeDescriptor_impl;
44class MoleculeListClass;
45class periodentafel;
46class ThermoStatContainer;
47
48
49/****************************************** forward declarations *****************************/
50
51/********************************************** Class World *******************************/
52
53class World : public Singleton<World>, public Observable
54{
55
56// Make access to constructor and destructor possible from inside the singleton
57friend class Singleton<World>;
58
59// necessary for coupling with descriptors
60friend class AtomDescriptor_impl;
61friend class AtomDescriptor;
62friend class MoleculeDescriptor_impl;
63friend class MoleculeDescriptor;
64
65// Actions, calculations etc associated with the World
66friend class ManipulateAtomsProcess;
67template<typename> friend class AtomsCalculation;
68public:
69
70 // Types for Atom and Molecule structures
71 typedef _AtomSet AtomSet;
72 typedef std::map<moleculeId_t,molecule*> MoleculeSet;
73
74 /***** getter and setter *****/
75 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
76 /**
77 * returns the periodentafel for the world.
78 */
79 periodentafel *&getPeriode();
80
81 /**
82 * returns the configuration for the world.
83 */
84 config *&getConfig();
85
86 /**
87 * returns the first atom that matches a given descriptor.
88 * Do not rely on ordering for descriptors that match more than one atom.
89 */
90 atom* getAtom(AtomDescriptor descriptor);
91
92 /**
93 * returns a vector containing all atoms that match a given descriptor
94 */
95 std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
96 std::vector<atom*> getAllAtoms();
97
98 /**
99 * returns a calculation that calls a given function on all atoms matching a descriptor.
100 * the calculation is not called at this point and can be used as an action, i.e. be stored in
101 * menus, be kept around for later use etc.
102 */
103 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
104 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string);
105
106 /**
107 * get the number of atoms in the World
108 */
109 int numAtoms();
110
111 /**
112 * returns the first molecule that matches a given descriptor.
113 * Do not rely on ordering for descriptors that match more than one molecule.
114 */
115 molecule *getMolecule(MoleculeDescriptor descriptor);
116
117 /**
118 * returns a vector containing all molecules that match a given descriptor
119 */
120 std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor);
121 std::vector<molecule*> getAllMolecules();
122
123 /**
124 * get the number of molecules in the World
125 */
126 int numMolecules();
127
128 /**
129 * get the domain size as a symmetric matrix (6 components)
130 */
131 Box& getDomain();
132
133 /**
134 * Set the domain size from a matrix object
135 *
136 * Matrix needs to be symmetric
137 */
138 void setDomain(const Matrix &mat);
139
140 /**
141 * set the domain size as a symmetric matrix (6 components)
142 */
143 void setDomain(double * matrix);
144
145 /**
146 * get the default name
147 */
148 std::string getDefaultName();
149
150 /**
151 * set the default name
152 */
153 void setDefaultName(std::string name);
154
155 /**
156 * get pointer to World's ThermoStatContainer
157 */
158 ThermoStatContainer * getThermostats();
159
160 /*
161 * get the ExitFlag
162 */
163 int getExitFlag();
164
165 /*
166 * set the ExitFlag
167 */
168 void setExitFlag(int flag);
169
170 /***** Methods to work with the World *****/
171
172 /**
173 * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
174 * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
175 */
176 molecule *createMolecule();
177
178 void destroyMolecule(molecule*);
179 void destroyMolecule(moleculeId_t);
180
181 /**
182 * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
183 * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
184 */
185 atom *createAtom();
186
187 /**
188 * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
189 * Do not re-register Atoms already known to the world since this will cause double-frees.
190 */
191 int registerAtom(atom*);
192
193 /**
194 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
195 * atom directly since this will leave the pointer inside the world.
196 */
197 void destroyAtom(atom*);
198
199 /**
200 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
201 * atom directly since this will leave the pointer inside the world.
202 */
203 void destroyAtom(atomId_t);
204
205 /**
206 * used when changing an atom Id.
207 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
208 *
209 * Return value indicates wether the change could be done or not.
210 */
211 bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0);
212
213 /**
214 * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
215 * called at this time, so it can be passed around, stored inside menuItems etc.
216 */
217 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
218 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
219
220 /****
221 * Iterators to use internal data structures
222 * All these iterators are observed to track changes.
223 * There is a corresponding protected section with unobserved iterators,
224 * which ca be used internally when the extra speed is needed
225 */
226
227 typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
228
229 /**
230 * returns an iterator over all Atoms matching a given descriptor.
231 * This iterator is observed, so don't keep it around unnecessary to
232 * avoid unintended blocking.
233 */
234 AtomIterator getAtomIter(AtomDescriptor descr);
235 AtomIterator getAtomIter();
236
237 AtomIterator atomEnd();
238
239protected:
240 /****
241 * Iterators to use internal data structures
242 * All these iterators are unobserved for speed reasons.
243 * There is a corresponding public section to these methods,
244 * which produce observed iterators.*/
245
246 // Atoms
247 typedef AtomSet::selective_internal_iterator internal_AtomIterator;
248
249 /**
250 * returns an iterator over all Atoms matching a given descriptor.
251 * used for internal purposes, like AtomProcesses and AtomCalculations.
252 */
253 internal_AtomIterator getAtomIter_internal(AtomDescriptor descr);
254
255 /**
256 * returns an iterator to the end of the AtomSet. Due to overloading this iterator
257 * can be compared to iterators produced by getAtomIter (see the mis-matching types).
258 * Thus it can be used to detect when such an iterator is at the end of the list.
259 * used for internal purposes, like AtomProcesses and AtomCalculations.
260 */
261 internal_AtomIterator atomEnd_internal();
262
263 // Molecules
264
265 typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
266
267 /**
268 * returns an iterator over all Molecules matching a given descriptor.
269 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
270 */
271 MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
272
273 /**
274 * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
275 * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
276 * Thus it can be used to detect when such an iterator is at the end of the list.
277 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
278 */
279 MoleculeIterator moleculeEnd();
280
281
282 /******* Internal manipulation routines for double callback and Observer mechanism ******/
283 void doManipulate(ManipulateAtomsProcess *);
284
285private:
286
287 atomId_t getNextAtomId();
288 void releaseAtomId(atomId_t);
289 bool reserveAtomId(atomId_t);
290
291 periodentafel *periode;
292 config *configuration;
293 Box *cell_size;
294 std::string defaultName;
295 class ThermoStatContainer *Thermostats;
296 int ExitFlag;
297public:
298 AtomSet atoms;
299private:
300 std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
301 atomId_t currAtomId; //!< stores the next available Id for atoms
302 MoleculeSet molecules;
303 moleculeId_t currMoleculeId;
304private:
305 /**
306 * private constructor to ensure creation of the world using
307 * the singleton pattern.
308 */
309 World();
310
311 /**
312 * private destructor to ensure destruction of the world using the
313 * singleton pattern.
314 */
315 virtual ~World();
316
317 /*****
318 * some legacy stuff that is include for now but will be removed later
319 *****/
320public:
321 MoleculeListClass *&getMolecules();
322
323private:
324 MoleculeListClass *molecules_deprecated;
325};
326
327#endif /* WORLD_HPP_ */
Note: See TracBrowser for help on using the repository browser.