forked from zhenming-xu/VASP-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchgflag.py
62 lines (51 loc) · 1.77 KB
/
chgflag.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
60
61
62
#!/bin/env python3
import sys
import re
from VASP import readVasp
from VASP import writeVasp
if len(sys.argv) != 3 and len(sys.argv) != 4:
print("")
print("Usage: %s line1,line2,.... T/F vaspfile" % sys.argv[0].split('/')[-1])
print("the format of line1,line2,... can be either x or x-x")
print("try again")
print("")
exit(1)
flag = sys.argv[-2]
if flag != 'T' and flag != 'F':
print('')
print("Error: unidentified flag '%s'" % flag)
print('')
exit(1)
lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective = readVasp(sys.argv[-1])
edit_line_number = []
pattern = re.compile(r'-')
if len(sys.argv) == 4:
line_number = re.split(',', sys.argv[1])
for num in line_number:
if pattern.search(num):
num_list = pattern.split(num)
num_list[0] = int(num_list[0]) - 1
num_list[1] = int(num_list[1])
for i in range(num_list[0], num_list[1]):
edit_line_number.append(i)
else:
edit_line_number.append(int(num) - 1)
if selectiveflag == '':
selectiveflag = 'Selective dynamics'
total_atoms = sum(num_atoms)
if sys.argv[-2] == 'T':
for i in range(0, total_atoms):
selective.append(['F', 'F', 'F'])
else:
for i in range(0, total_atoms):
selective.append(['T', 'T', 'T'])
if edit_line_number:
for i in edit_line_number:
selective[i] = [sys.argv[-2], sys.argv[-2], sys.argv[-2]]
else:
for i in range(0, len(coordinates)):
selective[i] = [sys.argv[-2], sys.argv[-2], sys.argv[-2]]
writeVasp(sys.argv[-1], lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective)
print('')
print('---------------Done---------------')
print('')