-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqe2vasp.py
More file actions
93 lines (85 loc) · 2.65 KB
/
qe2vasp.py
File metadata and controls
93 lines (85 loc) · 2.65 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import numpy as np
import glob
import re
from collections import Counter
natoms=5
ry2ev=13.605662285137
rypbr2evpang=25.71104309541616
br2ang=ry2ev/rypbr2evpang
def qe2poscar(finp):
lattice=[]
coords=[]
species=[]
f=open(finp, 'r')
for line in f:
if re.search('nat', line):
natoms=int(line.split()[2])
if line == None:
nat=NAN
f.close()
f=open(finp, 'r')
for line in f:
if re.search("CELL_PARAMETERS", line):
if "angstrom" in line:
factor=1
if "bohr" in line:
factor=br2ang
it=0
for line in f:
if (it<3):
line=line.split()
lattice.append(line)
it=it+1
if line == None:
lattice=NAN
f.close()
f=open(finp, 'r')
for line in f:
if re.search("ATOMIC_POSITIONS", line):
if "crystal" in line:
vaspName="DIRECT"
if "angstrom" in line:
vaspName="CARTESIAN"
it=0
for line in f:
if(it<natoms):
line=line.split()
species.append(line[0])
coords.append(line[1:4])
it=it+1
if line == None:
coords=NAN
species=NAN
f.close()
elements=list(Counter(species).keys()) # equals to list(set(words))
nElements=list(Counter(species).values()) # counts the elements' frequency
lattice=np.array(lattice).astype('float')
coords=np.array(coords).astype('float')
fvaspname=finp[:-4]+'.POSCAR.vasp'
fvasp=open(fvaspname,'w')
for iline in range(8+natoms):
if(iline==0):
outline="Written by Krishna\n"
if(iline==1):
outline="1.0\n"
if(iline>=2 and iline<5):
outline="{:23.16f} {:21.16f} {:21.16f}\n".format(lattice[iline-2,0],lattice[iline-2,1],lattice[iline-2,2])
if(iline==5):
outline="{} {} {}\n".format(elements[0],elements[1],elements[2])
if(iline==6):
outline="{} {} {}\n".format(nElements[0],nElements[1],nElements[2])
if(iline==7):
outline=vaspName+"\n"
if(iline>=8):
outline="{:21.16f} {:21.16f} {:21.16f}\n".format(coords[iline-8,0],coords[iline-8,1],coords[iline-8,2])
fvasp.write(outline)
return(natoms)
def qe2contcar(fout,natoms):
##yet to write the script
return()
topDir='./'
for inp in glob.glob(topDir+"*.inp"):
out=inp[:-4]+'.out'
natom=qe2poscar(inp)
qe2contcar(out,natoms)
print("done")