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
RevLine 
[5d1611]1/*
2 * World.cpp
3 *
4 * Created on: Feb 3, 2010
5 * Author: crueger
6 */
7
8#include "World.hpp"
9
[d346b6]10#include "atom.hpp"
[354859]11#include "molecule.hpp"
12#include "periodentafel.hpp"
[fc1b24]13#include "Descriptors/AtomDescriptor.hpp"
[865a945]14#include "Descriptors/AtomDescriptor_impl.hpp"
[1c51c8]15#include "Descriptors/MoleculeDescriptor.hpp"
16#include "Descriptors/MoleculeDescriptor_impl.hpp"
[6e97e5]17#include "Descriptors/SelectiveIterator_impl.hpp"
[7c4e29]18#include "Actions/ManipulateAtomsProcess.hpp"
[d346b6]19
[23b547]20#include "Patterns/Singleton_impl.hpp"
21
[d346b6]22using namespace std;
[4d9c01]23
[5d1611]24/******************************* getter and setter ************************/
[354859]25periodentafel *&World::getPeriode(){
[5d1611]26 return periode;
27}
28
[1c51c8]29// Atoms
30
[7a1ce5]31atom* World::getAtom(AtomDescriptor descriptor){
[fc1b24]32 return descriptor.find();
33}
34
[7a1ce5]35vector<atom*> World::getAllAtoms(AtomDescriptor descriptor){
[fc1b24]36 return descriptor.findAll();
37}
38
[0e2a47]39vector<atom*> World::getAllAtoms(){
40 return getAllAtoms(AllAtoms());
41}
42
[354859]43int World::numAtoms(){
44 return atoms.size();
45}
46
[1c51c8]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
[354859]57int World::numMolecules(){
58 return molecules_deprecated->ListOfMolecules.size();
59}
60
[5f612ee]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
[afb47f]88/******************** Methods to change World state *********************/
89
[354859]90molecule* World::createMolecule(){
91 OBSERVE;
92 molecule *mol = NULL;
[cbc5fb]93 mol = NewMolecule();
[d2dbac0]94 assert(!molecules.count(currMoleculeId));
[cbc5fb]95 mol->setId(currMoleculeId++);
[244d26]96 // store the molecule by ID
[cbc5fb]97 molecules[mol->getId()] = mol;
[354859]98 mol->signOn(this);
99 return mol;
100}
101
[cbc5fb]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
[5f612ee]115double *World::cell_size = NULL;
116char *World::defaultName = NULL;
[7c4e29]117
[46d958]118atom *World::createAtom(){
119 OBSERVE;
[88d586]120 atomId_t id = getNextAtomId();
121 atom *res = NewAtom(id);
[46d958]122 res->setWorld(this);
[244d26]123 // store the atom by ID
[46d958]124 atoms[res->getId()] = res;
125 return res;
126}
127
[5f612ee]128
[46d958]129int World::registerAtom(atom *atom){
130 OBSERVE;
[88d586]131 atomId_t id = getNextAtomId();
132 atom->setId(id);
[46d958]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
[cbc5fb]144void World::destroyAtom(atomId_t id) {
[46d958]145 OBSERVE;
146 atom *atom = atoms[id];
147 assert(atom);
148 DeleteAtom(atom);
149 atoms.erase(id);
[88d586]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 }
[46d958]172}
173
[7c4e29]174ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
175 return new ManipulateAtomsProcess(op, descr,name,true);
176}
177
[0e2a47]178ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
179 return manipulateAtoms(op,name,AllAtoms());
180}
181
[afb47f]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}
[88d586]192/******************************* IDManagement *****************************/
193
[57adc7]194// Atoms
195
[88d586]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);
[23b547]205 return id;
[88d586]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}
[afb47f]218
[88d586]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}
[57adc7]237
238// Molecules
239
[865a945]240/******************************* Iterators ********************************/
241
[6e97e5]242// Build the AtomIterator from template
243CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor);
244
[865a945]245
246World::AtomIterator World::getAtomIter(AtomDescriptor descr){
[6e97e5]247 return AtomIterator(descr,atoms);
[865a945]248}
[354859]249
[6e97e5]250World::AtomIterator World::atomEnd(){
251 return AtomIterator(AllAtoms(),atoms,atoms.end());
[7c4e29]252}
253
[6e97e5]254// build the MoleculeIterator from template
255CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor);
256
[1c51c8]257World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
[6e97e5]258 return MoleculeIterator(descr,molecules);
[1c51c8]259}
260
[6e97e5]261World::MoleculeIterator World::moleculeEnd(){
262 return MoleculeIterator(AllMolecules(),molecules,molecules.end());
[1c51c8]263}
264
[5d1611]265/******************************* Singleton Stuff **************************/
266
[7a1ce5]267World::World() :
[354859]268 periode(new periodentafel),
[d2dbac0]269 atoms(),
[24a5e0]270 currAtomId(0),
271 molecules(),
272 currMoleculeId(0),
273 molecules_deprecated(new MoleculeListClass(this))
[7dad10]274{
[b34306]275 cell_size = new double[6];
[fd179f]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.;
[5f612ee]282 defaultName = new char[MAXSTRINGSIZE];
283 strcpy(defaultName, "none");
[7dad10]284 molecules_deprecated->signOn(this);
285}
[5d1611]286
287World::~World()
[354859]288{
[028c2e]289 molecules_deprecated->signOff(this);
[5f612ee]290 delete[] cell_size;
291 delete[] defaultName;
[46d958]292 delete molecules_deprecated;
[354859]293 delete periode;
[cbc5fb]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);
[46d958]302 }
303 atoms.clear();
[354859]304}
[5d1611]305
[23b547]306// Explicit instantiation of the singleton mechanism at this point
[5d1611]307
[23b547]308CONSTRUCT_SINGLETON(World)
[5d1611]309
310/******************************* deprecated Legacy Stuff ***********************/
311
[354859]312MoleculeListClass *&World::getMolecules() {
313 return molecules_deprecated;
[5d1611]314}
Note: See TracBrowser for help on using the repository browser.