Changeset 7a1ce5
- Timestamp:
- Feb 16, 2010, 4:24:07 PM (15 years ago)
- Branches:
- 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
- Children:
- 354859
- Parents:
- d1c5e2
- Location:
- src
- Files:
-
- 4 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Descriptors/AtomDescriptor.cpp
rd1c5e2 r7a1ce5 6 6 */ 7 7 8 #include "AtomDescriptor.hpp" 8 #include "Descriptors/AtomDescriptor.hpp" 9 #include "Descriptors/AtomDescriptor_impl.hpp" 9 10 10 11 #include "World.hpp" 11 12 13 #include "atom.hpp" 14 12 15 #include <boost/bind.hpp> 13 16 #include <cassert> 17 #include <iostream> 14 18 15 19 using namespace std; … … 18 22 typedef atoms_t::iterator atoms_iter_t; 19 23 20 AtomDescriptor::AtomDescriptor() 24 /************************ Forwarding object **************************************/ 25 26 27 AtomDescriptor::AtomDescriptor(impl_ptr _impl) : 28 impl(_impl) 29 {} 30 31 AtomDescriptor::AtomDescriptor(const AtomDescriptor& src) : 32 impl(src.get_impl()) 33 {} 34 35 AtomDescriptor::~AtomDescriptor() 36 {} 37 38 AtomDescriptor& AtomDescriptor::operator=(AtomDescriptor &src){ 39 if(&src!=this) { 40 impl=src.get_impl(); 41 } 42 return *this; 43 } 44 45 atom* AtomDescriptor::find(){ 46 return impl->find(); 47 } 48 49 std::vector<atom*> AtomDescriptor::findAll(){ 50 return impl->findAll(); 51 } 52 53 AtomDescriptor::impl_ptr AtomDescriptor::get_impl() const{ 54 return impl; 55 } 56 57 58 59 60 /**************************** implementation ********************/ 61 62 AtomDescriptor_impl::AtomDescriptor_impl() 21 63 { 22 64 } 23 65 24 AtomDescriptor::AtomDescriptor(const AtomDescriptor &desc) { 25 } 26 27 AtomDescriptor::~AtomDescriptor() 66 AtomDescriptor_impl::~AtomDescriptor_impl() 28 67 { 29 68 } 30 69 31 32 atoms_t& AtomDescriptor::getAtoms(){ 70 atoms_t& AtomDescriptor_impl::getAtoms(){ 33 71 return World::get()->atoms; 34 72 } 35 73 36 atom* AtomDescriptor ::find() {74 atom* AtomDescriptor_impl::find() { 37 75 atoms_t atoms = getAtoms(); 38 atoms_iter_t res = find_if(atoms.begin(),atoms.end(),boost::bind(&AtomDescriptor ::predicate,this,_1));76 atoms_iter_t res = find_if(atoms.begin(),atoms.end(),boost::bind(&AtomDescriptor_impl::predicate,this,_1)); 39 77 return (res!=atoms.end())?((*res).second):0; 40 78 } 41 79 42 vector<atom*> AtomDescriptor ::findAll() {80 vector<atom*> AtomDescriptor_impl::findAll() { 43 81 vector<atom*> res; 44 82 atoms_t atoms = getAtoms(); 45 83 atoms_iter_t iter; 46 84 for(iter=atoms.begin();iter!=atoms.end();++iter) { 47 if(predicate(*iter)) 85 if(predicate(*iter)){ 48 86 res.push_back((*iter).second); 87 } 49 88 } 89 return res; 50 90 } 51 91 52 // stuff for operators 92 /************************** Universe and Emptyset *****************/ 93 94 AtomAllDescriptor_impl::AtomAllDescriptor_impl() 95 {} 96 97 AtomAllDescriptor_impl::~AtomAllDescriptor_impl() 98 {} 99 100 bool AtomAllDescriptor_impl::predicate(std::pair<int,atom*>){ 101 return true; 102 } 103 104 AtomDescriptor AllAtoms(){ 105 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomAllDescriptor_impl)); 106 } 107 108 AtomNoneDescriptor_impl::AtomNoneDescriptor_impl() 109 {} 110 111 AtomNoneDescriptor_impl::~AtomNoneDescriptor_impl() 112 {} 113 114 bool AtomNoneDescriptor_impl::predicate(std::pair<int,atom*>){ 115 return false; 116 } 117 118 AtomDescriptor NoAtoms(){ 119 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomNoneDescriptor_impl)); 120 } 121 122 /************************** Operator stuff ************************/ 53 123 54 124 // AND 55 AtomAndDescriptor::AtomAndDescriptor(const AtomDescriptor &_lhs,const AtomDescriptor &_rhs){ 56 lhs=_lhs.clone(); 57 rhs=_rhs.clone(); 58 } 125 AtomAndDescriptor_impl::AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs) : 126 lhs(_lhs), rhs(_rhs) 127 {} 59 128 60 AtomAndDescriptor::AtomAndDescriptor(const AtomAndDescriptor &_desc) 61 { 62 // the copy constructor needs it's parameter as const to work, 63 // however we need to be able to transfer the ownership of the pointers 64 // to the new method to avoid another cloning. 65 // 66 // the only place where the copy constructor is used for these classes, 67 // is when returning a temporary. 68 // this is one of the very rare cases when const_cast makes sense 69 AtomAndDescriptor &desc = const_cast<AtomAndDescriptor&>(_desc); 70 lhs = desc.lhs; 71 rhs = desc.rhs; 72 } 129 AtomAndDescriptor_impl::~AtomAndDescriptor_impl() 130 {} 73 131 74 AtomAndDescriptor::~AtomAndDescriptor(){ 75 } 76 77 bool AtomAndDescriptor::predicate(std::pair<int,atom*> atom){ 132 bool AtomAndDescriptor_impl::predicate(std::pair<int,atom*> atom){ 78 133 return lhs->predicate(atom) && rhs->predicate(atom); 79 134 } 80 81 AtomAndDescriptor::desc_ptr AtomAndDescriptor::clone() const{ 82 return desc_ptr(new AtomAndDescriptor(*lhs,*rhs)); 83 } 84 85 AtomAndDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs){ 86 return AtomAndDescriptor(lhs,rhs); 135 AtomDescriptor 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); 87 138 } 88 139 89 140 // OR 141 AtomOrDescriptor_impl::AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs ,AtomDescriptor::impl_ptr _rhs) : 142 lhs(_lhs), rhs(_rhs) 143 {} 90 144 91 AtomOrDescriptor::AtomOrDescriptor(const AtomDescriptor &_lhs,const AtomDescriptor &_rhs){ 92 lhs=_lhs.clone(); 93 rhs=_rhs.clone(); 145 AtomOrDescriptor_impl::~AtomOrDescriptor_impl(){ 94 146 } 95 147 96 AtomOrDescriptor::AtomOrDescriptor(const AtomOrDescriptor &_desc) 97 { 98 // the copy constructor needs it's parameter as const to work, 99 // however we need to be able to transfer the ownership of the pointers 100 // to the new method to avoid another cloning. 101 // 102 // the only place where the copy constructor is used for these classes, 103 // is when returning a temporary. 104 // this is one of the very rare cases when const_cast makes sense 105 AtomOrDescriptor &desc = const_cast<AtomOrDescriptor&>(_desc); 106 lhs = desc.lhs; 107 rhs = desc.rhs; 108 } 109 110 AtomOrDescriptor::~AtomOrDescriptor(){ 111 } 112 113 bool AtomOrDescriptor::predicate(std::pair<int,atom*> atom){ 148 bool AtomOrDescriptor_impl::predicate(std::pair<int,atom*> atom){ 114 149 return lhs->predicate(atom) || rhs->predicate(atom); 115 150 } 116 151 117 AtomAndDescriptor::desc_ptr AtomOrDescriptor::clone() const{ 118 return desc_ptr(new AtomOrDescriptor(*lhs,*rhs)); 119 } 120 121 AtomOrDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs){ 122 return AtomOrDescriptor(lhs,rhs); 152 AtomDescriptor 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); 123 155 } 124 156 125 157 // NOT 126 158 127 AtomNotDescriptor ::AtomNotDescriptor(const AtomDescriptor &_arg){128 arg = _arg.clone();129 }159 AtomNotDescriptor_impl::AtomNotDescriptor_impl(AtomDescriptor::impl_ptr _arg) : 160 arg(_arg) 161 {} 130 162 131 AtomNotDescriptor::AtomNotDescriptor(const AtomNotDescriptor &_desc) {132 // the copy constructor needs it's parameter as const to work,133 // however we need to be able to transfer the ownership of the pointers134 // to the new method to avoid another cloning.135 //136 // the only place where the copy constructor is used for these classes,137 // is when returning a temporary.138 // this is one of the very rare cases when const_cast makes sense139 AtomNotDescriptor &desc = const_cast<AtomNotDescriptor&>(_desc);140 arg = desc.arg;141 }142 163 143 AtomNotDescriptor ::~AtomNotDescriptor()164 AtomNotDescriptor_impl::~AtomNotDescriptor_impl() 144 165 { 145 166 } 146 167 147 bool AtomNotDescriptor ::predicate(std::pair<int,atom*> atom){168 bool AtomNotDescriptor_impl::predicate(std::pair<int,atom*> atom){ 148 169 return !(arg->predicate(atom)); 149 170 } 150 171 151 AtomAndDescriptor::desc_ptr AtomNotDescriptor::clone() const{ 152 return desc_ptr(new AtomNotDescriptor(*arg)); 172 AtomDescriptor operator!(const AtomDescriptor &arg){ 173 AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomNotDescriptor_impl(arg.get_impl())); 174 return AtomDescriptor(newImpl); 153 175 } 154 155 AtomNotDescriptor operator!(const AtomDescriptor &arg){156 return AtomNotDescriptor(arg);157 } -
src/Descriptors/AtomDescriptor.hpp
rd1c5e2 r7a1ce5 17 17 class atom; 18 18 19 class AtomDescriptor 20 { 19 // internal implementation, allows assignment, copying etc 20 class AtomDescripter_impl; 21 22 class AtomDescriptor { 23 friend atom* World::getAtom(AtomDescriptor descriptor); 24 friend std::vector<atom*> World::getAllAtoms(AtomDescriptor descriptor); 25 26 friend AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs); 27 friend AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs); 28 friend AtomDescriptor operator!(const AtomDescriptor &arg); 29 21 30 public: 31 typedef boost::shared_ptr<AtomDescriptor_impl> impl_ptr; 22 32 23 typedef boost::shared_ptr<AtomDescriptor> desc_ptr; 33 AtomDescriptor(impl_ptr); 34 AtomDescriptor(const AtomDescriptor&); 35 ~AtomDescriptor(); 24 36 25 friend atom* World::getAtom(AtomDescriptor& descriptor); 26 friend std::vector<atom*> World::getAllAtoms(AtomDescriptor& descriptor); 27 28 AtomDescriptor(); 29 virtual ~AtomDescriptor(); 30 AtomDescriptor(const AtomDescriptor&); 31 32 virtual bool predicate(std::pair<int,atom*>)=0; 33 // clone is only used internally to generate operators 34 virtual desc_ptr clone() const=0; 37 AtomDescriptor &operator=(AtomDescriptor &); 35 38 36 39 protected: 37 virtual atom* find(); 38 virtual std::vector<atom*> findAll(); 39 std::map<int,atom*>& getAtoms(); 40 atom* find(); 41 std::vector<atom*> findAll(); 42 impl_ptr get_impl() const; 43 44 private: 45 impl_ptr impl; 40 46 }; 41 47 42 class AtomAndDescriptor : public AtomDescriptor 43 { 44 friend AtomAndDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs); 45 public: 46 AtomAndDescriptor(const AtomAndDescriptor&); 47 ~AtomAndDescriptor(); 48 49 virtual desc_ptr clone() const; 50 virtual bool predicate(std::pair<int,atom*>); 51 52 private: 53 desc_ptr lhs; 54 desc_ptr rhs; 55 56 // private constructor to enforce construction through operators 57 AtomAndDescriptor(const AtomDescriptor &_lhs, const AtomDescriptor &_rhs); 58 }; 59 60 class AtomOrDescriptor : public AtomDescriptor 61 { 62 friend AtomOrDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs); 63 public: 64 AtomOrDescriptor(const AtomOrDescriptor &); 65 ~AtomOrDescriptor(); 66 67 virtual desc_ptr clone() const; 68 virtual bool predicate(std::pair<int,atom*>); 69 70 private: 71 desc_ptr lhs; 72 desc_ptr rhs; 73 74 // private constructor to enforce construction through operators 75 AtomOrDescriptor(const AtomDescriptor &_lhs, const AtomDescriptor &_rhs); 76 }; 77 78 class AtomNotDescriptor : public AtomDescriptor 79 { 80 friend AtomNotDescriptor operator!(const AtomDescriptor &arg); 81 public: 82 AtomNotDescriptor(const AtomNotDescriptor &); 83 ~AtomNotDescriptor(); 84 85 virtual desc_ptr clone() const; 86 virtual bool predicate(std::pair<int,atom*>); 87 88 private: 89 desc_ptr arg; 90 91 // protected constructor to enforce construction through operators 92 AtomNotDescriptor(const AtomDescriptor &_arg); 93 }; 48 // Functions to construct actual descriptors 49 AtomDescriptor AllAtoms(); 50 AtomDescriptor NoAtoms(); 94 51 95 52 // no true short circuit, but the test of the second descriptor wont be done 96 Atom AndDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);97 Atom OrDescriptoroperator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs);98 Atom NotDescriptor operator!(const AtomDescriptor &arg);53 AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs); 54 AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs); 55 AtomDescriptor operator!(const AtomDescriptor &arg); 99 56 100 57 #endif /* ATOMDESCRIPTOR_HPP_ */ -
src/Descriptors/AtomIdDescriptor.cpp
rd1c5e2 r7a1ce5 7 7 8 8 #include "AtomIdDescriptor.hpp" 9 #include "AtomIdDescriptor_impl.hpp" 9 10 10 11 #include "atom.hpp" … … 12 13 using namespace std; 13 14 14 AtomIdDescriptor::AtomIdDescriptor(int _id) : 15 16 AtomIdDescriptor_impl::AtomIdDescriptor_impl(int _id) : 15 17 id(_id) 16 18 {} 17 19 18 AtomIdDescriptor ::~AtomIdDescriptor()20 AtomIdDescriptor_impl::~AtomIdDescriptor_impl() 19 21 {} 20 22 21 bool AtomIdDescriptor ::predicate(std::pair<int,atom*> atom) {23 bool AtomIdDescriptor_impl::predicate(std::pair<int,atom*> atom) { 22 24 return atom.second->getId()==id; 23 25 } 24 26 25 AtomDescriptor ::desc_ptr AtomIdDescriptor::clone() const{26 return desc_ptr(new AtomIdDescriptor(id));27 AtomDescriptor AtomById(int id){ 28 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomIdDescriptor_impl(id))); 27 29 } 28 30 -
src/Descriptors/AtomIdDescriptor.hpp
rd1c5e2 r7a1ce5 11 11 #include "Descriptors/AtomDescriptor.hpp" 12 12 13 class AtomIdDescriptor : public AtomDescriptor 14 { 15 public: 16 AtomIdDescriptor(int _id); 17 virtual ~AtomIdDescriptor(); 18 19 bool predicate(std::pair<int,atom*> atom); 20 21 virtual desc_ptr clone() const; 22 23 protected: 24 #if 0 25 atom *find(); 26 std::vector<atom*> findAll(); 27 #endif 28 private: 29 int id; 30 }; 13 AtomDescriptor AtomById(int id); 31 14 32 15 #endif /* ATOMIDDESCRIPTOR_HPP_ */ -
src/World.cpp
rd1c5e2 r7a1ce5 18 18 } 19 19 20 atom* World::getAtom(AtomDescriptor &descriptor){20 atom* World::getAtom(AtomDescriptor descriptor){ 21 21 return descriptor.find(); 22 22 } 23 23 24 vector<atom*> World::getAllAtoms(AtomDescriptor &descriptor){24 vector<atom*> World::getAllAtoms(AtomDescriptor descriptor){ 25 25 return descriptor.findAll(); 26 26 } … … 34 34 35 35 36 World::World() 36 World::World() : 37 dummyId(0) 37 38 {} 38 39 … … 87 88 void World::registerAtom(atom *theAtom){ 88 89 OBSERVE; 89 atoms[ theAtom->getId()] = theAtom;90 atoms[dummyId++] = theAtom; 90 91 } 91 92 -
src/World.hpp
rd1c5e2 r7a1ce5 21 21 class atom; 22 22 class AtomDescriptor; 23 class AtomDescriptor_impl; 23 24 24 25 class World : public Observable 25 26 { 26 friend class AtomDescriptor ;27 friend class AtomDescriptor_impl; 27 28 public: 28 29 29 30 /***** getter and setter *****/ 30 31 periodentafel* getPeriode(); 31 atom* getAtom(AtomDescriptor &descriptor);32 std::vector<atom*> getAllAtoms(AtomDescriptor &descriptor);32 atom* getAtom(AtomDescriptor descriptor); 33 std::vector<atom*> getAllAtoms(AtomDescriptor descriptor); 33 34 private: 34 35 periodentafel *periode; … … 63 64 private: 64 65 MoleculeListClass *molecules; 66 67 // this is needed to assign unique IDs to atoms... so far 68 // IDs are not assigned upon Atom creation, so we cannot query the ID 69 // during construction. By using the dummy ID we can make sure all atoms 70 // are actually stored in the map and don't overwrite each other. 71 int dummyId; 65 72 }; 66 73 -
src/atom_particleinfo.hpp
rd1c5e2 r7a1ce5 35 35 ostream & operator << (ostream &ost) const; 36 36 37 int getId();37 virtual int getId(); 38 38 39 39 private: -
src/unittests/Makefile.am
rd1c5e2 r7a1ce5 29 29 ObserverTest \ 30 30 CacheableTest \ 31 DescriptorUnittest \ 31 32 ${MENUTESTS} 32 33 … … 107 108 CacheableTest_LDADD = ${ALLLIBS} 108 109 110 DescriptorUnittest_SOURCES = DescriptorUnittest.cpp DescriptorUnittest.hpp 111 DescriptorUnittest_LDADD = ${ALLLIBS} 112 109 113 #AUTOMAKE_OPTIONS = parallel-tests 110 114
Note:
See TracChangeset
for help on using the changeset viewer.