source: src/World.cpp@ 1b2d30

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