source: src/atom_atominfo.cpp@ 6625c3

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 6625c3 was 6625c3, checked in by Frederik Heber <heber@…>, 14 years ago

Removed atom_trajectoryparticle*, replaced by AtomInfo class now having std::vector<> for trajectories.

AtomInfo:

Other changes:

  • gsl_rng_gaussian() exchanged by boost::random specific type.
  • Property mode set to 100644
File size: 10.2 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 return AtomicPosition[0][i];
83}
84
85const double& AtomInfo::at(size_t i) const
86{
87 return AtomicPosition[0].at(i);
88}
89
90void AtomInfo::set(size_t i, const double value)
91{
92 AtomicPosition[0].at(i) = value;
93}
94
95const Vector& AtomInfo::getPosition() const
96{
97 return AtomicPosition[0];
98}
99
100const Vector& AtomInfo::getPosition(const int _step) const
101{
102 ASSERT(_step < AtomicPosition.size(),
103 "AtomInfo::getPosition() - Access out of range.");
104 return AtomicPosition[_step];
105}
106
107void AtomInfo::setType(const element* _type) {
108 AtomicElement = _type;
109}
110
111void AtomInfo::setType(const int Z) {
112 const element *elem = World::getInstance().getPeriode()->FindElement(Z);
113 setType(elem);
114}
115
116Vector& AtomInfo::getAtomicVelocity()
117{
118 return AtomicVelocity[0];
119}
120
121Vector& AtomInfo::getAtomicVelocity(const int _step)
122{
123 ASSERT(_step < AtomicVelocity.size(),
124 "AtomInfo::getAtomicVelocity() - Access out of range.");
125 return AtomicVelocity[_step];
126}
127
128const Vector& AtomInfo::getAtomicVelocity() const
129{
130 return AtomicVelocity[0];
131}
132
133const Vector& AtomInfo::getAtomicVelocity(const int _step) const
134{
135 ASSERT(_step < AtomicVelocity.size(),
136 "AtomInfo::getAtomicVelocity() - Access out of range.");
137 return AtomicVelocity[_step];
138}
139
140void AtomInfo::setAtomicVelocity(const Vector &_newvelocity)
141{
142 AtomicVelocity[0] = _newvelocity;
143}
144
145void AtomInfo::setAtomicVelocity(const int _step, const Vector &_newvelocity)
146{
147 ASSERT(_step <= AtomicVelocity.size(),
148 "AtomInfo::setAtomicVelocity() - Access out of range.");
149 if(_step < (int)AtomicVelocity.size()) {
150 AtomicVelocity[_step] = _newvelocity;
151 } else if (_step == (int)AtomicVelocity.size()) {
152 AtomicVelocity.push_back(_newvelocity);
153 }
154}
155
156const Vector& AtomInfo::getAtomicForce() const
157{
158 return AtomicForce[0];
159}
160
161const Vector& AtomInfo::getAtomicForce(const int _step) const
162{
163 ASSERT(_step < AtomicForce.size(),
164 "AtomInfo::getAtomicForce() - Access out of range.");
165 return AtomicForce[_step];
166}
167
168void AtomInfo::setAtomicForce(const Vector &_newforce)
169{
170 AtomicForce[0] = _newforce;
171}
172
173void AtomInfo::setAtomicForce(const int _step, const Vector &_newforce)
174{
175 ASSERT(_step <= AtomicForce.size(),
176 "AtomInfo::setAtomicForce() - Access out of range.");
177 if(_step < (int)AtomicForce.size()) {
178 AtomicForce[_step] = _newforce;
179 } else if (_step == (int)AtomicForce.size()) {
180 AtomicForce.push_back(_newforce);
181 }
182}
183
184bool AtomInfo::getFixedIon() const
185{
186 return FixedIon;
187}
188
189void AtomInfo::setFixedIon(const bool _fixedion)
190{
191 FixedIon = _fixedion;
192}
193
194void AtomInfo::setPosition(const Vector& _vector)
195{
196 AtomicPosition[0] = _vector;
197 //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl;
198}
199
200void AtomInfo::setPosition(int _step, const Vector& _vector)
201{
202 ASSERT(_step <= AtomicPosition.size(),
203 "AtomInfo::setPosition() - Access out of range.");
204 if(_step < (int)AtomicPosition.size()) {
205 AtomicPosition[_step] = _vector;
206 } else if (_step == (int)AtomicPosition.size()) {
207 AtomicPosition.push_back(_vector);
208 }
209 //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl;
210}
211
212const VectorInterface& AtomInfo::operator+=(const Vector& b)
213{
214 AtomicPosition[0] += b;
215 return *this;
216}
217
218const VectorInterface& AtomInfo::operator-=(const Vector& b)
219{
220 AtomicPosition[0] -= b;
221 return *this;
222}
223
224Vector const AtomInfo::operator+(const Vector& b) const
225{
226 Vector a(AtomicPosition[0]);
227 a += b;
228 return a;
229}
230
231Vector const AtomInfo::operator-(const Vector& b) const
232{
233 Vector a(AtomicPosition[0]);
234 a -= b;
235 return a;
236}
237
238double AtomInfo::distance(const Vector &point) const
239{
240 return AtomicPosition[0].distance(point);
241}
242
243double AtomInfo::DistanceSquared(const Vector &y) const
244{
245 return AtomicPosition[0].DistanceSquared(y);
246}
247
248double AtomInfo::distance(const VectorInterface &_atom) const
249{
250 return _atom.distance(AtomicPosition[0]);
251}
252
253double AtomInfo::DistanceSquared(const VectorInterface &_atom) const
254{
255 return _atom.DistanceSquared(AtomicPosition[0]);
256}
257
258VectorInterface &AtomInfo::operator=(const Vector& _vector)
259{
260 AtomicPosition[0] = _vector;
261 return *this;
262}
263
264void AtomInfo::ScaleAll(const double *factor)
265{
266 AtomicPosition[0].ScaleAll(factor);
267}
268
269void AtomInfo::ScaleAll(const Vector &factor)
270{
271 AtomicPosition[0].ScaleAll(factor);
272}
273
274void AtomInfo::Scale(const double factor)
275{
276 AtomicPosition[0].Scale(factor);
277}
278
279void AtomInfo::Zero()
280{
281 AtomicPosition[0].Zero();
282}
283
284void AtomInfo::One(const double one)
285{
286 AtomicPosition[0].One(one);
287}
288
289void AtomInfo::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors)
290{
291 AtomicPosition[0].LinearCombinationOfVectors(x1,x2,x3,factors);
292}
293
294/**
295 * returns the kinetic energy of this atom at a given time step
296 */
297double AtomInfo::getKineticEnergy(unsigned int step) const{
298 return getMass() * AtomicVelocity[step].NormSquared();
299}
300
301Vector AtomInfo::getMomentum(unsigned int step) const{
302 return getMass()*AtomicVelocity[step];
303}
304
305/** Extends the trajectory STL vector to the new size.
306 * Does nothing if \a MaxSteps is smaller than current size.
307 * \param MaxSteps
308 */
309void AtomInfo::ResizeTrajectory(size_t MaxSteps)
310{
311 if (AtomicPosition.size() <= (unsigned int)(MaxSteps)) {
312 DoLog(0) && (Log() << Verbose(0) << "Increasing size for trajectory array from " << AtomicPosition.size() << " to " << (MaxSteps+1) << "." << endl);
313 AtomicPosition.resize(MaxSteps+1, zeroVec);
314 AtomicVelocity.resize(MaxSteps+1, zeroVec);
315 AtomicForce.resize(MaxSteps+1, zeroVec);
316 }
317};
318
319size_t AtomInfo::getTrajectorySize() const
320{
321 return AtomicPosition.size();
322}
323
324double AtomInfo::getMass() const{
325 return AtomicElement->getMass();
326}
327
328/** Copies a given trajectory step \a src onto another \a dest
329 * \param dest index of destination step
330 * \param src index of source step
331 */
332void AtomInfo::CopyStepOnStep(int dest, int src)
333{
334 if (dest == src) // self assignment check
335 return;
336
337 ASSERT(dest < AtomicPosition.size(),
338 "AtomInfo::CopyStepOnStep() - destination outside of current trajectory array.");
339 ASSERT(src < AtomicPosition.size(),
340 "AtomInfo::CopyStepOnStep() - source outside of current trajectory array.");
341 for (int n=NDIM;n--;) {
342 AtomicPosition.at(dest)[n] = AtomicPosition.at(src)[n];
343 AtomicVelocity.at(dest)[n] = AtomicVelocity.at(src)[n];
344 AtomicForce.at(dest)[n] = AtomicForce.at(src)[n];
345 }
346};
347
348/** Performs a velocity verlet update of the trajectory.
349 * Parameters are according to those in configuration class.
350 * \param NextStep index of sequential step to set
351 * \param *configuration pointer to configuration with parameters
352 * \param *Force matrix with forces
353 */
354void AtomInfo::VelocityVerletUpdate(int nr, int NextStep, config *configuration, ForceMatrix *Force, const size_t offset)
355{
356 //a = configuration.Deltat*0.5/walker->type->mass; // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a
357 if ((int)AtomicPosition.size() <= NextStep)
358 ResizeTrajectory(NextStep+10);
359 for (int d=0; d<NDIM; d++) {
360 AtomicForce.at(NextStep)[d] = -Force->Matrix[0][nr][d+offset]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.);
361 AtomicPosition.at(NextStep)[d] = AtomicPosition.at(NextStep-1)[d];
362 AtomicPosition.at(NextStep)[d] += configuration->Deltat*(AtomicVelocity.at(NextStep-1)[d]); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
363 AtomicPosition.at(NextStep)[d] += 0.5*configuration->Deltat*configuration->Deltat*(AtomicForce.at(NextStep)[d]/getMass()); // F = m * a and s =
364 }
365 // Update U
366 for (int d=0; d<NDIM; d++) {
367 AtomicVelocity.at(NextStep)[d] = AtomicVelocity.at(NextStep-1)[d];
368 AtomicVelocity.at(NextStep)[d] += configuration->Deltat * (AtomicForce.at(NextStep)[d]+AtomicForce.at(NextStep-1)[d]/getMass()); // v = F/m * t
369 }
370 // Update R (and F)
371// out << "Integrated position&velocity of step " << (NextStep) << ": (";
372// for (int d=0;d<NDIM;d++)
373// out << AtomicPosition.at(NextStep).x[d] << " "; // next step
374// out << ")\t(";
375// for (int d=0;d<NDIM;d++)
376// Log() << Verbose(0) << AtomicVelocity.at(NextStep).x[d] << " "; // next step
377// out << ")" << endl;
378};
379
380const AtomInfo& operator*=(AtomInfo& a, const double m)
381{
382 a.Scale(m);
383 return a;
384}
385
386AtomInfo const operator*(const AtomInfo& a, const double m)
387{
388 AtomInfo copy(a);
389 copy *= m;
390 return copy;
391}
392
393AtomInfo const operator*(const double m, const AtomInfo& a)
394{
395 AtomInfo copy(a);
396 copy *= m;
397 return copy;
398}
399
400std::ostream & AtomInfo::operator << (std::ostream &ost) const
401{
402 return (ost << getPosition());
403}
404
405std::ostream & operator << (std::ostream &ost, const AtomInfo &a)
406{
407 ost << a;
408 return ost;
409}
410
Note: See TracBrowser for help on using the repository browser.