-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvelocity_acf.py
executable file
·73 lines (63 loc) · 1.95 KB
/
velocity_acf.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
import statsmodels.tsa.api as smt
import utilities
import ase.io
from numba import jit
def velocity_from_newton(dx, a, dt):
return (dx - 0.5 * a * (dt**2)) / dt
def velocity_from_infinite(dx, dt):
return dx / dt
def get_velocitys(strcs, dt=1,method='newton'):
x = np.array([i.get_scaled_positions() for i in strcs]) # frac
dx = (utilities.get_nearest_distence(x[1:] - x[:-1]) @ strcs[0].cell) * (
10**-10) # \AA -> m
dt = 10**-15*dt # fs -> s
T = len(strcs)
if method == "newton":
f = np.array([i.get_forces() for i in strcs
]) * 1.6021766208 * (10**-19) / (10**-10) # eV / \AA -> J/m
m = strcs[0].get_masses() * 1.66053904 * (10**-27) # a.u -> kg
a = f / m[None, :, None] # J/m/kg = m*s^-2
v = velocity_from_newton(dx, a[:-1], dt)
elif method == "back":
v = velocity_from_infinite(dx, dt)
return v
@jit(nopython=True)
def uacf(tdE,tot):
dE=tdE[len(tdE)-tot:]
dEbar=dE.mean()
Cut=np.zeros(tot)
for i in range(tot):
temp=0
temp=(dE[i+1:]-dEbar)*(dE[:-i-1]-dEbar)
Cut[i]=temp.sum()
return Cut/tot
#@jit
def get_acf_all(v):
vsize=v.shape[0]
v=v.reshape(vsize,-1)
allacf=np.array([np.correlate(i,i,mode='full')[vsize-1:] for i in v.T],)
return allacf
#@jit(nopython=True)
#def get_acf_all(v):
# vsize=v.shape[0]
# v=v.reshape(vsize,-1)
# allacf=[uacf(i,vsize) for i in v.T]
# return allacf
def v2f(vacf,dt=1):
vacf /= vacf[0]
T = vacf.shape[0]
x = np.arange(0, 1000 / dt, 1000 / T * dt) / 3 * 100
fft = np.abs(np.fft.fft(vacf))
return x, fft
#if __name__ == "__main__":
# OUTCAR='OUTCAR'
# strcs=ase.io.read('OUTCAR',':')
# v=get_velocitys(strcs)
# np.save('v.npy',v)
# allacf=get_acf_all(v).sum(0)
# x,fft=v2f(allacf)
# np.savetxt('allacf.dat',allacf)
# np.savetxt('fftacf.dat',np.array([x,fft]).T)
# plt.plot(x,fft)
# plt.show()