source: src/World.hpp@ c88597

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

Made BondGraph an instance of World, removed from config.

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