-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryproperties.py
executable file
·56 lines (50 loc) · 1.77 KB
/
cryproperties.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
#!/usr/bin/env python3
import os
import re
import numpy as np
from io import StringIO
from itertools import accumulate
from functools import reduce
from phonopy.units import Hartree
for file in os.listdir(os.getcwd()):
if os.path.isfile(file):
if file[-4:] == '.out':
fout = file
elif file[-5:] == '.BAND':
fband = file
elif file[-5:] == '.DOSS':
fdoss = file
with open(fout, 'r') as f:
outStr = f.read()
kp = re.findall(r'LINE\s{0,}[0-9]+\s{0,}\((.*)\) IN TERMS OF PRIMITIVE LATTICE VECTORS\n\s{0,}([0-9]+)', outStr)
paths = [re.sub(':', ' ---> ', p[0]) for p in kp]
nums = [int(p[1]) for p in kp]
accuNums = [0,] + list(accumulate(nums))
efermi = max(float(e) for e in re.findall(r'TOP OF VALENCE BANDS.*EIG(.*)AU', outStr))
with open(fband, 'r') as f:
bandStr = f.read()
ticks = [float(t) for t in re.findall(r'@ XAXIS TICK\b.+,\s{0,}(.*)', bandStr)]
lens = []
for i in range(1, len(ticks)):
lens.append(ticks[i] - ticks[i - 1])
band = np.loadtxt(StringIO(bandStr), comments=['#', '@'])[:, 1:] * Hartree
print('%d paths as follow:' % len(paths))
[print(' %s' % p) for p in paths]
inp = input('please input the output order: ')
order = [int(n) for n in inp.strip().split()]
src = 0
index, xaxis = [], []
for n in order:
n_abs = abs(n)
index_tmp = list(range(accuNums[n_abs - 1], accuNums[n_abs]))
if n < 0:
index_tmp.reverse()
index += index_tmp
dst = src + lens[n_abs - 1]
xaxis.append(np.linspace(src, dst, nums[n_abs - 1]))
print('%9.6f ---> %9.6f' % (src, dst))
src = dst
xaxis = np.column_stack([x.reshape(1, -1) for x in xaxis]).flatten()
np.savetxt('band.dat', np.column_stack((xaxis, band[index, :])), fmt='%12.6f')
doss = (np.loadtxt(fdoss, comments=['#', '@']) - np.array([efermi, 0])) * np.array([Hartree, 1 / Hartree])
np.savetxt('doss.dat', doss, fmt='%12.6f')