DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
molecularDynamicsClass.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2025 The Regents of the University of Michigan and DFT-FE
4// authors.
5//
6// This file is part of the DFT-FE code.
7//
8// The DFT-FE code is free software; you can use it, redistribute
9// it, and/or modify it under the terms of the GNU Lesser General
10// Public License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12// The full text of the license can be found in the file LICENSE at
13// the top level of the DFT-FE distribution.
14//
15// ---------------------------------------------------------------------
16//
17// @author Kartick Ramakrishnan
18//
19
20#ifndef molecularDynamicsClass_H_
21#define molecularDynamicsClass_H_
22#include "constants.h"
23#include "headers.h"
24#include <vector>
25#include <memory>
26#include "dftBase.h"
27#include "dftfeWrapper.h"
28
29
30namespace dftfe
31{
33 {
34 public:
35 /**
36 * @brief molecularDynamicsClass constructor: copy data from dftparameters to the memebrs of molecularDynamicsClass
37 *
38 *
39 * @param[in] dftBase *_dftBasePtr pointer to base class of dftClass
40 * @param[in] mpi_comm_parent parent mpi communicator
41 */
42 molecularDynamicsClass(const std::string parameter_file,
43 const std::string restartFilesPath,
44 const MPI_Comm & mpi_comm_parent,
45 const bool restart,
46 const int verbosity,
47 const bool useDevice);
48
49
50 const double haPerBohrToeVPerAng = 27.211386245988 / 0.529177210903;
51 const double haToeV = 27.211386245988;
52 const double bohrToAng = 0.529177210903;
53 const double AngTobohr = 1.0 / bohrToAng;
54 const double kB = 8.617333262e-05; // eV/K **3.166811429e-6**;
55
57 /**
58 * @brief runMD: Assign atom mass to charge. Create vectors for displacement, velocity, force.
59 * Create KE vector, TE vector, PE vector. Initialise velocities from
60 * Boltsmann distribution. Set Center of Mass velocities to be 0. Call the
61 * resepective ensemble based on input file
62 *
63 *
64 */
65 int
67
68
69
70 private:
71 // pointer to dft class
72 std::unique_ptr<dftfeWrapper> d_dftfeWrapper;
74
75 // parallel communication objects
76 const MPI_Comm d_mpiCommParent;
77 const unsigned int d_this_mpi_process;
78
79 // conditional stream object
80 dealii::ConditionalOStream pcout;
81
82 std::string d_restartFilesPath;
83 const int d_verbosity;
84
85 unsigned int d_restartFlag;
87 double d_TimeStep;
88 unsigned int d_TimeIndex;
89 unsigned int d_numberofSteps;
92 std::string d_ThermostatType;
95 std::vector<std::vector<double>> d_atomFractionalunwrapped;
96 std::vector<double> d_domainLength;
99
100
101 /**
102 * @brief mdNVE Performs a Ccanonical Ensemble MD calculation. The inital temperature is set by runMD().
103 * Temperature is NOT_CONTROLLED. Controls the timeloop.
104
105 * @param[in] atomMass Stores the mass of each Charge.
106 * @param[out] KineticEnergyVector Stores KineticEnergy at each TimeStep
107 * @param[out] InternalEnergyVector Stores InternalEnergy at each TimeStep
108 * @param[out] EntropicEnergyVector Stores PotentialEnergy at each TimeStep
109 * @param[out] TotalEnergyVector Stores TotalEnergy at each TimeStep
110 * @param[out] displacements Stores the displacment of each Charge, updated
111 at each TimeStep
112 * @param[out] velocity Stores the velocity of each Charge, updated at each
113 TimeStep
114 * @param[out] force Stores the -ve of force on each charge, updated at each
115 TimeStep
116 *
117 *
118 *
119 */
120 int
121 mdNVE(std::vector<double> & KineticEnergyVector,
122 std::vector<double> & InternalEnergyVector,
123 std::vector<double> & EntropicEnergyVector,
124 std::vector<double> & TotalEnergyVector,
125 std::vector<dealii::Tensor<1, 3, double>> &displacements,
126 std::vector<double> & velocity,
127 std::vector<double> & force,
128 const std::vector<double> & atomMass);
129 /**
130
131 @brief mdNVTnosehoverchainsThermostat Performs a Canonical Ensemble MD calculation. The inital temperature is set by runMD().
132 * Thermostat type is NOSE_HOVER_CHAINS. Controls the timeloop.
133 *
134 * @param[in] atomMass Stores the mass of each Charge.
135 * @param[out] KineticEnergyVector Stores KineticEnergy at each TimeStep
136 * @param[out] InternalEnergyVector Stores InternalEnergy at each TimeStep
137 * @param[out] EntropicEnergyVector Stores PotentialEnergy at each TimeStep
138 * @param[out] TotalEnergyVector Stores TotalEnergy at each TimeStep
139 * @param[out] displacements Stores the displacment of each Charge, updated
140 at each TimeStep
141 * @param[out] velocity Stores the velocity of each Charge, updated at each
142 TimeStep
143 * @param[out] force Stores the -ve of force on each charge, updated at each
144 TimeStep
145 *
146 *
147 *
148 */
149 int
151 std::vector<double> & KineticEnergyVector,
152 std::vector<double> & InternalEnergyVector,
153 std::vector<double> & EntropicEnergyVector,
154 std::vector<double> & TotalEnergyVector,
155 std::vector<dealii::Tensor<1, 3, double>> &displacements,
156 std::vector<double> & velocity,
157 std::vector<double> & force,
158 const std::vector<double> & atomMass);
159
160 /**
161
162 @brief mdNVTrescaleThermostat Performs a Constant Kinetic Energy Ensemble MD calculation. The inital temperature is set by runMD().
163 * Thermostat type is RESCALE. Controls the timeloop. At timestep which is
164 multiple of Thermostat time constatn, the veloctites are rescaled *such that
165 the temperature is set to inital temperature .
166 *
167 * @param[in] atomMass Stores the mass of each Charge.
168 * @param[out] KineticEnergyVector Stores KineticEnergy at each TimeStep
169 * @param[out] InternalEnergyVector Stores InternalEnergy at each TimeStep
170 * @param[out] EntropicEnergyVector Stores PotentialEnergy at each TimeStep
171 * @param[out] TotalEnergyVector Stores TotalEnergy at each TimeStep
172 * @param[out] displacements Stores the displacment of each Charge, updated
173 at each TimeStep
174 * @param[out] velocity Stores the velocity of each Charge, updated at each
175 TimeStep
176 * @param[out] force Stores the -ve of force on each charge, updated at each
177 TimeStep
178 *
179 *
180 *
181 */
182 int
184 std::vector<double> & KineticEnergyVector,
185 std::vector<double> & InternalEnergyVector,
186 std::vector<double> & EntropicEnergyVector,
187 std::vector<double> & TotalEnergyVector,
188 std::vector<dealii::Tensor<1, 3, double>> &displacements,
189 std::vector<double> & velocity,
190 std::vector<double> & force,
191 const std::vector<double> & atomMass);
192
193
194 /**
195
196 @brief mdNVTsvrThermostat Performs a Canonical Ensemble MD calculation. The inital temperature is set by runMD().
197 * Thermostat type is SVR. Controls the timeloop.
198 * @param[in] massAtoms Stores the mass of each Charge. *
199 * @param[out] KineticEnergyVector Stores KineticEnergy at each TimeStep
200 * @param[out] InternalEnergyVector Stores InternalEnergy at each TimeStep
201 * @param[out] EntropicEnergyVector Stores PotentialEnergy at each TimeStep
202 * @param[out] TotalEnergyVector Stores TotalEnergy at each TimeStep
203 * @param[out] displacements Stores the displacment of each Charge, updated
204 at each TimeStep
205 * @param[out] velocity Stores the velocity of each Charge, updated at each
206 TimeStep
207 * @param[out] force Stores the -ve of force on each charge, updated at each
208 TimeStep
209 *
210 */
211 int
212 mdNVTsvrThermostat(std::vector<double> &KineticEnergyVector,
213 std::vector<double> &InternalEnergyVector,
214 std::vector<double> &EntropicEnergyVector,
215 std::vector<double> &TotalEnergyVector,
216 std::vector<dealii::Tensor<1, 3, double>> &displacements,
217 std::vector<double> & velocity,
218 std::vector<double> & force,
219 const std::vector<double> & atomMass);
220
221
222 /**
223 * @brief RescaleVelocities controls the velocity at timestep t. The scaling of
224 * velocities depends on ratio of T at that timestep and inital Temperature.
225
226
227 * @param[in] M Stores the mass of each Charge.
228 * @param[in] Temperature temperature at current Timestep
229 * @param[out] v Stores the velocity of each Charge, updated at each
230 Timestep
231 *
232 * @param[return] KE Kinetic Energy at current timestp in eV
233
234 *
235 *
236 *
237 */
238 double
239 RescaleVelocities(std::vector<double> & v,
240 const std::vector<double> &M,
241 double Temperature);
242
243
244 /**
245
246 * @brief NoseHoverChains controls the velocity at timestep t. The temperature is contolled by
247 2 thermostats. Thermostat 1 contols the velocity of all Charges.
248 Thermostat 2 controls thermostat 1. Employs Extended Lagrangian approach.
249
250
251 * @param[in] Q stores mass of each Thermostat
252 * @param[in] Temperature temperature of previous timestep
253 * @param[out] v Stores the velocity of each Charge, updated at each
254 TimeStep
255 * @param[out] v_e Stores the thermostat velocity
256 * @param[out] e Stores the position of each thermosat
257 *
258 */
259 void
260 NoseHoverChains(std::vector<double> &v,
261 std::vector<double> &v_e,
262 std::vector<double> &e,
263 std::vector<double> Q,
264 double KE,
265 double Temperature);
266
267 /**
268
269 * @brief
270
271 *
272 * @param[in] KEref Target value of Kinetic Enegy from Temperature
273 * @param[out] v Stores the velocity of each Charge, updated at each
274 TimeStep
275 * @param[out] KE rescaled Kinetic Energy from svr thermostat
276 *
277 *
278 */
279 double
280 svr(std::vector<double> &v, double KE, double KEref);
281
282
283
284 /**
285
286 * @brief velocityVerlet
287
288
289 * @param[in] atomMass Stores the mass of each Charge.
290
291 *
292 * @param[return] KE Kinetic Energy at current timestp in eV
293 * @param[out] forceonAtoms Updated -ve forces on each charge.
294 * @param[out] r Updated displacement
295 * @param[out] v Updated velocity of each atom
296 *
297 *
298 *
299 */
300 double
301 velocityVerlet(std::vector<double> & v,
302 std::vector<dealii::Tensor<1, 3, double>> &r,
303 const std::vector<double> & atomMass,
304 std::vector<double> & forceOnAtoms);
305
306
307
308 /**
309 * @brief writeRestartFile: Writing files at each timestep to mdRestart
310
311 * @param[in] velocity Velocity updated from restart
312 * @param[in] force Force data at each timeStep
313 * @param[in] PE Free energy of system at current Timestep
314 * @param[in] KE Kinetic ENergy of nuclei at current Timestep
315 * @param[in] TE temperature at current Timestep
316 * @param[in] time Current TimeStep
317 *
318 *
319 */
320
321 void
322 writeRestartFile(const std::vector<dealii::Tensor<1, 3, double>> &disp,
323 const std::vector<double> & velocity,
324 const std::vector<double> & force,
325 const std::vector<double> &KineticEnergyVector,
326 const std::vector<double> &InternalEnergyVector,
327 const std::vector<double> &TotalEnergyVector,
328 int time);
329
330 /**
331
332* @brief InitialiseFromRestartFile : Initialise atomcordinates, velocity and force at restart
333
334 * @param[out] disp Displacements of previous timestep from restart
335 * @param[out] velocity Velocity updated from restart
336 * @param[out] force Force updated from dft->Solve
337 * @param[out] PE Free energy of system at current Timestep
338 * @param[out] KE Kinetic ENergy of nuclei at current Timestep
339 * @param[out] TE temperature at current Timestep
340 *
341
342 *
343 *
344 *
345 */
346 void
347 InitialiseFromRestartFile(std::vector<dealii::Tensor<1, 3, double>> &disp,
348 std::vector<double> &velocity,
349 std::vector<double> &force,
350 std::vector<double> &KE,
351 std::vector<double> &IE,
352 std::vector<double> &TE);
353
354 /**
355
356* @brief NoseHoverExtendedLagrangian Writes the NHC parameters at each timeStep
357
358 * @param[in] thermovelocity Velocity of each, updated at each TimeStep
359 * @param[in] thermoposition Position of each thermostat , updated at each
360 TimeStep
361 * @param[in] thermomass Stores the mass of each thermostat.
362 * @param[in] time Current TimeStep
363 *
364 *
365 */
366 void
367 writeRestartNHCfile(const std::vector<double> &v_e,
368 const std::vector<double> &e,
369 const std::vector<double> &Q,
370 const int time);
371
372 /**
373
374* @brief InitialiseFromRestartNHCFile: Reads the NHC parameters during restart
375
376 * @param[out] thermovelocity Velocity of each, updated at each TimeStep
377 * @param[out] thermoposition Position of each thermostat , updated at each
378 TimeStep
379 * @param[out] thermomass Stores the mass of each thermostat.
380 *
381 *
382 *
383 */
384 void
385 InitialiseFromRestartNHCFile(std::vector<double> &v_e,
386 std::vector<double> &e,
387 std::vector<double> &Q);
388
389 /**
390
391* @brief writeTotalDisplacementFile: Updates Displacement.chk and appends TotalDisplacement.chk
392
393 * @param[in] r Displacemnt of each atom, updated at each TimeStep
394 * @param[in] time each TimeStep
395
396 *
397 *
398 *
399 */
400 void
402 const std::vector<dealii::Tensor<1, 3, double>> &r,
403 int time);
404
405 /**
406
407 * @brief NoseHoverExtendedLagrangian: Computes the Nose-Hover Hamiltonian when using NHC thermostat
408
409 * @param[in] thermovelocity Velocity of each, updated at each TimeStep
410 * @param[in] thermoposition Position of each thermostat , updated at each
411 TimeStep
412 * @param[in] thermomass Stores the mass of each thermostat.
413 * @param[in] PE Free energy of system at current Timestep
414 * @param[in] KE Kinetic ENergy of nuclei at current Timestep
415 * @param[in] Temperature temperature at current Timestep
416 *
417 * @return Hnose Nose Hamiltonian at each timestep
418 *
419 *
420 *
421 */
422
423 double
424 NoseHoverExtendedLagrangian(const std::vector<double> &thermovelocity,
425 const std::vector<double> &thermoposition,
426 const std::vector<double> &thermomass,
427 double PE,
428 double KE,
429 double T);
430 /**
431 * @brief checkRestart: Identifies the folder containing the restart file, sets the path of coordinates file and restursn the starting timestep *
432 * @return StartingTimeStep the timestep to restart the MD from.
433 *
434 *
435 *
436 */
437 int
438 checkRestart(std::string &coordinatesFile,
439 std::string &domainVectorsFile,
440 bool & scfRestart);
441
442 /**
443 * @brief DensityExtrapolation Identifies the folder containing the restart file, sets the path of coordinates file and restursn the starting timestep *
444 *
445 *
446 *
447 *
448 */
449 void
450 DensityExtrapolation(int TimeStep);
451
452 /**
453 * @brief DensityExtrapolation calculates the t+dt density as a second order extrapolation of density from t, t-dt and t-2dt
454 *
455 *
456 *
457 *
458 *
459 */
460 void
462
463
464 /**
465 * @brief set() initalises all the private datamembers of mdclass object from the parameters declared by user.
466 *
467 *
468 *
469 *
470 */
471 void
473 };
474} // namespace dftfe
475#endif
abstract base class for dft
Definition dftBase.h:34
std::string d_ThermostatType
Definition molecularDynamicsClass.h:92
void DensitySplitExtrapolation(int TimeStep)
DensityExtrapolation calculates the t+dt density as a second order extrapolation of density from t,...
double velocityVerlet(std::vector< double > &v, std::vector< dealii::Tensor< 1, 3, double > > &r, const std::vector< double > &atomMass, std::vector< double > &forceOnAtoms)
velocityVerlet
std::vector< std::vector< double > > d_atomFractionalunwrapped
Definition molecularDynamicsClass.h:95
void writeTotalDisplacementFile(const std::vector< dealii::Tensor< 1, 3, double > > &r, int time)
writeTotalDisplacementFile: Updates Displacement.chk and appends TotalDisplacement....
dealii::ConditionalOStream pcout
Definition molecularDynamicsClass.h:80
const unsigned int d_this_mpi_process
Definition molecularDynamicsClass.h:77
std::string d_restartFilesPath
Definition molecularDynamicsClass.h:82
double svr(std::vector< double > &v, double KE, double KEref)
void DensityExtrapolation(int TimeStep)
DensityExtrapolation Identifies the folder containing the restart file, sets the path of coordinates ...
void InitialiseFromRestartNHCFile(std::vector< double > &v_e, std::vector< double > &e, std::vector< double > &Q)
InitialiseFromRestartNHCFile: Reads the NHC parameters during restart.
dftBase * d_dftPtr
Definition molecularDynamicsClass.h:73
int mdNVTnosehoverchainsThermostat(std::vector< double > &KineticEnergyVector, std::vector< double > &InternalEnergyVector, std::vector< double > &EntropicEnergyVector, std::vector< double > &TotalEnergyVector, std::vector< dealii::Tensor< 1, 3, double > > &displacements, std::vector< double > &velocity, std::vector< double > &force, const std::vector< double > &atomMass)
mdNVTnosehoverchainsThermostat Performs a Canonical Ensemble MD calculation. The inital temperature i...
distributedCPUVec< double > d_extrapDensity_tmin1
Definition molecularDynamicsClass.h:97
void InitialiseFromRestartFile(std::vector< dealii::Tensor< 1, 3, double > > &disp, std::vector< double > &velocity, std::vector< double > &force, std::vector< double > &KE, std::vector< double > &IE, std::vector< double > &TE)
InitialiseFromRestartFile : Initialise atomcordinates, velocity and force at restart.
double d_MDstartWallTime
Definition molecularDynamicsClass.h:93
int mdNVTsvrThermostat(std::vector< double > &KineticEnergyVector, std::vector< double > &InternalEnergyVector, std::vector< double > &EntropicEnergyVector, std::vector< double > &TotalEnergyVector, std::vector< dealii::Tensor< 1, 3, double > > &displacements, std::vector< double > &velocity, std::vector< double > &force, const std::vector< double > &atomMass)
mdNVTsvrThermostat Performs a Canonical Ensemble MD calculation. The inital temperature is set by run...
void writeRestartFile(const std::vector< dealii::Tensor< 1, 3, double > > &disp, const std::vector< double > &velocity, const std::vector< double > &force, const std::vector< double > &KineticEnergyVector, const std::vector< double > &InternalEnergyVector, const std::vector< double > &TotalEnergyVector, int time)
writeRestartFile: Writing files at each timestep to mdRestart
const double kB
Definition molecularDynamicsClass.h:54
void set()
set() initalises all the private datamembers of mdclass object from the parameters declared by user.
const int d_verbosity
Definition molecularDynamicsClass.h:83
distributedCPUVec< double > d_extrapDensity_tp1
Definition molecularDynamicsClass.h:98
int d_ThermostatTimeConstant
Definition molecularDynamicsClass.h:91
unsigned int d_restartFlag
Definition molecularDynamicsClass.h:85
distributedCPUVec< double > d_extrapDensity_tmin2
Definition molecularDynamicsClass.h:97
int mdNVTrescaleThermostat(std::vector< double > &KineticEnergyVector, std::vector< double > &InternalEnergyVector, std::vector< double > &EntropicEnergyVector, std::vector< double > &TotalEnergyVector, std::vector< dealii::Tensor< 1, 3, double > > &displacements, std::vector< double > &velocity, std::vector< double > &force, const std::vector< double > &atomMass)
mdNVTrescaleThermostat Performs a Constant Kinetic Energy Ensemble MD calculation....
distributedCPUVec< double > d_extrapDensity_t0
Definition molecularDynamicsClass.h:98
double NoseHoverExtendedLagrangian(const std::vector< double > &thermovelocity, const std::vector< double > &thermoposition, const std::vector< double > &thermomass, double PE, double KE, double T)
NoseHoverExtendedLagrangian: Computes the Nose-Hover Hamiltonian when using NHC thermostat.
std::vector< double > d_domainLength
Definition molecularDynamicsClass.h:96
const double AngTobohr
Definition molecularDynamicsClass.h:53
std::unique_ptr< dftfeWrapper > d_dftfeWrapper
Definition molecularDynamicsClass.h:72
double RescaleVelocities(std::vector< double > &v, const std::vector< double > &M, double Temperature)
RescaleVelocities controls the velocity at timestep t. The scaling of velocities depends on ratio of ...
unsigned int d_numberGlobalCharges
Definition molecularDynamicsClass.h:86
const double haToeV
Definition molecularDynamicsClass.h:51
unsigned int d_TimeIndex
Definition molecularDynamicsClass.h:88
void writeRestartNHCfile(const std::vector< double > &v_e, const std::vector< double > &e, const std::vector< double > &Q, const int time)
NoseHoverExtendedLagrangian Writes the NHC parameters at each timeStep.
double d_MaxWallTime
Definition molecularDynamicsClass.h:94
int mdNVE(std::vector< double > &KineticEnergyVector, std::vector< double > &InternalEnergyVector, std::vector< double > &EntropicEnergyVector, std::vector< double > &TotalEnergyVector, std::vector< dealii::Tensor< 1, 3, double > > &displacements, std::vector< double > &velocity, std::vector< double > &force, const std::vector< double > &atomMass)
mdNVE Performs a Ccanonical Ensemble MD calculation. The inital temperature is set by runMD()....
const double bohrToAng
Definition molecularDynamicsClass.h:52
molecularDynamicsClass(const std::string parameter_file, const std::string restartFilesPath, const MPI_Comm &mpi_comm_parent, const bool restart, const int verbosity, const bool useDevice)
molecularDynamicsClass constructor: copy data from dftparameters to the memebrs of molecularDynamicsC...
int d_startingTimeStep
Definition molecularDynamicsClass.h:56
int runMD()
runMD: Assign atom mass to charge. Create vectors for displacement, velocity, force....
unsigned int d_numberofSteps
Definition molecularDynamicsClass.h:89
void NoseHoverChains(std::vector< double > &v, std::vector< double > &v_e, std::vector< double > &e, std::vector< double > Q, double KE, double Temperature)
NoseHoverChains controls the velocity at timestep t. The temperature is contolled by 2 thermostats....
const double haPerBohrToeVPerAng
Definition molecularDynamicsClass.h:50
double d_TimeStep
Definition molecularDynamicsClass.h:87
double d_startingTemperature
Definition molecularDynamicsClass.h:90
int checkRestart(std::string &coordinatesFile, std::string &domainVectorsFile, bool &scfRestart)
checkRestart: Identifies the folder containing the restart file, sets the path of coordinates file an...
const MPI_Comm d_mpiCommParent
Definition molecularDynamicsClass.h:76
Definition forceWfcContractions.h:32
Definition pseudoPotentialToDftfeConverter.cc:34
@ e
Definition ExcSSDFunctionalBaseClass.h:52
dealii::LinearAlgebra::distributed::Vector< elem_type, dealii::MemorySpace::Host > distributedCPUVec
Definition headers.h:92