source: src/Descriptors/AtomDescriptor.cpp@ 229e3c

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 229e3c was 23b547, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added generic singleton Pattern that can be inherited to any class making that class a singleton.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * AtomDescriptor.cpp
3 *
4 * Created on: Feb 5, 2010
5 * Author: crueger
6 */
7
8#include "Descriptors/AtomDescriptor.hpp"
9#include "Descriptors/AtomDescriptor_impl.hpp"
10
11#include "World.hpp"
12
13#include "atom.hpp"
14
15#include <boost/bind.hpp>
16#include <cassert>
17#include <iostream>
18
19using namespace std;
20
21typedef World::AtomSet::iterator atoms_iter_t;
22
23/************************ Forwarding object **************************************/
24
25
26AtomDescriptor::AtomDescriptor(impl_ptr _impl) :
27 impl(_impl)
28{}
29
30AtomDescriptor::AtomDescriptor(const AtomDescriptor& src) :
31 impl(src.get_impl())
32{}
33
34AtomDescriptor::~AtomDescriptor()
35{}
36
37AtomDescriptor& AtomDescriptor::operator=(AtomDescriptor &src){
38 if(&src!=this) {
39 impl=src.get_impl();
40 }
41 return *this;
42}
43
44atom* AtomDescriptor::find(){
45 return impl->find();
46}
47
48std::vector<atom*> AtomDescriptor::findAll(){
49 return impl->findAll();
50}
51
52AtomDescriptor::impl_ptr AtomDescriptor::get_impl() const{
53 return impl;
54}
55
56
57
58
59/**************************** implementation ********************/
60
61AtomDescriptor_impl::AtomDescriptor_impl()
62{
63}
64
65AtomDescriptor_impl::~AtomDescriptor_impl()
66{
67}
68
69World::AtomSet& AtomDescriptor_impl::getAtoms(){
70 return World::getInstance().atoms;
71}
72
73atom* AtomDescriptor_impl::find() {
74 World::AtomSet atoms = getAtoms();
75 atoms_iter_t res = find_if(atoms.begin(),atoms.end(),boost::bind(&AtomDescriptor_impl::predicate,this,_1));
76 return (res!=atoms.end())?((*res).second):0;
77}
78
79vector<atom*> AtomDescriptor_impl::findAll() {
80 vector<atom*> res;
81 World::AtomSet atoms = getAtoms();
82 atoms_iter_t iter;
83 for(iter=atoms.begin();iter!=atoms.end();++iter) {
84 if(predicate(*iter)){
85 res.push_back((*iter).second);
86 }
87 }
88 return res;
89}
90
91/************************** Universe and Emptyset *****************/
92
93AtomAllDescriptor_impl::AtomAllDescriptor_impl()
94{}
95
96AtomAllDescriptor_impl::~AtomAllDescriptor_impl()
97{}
98
99bool AtomAllDescriptor_impl::predicate(std::pair<atomId_t,atom*>){
100 return true;
101}
102
103AtomDescriptor AllAtoms(){
104 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomAllDescriptor_impl));
105}
106
107AtomNoneDescriptor_impl::AtomNoneDescriptor_impl()
108{}
109
110AtomNoneDescriptor_impl::~AtomNoneDescriptor_impl()
111{}
112
113bool AtomNoneDescriptor_impl::predicate(std::pair<atomId_t,atom*>){
114 return false;
115}
116
117AtomDescriptor NoAtoms(){
118 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomNoneDescriptor_impl));
119}
120
121/************************** Operator stuff ************************/
122
123// AND
124AtomAndDescriptor_impl::AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs) :
125 lhs(_lhs), rhs(_rhs)
126{}
127
128AtomAndDescriptor_impl::~AtomAndDescriptor_impl()
129{}
130
131bool AtomAndDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
132 return lhs->predicate(atom) && rhs->predicate(atom);
133}
134AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs){
135 AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomAndDescriptor_impl(lhs.get_impl(),rhs.get_impl()));
136 return AtomDescriptor(newImpl);
137}
138
139// OR
140AtomOrDescriptor_impl::AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs ,AtomDescriptor::impl_ptr _rhs) :
141 lhs(_lhs), rhs(_rhs)
142{}
143
144AtomOrDescriptor_impl::~AtomOrDescriptor_impl(){
145}
146
147bool AtomOrDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
148 return lhs->predicate(atom) || rhs->predicate(atom);
149}
150
151AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs){
152 AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomOrDescriptor_impl(lhs.get_impl(),rhs.get_impl()));
153 return AtomDescriptor(newImpl);
154}
155
156// NOT
157
158AtomNotDescriptor_impl::AtomNotDescriptor_impl(AtomDescriptor::impl_ptr _arg) :
159 arg(_arg)
160{}
161
162
163AtomNotDescriptor_impl::~AtomNotDescriptor_impl()
164{
165}
166
167bool AtomNotDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
168 return !(arg->predicate(atom));
169}
170
171AtomDescriptor operator!(const AtomDescriptor &arg){
172 AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomNotDescriptor_impl(arg.get_impl()));
173 return AtomDescriptor(newImpl);
174}
Note: See TracBrowser for help on using the repository browser.