source: src/atom_atominfo.cpp@ 056e70

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 Candidate_v1.7.0 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 056e70 was 056e70, checked in by Frederik Heber <heber@…>, 15 years ago

Suffixed getters and setters for AtomInfo trajecories with AtStep.

  • AtomInfo:: getters are now const members
  • added lots of ASSERTS to getters with time step to assure no out-of-bounds access.
  • Property mode set to 100644
File size: 12.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * atom_atominfo.cpp
10 *
11 * Created on: Oct 19, 2009
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "CodePatterns/Log.hpp"
23#include "CodePatterns/Verbose.hpp"
24#include "config.hpp"
25#include "element.hpp"
26#include "parser.hpp"
27#include "periodentafel.hpp"
28#include "World.hpp"
29#include "atom_atominfo.hpp"
30
31/** Constructor of class AtomInfo.
32 */
33AtomInfo::AtomInfo() :
34 AtomicElement(NULL),
35 FixedIon(false)
36{
37 AtomicPosition.reserve(1);
38 AtomicPosition.push_back(zeroVec);
39 AtomicVelocity.reserve(1);
40 AtomicVelocity.push_back(zeroVec);
41 AtomicForce.reserve(1);
42 AtomicForce.push_back(zeroVec);
43};
44
45/** Copy constructor of class AtomInfo.
46 */
47AtomInfo::AtomInfo(const AtomInfo &_atom) :
48 AtomicPosition(_atom.AtomicPosition),
49 AtomicElement(_atom.AtomicElement),
50 FixedIon(false)
51{
52 AtomicVelocity.reserve(1);
53 AtomicVelocity.push_back(zeroVec);
54 AtomicForce.reserve(1);
55 AtomicForce.push_back(zeroVec);
56};
57
58AtomInfo::AtomInfo(const VectorInterface &_v) :
59 AtomicElement(NULL),
60 FixedIon(false)
61{
62 AtomicPosition[0] = _v.getPosition();
63 AtomicVelocity.reserve(1);
64 AtomicVelocity.push_back(zeroVec);
65 AtomicForce.reserve(1);
66 AtomicForce.push_back(zeroVec);
67};
68
69/** Destructor of class AtomInfo.
70 */
71AtomInfo::~AtomInfo()
72{
73};
74
75const element *AtomInfo::getType() const
76{
77 return AtomicElement;
78}
79
80const double& AtomInfo::operator[](size_t i) const
81{
82 ASSERT(AtomicPosition.size() > 0,
83 "AtomInfo::operator[]() - Access out of range.");
84 return AtomicPosition[0][i];
85}
86
87const double& AtomInfo::at(size_t i) const
88{
89 ASSERT(AtomicPosition.size() > 0,
90 "AtomInfo::at() - Access out of range.");
91 return AtomicPosition[0].at(i);
92}
93
94const double& AtomInfo::atStep(size_t i, int _step) const
95{
96 ASSERT(AtomicPosition.size() > _step,
97 "AtomInfo::atStep() - Access out of range.");
98 return AtomicPosition[_step].at(i);
99}
100
101void AtomInfo::set(size_t i, const double value)
102{
103 ASSERT(AtomicPosition.size() > 0,
104 "AtomInfo::set() - Access out of range.");
105 AtomicPosition[0].at(i) = value;
106}
107
108const Vector& AtomInfo::getPosition() const
109{
110 ASSERT(AtomicPosition.size() > 0,
111 "AtomInfo::getPosition() - Access out of range.");
112 return AtomicPosition[0];
113}
114
115const Vector& AtomInfo::getPositionAtStep(const int _step) const
116{
117 ASSERT(_step < AtomicPosition.size(),
118 "AtomInfo::getPositionAtStep() - Access out of range.");
119 return AtomicPosition[_step];
120}
121
122void AtomInfo::setType(const element* _type) {
123 AtomicElement = _type;
124}
125
126void AtomInfo::setType(const int Z) {
127 const element *elem = World::getInstance().getPeriode()->FindElement(Z);
128 setType(elem);
129}
130
131//Vector& AtomInfo::getAtomicVelocity()
132//{
133// return AtomicVelocity[0];
134//}
135
136//Vector& AtomInfo::getAtomicVelocity(const int _step)
137//{
138// ASSERT(_step < AtomicVelocity.size(),
139// "AtomInfo::getAtomicVelocity() - Access out of range.");
140// return AtomicVelocity[_step];
141//}
142
143const Vector& AtomInfo::getAtomicVelocity() const
144{
145 ASSERT(AtomicVelocity.size() > 0,
146 "AtomInfo::getAtomicVelocity() - Access out of range.");
147 return AtomicVelocity[0];
148}
149
150const Vector& AtomInfo::getAtomicVelocityAtStep(const int _step) const
151{
152 ASSERT(_step < AtomicVelocity.size(),
153 "AtomInfo::getAtomicVelocity() - Access out of range.");
154 return AtomicVelocity[_step];
155}
156
157void AtomInfo::setAtomicVelocity(const Vector &_newvelocity)
158{
159 ASSERT(0 < AtomicVelocity.size(),
160 "AtomInfo::setAtomicVelocity() - Access out of range.");
161 AtomicVelocity[0] = _newvelocity;
162}
163
164void AtomInfo::setAtomicVelocityAtStep(const int _step, const Vector &_newvelocity)
165{
166 ASSERT(_step <= AtomicVelocity.size(),
167 "AtomInfo::setAtomicVelocityAtStep() - Access out of range.");
168 if(_step < (int)AtomicVelocity.size()) {
169 AtomicVelocity[_step] = _newvelocity;
170 } else if (_step == (int)AtomicVelocity.size()) {
171 AtomicVelocity.push_back(_newvelocity);
172 }
173}
174
175const Vector& AtomInfo::getAtomicForce() const
176{
177 ASSERT(0 < AtomicForce.size(),
178 "AtomInfo::getAtomicForce() - Access out of range.");
179 return AtomicForce[0];
180}
181
182const Vector& AtomInfo::getAtomicForceAtStep(const int _step) const
183{
184 ASSERT(_step < AtomicForce.size(),
185 "AtomInfo::getAtomicForce() - Access out of range.");
186 return AtomicForce[_step];
187}
188
189void AtomInfo::setAtomicForce(const Vector &_newforce)
190{
191 ASSERT(0 < AtomicForce.size(),
192 "AtomInfo::setAtomicForce() - Access out of range.");
193 AtomicForce[0] = _newforce;
194}
195
196void AtomInfo::setAtomicForceAtStep(const int _step, const Vector &_newforce)
197{
198 const int size = AtomicForce.size();
199 ASSERT(_step <= size,
200 "AtomInfo::setAtomicForce() - Access out of range.");
201 if(_step < size) {
202 AtomicForce[_step] = _newforce;
203 } else if (_step == size) {
204 AtomicForce.push_back(_newforce);
205 }
206}
207
208bool AtomInfo::getFixedIon() const
209{
210 return FixedIon;
211}
212
213void AtomInfo::setFixedIon(const bool _fixedion)
214{
215 FixedIon = _fixedion;
216}
217
218void AtomInfo::setPosition(const Vector& _vector)
219{
220 ASSERT(0 < AtomicPosition.size(),
221 "AtomInfo::setPosition() - Access out of range.");
222 AtomicPosition[0] = _vector;
223 //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl;
224}
225
226void AtomInfo::setPositionAtStep(int _step, const Vector& _vector)
227{
228 ASSERT(_step <= AtomicPosition.size(),
229 "AtomInfo::setPosition() - Access out of range.");
230 if(_step < (int)AtomicPosition.size()) {
231 AtomicPosition[_step] = _vector;
232 } else if (_step == (int)AtomicPosition.size()) {
233 AtomicPosition.push_back(_vector);
234 }
235 //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl;
236}
237
238const VectorInterface& AtomInfo::operator+=(const Vector& b)
239{
240 ASSERT(0 < AtomicPosition.size(),
241 "AtomInfo::operator+=() - Access out of range.");
242 AtomicPosition[0] += b;
243 return *this;
244}
245
246const VectorInterface& AtomInfo::operator-=(const Vector& b)
247{
248 ASSERT(0 < AtomicPosition.size(),
249 "AtomInfo::operator-=() - Access out of range.");
250 AtomicPosition[0] -= b;
251 return *this;
252}
253
254Vector const AtomInfo::operator+(const Vector& b) const
255{
256 ASSERT(0 < AtomicPosition.size(),
257 "AtomInfo::operator+() - Access out of range.");
258 Vector a(AtomicPosition[0]);
259 a += b;
260 return a;
261}
262
263Vector const AtomInfo::operator-(const Vector& b) const
264{
265 ASSERT(0 < AtomicPosition.size(),
266 "AtomInfo::operator-() - Access out of range.");
267 Vector a(AtomicPosition[0]);
268 a -= b;
269 return a;
270}
271
272double AtomInfo::distance(const Vector &point) const
273{
274 ASSERT(0 < AtomicPosition.size(),
275 "AtomInfo::distance() - Access out of range.");
276 return AtomicPosition[0].distance(point);
277}
278
279double AtomInfo::DistanceSquared(const Vector &y) const
280{
281 ASSERT(0 < AtomicPosition.size(),
282 "AtomInfo::DistanceSquared() - Access out of range.");
283 return AtomicPosition[0].DistanceSquared(y);
284}
285
286double AtomInfo::distance(const VectorInterface &_atom) const
287{
288 ASSERT(0 < AtomicPosition.size(),
289 "AtomInfo::distance() - Access out of range.");
290 return _atom.distance(AtomicPosition[0]);
291}
292
293double AtomInfo::DistanceSquared(const VectorInterface &_atom) const
294{
295 ASSERT(0 < AtomicPosition.size(),
296 "AtomInfo::DistanceSquared() - Access out of range.");
297 return _atom.DistanceSquared(AtomicPosition[0]);
298}
299
300VectorInterface &AtomInfo::operator=(const Vector& _vector)
301{
302 ASSERT(0 < AtomicPosition.size(),
303 "AtomInfo::operator=() - Access out of range.");
304 AtomicPosition[0] = _vector;
305 return *this;
306}
307
308void AtomInfo::ScaleAll(const double *factor)
309{
310 ASSERT(0 < AtomicPosition.size(),
311 "AtomInfo::ScaleAll() - Access out of range.");
312 AtomicPosition[0].ScaleAll(factor);
313}
314
315void AtomInfo::ScaleAll(const Vector &factor)
316{
317 ASSERT(0 < AtomicPosition.size(),
318 "AtomInfo::ScaleAll() - Access out of range.");
319 AtomicPosition[0].ScaleAll(factor);
320}
321
322void AtomInfo::Scale(const double factor)
323{
324 ASSERT(0 < AtomicPosition.size(),
325 "AtomInfo::Scale() - Access out of range.");
326 AtomicPosition[0].Scale(factor);
327}
328
329void AtomInfo::Zero()
330{
331 ASSERT(0 < AtomicPosition.size(),
332 "AtomInfo::Zero() - Access out of range.");
333 AtomicPosition[0].Zero();
334}
335
336void AtomInfo::One(const double one)
337{
338 ASSERT(0 < AtomicPosition.size(),
339 "AtomInfo::One() - Access out of range.");
340 AtomicPosition[0].One(one);
341}
342
343void AtomInfo::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors)
344{
345 ASSERT(0 < AtomicPosition.size(),
346 "AtomInfo::LinearCombinationOfVectors() - Access out of range.");
347 AtomicPosition[0].LinearCombinationOfVectors(x1,x2,x3,factors);
348}
349
350/**
351 * returns the kinetic energy of this atom at a given time step
352 */
353double AtomInfo::getKineticEnergy(unsigned int _step) const{
354 ASSERT(_step < AtomicPosition.size(),
355 "AtomInfo::getKineticEnergy() - Access out of range.");
356 return getMass() * AtomicVelocity[_step].NormSquared();
357}
358
359Vector AtomInfo::getMomentum(unsigned int _step) const{
360 ASSERT(_step < AtomicPosition.size(),
361 "AtomInfo::getMomentum() - Access out of range.");
362 return getMass()*AtomicVelocity[_step];
363}
364
365/** Extends the trajectory STL vector to the new size.
366 * Does nothing if \a MaxSteps is smaller than current size.
367 * \param MaxSteps
368 */
369void AtomInfo::ResizeTrajectory(size_t MaxSteps)
370{
371 if (AtomicPosition.size() <= (unsigned int)(MaxSteps)) {
372 DoLog(0) && (Log() << Verbose(0) << "Increasing size for trajectory array from " << AtomicPosition.size() << " to " << (MaxSteps+1) << "." << endl);
373 AtomicPosition.resize(MaxSteps+1, zeroVec);
374 AtomicVelocity.resize(MaxSteps+1, zeroVec);
375 AtomicForce.resize(MaxSteps+1, zeroVec);
376 }
377};
378
379size_t AtomInfo::getTrajectorySize() const
380{
381 return AtomicPosition.size();
382}
383
384double AtomInfo::getMass() const{
385 return AtomicElement->getMass();
386}
387
388/** Copies a given trajectory step \a src onto another \a dest
389 * \param dest index of destination step
390 * \param src index of source step
391 */
392void AtomInfo::CopyStepOnStep(int dest, int src)
393{
394 if (dest == src) // self assignment check
395 return;
396
397 ASSERT(dest < AtomicPosition.size(),
398 "AtomInfo::CopyStepOnStep() - destination outside of current trajectory array.");
399 ASSERT(src < AtomicPosition.size(),
400 "AtomInfo::CopyStepOnStep() - source outside of current trajectory array.");
401 for (int n=NDIM;n--;) {
402 AtomicPosition.at(dest)[n] = AtomicPosition.at(src)[n];
403 AtomicVelocity.at(dest)[n] = AtomicVelocity.at(src)[n];
404 AtomicForce.at(dest)[n] = AtomicForce.at(src)[n];
405 }
406};
407
408/** Performs a velocity verlet update of the trajectory.
409 * Parameters are according to those in configuration class.
410 * \param NextStep index of sequential step to set
411 * \param *configuration pointer to configuration with parameters
412 * \param *Force matrix with forces
413 */
414void AtomInfo::VelocityVerletUpdate(int nr, int NextStep, config *configuration, ForceMatrix *Force, const size_t offset)
415{
416 // update force
417 // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a
418 Vector tempVector;
419 for (int d=0; d<NDIM; d++)
420 tempVector[d] = -Force->Matrix[0][nr][d+offset]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.);
421 setAtomicForceAtStep(NextStep, tempVector);
422
423 // update position
424 tempVector = getPositionAtStep(NextStep-1);
425 tempVector += configuration->Deltat*(getAtomicVelocityAtStep(NextStep-1)); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
426 tempVector += 0.5*configuration->Deltat*configuration->Deltat*(getAtomicForceAtStep(NextStep))*(1./getMass()); // F = m * a and s =
427 setPositionAtStep(NextStep, tempVector);
428
429 // Update U
430 tempVector = getAtomicVelocityAtStep(NextStep-1);
431 tempVector += configuration->Deltat * (getAtomicForceAtStep(NextStep)+getAtomicForceAtStep(NextStep-1))*(1./getMass()); // v = F/m * t
432 setAtomicVelocityAtStep(NextStep, tempVector);
433
434 // some info for debugging
435 DoLog(2) && (Log() << Verbose(2)
436 << "Integrated position&velocity of step " << (NextStep) << ": ("
437 << getPositionAtStep(NextStep) << ")\t("
438 << getAtomicVelocityAtStep(NextStep) << ")" << std::endl);
439};
440
441const AtomInfo& operator*=(AtomInfo& a, const double m)
442{
443 a.Scale(m);
444 return a;
445}
446
447AtomInfo const operator*(const AtomInfo& a, const double m)
448{
449 AtomInfo copy(a);
450 copy *= m;
451 return copy;
452}
453
454AtomInfo const operator*(const double m, const AtomInfo& a)
455{
456 AtomInfo copy(a);
457 copy *= m;
458 return copy;
459}
460
461std::ostream & AtomInfo::operator << (std::ostream &ost) const
462{
463 return (ost << getPosition());
464}
465
466std::ostream & operator << (std::ostream &ost, const AtomInfo &a)
467{
468 ost << a;
469 return ost;
470}
471
Note: See TracBrowser for help on using the repository browser.