source: src/AtomSet.hpp@ 9e23a3

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

Moved molecule::CreateAdjacencyList over to class BondGraph.

to make this possible we had to:

other changes:

TESTFIXES:

  • the regression test for all Actions mentioned above that don't create adjacency themselves anymore needed to be prepended with --select-all-atoms --create-adjacency.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * AtomSet.hpp
3 *
4 * Created on: Jul 30, 2010
5 * Author: crueger
6 */
7
8#ifndef ATOMSET_HPP_
9#define ATOMSET_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16
17
18#include <functional>
19#include <numeric>
20#include <algorithm>
21#include <boost/foreach.hpp>
22#include <limits>
23
24/**
25 * A simple mixin to give any STL conforming structure fast Vector abilities
26 *
27 * TODO: make this work for maps
28 */
29
30#include "atom.hpp"
31
32// this tests, whether we actually have a Vector
33template <class V>
34struct is_atom{};
35
36template <>
37struct is_atom<atom*>{
38 typedef void wrong_type;
39};
40
41template <class container_type,
42 class iterator_type = typename container_type::iterator,
43 class const_iterator_type = typename container_type::const_iterator>
44class AtomSetMixin : public container_type
45{
46 // when our set carries something besides a atom* this will produce an error
47 typedef typename is_atom<typename container_type::value_type>::wrong_type check_for_atom;
48public:
49 // typedefs for STL conforming structure
50 typedef iterator_type iterator;
51 typedef const_iterator_type const_iterator;
52
53 AtomSetMixin() :
54 container_type()
55 {}
56
57 AtomSetMixin(const container_type& src) :
58 container_type(src)
59 {}
60 virtual ~AtomSetMixin(){}
61
62 /**
63 * translate all Atoms within this set by a specified amount
64 */
65 void translate(const Vector &translater);
66 void addVelocityAtStep(const Vector velocity, unsigned int step);
67
68 template<class Function>
69 void transformNodes(Function f);
70 double totalMass() const;
71 double totalTemperatureAtStep(unsigned int step) const;
72 Vector totalMomentumAtStep(unsigned int step) const;
73
74private:
75 template<class Function>
76 struct workOnNodePointer {
77 workOnNodePointer(Function &_f) : f(_f){}
78 void operator()(atom *atom){
79 atom->setPosition(f(atom->getPosition()));
80 }
81 Function &f;
82 };
83
84 template<class T>
85 struct valueSum {
86 valueSum(T (AtomInfo::*_f)() const,T startValue) :
87 f(_f),
88 value(startValue)
89 {}
90 T operator+(AtomInfo *atom){
91 return value + (atom->*f)();
92 }
93 T operator=(T _value){
94 value = _value;
95 return value;
96 }
97 T (AtomInfo::*f)() const;
98 T value;
99 };
100
101 template<class T>
102 struct stepValueSum {
103 stepValueSum(unsigned int _step, T (AtomInfo::*_f)(unsigned int) const,T startValue) :
104 step(_step),
105 f(_f),
106 value(startValue)
107 {}
108 T operator+(AtomInfo *atom){
109 return value + (atom->*f)(step);
110 }
111 T operator=(T _value){
112 value = _value;
113 return value;
114 }
115 unsigned int step;
116 T (AtomInfo::*f)(unsigned int) const;
117 T value;
118 };
119};
120
121template <class container_type,
122 class iterator_type,
123 class const_iterator_type>
124inline void AtomSetMixin<container_type,iterator_type,const_iterator_type>::translate(const Vector &translater){
125 BOOST_FOREACH(AtomInfo *atom,*this){
126 *(atom) += translater;
127 }
128}
129
130template <class container_type,
131 class iterator_type,
132 class const_iterator_type>
133inline void AtomSetMixin<container_type,iterator_type,const_iterator_type>::addVelocityAtStep(const Vector velocity, unsigned int step){
134 BOOST_FOREACH(AtomInfo *atom,*this){
135 atom->setAtomicVelocityAtStep(step, atom->getAtomicVelocityAtStep(step)+velocity);
136 }
137}
138
139template <class container_type,
140 class iterator_type,
141 class const_iterator_type>
142template<class Function>
143inline void AtomSetMixin<container_type,iterator_type,const_iterator_type>::transformNodes(Function f){
144 std::for_each(this->begin(),
145 this->end(),
146 AtomSetMixin::workOnNodePointer<Function>(f));
147}
148
149template <class container_type,
150 class iterator_type,
151 class const_iterator_type>
152inline double AtomSetMixin<container_type,iterator_type,const_iterator_type>::totalMass() const{
153 return accumulate(this->begin(),this->end(),valueSum<double>(&AtomInfo::getMass,0)).value;
154}
155
156template <class container_type,
157 class iterator_type,
158 class const_iterator_type>
159inline double AtomSetMixin<container_type,iterator_type,const_iterator_type>::totalTemperatureAtStep(unsigned int step) const{
160 return accumulate(this->begin(),this->end(),stepValueSum<double>(step,&AtomInfo::getKineticEnergy,0)).value;
161}
162
163template <class container_type,
164 class iterator_type,
165 class const_iterator_type>
166inline Vector AtomSetMixin<container_type,iterator_type,const_iterator_type>::totalMomentumAtStep(unsigned int step) const{
167 return accumulate(this->begin(),this->end(),stepValueSum<Vector>(step,&AtomInfo::getMomentum,Vector())).value;
168}
169
170// allows simpler definition of AtomSets
171#define ATOMSET(container_type) AtomSetMixin<container_type<atom*> >
172
173#endif /* ATOMSET_HPP_ */
Note: See TracBrowser for help on using the repository browser.