source: src/World.hpp@ b80021

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 b80021 was 43dad6, checked in by Frederik Heber <heber@…>, 15 years ago

Introducing (but not yet incorporated) FormatParser specializations for MPQC and PCP config files.

  • new modules MpqcParser.[ch]pp and PcpParser.[ch]pp.
  • class MpqcParser:
    • just a skeleton so far
  • class PcpParser:
    • load and save basically adapted from config::Load and config::Save.
    • new functions OutputAtoms() and OutputElements() from molecule::Output() and molecule::CheckOut().
    • ne function ParseThermostats() - as the parsing is specific to the format it should be handled by the FormatParser, not bz ThermoStatContainer.
    • most of the variables from config placed into struct to put them into groups (for later splitting up load&save into subfunctions).
  • new overload ConfigFileBuffer::InitFileBuffer() accepting streams (FormatParser works on streams, config still with filenames).
  • World: new member Thermostats which contains all thermostat parameters with getter function.
  • ThermoStatContainer::ParseThermostats() moved over to PcpParser and re-introduced in config.
  • atom::OutputArrayIndexed() now works on ostream, not ofstream.
  • molecule::Output() adapted to ostream change.
  • Property mode set to 100644
File size: 8.5 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"
[6e97e5]21#include "Descriptors/SelectiveIterator.hpp"
[5d1611]22#include "Patterns/Observer.hpp"
23#include "Patterns/Cacheable.hpp"
[23b547]24#include "Patterns/Singleton.hpp"
25
[b34306]26// include config.h
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
[5d1611]30
31// forward declarations
[4d9c01]32class atom;
[fc1b24]33class AtomDescriptor;
[7a1ce5]34class AtomDescriptor_impl;
[43dad6]35template<typename T> class AtomsCalculation;
36class config;
37class ManipulateAtomsProcess;
38class molecule;
[1c51c8]39class MoleculeDescriptor;
40class MoleculeDescriptor_impl;
[43dad6]41class MoleculeListClass;
42class periodentafel;
43class ThermoStatContainer;
[5d1611]44
[b34306]45/****************************************** forward declarations *****************************/
[23b547]46
[b34306]47/********************************************** Class World *******************************/
[23b547]48
49class World : public Singleton<World>, public Observable
[5d1611]50{
[23b547]51
52// Make access to constructor and destructor possible from inside the singleton
53friend class Singleton<World>;
54
[b54ac8]55// necessary for coupling with descriptors
[7a1ce5]56friend class AtomDescriptor_impl;
[865a945]57friend class AtomDescriptor;
[1c51c8]58friend class MoleculeDescriptor_impl;
59friend class MoleculeDescriptor;
[865a945]60
[b54ac8]61// Actions, calculations etc associated with the World
[7c4e29]62friend class ManipulateAtomsProcess;
[b54ac8]63template<typename> friend class AtomsCalculation;
[5d1611]64public:
[23b547]65
66 // Types for Atom and Molecule structures
[7042f45]67 typedef std::map<atomId_t,atom*> AtomSet;
68 typedef std::map<moleculeId_t,molecule*> MoleculeSet;
[5d1611]69
70 /***** getter and setter *****/
[354859]71 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
[02ee15]72 /**
73 * returns the periodentafel for the world.
74 */
[354859]75 periodentafel *&getPeriode();
[02ee15]76
[8e1f7af]77 /**
78 * returns the configuration for the world.
79 */
80 config *&getConfig();
81
[02ee15]82 /**
83 * returns the first atom that matches a given descriptor.
84 * Do not rely on ordering for descriptors that match more than one atom.
85 */
[7a1ce5]86 atom* getAtom(AtomDescriptor descriptor);
[02ee15]87
88 /**
89 * returns a vector containing all atoms that match a given descriptor
90 */
[7a1ce5]91 std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
[0e2a47]92 std::vector<atom*> getAllAtoms();
[b54ac8]93
[02ee15]94 /**
95 * returns a calculation that calls a given function on all atoms matching a descriptor.
96 * the calculation is not called at this point and can be used as an action, i.e. be stored in
97 * menus, be kept around for later use etc.
98 */
[0e2a47]99 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
100 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string);
[b54ac8]101
[02ee15]102 /**
103 * get the number of atoms in the World
104 */
[354859]105 int numAtoms();
[02ee15]106
[1c51c8]107 /**
108 * returns the first molecule that matches a given descriptor.
109 * Do not rely on ordering for descriptors that match more than one molecule.
110 */
111 molecule *getMolecule(MoleculeDescriptor descriptor);
112
113 /**
114 * returns a vector containing all molecules that match a given descriptor
115 */
116 std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor);
[97ebf8]117 std::vector<molecule*> getAllMolecules();
[1c51c8]118
[02ee15]119 /**
120 * get the number of molecules in the World
121 */
[354859]122 int numMolecules();
123
[5f612ee]124 /**
125 * get the domain size as a symmetric matrix (6 components)
126 */
127 double * getDomain();
128
129 /**
130 * set the domain size as a symmetric matrix (6 components)
131 */
132 void setDomain(double * matrix);
133
134 /**
135 * get the default name
136 */
[387b36]137 std::string getDefaultName();
[5f612ee]138
139 /**
140 * set the default name
141 */
[387b36]142 void setDefaultName(std::string name);
[5f612ee]143
[43dad6]144 /**
145 * get pointer to World's ThermoStatContainer
146 */
147 ThermoStatContainer * getThermostats();
148
[e4b5de]149 /*
150 * get the ExitFlag
151 */
152 int getExitFlag();
153
154 /*
155 * set the ExitFlag
156 */
157 void setExitFlag(int flag);
158
[354859]159 /***** Methods to work with the World *****/
[02ee15]160
161 /**
162 * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
163 * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
164 */
[354859]165 molecule *createMolecule();
[02ee15]166
[cbc5fb]167 void destroyMolecule(molecule*);
168 void destroyMolecule(moleculeId_t);
169
[02ee15]170 /**
171 * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
172 * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
173 */
[46d958]174 atom *createAtom();
[02ee15]175
176 /**
177 * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
178 * Do not re-register Atoms already known to the world since this will cause double-frees.
179 */
[46d958]180 int registerAtom(atom*);
[02ee15]181
182 /**
183 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
184 * atom directly since this will leave the pointer inside the world.
185 */
[46d958]186 void destroyAtom(atom*);
[02ee15]187
188 /**
189 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
190 * atom directly since this will leave the pointer inside the world.
191 */
[cbc5fb]192 void destroyAtom(atomId_t);
[865a945]193
[88d586]194 /**
195 * used when changing an atom Id.
196 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
197 *
198 * Return value indicates wether the change could be done or not.
199 */
200 bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0);
201
[02ee15]202 /**
203 * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
204 * called at this time, so it can be passed around, stored inside menuItems etc.
205 */
[7c4e29]206 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
[0e2a47]207 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
[7c4e29]208
[865a945]209protected:
210 /**** Iterators to use internal data structures */
[1c51c8]211
212 // Atoms
[6e97e5]213 typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
[865a945]214
[02ee15]215 /**
216 * returns an iterator over all Atoms matching a given descriptor.
217 * used for internal purposes, like AtomProcesses and AtomCalculations.
218 */
[865a945]219 AtomIterator getAtomIter(AtomDescriptor descr);
[02ee15]220
221 /**
[d2dbac0]222 * returns an iterator to the end of the AtomSet. Due to overloading this iterator
[02ee15]223 * can be compared to iterators produced by getAtomIter (see the mis-matching types).
224 * Thus it can be used to detect when such an iterator is at the end of the list.
225 * used for internal purposes, like AtomProcesses and AtomCalculations.
226 */
[6e97e5]227 AtomIterator atomEnd();
[865a945]228
[1c51c8]229 // Molecules
230
[6e97e5]231 typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
[1c51c8]232
233 /**
234 * returns an iterator over all Molecules matching a given descriptor.
235 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
236 */
237 MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
238
239 /**
240 * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
241 * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
242 * Thus it can be used to detect when such an iterator is at the end of the list.
243 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
244 */
[6e97e5]245 MoleculeIterator moleculeEnd();
[1c51c8]246
247
[afb47f]248 /******* Internal manipulation routines for double callback and Observer mechanism ******/
249 void doManipulate(ManipulateAtomsProcess *);
250
[5d1611]251private:
[88d586]252
253 atomId_t getNextAtomId();
254 void releaseAtomId(atomId_t);
255 bool reserveAtomId(atomId_t);
256
[5d1611]257 periodentafel *periode;
[8e1f7af]258 config *configuration;
[5f612ee]259 static double *cell_size;
[387b36]260 std::string defaultName;
[43dad6]261 class ThermoStatContainer *Thermostats;
[e4b5de]262 int ExitFlag;
[6e97e5]263public:
[d2dbac0]264 AtomSet atoms;
[6e97e5]265private:
[88d586]266 std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
[cbc5fb]267 atomId_t currAtomId; //!< stores the next available Id for atoms
[d2dbac0]268 MoleculeSet molecules;
[cbc5fb]269 moleculeId_t currMoleculeId;
[5d1611]270private:
[02ee15]271 /**
272 * private constructor to ensure creation of the world using
273 * the singleton pattern.
274 */
[5d1611]275 World();
[02ee15]276
277 /**
278 * private destructor to ensure destruction of the world using the
279 * singleton pattern.
280 */
[5d1611]281 virtual ~World();
282
283 /*****
284 * some legacy stuff that is include for now but will be removed later
285 *****/
286public:
[354859]287 MoleculeListClass *&getMolecules();
[4d9c01]288
[5d1611]289private:
[354859]290 MoleculeListClass *molecules_deprecated;
[5d1611]291};
292
293#endif /* WORLD_HPP_ */
Note: See TracBrowser for help on using the repository browser.