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