source: src/World.hpp@ 8e1f7af

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 8e1f7af was 8e1f7af, checked in by Frederik Heber <heber@…>, 15 years ago

class config added to World.

  • World now has the global configuration.
  • new function World::getConfig().
  • TextWindow::TextWindow() uses thr above to obtain the configuration.

Signed-off-by: Frederik Heber <heber@…>

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