source: src/atom_trajectoryparticle.cpp@ 43dad6

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 43dad6 was a3fded, checked in by Frederik Heber <heber@…>, 15 years ago

New class ThermoStatContainer containing all parameters and changes to ConfigFileBuffer.

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