source: src/molecule_template.hpp@ c66537

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 c66537 was d74077, checked in by Frederik Heber <heber@…>, 15 years ago

Member variable Vector and element of class atom are now private.

  • Property mode set to 100644
File size: 14.0 KB
Line 
1/*
2 * molecule_template.hpp
3 *
4 * Created on: Oct 6, 2009
5 * Author: heber
6 */
7
8#ifndef MOLECULE_TEMPLATE_HPP_
9#define MOLECULE_TEMPLATE_HPP_
10
11/*********************************************** includes ***********************************/
12
13// include config.h
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include "atom.hpp"
19/********************************************** declarations *******************************/
20
21
22// ========================= Summing over each Atoms =================================== //
23
24// zero arguments
25template <typename res, typename typ> res molecule::SumPerAtom(res (typ::*f)() ) const
26{
27 res result = 0;
28 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
29 result += ((*iter)->*f)();
30 }
31 return result;
32};
33template <typename res, typename typ> res molecule::SumPerAtom(res (typ::*f)() const ) const
34{
35 res result = 0;
36 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
37 result += ((*iter)->*f)();
38 }
39 return result;
40};
41// one argument
42template <typename res, typename typ, typename T> res molecule::SumPerAtom(res (typ::*f)(T), T t ) const
43{
44 res result = 0;
45 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
46 result += ((*iter)->*f)(t);
47 }
48 return result;
49};
50template <typename res, typename typ, typename T> res molecule::SumPerAtom(res (typ::*f)(T) const, T t ) const
51{
52 res result = 0;
53 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
54 result += ((*iter)->*f)(t);
55 }
56 return result;
57};
58
59
60// ================== Acting with each Atoms on same molecule ========================== //
61
62// zero arguments
63template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *)) const
64{
65 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
66 (*f)((*iter));
67 }
68};
69template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *) const) const
70{
71 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
72 (*f)((*iter));
73 }
74};
75
76// ================== Acting with each Atoms on copy molecule ========================== //
77
78// zero arguments
79template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const
80{
81 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
82 (copy->*f)((*iter));
83 }
84};
85template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const
86{
87 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
88 (copy->*f)((*iter));
89 }
90};
91
92// ================== Acting with each Atoms on copy molecule if true ========================== //
93
94// zero arguments
95template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () ) const
96{
97 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
98 if (((*iter)->*condition)())
99 (copy->*f)((*iter));
100 }
101};
102template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () const ) const
103{
104 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
105 if (((*iter)->*condition)())
106 (copy->*f)((*iter));
107 }
108};
109template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) () ) const
110{
111 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
112 if (((*iter)->*condition)())
113 (copy->*f)((*iter));
114 }
115};
116template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) () const ) const
117{
118 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
119 if (((*iter)->*condition)())
120 (copy->*f)((*iter));
121 }
122};
123// one argument
124template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t ) const
125{
126 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
127 if (((*iter)->*condition)(t))
128 (copy->*f)((*iter));
129 }
130};
131template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T) const, T t ) const
132{
133 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
134 if (((*iter)->*condition)(t))
135 (copy->*f)((*iter));
136 }
137};
138template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T), T t ) const
139{
140 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
141 if (((*iter)->*condition)(t))
142 (copy->*f)((*iter));
143 }
144};
145template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T) const, T t ) const
146{
147 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
148 if (((*iter)->*condition)(t))
149 (copy->*f)((*iter));
150 }
151};
152// two arguments
153template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const
154{
155 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
156 if (((*iter)->*condition)(t,u))
157 (copy->*f)((*iter));
158 }
159};
160template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const
161{
162 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
163 if (((*iter)->*condition)(t,u))
164 (copy->*f)((*iter));
165 }
166};
167template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const
168{
169 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
170 if (((*iter)->*condition)(t,u))
171 (copy->*f)((*iter));
172 }
173};
174template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const
175{
176 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
177 if (((*iter)->*condition)(t,u))
178 (copy->*f)((*iter));
179 }
180};
181// three arguments
182template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const
183{
184 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
185 if (((*iter)->*condition)(t,u,v))
186 (copy->*f)((*iter));
187 }
188};
189template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const
190{
191 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
192 if (((*iter)->*condition)(t,u,v))
193 (copy->*f)((*iter));
194 }
195};
196template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const
197{
198 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
199 if (((*iter)->*condition)(t,u,v))
200 (copy->*f)((*iter));
201 }
202};
203template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const
204{
205 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
206 if (((*iter)->*condition)(t,u,v))
207 (copy->*f)((*iter));
208 }
209};
210
211// ================== Acting on all Atoms ========================== //
212
213// zero arguments
214template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)()) const
215{
216 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
217 ((*iter)->*f)();
218 }
219};
220template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)() const) const
221{
222 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
223 ((*iter)->*f)();
224 }
225};
226// one argument
227template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T), T t ) const
228{
229 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
230 ((*iter)->*f)(t);
231 }
232};
233template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T) const, T t ) const
234{
235 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
236 ((*iter)->*f)(t);
237 }
238};
239// two argument
240template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U), T t, U u ) const
241{
242 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
243 ((*iter)->*f)(t, u);
244 }
245};
246template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U) const, T t, U u ) const
247{
248 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
249 ((*iter)->*f)(t, u);
250 }
251};
252// three argument
253template <typename res, typename typ, typename T, typename U, typename V> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V), T t, U u, V v) const
254{
255 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
256 ((*iter)->*f)(t, u, v);
257 }
258};
259template <typename res, typename typ, typename T, typename U, typename V> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V) const, T t, U u, V v) const
260{
261 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
262 ((*iter)->*f)(t, u, v);
263 }
264};
265// four arguments
266template <typename res, typename typ, typename T, typename U, typename V, typename W> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V, W), T t, U u, V v, W w) const
267{
268 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
269 ((*iter)->*f)(t, u, v, w);
270 }
271};
272template <typename res, typename typ, typename T, typename U, typename V, typename W> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V, W) const, T t, U u, V v, W w) const
273{
274 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
275 ((*iter)->*f)(t, u, v, w);
276 }
277};
278
279// ===================== Accessing arrays indexed by some integer for each atom ======================
280
281// for atom ints
282template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *) ) const
283{
284 int inc = 1;
285 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
286 (*Setor) (&array[((*iter)->*index)], &inc);
287 }
288};
289template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T value ) const
290{
291 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
292 (*Setor) (&array[((*iter)->*index)], &value);
293 }
294};
295template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T *value ) const
296{
297 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
298 (*Setor) (&array[((*iter)->*index)], value);
299 }
300};
301// for element ints
302template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *) ) const
303{
304 int inc = 1;
305 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
306 (*Setor) (&array[((*iter)->getType()->*index)], &inc);
307 }
308};
309template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T value ) const
310{
311 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
312 (*Setor) (&array[((*iter)->getType()->*index)], &value);
313 }
314};
315template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T *value ) const
316{
317 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
318 (*Setor) (&array[((*iter)->getType()->*index)], value);
319 }
320};
321
322template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ atom::*value ) const
323{
324 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
325 array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value);
326 }
327};
328template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ atom::*value ) const
329{
330 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
331 array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value);
332 }
333};
334template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ &vect ) const
335{
336 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
337 array[((*iter)->*index)] = ((*iter)->*Setor) (vect);
338 }
339};
340template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ &vect ) const
341{
342 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
343 array[((*iter)->*index)] = ((*iter)->*Setor) (vect);
344 }
345};
346template <typename T, typename typ, typename typ2> void molecule::SetAtomValueToIndexedArray ( T *array, int typ::*index, T typ2::*value ) const
347{
348 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
349 (*iter)->*value = array[((*iter)->*index)];
350 //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*value); << endl;
351 }
352};
353
354template <typename T, typename typ> void molecule::SetAtomValueToValue ( T value, T typ::*ptr ) const
355{
356 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
357 (*iter)->*ptr = value;
358 //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*ptr) << endl;
359 }
360};
361
362
363#endif /* MOLECULE_TEMPLATE_HPP_ */
Note: See TracBrowser for help on using the repository browser.