-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasisconv.py
executable file
·59 lines (48 loc) · 1.34 KB
/
basisconv.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
#!/usr/bin/env python3
import sys
if len(sys.argv)<2:
print ("usage:", sys.argv[0], 'input > output')
exit(0)
fname = sys.argv[1]
f = open(fname, 'r')
contents = f.read()
f.close()
contents = contents.split('\n')
contents = list(filter(lambda x: len(x) and x[0]!='!', contents))
qs = []
atom_start = []
for i in range(len(contents)):
line = contents[i].split()
if len(line)==2 and line[0]=='a' and line[1].isdigit():
atom_start.append(i)
qs.append(int(line[1]))
if atom_start[0]!=0:
exit(1)
atom_start.append(len(contents))
basis = {}
for i in range(len(atom_start)-1):
basis[qs[i]] = contents[ atom_start[i]+1 : atom_start[i+1] ]
print('$basis')
print('type=gc')
for q in basis.keys():
nl = 0
j = 0
while j<len(basis[q]):
line = basis[q][j].split()
if len(line)!=3 and line[0]!='H' and not line[1].isdigit() and not line[2].isdigit():
exit(1)
nl += 1
np = int(line[1])
nc = int(line[2])
basis[q][j] = '%2d %2d' % (np, nc)
j+=1
for i in range(np):
line = basis[q][j].split()
if len(line)<nc+1:
exit(1)
line = " ".join(['%+.12e'%float(x) for x in line])
basis[q][j] = line
j+=1
print(" %3d %d" % (q, nl-1))
print( "\n".join(basis[q]) )
print('$end')