DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
nudgedElasticBandClass.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
18
19#ifndef nudgedElasticBandClass_H_
20#define nudgedElasticBandClass_H_
21#include <vector>
23#include "nonLinearSolver.h"
24#include "dftBase.h"
25#include "dftfeWrapper.h"
26#include "headers.h"
27#include "constants.h"
29#include <BFGSNonLinearSolver.h>
31#include <dft.h>
32#include <dftUtils.h>
33#include <fileReaders.h>
34#include <force.h>
35#include <iomanip>
36#include <sys/stat.h>
37namespace dftfe
38{
40 {
41 public:
42 /**
43 * @brief First, sets the nebRestart path. Second, creates Step0 folder with coordinaes and domainVectors file.
44 * Third, creates the array of pointers of dftClass for each image.
45 * If in restart mode, calls function to read coordinates and initialise
46 * parameters Sets solvermode: CGPT, LBFGS, BFGS
47 */
48
49 nudgedElasticBandClass(const std::string parameter_file,
50 const std::string restartFilesPath,
51 const MPI_Comm & mpi_comm_parent,
52 const bool restart,
53 const int verbosity,
54 const bool useDevice,
55 const int d_numberOfImages,
56 const bool imageFreeze,
57 double Kmax,
58 double Kmin,
59 const double pathThreshold,
60 const int maximumNEBIteration,
61 const unsigned int _maxLineSearchIterCGPRP,
62 const unsigned int _lbfgsNumPastSteps,
63 const std::string &_bfgsStepMethod,
64 const double optimizermaxIonUpdateStep,
65 const std::string &optimizationSolver,
66 const std::string &coordinatesFileNEB,
67 const std::string &domainVectorsFileNEB,
68 const std::string &ionRelaxFlagsFile);
69
70 //~nudgedElasticBandClass();
71
72 double d_kmax = 0.1; // 0.1 Ha/bohr
73 double d_kmin = 0.1; // 0.1Ha/bohr
75 /**
76 * @brief Calls optimizer(nonLinearClass) solve. Prints the Final NEB energies and forces.
77 * References:
78 * 1.
79 * https://pubs.aip.org/aip/jcp/article/113/22/9978/184858/Improved-tangent-estimate-in-the-nudged-elastic
80 * 2.
81 * https://pubs.aip.org/aip/jcp/article/128/13/134106/977389/Optimization-methods-for-finding-minimum-energy
82 */
83 int
85 /**
86 * @brief Returns the Normed vetor satistfying ||v||_2 = 1
87 */
88 void
89 ReturnNormedVector(std::vector<double> &, int);
90 /**
91 * @brief Calculates the L-norm of a vector
92 */
93 void
94 LNorm(double &, std::vector<double>, int, int);
95 /**
96 * @brief Identifies the images to freeze, calculates gradient.
97 * First prints the Image No., free energy and force error of each image
98 * Prints activation energy of current step
99 */
100 void
101 gradient(std::vector<double> &gradient);
102 /**
103 * @brief Returns the total DoFs of the optimizer problem.
104 */
105 unsigned int
107 /**
108 * @brief Updates the positions of atoms and the total step count.
109 * Calls dftPtr colve to compute eenergy and force for current step.
110 */
111 void
112 update(const std::vector<double> &solution,
113 const bool computeForces = true,
114 const bool useSingleAtomSolutionsInitialGuess = false);
115 /**
116 * @brief Saves the output files for restart.
117 */
118 void
120 /**
121 * @brief initializes the data member d_relaxationFlags, nonlinearSolver,
122 *
123 */
124 void
126 /**
127 * @brief Not working. Finds the saddle point energy.
128 */
129 void
130 value(std::vector<double> &functionValue);
131
132 /// not implemented
133 void
134 precondition(std::vector<double> &s, const std::vector<double> &gradient);
135 /// not implemented
136 void
137 solution(std::vector<double> &solution);
138 /// not implemented
139 std::vector<unsigned int>
141
142 private:
143 std::vector<std::unique_ptr<dftfeWrapper>> d_dftfeWrapper;
145 std::unique_ptr<nonLinearSolver> d_nonLinearSolverPtr;
146 // parallel communication objects
147 const MPI_Comm d_mpiCommParent;
148 // const unsigned int n_mpi_processes;
149 const unsigned int d_this_mpi_process;
150
151 // conditional stream object
152 dealii::ConditionalOStream pcout;
153
157
158 /// total number of calls to update()
164 unsigned int d_restartFlag;
167 unsigned int d_numberOfImages;
169 // Solver Details
173 std::string bfgsStepMethod;
175 unsigned int lbfgsNumPastSteps;
178
179
180 std::map<int, std::vector<std::vector<double>>> d_atomLocationsInitial;
181 std::vector<unsigned int> d_relaxationFlags;
182 std::vector<double> d_externalForceOnAtom;
183 std::vector<double> d_ImageError;
184 std::vector<double> d_Length;
186 const MPI_Comm &
188
189 /**
190 * @brief Calculate the tangent between each image
191 */
192 void
193 CalculatePathTangent(int, std::vector<double> &);
194
195 /**
196 * @brief Calculates the force on atom along the tangent between images
197 */
198 void
200 std::vector<double> &,
201 const std::vector<double> &);
202 /**
203 * @brief Calculates force perpendicular to the tangent
204 */
205 void
207 std::vector<double> &,
208 const std::vector<double> &,
209 const std::vector<double> &);
210
211
212 /**
213 * @brief Calculates the force due to the spring.
214 */
215 void
216 CalculateSpringForce(int, std::vector<double> &, std::vector<double>);
217
218 /**
219 * @brief Calculates F_NEB = G_per+ F_spring
220 */
221 void
222 CalculateForceonImage(const std::vector<double> &,
223 const std::vector<double> &,
224 std::vector<double> &);
225
226 /**
227 * @brief Calculate path length: max diaplacement of atoms
228 */
229 double
230 CalculatePathLength(bool flag) const;
231
232 /**
233 * @brief Write Restart files
234 */
235 void
237
238
239 /**
240 * @brief Find spring constant based on k_max and k_min.
241 */
242 void
244
245 /**
246 * @brief Calculate F_per norm
247 */
248 void
249 ImageError(int image, double &Force);
250
251 /**
252 * @brief set() initalises all the private datamembers of nudgedElasticBandClass object from the parameters declared by user.
253 */
254 void
256
257 /**
258 * @brief check for convergence.
259 *
260 */
261 bool
262 isConverged() const;
263 /**
264 * @brief Check the restart files.
265 */
266 int
267 checkRestart(bool &periodic);
268 };
269
270
271} // namespace dftfe
272#endif
abstract base class for dft
Definition dftBase.h:34
nonlinearSolverProblem()
Constructor.
void solution(std::vector< double > &solution)
not implemented
std::unique_ptr< nonLinearSolver > d_nonLinearSolverPtr
Definition nudgedElasticBandClass.h:145
std::string d_optimizationSolver
Definition nudgedElasticBandClass.h:176
std::map< int, std::vector< std::vector< double > > > d_atomLocationsInitial
Definition nudgedElasticBandClass.h:180
bool d_solverRestart
Definition nudgedElasticBandClass.h:163
dftBase * d_dftPtr
Definition nudgedElasticBandClass.h:144
int d_NEBImageno
Definition nudgedElasticBandClass.h:74
double d_kmin
Definition nudgedElasticBandClass.h:73
void WriteRestartFiles(int step)
Write Restart files.
void LNorm(double &, std::vector< double >, int, int)
Calculates the L-norm of a vector.
std::string d_restartFilesPath
Definition nudgedElasticBandClass.h:155
dealii::ConditionalOStream pcout
Definition nudgedElasticBandClass.h:152
unsigned int d_countrelaxationFlags
Definition nudgedElasticBandClass.h:168
void precondition(std::vector< double > &s, const std::vector< double > &gradient)
not implemented
const unsigned int d_this_mpi_process
Definition nudgedElasticBandClass.h:149
unsigned int maxLineSearchIterCGPRP
Definition nudgedElasticBandClass.h:172
int findMEP()
Calls optimizer(nonLinearClass) solve. Prints the Final NEB energies and forces. References: 1....
unsigned int getNumberUnknowns() const
Returns the total DoFs of the optimizer problem.
void value(std::vector< double > &functionValue)
Not working. Finds the saddle point energy.
int d_startStep
Definition nudgedElasticBandClass.h:160
unsigned int d_maximumNEBIteration
Definition nudgedElasticBandClass.h:170
double d_kmax
Definition nudgedElasticBandClass.h:72
unsigned int d_numberOfImages
Definition nudgedElasticBandClass.h:167
void set()
set() initalises all the private datamembers of nudgedElasticBandClass object from the parameters dec...
unsigned int lbfgsNumPastSteps
Definition nudgedElasticBandClass.h:175
void CalculateForceperpendicular(int, std::vector< double > &, const std::vector< double > &, const std::vector< double > &)
Calculates force perpendicular to the tangent.
void update(const std::vector< double > &solution, const bool computeForces=true, const bool useSingleAtomSolutionsInitialGuess=false)
Updates the positions of atoms and the total step count. Calls dftPtr colve to compute eenergy and fo...
std::vector< unsigned int > getUnknownCountFlag() const
not implemented
std::string d_domainVectorsFileNEB
Definition nudgedElasticBandClass.h:185
void CalculateSpringForce(int, std::vector< double > &, std::vector< double >)
Calculates the force due to the spring.
void gradient(std::vector< double > &gradient)
Identifies the images to freeze, calculates gradient. First prints the Image No., free energy and for...
nudgedElasticBandClass(const std::string parameter_file, const std::string restartFilesPath, const MPI_Comm &mpi_comm_parent, const bool restart, const int verbosity, const bool useDevice, const int d_numberOfImages, const bool imageFreeze, double Kmax, double Kmin, const double pathThreshold, const int maximumNEBIteration, const unsigned int _maxLineSearchIterCGPRP, const unsigned int _lbfgsNumPastSteps, const std::string &_bfgsStepMethod, const double optimizermaxIonUpdateStep, const std::string &optimizationSolver, const std::string &coordinatesFileNEB, const std::string &domainVectorsFileNEB, const std::string &ionRelaxFlagsFile)
First, sets the nebRestart path. Second, creates Step0 folder with coordinaes and domainVectors file....
void CalculateForceparallel(int, std::vector< double > &, const std::vector< double > &)
Calculates the force on atom along the tangent between images.
int checkRestart(bool &periodic)
Check the restart files.
double d_optimizermaxIonUpdateStep
Definition nudgedElasticBandClass.h:174
void CalculateSpringConstant(int, double &)
Find spring constant based on k_max and k_min.
double d_maximumAtomForceToBeRelaxed
Definition nudgedElasticBandClass.h:166
unsigned int d_numberGlobalCharges
Definition nudgedElasticBandClass.h:165
bool isConverged() const
check for convergence.
unsigned int d_restartFlag
Definition nudgedElasticBandClass.h:164
void CalculatePathTangent(int, std::vector< double > &)
Calculate the tangent between each image.
void CalculateForceonImage(const std::vector< double > &, const std::vector< double > &, std::vector< double > &)
Calculates F_NEB = G_per+ F_spring.
int d_totalUpdateCalls
total number of calls to update()
Definition nudgedElasticBandClass.h:159
double d_optimizertolerance
Definition nudgedElasticBandClass.h:171
std::vector< double > d_ImageError
Definition nudgedElasticBandClass.h:183
void init()
initializes the data member d_relaxationFlags, nonlinearSolver,
const MPI_Comm & getMPICommunicator()
get MPI communicator.
std::vector< double > d_externalForceOnAtom
Definition nudgedElasticBandClass.h:182
std::vector< unsigned int > d_relaxationFlags
Definition nudgedElasticBandClass.h:181
std::string bfgsStepMethod
Definition nudgedElasticBandClass.h:173
bool d_isRestart
Definition nudgedElasticBandClass.h:162
std::string d_ionRelaxFlagsFile
Definition nudgedElasticBandClass.h:177
bool d_imageFreeze
Definition nudgedElasticBandClass.h:156
std::string d_solverRestartPath
Definition nudgedElasticBandClass.h:155
std::vector< double > d_Length
Definition nudgedElasticBandClass.h:184
void ImageError(int image, double &Force)
Calculate F_per norm.
double CalculatePathLength(bool flag) const
Calculate path length: max diaplacement of atoms.
int d_solver
Definition nudgedElasticBandClass.h:161
std::vector< std::unique_ptr< dftfeWrapper > > d_dftfeWrapper
Definition nudgedElasticBandClass.h:143
const MPI_Comm d_mpiCommParent
Definition nudgedElasticBandClass.h:147
int d_verbosity
Definition nudgedElasticBandClass.h:154
std::string d_coordinatesFileNEB
Definition nudgedElasticBandClass.h:185
void ReturnNormedVector(std::vector< double > &, int)
Returns the Normed vetor satistfying ||v||_2 = 1.
void save()
Saves the output files for restart.
Contains commonly used I/O file utils functions.
Definition pseudoPotentialToDftfeConverter.cc:34