-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxsd2vasp.py
executable file
·59 lines (48 loc) · 1.9 KB
/
xsd2vasp.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
#!/usr/bin/env python3
from sys import argv
import xml.dom.minidom
import numpy as np
from ase.data import chemical_symbols
prefix = "/home/zeyitu/.local/opt/Parameters/vasp-pseudopotential"
cellformat = " 1.00000000000000\n" \
" {0[0][0]:21.16f} {0[0][1]:21.16f} {0[0][2]:21.16f}\n" \
" {0[1][0]:21.16f} {0[1][1]:21.16f} {0[1][2]:21.16f}\n" \
" {0[2][0]:21.16f} {0[2][1]:21.16f} {0[2][2]:21.16f}".format
vecformat = " {0[0]:19.16f} {0[1]:19.16f} {0[2]:19.16f}".format
fxsd = argv[1]
xsd = xml.dom.minidom.parse(fxsd)
aimdoms = xsd.getElementsByTagName("IdentityMapping")
for aimdom in aimdoms:
sxyzlist = aimdom.getElementsByTagName("Atom3d")
if len(sxyzlist) > 0: break
symbols = [sxyz.getAttribute("Components") for sxyz in sxyzlist]
positions = np.array([sxyz.getAttribute("XYZ").split(',') for sxyz in sxyzlist], dtype=np.double)
for aimdom in aimdoms:
vectors = aimdom.getElementsByTagName("SpaceGroup")
if len(vectors) > 0: break
cell = np.array([vectors[0].getAttribute(axis).split(',') for axis in ("AVector", "BVector", "CVector")], dtype=np.double)
atomNums = np.array([chemical_symbols.index(symbol) for symbol in symbols])
atomOrder = np.argsort(atomNums, kind="mergesort")
atomNums = atomNums[atomOrder]
positions = positions[atomOrder]
nums, syms, history = [], [], []
for n in atomNums:
if n not in history:
history.append(n)
nums.append(1)
syms.append(chemical_symbols[n])
else:
nums[-1] += 1
txt_list = ['xsd', cellformat(cell)]
txt_list.append(' '.join(['{:>3s}'.format(sym) for sym in syms]))
txt_list.append(' '.join(['{:5d}'.format(num) for num in nums]))
txt_list.append("Direct")
txt_list.append('\n'.join([vecformat(vec) for vec in positions]))
with open("POSCAR", 'w') as f:
f.write('\n'.join(txt_list))
pot_list = []
for sym in syms:
with open('/'.join([prefix, sym, "POTCAR"]), 'r') as f:
pot_list.append(f.read())
with open("POTCAR", 'w') as f:
f.write(''.join(pot_list))