source: src/Descriptors/MoleculeDescriptor.cpp@ 36166d

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