source: src/Descriptors/AtomDescriptor.cpp@ 9cd807

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 9cd807 was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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