source: src/World.cpp@ 906822

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 906822 was e6317b, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Broken: Merge commit 'Gitosis/stable' into stable

Conflicts:

molecuilder/src/Actions/AnalysisAction/PairCorrelationToPointAction.cpp
molecuilder/src/Actions/AnalysisAction/PairCorrelationToSurfaceAction.cpp
molecuilder/src/Makefile.am

  • Property mode set to 100644
File size: 7.2 KB
Line 
1/*
2 * World.cpp
3 *
4 * Created on: Feb 3, 2010
5 * Author: crueger
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include "World.hpp"
11
12#include "atom.hpp"
13#include "config.hpp"
14#include "molecule.hpp"
15#include "periodentafel.hpp"
16#include "Descriptors/AtomDescriptor.hpp"
17#include "Descriptors/AtomDescriptor_impl.hpp"
18#include "Descriptors/MoleculeDescriptor.hpp"
19#include "Descriptors/MoleculeDescriptor_impl.hpp"
20#include "Descriptors/SelectiveIterator_impl.hpp"
21#include "Actions/ManipulateAtomsProcess.hpp"
22
23#include "Patterns/Singleton_impl.hpp"
24
25using namespace std;
26
27/******************************* getter and setter ************************/
28periodentafel *&World::getPeriode(){
29 return periode;
30}
31
32config *&World::getConfig(){
33 return configuration;
34}
35
36// Atoms
37
38atom* World::getAtom(AtomDescriptor descriptor){
39 return descriptor.find();
40}
41
42vector<atom*> World::getAllAtoms(AtomDescriptor descriptor){
43 return descriptor.findAll();
44}
45
46vector<atom*> World::getAllAtoms(){
47 return getAllAtoms(AllAtoms());
48}
49
50int World::numAtoms(){
51 return atoms.size();
52}
53
54// Molecules
55
56molecule *World::getMolecule(MoleculeDescriptor descriptor){
57 return descriptor.find();
58}
59
60std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
61 return descriptor.findAll();
62}
63
64std::vector<molecule*> World::getAllMolecules(){
65 return getAllMolecules(AllMolecules());
66}
67
68int World::numMolecules(){
69 return molecules_deprecated->ListOfMolecules.size();
70}
71
72// system
73
74double * World::getDomain() {
75 return cell_size;
76}
77
78void World::setDomain(double * matrix)
79{
80
81}
82
83std::string World::getDefaultName() {
84 return defaultName;
85}
86
87void World::setDefaultName(std::string name)
88{
89 defaultName = name;
90};
91
92int World::getExitFlag() {
93 return ExitFlag;
94}
95
96void World::setExitFlag(int flag) {
97 if (ExitFlag < flag)
98 ExitFlag = flag;
99}
100
101/******************** Methods to change World state *********************/
102
103molecule* World::createMolecule(){
104 OBSERVE;
105 molecule *mol = NULL;
106 mol = NewMolecule();
107 assert(!molecules.count(currMoleculeId));
108 mol->setId(currMoleculeId++);
109 // store the molecule by ID
110 molecules[mol->getId()] = mol;
111 mol->signOn(this);
112 return mol;
113}
114
115void World::destroyMolecule(molecule* mol){
116 OBSERVE;
117 destroyMolecule(mol->getId());
118}
119
120void World::destroyMolecule(moleculeId_t id){
121 OBSERVE;
122 molecule *mol = molecules[id];
123 assert(mol);
124 DeleteMolecule(mol);
125 molecules.erase(id);
126}
127
128double *World::cell_size = NULL;
129
130atom *World::createAtom(){
131 OBSERVE;
132 atomId_t id = getNextAtomId();
133 atom *res = NewAtom(id);
134 res->setWorld(this);
135 // store the atom by ID
136 atoms[res->getId()] = res;
137 return res;
138}
139
140
141int World::registerAtom(atom *atom){
142 OBSERVE;
143 atomId_t id = getNextAtomId();
144 atom->setId(id);
145 atom->setWorld(this);
146 atoms[atom->getId()] = atom;
147 return atom->getId();
148}
149
150void World::destroyAtom(atom* atom){
151 OBSERVE;
152 int id = atom->getId();
153 destroyAtom(id);
154}
155
156void World::destroyAtom(atomId_t id) {
157 OBSERVE;
158 atom *atom = atoms[id];
159 assert(atom);
160 DeleteAtom(atom);
161 atoms.erase(id);
162 releaseAtomId(id);
163}
164
165bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
166 OBSERVE;
167 // in case this call did not originate from inside the atom, we redirect it,
168 // to also let it know that it has changed
169 if(!target){
170 target = atoms[oldId];
171 assert(target && "Atom with that ID not found");
172 return target->changeId(newId);
173 }
174 else{
175 if(reserveAtomId(newId)){
176 atoms.erase(oldId);
177 atoms.insert(pair<atomId_t,atom*>(newId,target));
178 return true;
179 }
180 else{
181 return false;
182 }
183 }
184}
185
186ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
187 return new ManipulateAtomsProcess(op, descr,name,true);
188}
189
190ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
191 return manipulateAtoms(op,name,AllAtoms());
192}
193
194/********************* Internal Change methods for double Callback and Observer mechanism ********/
195
196void World::doManipulate(ManipulateAtomsProcess *proc){
197 proc->signOn(this);
198 {
199 OBSERVE;
200 proc->doManipulate(this);
201 }
202 proc->signOff(this);
203}
204/******************************* IDManagement *****************************/
205
206// Atoms
207
208atomId_t World::getNextAtomId(){
209 // see if we can reuse some Id
210 if(atomIdPool.empty()){
211 return currAtomId++;
212 }
213 else{
214 // we give out the first ID from the pool
215 atomId_t id = *(atomIdPool.begin());
216 atomIdPool.erase(id);
217 return id;
218 }
219}
220
221void World::releaseAtomId(atomId_t id){
222 atomIdPool.insert(id);
223 // defragmentation of the pool
224 set<atomId_t>::reverse_iterator iter;
225 // go through all Ids in the pool that lie immediately below the border
226 while(!atomIdPool.empty() && *(atomIdPool.rbegin())==(currAtomId-1)){
227 atomIdPool.erase(--currAtomId);
228 }
229}
230
231bool World::reserveAtomId(atomId_t id){
232 if(id>=currAtomId ){
233 // add all ids between the new one and current border as available
234 for(atomId_t pos=currAtomId; pos<id; ++pos){
235 atomIdPool.insert(pos);
236 }
237 currAtomId=id+1;
238 return true;
239 }
240 else if(atomIdPool.count(id)){
241 atomIdPool.erase(id);
242 return true;
243 }
244 else{
245 // this ID could not be reserved
246 return false;
247 }
248}
249
250// Molecules
251
252/******************************* Iterators ********************************/
253
254// Build the AtomIterator from template
255CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor);
256
257
258World::AtomIterator World::getAtomIter(AtomDescriptor descr){
259 return AtomIterator(descr,atoms);
260}
261
262World::AtomIterator World::atomEnd(){
263 return AtomIterator(AllAtoms(),atoms,atoms.end());
264}
265
266// build the MoleculeIterator from template
267CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor);
268
269World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
270 return MoleculeIterator(descr,molecules);
271}
272
273World::MoleculeIterator World::moleculeEnd(){
274 return MoleculeIterator(AllMolecules(),molecules,molecules.end());
275}
276
277/******************************* Singleton Stuff **************************/
278
279World::World() :
280 Observable("World"),
281 periode(new periodentafel),
282 configuration(new config),
283 ExitFlag(0),
284 atoms(),
285 currAtomId(0),
286 molecules(),
287 currMoleculeId(0),
288 molecules_deprecated(new MoleculeListClass(this))
289{
290 cell_size = new double[6];
291 cell_size[0] = 20.;
292 cell_size[1] = 0.;
293 cell_size[2] = 20.;
294 cell_size[3] = 0.;
295 cell_size[4] = 0.;
296 cell_size[5] = 20.;
297 defaultName = "none";
298 molecules_deprecated->signOn(this);
299}
300
301World::~World()
302{
303 molecules_deprecated->signOff(this);
304 delete[] cell_size;
305 delete molecules_deprecated;
306 delete periode;
307 delete configuration;
308 MoleculeSet::iterator molIter;
309 for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
310 DeleteMolecule((*molIter).second);
311 }
312 molecules.clear();
313 AtomSet::iterator atIter;
314 for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
315 DeleteAtom((*atIter).second);
316 }
317 atoms.clear();
318}
319
320// Explicit instantiation of the singleton mechanism at this point
321
322CONSTRUCT_SINGLETON(World)
323
324/******************************* deprecated Legacy Stuff ***********************/
325
326MoleculeListClass *&World::getMolecules() {
327 return molecules_deprecated;
328}
Note: See TracBrowser for help on using the repository browser.