source: src/molecule_template.hpp@ 05a97c

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 05a97c was 9879f6, checked in by Frederik Heber <heber@…>, 15 years ago

Huge Refactoring due to class molecule now being an STL container.

  • molecule::start and molecule::end were dropped. Hence, the usual construct Walker = start while (Walker->next != end) {

Walker = walker->next
...

}
was changed to
for (molecule::iterator iter = begin(); iter != end(); ++iter) {

...

}
and (*iter) used instead of Walker.

  • Two build errors remain (beside some more in folder Actions, Patterns and unittest) in molecule_pointcloud.cpp and molecule.cpp
  • lists.cpp was deleted as specialization of atom* was not needed anymore
  • link, unlink, add, remove, removewithoutcheck all are not needed for atoms anymore, just for bonds (where first, last entries remain in molecule)
  • CreateFatherLookupTable() was put back into class molecule.
  • molecule::InternalPointer is now an iterator
  • class PointCloud: GoToPrevious() and GetTerminalPoint() were dropped as not needed.
  • some new STL functions in class molecule: size(), empty(), erase(), find() and insert()
  • Property mode set to 100644
File size: 15.9 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 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
27 (((*iter)->node)->*f)();
28 }
29};
30template <typename res> void molecule::ActOnAllVectors( res (Vector::*f)() const ) const
31 {
32 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
33 (((*iter)->node)->*f)();
34 }
35};
36// one argument
37template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T), T t ) const
38{
39 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
40 (((*iter)->node)->*f)(t);
41 }
42};
43template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T) const, T t ) const
44{
45 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
46 (((*iter)->node)->*f)(t);
47 }
48};
49// two arguments
50template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const
51{
52 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
53 (((*iter)->node)->*f)(t, u);
54 }
55};
56template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const
57{
58 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
59 (((*iter)->node)->*f)(t, u);
60 }
61};
62// three arguments
63template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v) const
64{
65 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
66 (((*iter)->node)->*f)(t, u, v);
67 }
68};
69template <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
70{
71 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
72 (((*iter)->node)->*f)(t, u, v);
73 }
74};
75
76// ========================= Summing over each Atoms =================================== //
77
78// zero arguments
79template <typename res, typename typ> res molecule::SumPerAtom(res (typ::*f)() ) const
80{
81 res result = 0;
82 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
83 result += ((*iter)->*f)();
84 }
85 return result;
86};
87template <typename res, typename typ> res molecule::SumPerAtom(res (typ::*f)() const ) const
88{
89 res result = 0;
90 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
91 result += ((*iter)->*f)();
92 }
93 return result;
94};
95// one argument
96template <typename res, typename typ, typename T> res molecule::SumPerAtom(res (typ::*f)(T), T t ) const
97{
98 res result = 0;
99 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
100 result += ((*iter)->*f)(t);
101 }
102 return result;
103};
104template <typename res, typename typ, typename T> res molecule::SumPerAtom(res (typ::*f)(T) const, T t ) const
105{
106 res result = 0;
107 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
108 result += ((*iter)->*f)(t);
109 }
110 return result;
111};
112
113
114// ================== Acting with each Atoms on same molecule ========================== //
115
116// zero arguments
117template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *)) const
118{
119 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
120 (*f)((*iter));
121 }
122};
123template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *) const) const
124{
125 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
126 (*f)((*iter));
127 }
128};
129
130// ================== Acting with each Atoms on copy molecule ========================== //
131
132// zero arguments
133template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const
134{
135 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
136 (copy->*f)((*iter));
137 }
138};
139template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const
140{
141 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
142 (copy->*f)((*iter));
143 }
144};
145
146// ================== Acting with each Atoms on copy molecule if true ========================== //
147
148// zero arguments
149template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () ) const
150{
151 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
152 if (((*iter)->*condition)())
153 (copy->*f)((*iter));
154 }
155};
156template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () const ) const
157{
158 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
159 if (((*iter)->*condition)())
160 (copy->*f)((*iter));
161 }
162};
163template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) () ) const
164{
165 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
166 if (((*iter)->*condition)())
167 (copy->*f)((*iter));
168 }
169};
170template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) () const ) const
171{
172 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
173 if (((*iter)->*condition)())
174 (copy->*f)((*iter));
175 }
176};
177// one argument
178template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t ) const
179{
180 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
181 if (((*iter)->*condition)(t))
182 (copy->*f)((*iter));
183 }
184};
185template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T) const, T t ) const
186{
187 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
188 if (((*iter)->*condition)(t))
189 (copy->*f)((*iter));
190 }
191};
192template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T), T t ) const
193{
194 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
195 if (((*iter)->*condition)(t))
196 (copy->*f)((*iter));
197 }
198};
199template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T) const, T t ) const
200{
201 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
202 if (((*iter)->*condition)(t))
203 (copy->*f)((*iter));
204 }
205};
206// two arguments
207template <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
208{
209 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
210 if (((*iter)->*condition)(t,u))
211 (copy->*f)((*iter));
212 }
213};
214template <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
215{
216 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
217 if (((*iter)->*condition)(t,u))
218 (copy->*f)((*iter));
219 }
220};
221template <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
222{
223 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
224 if (((*iter)->*condition)(t,u))
225 (copy->*f)((*iter));
226 }
227};
228template <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
229{
230 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
231 if (((*iter)->*condition)(t,u))
232 (copy->*f)((*iter));
233 }
234};
235// three arguments
236template <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
237{
238 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
239 if (((*iter)->*condition)(t,u,v))
240 (copy->*f)((*iter));
241 }
242};
243template <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
244{
245 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
246 if (((*iter)->*condition)(t,u,v))
247 (copy->*f)((*iter));
248 }
249};
250template <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
251{
252 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
253 if (((*iter)->*condition)(t,u,v))
254 (copy->*f)((*iter));
255 }
256};
257template <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
258{
259 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
260 if (((*iter)->*condition)(t,u,v))
261 (copy->*f)((*iter));
262 }
263};
264
265// ================== Acting on all Atoms ========================== //
266
267// zero arguments
268template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)()) const
269{
270 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
271 ((*iter)->*f)();
272 }
273};
274template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)() const) const
275{
276 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
277 ((*iter)->*f)();
278 }
279};
280// one argument
281template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T), T t ) const
282{
283 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
284 ((*iter)->*f)(t);
285 }
286};
287template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T) const, T t ) const
288{
289 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
290 ((*iter)->*f)(t);
291 }
292};
293// two argument
294template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U), T t, U u ) const
295{
296 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
297 ((*iter)->*f)(t, u);
298 }
299};
300template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U) const, T t, U u ) const
301{
302 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
303 ((*iter)->*f)(t, u);
304 }
305};
306// three argument
307template <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
308{
309 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
310 ((*iter)->*f)(t, u, v);
311 }
312};
313template <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
314{
315 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
316 ((*iter)->*f)(t, u, v);
317 }
318};
319// four arguments
320template <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
321{
322 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
323 ((*iter)->*f)(t, u, v, w);
324 }
325};
326template <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
327{
328 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
329 ((*iter)->*f)(t, u, v, w);
330 }
331};
332
333// ===================== Accessing arrays indexed by some integer for each atom ======================
334
335// for atom ints
336template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *) ) const
337{
338 int inc = 1;
339 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
340 (*Setor) (&array[((*iter)->*index)], &inc);
341 }
342};
343template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T value ) const
344{
345 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
346 (*Setor) (&array[((*iter)->*index)], &value);
347 }
348};
349template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T *value ) const
350{
351 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
352 (*Setor) (&array[((*iter)->*index)], value);
353 }
354};
355// for element ints
356template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *) ) const
357{
358 int inc = 1;
359 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
360 (*Setor) (&array[((*iter)->type->*index)], &inc);
361 }
362};
363template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T value ) const
364{
365 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
366 (*Setor) (&array[((*iter)->type->*index)], &value);
367 }
368};
369template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T *value ) const
370{
371 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
372 (*Setor) (&array[((*iter)->type->*index)], value);
373 }
374};
375
376template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ atom::*value ) const
377{
378 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
379 array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value);
380 }
381};
382template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ atom::*value ) const
383{
384 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
385 array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value);
386 }
387};
388template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ &vect ) const
389{
390 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
391 array[((*iter)->*index)] = ((*iter)->*Setor) (vect);
392 }
393};
394template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ &vect ) const
395{
396 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
397 array[((*iter)->*index)] = ((*iter)->*Setor) (vect);
398 }
399};
400template <typename T, typename typ, typename typ2> void molecule::SetAtomValueToIndexedArray ( T *array, int typ::*index, T typ2::*value ) const
401{
402 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
403 (*iter)->*value = array[((*iter)->*index)];
404 //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*value); << endl;
405 }
406};
407
408template <typename T, typename typ> void molecule::SetAtomValueToValue ( T value, T typ::*ptr ) const
409{
410 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
411 (*iter)->*ptr = value;
412 //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*ptr) << endl;
413 }
414};
415
416
417#endif /* MOLECULE_TEMPLATE_HPP_ */
Note: See TracBrowser for help on using the repository browser.