source: src/Descriptors/AtomDescriptor.cpp@ 4464ef

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 4464ef was 795c0f, checked in by Frederik Heber <heber@…>, 9 years ago

World::getAtoms() now has const versions as well.

  • this in turn required to adapt all AtomDescriptors and some fixes, e.g. predicate is now const member and works on const atom ptr.
  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * AtomDescriptor.cpp
25 *
26 * Created on: Feb 5, 2010
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "Descriptors/AtomDescriptor.hpp"
38#include "Descriptors/AtomDescriptor_impl.hpp"
39
40#include "World.hpp"
41#include "Atom/atom.hpp"
42#include "CodePatterns/Observer/ObservedContainer_impl.hpp"
43
44#include <boost/bind.hpp>
45
46#include <iostream>
47
48using namespace std;
49
50typedef World::AtomSet::internal_iterator atoms_iter_t;
51typedef World::AtomSet::const_iterator atoms_const_iter_t;
52
53/************************ Forwarding object **************************************/
54
55
56AtomDescriptor::AtomDescriptor(impl_ptr _impl) :
57 impl(_impl)
58{}
59
60AtomDescriptor::AtomDescriptor(const AtomDescriptor& src) :
61 impl(src.get_impl())
62{}
63
64AtomDescriptor::~AtomDescriptor()
65{}
66
67AtomDescriptor& AtomDescriptor::operator=(AtomDescriptor &src){
68 if(&src!=this) {
69 impl=src.get_impl();
70 }
71 return *this;
72}
73
74atom* AtomDescriptor::find(){
75 return impl->find();
76}
77
78const atom* AtomDescriptor::find() const {
79 return const_cast<const impl_t &>(*impl).find();
80}
81
82std::vector<atom*> AtomDescriptor::findAll(){
83 return impl->findAll();
84}
85
86std::vector<const atom*> AtomDescriptor::findAll() const {
87 return const_cast<const impl_t &>(*impl).findAll();
88}
89
90AtomDescriptor::impl_ptr AtomDescriptor::get_impl() const{
91 return impl;
92}
93
94
95
96
97/**************************** implementation ********************/
98
99AtomDescriptor_impl::AtomDescriptor_impl()
100{
101}
102
103AtomDescriptor_impl::~AtomDescriptor_impl()
104{
105}
106
107World::AtomSet& AtomDescriptor_impl::getAtoms(){
108 return World::getInstance().atoms;
109}
110
111const World::AtomSet& AtomDescriptor_impl::getAtoms() const {
112 return const_cast<const World &>(World::getInstance()).atoms;
113}
114
115atom* AtomDescriptor_impl::find() {
116 World::AtomSet &atoms = getAtoms();
117 atoms_iter_t res = find_if(atoms.begin_internal(),atoms.end_internal(),boost::bind(&AtomDescriptor_impl::predicate,this,_1));
118 return (res!=atoms.end_internal())?((*res).second):0;
119}
120
121const atom* AtomDescriptor_impl::find() const {
122 const World::AtomSet &atoms = getAtoms();
123 atoms_const_iter_t res = find_if(atoms.begin(),atoms.end(),boost::bind(&AtomDescriptor_impl::predicate,this,_1));
124 return (res!=atoms.end())?((*res).second):0;
125}
126
127vector<atom*> AtomDescriptor_impl::findAll() {
128 vector<atom*> res;
129 World::AtomSet atoms = getAtoms();
130 for_each(atoms.begin_internal(),
131 atoms.end_internal(),
132 boost::bind(static_cast<void (AtomDescriptor_impl::*)(
133 std::vector<atom*> *,
134 std::pair<atomId_t,atom*>)>(&AtomDescriptor_impl::checkAndAdd),
135 this,boost::cref(&res),_1));
136 return res;
137}
138
139vector<const atom*> AtomDescriptor_impl::findAll() const {
140 vector<const atom*> res;
141 const World::AtomSet &atoms = getAtoms();
142 for_each(atoms.begin(),
143 atoms.end(),
144 boost::bind(static_cast<void (AtomDescriptor_impl::*)(
145 std::vector<const atom*> *,
146 std::pair<atomId_t,const atom*>) const>(&AtomDescriptor_impl::checkAndAdd),
147 boost::cref(this),&res,_1));
148 return res;
149}
150
151void AtomDescriptor_impl::checkAndAdd(std::vector<atom*> *v,std::pair<atomId_t,atom*> p){
152 if(predicate(p)){
153 v->push_back(p.second);
154 }
155}
156
157void AtomDescriptor_impl::checkAndAdd(std::vector<const atom*> *v,std::pair<atomId_t,const atom*> p) const{
158 if(predicate(p)){
159 v->push_back(p.second);
160 }
161}
162
163/************************** Universe and Emptyset *****************/
164
165AtomAllDescriptor_impl::AtomAllDescriptor_impl()
166{}
167
168AtomAllDescriptor_impl::~AtomAllDescriptor_impl()
169{}
170
171bool AtomAllDescriptor_impl::predicate(std::pair<atomId_t,const atom*>) const{
172 return true;
173}
174
175AtomDescriptor AllAtoms(){
176 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomAllDescriptor_impl));
177}
178
179AtomNoneDescriptor_impl::AtomNoneDescriptor_impl()
180{}
181
182AtomNoneDescriptor_impl::~AtomNoneDescriptor_impl()
183{}
184
185bool AtomNoneDescriptor_impl::predicate(std::pair<atomId_t,const atom*>) const{
186 return false;
187}
188
189AtomDescriptor NoAtoms(){
190 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomNoneDescriptor_impl));
191}
192
193/************************** Operator stuff ************************/
194
195// AND
196AtomAndDescriptor_impl::AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs) :
197 lhs(_lhs), rhs(_rhs)
198{}
199
200AtomAndDescriptor_impl::~AtomAndDescriptor_impl()
201{}
202
203bool AtomAndDescriptor_impl::predicate(std::pair<atomId_t,const atom*> atom) const{
204 return lhs->predicate(atom) && rhs->predicate(atom);
205}
206AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs){
207 AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomAndDescriptor_impl(lhs.get_impl(),rhs.get_impl()));
208 return AtomDescriptor(newImpl);
209}
210
211// OR
212AtomOrDescriptor_impl::AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs ,AtomDescriptor::impl_ptr _rhs) :
213 lhs(_lhs), rhs(_rhs)
214{}
215
216AtomOrDescriptor_impl::~AtomOrDescriptor_impl(){
217}
218
219bool AtomOrDescriptor_impl::predicate(std::pair<atomId_t,const atom*> atom) const{
220 return lhs->predicate(atom) || rhs->predicate(atom);
221}
222
223AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs){
224 AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomOrDescriptor_impl(lhs.get_impl(),rhs.get_impl()));
225 return AtomDescriptor(newImpl);
226}
227
228// NOT
229
230AtomNotDescriptor_impl::AtomNotDescriptor_impl(AtomDescriptor::impl_ptr _arg) :
231 arg(_arg)
232{}
233
234
235AtomNotDescriptor_impl::~AtomNotDescriptor_impl()
236{
237}
238
239bool AtomNotDescriptor_impl::predicate(std::pair<atomId_t,const atom*> atom) const{
240 return !(arg->predicate(atom));
241}
242
243AtomDescriptor operator!(const AtomDescriptor &arg){
244 AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomNotDescriptor_impl(arg.get_impl()));
245 return AtomDescriptor(newImpl);
246}
Note: See TracBrowser for help on using the repository browser.