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