source: src/Descriptors/MoleculeDescriptor.cpp@ 1c51c8

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 1c51c8 was 1c51c8, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added methods for querying molecules using descriptors

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