source: src/World.cpp@ e38447

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 e38447 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
RevLine 
[5d1611]1/*
2 * World.cpp
3 *
4 * Created on: Feb 3, 2010
5 * Author: crueger
6 */
7
[112b09]8#include "Helpers/MemDebug.hpp"
9
[5d1611]10#include "World.hpp"
11
[d346b6]12#include "atom.hpp"
[8e1f7af]13#include "config.hpp"
[354859]14#include "molecule.hpp"
15#include "periodentafel.hpp"
[fc1b24]16#include "Descriptors/AtomDescriptor.hpp"
[865a945]17#include "Descriptors/AtomDescriptor_impl.hpp"
[1c51c8]18#include "Descriptors/MoleculeDescriptor.hpp"
19#include "Descriptors/MoleculeDescriptor_impl.hpp"
[6e97e5]20#include "Descriptors/SelectiveIterator_impl.hpp"
[7c4e29]21#include "Actions/ManipulateAtomsProcess.hpp"
[d346b6]22
[23b547]23#include "Patterns/Singleton_impl.hpp"
24
[d346b6]25using namespace std;
[4d9c01]26
[5d1611]27/******************************* getter and setter ************************/
[354859]28periodentafel *&World::getPeriode(){
[5d1611]29 return periode;
30}
31
[8e1f7af]32config *&World::getConfig(){
33 return configuration;
34}
35
[1c51c8]36// Atoms
37
[7a1ce5]38atom* World::getAtom(AtomDescriptor descriptor){
[fc1b24]39 return descriptor.find();
40}
41
[7a1ce5]42vector<atom*> World::getAllAtoms(AtomDescriptor descriptor){
[fc1b24]43 return descriptor.findAll();
44}
45
[0e2a47]46vector<atom*> World::getAllAtoms(){
47 return getAllAtoms(AllAtoms());
48}
49
[354859]50int World::numAtoms(){
51 return atoms.size();
52}
53
[1c51c8]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
[97ebf8]64std::vector<molecule*> World::getAllMolecules(){
65 return getAllMolecules(AllMolecules());
66}
67
[354859]68int World::numMolecules(){
69 return molecules_deprecated->ListOfMolecules.size();
70}
71
[5f612ee]72// system
73
74double * World::getDomain() {
75 return cell_size;
76}
77
78void World::setDomain(double * matrix)
79{
80
81}
82
[387b36]83std::string World::getDefaultName() {
[5f612ee]84 return defaultName;
85}
86
[387b36]87void World::setDefaultName(std::string name)
[5f612ee]88{
[387b36]89 defaultName = name;
[5f612ee]90};
91
[e4b5de]92int World::getExitFlag() {
93 return ExitFlag;
94}
95
96void World::setExitFlag(int flag) {
97 if (ExitFlag < flag)
98 ExitFlag = flag;
99}
[5f612ee]100
[afb47f]101/******************** Methods to change World state *********************/
102
[354859]103molecule* World::createMolecule(){
104 OBSERVE;
105 molecule *mol = NULL;
[cbc5fb]106 mol = NewMolecule();
[d2dbac0]107 assert(!molecules.count(currMoleculeId));
[cbc5fb]108 mol->setId(currMoleculeId++);
[244d26]109 // store the molecule by ID
[cbc5fb]110 molecules[mol->getId()] = mol;
[354859]111 mol->signOn(this);
112 return mol;
113}
114
[cbc5fb]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
[5f612ee]128double *World::cell_size = NULL;
[7c4e29]129
[46d958]130atom *World::createAtom(){
131 OBSERVE;
[88d586]132 atomId_t id = getNextAtomId();
133 atom *res = NewAtom(id);
[46d958]134 res->setWorld(this);
[244d26]135 // store the atom by ID
[46d958]136 atoms[res->getId()] = res;
137 return res;
138}
139
[5f612ee]140
[46d958]141int World::registerAtom(atom *atom){
142 OBSERVE;
[88d586]143 atomId_t id = getNextAtomId();
144 atom->setId(id);
[46d958]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
[cbc5fb]156void World::destroyAtom(atomId_t id) {
[46d958]157 OBSERVE;
158 atom *atom = atoms[id];
159 assert(atom);
160 DeleteAtom(atom);
161 atoms.erase(id);
[88d586]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 }
[46d958]184}
185
[7c4e29]186ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
187 return new ManipulateAtomsProcess(op, descr,name,true);
188}
189
[0e2a47]190ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
191 return manipulateAtoms(op,name,AllAtoms());
192}
193
[afb47f]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}
[88d586]204/******************************* IDManagement *****************************/
205
[57adc7]206// Atoms
207
[88d586]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);
[23b547]217 return id;
[88d586]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}
[afb47f]230
[88d586]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}
[57adc7]249
250// Molecules
251
[865a945]252/******************************* Iterators ********************************/
253
[6e97e5]254// Build the AtomIterator from template
255CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor);
256
[865a945]257
258World::AtomIterator World::getAtomIter(AtomDescriptor descr){
[6e97e5]259 return AtomIterator(descr,atoms);
[865a945]260}
[354859]261
[6e97e5]262World::AtomIterator World::atomEnd(){
263 return AtomIterator(AllAtoms(),atoms,atoms.end());
[7c4e29]264}
265
[6e97e5]266// build the MoleculeIterator from template
267CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor);
268
[1c51c8]269World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
[6e97e5]270 return MoleculeIterator(descr,molecules);
[1c51c8]271}
272
[6e97e5]273World::MoleculeIterator World::moleculeEnd(){
274 return MoleculeIterator(AllMolecules(),molecules,molecules.end());
[1c51c8]275}
276
[5d1611]277/******************************* Singleton Stuff **************************/
278
[7a1ce5]279World::World() :
[cd5047]280 Observable("World"),
[354859]281 periode(new periodentafel),
[8e1f7af]282 configuration(new config),
[e4b5de]283 ExitFlag(0),
[d2dbac0]284 atoms(),
[24a5e0]285 currAtomId(0),
286 molecules(),
287 currMoleculeId(0),
288 molecules_deprecated(new MoleculeListClass(this))
[7dad10]289{
[b34306]290 cell_size = new double[6];
[fd179f]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.;
[387b36]297 defaultName = "none";
[7dad10]298 molecules_deprecated->signOn(this);
299}
[5d1611]300
301World::~World()
[354859]302{
[028c2e]303 molecules_deprecated->signOff(this);
[5f612ee]304 delete[] cell_size;
[46d958]305 delete molecules_deprecated;
[354859]306 delete periode;
[8e1f7af]307 delete configuration;
[cbc5fb]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);
[46d958]316 }
317 atoms.clear();
[354859]318}
[5d1611]319
[23b547]320// Explicit instantiation of the singleton mechanism at this point
[5d1611]321
[23b547]322CONSTRUCT_SINGLETON(World)
[5d1611]323
324/******************************* deprecated Legacy Stuff ***********************/
325
[354859]326MoleculeListClass *&World::getMolecules() {
327 return molecules_deprecated;
[5d1611]328}
Note: See TracBrowser for help on using the repository browser.