source: src/Atom/atom_atominfo.cpp@ 2a8731

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 2a8731 was cd9a59, checked in by Frederik Heber <heber@…>, 11 years ago

Added TrajectoryChanged channel to atom_observable.

  • Property mode set to 100644
File size: 21.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * atom_atominfo.cpp
25 *
26 * Created on: Oct 19, 2009
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "CodePatterns/Verbose.hpp"
38
39#include "atom_atominfo.hpp"
40#include "CodePatterns/Log.hpp"
41#include "config.hpp"
42#include "Element/element.hpp"
43#include "Element/periodentafel.hpp"
44#include "Fragmentation/ForceMatrix.hpp"
45#include "World.hpp"
46#include "WorldTime.hpp"
47
48#include <iomanip>
49
50/** Constructor of class AtomInfo.
51 */
52AtomInfo::AtomInfo() :
53 AtomicElement(0),
54 FixedIon(false),
55 charge(0.)
56{
57 AtomicPosition.reserve(1);
58 AtomicPosition.push_back(zeroVec);
59 AtomicVelocity.reserve(1);
60 AtomicVelocity.push_back(zeroVec);
61 AtomicForce.reserve(1);
62 AtomicForce.push_back(zeroVec);
63
64};
65
66/** Copy constructor of class AtomInfo.
67 */
68AtomInfo::AtomInfo(const AtomInfo &_atom) :
69 AtomicPosition(_atom.AtomicPosition),
70 AtomicElement(_atom.AtomicElement),
71 FixedIon(_atom.FixedIon),
72 charge(_atom.charge)
73{
74 AtomicVelocity.reserve(1);
75 AtomicVelocity.push_back(zeroVec);
76 AtomicForce.reserve(1);
77 AtomicForce.push_back(zeroVec);
78};
79
80AtomInfo::AtomInfo(const VectorInterface &_v) :
81 AtomicElement(-1),
82 FixedIon(false),
83 charge(0.)
84{
85 AtomicPosition[0] = _v.getPosition();
86 AtomicVelocity.reserve(1);
87 AtomicVelocity.push_back(zeroVec);
88 AtomicForce.reserve(1);
89 AtomicForce.push_back(zeroVec);
90};
91
92/** Destructor of class AtomInfo.
93 */
94AtomInfo::~AtomInfo()
95{
96};
97
98void AtomInfo::AppendTrajectoryStep()
99{
100 NOTIFY(TrajectoryChanged);
101 AtomicPosition.push_back(zeroVec);
102 AtomicVelocity.push_back(zeroVec);
103 AtomicForce.push_back(zeroVec);
104 LOG(5,"AtomInfo::AppendTrajectoryStep() called, size is ("
105 << AtomicPosition.size() << ","
106 << AtomicVelocity.size() << ","
107 << AtomicForce.size() << ")");
108}
109
110const element *AtomInfo::getType() const
111{
112 const element *elem = World::getInstance().getPeriode()->FindElement(AtomicElement);
113 return elem;
114}
115
116const element &AtomInfo::getElement() const
117{
118 const element &elem = *World::getInstance().getPeriode()->FindElement(AtomicElement);
119 return elem;
120}
121
122atomicNumber_t AtomInfo::getElementNo() const
123{
124 return AtomicElement;
125}
126
127const double& AtomInfo::operator[](size_t i) const
128{
129 ASSERT(AtomicPosition.size() > WorldTime::getTime(),
130 "AtomInfo::operator[]() - Access out of range: "
131 +toString(WorldTime::getTime())
132 +" not in [0,"+toString(AtomicPosition.size())+").");
133 return AtomicPosition[WorldTime::getTime()][i];
134}
135
136const double& AtomInfo::at(size_t i) const
137{
138 ASSERT(AtomicPosition.size() > WorldTime::getTime(),
139 "AtomInfo::at() - Access out of range: "
140 +toString(WorldTime::getTime())
141 +" not in [0,"+toString(AtomicPosition.size())+").");
142 return AtomicPosition[WorldTime::getTime()].at(i);
143}
144
145const double& AtomInfo::atStep(size_t i, unsigned int _step) const
146{
147 ASSERT(AtomicPosition.size() > _step,
148 "AtomInfo::atStep() - Access out of range: "
149 +toString(_step)
150 +" not in [0,"+toString(AtomicPosition.size())+").");
151 return AtomicPosition[_step].at(i);
152}
153
154void AtomInfo::set(size_t i, const double value)
155{
156 OBSERVE;
157 NOTIFY(AtomObservable::PositionChanged);
158 ASSERT(AtomicPosition.size() > WorldTime::getTime(),
159 "AtomInfo::set() - Access out of range: "
160 +toString(WorldTime::getTime())
161 +" not in [0,"+toString(AtomicPosition.size())+").");
162 AtomicPosition[WorldTime::getTime()].at(i) = value;
163}
164
165const Vector& AtomInfo::getPosition() const
166{
167 ASSERT(AtomicPosition.size() > WorldTime::getTime(),
168 "AtomInfo::getPosition() - Access out of range: "
169 +toString(WorldTime::getTime())
170 +" not in [0,"+toString(AtomicPosition.size())+").");
171 return AtomicPosition[WorldTime::getTime()];
172}
173
174const Vector& AtomInfo::getPositionAtStep(const unsigned int _step) const
175{
176 ASSERT(_step < AtomicPosition.size(),
177 "AtomInfo::getPositionAtStep() - Access out of range: "
178 +toString(_step)
179 +" not in [0,"+toString(AtomicPosition.size())+").");
180 return AtomicPosition[_step];
181}
182
183void AtomInfo::setType(const element* _type)
184{
185 if (_type->getAtomicNumber() != AtomicElement) {
186 OBSERVE;
187 NOTIFY(AtomObservable::ElementChanged);
188 AtomicElement = _type->getAtomicNumber();
189 }
190}
191
192void AtomInfo::setType(const int Z)
193{
194 const element *elem = World::getInstance().getPeriode()->FindElement(Z);
195 if (elem != NULL) {
196 OBSERVE;
197 NOTIFY(AtomObservable::ElementChanged);
198 AtomicElement = Z;
199 }
200}
201
202//Vector& AtomInfo::getAtomicVelocity()
203//{
204// return AtomicVelocity[0];
205//}
206
207//Vector& AtomInfo::getAtomicVelocity(const int _step)
208//{
209// ASSERT(_step < AtomicVelocity.size(),
210// "AtomInfo::getAtomicVelocity() - Access out of range.");
211// return AtomicVelocity[_step];
212//}
213
214const Vector& AtomInfo::getAtomicVelocity() const
215{
216 ASSERT(AtomicVelocity.size() > 0,
217 "AtomInfo::getAtomicVelocity() - Access out of range: "
218 +toString(WorldTime::getTime())
219 +" not in [0,"+toString(AtomicPosition.size())+").");
220 return AtomicVelocity[WorldTime::getTime()];
221}
222
223const Vector& AtomInfo::getAtomicVelocityAtStep(const unsigned int _step) const
224{
225 ASSERT(_step < AtomicVelocity.size(),
226 "AtomInfo::getAtomicVelocity() - Access out of range: "
227 +toString(_step)
228 +" not in [0,"+toString(AtomicPosition.size())+").");
229 return AtomicVelocity[_step];
230}
231
232void AtomInfo::setAtomicVelocity(const Vector &_newvelocity)
233{
234 OBSERVE;
235 NOTIFY(AtomObservable::VelocityChanged);
236 ASSERT(WorldTime::getTime() < AtomicVelocity.size(),
237 "AtomInfo::setAtomicVelocity() - Access out of range: "
238 +toString(WorldTime::getTime())
239 +" not in [0,"+toString(AtomicPosition.size())+").");
240 AtomicVelocity[WorldTime::getTime()] = _newvelocity;
241}
242
243void AtomInfo::setAtomicVelocityAtStep(const unsigned int _step, const Vector &_newvelocity)
244{
245 OBSERVE;
246 if (WorldTime::getTime() == _step)
247 NOTIFY(AtomObservable::VelocityChanged);
248 const unsigned int size = AtomicVelocity.size();
249 ASSERT(_step <= size,
250 "AtomInfo::setAtomicVelocityAtStep() - Access out of range: "
251 +toString(_step)
252 +" not in [0,"+toString(size)+"].");
253 if(_step < size) {
254 AtomicVelocity[_step] = _newvelocity;
255 } else if (_step == size) {
256 UpdateSteps();
257 AtomicVelocity[_step] = _newvelocity;
258 }
259}
260
261const Vector& AtomInfo::getAtomicForce() const
262{
263 ASSERT(WorldTime::getTime() < AtomicForce.size(),
264 "AtomInfo::getAtomicForce() - Access out of range: "
265 +toString(WorldTime::getTime())
266 +" not in [0,"+toString(AtomicPosition.size())+").");
267 return AtomicForce[WorldTime::getTime()];
268}
269
270const Vector& AtomInfo::getAtomicForceAtStep(const unsigned int _step) const
271{
272 ASSERT(_step < AtomicForce.size(),
273 "AtomInfo::getAtomicForce() - Access out of range: "
274 +toString(_step)
275 +" not in [0,"+toString(AtomicPosition.size())+").");
276 return AtomicForce[_step];
277}
278
279void AtomInfo::setAtomicForce(const Vector &_newforce)
280{
281 OBSERVE;
282 NOTIFY(AtomObservable::ForceChanged);
283 ASSERT(WorldTime::getTime() < AtomicForce.size(),
284 "AtomInfo::setAtomicForce() - Access out of range: "
285 +toString(WorldTime::getTime())
286 +" not in [0,"+toString(AtomicPosition.size())+").");
287 AtomicForce[WorldTime::getTime()] = _newforce;
288}
289
290void AtomInfo::setAtomicForceAtStep(const unsigned int _step, const Vector &_newforce)
291{
292 OBSERVE;
293 if (WorldTime::getTime() == _step)
294 NOTIFY(AtomObservable::ForceChanged);
295 const unsigned int size = AtomicForce.size();
296 ASSERT(_step <= size,
297 "AtomInfo::setAtomicForce() - Access out of range: "
298 +toString(_step)
299 +" not in [0,"+toString(AtomicPosition.size())+"].");
300 if(_step < size) {
301 AtomicForce[_step] = _newforce;
302 } else if (_step == size) {
303 UpdateSteps();
304 AtomicForce[_step] = _newforce;
305 }
306}
307
308bool AtomInfo::getFixedIon() const
309{
310 return FixedIon;
311}
312
313void AtomInfo::setFixedIon(const bool _fixedion)
314{
315 OBSERVE;
316 NOTIFY(AtomObservable::PropertyChanged);
317 FixedIon = _fixedion;
318}
319
320void AtomInfo::setPosition(const Vector& _vector)
321{
322 OBSERVE;
323 NOTIFY(AtomObservable::PositionChanged);
324 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
325 "AtomInfo::setPosition() - Access out of range: "
326 +toString(WorldTime::getTime())
327 +" not in [0,"+toString(AtomicPosition.size())+").");
328 AtomicPosition[WorldTime::getTime()] = _vector;
329 //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl;
330}
331
332void AtomInfo::setPositionAtStep(unsigned int _step, const Vector& _vector)
333{
334 OBSERVE;
335 if (WorldTime::getTime() == _step)
336 NOTIFY(AtomObservable::PositionChanged);
337 const unsigned int size = AtomicPosition.size();
338 ASSERT(_step <= size,
339 "AtomInfo::setPosition() - Access out of range: "
340 +toString(_step)
341 +" not in [0,"+toString(size)+"].");
342 if(_step < size) {
343 AtomicPosition[_step] = _vector;
344 } else if (_step == size) {
345 UpdateSteps();
346 AtomicPosition[_step] = _vector;
347 }
348 //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl;
349}
350
351const VectorInterface& AtomInfo::operator+=(const Vector& b)
352{
353 OBSERVE;
354 NOTIFY(AtomObservable::PositionChanged);
355 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
356 "AtomInfo::operator+=() - Access out of range: "
357 +toString(WorldTime::getTime())
358 +" not in [0,"+toString(AtomicPosition.size())+").");
359 AtomicPosition[WorldTime::getTime()] += b;
360 return *this;
361}
362
363const VectorInterface& AtomInfo::operator-=(const Vector& b)
364{
365 OBSERVE;
366 NOTIFY(AtomObservable::PositionChanged);
367 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
368 "AtomInfo::operator-=() - Access out of range: "
369 +toString(WorldTime::getTime())
370 +" not in [0,"+toString(AtomicPosition.size())+").");
371 AtomicPosition[WorldTime::getTime()] -= b;
372 return *this;
373}
374
375Vector const AtomInfo::operator+(const Vector& b) const
376{
377 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
378 "AtomInfo::operator+() - Access out of range: "
379 +toString(WorldTime::getTime())
380 +" not in [0,"+toString(AtomicPosition.size())+").");
381 Vector a(AtomicPosition[WorldTime::getTime()]);
382 a += b;
383 return a;
384}
385
386Vector const AtomInfo::operator-(const Vector& b) const
387{
388 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
389 "AtomInfo::operator-() - Access out of range: "
390 +toString(WorldTime::getTime())
391 +" not in [0,"+toString(AtomicPosition.size())+").");
392 Vector a(AtomicPosition[WorldTime::getTime()]);
393 a -= b;
394 return a;
395}
396
397double AtomInfo::distance(const Vector &point) const
398{
399 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
400 "AtomInfo::distance() - Access out of range: "
401 +toString(WorldTime::getTime())
402 +" not in [0,"+toString(AtomicPosition.size())+").");
403 return AtomicPosition[WorldTime::getTime()].distance(point);
404}
405
406double AtomInfo::DistanceSquared(const Vector &y) const
407{
408 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
409 "AtomInfo::DistanceSquared() - Access out of range: "
410 +toString(WorldTime::getTime())
411 +" not in [0,"+toString(AtomicPosition.size())+").");
412 return AtomicPosition[WorldTime::getTime()].DistanceSquared(y);
413}
414
415double AtomInfo::distance(const VectorInterface &_atom) const
416{
417 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
418 "AtomInfo::distance() - Access out of range: "
419 +toString(WorldTime::getTime())
420 +" not in [0,"+toString(AtomicPosition.size())+").");
421 return _atom.distance(AtomicPosition[WorldTime::getTime()]);
422}
423
424double AtomInfo::DistanceSquared(const VectorInterface &_atom) const
425{
426 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
427 "AtomInfo::DistanceSquared() - Access out of range: "
428 +toString(WorldTime::getTime())
429 +" not in [0,"+toString(AtomicPosition.size())+").");
430 return _atom.DistanceSquared(AtomicPosition[WorldTime::getTime()]);
431}
432
433VectorInterface &AtomInfo::operator=(const Vector& _vector)
434{
435 OBSERVE;
436 NOTIFY(AtomObservable::PositionChanged);
437 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
438 "AtomInfo::operator=() - Access out of range: "
439 +toString(WorldTime::getTime())
440 +" not in [0,"+toString(AtomicPosition.size())+").");
441 AtomicPosition[WorldTime::getTime()] = _vector;
442 return *this;
443}
444
445void AtomInfo::ScaleAll(const double *factor)
446{
447 OBSERVE;
448 NOTIFY(AtomObservable::PositionChanged);
449 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
450 "AtomInfo::ScaleAll() - Access out of range: "
451 +toString(WorldTime::getTime())
452 +" not in [0,"+toString(AtomicPosition.size())+").");
453 AtomicPosition[WorldTime::getTime()].ScaleAll(factor);
454}
455
456void AtomInfo::ScaleAll(const Vector &factor)
457{
458 OBSERVE;
459 NOTIFY(AtomObservable::PositionChanged);
460 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
461 "AtomInfo::ScaleAll() - Access out of range: "
462 +toString(WorldTime::getTime())
463 +" not in [0,"+toString(AtomicPosition.size())+").");
464 AtomicPosition[WorldTime::getTime()].ScaleAll(factor);
465}
466
467void AtomInfo::Scale(const double factor)
468{
469 OBSERVE;
470 NOTIFY(AtomObservable::PositionChanged);
471 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
472 "AtomInfo::Scale() - Access out of range: "
473 +toString(WorldTime::getTime())
474 +" not in [0,"+toString(AtomicPosition.size())+").");
475 AtomicPosition[WorldTime::getTime()].Scale(factor);
476}
477
478void AtomInfo::Zero()
479{
480 OBSERVE;
481 NOTIFY(AtomObservable::PositionChanged);
482 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
483 "AtomInfo::Zero() - Access out of range: "
484 +toString(WorldTime::getTime())
485 +" not in [0,"+toString(AtomicPosition.size())+").");
486 AtomicPosition[WorldTime::getTime()].Zero();
487}
488
489void AtomInfo::One(const double one)
490{
491 OBSERVE;
492 NOTIFY(AtomObservable::PositionChanged);
493 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
494 "AtomInfo::One() - Access out of range: "
495 +toString(WorldTime::getTime())
496 +" not in [0,"+toString(AtomicPosition.size())+").");
497 AtomicPosition[WorldTime::getTime()].One(one);
498}
499
500void AtomInfo::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors)
501{
502 OBSERVE;
503 NOTIFY(AtomObservable::PositionChanged);
504 ASSERT(WorldTime::getTime() < AtomicPosition.size(),
505 "AtomInfo::LinearCombinationOfVectors() - Access out of range: "
506 +toString(WorldTime::getTime())
507 +" not in [0,"+toString(AtomicPosition.size())+").");
508 AtomicPosition[WorldTime::getTime()].LinearCombinationOfVectors(x1,x2,x3,factors);
509}
510
511/**
512 * returns the kinetic energy of this atom at a given time step
513 */
514double AtomInfo::getKineticEnergy(const unsigned int _step) const
515{
516 ASSERT(_step < AtomicPosition.size(),
517 "AtomInfo::getKineticEnergy() - Access out of range: "
518 +toString(WorldTime::getTime())
519 +" not in [0,"+toString(AtomicPosition.size())+").");
520 return getMass() * AtomicVelocity[_step].NormSquared();
521}
522
523Vector AtomInfo::getMomentum(const unsigned int _step) const
524{
525 ASSERT(_step < AtomicPosition.size(),
526 "AtomInfo::getMomentum() - Access out of range: "
527 +toString(WorldTime::getTime())
528 +" not in [0,"+toString(AtomicPosition.size())+").");
529 return getMass()*AtomicVelocity[_step];
530}
531
532/** Extends the trajectory STL vector to the new size.
533 * Does nothing if \a MaxSteps is smaller than current size.
534 * \param MaxSteps
535 */
536void AtomInfo::ResizeTrajectory(size_t MaxSteps)
537{
538 for (;AtomicPosition.size() <= (unsigned int)(MaxSteps);)
539 UpdateSteps();
540}
541
542size_t AtomInfo::getTrajectorySize() const
543{
544 return AtomicPosition.size();
545}
546
547double AtomInfo::getMass() const
548{
549 return getType()->getMass();
550}
551
552/** Copies a given trajectory step \a src onto another \a dest
553 * \param dest index of destination step
554 * \param src index of source step
555 */
556void AtomInfo::CopyStepOnStep(const unsigned int dest, const unsigned int src)
557{
558 if (dest == src) // self assignment check
559 return;
560
561 if (WorldTime::getTime() == dest){
562 NOTIFY(AtomObservable::PositionChanged);
563 NOTIFY(AtomObservable::VelocityChanged);
564 NOTIFY(AtomObservable::ForceChanged);
565 }
566
567 ASSERT(dest < AtomicPosition.size(),
568 "AtomInfo::CopyStepOnStep() - destination outside of current trajectory array: "
569 +toString(dest)
570 +" not in [0,"+toString(AtomicPosition.size())+").");
571 ASSERT(src < AtomicPosition.size(),
572 "AtomInfo::CopyStepOnStep() - source outside of current trajectory array: "
573 +toString(src)
574 +" not in [0,"+toString(AtomicPosition.size())+").");
575 for (int n=NDIM;n--;) {
576 AtomicPosition.at(dest)[n] = AtomicPosition.at(src)[n];
577 AtomicVelocity.at(dest)[n] = AtomicVelocity.at(src)[n];
578 AtomicForce.at(dest)[n] = AtomicForce.at(src)[n];
579 }
580};
581
582/** Performs a velocity verlet update of the position at \a NextStep from \a LastStep information only.
583 *
584 * We calculate \f$x(t + \delta t) = x(t) + v(t)* \delta t + .5 * \delta t * \delta t * F(t)/m \f$.
585 *
586 *
587 * \param NextStep index of sequential step to set
588 * \param Deltat time step width
589 * \param IsAngstroem whether the force's underlying unit of length is angstroem or bohr radii
590 */
591void AtomInfo::VelocityVerletUpdateX(int nr, const unsigned int NextStep, double Deltat, bool IsAngstroem)
592{
593 const unsigned int LastStep = NextStep == 0 ? 0 : NextStep-1;
594
595 LOG(2, "INFO: Particle that currently " << *this);
596 LOG(2, "INFO: Integrating position with mass=" << getMass() << " and Deltat="
597 << Deltat << " at NextStep=" << NextStep);
598
599 // update position
600 {
601 Vector tempVector = getPositionAtStep(LastStep);
602 LOG(4, "INFO: initial position from last step " << setprecision(4) << tempVector);
603 tempVector += Deltat*(getAtomicVelocityAtStep(LastStep)); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
604 LOG(4, "INFO: position with velocity " << getAtomicVelocityAtStep(LastStep) << " from last step " << tempVector);
605 tempVector += .5*Deltat*Deltat*(getAtomicForceAtStep(LastStep))*(1./getMass()); // F = m * a and s =
606 LOG(4, "INFO: position with force " << getAtomicForceAtStep(LastStep) << " from last step " << tempVector);
607 setPositionAtStep(NextStep, tempVector);
608 LOG(3, "INFO: Position at step " << NextStep << " set to " << tempVector);
609 }
610};
611
612/** Performs a velocity verlet update of the velocity at \a NextStep.
613 *
614 * \note forces at NextStep should have been calculated based on position at NextStep prior
615 * to calling this function.
616 *
617 * We calculate \f$v(t) = v(t - \delta t) + \delta _t * .5 * (F(t - \delta t) + F(t))/m \f$.
618 *
619 * Parameters are according to those in configuration class.
620 * \param NextStep index of sequential step to set
621 * \param Deltat time step width
622 * \param IsAngstroem whether the force's underlying unit of length is angstroem or bohr radii
623 */
624void AtomInfo::VelocityVerletUpdateU(int nr, const unsigned int NextStep, double Deltat, bool IsAngstroem)
625{
626 const unsigned int LastStep = NextStep == 0 ? 0 : NextStep-1;
627
628 LOG(2, "INFO: Particle that currently " << *this);
629 LOG(2, "INFO: Integrating velocity with mass=" << getMass() << " and Deltat="
630 << Deltat << " at NextStep=" << NextStep);
631
632 // Update U
633 {
634 Vector tempVector = getAtomicVelocityAtStep(LastStep);
635 LOG(4, "INFO: initial velocity from last step " << tempVector);
636 tempVector += Deltat * .5*(getAtomicForceAtStep(LastStep)+getAtomicForceAtStep(NextStep))*(1./getMass()); // v = F/m * t
637 LOG(4, "INFO: Velocity with force from last " << getAtomicForceAtStep(LastStep)
638 << " and present " << getAtomicForceAtStep(NextStep) << " step " << tempVector);
639 setAtomicVelocityAtStep(NextStep, tempVector);
640 LOG(3, "INFO: Velocity at step " << NextStep << " set to " << tempVector);
641 }
642};
643
644//const AtomInfo& operator*=(AtomInfo& a, const double m)
645//{
646// a.Scale(m);
647// return a;
648//}
649//
650//AtomInfo const operator*(const AtomInfo& a, const double m)
651//{
652// AtomInfo copy(a);
653// copy *= m;
654// return copy;
655//}
656//
657//AtomInfo const operator*(const double m, const AtomInfo& a)
658//{
659// AtomInfo copy(a);
660// copy *= m;
661// return copy;
662//}
663
664std::ostream & AtomInfo::operator << (std::ostream &ost) const
665{
666 return (ost << getPosition());
667}
668
669std::ostream & operator << (std::ostream &ost, const AtomInfo &a)
670{
671 const size_t terminalstep = a.getTrajectorySize()-1;
672 if (terminalstep) {
673 ost << "starts at "
674 << a.getPositionAtStep(0) << " and ends at "
675 << a.getPositionAtStep(terminalstep)
676 << " at time step " << terminalstep;
677 } else {
678 ost << "is at "
679 << a.getPositionAtStep(0) << " with a single time step only";
680 }
681 return ost;
682}
683
Note: See TracBrowser for help on using the repository browser.