source: src/World.hpp@ e0f8c8

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 v1.1.4
Last change on this file since e0f8c8 was 38f991, checked in by Frederik Heber <heber@…>, 13 years ago

FormatParser now listens to World::AtomRemoved and ::AtomInserted notifications.

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