source: src/molecule_template.hpp@ 68f03d

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

Prepared interface of Vector Class for transition to VectorComposites

  • Property mode set to 100644
File size: 16.8 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// ================== Acting on all Vectors ========================== //
22
23// zero arguments
24template <typename res> void molecule::ActOnAllVectors( res (Vector::*f)() ) const
25 {
26 atom *Walker = start;
27 while (Walker->next != end) {
28 Walker = Walker->next;
29 ((Walker->node)->*f)();
30 }
31};
32template <typename res> void molecule::ActOnAllVectors( res (Vector::*f)() const ) const
33 {
34 atom *Walker = start;
35 while (Walker->next != end) {
36 Walker = Walker->next;
37 ((Walker->node)->*f)();
38 }
39};
40// one argument
41template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T), T t ) const
42{
43 atom *Walker = start;
44 while (Walker->next != end) {
45 Walker = Walker->next;
46 ((Walker->node)->*f)(t);
47 }
48};
49template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T) const, T t ) const
50{
51 atom *Walker = start;
52 while (Walker->next != end) {
53 Walker = Walker->next;
54 ((Walker->node)->*f)(t);
55 }
56};
57template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&), T &t ) const
58{
59 atom *Walker = start;
60 while (Walker->next != end) {
61 Walker = Walker->next;
62 ((Walker->node)->*f)(t);
63 }
64};
65template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const
66{
67 atom *Walker = start;
68 while (Walker->next != end) {
69 Walker = Walker->next;
70 ((Walker->node)->*f)(t);
71 }
72};
73// two arguments
74template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const
75{
76 atom *Walker = start;
77 while (Walker->next != end) {
78 Walker = Walker->next;
79 ((Walker->node)->*f)(t, u);
80 }
81};
82template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const
83{
84 atom *Walker = start;
85 while (Walker->next != end) {
86 Walker = Walker->next;
87 ((Walker->node)->*f)(t, u);
88 }
89};
90// three arguments
91template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v) const
92{
93 atom *Walker = start;
94 while (Walker->next != end) {
95 Walker = Walker->next;
96 ((Walker->node)->*f)(t, u, v);
97 }
98};
99template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v) const
100{
101 atom *Walker = start;
102 while (Walker->next != end) {
103 Walker = Walker->next;
104 ((Walker->node)->*f)(t, u, v);
105 }
106};
107
108// ========================= Summing over each Atoms =================================== //
109
110// zero arguments
111template <typename res, typename typ> res molecule::SumPerAtom(res (typ::*f)() ) const
112{
113 res result = 0;
114 atom *Walker = start;
115 while (Walker->next != end) {
116 Walker = Walker->next;
117 result += (Walker->*f)();
118 }
119 return result;
120};
121template <typename res, typename typ> res molecule::SumPerAtom(res (typ::*f)() const ) const
122{
123 res result = 0;
124 atom *Walker = start;
125 while (Walker->next != end) {
126 Walker = Walker->next;
127 result += (Walker->*f)();
128 }
129 return result;
130};
131// one argument
132template <typename res, typename typ, typename T> res molecule::SumPerAtom(res (typ::*f)(T), T t ) const
133{
134 res result = 0;
135 atom *Walker = start;
136 while (Walker->next != end) {
137 Walker = Walker->next;
138 result += (Walker->*f)(t);
139 }
140 return result;
141};
142template <typename res, typename typ, typename T> res molecule::SumPerAtom(res (typ::*f)(T) const, T t ) const
143{
144 res result = 0;
145 atom *Walker = start;
146 while (Walker->next != end) {
147 Walker = Walker->next;
148 result += (Walker->*f)(t);
149 }
150 return result;
151};
152
153
154// ================== Acting with each Atoms on same molecule ========================== //
155
156// zero arguments
157template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *)) const
158{
159 atom *Walker = start;
160 while (Walker->next != end) {
161 Walker = Walker->next;
162 (*f)(Walker);
163 }
164};
165template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *) const) const
166{
167 atom *Walker = start;
168 while (Walker->next != end) {
169 Walker = Walker->next;
170 (*f)(Walker);
171 }
172};
173
174// ================== Acting with each Atoms on copy molecule ========================== //
175
176// zero arguments
177template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const
178{
179 atom *Walker = start;
180 while (Walker->next != end) {
181 Walker = Walker->next;
182 (copy->*f)(Walker);
183 }
184};
185template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const
186{
187 atom *Walker = start;
188 while (Walker->next != end) {
189 Walker = Walker->next;
190 (copy->*f)(Walker);
191 }
192};
193
194// ================== Acting with each Atoms on copy molecule if true ========================== //
195
196// zero arguments
197template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () ) const
198{
199 atom *Walker = start;
200 while (Walker->next != end) {
201 Walker = Walker->next;
202 if ((Walker->*condition)())
203 (copy->*f)(Walker);
204 }
205};
206template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () const ) const
207{
208 atom *Walker = start;
209 while (Walker->next != end) {
210 Walker = Walker->next;
211 if ((Walker->*condition)())
212 (copy->*f)(Walker);
213 }
214};
215template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) () ) const
216{
217 atom *Walker = start;
218 while (Walker->next != end) {
219 Walker = Walker->next;
220 if ((Walker->*condition)())
221 (copy->*f)(Walker);
222 }
223};
224template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) () const ) const
225{
226 atom *Walker = start;
227 while (Walker->next != end) {
228 Walker = Walker->next;
229 if ((Walker->*condition)())
230 (copy->*f)(Walker);
231 }
232};
233// one argument
234template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t ) const
235{
236 atom *Walker = start;
237 while (Walker->next != end) {
238 Walker = Walker->next;
239 if ((Walker->*condition)(t))
240 (copy->*f)(Walker);
241 }
242};
243template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T) const, T t ) const
244{
245 atom *Walker = start;
246 while (Walker->next != end) {
247 Walker = Walker->next;
248 if ((Walker->*condition)(t))
249 (copy->*f)(Walker);
250 }
251};
252template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T), T t ) const
253{
254 atom *Walker = start;
255 while (Walker->next != end) {
256 Walker = Walker->next;
257 if ((Walker->*condition)(t))
258 (copy->*f)(Walker);
259 }
260};
261template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T) const, T t ) const
262{
263 atom *Walker = start;
264 while (Walker->next != end) {
265 Walker = Walker->next;
266 if ((Walker->*condition)(t))
267 (copy->*f)(Walker);
268 }
269};
270// two arguments
271template <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
272{
273 atom *Walker = start;
274 while (Walker->next != end) {
275 Walker = Walker->next;
276 if ((Walker->*condition)(t,u))
277 (copy->*f)(Walker);
278 }
279};
280template <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
281{
282 atom *Walker = start;
283 while (Walker->next != end) {
284 Walker = Walker->next;
285 if ((Walker->*condition)(t,u))
286 (copy->*f)(Walker);
287 }
288};
289template <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
290{
291 atom *Walker = start;
292 while (Walker->next != end) {
293 Walker = Walker->next;
294 if ((Walker->*condition)(t,u))
295 (copy->*f)(Walker);
296 }
297};
298template <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
299{
300 atom *Walker = start;
301 while (Walker->next != end) {
302 Walker = Walker->next;
303 if ((Walker->*condition)(t,u))
304 (copy->*f)(Walker);
305 }
306};
307// three arguments
308template <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
309{
310 atom *Walker = start;
311 while (Walker->next != end) {
312 Walker = Walker->next;
313 if ((Walker->*condition)(t,u,v))
314 (copy->*f)(Walker);
315 }
316};
317template <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
318{
319 atom *Walker = start;
320 while (Walker->next != end) {
321 Walker = Walker->next;
322 if ((Walker->*condition)(t,u,v))
323 (copy->*f)(Walker);
324 }
325};
326template <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
327{
328 atom *Walker = start;
329 while (Walker->next != end) {
330 Walker = Walker->next;
331 if ((Walker->*condition)(t,u,v))
332 (copy->*f)(Walker);
333 }
334};
335template <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
336{
337 atom *Walker = start;
338 while (Walker->next != end) {
339 Walker = Walker->next;
340 if ((Walker->*condition)(t,u,v))
341 (copy->*f)(Walker);
342 }
343};
344
345// ================== Acting on all Atoms ========================== //
346
347// zero arguments
348template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)()) const
349{
350 atom *Walker = start;
351 while (Walker->next != end) {
352 Walker = Walker->next;
353 (Walker->*f)();
354 }
355};
356template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)() const) const
357{
358 atom *Walker = start;
359 while (Walker->next != end) {
360 Walker = Walker->next;
361 (Walker->*f)();
362 }
363};
364// one argument
365template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T), T t ) const
366{
367 atom *Walker = start;
368 while (Walker->next != end) {
369 Walker = Walker->next;
370 (Walker->*f)(t);
371 }
372};
373template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T) const, T t ) const
374{
375 atom *Walker = start;
376 while (Walker->next != end) {
377 Walker = Walker->next;
378 (Walker->*f)(t);
379 }
380};
381// two argument
382template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U), T t, U u ) const
383{
384 atom *Walker = start;
385 while (Walker->next != end) {
386 Walker = Walker->next;
387 (Walker->*f)(t, u);
388 }
389};
390template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U) const, T t, U u ) const
391{
392 atom *Walker = start;
393 while (Walker->next != end) {
394 Walker = Walker->next;
395 (Walker->*f)(t, u);
396 }
397};
398// three argument
399template <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
400{
401 atom *Walker = start;
402 while (Walker->next != end) {
403 Walker = Walker->next;
404 (Walker->*f)(t, u, v);
405 }
406};
407template <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
408{
409 atom *Walker = start;
410 while (Walker->next != end) {
411 Walker = Walker->next;
412 (Walker->*f)(t, u, v);
413 }
414};
415// four arguments
416template <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
417{
418 atom *Walker = start;
419 while (Walker->next != end) {
420 Walker = Walker->next;
421 (Walker->*f)(t, u, v, w);
422 }
423};
424template <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
425{
426 atom *Walker = start;
427 while (Walker->next != end) {
428 Walker = Walker->next;
429 (Walker->*f)(t, u, v, w);
430 }
431};
432
433// ===================== Accessing arrays indexed by some integer for each atom ======================
434
435// for atom ints
436template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *) ) const
437{
438 atom *Walker = start;
439 int inc = 1;
440 while (Walker->next != end) {
441 Walker = Walker->next;
442 (*Setor) (&array[(Walker->*index)], &inc);
443 }
444};
445template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T value ) const
446{
447 atom *Walker = start;
448 while (Walker->next != end) {
449 Walker = Walker->next;
450 (*Setor) (&array[(Walker->*index)], &value);
451 }
452};
453template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T *value ) const
454{
455 atom *Walker = start;
456 while (Walker->next != end) {
457 Walker = Walker->next;
458 (*Setor) (&array[(Walker->*index)], value);
459 }
460};
461// for element ints
462template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *) ) const
463{
464 atom *Walker = start;
465 int inc = 1;
466 while (Walker->next != end) {
467 Walker = Walker->next;
468 (*Setor) (&array[(Walker->type->*index)], &inc);
469 }
470};
471template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T value ) const
472{
473 atom *Walker = start;
474 while (Walker->next != end) {
475 Walker = Walker->next;
476 (*Setor) (&array[(Walker->type->*index)], &value);
477 }
478};
479template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T *value ) const
480{
481 atom *Walker = start;
482 while (Walker->next != end) {
483 Walker = Walker->next;
484 (*Setor) (&array[(Walker->type->*index)], value);
485 }
486};
487
488template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ atom::*value ) const
489{
490 atom *Walker = start;
491 while (Walker->next != end) {
492 Walker = Walker->next;
493 array[(Walker->*index)] = (Walker->*Setor) (Walker->*value);
494 }
495};
496template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ atom::*value ) const
497{
498 atom *Walker = start;
499 while (Walker->next != end) {
500 Walker = Walker->next;
501 array[(Walker->*index)] = (Walker->*Setor) (Walker->*value);
502 }
503};
504template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ &vect ) const
505{
506 atom *Walker = start;
507 while (Walker->next != end) {
508 Walker = Walker->next;
509 array[(Walker->*index)] = (Walker->*Setor) (vect);
510 }
511};
512template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ &vect ) const
513{
514 atom *Walker = start;
515 while (Walker->next != end) {
516 Walker = Walker->next;
517 array[(Walker->*index)] = (Walker->*Setor) (vect);
518 }
519};
520template <typename T, typename typ, typename typ2> void molecule::SetAtomValueToIndexedArray ( T *array, int typ::*index, T typ2::*value ) const
521{
522 atom *Walker = start;
523 while (Walker->next != end) {
524 Walker = Walker->next;
525 Walker->*value = array[(Walker->*index)];
526 //Log() << Verbose(2) << *Walker << " gets " << (Walker->*value); << endl;
527 }
528};
529
530template <typename T, typename typ> void molecule::SetAtomValueToValue ( T value, T typ::*ptr ) const
531{
532 atom *Walker = start;
533 while (Walker->next != end) {
534 Walker = Walker->next;
535 Walker->*ptr = value;
536 //Log() << Verbose(2) << *Walker << " gets " << (Walker->*ptr) << endl;
537 }
538};
539
540
541#endif /* MOLECULE_TEMPLATE_HPP_ */
Note: See TracBrowser for help on using the repository browser.