source: src/World.hpp@ 61d655e

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

Added methods for unselecting molecules and atoms

  • Property mode set to 100644
File size: 11.7 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
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 ObservedContainer<std::map<atomId_t,atom*> > AtomSet;
72 typedef ObservedContainer<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 can 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
239 typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
240
241 /**
242 * returns an iterator over all Molecules matching a given descriptor.
243 * This iterator is observed, so don't keep it around unnecessary to
244 * avoid unintended blocking.
245 */
246 MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
247 MoleculeIterator getMoleculeIter();
248
249 MoleculeIterator moleculeEnd();
250
251 /******** Selections of molecules and Atoms *************/
252 void clearAtomSelection();
253 void selectAtom(atom*);
254 void selectAtom(atomId_t);
255 void selectAllAtoms(AtomDescriptor);
256 void selectAtomsOfMolecule(molecule*);
257 void selectAtomsOfMolecule(moleculeId_t);
258 void unselectAtom(atom*);
259 void unselectAtom(atomId_t);
260 void unselectAllAtoms(AtomDescriptor);
261 void unselectAtomsOfMolecule(molecule*);
262 void unselectAtomsOfMolecule(moleculeId_t);
263
264 void clearMoleculeSelection();
265 void selectMolecule(molecule*);
266 void selectMolecule(moleculeId_t);
267 void selectAllMoleculess(MoleculeDescriptor);
268 void selectMoleculeOfAtom(atom*);
269 void selectMoleculeOfAtom(atomId_t);
270 void unselectMolecule(molecule*);
271 void unselectMolecule(moleculeId_t);
272 void unselectAllMoleculess(MoleculeDescriptor);
273 void unselectMoleculeOfAtom(atom*);
274 void unselectMoleculeOfAtom(atomId_t);
275
276protected:
277 /****
278 * Iterators to use internal data structures
279 * All these iterators are unobserved for speed reasons.
280 * There is a corresponding public section to these methods,
281 * which produce observed iterators.*/
282
283 // Atoms
284 typedef SelectiveIterator<atom*,AtomSet::set_t,AtomDescriptor> internal_AtomIterator;
285
286 /**
287 * returns an iterator over all Atoms matching a given descriptor.
288 * used for internal purposes, like AtomProcesses and AtomCalculations.
289 */
290 internal_AtomIterator getAtomIter_internal(AtomDescriptor descr);
291
292 /**
293 * returns an iterator to the end of the AtomSet. Due to overloading this iterator
294 * can be compared to iterators produced by getAtomIter (see the mis-matching types).
295 * Thus it can be used to detect when such an iterator is at the end of the list.
296 * used for internal purposes, like AtomProcesses and AtomCalculations.
297 */
298 internal_AtomIterator atomEnd_internal();
299
300 // Molecules
301 typedef SelectiveIterator<molecule*,MoleculeSet::set_t,MoleculeDescriptor> internal_MoleculeIterator;
302
303
304 /**
305 * returns an iterator over all Molecules matching a given descriptor.
306 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
307 */
308 internal_MoleculeIterator getMoleculeIter_internal(MoleculeDescriptor descr);
309
310 /**
311 * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
312 * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
313 * Thus it can be used to detect when such an iterator is at the end of the list.
314 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
315 */
316 internal_MoleculeIterator moleculeEnd_internal();
317
318
319 /******* Internal manipulation routines for double callback and Observer mechanism ******/
320 void doManipulate(ManipulateAtomsProcess *);
321
322private:
323
324 atomId_t getNextAtomId();
325 void releaseAtomId(atomId_t);
326 bool reserveAtomId(atomId_t);
327 void defragAtomIdPool();
328
329 moleculeId_t getNextMoleculeId();
330 void releaseMoleculeId(moleculeId_t);
331 bool reserveMoleculeId(moleculeId_t);
332 void defragMoleculeIdPool();
333
334 periodentafel *periode;
335 config *configuration;
336 Box *cell_size;
337 std::string defaultName;
338 class ThermoStatContainer *Thermostats;
339 int ExitFlag;
340private:
341
342 AtomSet atoms;
343 AtomSet selectedAtoms;
344 typedef std::set<std::pair<atomId_t, atomId_t> > atomIdPool_t;
345 /**
346 * stores the pool for all available AtomIds below currAtomId
347 *
348 * The pool contains ranges of free ids in the form [bottom,top).
349 */
350 atomIdPool_t atomIdPool;
351 atomId_t currAtomId; //!< stores the next available Id for atoms
352 size_t lastAtomPoolSize; //!< size of the pool after last defrag, to skip some defrags
353 unsigned int numAtomDefragSkips;
354
355 MoleculeSet molecules;
356 MoleculeSet selectedMolecules;
357 typedef std::set<std::pair<moleculeId_t, moleculeId_t> > moleculeIdPool_t;
358 /**
359 * stores the pool for all available AtomIds below currAtomId
360 *
361 * The pool contains ranges of free ids in the form [bottom,top).
362 */
363 moleculeIdPool_t moleculeIdPool;
364 moleculeId_t currMoleculeId;
365 size_t lastMoleculePoolSize; //!< size of the pool after last defrag, to skip some defrags
366 unsigned int numMoleculeDefragSkips;
367private:
368 /**
369 * private constructor to ensure creation of the world using
370 * the singleton pattern.
371 */
372 World();
373
374 /**
375 * private destructor to ensure destruction of the world using the
376 * singleton pattern.
377 */
378 virtual ~World();
379
380 /*****
381 * some legacy stuff that is include for now but will be removed later
382 *****/
383public:
384 MoleculeListClass *&getMolecules();
385
386private:
387 MoleculeListClass *molecules_deprecated;
388};
389
390#endif /* WORLD_HPP_ */
Note: See TracBrowser for help on using the repository browser.