-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdummy.py
executable file
·68 lines (53 loc) · 1.88 KB
/
dummy.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
63
64
65
66
67
68
# Adds and removes dummy atoms to fc.dat files in specified indicies
# python dummy.py filename [indicies] [indicies]
# use "-" and "+" to specify indicies and "," to separate them
# e.g. python dummy.py fc.dat -1,2 +10,11
# indicies can be in any order and there can be more than one specification
import sys
import numpy as np
np.set_printoptions(precision=2, suppress=True, linewidth=300)
with open(sys.argv[1], 'r+') as f:
lines = f.readlines()
ndim = int(lines[0].split()[1])
fcmat = []
for line in lines[1:]:
fcmat.append([float(i) for i in line.split()])
fcnew = np.array(fcmat).reshape((ndim,ndim))
# print(fcnew)
# print()
# print(sys.argv[1:])
sub, add = False, False
sub_ind, add_ind = [],[]
for arg in sys.argv[2:]:
if "-" in arg:
sub = True
sub_ind += [int(i) for i in arg[1:].split(",")]
# print(sub_ind)
if "+" in arg:
add = True
add_ind += [int(i) for i in arg[1:].split(",")]
# print(add_ind)
sub_ind = sorted(sub_ind,reverse=True)
add_ind = sorted(add_ind)
if sub:
for i in sub_ind:
fcnew = np.delete(fcnew, slice((i-1)*3,i*3), axis=0)
ndim -= 3
fcnew = np.delete(fcnew, slice((i-1)*3,i*3), axis=1)
# print(fcnew)
# print()
if add:
for i in add_ind:
fcnew = np.insert(fcnew, (i-1)*3, np.zeros((3,ndim)), axis=0)
ndim += 3
fcnew = np.insert(fcnew, [(i-1)*3], np.zeros((ndim,3)), axis=1)
# print(fcnew)
# print()
fcnew = fcnew.reshape((-1, 3))
new_txt = ' {0:<4}{1} \n'.format(int(ndim/3), ndim)
for row in fcnew:
new_txt += ' {0:>13.10f} {1:>13.10f} {2:>13.10f} \n'.format(row[0],row[1],row[2])
f.seek(0)
f.truncate()
f.write(new_txt)
f.close()