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
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"
[8e1f7af]11#include "config.hpp"
[354859]12#include "molecule.hpp"
13#include "periodentafel.hpp"
[43dad6]14#include "ThermoStatContainer.hpp"
[fc1b24]15#include "Descriptors/AtomDescriptor.hpp"
[865a945]16#include "Descriptors/AtomDescriptor_impl.hpp"
[1c51c8]17#include "Descriptors/MoleculeDescriptor.hpp"
18#include "Descriptors/MoleculeDescriptor_impl.hpp"
[6e97e5]19#include "Descriptors/SelectiveIterator_impl.hpp"
[7c4e29]20#include "Actions/ManipulateAtomsProcess.hpp"
[d346b6]21
[23b547]22#include "Patterns/Singleton_impl.hpp"
23
[d346b6]24using namespace std;
[4d9c01]25
[5d1611]26/******************************* getter and setter ************************/
[354859]27periodentafel *&World::getPeriode(){
[5d1611]28 return periode;
29}
30
[8e1f7af]31config *&World::getConfig(){
32 return configuration;
33}
34
[1c51c8]35// Atoms
36
[7a1ce5]37atom* World::getAtom(AtomDescriptor descriptor){
[fc1b24]38 return descriptor.find();
39}
40
[7a1ce5]41vector<atom*> World::getAllAtoms(AtomDescriptor descriptor){
[fc1b24]42 return descriptor.findAll();
43}
44
[0e2a47]45vector<atom*> World::getAllAtoms(){
46 return getAllAtoms(AllAtoms());
47}
48
[354859]49int World::numAtoms(){
50 return atoms.size();
51}
52
[1c51c8]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
[97ebf8]63std::vector<molecule*> World::getAllMolecules(){
64 return getAllMolecules(AllMolecules());
65}
66
[354859]67int World::numMolecules(){
68 return molecules_deprecated->ListOfMolecules.size();
69}
70
[5f612ee]71// system
72
73double * World::getDomain() {
74 return cell_size;
75}
76
77void World::setDomain(double * matrix)
78{
79
80}
81
[387b36]82std::string World::getDefaultName() {
[5f612ee]83 return defaultName;
84}
85
[387b36]86void World::setDefaultName(std::string name)
[5f612ee]87{
[387b36]88 defaultName = name;
[5f612ee]89};
90
[43dad6]91class ThermoStatContainer * World::getThermostats()
92{
93 return Thermostats;
94}
95
96
[e4b5de]97int World::getExitFlag() {
98 return ExitFlag;
99}
100
101void World::setExitFlag(int flag) {
102 if (ExitFlag < flag)
103 ExitFlag = flag;
104}
[5f612ee]105
[afb47f]106/******************** Methods to change World state *********************/
107
[354859]108molecule* World::createMolecule(){
109 OBSERVE;
110 molecule *mol = NULL;
[cbc5fb]111 mol = NewMolecule();
[d2dbac0]112 assert(!molecules.count(currMoleculeId));
[cbc5fb]113 mol->setId(currMoleculeId++);
[244d26]114 // store the molecule by ID
[cbc5fb]115 molecules[mol->getId()] = mol;
[354859]116 mol->signOn(this);
117 return mol;
118}
119
[cbc5fb]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
[5f612ee]133double *World::cell_size = NULL;
[7c4e29]134
[46d958]135atom *World::createAtom(){
136 OBSERVE;
[88d586]137 atomId_t id = getNextAtomId();
138 atom *res = NewAtom(id);
[46d958]139 res->setWorld(this);
[244d26]140 // store the atom by ID
[46d958]141 atoms[res->getId()] = res;
142 return res;
143}
144
[5f612ee]145
[46d958]146int World::registerAtom(atom *atom){
147 OBSERVE;
[88d586]148 atomId_t id = getNextAtomId();
149 atom->setId(id);
[46d958]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
[cbc5fb]161void World::destroyAtom(atomId_t id) {
[46d958]162 OBSERVE;
163 atom *atom = atoms[id];
164 assert(atom);
165 DeleteAtom(atom);
166 atoms.erase(id);
[88d586]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 }
[46d958]189}
190
[7c4e29]191ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
192 return new ManipulateAtomsProcess(op, descr,name,true);
193}
194
[0e2a47]195ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
196 return manipulateAtoms(op,name,AllAtoms());
197}
198
[afb47f]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}
[88d586]209/******************************* IDManagement *****************************/
210
[57adc7]211// Atoms
212
[88d586]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);
[23b547]222 return id;
[88d586]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}
[afb47f]235
[88d586]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}
[57adc7]254
255// Molecules
256
[865a945]257/******************************* Iterators ********************************/
258
[6e97e5]259// Build the AtomIterator from template
260CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor);
261
[865a945]262
263World::AtomIterator World::getAtomIter(AtomDescriptor descr){
[6e97e5]264 return AtomIterator(descr,atoms);
[865a945]265}
[354859]266
[6e97e5]267World::AtomIterator World::atomEnd(){
268 return AtomIterator(AllAtoms(),atoms,atoms.end());
[7c4e29]269}
270
[6e97e5]271// build the MoleculeIterator from template
272CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor);
273
[1c51c8]274World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
[6e97e5]275 return MoleculeIterator(descr,molecules);
[1c51c8]276}
277
[6e97e5]278World::MoleculeIterator World::moleculeEnd(){
279 return MoleculeIterator(AllMolecules(),molecules,molecules.end());
[1c51c8]280}
281
[5d1611]282/******************************* Singleton Stuff **************************/
283
[7a1ce5]284World::World() :
[354859]285 periode(new periodentafel),
[8e1f7af]286 configuration(new config),
[43dad6]287 Thermostats(new ThermoStatContainer),
[e4b5de]288 ExitFlag(0),
[d2dbac0]289 atoms(),
[24a5e0]290 currAtomId(0),
291 molecules(),
292 currMoleculeId(0),
293 molecules_deprecated(new MoleculeListClass(this))
[7dad10]294{
[b34306]295 cell_size = new double[6];
[fd179f]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.;
[387b36]302 defaultName = "none";
[7dad10]303 molecules_deprecated->signOn(this);
304}
[5d1611]305
306World::~World()
[354859]307{
[028c2e]308 molecules_deprecated->signOff(this);
[5f612ee]309 delete[] cell_size;
[46d958]310 delete molecules_deprecated;
[354859]311 delete periode;
[8e1f7af]312 delete configuration;
[43dad6]313 delete Thermostats;
[cbc5fb]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);
[46d958]322 }
323 atoms.clear();
[354859]324}
[5d1611]325
[23b547]326// Explicit instantiation of the singleton mechanism at this point
[5d1611]327
[23b547]328CONSTRUCT_SINGLETON(World)
[5d1611]329
330/******************************* deprecated Legacy Stuff ***********************/
331
[354859]332MoleculeListClass *&World::getMolecules() {
333 return molecules_deprecated;
[5d1611]334}
Note: See TracBrowser for help on using the repository browser.