source: src/World.cpp@ 0e01b4

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 0e01b4 was 5f612ee, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'Analysis_PairCorrelation' into StructureRefactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/World.cpp
molecuilder/src/World.hpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/log.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/periodentafel.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/gslvectorunittest.cpp
molecuilder/src/unittests/logunittest.cpp
molecuilder/src/unittests/tesselation_boundarytriangleunittest.hpp
molecuilder/src/vector.cpp
molecuilder/tests/Tesselations/defs.in

Conflicts have been many and too numerous to listen here, just the few general cases

  • new molecule() replaced by World::getInstance().createMolecule()
  • new atom() replaced by World::getInstance().createAtom() where appropriate.
  • Some DoLog()s added interfered with changes to the message produced by Log() << Verbose(.) << ...
  • DoLog() has been erroneously added to TestRunner.cpp as well, there cout is appropriate
  • ...

Additionally, there was a bug in atom::clone(), sort was set to atom::nr of the atom to clone not of the clone itself. This caused a failure of the fragmentation.

This merge has been fully checked from a clean build directory with subsequent configure,make all install and make check.
It configures, compiles and runs all test cases and the test suite without errors.

Signed-off-by: Frederik Heber <heber@…>

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