source: src/Atom/atom_atominfo.cpp@ d8821e

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 d8821e was 606c24, checked in by Frederik Heber <heber@…>, 11 years ago

FIX: Newly created default atom has element hydrogen.

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