source: src/atom_trajectoryparticle.cpp@ e2b47c

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

Added cased '-P' (force integration) to testsuite.

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