source: src/World.hpp@ b54ac8

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 Candidate_v1.7.0 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 b54ac8 was b54ac8, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Added templates that allow arbitrary calculations on atoms to be mapped to sets of Atoms

  • Property mode set to 100644
File size: 3.7 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
[7c4e29]11#include <string>
[d346b6]12#include <map>
[fc1b24]13#include <vector>
[354859]14#include <set>
[7c4e29]15#include <boost/thread.hpp>
[865a945]16#include <boost/shared_ptr.hpp>
[5d1611]17
[7c4e29]18
[5d1611]19#include "Patterns/Observer.hpp"
20#include "Patterns/Cacheable.hpp"
21
22// forward declarations
23class periodentafel;
24class MoleculeListClass;
[4d9c01]25class atom;
[354859]26class molecule;
[fc1b24]27class AtomDescriptor;
[7a1ce5]28class AtomDescriptor_impl;
[7c4e29]29class ManipulateAtomsProcess;
[b54ac8]30template<typename T>
31class AtomsCalculation;
[5d1611]32
33class World : public Observable
34{
[b54ac8]35// necessary for coupling with descriptors
[7a1ce5]36friend class AtomDescriptor_impl;
[865a945]37friend class AtomDescriptor;
38
[b54ac8]39// Actions, calculations etc associated with the World
[7c4e29]40friend class ManipulateAtomsProcess;
[b54ac8]41template<typename> friend class AtomsCalculation;
[7c4e29]42
[865a945]43typedef std::map<int,atom*> AtomList;
[5d1611]44public:
45
46 /***** getter and setter *****/
[354859]47 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
48 periodentafel *&getPeriode();
[7a1ce5]49 atom* getAtom(AtomDescriptor descriptor);
50 std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
[b54ac8]51
52 template<typename T>
53 AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
54
[354859]55 int numAtoms();
56 int numMolecules();
57
58 /***** Methods to work with the World *****/
59 molecule *createMolecule();
[865a945]60
[7c4e29]61 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
62
[865a945]63protected:
64 /**** Iterators to use internal data structures */
65 class AtomIterator {
66 public:
[7c4e29]67 AtomIterator();
[865a945]68 AtomIterator(AtomDescriptor, World*);
69 AtomIterator(const AtomIterator&);
[7c4e29]70 AtomIterator& operator=(const AtomIterator&);
71 AtomIterator& operator++(); // prefix
72 AtomIterator operator++(int); // postfix with dummy parameter
[865a945]73 bool operator==(const AtomIterator&);
[7c4e29]74 bool operator==(const AtomList::iterator&);
[865a945]75 bool operator!=(const AtomIterator&);
[7c4e29]76 bool operator!=(const AtomList::iterator&);
[865a945]77 atom* operator*();
[7c4e29]78
79 int getCount();
[865a945]80 protected:
81 void advanceState();
82 World* world;
83 AtomList::iterator state;
84 boost::shared_ptr<AtomDescriptor_impl> descr;
[7c4e29]85 int index;
[865a945]86 };
87
88 AtomIterator getAtomIter(AtomDescriptor descr);
[7c4e29]89 AtomList::iterator atomEnd();
[865a945]90
[afb47f]91 /******* Internal manipulation routines for double callback and Observer mechanism ******/
92 void doManipulate(ManipulateAtomsProcess *);
93
[5d1611]94private:
95 periodentafel *periode;
[865a945]96 AtomList atoms;
[354859]97 std::set<molecule*> molecules;
[5d1611]98
99
100 /***** singleton Stuff *****/
101public:
102 static World* get();
103 static void destroy();
104 static World* reset();
105
106private:
107 World();
108 virtual ~World();
109
110 static World *theWorld;
111 // this mutex only saves the singleton pattern...
112 // use other mutexes to protect internal data as well
113 // this mutex handles access to the pointer, not to the object!!!
114 static boost::mutex worldLock;
115
116 /*****
117 * some legacy stuff that is include for now but will be removed later
118 *****/
119public:
[354859]120 MoleculeListClass *&getMolecules();
[4d9c01]121
122 // functions used for the WorldContent template mechanism
[d346b6]123 void registerAtom(atom *theAtom);
124 void unregisterAtom(atom *theAtom);
[5d1611]125private:
[354859]126 // this function cleans up anything that cannot be cleaned while the lock is active
127 // at a later point all these cleanups have to be moved to the World Class so the deadlock and
128 // race condition can both be avoided.
129 void destroyLegacy();
130
131 MoleculeListClass *molecules_deprecated;
[7a1ce5]132
133 // this is needed to assign unique IDs to atoms... so far
134 // IDs are not assigned upon Atom creation, so we cannot query the ID
135 // during construction. By using the dummy ID we can make sure all atoms
136 // are actually stored in the map and don't overwrite each other.
137 int dummyId;
[5d1611]138};
139
140#endif /* WORLD_HPP_ */
Note: See TracBrowser for help on using the repository browser.