source: src/World.hpp@ e2373df

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 e2373df was d297a3, checked in by Frederik Heber <heber@…>, 14 years ago

World::setTime() is single access point to modifying WorldTime::CurrentTime.

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