source: src/Atom/atom_atominfo.cpp@ bff93d

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 bff93d was 2034f3, checked in by Frederik Heber <heber@…>, 13 years ago

Added AtomInfo::charge along with getter and setter.

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