-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefactor.py
55 lines (37 loc) · 1.34 KB
/
prefactor.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
#!/usr/bin/python
"""
script for calculating the Vineyard prefactor from dynamical matrices
"""
import sys
import numpy as np
from numpy.typing import NDArray
def get_nonzero_eigvals(file_name: str) -> NDArray[float]:
"""
get the non-zero eigenvalues from text file
"""
dynmat = np.loadtxt(file_name)
dynlen = int(3 * np.sqrt(len(dynmat) / 3))
dynmat = dynmat.reshape((dynlen, dynlen))
eigvals, _ = np.linalg.eig(dynmat)
return eigvals[eigvals != 0]
def main():
# grab eigenvalues from text files specified in command line
initial_eigvals = get_nonzero_eigvals(sys.argv[1])
saddle_eigvals = get_nonzero_eigvals(sys.argv[2])
# make sure there are the same number of non-zero eigenvalues for both states
assert initial_eigvals.shape == saddle_eigvals.shape
# make sure there is one negative eigenvalue at saddle, and none at initial
assert np.sum(saddle_eigvals < 0) == 1
assert np.sum(initial_eigvals < 0) == 0
# calculate prefactor and print it to stdout
prefactor = np.exp(
0.5
* (
np.sum(np.log(initial_eigvals))
- np.sum(np.log(saddle_eigvals[saddle_eigvals > 0]))
)
)
print("# Vineyard prefactor in THz")
print(prefactor)
if __name__ == "__main__":
main()