source: src/Descriptors/AtomDescriptor.cpp@ 127a8e

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 127a8e was 6d574a, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Replaced several old-style asserts with more usable ASSERTs

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