-
Notifications
You must be signed in to change notification settings - Fork 2
/
neb_spline.m
executable file
·44 lines (35 loc) · 1.48 KB
/
neb_spline.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function [ energy hyperdistance ] = neb_spline( directory, N )
%NEB_SPLINE Fit energies and forces of a NEB calculation using a spline.
% [energy,x] = neb_spline(directory,N) interpolates the energies from
% an NEB calculation using piecewise cubic Hermite polynomial
% interpolation. Optional argument directory specifies the directory
% containing the subdirectories 00, 01, etc. Optional argument N
% specifies the number of points to interpolate; the default is 1000.
% Both the energies and forces are used to perform the interpolation.
% The vector energy contains the energy, and the vector x contains the
% hyperdistance along the path.
%
% See also NEB_ENERGIES, PLOT_NEB_SPLINE, HYPERDISTANCE.
startDir = pwd();
if nargin > 0
cd(directory);
end
if nargin < 2
N=1000; % number of points to interpolate
end
nimg = num_images();
slope = zeros(1,nimg);
slope(1) = 0;
slope(nimg+2) = 0;
[ energy0 hyperdistance0 ] = neb_energies(); % energies/distance of images
% read images
for i = 2:nimg+1
forces = import_outcar([sprintf('%02d',i-1) '/OUTCAR'],'forces');
tangent = import_outcar([sprintf('%02d',i-1) '/OUTCAR'],'tangent');
tangent = tangent/sqrt(sum(sum(tangent.^2)));
slope(i) = -sum(sum(forces.*tangent));
end
hyperdistance = 0:hyperdistance0(end)/(N-1):hyperdistance0(end);
energy = pchipd(hyperdistance0,energy0,slope,hyperdistance);
cd(startDir);
end