source: src/AtomSet.hpp@ 3f9eba

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 3f9eba was 56f73b, checked in by Frederik Heber <heber@…>, 14 years ago

Added config.h also to all header files, code check test ascertain this in the future.

  • as we want to use config.h to pass stuff such as MEMDEBUG, NDEBUG, LOG_OBSERVER, we have to make sure that it is present in each and every file.
  • split up CodeChecks/testsuite.at: each test has its own .at file.
  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[5a5c47]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
[56f73b]11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16
[5a5c47]17
18#include <functional>
[ddc85b]19#include <numeric>
[5a5c47]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 Set>
42class AtomSetMixin : public Set
43{
44 // when our set carries something besides a atom* this will produce an error
45 typedef typename is_atom<typename Set::value_type>::wrong_type check_for_atom;
46public:
47 // typedefs for STL conforming structure
48 typedef typename Set::iterator iterator;
49 typedef typename Set::const_iterator const_iterator;
50
51 AtomSetMixin() :
52 Set()
53 {}
54
55 AtomSetMixin(const Set& src) :
56 Set(src)
57 {}
58 virtual ~AtomSetMixin(){}
59
60 /**
61 * translate all Atoms within this set by a specified amount
62 */
[a33ea5]63 void translate(const Vector &translater);
[5ac690]64 void addVelocityAtStep(const Vector velocity, unsigned int step);
[a33ea5]65
66 template<class Function>
67 void transformNodes(Function f);
[cddda7]68 double totalMass() const;
[5e99bc]69 double totalTemperatureAtStep(unsigned int step) const;
70 Vector totalMomentumAtStep(unsigned int step) const;
[a33ea5]71
72private:
73 template<class Function>
74 struct workOnNodePointer {
75 workOnNodePointer(Function &_f) : f(_f){}
76 void operator()(atom *atom){
[8f4df1]77 atom->setPosition(f(atom->getPosition()));
[5a5c47]78 }
[a33ea5]79 Function &f;
80 };
[ddc85b]81
[cddda7]82 template<class T>
83 struct valueSum {
[5e99bc]84 valueSum(T (atom::*_f)() const,T startValue) :
[cddda7]85 f(_f),
[5e99bc]86 value(startValue)
[cddda7]87 {}
88 T operator+(atom *atom){
89 return value + (atom->*f)();
[ddc85b]90 }
[5e99bc]91 T operator=(T _value){
[cddda7]92 value = _value;
93 return value;
94 }
95 T (atom::*f)() const;
96 T value;
97 };
98
99 template<class T>
100 struct stepValueSum {
[5e99bc]101 stepValueSum(unsigned int _step, T (atom::*_f)(unsigned int) const,T startValue) :
[cddda7]102 step(_step),
103 f(_f),
[5e99bc]104 value(startValue)
[cddda7]105 {}
106 T operator+(atom *atom){
107 return value + (atom->*f)(step);
108 }
[5e99bc]109 T operator=(T _value){
[ddc85b]110 value = _value;
111 return value;
112 }
113 unsigned int step;
[cddda7]114 T (atom::*f)(unsigned int) const;
115 T value;
[ddc85b]116 };
[5a5c47]117};
118
[a33ea5]119template<class Set>
120inline void AtomSetMixin<Set>::translate(const Vector &translater){
121 BOOST_FOREACH(atom *atom,*this){
[8f4df1]122 *(atom) += translater;
[a33ea5]123 }
124}
125
[5ac690]126template<class Set>
127inline void AtomSetMixin<Set>::addVelocityAtStep(const Vector velocity, unsigned int step){
128 BOOST_FOREACH(atom *atom,*this){
129 atom->Trajectory.U.at(step) += velocity;
130 }
131}
132
[a33ea5]133template<class Set>
134template<class Function>
135inline void AtomSetMixin<Set>::transformNodes(Function f){
136 std::for_each(this->begin(),
137 this->end(),
138 AtomSetMixin::workOnNodePointer<Function>(f));
139}
140
[5e99bc]141template<class Set>
142inline double AtomSetMixin<Set>::totalMass() const{
143 return accumulate(this->begin(),this->end(),valueSum<double>(&atom::getMass,0)).value;
144}
145
[ddc85b]146template<class Set>
147inline double AtomSetMixin<Set>::totalTemperatureAtStep(unsigned int step) const{
[5e99bc]148 return accumulate(this->begin(),this->end(),stepValueSum<double>(step,&atom::getKineticEnergy,0)).value;
[cddda7]149}
150
151template<class Set>
[5e99bc]152inline Vector AtomSetMixin<Set>::totalMomentumAtStep(unsigned int step) const{
153 return accumulate(this->begin(),this->end(),stepValueSum<Vector>(step,&atom::getMomentum,Vector())).value;
[ddc85b]154}
155
[5a5c47]156// allows simpler definition of AtomSets
157#define ATOMSET(container_type) AtomSetMixin<container_type<atom*> >
158
159#endif /* ATOMSET_HPP_ */
Note: See TracBrowser for help on using the repository browser.