-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathxdatcar_to_arc.py
More file actions
46 lines (38 loc) · 1.21 KB
/
xdatcar_to_arc.py
File metadata and controls
46 lines (38 loc) · 1.21 KB
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
#!/usr/bin/env python
'''
Script to convert XDATCAR to *.arc file to display in Material Studio.
'''
import numpy as np
from vaspy.atomco import XdatCar
from vaspy.functions import get_angle
xdatcar = XdatCar()
x, y, z = xdatcar.bases
# lattice info
# angles
alpha = get_angle(y, z)
beta = get_angle(x, z)
gamma = get_angle(x, y)
# length
lx = np.linalg.norm(x)
ly = np.linalg.norm(y)
lz = np.linalg.norm(z)
content = '!BIOSYM archive 3\nPBC=ON\n'
for step, data in xdatcar:
print("step = %s" % step)
content += ('%80.4f\n' % 0.0)
content += '!DATE Oct 29 11:16:38 2015\n'
content += 'PBC%10.4f%10.4f%10.4f%10.4f%10.4f%10.4f\n' %\
(lx, ly, lz, alpha, beta, gamma)
# data
data = xdatcar.dir2cart(xdatcar.bases, data)
atom_names = []
for n, atom in zip(xdatcar.atom_numbers, xdatcar.atom_types):
atom_names.extend([atom]*n)
for atom_name, coord in zip(atom_names, data):
coord = coord.tolist()
content += '%2s%16.9f%16.9f%16.9f%5s%2d%8s%8s%7.3f\n' %\
(atom_name, coord[0], coord[1], coord[2],
'XXXX', 1, 'xx', atom_name, 0.0)
content += 'end\nend\n'
with open('xdatcar.arc', 'w') as f:
f.write(content)