source: src/atom_trajectoryparticle.cpp@ 906822

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 906822 was 112b09, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added #include "Helpers/MemDebug.hpp" to all .cpp files

  • Property mode set to 100644
File size: 9.8 KB
Line 
1/*
2 * atom_trajectoryparticle.cpp
3 *
4 * Created on: Oct 19, 2009
5 * Author: heber
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include "atom.hpp"
11#include "atom_trajectoryparticle.hpp"
12#include "config.hpp"
13#include "element.hpp"
14#include "info.hpp"
15#include "log.hpp"
16#include "parser.hpp"
17#include "verbose.hpp"
18
19/** Constructor of class TrajectoryParticle.
20 */
21TrajectoryParticle::TrajectoryParticle()
22{
23};
24
25/** Destructor of class TrajectoryParticle.
26 */
27TrajectoryParticle::~TrajectoryParticle()
28{
29};
30
31
32/** Adds kinetic energy of this atom to given temperature value.
33 * \param *temperature add on this value
34 * \param step given step of trajectory to add
35 */
36void TrajectoryParticle::AddKineticToTemperature(double *temperature, int step) const
37{
38 for (int i=NDIM;i--;)
39 *temperature += type->mass * Trajectory.U.at(step)[i]* Trajectory.U.at(step)[i];
40};
41
42/** Evaluates some constraint potential if atom moves from \a startstep at once to \endstep in trajectory.
43 * \param startstep trajectory begins at
44 * \param endstep trajectory ends at
45 * \param **PermutationMap if atom switches places with some other atom, there is no translation but a permutaton noted here (not in the trajectories of ea
46 * \param *Force Force matrix to store result in
47 */
48void TrajectoryParticle::EvaluateConstrainedForce(int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force) const
49{
50 double constant = 10.;
51 TrajectoryParticle *Sprinter = PermutationMap[nr];
52 // set forces
53 for (int i=NDIM;i++;)
54 Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).distance(Sprinter->Trajectory.R.at(endstep)));
55};
56
57/** Correct velocity against the summed \a CoGVelocity for \a step.
58 * \param *ActualTemp sum up actual temperature meanwhile
59 * \param Step MD step in atom::Tracjetory
60 * \param *CoGVelocity remnant velocity (i.e. vector sum of all atom velocities)
61 */
62void TrajectoryParticle::CorrectVelocity(double *ActualTemp, int Step, Vector *CoGVelocity)
63{
64 for(int d=0;d<NDIM;d++) {
65 Trajectory.U.at(Step)[d] -= CoGVelocity->at(d);
66 *ActualTemp += 0.5 * type->mass * Trajectory.U.at(Step)[d] * Trajectory.U.at(Step)[d];
67 }
68};
69
70/** Extends the trajectory STL vector to the new size.
71 * Does nothing if \a MaxSteps is smaller than current size.
72 * \param MaxSteps
73 */
74void TrajectoryParticle::ResizeTrajectory(int MaxSteps)
75{
76 Info FunctionInfo(__func__);
77 if (Trajectory.R.size() <= (unsigned int)(MaxSteps)) {
78 DoLog(0) && (Log() << Verbose(0) << "Increasing size for trajectory array of " << nr << " from " << Trajectory.R.size() << " to " << (MaxSteps+1) << "." << endl);
79 Trajectory.R.resize(MaxSteps+1);
80 Trajectory.U.resize(MaxSteps+1);
81 Trajectory.F.resize(MaxSteps+1);
82 }
83};
84
85/** Copies a given trajectory step \a src onto another \a dest
86 * \param dest index of destination step
87 * \param src index of source step
88 */
89void TrajectoryParticle::CopyStepOnStep(int dest, int src)
90{
91 if (dest == src) // self assignment check
92 return;
93
94 for (int n=NDIM;n--;) {
95 Trajectory.R.at(dest)[n] = Trajectory.R.at(src)[n];
96 Trajectory.U.at(dest)[n] = Trajectory.U.at(src)[n];
97 Trajectory.F.at(dest)[n] = Trajectory.F.at(src)[n];
98 }
99};
100
101/** Performs a velocity verlet update of the trajectory.
102 * Parameters are according to those in configuration class.
103 * \param NextStep index of sequential step to set
104 * \param *configuration pointer to configuration with parameters
105 * \param *Force matrix with forces
106 */
107void TrajectoryParticle::VelocityVerletUpdate(int NextStep, config *configuration, ForceMatrix *Force)
108{
109 //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
110 for (int d=0; d<NDIM; d++) {
111 Trajectory.F.at(NextStep)[d] = -Force->Matrix[0][nr][d+5]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.);
112 Trajectory.R.at(NextStep)[d] = Trajectory.R.at(NextStep-1)[d];
113 Trajectory.R.at(NextStep)[d] += configuration->Deltat*(Trajectory.U.at(NextStep-1)[d]); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
114 Trajectory.R.at(NextStep)[d] += 0.5*configuration->Deltat*configuration->Deltat*(Trajectory.F.at(NextStep)[d]/type->mass); // F = m * a and s =
115 }
116 // Update U
117 for (int d=0; d<NDIM; d++) {
118 Trajectory.U.at(NextStep)[d] = Trajectory.U.at(NextStep-1)[d];
119 Trajectory.U.at(NextStep)[d] += configuration->Deltat * (Trajectory.F.at(NextStep)[d]+Trajectory.F.at(NextStep-1)[d]/type->mass); // v = F/m * t
120 }
121 // Update R (and F)
122// out << "Integrated position&velocity of step " << (NextStep) << ": (";
123// for (int d=0;d<NDIM;d++)
124// out << Trajectory.R.at(NextStep).x[d] << " "; // next step
125// out << ")\t(";
126// for (int d=0;d<NDIM;d++)
127// Log() << Verbose(0) << Trajectory.U.at(NextStep).x[d] << " "; // next step
128// out << ")" << endl;
129};
130
131/** Sums up mass and kinetics.
132 * \param Step step to sum for
133 * \param *TotalMass pointer to total mass sum
134 * \param *TotalVelocity pointer to tota velocity sum
135 */
136void TrajectoryParticle::SumUpKineticEnergy( int Step, double *TotalMass, Vector *TotalVelocity ) const
137{
138 *TotalMass += type->mass; // sum up total mass
139 for(int d=0;d<NDIM;d++) {
140 TotalVelocity->at(d) += Trajectory.U.at(Step)[d]*type->mass;
141 }
142};
143
144/** Scales velocity of atom according to Woodcock thermostat.
145 * \param ScaleTempFactor factor to scale the velocities with (i.e. sqrt of energy scale factor)
146 * \param Step MD step to scale
147 * \param *ekin sum of kinetic energy
148 */
149void TrajectoryParticle::Thermostat_Woodcock(double ScaleTempFactor, int Step, double *ekin)
150{
151 Vector &U = Trajectory.U.at(Step);
152 if (FixedIon == 0) // even FixedIon moves, only not by other's forces
153 for (int d=0; d<NDIM; d++) {
154 U[d] *= ScaleTempFactor;
155 *ekin += 0.5*type->mass * U[d]*U[d];
156 }
157};
158
159/** Scales velocity of atom according to Gaussian thermostat.
160 * \param Step MD step to scale
161 * \param *G
162 * \param *E
163 */
164void TrajectoryParticle::Thermostat_Gaussian_init(int Step, double *G, double *E)
165{
166 Vector &U = Trajectory.U.at(Step);
167 Vector &F = Trajectory.F.at(Step);
168 if (FixedIon == 0) // even FixedIon moves, only not by other's forces
169 for (int d=0; d<NDIM; d++) {
170 *G += U[d] * F[d];
171 *E += U[d]*U[d]*type->mass;
172 }
173};
174
175/** Determines scale factors according to Gaussian thermostat.
176 * \param Step MD step to scale
177 * \param GE G over E ratio
178 * \param *ekin sum of kinetic energy
179 * \param *configuration configuration class with TempFrequency and TargetTemp
180 */
181void TrajectoryParticle::Thermostat_Gaussian_least_constraint(int Step, double G_over_E, double *ekin, config *configuration)
182{
183 Vector &U = Trajectory.U.at(Step);
184 if (FixedIon == 0) // even FixedIon moves, only not by other's forces
185 for (int d=0; d<NDIM; d++) {
186 U[d] += configuration->Deltat/type->mass * ( (G_over_E) * (U[d]*type->mass) );
187 *ekin += type->mass * U[d]*U[d];
188 }
189};
190
191/** Scales velocity of atom according to Langevin thermostat.
192 * \param Step MD step to scale
193 * \param *r random number generator
194 * \param *ekin sum of kinetic energy
195 * \param *configuration configuration class with TempFrequency and TargetTemp
196 */
197void TrajectoryParticle::Thermostat_Langevin(int Step, gsl_rng * r, double *ekin, config *configuration)
198{
199 double sigma = sqrt(configuration->TargetTemp/type->mass); // sigma = (k_b T)/m (Hartree/atomicmass = atomiclength/atomictime)
200 Vector &U = Trajectory.U.at(Step);
201 if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
202 // throw a dice to determine whether it gets hit by a heat bath particle
203 if (((((rand()/(double)RAND_MAX))*configuration->TempFrequency) < 1.)) {
204 DoLog(3) && (Log() << Verbose(3) << "Particle " << *this << " was hit (sigma " << sigma << "): " << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << " -> ");
205 // pick three random numbers from a Boltzmann distribution around the desired temperature T for each momenta axis
206 for (int d=0; d<NDIM; d++) {
207 U[d] = gsl_ran_gaussian (r, sigma);
208 }
209 DoLog(2) && (Log() << Verbose(2) << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << endl);
210 }
211 for (int d=0; d<NDIM; d++)
212 *ekin += 0.5*type->mass * U[d]*U[d];
213 }
214};
215
216/** Scales velocity of atom according to Berendsen thermostat.
217 * \param Step MD step to scale
218 * \param ScaleTempFactor factor to scale energy (not velocity!) with
219 * \param *ekin sum of kinetic energy
220 * \param *configuration configuration class with TempFrequency and Deltat
221 */
222void TrajectoryParticle::Thermostat_Berendsen(int Step, double ScaleTempFactor, double *ekin, config *configuration)
223{
224 Vector &U = Trajectory.U.at(Step);
225 if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
226 for (int d=0; d<NDIM; d++) {
227 U[d] *= sqrt(1+(configuration->Deltat/configuration->TempFrequency)*(ScaleTempFactor-1));
228 *ekin += 0.5*type->mass * U[d]*U[d];
229 }
230 }
231};
232
233/** Initializes current run of NoseHoover thermostat.
234 * \param Step MD step to scale
235 * \param *delta_alpha additional sum of kinetic energy on return
236 */
237void TrajectoryParticle::Thermostat_NoseHoover_init(int Step, double *delta_alpha)
238{
239 Vector &U = Trajectory.U.at(Step);
240 if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
241 for (int d=0; d<NDIM; d++) {
242 *delta_alpha += U[d]*U[d]*type->mass;
243 }
244 }
245};
246
247/** Initializes current run of NoseHoover thermostat.
248 * \param Step MD step to scale
249 * \param *ekin sum of kinetic energy
250 * \param *configuration configuration class with TempFrequency and Deltat
251 */
252void TrajectoryParticle::Thermostat_NoseHoover_scale(int Step, double *ekin, config *configuration)
253{
254 Vector &U = Trajectory.U.at(Step);
255 if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
256 for (int d=0; d<NDIM; d++) {
257 U[d] += configuration->Deltat/type->mass * (configuration->alpha * (U[d] * type->mass));
258 *ekin += (0.5*type->mass) * U[d]*U[d];
259 }
260 }
261};
Note: See TracBrowser for help on using the repository browser.